Asn1Parser.g4 95.2 KB
Newer Older
Elemer Lelik's avatar
Elemer Lelik committed
1
parser grammar Asn1Parser;
Elemer Lelik's avatar
Elemer Lelik committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

@header {
	import java.util.ArrayList;
	import java.util.List;
	import org.eclipse.titan.common.parsers.SyntacticErrorStorage;
	import org.eclipse.core.resources.IFile;
	import org.eclipse.core.resources.IMarker;
	import org.eclipse.core.resources.IProject;
	import org.eclipse.titan.common.parsers.TITANMarker;
	import org.eclipse.titan.designer.AST.*;
	import org.eclipse.titan.designer.AST.Identifier.Identifier_type;
	import org.eclipse.titan.designer.AST.ASN1.*;
	import org.eclipse.titan.designer.AST.ASN1.definitions.*;
	import org.eclipse.titan.designer.AST.ASN1.Object.*;
	import org.eclipse.titan.designer.AST.ASN1.Object.ObjectClassSyntax_setting.SyntaxSetting_types;
	import org.eclipse.titan.designer.AST.ASN1.types.*;
	import org.eclipse.titan.designer.AST.ASN1.values.*;
	import org.eclipse.titan.designer.AST.TTCN3.types.*; //maybe this should not be here
	import org.eclipse.titan.designer.AST.TTCN3.values.*;
	import org.eclipse.titan.designer.preferences.PreferenceConstants;
Elemer Lelik's avatar
Elemer Lelik committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
	import org.eclipse.titan.designer.AST.ASN1.values.Undefined_Block_Value;
	import org.eclipse.titan.designer.AST.ASN1.Object.ObjectSet_definition;
	import org.eclipse.titan.designer.AST.ASN1.Object.ObjectClass_Definition;
	import org.eclipse.titan.designer.AST.ASN1.types.ASN1_Enumerated_Type;
	import org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type;
	import org.eclipse.titan.designer.AST.ASN1.types.ASN1_BitString_Type;
	import org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type;
	import org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type;
	import org.eclipse.titan.designer.AST.ASN1.types.ASN1_Integer_Type;
	import org.eclipse.titan.designer.AST.ASN1.Parameterised_Reference;
	import org.eclipse.titan.designer.AST.ASN1.InformationFromObj;
	import org.eclipse.titan.designer.AST.ASN1.TableConstraint;
	import org.eclipse.titan.designer.AST.ASN1.Undefined_Assignment_OS_or_VS;
	import org.eclipse.titan.designer.AST.ASN1.ValueSet_Assignment;
Elemer Lelik's avatar
Elemer Lelik committed
36
37
38
39
}

/*
******************************************************************************
balaskoa's avatar
balaskoa committed
40
 * Copyright (c) 2000-2016 Ericsson Telecom AB
Elemer Lelik's avatar
Elemer Lelik committed
41
42
43
44
45
46
47
48
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 ******************************************************************************
*/
@members{
	private IFile actualFile = null;
49
	private int line = 1;
Elemer Lelik's avatar
Elemer Lelik committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
	private int offset = 0;
	private ASN1Module act_asn1_module = null;
	private IProject project = null;

	private List<SyntacticErrorStorage> errorsStored = new ArrayList<SyntacticErrorStorage>();
	
	public List<SyntacticErrorStorage> getErrorStorage() {
		return errorsStored;
	}
	
	public void setProject(IProject project) {
		this.project = project;
	}

	public ASN1Module getModule() {
		return act_asn1_module;
	}
  
	public void setActualFile(final IFile file) {
		actualFile = file;
	}
  
	public void setLine(final int line) {
		this.line = line;
	}

	public void setOffset(final int offset) {
		this.offset = offset;
	}
  
	private Location getLocation(final Token token) {
Elemer Lelik's avatar
Elemer Lelik committed
81
		return new Location(actualFile, line + token.getLine() - 1, offset + token.getStartIndex(), offset + token.getStopIndex() + 1);
Elemer Lelik's avatar
Elemer Lelik committed
82
83
84
85
86
87
	}
  
	private Location getLocation(final Token startToken, final Token endToken) {
		if (endToken == null) {
			return getLocation(startToken);
		}
Elemer Lelik's avatar
Elemer Lelik committed
88
		return new Location(actualFile, line - 1 + startToken.getLine(), offset + startToken.getStartIndex(), offset + endToken.getStopIndex() + 1);
Elemer Lelik's avatar
Elemer Lelik committed
89
90
91
92
93
94
	}

	public void reportWarning(TITANMarker marker){
		warnings.add(marker);
	}

Elemer Lelik's avatar
Elemer Lelik committed
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
	/**
	 * Creates a marker.
	 * Locations of input tokens are not moved by offset and line yet, this function does this conversion.
	 * @param aMessage marker message
	 * @param aStartToken the 1st token, its line and start position will be used for the location
	 *                  NOTE: start position is the column index of the tokens 1st character.
	 *                        Column index starts with 0.
	 * @param aEndToken the last token, its end position will be used for the location.
	 *                  NOTE: end position is the column index after the token's last character.
	 * @param aSeverity severity (info/warning/error)
	 * @param aPriority priority (low/normal/high)
	 * @return new marker
	 */
	public TITANMarker createMarker( final String aMessage, final Token aStartToken, final Token aEndToken, final int aSeverity, final int aPriority ) {
		TITANMarker marker = new TITANMarker(
			aMessage,
			(aStartToken != null) ? line - 1 + aStartToken.getLine() : -1,
			(aStartToken != null) ? offset + aStartToken.getStartIndex() : -1,
			(aEndToken != null) ? offset + aEndToken.getStopIndex() + 1 : -1,
			aSeverity, aPriority );
		return marker;
	}

	/**
	 * Adds a warning marker.
	 * Locations of input tokens are not moved by offset and line yet, this function does this conversion.
	 * @param aMessage marker message
	 * @param aStartToken the 1st token, its line and start position will be used for the location
	 *                  NOTE: start position is the column index of the tokens 1st character.
	 *                        Column index starts with 0.
	 * @param aEndToken the last token, its end position will be used for the location.
	 *                  NOTE: end position is the column index after the token's last character.
	 */
	public void reportWarning( final String aMessage, final Token aStartToken, final Token aEndToken ) {
		TITANMarker marker = createMarker( aMessage, aStartToken, aEndToken, IMarker.SEVERITY_WARNING, IMarker.PRIORITY_NORMAL );
		warnings.add(marker);
	}

Elemer Lelik's avatar
Elemer Lelik committed
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
	private List<TITANMarker> warnings = new ArrayList<TITANMarker>();


	public List<TITANMarker> getWarnings(){
		return warnings;
	}
	
	private ArrayList<TITANMarker> unsupportedConstructs = new ArrayList<TITANMarker>();

	public void reportUnsupportedConstruct(TITANMarker marker) {
		unsupportedConstructs.add(marker);
	}

	public ArrayList<TITANMarker> getUnsupportedConstructs() {
		return unsupportedConstructs;
	}
	
	int consume_counter = 0;

	public int nof_consumed_tokens() {
		return consume_counter;
	}

	public Token consume() {
			Token token = super.consume();
			
			if(token.getType() == BLOCK) {
Elemer Lelik's avatar
Elemer Lelik committed
160
				consume_counter += ((TokenWithIndexAndSubTokens)token).tokenList.size() + 2;
Elemer Lelik's avatar
Elemer Lelik committed
161
162
163
164
165
166
167
168
169
170
171
172
173
			} else {
				consume_counter++;
			}
			
			return token;
	}
}

/*
 * @author Laszlo Baji
 * 
 * */
options {
Elemer Lelik's avatar
Elemer Lelik committed
174
tokenVocab=Asn1Lexer;
Elemer Lelik's avatar
Elemer Lelik committed
175
176
177
178
179
180
181
182
183
184
185
186
}

pr_TITAN_special_Assignment [Identifier identifier]
returns [ASN1Assignment assignment]
locals [Token col, ASN1Type type, Reference reference, ObjectClass_Definition objectClass_Definition]
@init { $type = null; $reference = null; $objectClass_Definition = null; $assignment = null; }:
(	
	(	
		a = pr_Type_reg
		{
			$type = $a.type; 
			$assignment = new Type_Assignment($identifier, null, $type);
187
			$assignment.setLocation(getLocation($a.start, $a.stop));
Elemer Lelik's avatar
Elemer Lelik committed
188
189
190
191
192
193
		}
	|	b = pr_FromObjs
		{
			$reference = $b.fromObj; 
			$col = $b.start;
			$type = new Referenced_Type($reference);
194
			$type.setLocation(getLocation($b.start, $b.stop));
Elemer Lelik's avatar
Elemer Lelik committed
195
			$assignment = new Type_Assignment($identifier, null, $type);
196
			$assignment.setLocation(getLocation($col, $b.stop));
Elemer Lelik's avatar
Elemer Lelik committed
197
198
199
200
201
202
		}
	|	c = pr_UpperFromObj
		{
			$reference = $c.fromObj;
			$col = $c.start;
			$type = new Referenced_Type($reference);
203
			$type.setLocation(getLocation($c.start, $c.stop));
Elemer Lelik's avatar
Elemer Lelik committed
204
			$assignment = new Type_Assignment($identifier, null, $type);
205
			$assignment.setLocation(getLocation($col, $c.stop));
Elemer Lelik's avatar
Elemer Lelik committed
206
207
208
209
210
211
		}
	|	d = pr_ObjectClassDefn
		{
			$objectClass_Definition = $d.objectClass_Definition; 
			$col = $d.start;
			$assignment = new ObjectClass_Assignment($identifier, null, $objectClass_Definition);
212
			$assignment.setLocation(getLocation($d.start, $d.stop));
Elemer Lelik's avatar
Elemer Lelik committed
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
		}
	)
	EOF
);


pr_ASN1ModuleDefinition
locals [Identifier identifier, Tag_types defaultTagging, boolean extensionImplied, ASN1Assignments assignments]
@init { $identifier = null; $defaultTagging = null; $assignments = null; }:
	a = pr_ModuleIdentifier { $identifier = $a.identifier; }
	(
		pr_DefinitiveIdentifier
	)?
	DEFINITIONS
	b = pr_TagDefault { $defaultTagging = $b.defaultTagging; }
	c = pr_ExtensionDefault { $extensionImplied = $c.implied; }
	ASSIGNMENT
	{
		act_asn1_module = new ASN1Module($identifier, project, $defaultTagging, $extensionImplied);
	}
	d = BEGIN
	e = pr_ModuleBody { $assignments = $e.assignments; }
	f = END
	EOF
{
Elemer Lelik's avatar
Elemer Lelik committed
238
	act_asn1_module.setLocation(new LargeLocation(actualFile, $start, $f));
Elemer Lelik's avatar
Elemer Lelik committed
239
	if($assignments != null) {
240
		$assignments.setLocation(getLocation($d, $f));
Elemer Lelik's avatar
Elemer Lelik committed
241
242
243
244
245
246
247
		act_asn1_module.setAssignments($assignments);
	}
};
pr_ModuleIdentifier returns [Identifier identifier]
@init { $identifier = null; }:
	a = UPPERIDENTIFIER
{
248
	$identifier = new Identifier(Identifier_type.ID_ASN, $a.getText(), getLocation($a, $a));
Elemer Lelik's avatar
Elemer Lelik committed
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
};

