blob: aae339bb205817145d0750208d6004e4a83b6f83 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001%{
2
3#include <stdlib.h>
4#include <stdio.h>
5#include <string.h>
6#include <errno.h>
7#include <assert.h>
8
9#include "asn1parser.h"
10
11#define YYPARSE_PARAM param
Lev Walkin4354b442005-06-07 21:25:42 +000012#define YYPARSE_PARAM_TYPE void **
Lev Walkinf15320b2004-06-03 03:38:44 +000013#define YYERROR_VERBOSE
14
15int yylex(void);
16int yyerror(const char *msg);
Lev Walkin8daab912005-06-07 21:32:16 +000017#ifdef YYBYACC
18int yyparse(void **param); /* byacc does not produce a prototype */
19#endif
Lev Walkinf15320b2004-06-03 03:38:44 +000020void asn1p_lexer_hack_push_opaque_state(void);
21void asn1p_lexer_hack_enable_with_syntax(void);
Lev Walkinf59d0752004-08-18 04:59:12 +000022void asn1p_lexer_hack_push_encoding_control(void);
Lev Walkinf15320b2004-06-03 03:38:44 +000023#define yylineno asn1p_lineno
24extern int asn1p_lineno;
25
Lev Walkin1ed22092005-08-12 10:06:17 +000026/*
Lev Walkinef625402005-09-05 05:17:57 +000027 * Process directives as <ASN1C:RepresentAsPointer>
Lev Walkin4696c742005-08-22 12:23:54 +000028 */
29extern int asn1p_as_pointer;
Lev Walkin4696c742005-08-22 12:23:54 +000030
31/*
Lev Walkin1ed22092005-08-12 10:06:17 +000032 * This temporary variable is used to solve the shortcomings of 1-lookahead
33 * parser.
34 */
35static struct AssignedIdentifier *saved_aid;
Lev Walkinf15320b2004-06-03 03:38:44 +000036
Lev Walkin2e9bd5c2005-08-13 09:07:11 +000037static asn1p_value_t *_convert_bitstring2binary(char *str, int base);
38static void _fixup_anonymous_identifier(asn1p_expr_t *expr);
Lev Walkinf15320b2004-06-03 03:38:44 +000039
Lev Walkina9532f42006-09-17 04:52:50 +000040static asn1p_module_t *currentModule;
41#define NEW_EXPR() (asn1p_expr_new(yylineno, currentModule))
42
Lev Walkin1ed22092005-08-12 10:06:17 +000043#define checkmem(ptr) do { \
44 if(!(ptr)) \
45 return yyerror("Memory failure"); \
Lev Walkinf15320b2004-06-03 03:38:44 +000046 } while(0)
47
Lev Walkin2c14a692005-08-12 10:08:45 +000048#define CONSTRAINT_INSERT(root, constr_type, arg1, arg2) do { \
Lev Walkin1ed22092005-08-12 10:06:17 +000049 if(arg1->type != constr_type) { \
50 int __ret; \
51 root = asn1p_constraint_new(yylineno); \
52 checkmem(root); \
53 root->type = constr_type; \
54 __ret = asn1p_constraint_insert(root, \
55 arg1); \
56 checkmem(__ret == 0); \
57 } else { \
58 root = arg1; \
59 } \
60 if(arg2) { \
61 int __ret \
62 = asn1p_constraint_insert(root, arg2); \
63 checkmem(__ret == 0); \
64 } \
Lev Walkinf15320b2004-06-03 03:38:44 +000065 } while(0)
66
Lev Walkin866bd7f2006-09-14 10:35:20 +000067#ifdef AL_IMPORT
68#error AL_IMPORT DEFINED ELSEWHERE!
69#endif
70#define AL_IMPORT(to,where,from,field) do { \
71 if(!(from)) break; \
72 while(TQ_FIRST(&((from)->where))) { \
73 TQ_ADD(&((to)->where), \
74 TQ_REMOVE(&((from)->where), field), \
75 field); \
76 } \
77 assert(TQ_FIRST(&((from)->where)) == 0); \
78 } while(0)
79
Lev Walkinf15320b2004-06-03 03:38:44 +000080%}
81
82
83/*
84 * Token value definition.
85 * a_*: ASN-specific types.
86 * tv_*: Locally meaningful types.
87 */
88%union {
89 asn1p_t *a_grammar;
90 asn1p_module_flags_e a_module_flags;
91 asn1p_module_t *a_module;
92 asn1p_expr_type_e a_type; /* ASN.1 Type */
93 asn1p_expr_t *a_expr; /* Constructed collection */
94 asn1p_constraint_t *a_constr; /* Constraint */
95 enum asn1p_constraint_type_e a_ctype;/* Constraint type */
96 asn1p_xports_t *a_xports; /* IMports/EXports */
Lev Walkin1ed22092005-08-12 10:06:17 +000097 struct AssignedIdentifier a_aid; /* Assigned Identifier */
Lev Walkinf15320b2004-06-03 03:38:44 +000098 asn1p_oid_t *a_oid; /* Object Identifier */
99 asn1p_oid_arc_t a_oid_arc; /* Single OID's arc */
100 struct asn1p_type_tag_s a_tag; /* A tag */
101 asn1p_ref_t *a_ref; /* Reference to custom type */
102 asn1p_wsyntx_t *a_wsynt; /* WITH SYNTAX contents */
103 asn1p_wsyntx_chunk_t *a_wchunk; /* WITH SYNTAX chunk */
104 struct asn1p_ref_component_s a_refcomp; /* Component of a reference */
105 asn1p_value_t *a_value; /* Number, DefinedValue, etc */
106 struct asn1p_param_s a_parg; /* A parameter argument */
107 asn1p_paramlist_t *a_plist; /* A pargs list */
Lev Walkin9c974182004-09-15 11:59:51 +0000108 struct asn1p_expr_marker_s a_marker; /* OPTIONAL/DEFAULT */
Lev Walkinf15320b2004-06-03 03:38:44 +0000109 enum asn1p_constr_pres_e a_pres; /* PRESENT/ABSENT/OPTIONAL */
Lev Walkin144db9b2004-10-12 23:26:53 +0000110 asn1c_integer_t a_int;
Lev Walkinadf863f2006-09-05 16:18:34 +0000111 double a_dbl;
Lev Walkinf15320b2004-06-03 03:38:44 +0000112 char *tv_str;
113 struct {
114 char *buf;
115 int len;
116 } tv_opaque;
117 struct {
118 char *name;
119 struct asn1p_type_tag_s tag;
120 } tv_nametag;
121};
122
123/*
124 * Token types returned by scanner.
125 */
126%token TOK_PPEQ /* "::=", Pseudo Pascal EQuality */
Lev Walkin0e90aa02013-03-19 16:17:13 -0700127%token TOK_VBracketLeft TOK_VBracketRight /* "[[", "]]" */
Lev Walkin57074f12006-03-16 05:11:14 +0000128%token <tv_opaque> TOK_whitespace /* A span of whitespace */
Lev Walkinf15320b2004-06-03 03:38:44 +0000129%token <tv_opaque> TOK_opaque /* opaque data (driven from .y) */
130%token <tv_str> TOK_bstring
131%token <tv_opaque> TOK_cstring
132%token <tv_str> TOK_hstring
133%token <tv_str> TOK_identifier
134%token <a_int> TOK_number
Lev Walkinadf863f2006-09-05 16:18:34 +0000135%token <a_int> TOK_number_negative
136%token <a_dbl> TOK_realnumber
Lev Walkind9574ae2005-03-24 16:22:35 +0000137%token <a_int> TOK_tuple
138%token <a_int> TOK_quadruple
Lev Walkinf15320b2004-06-03 03:38:44 +0000139%token <tv_str> TOK_typereference
Lev Walkinf59d0752004-08-18 04:59:12 +0000140%token <tv_str> TOK_capitalreference /* "CLASS1" */
Lev Walkinf15320b2004-06-03 03:38:44 +0000141%token <tv_str> TOK_typefieldreference /* "&Pork" */
142%token <tv_str> TOK_valuefieldreference /* "&id" */
Lev Walkin9d542d22006-03-14 16:31:37 +0000143%token <tv_str> TOK_Literal /* "BY" */
Lev Walkinf15320b2004-06-03 03:38:44 +0000144
145/*
146 * Token types representing ASN.1 standard keywords.
147 */
148%token TOK_ABSENT
149%token TOK_ABSTRACT_SYNTAX
150%token TOK_ALL
151%token TOK_ANY
152%token TOK_APPLICATION
153%token TOK_AUTOMATIC
154%token TOK_BEGIN
155%token TOK_BIT
156%token TOK_BMPString
157%token TOK_BOOLEAN
158%token TOK_BY
159%token TOK_CHARACTER
160%token TOK_CHOICE
161%token TOK_CLASS
162%token TOK_COMPONENT
163%token TOK_COMPONENTS
164%token TOK_CONSTRAINED
165%token TOK_CONTAINING
166%token TOK_DEFAULT
167%token TOK_DEFINITIONS
168%token TOK_DEFINED
169%token TOK_EMBEDDED
170%token TOK_ENCODED
Lev Walkinf59d0752004-08-18 04:59:12 +0000171%token TOK_ENCODING_CONTROL
Lev Walkinf15320b2004-06-03 03:38:44 +0000172%token TOK_END
173%token TOK_ENUMERATED
174%token TOK_EXPLICIT
175%token TOK_EXPORTS
176%token TOK_EXTENSIBILITY
177%token TOK_EXTERNAL
178%token TOK_FALSE
179%token TOK_FROM
180%token TOK_GeneralizedTime
181%token TOK_GeneralString
182%token TOK_GraphicString
183%token TOK_IA5String
184%token TOK_IDENTIFIER
185%token TOK_IMPLICIT
186%token TOK_IMPLIED
187%token TOK_IMPORTS
188%token TOK_INCLUDES
189%token TOK_INSTANCE
Lev Walkinf59d0752004-08-18 04:59:12 +0000190%token TOK_INSTRUCTIONS
Lev Walkinf15320b2004-06-03 03:38:44 +0000191%token TOK_INTEGER
192%token TOK_ISO646String
193%token TOK_MAX
194%token TOK_MIN
195%token TOK_MINUS_INFINITY
196%token TOK_NULL
197%token TOK_NumericString
198%token TOK_OBJECT
199%token TOK_ObjectDescriptor
200%token TOK_OCTET
201%token TOK_OF
202%token TOK_OPTIONAL
203%token TOK_PATTERN
204%token TOK_PDV
205%token TOK_PLUS_INFINITY
206%token TOK_PRESENT
207%token TOK_PrintableString
208%token TOK_PRIVATE
209%token TOK_REAL
210%token TOK_RELATIVE_OID
211%token TOK_SEQUENCE
212%token TOK_SET
213%token TOK_SIZE
214%token TOK_STRING
215%token TOK_SYNTAX
216%token TOK_T61String
217%token TOK_TAGS
218%token TOK_TeletexString
219%token TOK_TRUE
220%token TOK_TYPE_IDENTIFIER
221%token TOK_UNIQUE
222%token TOK_UNIVERSAL
223%token TOK_UniversalString
224%token TOK_UTCTime
225%token TOK_UTF8String
226%token TOK_VideotexString
227%token TOK_VisibleString
228%token TOK_WITH
229
Lev Walkinf1727152006-09-21 01:50:37 +0000230%nonassoc TOK_EXCEPT
Lev Walkinf59d0752004-08-18 04:59:12 +0000231%left '^' TOK_INTERSECTION
232%left '|' TOK_UNION
Lev Walkinf15320b2004-06-03 03:38:44 +0000233
234/* Misc tags */
235%token TOK_TwoDots /* .. */
236%token TOK_ThreeDots /* ... */
Lev Walkinf15320b2004-06-03 03:38:44 +0000237
238
239/*
240 * Types defined herein.
241 */
242%type <a_grammar> ModuleList
Lev Walkin866bd7f2006-09-14 10:35:20 +0000243%type <a_module> ModuleDefinition
244%type <a_module> ModuleBody
245%type <a_module> AssignmentList
246%type <a_module> Assignment
247%type <a_module> optModuleBody /* Optional */
248%type <a_module_flags> optModuleDefinitionFlags
249%type <a_module_flags> ModuleDefinitionFlags /* Set of FL */
250%type <a_module_flags> ModuleDefinitionFlag /* Single FL */
251%type <a_module> optImports
252%type <a_module> optExports
Lev Walkinf15320b2004-06-03 03:38:44 +0000253%type <a_module> ImportsDefinition
Lev Walkin4a4543f2006-10-13 12:37:39 +0000254%type <a_module> optImportsBundleSet
Lev Walkinf15320b2004-06-03 03:38:44 +0000255%type <a_module> ImportsBundleSet
256%type <a_xports> ImportsBundle
257%type <a_xports> ImportsList
258%type <a_xports> ExportsDefinition
259%type <a_xports> ExportsBody
260%type <a_expr> ImportsElement
261%type <a_expr> ExportsElement
Lev Walkinf15320b2004-06-03 03:38:44 +0000262%type <a_expr> ExtensionAndException
Lev Walkina9532f42006-09-17 04:52:50 +0000263%type <a_expr> Type
Lev Walkin070a52d2004-08-22 03:19:54 +0000264%type <a_expr> TypeDeclaration
Lev Walkin4696c742005-08-22 12:23:54 +0000265%type <a_expr> TypeDeclarationSet
Lev Walkinf15320b2004-06-03 03:38:44 +0000266%type <a_ref> ComplexTypeReference
267%type <a_ref> ComplexTypeReferenceAmpList
268%type <a_refcomp> ComplexTypeReferenceElement
Lev Walkind370e9f2006-03-16 10:03:35 +0000269%type <a_refcomp> PrimitiveFieldReference
Lev Walkin9c2285a2006-03-09 08:49:26 +0000270%type <a_expr> FieldSpec
271%type <a_ref> FieldName
272%type <a_ref> DefinedObjectClass
Lev Walkinf15320b2004-06-03 03:38:44 +0000273%type <a_expr> ClassField
Lev Walkin9c2285a2006-03-09 08:49:26 +0000274%type <a_expr> ObjectClass
Lev Walkinf15320b2004-06-03 03:38:44 +0000275%type <a_expr> DataTypeReference /* Type1 ::= Type2 */
Lev Walkin0c0bca62006-03-21 04:48:15 +0000276%type <a_expr> DefinedType
Lev Walkin557f27d2006-03-21 07:46:48 +0000277%type <a_constr> ValueSet /* {a|b|c}*/
278%type <a_expr> ValueSetTypeAssignment /* Val INTEGER ::= {1|2} */
Lev Walkinc6ab03c2006-10-21 05:54:49 +0000279%type <a_expr> ValueAssignment /* val INTEGER ::= 1*/
Lev Walkin9c974182004-09-15 11:59:51 +0000280%type <a_value> Value
Lev Walkin0c0bca62006-03-21 04:48:15 +0000281%type <a_value> SimpleValue
Lev Walkinf15320b2004-06-03 03:38:44 +0000282%type <a_value> DefinedValue
283%type <a_value> SignedNumber
Lev Walkinadf863f2006-09-05 16:18:34 +0000284%type <a_value> RealValue
Lev Walkin1c8d5aa2006-10-27 05:37:39 +0000285%type <a_value> BitStringValue
Lev Walkin144db9b2004-10-12 23:26:53 +0000286%type <a_expr> optComponentTypeLists
Lev Walkin070a52d2004-08-22 03:19:54 +0000287%type <a_expr> ComponentTypeLists
288%type <a_expr> ComponentType
289%type <a_expr> AlternativeTypeLists
290%type <a_expr> AlternativeType
Lev Walkinf15320b2004-06-03 03:38:44 +0000291%type <a_expr> UniverationDefinition
292%type <a_expr> UniverationList
293%type <a_expr> UniverationElement
294%type <tv_str> TypeRefName
295%type <tv_str> ObjectClassReference
Lev Walkinf15320b2004-06-03 03:38:44 +0000296%type <tv_str> Identifier
Lev Walkin83cac2f2004-09-22 16:03:36 +0000297%type <tv_str> optIdentifier
Lev Walkinf15320b2004-06-03 03:38:44 +0000298%type <a_parg> ParameterArgumentName
299%type <a_plist> ParameterArgumentList
Lev Walkin5045dfa2006-03-21 09:41:28 +0000300%type <a_expr> ActualParameter
301%type <a_expr> ActualParameterList
Lev Walkin1ed22092005-08-12 10:06:17 +0000302%type <a_aid> AssignedIdentifier /* OID/DefinedValue */
Lev Walkinf15320b2004-06-03 03:38:44 +0000303%type <a_oid> ObjectIdentifier /* OID */
304%type <a_oid> optObjectIdentifier /* Optional OID */
305%type <a_oid> ObjectIdentifierBody
306%type <a_oid_arc> ObjectIdentifierElement
307%type <a_expr> BasicType
308%type <a_type> BasicTypeId
309%type <a_type> BasicTypeId_UniverationCompatible
310%type <a_type> BasicString
311%type <tv_opaque> Opaque
Lev Walkinc603f102005-01-23 09:51:44 +0000312%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
313%type <a_tag> TagClass TagTypeValue TagPlicit
Lev Walkinf15320b2004-06-03 03:38:44 +0000314%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
315%type <a_constr> optConstraints
Lev Walkina9532f42006-09-17 04:52:50 +0000316%type <a_constr> Constraint
317%type <a_constr> SubtypeConstraint
318%type <a_constr> GeneralConstraint
Lev Walkinf59d0752004-08-18 04:59:12 +0000319%type <a_constr> SetOfConstraints
320%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
321%type <a_constr> ElementSetSpec /* 1..2,...,3 */
Lev Walkinf1727152006-09-21 01:50:37 +0000322%type <a_constr> Unions
323%type <a_constr> Intersections
324%type <a_constr> IntersectionElements
Lev Walkinf15320b2004-06-03 03:38:44 +0000325%type <a_constr> ConstraintSubtypeElement /* 1..2 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000326%type <a_constr> SimpleTableConstraint
Lev Walkina9532f42006-09-17 04:52:50 +0000327%type <a_constr> UserDefinedConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +0000328%type <a_constr> TableConstraint
Lev Walkina9532f42006-09-17 04:52:50 +0000329%type <a_constr> ContentsConstraint
Lev Walkin5c541f12006-10-18 18:40:14 +0000330%type <a_constr> PatternConstraint
Lev Walkine596bf02005-03-28 15:01:27 +0000331%type <a_constr> InnerTypeConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +0000332%type <a_constr> WithComponentsList
333%type <a_constr> WithComponentsElement
334%type <a_constr> ComponentRelationConstraint
335%type <a_constr> AtNotationList
336%type <a_ref> AtNotationElement
Lev Walkinff7dd142005-03-20 12:58:00 +0000337%type <a_value> SingleValue
338%type <a_value> ContainedSubtype
Lev Walkinf15320b2004-06-03 03:38:44 +0000339%type <a_ctype> ConstraintSpec
340%type <a_ctype> ConstraintRangeSpec
Lev Walkin1e448d32005-03-24 14:26:38 +0000341%type <a_value> RestrictedCharacterStringValue
Lev Walkinf15320b2004-06-03 03:38:44 +0000342%type <a_wsynt> optWithSyntax
343%type <a_wsynt> WithSyntax
Lev Walkin9d542d22006-03-14 16:31:37 +0000344%type <a_wsynt> WithSyntaxList
345%type <a_wchunk> WithSyntaxToken
Lev Walkinf15320b2004-06-03 03:38:44 +0000346%type <a_marker> optMarker Marker
347%type <a_int> optUnique
348%type <a_pres> optPresenceConstraint PresenceConstraint
349%type <tv_str> ComponentIdList
Lev Walkinef625402005-09-05 05:17:57 +0000350%type <a_int> NSTD_IndirectMarker
Lev Walkinf15320b2004-06-03 03:38:44 +0000351
352
353%%
354
355
356ParsedGrammar:
357 ModuleList {
358 *(void **)param = $1;
359 }
360 ;
361
362ModuleList:
Lev Walkin866bd7f2006-09-14 10:35:20 +0000363 ModuleDefinition {
Lev Walkinf15320b2004-06-03 03:38:44 +0000364 $$ = asn1p_new();
365 checkmem($$);
366 TQ_ADD(&($$->modules), $1, mod_next);
367 }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000368 | ModuleList ModuleDefinition {
Lev Walkinf15320b2004-06-03 03:38:44 +0000369 $$ = $1;
370 TQ_ADD(&($$->modules), $2, mod_next);
371 }
372 ;
373
374/*
375 * ASN module definition.
376 * === EXAMPLE ===
377 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
378 * BEGIN
379 * ...
380 * END
381 * === EOF ===
382 */
383
Lev Walkin866bd7f2006-09-14 10:35:20 +0000384ModuleDefinition:
Lev Walkina9532f42006-09-17 04:52:50 +0000385 TypeRefName { currentModule = asn1p_module_new(); }
386 optObjectIdentifier TOK_DEFINITIONS
Lev Walkin866bd7f2006-09-14 10:35:20 +0000387 optModuleDefinitionFlags
Lev Walkinf15320b2004-06-03 03:38:44 +0000388 TOK_PPEQ TOK_BEGIN
Lev Walkin866bd7f2006-09-14 10:35:20 +0000389 optModuleBody
Lev Walkinf15320b2004-06-03 03:38:44 +0000390 TOK_END {
391
Lev Walkina9532f42006-09-17 04:52:50 +0000392 $$ = currentModule;
393
394 if($8) {
395 asn1p_module_t tmp = *($$);
396 *($$) = *($8);
397 *($8) = tmp;
398 asn1p_module_free($8);
Lev Walkinf15320b2004-06-03 03:38:44 +0000399 } else {
400 /* There's a chance that a module is just plain empty */
Lev Walkinf15320b2004-06-03 03:38:44 +0000401 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000402
Lev Walkin1ed22092005-08-12 10:06:17 +0000403 $$->ModuleName = $1;
Lev Walkina9532f42006-09-17 04:52:50 +0000404 $$->module_oid = $3;
405 $$->module_flags = $5;
Lev Walkinf15320b2004-06-03 03:38:44 +0000406 }
407 ;
408
409/*
410 * Object Identifier Definition
411 * { iso member-body(2) 3 }
412 */
413optObjectIdentifier:
414 { $$ = 0; }
415 | ObjectIdentifier { $$ = $1; }
416 ;
417
418ObjectIdentifier:
419 '{' ObjectIdentifierBody '}' {
420 $$ = $2;
421 }
422 | '{' '}' {
423 $$ = 0;
424 }
425 ;
426
427ObjectIdentifierBody:
428 ObjectIdentifierElement {
429 $$ = asn1p_oid_new();
430 asn1p_oid_add_arc($$, &$1);
431 if($1.name)
432 free($1.name);
433 }
434 | ObjectIdentifierBody ObjectIdentifierElement {
435 $$ = $1;
436 asn1p_oid_add_arc($$, &$2);
437 if($2.name)
438 free($2.name);
439 }
440 ;
441
442ObjectIdentifierElement:
443 Identifier { /* iso */
444 $$.name = $1;
445 $$.number = -1;
446 }
447 | Identifier '(' TOK_number ')' { /* iso(1) */
448 $$.name = $1;
449 $$.number = $3;
450 }
451 | TOK_number { /* 1 */
452 $$.name = 0;
453 $$.number = $1;
454 }
455 ;
456
457/*
458 * Optional module flags.
459 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000460optModuleDefinitionFlags:
Lev Walkinf15320b2004-06-03 03:38:44 +0000461 { $$ = MSF_NOFLAGS; }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000462 | ModuleDefinitionFlags {
Lev Walkinf15320b2004-06-03 03:38:44 +0000463 $$ = $1;
464 }
465 ;
466
467/*
468 * Module flags.
469 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000470ModuleDefinitionFlags:
471 ModuleDefinitionFlag {
Lev Walkinf15320b2004-06-03 03:38:44 +0000472 $$ = $1;
473 }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000474 | ModuleDefinitionFlags ModuleDefinitionFlag {
Lev Walkinf15320b2004-06-03 03:38:44 +0000475 $$ = $1 | $2;
476 }
477 ;
478
479/*
480 * Single module flag.
481 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000482ModuleDefinitionFlag:
Lev Walkinf15320b2004-06-03 03:38:44 +0000483 TOK_EXPLICIT TOK_TAGS {
484 $$ = MSF_EXPLICIT_TAGS;
485 }
486 | TOK_IMPLICIT TOK_TAGS {
487 $$ = MSF_IMPLICIT_TAGS;
488 }
489 | TOK_AUTOMATIC TOK_TAGS {
490 $$ = MSF_AUTOMATIC_TAGS;
491 }
492 | TOK_EXTENSIBILITY TOK_IMPLIED {
493 $$ = MSF_EXTENSIBILITY_IMPLIED;
494 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000495 /* EncodingReferenceDefault */
496 | TOK_capitalreference TOK_INSTRUCTIONS {
497 /* X.680Amd1 specifies TAG and XER */
498 if(strcmp($1, "TAG") == 0) {
499 $$ = MSF_TAG_INSTRUCTIONS;
500 } else if(strcmp($1, "XER") == 0) {
501 $$ = MSF_XER_INSTRUCTIONS;
502 } else {
503 fprintf(stderr,
504 "WARNING: %s INSTRUCTIONS at line %d: "
505 "Unrecognized encoding reference\n",
506 $1, yylineno);
507 $$ = MSF_unk_INSTRUCTIONS;
508 }
509 free($1);
510 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000511 ;
512
513/*
514 * Optional module body.
515 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000516optModuleBody:
Lev Walkinf15320b2004-06-03 03:38:44 +0000517 { $$ = 0; }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000518 | ModuleBody {
Lev Walkinf15320b2004-06-03 03:38:44 +0000519 $$ = $1;
520 }
521 ;
522
523/*
524 * ASN.1 Module body.
525 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000526ModuleBody:
527 optExports optImports AssignmentList {
528 $$ = asn1p_module_new();
529 AL_IMPORT($$, exports, $1, xp_next);
530 AL_IMPORT($$, imports, $2, xp_next);
531 AL_IMPORT($$, members, $3, next);
Lev Walkinf15320b2004-06-03 03:38:44 +0000532 }
533 ;
534
Lev Walkin866bd7f2006-09-14 10:35:20 +0000535AssignmentList:
536 Assignment {
537 $$ = $1;
538 }
539 | AssignmentList Assignment {
540 if($1) {
541 $$ = $1;
542 } else {
543 $$ = $2;
544 break;
545 }
546 AL_IMPORT($$, members, $2, next);
547 }
548 ;
549
550
Lev Walkinf15320b2004-06-03 03:38:44 +0000551/*
552 * One of the elements of ASN.1 module specification.
553 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000554Assignment:
555 DataTypeReference {
Lev Walkinf15320b2004-06-03 03:38:44 +0000556 $$ = asn1p_module_new();
557 checkmem($$);
558 assert($1->expr_type != A1TC_INVALID);
559 assert($1->meta_type != AMT_INVALID);
560 TQ_ADD(&($$->members), $1, next);
561 }
Lev Walkinc6ab03c2006-10-21 05:54:49 +0000562 | ValueAssignment {
Lev Walkinf15320b2004-06-03 03:38:44 +0000563 $$ = asn1p_module_new();
564 checkmem($$);
565 assert($1->expr_type != A1TC_INVALID);
566 assert($1->meta_type != AMT_INVALID);
567 TQ_ADD(&($$->members), $1, next);
568 }
569 /*
570 * Value set definition
571 * === EXAMPLE ===
572 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
573 * === EOF ===
574 */
Lev Walkin557f27d2006-03-21 07:46:48 +0000575 | ValueSetTypeAssignment {
Lev Walkinf15320b2004-06-03 03:38:44 +0000576 $$ = asn1p_module_new();
577 checkmem($$);
578 assert($1->expr_type != A1TC_INVALID);
579 assert($1->meta_type != AMT_INVALID);
580 TQ_ADD(&($$->members), $1, next);
581 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000582 | TOK_ENCODING_CONTROL TOK_capitalreference
583 { asn1p_lexer_hack_push_encoding_control(); }
584 {
585 fprintf(stderr,
586 "WARNING: ENCODING-CONTROL %s "
587 "specification at line %d ignored\n",
588 $2, yylineno);
589 free($2);
590 $$ = 0;
591 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000592
593 /*
594 * Erroneous attemps
595 */
596 | BasicString {
597 return yyerror(
Lev Walkin70853052005-11-26 11:21:55 +0000598 "Attempt to redefine a standard basic string type, "
599 "please comment out or remove this type redefinition.");
Lev Walkinf15320b2004-06-03 03:38:44 +0000600 }
601 ;
602
603/*
604 * === EXAMPLE ===
605 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
606 * === EOF ===
607 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000608optImports:
609 { $$ = 0; }
610 | ImportsDefinition;
611
Lev Walkinf15320b2004-06-03 03:38:44 +0000612ImportsDefinition:
Lev Walkin4a4543f2006-10-13 12:37:39 +0000613 TOK_IMPORTS optImportsBundleSet ';' {
Lev Walkin1ed22092005-08-12 10:06:17 +0000614 if(!saved_aid && 0)
615 return yyerror("Unterminated IMPORTS FROM, "
616 "expected semicolon ';'");
617 saved_aid = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +0000618 $$ = $2;
619 }
620 /*
621 * Some error cases.
622 */
623 | TOK_IMPORTS TOK_FROM /* ... */ {
624 return yyerror("Empty IMPORTS list");
625 }
626 ;
627
Lev Walkin4a4543f2006-10-13 12:37:39 +0000628optImportsBundleSet:
629 { $$ = asn1p_module_new(); }
630 | ImportsBundleSet;
631
Lev Walkinf15320b2004-06-03 03:38:44 +0000632ImportsBundleSet:
633 ImportsBundle {
634 $$ = asn1p_module_new();
635 checkmem($$);
636 TQ_ADD(&($$->imports), $1, xp_next);
637 }
638 | ImportsBundleSet ImportsBundle {
639 $$ = $1;
640 TQ_ADD(&($$->imports), $2, xp_next);
641 }
642 ;
643
Lev Walkin1ed22092005-08-12 10:06:17 +0000644AssignedIdentifier:
645 { memset(&$$, 0, sizeof($$)); }
646 | ObjectIdentifier { $$.oid = $1; };
647 /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
648
Lev Walkinf15320b2004-06-03 03:38:44 +0000649ImportsBundle:
Lev Walkin1ed22092005-08-12 10:06:17 +0000650 ImportsList TOK_FROM TypeRefName AssignedIdentifier {
Lev Walkinf15320b2004-06-03 03:38:44 +0000651 $$ = $1;
Lev Walkin1ed22092005-08-12 10:06:17 +0000652 $$->fromModuleName = $3;
653 $$->identifier = $4;
654 /* This stupid thing is used for look-back hack. */
655 saved_aid = $$->identifier.oid ? 0 : &($$->identifier);
Lev Walkinf15320b2004-06-03 03:38:44 +0000656 checkmem($$);
657 }
658 ;
659
660ImportsList:
661 ImportsElement {
662 $$ = asn1p_xports_new();
663 checkmem($$);
664 TQ_ADD(&($$->members), $1, next);
665 }
666 | ImportsList ',' ImportsElement {
667 $$ = $1;
668 TQ_ADD(&($$->members), $3, next);
669 }
670 ;
671
672ImportsElement:
673 TypeRefName {
Lev Walkina9532f42006-09-17 04:52:50 +0000674 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000675 checkmem($$);
676 $$->Identifier = $1;
677 $$->expr_type = A1TC_REFERENCE;
678 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000679 | TypeRefName '{' '}' { /* Completely equivalent to above */
Lev Walkina9532f42006-09-17 04:52:50 +0000680 $$ = NEW_EXPR();
Lev Walkin144db9b2004-10-12 23:26:53 +0000681 checkmem($$);
682 $$->Identifier = $1;
683 $$->expr_type = A1TC_REFERENCE;
684 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000685 | Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +0000686 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000687 checkmem($$);
688 $$->Identifier = $1;
689 $$->expr_type = A1TC_REFERENCE;
690 }
691 ;
692
Lev Walkin866bd7f2006-09-14 10:35:20 +0000693
694optExports:
695 { $$ = 0; }
696 | ExportsDefinition {
697 $$ = asn1p_module_new();
698 checkmem($$);
699 if($1) {
700 TQ_ADD(&($$->exports), $1, xp_next);
701 } else {
702 /* "EXPORTS ALL;" */
703 }
704 }
705 ;
706
Lev Walkinf15320b2004-06-03 03:38:44 +0000707ExportsDefinition:
708 TOK_EXPORTS ExportsBody ';' {
709 $$ = $2;
710 }
711 | TOK_EXPORTS TOK_ALL ';' {
712 $$ = 0;
713 }
714 | TOK_EXPORTS ';' {
715 /* Empty EXPORTS clause effectively prohibits export. */
716 $$ = asn1p_xports_new();
717 checkmem($$);
718 }
719 ;
720
721ExportsBody:
722 ExportsElement {
723 $$ = asn1p_xports_new();
724 assert($$);
725 TQ_ADD(&($$->members), $1, next);
726 }
727 | ExportsBody ',' ExportsElement {
728 $$ = $1;
729 TQ_ADD(&($$->members), $3, next);
730 }
731 ;
732
733ExportsElement:
734 TypeRefName {
Lev Walkina9532f42006-09-17 04:52:50 +0000735 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000736 checkmem($$);
737 $$->Identifier = $1;
738 $$->expr_type = A1TC_EXPORTVAR;
739 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000740 | TypeRefName '{' '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000741 $$ = NEW_EXPR();
Lev Walkin144db9b2004-10-12 23:26:53 +0000742 checkmem($$);
743 $$->Identifier = $1;
744 $$->expr_type = A1TC_EXPORTVAR;
745 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000746 | Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +0000747 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000748 checkmem($$);
749 $$->Identifier = $1;
750 $$->expr_type = A1TC_EXPORTVAR;
751 }
752 ;
753
754
Lev Walkin418298d2006-07-13 08:24:20 +0000755ValueSet: '{' ElementSetSpecs '}' { $$ = $2; };
Lev Walkin557f27d2006-03-21 07:46:48 +0000756
757ValueSetTypeAssignment:
758 TypeRefName DefinedType TOK_PPEQ ValueSet {
Lev Walkinf15320b2004-06-03 03:38:44 +0000759 $$ = $2;
760 assert($$->Identifier == 0);
761 $$->Identifier = $1;
762 $$->meta_type = AMT_VALUESET;
Lev Walkin557f27d2006-03-21 07:46:48 +0000763 $$->constraints = $4;
Lev Walkinf15320b2004-06-03 03:38:44 +0000764 }
765 ;
766
Lev Walkin0c0bca62006-03-21 04:48:15 +0000767DefinedType:
768 BasicType {
769 $$ = $1;
770 }
771 /*
772 * A DefinedType reference.
773 * "CLASS1.&id.&id2"
774 * or
775 * "Module.Type"
776 * or
777 * "Module.identifier"
778 * or
779 * "Type"
780 */
781 | ComplexTypeReference {
Lev Walkina9532f42006-09-17 04:52:50 +0000782 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000783 checkmem($$);
784 $$->reference = $1;
785 $$->expr_type = A1TC_REFERENCE;
786 $$->meta_type = AMT_TYPEREF;
787 }
Lev Walkin0c0bca62006-03-21 04:48:15 +0000788 /*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000789 * A parameterized assignment.
Lev Walkin0c0bca62006-03-21 04:48:15 +0000790 */
Lev Walkin5045dfa2006-03-21 09:41:28 +0000791 | ComplexTypeReference '{' ActualParameterList '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000792 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000793 checkmem($$);
Lev Walkin0c0bca62006-03-21 04:48:15 +0000794 $$->reference = $1;
795 $$->rhs_pspecs = $3;
796 $$->expr_type = A1TC_REFERENCE;
797 $$->meta_type = AMT_TYPEREF;
Lev Walkinf15320b2004-06-03 03:38:44 +0000798 }
799 ;
800
Lev Walkinf15320b2004-06-03 03:38:44 +0000801/*
802 * Data Type Reference.
803 * === EXAMPLE ===
804 * Type3 ::= CHOICE { a Type1, b Type 2 }
805 * === EOF ===
806 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000807DataTypeReference:
808 /*
809 * Optionally tagged type definition.
810 */
Lev Walkin9c2285a2006-03-09 08:49:26 +0000811 TypeRefName TOK_PPEQ Type {
Lev Walkinaf120f72004-09-14 02:36:39 +0000812 $$ = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000813 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000814 assert($$->expr_type);
815 assert($$->meta_type);
816 }
Lev Walkin9c2285a2006-03-09 08:49:26 +0000817 | TypeRefName TOK_PPEQ ObjectClass {
Lev Walkinf15320b2004-06-03 03:38:44 +0000818 $$ = $3;
819 $$->Identifier = $1;
820 assert($$->expr_type == A1TC_CLASSDEF);
Lev Walkin9c2285a2006-03-09 08:49:26 +0000821 assert($$->meta_type == AMT_OBJECTCLASS);
Lev Walkinf15320b2004-06-03 03:38:44 +0000822 }
823 /*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000824 * Parameterized <Type> declaration:
Lev Walkinf15320b2004-06-03 03:38:44 +0000825 * === EXAMPLE ===
826 * SIGNED { ToBeSigned } ::= SEQUENCE {
827 * toBeSigned ToBeSigned,
828 * algorithm AlgorithmIdentifier,
829 * signature BIT STRING
830 * }
831 * === EOF ===
832 */
Lev Walkin070a52d2004-08-22 03:19:54 +0000833 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000834 $$ = $6;
Lev Walkin5045dfa2006-03-21 09:41:28 +0000835 $$->Identifier = $1;
836 $$->lhs_params = $3;
837 }
838 /* Parameterized CLASS declaration */
839 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ ObjectClass {
840 $$ = $6;
Lev Walkinf15320b2004-06-03 03:38:44 +0000841 $$->Identifier = $1;
Lev Walkina00d6b32006-03-21 03:40:38 +0000842 $$->lhs_params = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000843 }
844 ;
845
846ParameterArgumentList:
847 ParameterArgumentName {
848 int ret;
849 $$ = asn1p_paramlist_new(yylineno);
850 checkmem($$);
851 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
852 checkmem(ret == 0);
853 if($1.governor) asn1p_ref_free($1.governor);
854 if($1.argument) free($1.argument);
855 }
856 | ParameterArgumentList ',' ParameterArgumentName {
857 int ret;
858 $$ = $1;
859 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
860 checkmem(ret == 0);
861 if($3.governor) asn1p_ref_free($3.governor);
862 if($3.argument) free($3.argument);
863 }
864 ;
865
866ParameterArgumentName:
867 TypeRefName {
868 $$.governor = NULL;
869 $$.argument = $1;
870 }
871 | TypeRefName ':' Identifier {
872 int ret;
873 $$.governor = asn1p_ref_new(yylineno);
874 ret = asn1p_ref_add_component($$.governor, $1, 0);
875 checkmem(ret == 0);
876 $$.argument = $3;
877 }
Lev Walkinc8092cb2005-02-18 16:34:21 +0000878 | TypeRefName ':' TypeRefName {
879 int ret;
880 $$.governor = asn1p_ref_new(yylineno);
881 ret = asn1p_ref_add_component($$.governor, $1, 0);
882 checkmem(ret == 0);
883 $$.argument = $3;
884 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000885 | BasicTypeId ':' Identifier {
886 int ret;
887 $$.governor = asn1p_ref_new(yylineno);
888 ret = asn1p_ref_add_component($$.governor,
889 ASN_EXPR_TYPE2STR($1), 1);
890 checkmem(ret == 0);
891 $$.argument = $3;
892 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000893 | BasicTypeId ':' TypeRefName {
894 int ret;
895 $$.governor = asn1p_ref_new(yylineno);
896 ret = asn1p_ref_add_component($$.governor,
897 ASN_EXPR_TYPE2STR($1), 1);
898 checkmem(ret == 0);
899 $$.argument = $3;
900 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000901 ;
902
Lev Walkin5045dfa2006-03-21 09:41:28 +0000903ActualParameterList:
904 ActualParameter {
Lev Walkina9532f42006-09-17 04:52:50 +0000905 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000906 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000907 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000908 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000909 | ActualParameterList ',' ActualParameter {
Lev Walkinf15320b2004-06-03 03:38:44 +0000910 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000911 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000912 }
913 ;
914
Lev Walkin5045dfa2006-03-21 09:41:28 +0000915ActualParameter:
Lev Walkin070a52d2004-08-22 03:19:54 +0000916 Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000917 $$ = $1;
918 }
Lev Walkin0c0bca62006-03-21 04:48:15 +0000919 | SimpleValue {
Lev Walkina9532f42006-09-17 04:52:50 +0000920 $$ = NEW_EXPR();
Lev Walkin0c0bca62006-03-21 04:48:15 +0000921 checkmem($$);
922 $$->Identifier = "?";
923 $$->expr_type = A1TC_REFERENCE;
924 $$->meta_type = AMT_VALUE;
925 $$->value = $1;
926 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000927 | Identifier {
Lev Walkina00d6b32006-03-21 03:40:38 +0000928 asn1p_ref_t *ref;
Lev Walkina9532f42006-09-17 04:52:50 +0000929 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000930 checkmem($$);
931 $$->Identifier = $1;
932 $$->expr_type = A1TC_REFERENCE;
933 $$->meta_type = AMT_VALUE;
Lev Walkina00d6b32006-03-21 03:40:38 +0000934 ref = asn1p_ref_new(yylineno);
935 asn1p_ref_add_component(ref, $1, RLT_lowercase);
936 $$->value = asn1p_value_fromref(ref, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +0000937 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000938 | ValueSet {
Lev Walkina9532f42006-09-17 04:52:50 +0000939 $$ = NEW_EXPR();
Lev Walkin5045dfa2006-03-21 09:41:28 +0000940 $$->expr_type = A1TC_VALUESET;
941 $$->meta_type = AMT_VALUESET;
942 $$->constraints = $1;
943 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000944 ;
945
946/*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000947 | '{' ActualParameter '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000948 $$ = NEW_EXPR();
Lev Walkinc8092cb2005-02-18 16:34:21 +0000949 checkmem($$);
950 asn1p_expr_add($$, $2);
951 $$->expr_type = A1TC_PARAMETRIZED;
952 $$->meta_type = AMT_TYPE;
953 }
954 ;
955*/
956
957/*
Lev Walkinf15320b2004-06-03 03:38:44 +0000958 * A collection of constructed data type members.
959 */
Lev Walkin144db9b2004-10-12 23:26:53 +0000960optComponentTypeLists:
Lev Walkina9532f42006-09-17 04:52:50 +0000961 { $$ = NEW_EXPR(); }
Lev Walkin144db9b2004-10-12 23:26:53 +0000962 | ComponentTypeLists { $$ = $1; };
963
Lev Walkin070a52d2004-08-22 03:19:54 +0000964ComponentTypeLists:
965 ComponentType {
Lev Walkina9532f42006-09-17 04:52:50 +0000966 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000967 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000968 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000969 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000970 | ComponentTypeLists ',' ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +0000971 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000972 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000973 }
Lev Walkin0e90aa02013-03-19 16:17:13 -0700974 | ComponentTypeLists ',' TOK_VBracketLeft ComponentTypeLists TOK_VBracketRight {
975 $$ = $1;
976 asn1p_expr_add_many($$, $4);
977 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000978 ;
979
Lev Walkin070a52d2004-08-22 03:19:54 +0000980ComponentType:
Lev Walkinaf120f72004-09-14 02:36:39 +0000981 Identifier Type optMarker {
Lev Walkin070a52d2004-08-22 03:19:54 +0000982 $$ = $2;
983 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +0000984 $$->Identifier = $1;
Lev Walkinef625402005-09-05 05:17:57 +0000985 $3.flags |= $$->marker.flags;
Lev Walkin070a52d2004-08-22 03:19:54 +0000986 $$->marker = $3;
987 }
Lev Walkinef625402005-09-05 05:17:57 +0000988 | Type optMarker {
989 $$ = $1;
990 $2.flags |= $$->marker.flags;
991 $$->marker = $2;
992 _fixup_anonymous_identifier($$);
993 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000994 | TOK_COMPONENTS TOK_OF Type {
Lev Walkina9532f42006-09-17 04:52:50 +0000995 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +0000996 checkmem($$);
997 $$->meta_type = $3->meta_type;
998 $$->expr_type = A1TC_COMPONENTS_OF;
Lev Walkin1004aa92004-09-08 00:28:11 +0000999 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +00001000 }
1001 | ExtensionAndException {
1002 $$ = $1;
1003 }
1004 ;
1005
1006AlternativeTypeLists:
1007 AlternativeType {
Lev Walkina9532f42006-09-17 04:52:50 +00001008 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001009 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00001010 asn1p_expr_add($$, $1);
Lev Walkin070a52d2004-08-22 03:19:54 +00001011 }
1012 | AlternativeTypeLists ',' AlternativeType {
1013 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001014 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +00001015 }
1016 ;
1017
1018AlternativeType:
Lev Walkinaf120f72004-09-14 02:36:39 +00001019 Identifier Type {
Lev Walkin070a52d2004-08-22 03:19:54 +00001020 $$ = $2;
1021 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +00001022 $$->Identifier = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001023 }
1024 | ExtensionAndException {
1025 $$ = $1;
1026 }
Lev Walkin2e9bd5c2005-08-13 09:07:11 +00001027 | Type {
1028 $$ = $1;
1029 _fixup_anonymous_identifier($$);
1030 }
Lev Walkin070a52d2004-08-22 03:19:54 +00001031 ;
1032
Lev Walkin9c2285a2006-03-09 08:49:26 +00001033ObjectClass:
1034 TOK_CLASS '{' FieldSpec '}' optWithSyntax {
Lev Walkinf15320b2004-06-03 03:38:44 +00001035 $$ = $3;
1036 checkmem($$);
1037 $$->with_syntax = $5;
1038 assert($$->expr_type == A1TC_CLASSDEF);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001039 assert($$->meta_type == AMT_OBJECTCLASS);
Lev Walkinf15320b2004-06-03 03:38:44 +00001040 }
1041 ;
1042
1043optUnique:
1044 { $$ = 0; }
1045 | TOK_UNIQUE { $$ = 1; }
1046 ;
1047
Lev Walkin9c2285a2006-03-09 08:49:26 +00001048FieldSpec:
Lev Walkinf15320b2004-06-03 03:38:44 +00001049 ClassField {
Lev Walkina9532f42006-09-17 04:52:50 +00001050 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001051 checkmem($$);
1052 $$->expr_type = A1TC_CLASSDEF;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001053 $$->meta_type = AMT_OBJECTCLASS;
Lev Walkin1004aa92004-09-08 00:28:11 +00001054 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001055 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001056 | FieldSpec ',' ClassField {
Lev Walkinf15320b2004-06-03 03:38:44 +00001057 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001058 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001059 }
1060 ;
1061
Lev Walkin9c2285a2006-03-09 08:49:26 +00001062 /* X.681 */
Lev Walkinf15320b2004-06-03 03:38:44 +00001063ClassField:
Lev Walkin9c2285a2006-03-09 08:49:26 +00001064
1065 /* TypeFieldSpec ::= typefieldreference TypeOptionalitySpec? */
1066 TOK_typefieldreference optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001067 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001068 checkmem($$);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001069 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001070 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001071 $$->expr_type = A1TC_CLASSFIELD_TFS; /* TypeFieldSpec */
Lev Walkinf15320b2004-06-03 03:38:44 +00001072 $$->marker = $2;
1073 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001074
1075 /* FixedTypeValueFieldSpec ::= valuefieldreference Type UNIQUE ? ValueOptionalitySpec ? */
1076 | TOK_valuefieldreference Type optUnique optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001077 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001078 $$->Identifier = $1;
1079 $$->meta_type = AMT_OBJECTFIELD;
1080 $$->expr_type = A1TC_CLASSFIELD_FTVFS; /* FixedTypeValueFieldSpec */
Lev Walkinb7c45ca2004-11-24 17:43:29 +00001081 $$->unique = $3;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001082 $$->marker = $4;
1083 asn1p_expr_add($$, $2);
Lev Walkinf15320b2004-06-03 03:38:44 +00001084 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001085
1086 /* VariableTypeValueFieldSpec ::= valuefieldreference FieldName ValueOptionalitySpec ? */
1087 | TOK_valuefieldreference FieldName optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001088 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001089 $$->Identifier = $1;
1090 $$->meta_type = AMT_OBJECTFIELD;
1091 $$->expr_type = A1TC_CLASSFIELD_VTVFS;
1092 $$->reference = $2;
1093 $$->marker = $3;
1094 }
1095
Lev Walkin9c2285a2006-03-09 08:49:26 +00001096 /* ObjectFieldSpec ::= objectfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1097 | TOK_valuefieldreference DefinedObjectClass optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001098 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001099 checkmem($$);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001100 $$->Identifier = $1;
1101 $$->reference = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00001102 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001103 $$->expr_type = A1TC_CLASSFIELD_OFS;
1104 $$->marker = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +00001105 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001106
Lev Walkin54868752006-03-09 09:08:49 +00001107 /* VariableTypeValueSetFieldSpec ::= valuesetfieldreference FieldName ValueOptionalitySpec ? */
1108 | TOK_typefieldreference FieldName optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001109 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001110 $$->Identifier = $1;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001111 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin54868752006-03-09 09:08:49 +00001112 $$->expr_type = A1TC_CLASSFIELD_VTVSFS;
1113 $$->reference = $2;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001114 $$->marker = $3;
1115 }
1116
1117 /* FixedTypeValueSetFieldSpec ::= valuesetfieldreference Type ValueSetOptionalitySpec ? */
1118 | TOK_typefieldreference Type optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001119 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001120 checkmem($$);
1121 $$->Identifier = $1;
1122 $$->meta_type = AMT_OBJECTFIELD;
1123 $$->expr_type = A1TC_CLASSFIELD_FTVSFS;
1124 asn1p_expr_add($$, $2);
1125 $$->marker = $3;
1126 }
1127
Lev Walkin54868752006-03-09 09:08:49 +00001128 /* ObjectSetFieldSpec ::= objectsetfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1129 | TOK_typefieldreference DefinedObjectClass optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001130 $$ = NEW_EXPR();
Lev Walkin54868752006-03-09 09:08:49 +00001131 checkmem($$);
1132 $$->Identifier = $1;
1133 $$->reference = $2;
1134 $$->meta_type = AMT_OBJECTFIELD;
1135 $$->expr_type = A1TC_CLASSFIELD_OSFS;
1136 $$->marker = $3;
1137 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001138 ;
1139
1140optWithSyntax:
1141 { $$ = 0; }
1142 | WithSyntax {
1143 $$ = $1;
1144 }
1145 ;
1146
1147WithSyntax:
1148 TOK_WITH TOK_SYNTAX '{'
1149 { asn1p_lexer_hack_enable_with_syntax(); }
Lev Walkin9d542d22006-03-14 16:31:37 +00001150 WithSyntaxList
Lev Walkinf15320b2004-06-03 03:38:44 +00001151 '}' {
1152 $$ = $5;
1153 }
1154 ;
1155
Lev Walkin9d542d22006-03-14 16:31:37 +00001156WithSyntaxList:
1157 WithSyntaxToken {
Lev Walkinf15320b2004-06-03 03:38:44 +00001158 $$ = asn1p_wsyntx_new();
1159 TQ_ADD(&($$->chunks), $1, next);
1160 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001161 | WithSyntaxList WithSyntaxToken {
Lev Walkinf15320b2004-06-03 03:38:44 +00001162 $$ = $1;
1163 TQ_ADD(&($$->chunks), $2, next);
1164 }
1165 ;
1166
Lev Walkin9d542d22006-03-14 16:31:37 +00001167WithSyntaxToken:
Lev Walkin57074f12006-03-16 05:11:14 +00001168 TOK_whitespace {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001169 $$ = asn1p_wsyntx_chunk_fromstring($1.buf, 0);
Lev Walkin57074f12006-03-16 05:11:14 +00001170 $$->type = WC_WHITESPACE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001171 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001172 | TOK_Literal {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001173 $$ = asn1p_wsyntx_chunk_fromstring($1, 0);
Lev Walkin9d542d22006-03-14 16:31:37 +00001174 }
Lev Walkind370e9f2006-03-16 10:03:35 +00001175 | PrimitiveFieldReference {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001176 $$ = asn1p_wsyntx_chunk_fromstring($1.name, 0);
Lev Walkind370e9f2006-03-16 10:03:35 +00001177 $$->type = WC_FIELD;
Lev Walkinf15320b2004-06-03 03:38:44 +00001178 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001179 | '[' WithSyntaxList ']' {
1180 $$ = asn1p_wsyntx_chunk_fromsyntax($2);
1181 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001182 ;
1183
Lev Walkinf15320b2004-06-03 03:38:44 +00001184ExtensionAndException:
1185 TOK_ThreeDots {
Lev Walkina9532f42006-09-17 04:52:50 +00001186 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001187 checkmem($$);
1188 $$->Identifier = strdup("...");
1189 checkmem($$->Identifier);
1190 $$->expr_type = A1TC_EXTENSIBLE;
1191 $$->meta_type = AMT_TYPE;
1192 }
1193 | TOK_ThreeDots '!' DefinedValue {
Lev Walkina9532f42006-09-17 04:52:50 +00001194 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001195 checkmem($$);
1196 $$->Identifier = strdup("...");
1197 checkmem($$->Identifier);
1198 $$->value = $3;
1199 $$->expr_type = A1TC_EXTENSIBLE;
1200 $$->meta_type = AMT_TYPE;
1201 }
1202 | TOK_ThreeDots '!' SignedNumber {
Lev Walkina9532f42006-09-17 04:52:50 +00001203 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001204 checkmem($$);
1205 $$->Identifier = strdup("...");
1206 $$->value = $3;
1207 checkmem($$->Identifier);
1208 $$->expr_type = A1TC_EXTENSIBLE;
1209 $$->meta_type = AMT_TYPE;
1210 }
1211 ;
1212
Lev Walkin070a52d2004-08-22 03:19:54 +00001213Type:
Lev Walkinaf120f72004-09-14 02:36:39 +00001214 optTag TypeDeclaration optConstraints {
1215 $$ = $2;
1216 $$->tag = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001217 /*
1218 * Outer constraint for SEQUENCE OF and SET OF applies
1219 * to the inner type.
1220 */
1221 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1222 || $$->expr_type == ASN_CONSTR_SET_OF) {
1223 assert(!TQ_FIRST(&($$->members))->constraints);
Lev Walkinaf120f72004-09-14 02:36:39 +00001224 TQ_FIRST(&($$->members))->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001225 } else {
1226 if($$->constraints) {
1227 assert(!$2);
1228 } else {
Lev Walkinaf120f72004-09-14 02:36:39 +00001229 $$->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001230 }
1231 }
Lev Walkinef625402005-09-05 05:17:57 +00001232 }
1233 ;
1234
1235NSTD_IndirectMarker:
1236 {
1237 $$ = asn1p_as_pointer ? EM_INDIRECT : 0;
1238 asn1p_as_pointer = 0;
Lev Walkin070a52d2004-08-22 03:19:54 +00001239 }
1240 ;
1241
1242TypeDeclaration:
Lev Walkinef625402005-09-05 05:17:57 +00001243 NSTD_IndirectMarker TypeDeclarationSet {
Lev Walkin4696c742005-08-22 12:23:54 +00001244 $$ = $2;
Lev Walkinef625402005-09-05 05:17:57 +00001245 $$->marker.flags |= $1;
1246
1247 if(($$->marker.flags & EM_INDIRECT)
1248 && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
1249 fprintf(stderr,
1250 "INFO: Directive <ASN1C:RepresentAsPointer> "
1251 "applied to %s at line %d\n",
1252 ASN_EXPR_TYPE2STR($$->expr_type)
1253 ? ASN_EXPR_TYPE2STR($$->expr_type)
1254 : "member",
1255 $$->_lineno
1256 );
1257 }
Lev Walkin4696c742005-08-22 12:23:54 +00001258 }
Lev Walkinef625402005-09-05 05:17:57 +00001259 ;
Lev Walkin4696c742005-08-22 12:23:54 +00001260
1261TypeDeclarationSet:
Lev Walkin0c0bca62006-03-21 04:48:15 +00001262 DefinedType {
Lev Walkinf15320b2004-06-03 03:38:44 +00001263 $$ = $1;
1264 }
Lev Walkinef625402005-09-05 05:17:57 +00001265 | TOK_CHOICE '{' AlternativeTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001266 $$ = $3;
1267 assert($$->expr_type == A1TC_INVALID);
1268 $$->expr_type = ASN_CONSTR_CHOICE;
1269 $$->meta_type = AMT_TYPE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001270 }
Lev Walkinef625402005-09-05 05:17:57 +00001271 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001272 $$ = $3;
1273 assert($$->expr_type == A1TC_INVALID);
1274 $$->expr_type = ASN_CONSTR_SEQUENCE;
1275 $$->meta_type = AMT_TYPE;
1276 }
Lev Walkinef625402005-09-05 05:17:57 +00001277 | TOK_SET '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001278 $$ = $3;
1279 assert($$->expr_type == A1TC_INVALID);
1280 $$->expr_type = ASN_CONSTR_SET;
1281 $$->meta_type = AMT_TYPE;
1282 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001283 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkina9532f42006-09-17 04:52:50 +00001284 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001285 checkmem($$);
1286 $$->constraints = $2;
1287 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1288 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001289 $6->Identifier = $4;
1290 $6->tag = $5;
1291 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001292 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001293 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkina9532f42006-09-17 04:52:50 +00001294 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001295 checkmem($$);
1296 $$->constraints = $2;
1297 $$->expr_type = ASN_CONSTR_SET_OF;
1298 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001299 $6->Identifier = $4;
1300 $6->tag = $5;
1301 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001302 }
1303 | TOK_ANY {
Lev Walkina9532f42006-09-17 04:52:50 +00001304 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001305 checkmem($$);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001306 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001307 $$->meta_type = AMT_TYPE;
1308 }
1309 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1310 int ret;
Lev Walkina9532f42006-09-17 04:52:50 +00001311 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001312 checkmem($$);
1313 $$->reference = asn1p_ref_new(yylineno);
1314 ret = asn1p_ref_add_component($$->reference,
1315 $4, RLT_lowercase);
1316 checkmem(ret == 0);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001317 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001318 $$->meta_type = AMT_TYPE;
1319 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001320 | TOK_INSTANCE TOK_OF ComplexTypeReference {
Lev Walkina9532f42006-09-17 04:52:50 +00001321 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001322 checkmem($$);
1323 $$->reference = $3;
1324 $$->expr_type = A1TC_INSTANCE;
1325 $$->meta_type = AMT_TYPE;
1326 }
1327 ;
1328
1329/*
1330 * A type name consisting of several components.
1331 * === EXAMPLE ===
1332 * === EOF ===
1333 */
1334ComplexTypeReference:
1335 TOK_typereference {
1336 int ret;
1337 $$ = asn1p_ref_new(yylineno);
1338 checkmem($$);
1339 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1340 checkmem(ret == 0);
1341 free($1);
1342 }
1343 | TOK_typereference '.' TypeRefName {
1344 int ret;
1345 $$ = asn1p_ref_new(yylineno);
1346 checkmem($$);
1347 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1348 checkmem(ret == 0);
1349 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1350 checkmem(ret == 0);
1351 free($1);
1352 }
Lev Walkin9c974182004-09-15 11:59:51 +00001353 | ObjectClassReference '.' TypeRefName {
1354 int ret;
1355 $$ = asn1p_ref_new(yylineno);
1356 checkmem($$);
1357 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1358 checkmem(ret == 0);
1359 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1360 checkmem(ret == 0);
1361 free($1);
1362 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001363 | TOK_typereference '.' Identifier {
1364 int ret;
1365 $$ = asn1p_ref_new(yylineno);
1366 checkmem($$);
1367 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1368 checkmem(ret == 0);
1369 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1370 checkmem(ret == 0);
1371 free($1);
1372 }
1373 | ObjectClassReference {
1374 int ret;
1375 $$ = asn1p_ref_new(yylineno);
1376 checkmem($$);
1377 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1378 free($1);
1379 checkmem(ret == 0);
1380 }
1381 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1382 int ret;
1383 $$ = $3;
1384 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1385 free($1);
1386 checkmem(ret == 0);
1387 /*
1388 * Move the last element infront.
1389 */
1390 {
1391 struct asn1p_ref_component_s tmp_comp;
1392 tmp_comp = $$->components[$$->comp_count-1];
1393 memmove(&$$->components[1],
1394 &$$->components[0],
1395 sizeof($$->components[0])
1396 * ($$->comp_count - 1));
1397 $$->components[0] = tmp_comp;
1398 }
1399 }
1400 ;
1401
1402ComplexTypeReferenceAmpList:
1403 ComplexTypeReferenceElement {
1404 int ret;
1405 $$ = asn1p_ref_new(yylineno);
1406 checkmem($$);
1407 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1408 free($1.name);
1409 checkmem(ret == 0);
1410 }
1411 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1412 int ret;
1413 $$ = $1;
1414 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1415 free($3.name);
1416 checkmem(ret == 0);
1417 }
1418 ;
1419
Lev Walkind370e9f2006-03-16 10:03:35 +00001420ComplexTypeReferenceElement: PrimitiveFieldReference;
Lev Walkinf15320b2004-06-03 03:38:44 +00001421
Lev Walkind370e9f2006-03-16 10:03:35 +00001422PrimitiveFieldReference:
Lev Walkinf15320b2004-06-03 03:38:44 +00001423 /* "&Type1" */
1424 TOK_typefieldreference {
1425 $$.lex_type = RLT_AmpUppercase;
1426 $$.name = $1;
1427 }
1428 /* "&id" */
1429 | TOK_valuefieldreference {
1430 $$.lex_type = RLT_Amplowercase;
1431 $$.name = $1;
1432 }
1433 ;
1434
1435
Lev Walkin9c2285a2006-03-09 08:49:26 +00001436FieldName:
1437 /* "&Type1" */
1438 TOK_typefieldreference {
1439 $$ = asn1p_ref_new(yylineno);
1440 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1441 }
1442 | FieldName '.' TOK_typefieldreference {
1443 $$ = $$;
1444 asn1p_ref_add_component($$, $3, RLT_AmpUppercase);
1445 }
1446 | FieldName '.' TOK_valuefieldreference {
1447 $$ = $$;
1448 asn1p_ref_add_component($$, $3, RLT_Amplowercase);
1449 }
1450 ;
1451
1452DefinedObjectClass:
1453 TOK_capitalreference {
1454 $$ = asn1p_ref_new(yylineno);
1455 asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1456 }
Lev Walkin54868752006-03-09 09:08:49 +00001457/*
Lev Walkin9c2285a2006-03-09 08:49:26 +00001458 | TypeRefName '.' TOK_capitalreference {
1459 $$ = asn1p_ref_new(yylineno);
1460 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1461 asn1p_ref_add_component($$, $3, RLT_CAPITALS);
1462 }
Lev Walkin54868752006-03-09 09:08:49 +00001463*/
Lev Walkin9c2285a2006-03-09 08:49:26 +00001464 ;
1465
1466
Lev Walkinf15320b2004-06-03 03:38:44 +00001467/*
1468 * === EXAMPLE ===
1469 * value INTEGER ::= 1
1470 * === EOF ===
1471 */
Lev Walkinc6ab03c2006-10-21 05:54:49 +00001472ValueAssignment:
1473 Identifier Type TOK_PPEQ Value {
Lev Walkinf15320b2004-06-03 03:38:44 +00001474 $$ = $2;
1475 assert($$->Identifier == NULL);
1476 $$->Identifier = $1;
1477 $$->meta_type = AMT_VALUE;
1478 $$->value = $4;
1479 }
1480 ;
1481
Lev Walkin9c974182004-09-15 11:59:51 +00001482Value:
Lev Walkin0c0bca62006-03-21 04:48:15 +00001483 SimpleValue
1484 | DefinedValue
1485 | Identifier ':' Value {
Lev Walkin9c974182004-09-15 11:59:51 +00001486 $$ = asn1p_value_fromint(0);
1487 checkmem($$);
1488 $$->type = ATV_CHOICE_IDENTIFIER;
1489 $$->value.choice_identifier.identifier = $1;
1490 $$->value.choice_identifier.value = $3;
1491 }
Lev Walkincbad2512005-03-24 16:27:02 +00001492 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Lev Walkinf15320b2004-06-03 03:38:44 +00001493 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1494 checkmem($$);
1495 $$->type = ATV_UNPARSED;
1496 }
Lev Walkin9c974182004-09-15 11:59:51 +00001497 | TOK_NULL {
1498 $$ = asn1p_value_fromint(0);
1499 checkmem($$);
1500 $$->type = ATV_NULL;
1501 }
Lev Walkin0c0bca62006-03-21 04:48:15 +00001502 ;
1503
1504SimpleValue:
1505 TOK_FALSE {
Lev Walkin9c974182004-09-15 11:59:51 +00001506 $$ = asn1p_value_fromint(0);
1507 checkmem($$);
1508 $$->type = ATV_FALSE;
1509 }
1510 | TOK_TRUE {
1511 $$ = asn1p_value_fromint(0);
1512 checkmem($$);
1513 $$->type = ATV_TRUE;
1514 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001515 | TOK_bstring {
1516 $$ = _convert_bitstring2binary($1, 'B');
1517 checkmem($$);
1518 }
1519 | TOK_hstring {
1520 $$ = _convert_bitstring2binary($1, 'H');
1521 checkmem($$);
1522 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001523 | RestrictedCharacterStringValue {
1524 $$ = $$;
Lev Walkinf15320b2004-06-03 03:38:44 +00001525 }
1526 | SignedNumber {
1527 $$ = $1;
1528 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001529 ;
1530
1531DefinedValue:
1532 Identifier {
1533 asn1p_ref_t *ref;
1534 int ret;
1535 ref = asn1p_ref_new(yylineno);
1536 checkmem(ref);
1537 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1538 checkmem(ret == 0);
1539 $$ = asn1p_value_fromref(ref, 0);
1540 checkmem($$);
1541 free($1);
1542 }
1543 | TypeRefName '.' Identifier {
1544 asn1p_ref_t *ref;
1545 int ret;
1546 ref = asn1p_ref_new(yylineno);
1547 checkmem(ref);
1548 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1549 checkmem(ret == 0);
1550 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1551 checkmem(ret == 0);
1552 $$ = asn1p_value_fromref(ref, 0);
1553 checkmem($$);
1554 free($1);
1555 free($3);
1556 }
1557 ;
1558
Lev Walkin1e448d32005-03-24 14:26:38 +00001559
1560RestrictedCharacterStringValue:
1561 TOK_cstring {
1562 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1563 checkmem($$);
1564 }
Lev Walkind9574ae2005-03-24 16:22:35 +00001565 | TOK_tuple {
1566 $$ = asn1p_value_fromint($1);
1567 checkmem($$);
1568 $$->type = ATV_TUPLE;
1569 }
1570 | TOK_quadruple {
1571 $$ = asn1p_value_fromint($1);
1572 checkmem($$);
1573 $$->type = ATV_QUADRUPLE;
1574 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001575 ;
1576
Lev Walkinf15320b2004-06-03 03:38:44 +00001577Opaque:
1578 TOK_opaque {
Lev Walkin1893ddf2005-03-20 14:28:32 +00001579 $$.len = $1.len + 1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001580 $$.buf = malloc($$.len + 1);
1581 checkmem($$.buf);
1582 $$.buf[0] = '{';
Lev Walkin1893ddf2005-03-20 14:28:32 +00001583 memcpy($$.buf + 1, $1.buf, $1.len);
Lev Walkinf15320b2004-06-03 03:38:44 +00001584 $$.buf[$$.len] = '\0';
1585 free($1.buf);
1586 }
1587 | Opaque TOK_opaque {
1588 int newsize = $1.len + $2.len;
1589 char *p = malloc(newsize + 1);
1590 checkmem(p);
1591 memcpy(p , $1.buf, $1.len);
1592 memcpy(p + $1.len, $2.buf, $2.len);
1593 p[newsize] = '\0';
1594 free($1.buf);
1595 free($2.buf);
1596 $$.buf = p;
1597 $$.len = newsize;
1598 }
1599 ;
1600
1601BasicTypeId:
1602 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1603 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1604 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1605 | BasicTypeId_UniverationCompatible { $$ = $1; }
1606 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1607 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1608 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1609 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1610 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1611 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1612 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1613 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
Lev Walkinc7d939d2005-03-20 11:12:40 +00001614 | BasicString { $$ = $1; }
Lev Walkinf15320b2004-06-03 03:38:44 +00001615 ;
1616
1617/*
1618 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1619 */
1620BasicTypeId_UniverationCompatible:
1621 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1622 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1623 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1624 ;
1625
1626BasicType:
1627 BasicTypeId {
Lev Walkina9532f42006-09-17 04:52:50 +00001628 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001629 checkmem($$);
1630 $$->expr_type = $1;
1631 $$->meta_type = AMT_TYPE;
1632 }
1633 | BasicTypeId_UniverationCompatible UniverationDefinition {
1634 if($2) {
1635 $$ = $2;
1636 } else {
Lev Walkina9532f42006-09-17 04:52:50 +00001637 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001638 checkmem($$);
1639 }
1640 $$->expr_type = $1;
1641 $$->meta_type = AMT_TYPE;
1642 }
1643 ;
1644
1645BasicString:
1646 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1647 | TOK_GeneralString {
1648 $$ = ASN_STRING_GeneralString;
Lev Walkin9c974182004-09-15 11:59:51 +00001649 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001650 }
1651 | TOK_GraphicString {
1652 $$ = ASN_STRING_GraphicString;
Lev Walkin9c974182004-09-15 11:59:51 +00001653 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001654 }
1655 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1656 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1657 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1658 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1659 | TOK_T61String {
1660 $$ = ASN_STRING_T61String;
Lev Walkin9c974182004-09-15 11:59:51 +00001661 fprintf(stderr, "WARNING: T61String is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001662 }
1663 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1664 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1665 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1666 | TOK_VideotexString {
1667 $$ = ASN_STRING_VideotexString;
Lev Walkin9c974182004-09-15 11:59:51 +00001668 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001669 }
1670 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1671 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1672 ;
1673
Lev Walkind2ea1de2004-08-20 13:25:29 +00001674
Lev Walkinf15320b2004-06-03 03:38:44 +00001675/*
1676 * Data type constraints.
1677 */
Lev Walkinf1727152006-09-21 01:50:37 +00001678UnionMark: '|' | TOK_UNION;
1679IntersectionMark: '^' | TOK_INTERSECTION;
Lev Walkinf15320b2004-06-03 03:38:44 +00001680
Lev Walkinf59d0752004-08-18 04:59:12 +00001681optConstraints:
1682 { $$ = 0; }
Lev Walkina9532f42006-09-17 04:52:50 +00001683 | Constraint {
Lev Walkind2ea1de2004-08-20 13:25:29 +00001684 $$ = $1;
1685 }
1686 ;
1687
Lev Walkina9532f42006-09-17 04:52:50 +00001688Constraint:
1689 SubtypeConstraint
Lev Walkina9532f42006-09-17 04:52:50 +00001690 ;
1691
1692SubtypeConstraint:
Lev Walkind2ea1de2004-08-20 13:25:29 +00001693 SetOfConstraints {
Lev Walkin2c14a692005-08-12 10:08:45 +00001694 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
Lev Walkinf59d0752004-08-18 04:59:12 +00001695 }
1696 | TOK_SIZE '(' ElementSetSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001697 /*
1698 * This is a special case, for compatibility purposes.
Lev Walkinf59d0752004-08-18 04:59:12 +00001699 * It goes without parentheses.
Lev Walkinf15320b2004-06-03 03:38:44 +00001700 */
Lev Walkin2c14a692005-08-12 10:08:45 +00001701 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001702 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001703 ;
1704
Lev Walkinf59d0752004-08-18 04:59:12 +00001705SetOfConstraints:
1706 '(' ElementSetSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001707 $$ = $2;
1708 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001709 | SetOfConstraints '(' ElementSetSpecs ')' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001710 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
Lev Walkinf59d0752004-08-18 04:59:12 +00001711 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001712 ;
1713
Lev Walkinf59d0752004-08-18 04:59:12 +00001714ElementSetSpecs:
Lev Walkin5045dfa2006-03-21 09:41:28 +00001715 TOK_ThreeDots {
1716 $$ = asn1p_constraint_new(yylineno);
1717 $$->type = ACT_EL_EXT;
1718 }
1719 | ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001720 $$ = $1;
1721 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001722 | ElementSetSpec ',' TOK_ThreeDots {
Lev Walkinf15320b2004-06-03 03:38:44 +00001723 asn1p_constraint_t *ct;
1724 ct = asn1p_constraint_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001725 ct->type = ACT_EL_EXT;
Lev Walkin2c14a692005-08-12 10:08:45 +00001726 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00001727 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001728 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001729 asn1p_constraint_t *ct;
1730 ct = asn1p_constraint_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001731 ct->type = ACT_EL_EXT;
Lev Walkin2c14a692005-08-12 10:08:45 +00001732 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinb4fcdd22004-08-13 12:35:09 +00001733 ct = $$;
Lev Walkin2c14a692005-08-12 10:08:45 +00001734 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
Lev Walkinf15320b2004-06-03 03:38:44 +00001735 }
Lev Walkinc6ab03c2006-10-21 05:54:49 +00001736 | GeneralConstraint {
1737 $$ = $1;
1738 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001739 ;
1740
Lev Walkinf59d0752004-08-18 04:59:12 +00001741ElementSetSpec:
Lev Walkinf1727152006-09-21 01:50:37 +00001742 Unions
Lev Walkin1e448d32005-03-24 14:26:38 +00001743 | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001744 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
Lev Walkin1e448d32005-03-24 14:26:38 +00001745 }
Lev Walkinf1727152006-09-21 01:50:37 +00001746 ;
1747
1748Unions:
1749 Intersections
1750 | Unions UnionMark Intersections {
Lev Walkin2c14a692005-08-12 10:08:45 +00001751 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001752 }
Lev Walkinf1727152006-09-21 01:50:37 +00001753 ;
1754
1755Intersections:
1756 IntersectionElements
1757 | Intersections IntersectionMark IntersectionElements {
Lev Walkin2c14a692005-08-12 10:08:45 +00001758 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001759 }
Lev Walkinf1727152006-09-21 01:50:37 +00001760 ;
1761
1762
1763IntersectionElements:
1764 ConstraintSubtypeElement
1765 | ConstraintSubtypeElement TOK_EXCEPT ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001766 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001767 }
1768 ;
1769
1770ConstraintSubtypeElement:
Lev Walkinf59d0752004-08-18 04:59:12 +00001771 ConstraintSpec '(' ElementSetSpecs ')' {
1772 int ret;
1773 $$ = asn1p_constraint_new(yylineno);
1774 checkmem($$);
1775 $$->type = $1;
1776 ret = asn1p_constraint_insert($$, $3);
1777 checkmem(ret == 0);
1778 }
1779 | '(' ElementSetSpecs ')' {
1780 int ret;
1781 $$ = asn1p_constraint_new(yylineno);
1782 checkmem($$);
1783 $$->type = ACT_CA_SET;
1784 ret = asn1p_constraint_insert($$, $2);
1785 checkmem(ret == 0);
1786 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001787 | SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001788 $$ = asn1p_constraint_new(yylineno);
1789 checkmem($$);
1790 $$->type = ACT_EL_VALUE;
1791 $$->value = $1;
1792 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001793 | ContainedSubtype {
1794 $$ = asn1p_constraint_new(yylineno);
1795 checkmem($$);
1796 $$->type = ACT_EL_TYPE;
1797 $$->containedSubtype = $1;
1798 }
1799 | SingleValue ConstraintRangeSpec SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001800 $$ = asn1p_constraint_new(yylineno);
1801 checkmem($$);
1802 $$->type = $2;
1803 $$->range_start = $1;
1804 $$->range_stop = $3;
1805 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001806 | TOK_MIN ConstraintRangeSpec SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001807 $$ = asn1p_constraint_new(yylineno);
1808 checkmem($$);
Lev Walkinf59d0752004-08-18 04:59:12 +00001809 $$->type = $2;
1810 $$->range_start = asn1p_value_fromint(-123);
1811 $$->range_stop = $3;
1812 $$->range_start->type = ATV_MIN;
1813 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001814 | SingleValue ConstraintRangeSpec TOK_MAX {
Lev Walkinf59d0752004-08-18 04:59:12 +00001815 $$ = asn1p_constraint_new(yylineno);
1816 checkmem($$);
1817 $$->type = $2;
1818 $$->range_start = $1;
1819 $$->range_stop = asn1p_value_fromint(321);
1820 $$->range_stop->type = ATV_MAX;
1821 }
1822 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1823 $$ = asn1p_constraint_new(yylineno);
1824 checkmem($$);
1825 $$->type = $2;
1826 $$->range_start = asn1p_value_fromint(-123);
1827 $$->range_stop = asn1p_value_fromint(321);
1828 $$->range_start->type = ATV_MIN;
1829 $$->range_stop->type = ATV_MAX;
Lev Walkinf15320b2004-06-03 03:38:44 +00001830 }
Lev Walkine596bf02005-03-28 15:01:27 +00001831 | InnerTypeConstraint {
Lev Walkinf15320b2004-06-03 03:38:44 +00001832 $$ = $1;
1833 }
Lev Walkin5c541f12006-10-18 18:40:14 +00001834 | PatternConstraint {
1835 $$ = $1;
1836 }
1837 ;
1838
1839PatternConstraint:
1840 TOK_PATTERN TOK_cstring {
1841 $$ = asn1p_constraint_new(yylineno);
1842 $$->type = ACT_CT_PATTERN;
1843 $$->value = asn1p_value_frombuf($2.buf, $2.len, 0);
1844 }
1845 | TOK_PATTERN Identifier {
1846 asn1p_ref_t *ref;
1847 $$ = asn1p_constraint_new(yylineno);
1848 $$->type = ACT_CT_PATTERN;
1849 ref = asn1p_ref_new(yylineno);
1850 asn1p_ref_add_component(ref, $2, RLT_lowercase);
1851 $$->value = asn1p_value_fromref(ref, 0);
1852 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001853 ;
1854
1855ConstraintSpec:
1856 TOK_SIZE {
1857 $$ = ACT_CT_SIZE;
1858 }
1859 | TOK_FROM {
1860 $$ = ACT_CT_FROM;
1861 }
1862 ;
1863
Lev Walkinff7dd142005-03-20 12:58:00 +00001864SingleValue:
Lev Walkinc8092cb2005-02-18 16:34:21 +00001865 TOK_FALSE {
1866 $$ = asn1p_value_fromint(0);
1867 checkmem($$);
1868 $$->type = ATV_FALSE;
1869 }
1870 | TOK_TRUE {
1871 $$ = asn1p_value_fromint(1);
1872 checkmem($$);
1873 $$->type = ATV_TRUE;
1874 }
Lev Walkinadf863f2006-09-05 16:18:34 +00001875 | RealValue
1876 | RestrictedCharacterStringValue
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001877 | BitStringValue
Lev Walkinf15320b2004-06-03 03:38:44 +00001878 | Identifier {
1879 asn1p_ref_t *ref;
1880 int ret;
1881 ref = asn1p_ref_new(yylineno);
1882 checkmem(ref);
1883 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1884 checkmem(ret == 0);
1885 $$ = asn1p_value_fromref(ref, 0);
1886 checkmem($$);
1887 free($1);
1888 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001889 ;
1890
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001891BitStringValue:
1892 TOK_bstring {
1893 $$ = _convert_bitstring2binary($1, 'B');
1894 checkmem($$);
1895 }
1896 | TOK_hstring {
1897 $$ = _convert_bitstring2binary($1, 'H');
1898 checkmem($$);
1899 }
1900 ;
1901
Lev Walkinff7dd142005-03-20 12:58:00 +00001902ContainedSubtype:
1903 TypeRefName {
Lev Walkinc8092cb2005-02-18 16:34:21 +00001904 asn1p_ref_t *ref;
1905 int ret;
1906 ref = asn1p_ref_new(yylineno);
1907 checkmem(ref);
1908 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1909 checkmem(ret == 0);
1910 $$ = asn1p_value_fromref(ref, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001911 checkmem($$);
Lev Walkinc8092cb2005-02-18 16:34:21 +00001912 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001913 }
1914 ;
1915
Lev Walkine596bf02005-03-28 15:01:27 +00001916InnerTypeConstraint:
1917 TOK_WITH TOK_COMPONENT SetOfConstraints {
Lev Walkin2c14a692005-08-12 10:08:45 +00001918 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
Lev Walkine596bf02005-03-28 15:01:27 +00001919 }
1920 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001921 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001922 }
1923 ;
1924
1925WithComponentsList:
1926 WithComponentsElement {
1927 $$ = $1;
1928 }
1929 | WithComponentsList ',' WithComponentsElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001930 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001931 }
1932 ;
1933
1934WithComponentsElement:
1935 TOK_ThreeDots {
1936 $$ = asn1p_constraint_new(yylineno);
1937 checkmem($$);
1938 $$->type = ACT_EL_EXT;
Lev Walkin418298d2006-07-13 08:24:20 +00001939 $$->value = asn1p_value_frombuf("...", 3, 1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001940 }
1941 | Identifier optConstraints optPresenceConstraint {
1942 $$ = asn1p_constraint_new(yylineno);
1943 checkmem($$);
1944 $$->type = ACT_EL_VALUE;
1945 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1946 $$->presence = $3;
Lev Walkine596bf02005-03-28 15:01:27 +00001947 if($2) asn1p_constraint_insert($$, $2);
Lev Walkinf15320b2004-06-03 03:38:44 +00001948 }
1949 ;
1950
1951/*
1952 * presence constraint for WithComponents
1953 */
1954optPresenceConstraint:
1955 { $$ = ACPRES_DEFAULT; }
1956 | PresenceConstraint { $$ = $1; }
1957 ;
1958
1959PresenceConstraint:
1960 TOK_PRESENT {
1961 $$ = ACPRES_PRESENT;
1962 }
1963 | TOK_ABSENT {
1964 $$ = ACPRES_ABSENT;
1965 }
1966 | TOK_OPTIONAL {
1967 $$ = ACPRES_OPTIONAL;
1968 }
1969 ;
1970
Lev Walkina9532f42006-09-17 04:52:50 +00001971
1972/* X.682 */
1973GeneralConstraint:
1974 UserDefinedConstraint
1975 | TableConstraint
1976 | ContentsConstraint
1977 ;
1978
1979UserDefinedConstraint:
1980 TOK_CONSTRAINED TOK_BY '{'
1981 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1982 $$ = asn1p_constraint_new(yylineno);
1983 checkmem($$);
1984 $$->type = ACT_CT_CTDBY;
1985 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
1986 checkmem($$->value);
1987 $$->value->type = ATV_UNPARSED;
1988 }
1989 ;
1990
1991ContentsConstraint:
1992 TOK_CONTAINING Type {
1993 $$ = asn1p_constraint_new(yylineno);
1994 $$->type = ACT_CT_CTNG;
1995 $$->value = asn1p_value_fromtype($2);
1996 }
1997 ;
1998
1999ConstraintRangeSpec:
2000 TOK_TwoDots { $$ = ACT_EL_RANGE; }
2001 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
2002 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
2003 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
2004 ;
Lev Walkinf15320b2004-06-03 03:38:44 +00002005TableConstraint:
2006 SimpleTableConstraint {
2007 $$ = $1;
2008 }
2009 | ComponentRelationConstraint {
2010 $$ = $1;
2011 }
2012 ;
2013
2014/*
2015 * "{ExtensionSet}"
2016 */
2017SimpleTableConstraint:
2018 '{' TypeRefName '}' {
2019 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
2020 asn1p_constraint_t *ct;
2021 int ret;
2022 ret = asn1p_ref_add_component(ref, $2, 0);
2023 checkmem(ret == 0);
2024 ct = asn1p_constraint_new(yylineno);
2025 checkmem($$);
2026 ct->type = ACT_EL_VALUE;
2027 ct->value = asn1p_value_fromref(ref, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00002028 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00002029 }
2030 ;
2031
2032ComponentRelationConstraint:
2033 SimpleTableConstraint '{' AtNotationList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00002034 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002035 }
2036 ;
2037
2038AtNotationList:
2039 AtNotationElement {
2040 $$ = asn1p_constraint_new(yylineno);
2041 checkmem($$);
2042 $$->type = ACT_EL_VALUE;
2043 $$->value = asn1p_value_fromref($1, 0);
2044 }
2045 | AtNotationList ',' AtNotationElement {
2046 asn1p_constraint_t *ct;
2047 ct = asn1p_constraint_new(yylineno);
2048 checkmem(ct);
2049 ct->type = ACT_EL_VALUE;
2050 ct->value = asn1p_value_fromref($3, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00002051 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00002052 }
2053 ;
2054
2055/*
2056 * @blah
2057 */
2058AtNotationElement:
2059 '@' ComponentIdList {
2060 char *p = malloc(strlen($2) + 2);
2061 int ret;
2062 *p = '@';
2063 strcpy(p + 1, $2);
2064 $$ = asn1p_ref_new(yylineno);
2065 ret = asn1p_ref_add_component($$, p, 0);
2066 checkmem(ret == 0);
2067 free(p);
2068 free($2);
2069 }
2070 | '@' '.' ComponentIdList {
2071 char *p = malloc(strlen($3) + 3);
2072 int ret;
2073 p[0] = '@';
2074 p[1] = '.';
2075 strcpy(p + 2, $3);
2076 $$ = asn1p_ref_new(yylineno);
2077 ret = asn1p_ref_add_component($$, p, 0);
2078 checkmem(ret == 0);
2079 free(p);
2080 free($3);
2081 }
2082 ;
2083
2084/* identifier "." ... */
2085ComponentIdList:
2086 Identifier {
2087 $$ = $1;
2088 }
2089 | ComponentIdList '.' Identifier {
2090 int l1 = strlen($1);
2091 int l3 = strlen($3);
2092 $$ = malloc(l1 + 1 + l3 + 1);
2093 memcpy($$, $1, l1);
2094 $$[l1] = '.';
2095 memcpy($$ + l1 + 1, $3, l3);
2096 $$[l1 + 1 + l3] = '\0';
2097 }
2098 ;
2099
2100
2101
2102/*
2103 * MARKERS
2104 */
2105
2106optMarker:
Lev Walkin9c974182004-09-15 11:59:51 +00002107 {
2108 $$.flags = EM_NOMARK;
2109 $$.default_value = 0;
2110 }
Lev Walkinf15320b2004-06-03 03:38:44 +00002111 | Marker { $$ = $1; }
2112 ;
2113
2114Marker:
2115 TOK_OPTIONAL {
Lev Walkin70853052005-11-26 11:21:55 +00002116 $$.flags = EM_OPTIONAL | EM_INDIRECT;
Lev Walkin9c974182004-09-15 11:59:51 +00002117 $$.default_value = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +00002118 }
Lev Walkin9c974182004-09-15 11:59:51 +00002119 | TOK_DEFAULT Value {
2120 $$.flags = EM_DEFAULT;
2121 $$.default_value = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00002122 }
2123 ;
2124
2125/*
2126 * Universal enumeration definition to use in INTEGER and ENUMERATED.
2127 * === EXAMPLE ===
2128 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
2129 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
2130 * === EOF ===
2131 */
2132/*
2133optUniverationDefinition:
2134 { $$ = 0; }
2135 | UniverationDefinition {
2136 $$ = $1;
2137 }
2138 ;
2139*/
2140
2141UniverationDefinition:
2142 '{' '}' {
Lev Walkina9532f42006-09-17 04:52:50 +00002143 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002144 checkmem($$);
2145 }
2146 | '{' UniverationList '}' {
2147 $$ = $2;
2148 }
2149 ;
2150
2151UniverationList:
2152 UniverationElement {
Lev Walkina9532f42006-09-17 04:52:50 +00002153 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002154 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00002155 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00002156 }
2157 | UniverationList ',' UniverationElement {
2158 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00002159 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002160 }
2161 ;
2162
2163UniverationElement:
2164 Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +00002165 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002166 checkmem($$);
2167 $$->expr_type = A1TC_UNIVERVAL;
2168 $$->meta_type = AMT_VALUE;
2169 $$->Identifier = $1;
2170 }
2171 | Identifier '(' SignedNumber ')' {
Lev Walkina9532f42006-09-17 04:52:50 +00002172 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002173 checkmem($$);
2174 $$->expr_type = A1TC_UNIVERVAL;
2175 $$->meta_type = AMT_VALUE;
2176 $$->Identifier = $1;
2177 $$->value = $3;
2178 }
2179 | Identifier '(' DefinedValue ')' {
Lev Walkina9532f42006-09-17 04:52:50 +00002180 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002181 checkmem($$);
2182 $$->expr_type = A1TC_UNIVERVAL;
2183 $$->meta_type = AMT_VALUE;
2184 $$->Identifier = $1;
2185 $$->value = $3;
2186 }
2187 | SignedNumber {
Lev Walkina9532f42006-09-17 04:52:50 +00002188 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002189 checkmem($$);
2190 $$->expr_type = A1TC_UNIVERVAL;
2191 $$->meta_type = AMT_VALUE;
2192 $$->value = $1;
2193 }
2194 | TOK_ThreeDots {
Lev Walkina9532f42006-09-17 04:52:50 +00002195 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002196 checkmem($$);
2197 $$->Identifier = strdup("...");
2198 checkmem($$->Identifier);
2199 $$->expr_type = A1TC_EXTENSIBLE;
2200 $$->meta_type = AMT_VALUE;
2201 }
2202 ;
2203
2204SignedNumber:
2205 TOK_number {
2206 $$ = asn1p_value_fromint($1);
2207 checkmem($$);
2208 }
2209 | TOK_number_negative {
2210 $$ = asn1p_value_fromint($1);
2211 checkmem($$);
2212 }
2213 ;
2214
Lev Walkinadf863f2006-09-05 16:18:34 +00002215RealValue:
2216 SignedNumber
2217 | TOK_realnumber {
2218 $$ = asn1p_value_fromdouble($1);
2219 checkmem($$);
2220 }
2221 ;
2222
Lev Walkinf15320b2004-06-03 03:38:44 +00002223/*
2224 * SEQUENCE definition.
2225 * === EXAMPLE ===
2226 * Struct1 ::= SEQUENCE {
2227 * memb1 Struct2,
2228 * memb2 SEQUENCE OF {
2229 * memb2-1 Struct 3
2230 * }
2231 * }
2232 * === EOF ===
2233 */
2234
2235
2236
2237/*
2238 * SET definition.
2239 * === EXAMPLE ===
2240 * Person ::= SET {
2241 * name [0] PrintableString (SIZE(1..20)),
2242 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2243 * }
2244 * === EOF ===
2245 */
2246
2247optTag:
2248 { memset(&$$, 0, sizeof($$)); }
2249 | Tag { $$ = $1; }
2250 ;
2251
2252Tag:
Lev Walkinc603f102005-01-23 09:51:44 +00002253 TagTypeValue TagPlicit {
Lev Walkinf15320b2004-06-03 03:38:44 +00002254 $$ = $1;
Lev Walkinc603f102005-01-23 09:51:44 +00002255 $$.tag_mode = $2.tag_mode;
Lev Walkinf15320b2004-06-03 03:38:44 +00002256 }
Lev Walkinc603f102005-01-23 09:51:44 +00002257 ;
2258
2259TagTypeValue:
2260 '[' TagClass TOK_number ']' {
2261 $$ = $2;
2262 $$.tag_value = $3;
2263 };
2264
2265TagClass:
2266 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2267 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2268 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2269 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2270 ;
2271
2272TagPlicit:
2273 { $$.tag_mode = TM_DEFAULT; }
2274 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2275 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
Lev Walkinf15320b2004-06-03 03:38:44 +00002276 ;
2277
2278TypeRefName:
2279 TOK_typereference {
2280 checkmem($1);
2281 $$ = $1;
2282 }
Lev Walkinf59d0752004-08-18 04:59:12 +00002283 | TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002284 checkmem($1);
2285 $$ = $1;
2286 }
2287 ;
2288
Lev Walkinf59d0752004-08-18 04:59:12 +00002289
Lev Walkinf15320b2004-06-03 03:38:44 +00002290ObjectClassReference:
Lev Walkinf59d0752004-08-18 04:59:12 +00002291 TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002292 checkmem($1);
2293 $$ = $1;
2294 }
2295 ;
2296
Lev Walkin83cac2f2004-09-22 16:03:36 +00002297optIdentifier:
2298 { $$ = 0; }
2299 | Identifier {
2300 $$ = $1;
2301 }
Lev Walkin8f294e02005-06-06 08:28:58 +00002302 ;
Lev Walkin83cac2f2004-09-22 16:03:36 +00002303
Lev Walkinf15320b2004-06-03 03:38:44 +00002304Identifier:
2305 TOK_identifier {
2306 checkmem($1);
2307 $$ = $1;
2308 }
2309 ;
2310
Lev Walkinf15320b2004-06-03 03:38:44 +00002311%%
2312
2313
2314/*
2315 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2316 */
2317static asn1p_value_t *
2318_convert_bitstring2binary(char *str, int base) {
2319 asn1p_value_t *val;
2320 int slen;
2321 int memlen;
2322 int baselen;
2323 int bits;
2324 uint8_t *binary_vector;
2325 uint8_t *bv_ptr;
2326 uint8_t cur_val;
2327
2328 assert(str);
2329 assert(str[0] == '\'');
2330
2331 switch(base) {
2332 case 'B':
2333 baselen = 1;
2334 break;
2335 case 'H':
2336 baselen = 4;
2337 break;
2338 default:
2339 assert(base == 'B' || base == 'H');
2340 errno = EINVAL;
2341 return NULL;
2342 }
2343
2344 slen = strlen(str);
2345 assert(str[slen - 1] == base);
2346 assert(str[slen - 2] == '\'');
2347
2348 memlen = slen / (8 / baselen); /* Conservative estimate */
2349
2350 bv_ptr = binary_vector = malloc(memlen + 1);
2351 if(bv_ptr == NULL)
2352 /* ENOMEM */
2353 return NULL;
2354
2355 cur_val = 0;
2356 bits = 0;
2357 while(*(++str) != '\'') {
2358 switch(baselen) {
2359 case 1:
2360 switch(*str) {
2361 case '1':
2362 cur_val |= 1 << (7 - (bits % 8));
2363 case '0':
2364 break;
2365 default:
2366 assert(!"_y UNREACH1");
2367 case ' ': case '\r': case '\n':
2368 continue;
2369 }
2370 break;
2371 case 4:
2372 switch(*str) {
2373 case '0': case '1': case '2': case '3': case '4':
2374 case '5': case '6': case '7': case '8': case '9':
2375 cur_val |= (*str - '0') << (4 - (bits % 8));
2376 break;
2377 case 'A': case 'B': case 'C':
2378 case 'D': case 'E': case 'F':
2379 cur_val |= ((*str - 'A') + 10)
2380 << (4 - (bits % 8));
2381 break;
2382 default:
2383 assert(!"_y UNREACH2");
2384 case ' ': case '\r': case '\n':
2385 continue;
2386 }
2387 break;
2388 }
2389
2390 bits += baselen;
2391 if((bits % 8) == 0) {
2392 *bv_ptr++ = cur_val;
2393 cur_val = 0;
2394 }
2395 }
2396
2397 *bv_ptr = cur_val;
2398 assert((bv_ptr - binary_vector) <= memlen);
2399
2400 val = asn1p_value_frombits(binary_vector, bits, 0);
2401 if(val == NULL) {
2402 free(binary_vector);
2403 }
2404
2405 return val;
2406}
2407
Lev Walkin2e9bd5c2005-08-13 09:07:11 +00002408/*
2409 * For unnamed types (used in old X.208 compliant modules)
2410 * generate some sort of interim names, to not to force human being to fix
2411 * the specification's compliance to modern ASN.1 standards.
2412 */
2413static void
2414_fixup_anonymous_identifier(asn1p_expr_t *expr) {
2415 char *p;
2416 assert(expr->Identifier == 0);
2417
2418 /*
2419 * Try to figure out the type name
2420 * without going too much into details
2421 */
2422 expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type);
2423 if(expr->reference && expr->reference->comp_count > 0)
2424 expr->Identifier = expr->reference->components[0].name;
2425
2426 fprintf(stderr,
2427 "WARNING: Line %d: expected lower-case member identifier, "
2428 "found an unnamed %s.\n"
2429 "WARNING: Obsolete X.208 syntax detected, "
2430 "please give the member a name.\n",
2431 yylineno, expr->Identifier ? expr->Identifier : "type");
2432
2433 if(!expr->Identifier)
2434 expr->Identifier = "unnamed";
2435 expr->Identifier = strdup(expr->Identifier);
2436 assert(expr->Identifier);
2437 /* Make a lowercase identifier from the type name */
2438 for(p = expr->Identifier; *p; p++) {
2439 switch(*p) {
2440 case 'A' ... 'Z': *p += 32; break;
2441 case ' ': *p = '_'; break;
2442 case '-': *p = '_'; break;
2443 }
2444 }
2445 fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". "
2446 "Name clash may occur later.\n",
2447 expr->Identifier);
2448}
2449
Lev Walkinf15320b2004-06-03 03:38:44 +00002450int
2451yyerror(const char *msg) {
Lev Walkin9d542d22006-03-14 16:31:37 +00002452 extern char *asn1p_text;
Lev Walkinf15320b2004-06-03 03:38:44 +00002453 fprintf(stderr,
2454 "ASN.1 grammar parse error "
2455 "near line %d (token \"%s\"): %s\n",
Lev Walkinceb20e72004-09-05 10:40:41 +00002456 yylineno, asn1p_text, msg);
Lev Walkinf15320b2004-06-03 03:38:44 +00002457 return -1;
2458}
2459