pr_DefinitiveIdentifier:
(
	BLOCK
);

pr_TagDefault returns [Tag_types defaultTagging]
@init { $defaultTagging = Tag_types.EXPLICIT_TAGS; }:
(
	EXPLICIT	TAGS  { $defaultTagging = Tag_types.EXPLICIT_TAGS; }
|	IMPLICIT	TAGS  { $defaultTagging = Tag_types.IMPLICIT_TAGS; }
|	AUTOMATIC	TAGS  { $defaultTagging = Tag_types.AUTOMATIC_TAGS; }
)?;

pr_ModuleBody returns[ASN1Assignments assignments]
locals [Exports exports, Imports imports]
@init { $exports = null; $imports = null; $assignments = null; }:
(
	(
		a = pr_Exports	{ $exports = $a.exports; }
	|	{ $exports = new Exports(true); }
	)
	(	
		b = pr_Imports	{ $imports = $b.imports; }
	|	{
			$imports = new Imports();
Elemer Lelik's avatar
Elemer Lelik committed
276
			Location location = new Location(actualFile);
Elemer Lelik's avatar
Elemer Lelik committed
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
			$imports.setLocation(location);
			reportWarning(new TITANMarker("Missing IMPORTS clause is interpreted as `IMPORTS ; (import nothing) instead of importing all symbols from all modules.",
										0, 0, 0, IMarker.SEVERITY_WARNING, IMarker.PRIORITY_NORMAL));
		}
	)
	c = pr_AssignmentList	{ $assignments = $c.assignments; }
|	{	
		$exports = new Exports(false);
		$imports = new Imports();
		$assignments = new ASN1Assignments();
	}
)
{
	act_asn1_module.setExports($exports != null ? $exports : new Exports(false));
	act_asn1_module.setImports($imports != null ? $imports : new Imports());
};

pr_ExtensionDefault returns [boolean implied]
@init { $implied = false; }:
(
	EXTENSIBILITY
	IMPLIED { $implied = true; }
)?;

pr_Exports returns [Exports exports]
@init { $exports = null; }:
(
	EXPORTS
	 a = pr_SymbolsExported { $exports = $a.exports; }
	SEMICOLON
);

earplov's avatar
earplov committed
309
pr_Imports returns [Imports imports]
Elemer Lelik's avatar
Elemer Lelik committed
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
@init { $imports = null; }:
(
	IMPORTS
	(
		a = pr_SymbolsImported { $imports = $a.imports; }
	|	{ $imports = new Imports(); }
	)
	SEMICOLON
);

pr_AssignmentList returns [ASN1Assignments assignments]
locals [ASN1Assignment assignment]
@init { $assignment = null; $assignments = new ASN1Assignments(); }:
(
	a = pr_Assignment { $assignment = $a.assignment;
		if($assignment != null) {
326
			$assignment.setLocation(getLocation($a.start, $a.stop));
Elemer Lelik's avatar
Elemer Lelik committed
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
			$assignments.addAssignment($assignment);
		}
	}
)+;

pr_SymbolsExported returns [Exports exports]
locals [Symbols symbols]
@init { $symbols = null; $exports = null;}:
(
	a = pr_SymbolList  { $symbols = $a.symbols; $exports = new Exports($symbols); }
|	ALL  { $exports = new Exports(true); }
|	{ $exports = new Exports(false); }
);

pr_SymbolsImported returns [Imports imports]
locals [ImportModule importModule]
@init { $importModule = null; $imports = new Imports(); }:
(
	(
		a = pr_SymbolsFromModule  { $importModule = $a.importModule; $imports.addImportModule($importModule); }
	)+
);

pr_Assignment returns [ASN1Assignment assignment]
locals [Token endcol, Token col]:
(
Elemer Lelik's avatar
Elemer Lelik committed
353
354
355
356
357
	a = pr_ValueAssignment			{ $assignment = $a.assignment;  $col = $a.start; $endcol = $a.stop; }
|	b = pr_ValueSetTypeAssignment	{ $assignment = $b.assignment;  $col = $b.start; $endcol = $b.stop; }
|	c = pr_UndefAssignment			{ $assignment = $c.assignment;  $col = $c.start; $endcol = $c.stop; }
|	d = pr_ObjectClassAssignment	{ $assignment = $d.assignment;  $col = $d.start; $endcol = $d.stop; }
|	e = pr_TypeAssignment			{ $assignment = $e.assignment;  $col = $e.start; $endcol = $e.stop; }
Elemer Lelik's avatar
Elemer Lelik committed
358
359
360
)
{
	if ($assignment != null) {
361
		$assignment.setLocation(getLocation($col, $endcol));
Elemer Lelik's avatar
Elemer Lelik committed
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
	}
};

pr_SymbolList returns [Symbols symbols, Identifier identifier]
@init { $symbols = new Symbols(); $identifier = null; }:
(
	a = pr_Symbol  { $identifier = $a.identifier; $symbols.addSymbol($identifier); }
	(
		COMMA
		b = pr_Symbol  { $identifier = $b.identifier; $symbols.addSymbol($identifier); }
	)*
);

pr_SymbolsFromModule returns [ImportModule importModule]
locals [Symbols symbols]
@init { $symbols = null; $importModule = null; }:
(
	a = pr_SymbolList { $symbols = $a.symbols; }
	FROM
	b = UPPERIDENTIFIER
	(
		pr_AssignedIdentifier
	)?
)
{
	$importModule = new ImportModule(new Identifier(Identifier_type.ID_ASN, $b.getText(), 
388
	getLocation($b, $b)), $symbols);
Elemer Lelik's avatar
Elemer Lelik committed
389
390
391
392
393
394
};

pr_TypeAssignment returns [ASN1Assignment assignment]
locals [Identifier identifier, Ass_pard formalParameters, ASN1Type type, Reference reference]
@init { $identifier = null; $formalParameters = null; $type = null; $reference = null; $assignment = null; }:
(
395
	id = UPPERIDENTIFIER	{ $identifier = new Identifier(Identifier_type.ID_ASN, $id.getText(), getLocation($id, $id)); }
Elemer Lelik's avatar
Elemer Lelik committed
396
397
398
399
400
401
402
403
404
405
406
407
408
409
	fp = pr_OptParList		{ $formalParameters = $fp.parameters; }
	ASSIGNMENT
	(
		tr = pr_Type_reg
		{
			$type = $tr.type;
			$assignment = new Type_Assignment($identifier, $formalParameters, $type);	
		}
	)
|	(
		uo = pr_UpperFromObj  
		{
			$reference = $uo.fromObj;
			$type = new Referenced_Type($reference);
410
			$type.setLocation(getLocation($uo.start, $uo.stop));
Elemer Lelik's avatar
Elemer Lelik committed
411
412
413
414
415
416
417
418
419
			$assignment = new Type_Assignment($identifier, $formalParameters, $type);
			
		}
	)
|	(
		fo = pr_FromObjs  
		{
			$reference = $fo.fromObj;
			$type = new Referenced_Type($reference);
420
			$type.setLocation(getLocation($fo.start, $fo.stop));
Elemer Lelik's avatar
Elemer Lelik committed
421
422
423
424
425
426
427
428
429
			$assignment = new Type_Assignment($identifier, $formalParameters, $type);
		}
	)
);

pr_ObjectClassAssignment returns [ASN1Assignment assignment]
locals [Token endCol, Identifier identifier, Ass_pard formalParameters, ObjectClass_Definition objectClass_Definition]
@init { $identifier = null; $formalParameters = null; $objectClass_Definition = null; $assignment = null; }:
(
430
	id = UPPERIDENTIFIER	{ $identifier = new Identifier(Identifier_type.ID_ASN, $id.getText(), getLocation($id, $id)); }
Elemer Lelik's avatar
Elemer Lelik committed
431
432
433
434
435
	fp = pr_OptParList		{ $formalParameters = $fp.parameters; }
	ASSIGNMENT
	cd = pr_ObjectClassDefn
	{
		$objectClass_Definition = $cd.objectClass_Definition;
Elemer Lelik's avatar
Elemer Lelik committed
436
		$endCol = $cd.stop;
Elemer Lelik's avatar
Elemer Lelik committed
437
438
439
440
441
		$assignment = new ObjectClass_Assignment($identifier, $formalParameters, $objectClass_Definition);
	}
)
/*{
	if ($objectClass_Definition != null) {
442
		$assignment.setLocation(getLocation($id, $endCol));
Elemer Lelik's avatar
Elemer Lelik committed
443
444
445
446
447
448
449
450
	}
}*/
;

pr_UndefAssignment returns [ASN1Assignment assignment]
locals [Identifier identifier, Ass_pard formalParameters, Reference reference, Reference reference2]
@init { $identifier = null; $formalParameters = null; $reference = null; $reference2 = null; $assignment = null; }:
(
451
	id = UPPERIDENTIFIER	{ $identifier = new Identifier(Identifier_type.ID_ASN, $id.getText(), getLocation($id, $id)); }
Elemer Lelik's avatar
Elemer Lelik committed
452
453
454
455
456
457
458
	fp = pr_OptParList		{ $formalParameters = $fp.parameters; }
	(
		(
			d1  = pr_DefdUpper	{ $reference = $d1.reference; }
			ASSIGNMENT
			b1 = BLOCK			
			{
Elemer Lelik's avatar
Elemer Lelik committed
459
				$assignment = new Undefined_Assignment_OS_or_VS($identifier, $formalParameters, $reference, new Block($b1));
Elemer Lelik's avatar
Elemer Lelik committed
460
461
462
463
464
465
466
467
468
469
470
471
472
473
			}
		)
	|	(
			ASSIGNMENT
			d2 = pr_DefdUpper	
			{
				$reference = $d2.reference;
				if ($reference != null) {
					$assignment = new Undefined_Assignment_T_or_OC($identifier, $formalParameters, $reference);
				}
			}
		)	
	)
|	(
474
		id = LOWERIDENTIFIER	{ $identifier = new Identifier(Identifier_type.ID_ASN, $id.getText(), getLocation($id, $id)); }
Elemer Lelik's avatar
Elemer Lelik committed
475
476
477
478
479
480
481
482
		fp = pr_OptParList		{ $formalParameters = $fp.parameters; }
		d3  = pr_DefdUpper		{ $reference = $d3.reference; }
		ASSIGNMENT
		(
			(
				b3 = BLOCK 
				{
					if($reference != null) {
Elemer Lelik's avatar
Elemer Lelik committed
483
						$assignment = new Undefined_Assignment_O_or_V($identifier, $formalParameters, $reference, new Block($b3));
Elemer Lelik's avatar
Elemer Lelik committed
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
					}
				}
			)
		|	(
				d4 = pr_RefdLower
				{
					$reference2 = $d4.reference; 
					if($reference != null) {
						$assignment = new Undefined_Assignment_O_or_V($identifier, $formalParameters, $reference, $reference2);
					}
				}
			)
		)
	)
);

pr_ValueSetTypeAssignment returns [ASN1Assignment assignment]
locals [Identifier identifier, Ass_pard formalParameters, ASN1Type type]
@init { $identifier = null; $formalParameters = null; $type = null; $assignment = null; }:
(
504
	id = UPPERIDENTIFIER	{ $identifier = new Identifier(Identifier_type.ID_ASN, $id.getText(), getLocation($id, $id)); }
Elemer Lelik's avatar
Elemer Lelik committed
505
506
507
508
509
	fp = pr_OptParList		{ $formalParameters = $fp.parameters; }
	tr = pr_Type_reg 		{ $type = $tr.type; }
	ASSIGNMENT
	b = BLOCK
	{
Elemer Lelik's avatar
Elemer Lelik committed
510
511
		$assignment = new ValueSet_Assignment($identifier, $formalParameters, $type, new Block($b));
		reportWarning( "Taking ValueSetTypeAssignment as a TypeAssignment", $id, $id );
Elemer Lelik's avatar
Elemer Lelik committed
512
513
514
515
516
517
518
	}
);

pr_ValueAssignment returns [ASN1Assignment assignment]
locals [Token endcol, Identifier identifier, Reference reference, Reference reference2, ASN1Type type, Value value, Ass_pard formalParameters]
@init { $assignment = null;  $identifier = null; $reference = null; $reference2 = null; $type = null; $value = null; $formalParameters = null; }: // valuereference Type "::=" Value
(
519
	id = LOWERIDENTIFIER	{ $identifier = new Identifier(Identifier_type.ID_ASN, $id.getText(), getLocation($id, $id)); }
Elemer Lelik's avatar
Elemer Lelik committed
520
521
522
523
524
525
	fp = pr_OptParList		{ $formalParameters = $fp.parameters; }
	(
		(
			a10 = pr_Type_reg { $type = $a10.type; }
			ASSIGNMENT
			(	
Elemer Lelik's avatar
Elemer Lelik committed
526
527
				a11 = pr_Value_reg			{ $value = $a11.value; $endcol = $a11.stop; }
			|	a12 = pr_NullValue			{ $value = $a12.value; $endcol = $a12.stop; }
Elemer Lelik's avatar
Elemer Lelik committed
528
			|	block1 = BLOCK				{ $value = new Undefined_Block_Value(new Block($block1)); $endcol = $block1;}
Elemer Lelik's avatar
Elemer Lelik committed
529
530
			|	a14 = pr_ReferencedValue_reg{ $value = $a14.value; $endcol = $a14.stop; }
			|	a15 = pr_LowerIdValue		{ $value = $a15.value; $endcol = $a15.stop; }
Elemer Lelik's avatar
Elemer Lelik committed
531
532
533
534
535
536
537
538
539
			)
			{
				$assignment = new Value_Assignment($identifier, $formalParameters, $type, $value);
			}
		)
	|	a20 = pr_FromObjs { $reference = $a20.fromObj; }
		ASSIGNMENT
		a21 = pr_Value { $value = $a21.value; }
		{
Elemer Lelik's avatar
Elemer Lelik committed
540
			$endcol = $a21.stop;
Elemer Lelik's avatar
Elemer Lelik committed
541
542
543
544
545
546
547
			$type = new Referenced_Type($reference);
			$assignment = new Value_Assignment($identifier, $formalParameters, $type, $value);
		}
	|	a30 = pr_UpperFromObj { $reference = $a30.fromObj; } 
		ASSIGNMENT
		a31 = pr_Value { $value = $a31.value; }
		{
Elemer Lelik's avatar
Elemer Lelik committed
548
			$endcol = $a31.stop;
Elemer Lelik's avatar
Elemer Lelik committed
549
550
551
552
553
554
555
556
557
			$type = new Referenced_Type($reference);
			$assignment = new Value_Assignment($identifier, $formalParameters, $type, $value);
		}
	|	(	
			a40 = pr_DefdUpper { $reference = $a40.reference; }
			ASSIGNMENT
			(	
				a41 = pr_Value_reg { $value = $a41.value; }//value_assignment
				{
Elemer Lelik's avatar
Elemer Lelik committed
558
					$endcol = $a41.stop;
Elemer Lelik's avatar
Elemer Lelik committed
559
560
561
562
563
					$type = new Referenced_Type($reference);
					$assignment = new Value_Assignment( $identifier, $formalParameters, $type, $value);
				}
			|	a42 = pr_NullValue { $value = $a42.value; } //value_assignment
				{
Elemer Lelik's avatar
Elemer Lelik committed
564
					$endcol = $a42.stop;
Elemer Lelik's avatar
Elemer Lelik committed
565
566
567
568
569
570
571
572
573
574
					$type = new Referenced_Type($reference);
					$assignment = new Value_Assignment($identifier, $formalParameters, $type, $value);
				}
			)
		)

	)
)
{
	if ($assignment != null) {
575
		$assignment.setLocation(getLocation($id, $endcol));
Elemer Lelik's avatar
Elemer Lelik committed
576
577
578
579
580
581
582
	}
};

pr_OptParList returns [Ass_pard parameters]
@init { $parameters = null; }:
(
	(
Elemer Lelik's avatar
Elemer Lelik committed
583
		b = BLOCK	{ if($b != null) { $parameters = new Ass_pard(new Block($b)); }}
Elemer Lelik's avatar
Elemer Lelik committed
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
	)?
);

pr_Type_reg returns [ASN1Type type]
locals [ASN1Type subType, NamedType_Helper namedType_Helper, Constraint constraint, Constraints constraints]
@init { $subType = null; $namedType_Helper = null; $constraint = null; $constraints = null; $type = null; }:
(
	(	(	
			set = SET
		|	sequence = SEQUENCE
		)
		(	
			a = pr_Constraint		{ $constraint = $a.constraint; }
		|	b = pr_SizeConstraint	{ $constraint = $b.constraint; }
		)?
		OF
		(	
			c = pr_NamedType{ $namedType_Helper = $c.helper; $subType = $namedType_Helper.type;}
		|	d = pr_Type		{ $subType = $d.type;}
		)   // pr_SeqOfSetOfWithConstraint, pr_SequenceOfType, pr_SetOfType
		{
			if($set != null) {
				$type = new SetOf_Type($subType);
607
				$type.setLocation(getLocation($set, $c.stop != null ? $c.stop : $d.stop));
Elemer Lelik's avatar
Elemer Lelik committed
608
609
			} else if($sequence != null) {
				$type = new SequenceOf_Type($subType);
610
				$type.setLocation(getLocation($sequence, $c.stop != null ? $c.stop : $d.stop));
Elemer Lelik's avatar
Elemer Lelik committed
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
			}
			if ($constraint != null && $type != null) {
				$constraints = new Constraints();
				$constraints.addConstraint($constraint);
				$type.addConstraints($constraints);
			}
		}
	)
|//	(
//		(
			(	
				builtin = pr_BuiltinType_reg { $type = $builtin.type; }
				(
					e = pr_Constraints { $constraints = $e.constraints; } 
				)?  // pr_BuiltinType_reg, pr_ConstrainedType
				{
Elemer Lelik's avatar
Elemer Lelik committed
627
					if ( $type != null ) {
628
						$type.setLocation(getLocation($builtin.start, $builtin.stop));
Elemer Lelik's avatar
Elemer Lelik committed
629
630
						$type.addConstraints($constraints);
					}
Elemer Lelik's avatar
Elemer Lelik committed
631
632
633
634
635
				}
			|	ref = pr_ReferencedType { $type = $ref.type; }
				f = pr_Constraints
				{
					$constraints = $f.constraints;
Elemer Lelik's avatar
Elemer Lelik committed
636
					if ( $type != null ) {
637
						$type.setLocation(getLocation($ref.start, $ref.stop));
Elemer Lelik's avatar
Elemer Lelik committed
638
639
						$type.addConstraints($constraints);
					}
Elemer Lelik's avatar
Elemer Lelik committed
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
				}
			)
/*		(	(	pr_ReferencedType
			|	pr_BuiltinType_reg
			)  //pr_NakedType_reg
			pr_Constraints
		)=>pr_NakedType_reg pr_Constraints*/
//	|	pr_SeqOfSetOfWithConstraint
//		)  //pr_ConstrainedType
//|	(	pr_BuiltinType_reg
//	|	pr_SequenceOfType
//	|	pr_SetOfType
//	) //pr_BuiltinType
|	pr_Tag
	d = pr_Type	{ $type = $d.type; }
);

pr_ObjectClassDefn returns [ObjectClass_Definition objectClass_Definition]
Elemer Lelik's avatar
Elemer Lelik committed
658
locals [Token end, Block withBlock]
Elemer Lelik's avatar
Elemer Lelik committed
659
660
661
662
663
@init { $withBlock = null; $objectClass_Definition = null; }:
(	
	CLASS
	block1 = BLOCK {  $end = $block1; }
	(	
Elemer Lelik's avatar
Elemer Lelik committed
664
		block2 = pr_WithSyntaxSpec { $withBlock = $block2.block; $end = $block2.stop; }
Elemer Lelik's avatar
Elemer Lelik committed
665
666
667
	)?
)
{
Elemer Lelik's avatar
Elemer Lelik committed
668
	$objectClass_Definition = new ObjectClass_Definition(new Block($block1), $withBlock);
669
	$objectClass_Definition.setLocation(getLocation($block1, $end));
Elemer Lelik's avatar
Elemer Lelik committed
670
671
672
673
674
675
676
677
};

pr_Symbol returns [Identifier identifier]
@init { $identifier = null; }:
(	
	(	
		a = UPPERIDENTIFIER
		{ 
678
			$identifier = new Identifier(Identifier_type.ID_ASN, $a.getText(), getLocation($a, $a));
Elemer Lelik's avatar
Elemer Lelik committed
679
680
681
		}
	|	b = LOWERIDENTIFIER
		{ 
682
			$identifier = new Identifier(Identifier_type.ID_ASN, $b.getText(), getLocation($b, $b));
Elemer Lelik's avatar
Elemer Lelik committed
683
684
685
686
687
688
689
690
691
692
693
694
695
		}
	)
	( 
		BLOCK
	)?
);

pr_AssignedIdentifier:
(	
	BLOCK
|	pr_DefinedValue
);

Elemer Lelik's avatar
Elemer Lelik committed
696
pr_WithSyntaxSpec returns [Block block]
Elemer Lelik's avatar
Elemer Lelik committed
697
698
699
700
701
702
703
@init { $block = null; }:
(	
	WITH
	SYNTAX
	b = BLOCK
)
{
Elemer Lelik's avatar
Elemer Lelik committed
704
	$block = new Block($b);
Elemer Lelik's avatar
Elemer Lelik committed
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
};


pr_special_ObjectSyntaxLiteral returns[ObjectClassSyntax_literal literal]
locals [String text]
@init { $text = _input.LT(1).getText(); }:
(	COMMA | ABSENT | ALL | ANY | APPLICATION | AUTOMATIC | BEGIN | BY | CLASS | COMPONENT | COMPONENTS
|	CONSTRAINED | CONTAINING | DEFAULT | DEFINED | DEFINITIONS | ENCODED | EXCEPT
|	EXPLICIT | EXPORTS | EXTENSIBILITY | FROM | IDENTIFIER | IMPLICIT | IMPLIED | IMPORTS | INCLUDES | MAX | MIN | OF
|	OPTIONAL | PATTERN | PDV | PRESENT | PRIVATE | SIZE | STRING | SYNTAX | TAGS | UNIQUE | UNIVERSAL | WITH
)
{
	$literal = new ObjectClassSyntax_literal($text);
};

pr_special_FieldSpecList returns [FieldSpecifications fieldSpecifications]
@init { $fieldSpecifications = null; }:
(	
	a = pr_FieldSpecList { $fieldSpecifications = $a.fieldSpecifications; }
	EOF
);

pr_FieldSpecList returns [FieldSpecifications fieldSpecifications]
locals [FieldSpecification fieldSpecification]
@init { $fieldSpecification = null; $fieldSpecifications = new FieldSpecifications(); }:
(
	startCol = pr_FieldSpec { $fieldSpecification = $startCol.fieldSpecification; }
	{
		if ($fieldSpecification != null) {
734
			$fieldSpecification.setLocation(getLocation($startCol.start, $startCol.stop));
Elemer Lelik's avatar
Elemer Lelik committed
735
736
737
738
739
740
741
			$fieldSpecifications.addFieldSpecification($fieldSpecification);
		}
	}
	(	
		COMMA
		endCol = pr_FieldSpec { $fieldSpecification = $endCol.fieldSpecification; }
			{	if($fieldSpecification != null) {
742
					$fieldSpecification.setLocation(getLocation($endCol.start, $endCol.stop));
Elemer Lelik's avatar
Elemer Lelik committed
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
					$fieldSpecifications.addFieldSpecification($fieldSpecification);
				}
			}
	)*
);

pr_FieldSpec returns [FieldSpecification fieldSpecification]
@init { $fieldSpecification = null; }:
(	
	a = pr_TypeFieldSpec { $fieldSpecification = $a.fieldspecification; }
|	b = pr_FixedTypeValueFieldSpec { $fieldSpecification = $b.fieldSpecification; }
|	c = pr_UndefFieldSpec { $fieldSpecification = $c.fieldSpecification; }
);

pr_TypeFieldSpec returns [Type_FieldSpecification fieldspecification]
@init { boolean is_optional = false; ASN1Type type = null; $fieldspecification = null; }:
(
	a = AMPUPPERIDENTIFIER
	(
		OPTIONAL	{ is_optional = true; }
	|	DEFAULT
		b = pr_Type	{ type = $b.type; }
	)?
)
{
768
	Identifier identifier = new Identifier(Identifier_type.ID_ASN, $a.getText(), getLocation($a, $a));
Elemer Lelik's avatar
Elemer Lelik committed
769
770
771
772
	$fieldspecification = new Type_FieldSpecification(identifier, is_optional, type);
};

pr_UndefFieldSpec returns [Undefined_FieldSpecification fieldSpecification]
Elemer Lelik's avatar
Elemer Lelik committed
773
locals [Identifier identifier, Defined_Reference reference, boolean is_optional, Block defaultBlock, Reference defaultSetting]
Elemer Lelik's avatar
Elemer Lelik committed
774
775
776
777
@init { $identifier = null; $reference = null;  $is_optional = false; $defaultBlock = null; $defaultSetting = null; 
		$fieldSpecification = null; } :
(
	(	
778
779
		a = AMPLOWERIDENTIFIER	{ $identifier = new Identifier(Identifier_type.ID_ASN, $a.getText(), getLocation($a, $a)); }
	|	b = AMPUPPERIDENTIFIER	{ $identifier = new Identifier(Identifier_type.ID_ASN, $b.getText(), getLocation($b, $b)); }
Elemer Lelik's avatar
Elemer Lelik committed
780
781
782
783
784
785
	)
	c = pr_SimplDefdUpper		{ $reference = $c.reference; }
	(	
		OPTIONAL	{ $is_optional = true; }
	|	DEFAULT
		(	
Elemer Lelik's avatar
Elemer Lelik committed
786
			block = BLOCK 	{ $defaultBlock = new Block($block); }//pr_Dflt_Block
Elemer Lelik's avatar
Elemer Lelik committed
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
		|	e = pr_RefdLower { $defaultSetting = $e.reference; }//pr_Dflt_RefdLower // This did not exist for AmpUpperIdentifier in the original parser
		)
	)?
)
{
	if($defaultBlock == null) {
		$fieldSpecification = new Undefined_FieldSpecification($identifier, $reference, $is_optional, $defaultSetting);
	} else {
		$fieldSpecification = new Undefined_FieldSpecification($identifier, $reference, $is_optional, $defaultBlock);
	}
};

pr_special_ObjectClassSyntax_Builder [FieldSpecifications fieldSpecifications]
returns [ArrayList<ObjectClassSyntax_Node> nodes]
locals [Token endcol, Identifier identifier, ObjectClassSyntax_literal literal]
@init { $identifier = null; $literal = null; $nodes = new ArrayList<ObjectClassSyntax_Node>(); }:
(	
	(
		block = BLOCK
		{
Elemer Lelik's avatar
Elemer Lelik committed
807
			ObjectClassSyntax_Builder builder = new ObjectClassSyntax_Builder(new Block($block), $fieldSpecifications);
Elemer Lelik's avatar
Elemer Lelik committed
808
809
810
811
812
813
814
815
816
817
818
819
820
			ObjectClassSyntax_sequence sequence = new ObjectClassSyntax_sequence(true, false);
			$nodes.add(sequence);
			sequence.accept(builder);
		}
	|	a = pr_special_ObjectSyntaxLiteral
			{
				$literal = $a.literal;
				if($literal != null){
					$nodes.add($literal);
				}
			}
	|	b = UPPERIDENTIFIER //literal_id
			{
821
				$identifier = new Identifier(Identifier_type.ID_ASN, $b.getText(), getLocation($b, $b));
Elemer Lelik's avatar
Elemer Lelik committed
822
823
824
825
826
				if($identifier.isvalidAsnWord()){
					$nodes.add(new ObjectClassSyntax_literal($identifier));
				}
			}
	|	(	
827
828
			c = AMPUPPERIDENTIFIER { $identifier = new Identifier(Identifier_type.ID_ASN, $c.getText(), getLocation($c, $c)); $endcol = $c; }
		|	d = AMPLOWERIDENTIFIER { $identifier = new Identifier(Identifier_type.ID_ASN, $d.getText(), getLocation($d, $d)); $endcol = $d; }
Elemer Lelik's avatar
Elemer Lelik committed
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
		)	//ampId
		{
			if ($identifier != null) {
				if ($fieldSpecifications.hasFieldSpecificationWithId($identifier)) {
					FieldSpecification fieldSpec = $fieldSpecifications.getFieldSpecificationByIdentifier($identifier).getLast();
					ObjectClassSyntax_setting setting;
					switch (fieldSpec.getFieldSpecificationType()) {
					case FS_T:
						$nodes.add(new ObjectClassSyntax_setting(SyntaxSetting_types.S_T, $identifier));
						break;
					case FS_V_FT:
					case FS_V_VT:
						$nodes.add(new ObjectClassSyntax_setting(SyntaxSetting_types.S_V, $identifier));
						break;
					case FS_VS_FT:
					case FS_VS_VT:
						$nodes.add(new ObjectClassSyntax_setting(SyntaxSetting_types.S_VS, $identifier));
						break;
					case FS_O:
						$nodes.add(new ObjectClassSyntax_setting(SyntaxSetting_types.S_O, $identifier));
						break;
					case FS_OS:
						$nodes.add(new ObjectClassSyntax_setting(SyntaxSetting_types.S_OS, $identifier));
						break;
					case FS_ERROR:
						break;
					case FS_UNDEFINED:
					default:
						// TODO mark as error
						break;
					}
				} else {
861
					(getLocation($endcol, $endcol)).reportSemanticError("No field with name `" + $identifier.getDisplayName() + "'");
Elemer Lelik's avatar
Elemer Lelik committed
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
				}
			}
		}
	)*
	EOF
);

pr_special_NamedBitListValue returns [Named_Bits named_bits]
@init { $named_bits = new Named_Bits(); }:
(
	pr_IdentifierList [$named_bits]
	EOF
);

pr_special_Type returns [ASN1Type type]
@init { $type = null; }:
(
	a = pr_Type { $type = $a.type; }
);

pr_special_Object returns [ASN1Object object]
@init { $object = null; }:
(
	a = pr_Object { $object = $a.object; }
);

pr_special_ObjectSet returns [ObjectSet objectSet]
@init { $objectSet = null; }:
(
	a = pr_ObjectSet  { $objectSet = $a.objectSet; }
);

pr_special_Value returns [Value value]
@init { $value = null; }:
(	
	a = pr_special_Value_subrule { $value = $a.value; }
);

pr_special_Value_subrule returns [Value value]
@init { $value = null; }:
(	// Originally pr_FixedTypeFieldValue, but moved to a separate branch not to have invalid lookaheads
	a = pr_BuiltinValue { $value = $a.value; }
Elemer Lelik's avatar
Elemer Lelik committed
904
905
|	b = pr_ReferencedValue_reg { $value = $b.value; }
|	c = pr_BuiltinValue { $value = $c.value; }
Elemer Lelik's avatar
Elemer Lelik committed
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
);

pr_special_Value_endCorrectingSubrule:
(	
	pr_special_Value_subrule
	( . | EOF )
	( . | EOF )
);

// SPECIAL RULE to parse any kind of references for code completion or open declaration features.

pr_parseReference returns [Reference reference]
locals [Token endCol, FieldSubReference subReference]
@init { $subReference = null; $reference = new Reference(null); }:
(	
	(
		(	a1 = LOWERIDENTIFIER
			{
924
				$subReference = new FieldSubReference(new Identifier(Identifier_type.ID_ASN, $a1.getText(), getLocation($a1, $a1)));
Elemer Lelik's avatar
Elemer Lelik committed
925
926
927
928
				$subReference.setLocation(getLocation($a1));
			}
		|	b1 = UPPERIDENTIFIER
			{
929
				$subReference = new FieldSubReference(new Identifier(Identifier_type.ID_ASN, $b1.getText(), getLocation($b1, $b1)));
Elemer Lelik's avatar
Elemer Lelik committed
930
931
932
933
				$subReference.setLocation(getLocation($b1));
			}
		|	c1 = AMPLOWERIDENTIFIER
			{
934
				$subReference = new FieldSubReference(new Identifier(Identifier_type.ID_ASN, $c1.getText(), getLocation($c1, $c1)));
Elemer Lelik's avatar
Elemer Lelik committed
935
936
937
938
				$subReference.setLocation(getLocation($c1));
			}
		|	d1 = AMPUPPERIDENTIFIER
			{
939
				$subReference = new FieldSubReference(new Identifier(Identifier_type.ID_ASN, $d1.getText(), getLocation($d1, $d1)));
Elemer Lelik's avatar
Elemer Lelik committed
940
941
942
943
944
945
946
947
948
949
				$subReference.setLocation(getLocation($d1));
			}
		)
		( BLOCK )?
		{ $reference.addSubReference($subReference); }
	)
	(	
		DOT
		(	a2 = LOWERIDENTIFIER
			{
950
				$subReference = new FieldSubReference(new Identifier(Identifier_type.ID_ASN, $a2.getText(), getLocation($a2, $a2)));
Elemer Lelik's avatar
Elemer Lelik committed
951
952
953
954
				$subReference.setLocation(getLocation($a2));
			}
		|	b2 = UPPERIDENTIFIER
			{
955
				$subReference = new FieldSubReference(new Identifier(Identifier_type.ID_ASN, $b2.getText(), getLocation($b2, $b2)));
Elemer Lelik's avatar
Elemer Lelik committed
956
957
958
959
				$subReference.setLocation(getLocation($b2));
			}
		|	c2 = AMPLOWERIDENTIFIER
			{
960
				$subReference = new FieldSubReference(new Identifier(Identifier_type.ID_ASN, $c2.getText(), getLocation($c2, $c2)));
Elemer Lelik's avatar
Elemer Lelik committed
961
962
963
964
				$subReference.setLocation(getLocation($c2));
			}
		|	d2 = AMPUPPERIDENTIFIER
			{
965
				$subReference = new FieldSubReference(new Identifier(Identifier_type.ID_ASN, $d2.getText(), getLocation($d2, $d2)));
Elemer Lelik's avatar
Elemer Lelik committed
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
				$subReference.setLocation(getLocation($d2));
			}
		)
		( BLOCK )?
		{ $reference.addSubReference($subReference); }
	)*
	(	i = DOT
		{
			$subReference = new FieldSubReference(new Identifier(Identifier_type.ID_ASN,""));
			$subReference.setLocation(getLocation($i));
			$reference.addSubReference($subReference);
		}
	)?
	j = EOF { $endCol = $j; }
|	k = EOF { $endCol = $k; }
	{
		$subReference = new FieldSubReference(new Identifier(Identifier_type.ID_ASN,""));
		$subReference.setLocation(getLocation($k));
		$reference.addSubReference($subReference);
	}
)
{
	$reference.setLocation(getLocation($start,$endCol));
};


pr_special_NamedNumberList returns [NamedValues namedValues]
@init { $namedValues = new NamedValues(); }:
(
	pr_NamedNumberList[$namedValues]
	EOF
);

pr_special_Enumerations returns [ASN1_Enumeration enumeration]
@init { $enumeration = new ASN1_Enumeration(); }:
(
	pr_Enumerations [$enumeration]
	EOF
);

pr_Enumerations [ASN1_Enumeration enumeration]
Elemer Lelik's avatar
Elemer Lelik committed
1007
1008
locals [ ExceptionSpecification exceptionSpecification]
@init	{ $exceptionSpecification = null; }:
Elemer Lelik's avatar
Elemer Lelik committed
1009
(	
Elemer Lelik's avatar
Elemer Lelik committed
1010
	a = pr_Enumeration	{ $enumeration.enumItems1 = $a.enumItems; }
Elemer Lelik's avatar
Elemer Lelik committed
1011
1012
1013
1014
1015
1016
	(	
		COMMA
		ELLIPSIS	{ $enumeration.hasEllipses = true; }
		b = pr_ExceptionSpec { $exceptionSpecification = $b.exceptionSpecification; } 
		(	
			COMMA
Elemer Lelik's avatar
Elemer Lelik committed
1017
			c = pr_Enumeration	{ $enumeration.enumItems2 = $c.enumItems; }
Elemer Lelik's avatar
Elemer Lelik committed
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
		)?
	)?
);

pr_Enumeration returns [EnumerationItems enumItems]
locals [EnumItem enumItem]
@init { $enumItem = null; $enumItems = new EnumerationItems(); }:
(
	a = pr_EnumerationItem 
	{
		$enumItem = $a.enumItem;
		if($enumItem != null) { $enumItems.addEnumItem($enumItem); }
	}
	(	
		COMMA
		b = pr_EnumerationItem
		{
			$enumItem = $b.enumItem;
			if($enumItem != null) { $enumItems.addEnumItem($enumItem); }
		}
	)*
);

pr_EnumerationItem returns [EnumItem enumItem]
locals [Value value]
@init { $value = null; $enumItem = null; }:
(
	a = LOWERIDENTIFIER
	(
		LPAREN
		(
			b = pr_SignedNumber	{ $value = $b.value; }
		|	c = pr_DefinedValue	{ $value = $c.value; }
		)
		d = RPAREN
	)?
)
{
1056
	Identifier identifier = new Identifier(Identifier_type.ID_ASN, $a.getText(), getLocation($a, $a));
Elemer Lelik's avatar
Elemer Lelik committed
1057
	$enumItem = new EnumItem(identifier, $value);
1058
	$enumItem.setLocation(getLocation($a, $d == null ? $a : $d));
Elemer Lelik's avatar
Elemer Lelik committed
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
};

pr_NamedBitList [NamedValues namedValues]
locals [NamedValue namedValue]
@init { $namedValue = null; }:
(	
	a = pr_NamedBit 
	{
		$namedValue = $a.namedValue;
		if($namedValue != null) { $namedValues.addNamedValue($namedValue); }
	}
	(
		COMMA
		b = pr_NamedBit
		{
			$namedValue = $b.namedValue;
			if($namedValue != null) { $namedValues.addNamedValue($namedValue); }
		}
	)*
);

pr_NamedBit returns [NamedValue namedValue]
locals [Value value]
@init { $value = null; $namedValue = null; }:
(	
	a = LOWERIDENTIFIER
	LPAREN
	(	
		b = pr_Val_Number	{ $value = $b.value; }
	|	c = pr_DefinedValue	{ $value = $c.value; }
	)
	d = RPAREN
)
{
1093
	Identifier identifier = new Identifier(Identifier_type.ID_ASN, $a.getText(), getLocation($a, $a));
Elemer Lelik's avatar
Elemer Lelik committed
1094
	$namedValue = new NamedValue(identifier, $value);
1095
	$namedValue.setLocation(getLocation($a, $d == null ? $a : $d));
Elemer Lelik's avatar
Elemer Lelik committed
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
};

pr_IdentifierList [Named_Bits named_bits]:
(
	pr_IdentifierList1[named_bits]

)?;

pr_IdentifierList1 [Named_Bits named_bits]:
(
	a = LOWERIDENTIFIER
	{
1108
		Identifier identifier1 = new Identifier(Identifier_type.ID_ASN, $a.getText(), getLocation($a, $a));
Elemer Lelik's avatar
Elemer Lelik committed
1109
1110
1111
1112
1113
1114
		$named_bits.addId(identifier1);
	}
	(	
		COMMA
		b = LOWERIDENTIFIER
		{
1115
			Identifier identifier2 = new Identifier(Identifier_type.ID_ASN, $b.getText(), getLocation($b, $b));
Elemer Lelik's avatar
Elemer Lelik committed
1116
1117
1118
1119
1120
			$named_bits.addId(identifier2);
		}
	)*
)
{
1121
	$named_bits.setLocation(getLocation($a, $b == null ? $a : $b));
Elemer Lelik's avatar
Elemer Lelik committed
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
};


pr_NamedNumberList [NamedValues namedValues]
locals [NamedValue namedValue]
@init { $namedValue = null; }:
(	a = pr_NamedNumber { if($a.namedValue != null) { $namedValues.addNamedValue($a.namedValue); }}
	(
		COMMA
		b = pr_NamedNumber { if($b.namedValue != null) { $namedValues.addNamedValue($b.namedValue); }}
	)*
);

pr_NamedNumber returns [NamedValue namedValue]
@init { Value value = null; $namedValue = null; }:
(	
	a = LOWERIDENTIFIER
	LPAREN
	(
		b = pr_SignedNumber { value = $b.value; }
	|	c = pr_DefinedValue { value = $c.value; }
	)
	endcol = RPAREN
)
{
1147
	Identifier identifier = new Identifier(Identifier_type.ID_ASN, $a.getText(), getLocation($a, $a));
Elemer Lelik's avatar
Elemer Lelik committed
1148
	$namedValue = new NamedValue(identifier, value);
1149
	$namedValue.setLocation(getLocation($a, $endcol == null ? $a : $endcol));
Elemer Lelik's avatar
Elemer Lelik committed
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
};

pr_SignedNumber returns[Integer_Value value]
@init {	$value = null; }:
(
	a = MINUS
	b = pr_Val_Number { $value = $b.value; $value.changeSign(); }
|	c = pr_Val_Number { $value = $c.value; }
);

pr_DefinedValue returns[Referenced_Value value]:
pr_DefdLower
{
	$value = new Referenced_Value($pr_DefdLower.reference);
1164
	$value.setLocation(getLocation($start, $pr_DefdLower.stop));
Elemer Lelik's avatar
Elemer Lelik committed
1165
1166
1167
1168
1169
1170
1171
};

pr_Val_Number returns[Integer_Value value]
@init { $value = null; }:
a = NUMBER
{
	$value = new Integer_Value($a.getText());
1172
	$value.setLocation(getLocation($start, $a));
Elemer Lelik's avatar
Elemer Lelik committed
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
};


pr_DefdLower returns [Defined_Reference reference]
@init { Defined_Reference simpleReference = null; $reference = null;}:
(	
	(
		startcol1 = pr_ExtLowerRef	{ simpleReference = $startcol1.reference; }	//pr_SimplDefdLower
	|	startcol2 = pr_LowerRef		{ simpleReference = $startcol2.reference; }	//pr_SimplDefdLower
	)
	(	
		b = BLOCK  //pr_PardLower
	)?
)
{
	if($b == null) {
		$reference = simpleReference;
	} else if (simpleReference != null){
Elemer Lelik's avatar
Elemer Lelik committed
1191
		$reference =  new Parameterised_Reference(simpleReference, new Block($b));
Elemer Lelik's avatar
Elemer Lelik committed
1192
1193
	}
	if($reference != null) {
1194
		$reference.setLocation(getLocation($start, $b == null ? $start: $b));
Elemer Lelik's avatar
Elemer Lelik committed
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
	}
};

pr_ExtLowerRef returns [Defined_Reference reference]
@init { Identifier id1 = null; Identifier id2 = null; $reference = null; }:
(	
	a = UPPERIDENTIFIER
	DOT
	b = LOWERIDENTIFIER
)
{
1206
	id1 = new Identifier(Identifier_type.ID_ASN, $a.getText(), getLocation($a, $a));
Elemer Lelik's avatar
Elemer Lelik committed
1207
	$reference = new Defined_Reference(id1);
1208
1209
	FieldSubReference subReference = new FieldSubReference(new Identifier(Identifier_type.ID_ASN, $b.getText(), getLocation($b, $b)));
	subReference.setLocation(getLocation($b, $b));
Elemer Lelik's avatar
Elemer Lelik committed
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
	$reference.addSubReference(subReference);
};

pr_LowerRef returns [Defined_Reference reference]
locals [Identifier id]
@init { $id = null; $reference = null; }:
(  
	a = LOWERIDENTIFIER
)
{
1220
	$id = new Identifier(Identifier_type.ID_ASN, $a.getText(), getLocation($a, $a));
Elemer Lelik's avatar
Elemer Lelik committed
1221
	FieldSubReference subReference = new FieldSubReference($id);
1222
	subReference.setLocation(getLocation($a, $a));
Elemer Lelik's avatar
Elemer Lelik committed
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
	ArrayList<ISubReference> subreferences = new ArrayList<ISubReference>();
	subreferences.add(subReference);
	$reference = new Defined_Reference(null, subreferences);
};

pr_Type returns [ASN1Type type]
locals [Type subType, NamedType_Helper namedType_Helper, Constraint constraint, Constraints constraints]
@init { $subType = null; $namedType_Helper = null; $constraint = null; $constraints = null; $type = null; }:
(	
	(	
		(	
			set = 		SET
		|	sequence =	SEQUENCE
		)
		(
			c1 = pr_Constraint { $constraint = $c1.constraint; }
		|	c2 = pr_SizeConstraint { $constraint = $c2.constraint; }
		)?  // pr_ConstrainedType if exists, pr_NakedType if not
		OF
		(
			(
				namedTypecol = pr_NamedType 
				{
					$namedType_Helper = $namedTypecol.helper;
					$subType = $namedType_Helper.type;
				}
			|	subTypecol = pr_Type
				{
					$subType = $subTypecol.type;
				}
			)   // pr_SeqOfSetOfWithConstraint, pr_SequenceOfType, pr_SetOfType
		)
		{
			if ($set != null) {
				$type = new SetOf_Type($subType);
1258
				$type.setLocation(getLocation($set, $namedTypecol.stop != null ? $namedTypecol.stop : $subTypecol.stop));
Elemer Lelik's avatar
Elemer Lelik committed
1259
1260
			} else if ($sequence != null) {
				$type = new SequenceOf_Type($subType);
1261
				$type.setLocation(getLocation($sequence, $namedTypecol.stop != null ? $namedTypecol.stop : $subTypecol.stop));
Elemer Lelik's avatar
Elemer Lelik committed
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
			}
			if ($constraint != null && $type != null) {
				$constraints = new Constraints();
				$constraints.addConstraint($constraint);
				$type.addConstraints($constraints);
			}
		}
	)
|	(
		(	
			builtin = pr_BuiltinType_reg 
			{
				$type = $builtin.type;
1275
				$type.setLocation(getLocation($builtin.start, $builtin.stop));
Elemer Lelik's avatar
Elemer Lelik committed
1276
1277
1278
1279
			}
		|	referenced = pr_ReferencedType
			{	
				$type = $referenced.type;
1280
				$type.setLocation(getLocation($referenced.start, $referenced.stop));
Elemer Lelik's avatar
Elemer Lelik committed
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
			}
		)//pr_NakedType_reg
		(
			a = pr_Constraints
			{
				$constraints = $a.constraints;
				$type.addConstraints($constraints);
			}// pr_ConstrainedType if exists, pr_NakedType if not
		)?
	)
|	pr_Tag
	b = pr_Type { $type = $b.type; }
);

pr_SizeConstraint returns[Constraint constraint]
@init { $constraint = null; }:
(	
	SIZE
Elemer Lelik's avatar
Elemer Lelik committed
1299
	a = pr_Constraint { $constraint = $a.constraint; }
Elemer Lelik's avatar
Elemer Lelik committed
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
);

pr_Constraint returns[Constraint constraint]
locals [ExceptionSpecification exceptionSpecfication]
@init { $exceptionSpecfication = null; $constraint = null; }:
(	
	LPAREN
	a = pr_ConstraintSpec	{ $constraint = $a.constraint; }
	b = pr_ExceptionSpec	{ $exceptionSpecfication = $b.exceptionSpecification; }
	RPAREN
);

pr_ConstraintSpec returns[Constraint constraint]
@init { $constraint = null; }:
(
	a = pr_GeneralConstraint { $constraint = $a.constraint; }
|	b = pr_SubtypeConstraint { $constraint = $b.constraint; }
);

pr_GeneralConstraint returns[Constraint constraint]
@init { $constraint = null; }:
(	
	a = pr_UserDefinedConstraint{ $constraint = $a.constraint; }
|	b = pr_TableConstraint		{ $constraint = $b.constraint; }
|	c = pr_ContentsConstraint	{ $constraint = $c.constraint; }
);

pr_NamedType returns [NamedType_Helper helper]
@init { ASN1Type type = null; $helper = new NamedType_Helper(); }:
(	
	a = LOWERIDENTIFIER
	b = pr_Type { type = $b.type; }
)
{
1334
	$helper.identifier = new Identifier(Identifier_type.ID_ASN, $a.getText(), getLocation($a, $a));
Elemer Lelik's avatar
Elemer Lelik committed
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
	$helper.type = type;
};

pr_Object returns [ASN1Object object]
@init { $object = null; }:
(	
	a = pr_DefinedObject	{ $object = $a.object; }
|	b = pr_ObjectDefn		{ $object = $b.object; }
);

pr_ObjectSet  returns [ObjectSet objectSet]
@init { $objectSet = null; }:
(
 	block = BLOCK
)
{
Elemer Lelik's avatar
Elemer Lelik committed
1351
	$objectSet = new ObjectSet_definition( new Block($block) );
1352
	$objectSet.setLocation(getLocation($block, $block));
Elemer Lelik's avatar
Elemer Lelik committed
1353
1354
1355
1356
1357
1358
1359
1360
};

pr_BuiltinValue returns[Value value]
@init { $value = null; }:
(	
	a = pr_BuiltinValue_reg	{ $value = $a.value; }
|	b = pr_NullValue		{ $value = $b.value; }
|	c = pr_LowerIdValue		{ $value = $c.value; }
Elemer Lelik's avatar
Elemer Lelik committed
1361
|	block = BLOCK { $value = new Undefined_Block_Value(new Block($block)); }
Elemer Lelik's avatar
Elemer Lelik committed
1362
1363
);

1364
pr_ReferencedValue_reg returns[Value value]
Elemer Lelik's avatar
Elemer Lelik committed
1365
1366
1367
1368
1369
1370
locals [Reference reference]
@init { $reference = null; $value = null; }:
(	
	a = pr_RefdLower_reg { $reference = $a.reference; }
)
{
1371
1372
1373
1374
1375
1376
	if ($reference != null && $reference.getModuleIdentifier() == null && $reference.getSubreferences().size() == 1) {
		Identifier identifier = $reference.getId();
		$value = new Undefined_LowerIdentifier_Value(identifier);
	} else {
		$value = new Referenced_Value($reference);
	}
1377
	$value.setLocation(getLocation($a.start, $a.stop));
Elemer Lelik's avatar
Elemer Lelik committed
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
};

pr_BuiltinType_reg returns [ASN1Type type]
@init { $type = null; }:
(	a = pr_NullType				{ $type = $a.type; }
|	b = pr_BitStringType		{ $type = $b.type; }
|	c = pr_BooleanType			{ $type = $c.type; }
|	d = pr_CharacterStringType	{ $type = $d.type; }
|	e = pr_ChoiceType			{ $type = $e.type; }
|	f = pr_SelectionType		{ $type = $f.type; }
|	g = pr_EnumeratedType		{ $type = $g.type; }
|	h = pr_IntegerType			{ $type = $h.type; }
|	i = pr_ObjectIdentifierType	{ $type = $i.type; }
|	j = pr_RelativeOIDType		{ $type = $j.type; }
|	k = pr_OctetStringType		{ $type = $k.type; }
|	l = pr_RealType				{ $type = $l.type; }
|	m = pr_SequenceType			{ $type = $m.type; }
|	n = pr_SetType				{ $type = $n.type; }
|	o = pr_EmbeddedPDVType		{ $type = $o.type; }
|	p = pr_ExternalType			{ $type = $p.type; }
|	q = pr_AnyType				{ $type = $q.type; }
|	r = pr_UsefulType			{ $type = $r.type; }
);

pr_ReferencedType returns [Referenced_Type type]
locals [Reference reference]
@init { $reference = null; }:
(	
	 a = pr_RefUpper { $reference = $a.reference; }
)
{
	$type = new Referenced_Type($reference);
1410
	$type.setLocation(getLocation($a.start, $a.stop));
Elemer Lelik's avatar
Elemer Lelik committed
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
};

pr_Constraints returns[Constraints constraints]
locals [Constraint constraint]
@init { $constraint = null; $constraints = new Constraints(); }:
(	
	a = pr_Constraint
	{
		$constraint = $a.constraint;
		$constraints.addConstraint($constraint);
	}
)+;

pr_Tag:
(
	SQUAREOPEN
	pr_Class
	pr_ClassNumber
	SQUARECLOSE
	(	
		IMPLICIT
	|	EXPLICIT
	)?
);

pr_ExceptionSpec returns [ExceptionSpecification exceptionSpecification]
@init { $exceptionSpecification = null; }:
(
	EXCLAMATION
	a = pr_ExceptionIdentification { $exceptionSpecification = $a.exceptionSpecification; }
)?;

pr_SubtypeConstraint returns[Constraint constraint]
@init { $constraint = null; }:
(
	a = pr_ElementSetSpecs { $constraint = $a.constraint; }
);

// NOT YET SUPPORTED IN SEMANTIC CHECKING
pr_UserDefinedConstraint returns[Constraint constraint]
@init { $constraint = null; }:
(
	CONSTRAINED
	BY
	BLOCK
);

pr_TableConstraint returns[TableConstraint constraint]
@init { $constraint = null; }:
(
	a = pr_ComponentRelationConstraint { $constraint = $a.constraint; }
);

// NOT YET SUPPORTED IN SEMANTIC CHECKING
pr_ContentsConstraint returns[Constraint constraint]
@init {ASN1Type type = null; Value value = null; $constraint = null; }:
(	
	CONTAINING
	a = pr_Type			{ type = $a.type; }
	(	
		ENCODED BY
		b = pr_Value	{ value = $b.value; }
	)?
|	ENCODED
	BY
	c = pr_Value		{ value = $c.value; }
);

pr_DefinedObject returns [ReferencedObject object]
@init { Reference reference = null; $object = null; }:
(
	a = pr_RefdLower { reference = $a.reference; }
)
{
	$object = new ReferencedObject(reference); 
};

pr_ObjectDefn returns [Object_Definition object]
@init { $object = null; }:
(
	block = BLOCK
)
{
Elemer Lelik's avatar
Elemer Lelik committed
1494
	$object = new Object_Definition( new Block($block) );
1495
	$object.setLocation(getLocation($block, $block));
Elemer Lelik's avatar
Elemer Lelik committed
1496
1497
1498
1499
1500
1501
1502
1503
};

pr_BuiltinValue_reg returns[Value value]
@init { $value = null; }:
(	
	a = BSTRING
	{
		$value = new Bitstring_Value($a.getText());
1504
		$value.setLocation(getLocation($a, $a));
Elemer Lelik's avatar
Elemer Lelik committed
1505
1506
1507
1508
	}
|	b = HSTRING
	{
		$value = new Hexstring_Value($b.getText());
1509
		$value.setLocation(getLocation($b, $b));
Elemer Lelik's avatar
Elemer Lelik committed
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
	}
|	c = pr_Val_CString	{ $value = $c.value; }
|	d = pr_BooleanValue	{ $value = $d.value; }
|	e = pr_ChoiceValue	{ $value = $e.value; }
|	(	
		f1 = MINUS
		(	
			f10 = pr_Val_Number
			{
				$value = $f10.value;
				((Integer_Value)$value).changeSign();
			}
		|	f11 = REALNUMBER	
			{
				$value = new Real_Value(Float.parseFloat( $f11.getText()));
1525
				$value.setLocation(getLocation($f11, $f11));
Elemer Lelik's avatar
Elemer Lelik committed
1526
1527
1528
1529
1530
1531
			}
		)
	|	(	f12 = pr_Val_Number	{ $value = $f12.value; }
		|	f13 = REALNUMBER
			{
				$value = new Real_Value(Float.parseFloat($f13.getText()));
1532
				$value.setLocation(getLocation($f13, $f13));
Elemer Lelik's avatar
Elemer Lelik committed
1533
1534
1535
1536
1537
1538
			}
		)
	)
|	g = PLUS_INFINITY
	{
		$value = new Real_Value(Float.POSITIVE_INFINITY);
1539
		$value.setLocation(getLocation($g, $g));
Elemer Lelik's avatar
Elemer Lelik committed
1540
1541
1542
1543
	}
|	h = MINUS_INFINITY
	{
		$value = new Real_Value(Float.NEGATIVE_INFINITY);
1544
		$value.setLocation(getLocation($h, $h));
Elemer Lelik's avatar
Elemer Lelik committed
1545
1546
1547
1548
	}
|   i = NOT_A_NUMBER
	{
		$value = new Real_Value(Float.NaN);
1549
		$value.setLocation(getLocation($i, $i));
Elemer Lelik's avatar
Elemer Lelik committed
1550
1551
1552
1553
1554
1555
1556
1557
	}
);

pr_NullValue returns[ASN1_Null_Value value]
@init { $value = null; }:
	NULL
{
	$value = new ASN1_Null_Value();
1558
	$value.setLocation(getLocation($start, $start));
Elemer Lelik's avatar
Elemer Lelik committed
1559
1560
1561
1562
1563
1564
};

pr_LowerIdValue returns[Undefined_LowerIdentifier_Value value]
@init { $value = null; }:
	a = LOWERIDENTIFIER
{
1565
	Location location = getLocation($a, $a);
Elemer Lelik's avatar
Elemer Lelik committed
1566
1567
	Identifier identifier = new Identifier(Identifier_type.ID_ASN,  $a.getText(), location);
	$value = new Undefined_LowerIdentifier_Value(identifier);
1568
	$value.setLocation(getLocation($a, $a));
Elemer Lelik's avatar
Elemer Lelik committed
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
};

pr_RefdLower_reg returns [Reference reference]
locals [Defined_Reference tempReference]
@init { $tempReference = null; $reference = null; }:
(	
	(
		a = pr_LowerRef		{ $tempReference = $a.reference; }
	|	b = pr_ExtLowerRef	{ $tempReference = $b.reference; }
	)
	(
		BLOCK //pr_PardLower
	)?
	(	
		DOT
		pr_FieldNameLower //pr_LowerFromObj
	|	{ $reference = $tempReference; }
	)
);

pr_NullType returns [NULL_Type type]
@init { $type = null; }:
(	
	NULL)
{
	$type = new NULL_Type();
1595
	$type.setLocation(getLocation($start, $start));
Elemer Lelik's avatar
Elemer Lelik committed
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
};

pr_BitStringType returns [ASN1_BitString_Type type]
locals [Token endCol]
@init { $type = null; }:
(
	a = BIT
	b = STRING	{ $endCol = $b; }
	(
		c = BLOCK { $endCol = $c; }
	)?
)
{
Elemer Lelik's avatar
Elemer Lelik committed
1609
	$type = new ASN1_BitString_Type($c != null ? new Block($c):null);
1610
	$type.setLocation(getLocation($a, $endCol));
Elemer Lelik's avatar
Elemer Lelik committed
1611
1612
1613
1614
1615
1616
1617
1618
1619
};

pr_BooleanType returns [Boolean_Type type]
@init { $type = null; }:
(
	BOOLEAN
)
{
	$type = new Boolean_Type();
1620
	$type.setLocation(getLocation($start,  $start));
Elemer Lelik's avatar
Elemer Lelik committed
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
};

pr_CharacterStringType returns [ASN1Type type]
@init { $type = null; }:
(	
	a = pr_RestrictedCharacterStringType	{ $type = $a.type; }
|	b = pr_UnrestrictedCharacterStringType	{ $type = $b.type; }
);

pr_ChoiceType returns [ASN1_Choice_Type type]
@init { $type = null; }:
(	
	CHOICE
	endCol = BLOCK
)
{
Elemer Lelik's avatar
Elemer Lelik committed
1637
	$type = new ASN1_Choice_Type($endCol != null ? new Block($endCol) : null);
1638
	$type.setLocation(getLocation($start, $endCol));
Elemer Lelik's avatar
Elemer Lelik committed
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
};

pr_SelectionTypeType returns [ASN1Type type]
@init { $type = null; }:
(	a = pr_ReferencedType		{ $type = $a.type; }
|	b = pr_ChoiceType			{ $type = $b.type; }
|	c = pr_SelectionType		{ $type = $c.type; }
|	pr_Tag
	d = pr_SelectionTypeType	{ $type = $d.type; }
);

pr_SelectionType returns [Selection_Type type]
@init { $type = null; }:
(
	LOWERIDENTIFIER
	LESSTHAN
	a = pr_SelectionTypeType
)
{
1658
	Identifier identifier = new Identifier(Identifier_type.ID_ASN, $start.getText(), getLocation($start, $start));
Elemer Lelik's avatar
Elemer Lelik committed
1659
	$type = new Selection_Type(identifier, $a.type);
1660
	$type.setLocation(getLocation($start, $a.stop));
Elemer Lelik's avatar
Elemer Lelik committed
1661
1662
1663
1664
1665
1666
1667
1668
1669
};

pr_EnumeratedType returns [ASN1_Enumerated_Type type]
@init { $type = null; }:
(	
	ENUMERATED
	block = BLOCK
)
{
Elemer Lelik's avatar
Elemer Lelik committed
1670
	$type = new ASN1_Enumerated_Type($block != null ? new Block($block) : null);
1671
	$type.setLocation(getLocation($start, $block));
Elemer Lelik's avatar
Elemer Lelik committed
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
};

pr_IntegerType returns [ASN1_Integer_Type type]
@init { $type = null; }:
(
	a = INTEGER
	(
		b = BLOCK
	)?
)
{
Elemer Lelik's avatar
Elemer Lelik committed
1683
	$type = new ASN1_Integer_Type($b != null ? new Block($b) : null);
1684
	$type.setLocation(getLocation($start, $b == null ? $start:$b));
Elemer Lelik's avatar
Elemer Lelik committed
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
};

pr_ObjectIdentifierType returns [ObjectID_Type type]
@init { $type = null; }:
(
	OBJECT
	a = IDENTIFIER
)
{
	$type = new ObjectID_Type();
1695
	$type.setLocation(getLocation($start, $a));
Elemer Lelik's avatar
Elemer Lelik committed
1696
1697
1698
1699
1700
1701
1702
1703
1704
};

pr_RelativeOIDType returns [RelativeObjectIdentifier_Type type]
@init { $type = null; }:
(
	RELATIVE_OID
)
{
	$type = new RelativeObjectIdentifier_Type();
1705
	$type.setLocation(getLocation($start, $start));
Elemer Lelik's avatar
Elemer Lelik committed
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
};

pr_OctetStringType returns [OctetString_Type type]
@init { $type = null; }:
(	
	OCTET
	a = STRING
)
{
	$type = new OctetString_Type();
1716
	$type.setLocation(getLocation($start, $a));
Elemer Lelik's avatar
Elemer Lelik committed
1717
1718
1719
1720
1721
1722
1723
1724
1725
};

pr_RealType returns[Float_Type type]
@init { $type = null; }:
(
	REAL
)
{
	$type = new Float_Type();
1726
	$type.setLocation(getLocation($start,  $start));
Elemer Lelik's avatar
Elemer Lelik committed
1727
1728
1729
1730
1731
1732
1733
1734
1735
};

pr_SequenceType returns [ASN1_Sequence_Type type]
@init { $type = null; }:
(	
	SEQUENCE
	block = BLOCK
)
{
Elemer Lelik's avatar
Elemer Lelik committed
1736
	$type = new ASN1_Sequence_Type($block != null ? new Block($block):null);
Elemer Lelik's avatar
Elemer Lelik committed
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
	$type.setLocation(getLocation($start, $block));
};

pr_SetType returns [ASN1_Set_Type type]
@init { $type = null; }:
(	
	SET
	block = BLOCK
)
{
Elemer Lelik's avatar
Elemer Lelik committed
1747
	$type = new ASN1_Set_Type($block != null ? new Block($block):null);
1748
	$type.setLocation(getLocation($start, $block));
Elemer Lelik's avatar
Elemer Lelik committed
1749
1750
1751
1752
1753
1754
1755
1756
1757
};

pr_EmbeddedPDVType returns [Embedded_PDV_Type type]
@init { $type = null; }:
(
	EMBEDDED PDV
)
{
	$type = new Embedded_PDV_Type();
1758
	$type.setLocation(getLocation($start,  $start));
Elemer Lelik's avatar
Elemer Lelik committed
1759
1760
1761
1762
1763
1764
1765
1766
1767
};

pr_ExternalType returns [External_Type type]
@init { $type = null; }:
(
	EXTERNAL
)
{
	$type = new External_Type();
1768
	$type.setLocation(getLocation($start,  $start));
Elemer Lelik's avatar
Elemer Lelik committed
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
};

pr_AnyType returns [Any_Type type]
locals [Token endCol]
@init { $type = null; }:
(
	a = ANY { $endCol = $a; }
	(	
		DEFINED BY
		b = LOWERIDENTIFIER { $endCol = $b; }
	)?
)
{
	$type = new Any_Type();
1783
	$type.setLocation(getLocation($a, $endCol));
Elemer Lelik's avatar
Elemer Lelik committed
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
};

pr_UsefulType returns [ASN1Type type]
locals [Token col]
@init { $type = null;}:
(	
	a = GENERALIZEDTIME		{ $type = new GeneralizedTime_Type(); $col = $a;}
|	b = UTCTIME				{ $type = new UTCTime_Type(); $col = $b;}
|	c = OBJECTDESCRIPTOR	{ $type = new ObjectDescriptor_Type(); $col = $c;}
)
{
	if ($type != null) {
1796
		$type.setLocation(getLocation($col, $col));
Elemer Lelik's avatar
Elemer Lelik committed
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
	}
};

pr_RefUpper returns [Reference reference]
@init { $reference = null; }:
(	
	a = pr_FromObjs		{ $reference = $a.fromObj; }
|	b = pr_UpperFromObj	{ $reference = $b.fromObj; }
|	c = pr_DefdUpper	{ $reference = $c.reference; }
);

pr_Class:
(	
	UNIVERSAL
|	APPLICATION
|	PRIVATE
)?;

pr_ClassNumber:
(
	pr_Val_Number
|	pr_DefinedValue
);

pr_ExceptionIdentification returns [ExceptionSpecification exceptionSpecification]
@init { ASN1Type type = null; Value value = null; $exceptionSpecification = null; }:
(	
	a = pr_SignedNumber
	{
		if ($a.value != null) { $exceptionSpecification = new ExceptionSpecification(null, $a.value); }
	}
|	b = pr_Type
	COLON
	c = pr_Value
	{
		if($c.value != null) { $exceptionSpecification = new ExceptionSpecification($b.type, $c.value); }
	}
|	d = pr_DefinedValue
	{
		if($d.value != null) { $exceptionSpecification = new ExceptionSpecification(null, $d.value); }
	}
);

pr_ComponentRelationConstraint returns[TableConstraint constraint]
@init { $constraint = null; }:
(
	objectSetBlock = BLOCK
	atNotationsBlock = BLOCK
)
{
Elemer Lelik's avatar
Elemer Lelik committed
1847
	$constraint = new TableConstraint(new Block($objectSetBlock), new Block($atNotationsBlock));
Elemer Lelik's avatar
Elemer Lelik committed
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
};

pr_Value returns[Value value]
@init { $value = null; }:
(
	a = pr_ObjectClassFieldValue { $value = $a.value; }
);

pr_RefdLower returns [Reference reference]
@init {
	Defined_Reference definedReference = null;
	FieldName field = null;
	$reference = null;
}:
(
	a = pr_DefdLower 
	(
		DOT
		b = pr_FieldNameLower //	pr_LowerFromObj
			{
Elemer Lelik's avatar
Elemer Lelik committed
1868
				$reference = new InformationFromObj($a.reference, $b.fieldName);
Elemer Lelik's avatar
Elemer Lelik committed
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
			}
	|	{ $reference = $a.reference; }
	)
);

pr_Val_CString returns[Charstring_Value value]
@init { $value = null; }:
	CSTRING
{
	$value = new Charstring_Value($start.getText());
1879
	$value.setLocation(getLocation($start, $start));
Elemer Lelik's avatar
Elemer Lelik committed
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
};

pr_BooleanValue returns[Boolean_Value value]
locals [Token col]
@init { $value = null; }:
(
	a = TRUE	{ $col = $a; $value = new Boolean_Value(true); }
|	b = FALSE	{ $col = $b; $value = new Boolean_Value(false); }
)
{
	if ($value != null) {
1891
		$value.setLocation(getLocation($col, $col));
Elemer Lelik's avatar
Elemer Lelik committed
1892
1893
1894
1895
	}
};

pr_ChoiceValue returns [Choice_Value value]
Elemer Lelik's avatar
Elemer Lelik committed
1896
@init {Identifier identifier = null; $value = null; }:
Elemer Lelik's avatar
Elemer Lelik committed
1897
1898
1899
1900
1901
1902
(
	LOWERIDENTIFIER
	COLON
	a = pr_Value
)
{
1903
	identifier = new Identifier(Identifier_type.ID_ASN, $start.getText(), getLocation($start, $start));
Elemer Lelik's avatar
Elemer Lelik committed
1904
	if ($a.value != null) {
Elemer Lelik's avatar
Elemer Lelik committed
1905
		$value = new Choice_Value(identifier, $a.value);
1906
		$value.setLocation(getLocation($start, $a.stop));
Elemer Lelik's avatar
Elemer Lelik committed
1907
1908
1909
1910
1911
1912
1913
1914
	}
};

pr_FieldNameLower returns [FieldName fieldName]
@init { $fieldName = new FieldName(); }:
(
	a = AMPLOWERIDENTIFIER
		{
1915
			Location location1 = getLocation($a, $a);
Elemer Lelik's avatar
Elemer Lelik committed
1916
1917
1918
1919
1920
1921
1922
			Identifier identifier1 = new Identifier(Identifier_type.ID_ASN, $a.getText(), location1);
			$fieldName.addField(identifier1);
		}
	(
		DOT
		b = AMPLOWERIDENTIFIER
		{
1923
			Location location2 = getLocation($b, $b);
Elemer Lelik's avatar
Elemer Lelik committed
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
			Identifier identifier2 = new Identifier(Identifier_type.ID_ASN, $b.getText(), location2);
			$fieldName.addField(identifier2);
		}
	)*
);

pr_RestrictedCharacterStringType returns [ASN1Type type]
@init { $type = null; }:
(	a = pr_GeneralString	{ $type = $a.type; }
|	b = pr_BMPString		{ $type = $b.type; }
|	c = pr_GraphicString	{ $type = $c.type; }
|	d = pr_IA5String		{ $type = $d.type; }
|	e = pr_NumericString	{ $type = $e.type; }
|	f = pr_PrintableString	{ $type = $f.type; }
|	g = pr_TeletexString	{ $type = $g.type; }
|	h = pr_UniversalString	{ $type = $h.type; }
|	i = pr_UTF8String		{ $type = $i.type; }
|	j = pr_VideoTextString	{ $type = $j.type; }
|	k = pr_VisibleString	{ $type = $k.type; }
);

pr_RestrictedCharacterStringValue:
(
	CSTRING
|	pr_CharacterStringList
|	pr_Quadruple
|	pr_Tuple
);

pr_CharacterStringList:
(
	BEGINCHAR pr_CharSyms ENDCHAR
);

pr_CharSyms:
(
	pr_CharsDefn (COMMA pr_CharsDefn)*
);

pr_CharsDefn:
(
	CSTRING
|	pr_Quadruple
|	pr_Tuple
|	pr_DefinedValue // returns object ????
);

pr_Quadruple:
(
	BEGINCHAR pr_Group COMMA pr_Plane COMMA pr_Row COMMA pr_Cell ENDCHAR
);

pr_Group:
(
	NUMBER	
);

pr_Plane:
(
	NUMBER
);

pr_Row:
(
	NUMBER
);

pr_Cell:
(
	NUMBER
);

pr_Tuple:
(
	BEGINCHAR pr_TableColumn COMMA pr_TableRow ENDCHAR
);

pr_TableColumn:
(
	NUMBER
);

pr_TableRow:
(
	NUMBER
);

pr_UnrestrictedCharacterStringType returns [UnrestrictedString_Type type]
@init { $type = null; }:
(
	CHARACTER
	a = STRING
)
{
	$type = new UnrestrictedString_Type();
2019
	$type.setLocation(getLocation($start, $a));
Elemer Lelik's avatar
Elemer Lelik committed
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
};

pr_FromObjs returns [InformationFromObj fromObj]
@init { $fromObj = null; }:
(
	a = pr_Lower_FromObjs	{ $fromObj = $a.fromObj; }
|	b = pr_Upper_FromObjs	{ $fromObj = $b.fromObj; }
);

pr_UpperFromObj returns [InformationFromObj fromObj]
@init { $fromObj = null; }:
(	
	a = pr_DefdLower
	DOT
	b = pr_FieldNameUpper
)
{
Elemer Lelik's avatar
Elemer Lelik committed
2037
	$fromObj = new InformationFromObj($a.reference, $b.fieldName);
2038
	$fromObj.setLocation(getLocation($a.start, $b.stop));
Elemer Lelik's avatar
Elemer Lelik committed
2039
2040
2041
2042
2043
2044
2045
2046
2047
};

pr_DefdUpper returns [Reference reference]
@init { $reference = null; }:
(
	a = pr_SimplDefdUpper
	(	
		block = BLOCK
		{
Elemer Lelik's avatar
Elemer Lelik committed
2048
			if($a.reference != null) { $reference = new Parameterised_Reference($a.reference, $block != null ? new Block($block):null); }
Elemer Lelik's avatar
Elemer Lelik committed
2049
2050
2051
2052
2053
2054
		}
	|	{ $reference = $a.reference; }
	)
)
{
	if($reference != null){
2055
		$reference.setLocation(getLocation($a.start, $block != null ? $block:$a.stop));
Elemer Lelik's avatar
Elemer Lelik committed
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
	}
};

pr_RootElementSetSpec returns[Constraint constraint]
@init { $constraint = null; }:
(
	a = pr_ElementSetSpec { $constraint = $a.constraint; }
);

pr_AdditionalElementSetSpec:
(
	pr_ElementSetSpec
);

pr_ObjectClassFieldValue returns[Value value]
@init { $value = null; }:
(
	a = pr_FixedTypeFieldValue { $value = $a.value; }
);

pr_GeneralString returns [GeneralString_Type type]
@init { $type = null; }:
(	
	GENERALSTRING
)
{
	$type = new GeneralString_Type();
2083
	$type.setLocation(getLocation($start, $start));
Elemer Lelik's avatar
Elemer Lelik committed
2084
2085
2086
2087
2088
2089
2090
2091
2092
};

pr_BMPString returns [BMPString_Type type]
@init { $type = null; }:
(	
	BMPSTRING
)
{
	$type = new BMPString_Type();
2093
	$type.setLocation(getLocation($start, $start));
Elemer Lelik's avatar
Elemer Lelik committed
2094
2095
2096
2097
2098
2099
2100
2101
2102
};

pr_GraphicString returns [GraphicString_Type type]
@init { $type = null; }:
(
	GRAPHICSTRING
)
{
	$type = new GraphicString_Type();
2103
	$type.setLocation(getLocation($start, $start));
Elemer Lelik's avatar
Elemer Lelik committed
2104
2105
2106
2107
2108
2109
2110
2111
2112
};

pr_IA5String returns [IA5String_Type type]
@init { $type = null; }:
(
	IA5STRING
)
{
	$type = new IA5String_Type();
2113
	$type.setLocation(getLocation($start, $start));
Elemer Lelik's avatar
Elemer Lelik committed
2114
2115
2116
2117
2118
2119
2120
2121
2122
};

pr_NumericString returns [NumericString_Type type]
@init { $type = null; }:
(	
	NUMERICSTRING
)
{
	$type = new NumericString_Type();
2123
	$type.setLocation(getLocation($start, $start));
Elemer Lelik's avatar
Elemer Lelik committed
2124
2125
2126
2127
2128
2129
2130
2131
2132
};

pr_PrintableString returns [PrintableString_Type type]
@init { $type = null; }:
(	
	PRINTABLESTRING
)
{
	$type = new PrintableString_Type();
2133
	$type.setLocation(getLocation($start, $start));
Elemer Lelik's avatar
Elemer Lelik committed
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
};

pr_TeletexString returns [TeletexString_Type type]
@init { $type = null; }:
(	
	TELETEXSTRING
|	T61STRING
)
{
	$type = new TeletexString_Type();
2144
	$type.setLocation(getLocation($start, $start));
Elemer Lelik's avatar
Elemer Lelik committed
2145
2146
2147
2148