blob: 61b1e3e805ad9c95ccec19341c3ae161ca379ee6 [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; \
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +080051 root = asn1p_constraint_new(yylineno, currentModule); \
Lev Walkin1ed22092005-08-12 10:06:17 +000052 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
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800318%type <a_constr> ConstraintSpecs
Lev Walkina9532f42006-09-17 04:52:50 +0000319%type <a_constr> GeneralConstraint
Lev Walkinf59d0752004-08-18 04:59:12 +0000320%type <a_constr> SetOfConstraints
321%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
322%type <a_constr> ElementSetSpec /* 1..2,...,3 */
Lev Walkinf1727152006-09-21 01:50:37 +0000323%type <a_constr> Unions
324%type <a_constr> Intersections
325%type <a_constr> IntersectionElements
Lev Walkinf15320b2004-06-03 03:38:44 +0000326%type <a_constr> ConstraintSubtypeElement /* 1..2 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000327%type <a_constr> SimpleTableConstraint
Lev Walkina9532f42006-09-17 04:52:50 +0000328%type <a_constr> UserDefinedConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +0000329%type <a_constr> TableConstraint
Lev Walkina9532f42006-09-17 04:52:50 +0000330%type <a_constr> ContentsConstraint
Lev Walkin5c541f12006-10-18 18:40:14 +0000331%type <a_constr> PatternConstraint
Lev Walkine596bf02005-03-28 15:01:27 +0000332%type <a_constr> InnerTypeConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +0000333%type <a_constr> WithComponentsList
334%type <a_constr> WithComponentsElement
335%type <a_constr> ComponentRelationConstraint
336%type <a_constr> AtNotationList
337%type <a_ref> AtNotationElement
Lev Walkinff7dd142005-03-20 12:58:00 +0000338%type <a_value> SingleValue
339%type <a_value> ContainedSubtype
Lev Walkinf15320b2004-06-03 03:38:44 +0000340%type <a_ctype> ConstraintSpec
341%type <a_ctype> ConstraintRangeSpec
Lev Walkin1e448d32005-03-24 14:26:38 +0000342%type <a_value> RestrictedCharacterStringValue
Lev Walkinf15320b2004-06-03 03:38:44 +0000343%type <a_wsynt> optWithSyntax
344%type <a_wsynt> WithSyntax
Lev Walkin9d542d22006-03-14 16:31:37 +0000345%type <a_wsynt> WithSyntaxList
346%type <a_wchunk> WithSyntaxToken
Lev Walkinf15320b2004-06-03 03:38:44 +0000347%type <a_marker> optMarker Marker
348%type <a_int> optUnique
349%type <a_pres> optPresenceConstraint PresenceConstraint
350%type <tv_str> ComponentIdList
Lev Walkinef625402005-09-05 05:17:57 +0000351%type <a_int> NSTD_IndirectMarker
Lev Walkinf15320b2004-06-03 03:38:44 +0000352
353
354%%
355
356
357ParsedGrammar:
358 ModuleList {
359 *(void **)param = $1;
360 }
361 ;
362
363ModuleList:
Lev Walkin866bd7f2006-09-14 10:35:20 +0000364 ModuleDefinition {
Lev Walkinf15320b2004-06-03 03:38:44 +0000365 $$ = asn1p_new();
366 checkmem($$);
367 TQ_ADD(&($$->modules), $1, mod_next);
368 }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000369 | ModuleList ModuleDefinition {
Lev Walkinf15320b2004-06-03 03:38:44 +0000370 $$ = $1;
371 TQ_ADD(&($$->modules), $2, mod_next);
372 }
373 ;
374
375/*
376 * ASN module definition.
377 * === EXAMPLE ===
378 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
379 * BEGIN
380 * ...
381 * END
382 * === EOF ===
383 */
384
Lev Walkin866bd7f2006-09-14 10:35:20 +0000385ModuleDefinition:
Lev Walkina9532f42006-09-17 04:52:50 +0000386 TypeRefName { currentModule = asn1p_module_new(); }
387 optObjectIdentifier TOK_DEFINITIONS
Lev Walkin866bd7f2006-09-14 10:35:20 +0000388 optModuleDefinitionFlags
Lev Walkinf15320b2004-06-03 03:38:44 +0000389 TOK_PPEQ TOK_BEGIN
Lev Walkin866bd7f2006-09-14 10:35:20 +0000390 optModuleBody
Lev Walkinf15320b2004-06-03 03:38:44 +0000391 TOK_END {
392
Lev Walkina9532f42006-09-17 04:52:50 +0000393 $$ = currentModule;
394
395 if($8) {
396 asn1p_module_t tmp = *($$);
397 *($$) = *($8);
398 *($8) = tmp;
399 asn1p_module_free($8);
Lev Walkinf15320b2004-06-03 03:38:44 +0000400 } else {
401 /* There's a chance that a module is just plain empty */
Lev Walkinf15320b2004-06-03 03:38:44 +0000402 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000403
Lev Walkin1ed22092005-08-12 10:06:17 +0000404 $$->ModuleName = $1;
Lev Walkina9532f42006-09-17 04:52:50 +0000405 $$->module_oid = $3;
406 $$->module_flags = $5;
Lev Walkinf15320b2004-06-03 03:38:44 +0000407 }
408 ;
409
410/*
411 * Object Identifier Definition
412 * { iso member-body(2) 3 }
413 */
414optObjectIdentifier:
415 { $$ = 0; }
416 | ObjectIdentifier { $$ = $1; }
417 ;
418
419ObjectIdentifier:
420 '{' ObjectIdentifierBody '}' {
421 $$ = $2;
422 }
423 | '{' '}' {
424 $$ = 0;
425 }
426 ;
427
428ObjectIdentifierBody:
429 ObjectIdentifierElement {
430 $$ = asn1p_oid_new();
431 asn1p_oid_add_arc($$, &$1);
432 if($1.name)
433 free($1.name);
434 }
435 | ObjectIdentifierBody ObjectIdentifierElement {
436 $$ = $1;
437 asn1p_oid_add_arc($$, &$2);
438 if($2.name)
439 free($2.name);
440 }
441 ;
442
443ObjectIdentifierElement:
444 Identifier { /* iso */
445 $$.name = $1;
446 $$.number = -1;
447 }
448 | Identifier '(' TOK_number ')' { /* iso(1) */
449 $$.name = $1;
450 $$.number = $3;
451 }
452 | TOK_number { /* 1 */
453 $$.name = 0;
454 $$.number = $1;
455 }
456 ;
457
458/*
459 * Optional module flags.
460 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000461optModuleDefinitionFlags:
Lev Walkinf15320b2004-06-03 03:38:44 +0000462 { $$ = MSF_NOFLAGS; }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000463 | ModuleDefinitionFlags {
Lev Walkinf15320b2004-06-03 03:38:44 +0000464 $$ = $1;
465 }
466 ;
467
468/*
469 * Module flags.
470 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000471ModuleDefinitionFlags:
472 ModuleDefinitionFlag {
Lev Walkinf15320b2004-06-03 03:38:44 +0000473 $$ = $1;
474 }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000475 | ModuleDefinitionFlags ModuleDefinitionFlag {
Lev Walkinf15320b2004-06-03 03:38:44 +0000476 $$ = $1 | $2;
477 }
478 ;
479
480/*
481 * Single module flag.
482 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000483ModuleDefinitionFlag:
Lev Walkinf15320b2004-06-03 03:38:44 +0000484 TOK_EXPLICIT TOK_TAGS {
485 $$ = MSF_EXPLICIT_TAGS;
486 }
487 | TOK_IMPLICIT TOK_TAGS {
488 $$ = MSF_IMPLICIT_TAGS;
489 }
490 | TOK_AUTOMATIC TOK_TAGS {
491 $$ = MSF_AUTOMATIC_TAGS;
492 }
493 | TOK_EXTENSIBILITY TOK_IMPLIED {
494 $$ = MSF_EXTENSIBILITY_IMPLIED;
495 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000496 /* EncodingReferenceDefault */
497 | TOK_capitalreference TOK_INSTRUCTIONS {
498 /* X.680Amd1 specifies TAG and XER */
499 if(strcmp($1, "TAG") == 0) {
500 $$ = MSF_TAG_INSTRUCTIONS;
501 } else if(strcmp($1, "XER") == 0) {
502 $$ = MSF_XER_INSTRUCTIONS;
503 } else {
504 fprintf(stderr,
505 "WARNING: %s INSTRUCTIONS at line %d: "
506 "Unrecognized encoding reference\n",
507 $1, yylineno);
508 $$ = MSF_unk_INSTRUCTIONS;
509 }
510 free($1);
511 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000512 ;
513
514/*
515 * Optional module body.
516 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000517optModuleBody:
Lev Walkinf15320b2004-06-03 03:38:44 +0000518 { $$ = 0; }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000519 | ModuleBody {
Lev Walkinf15320b2004-06-03 03:38:44 +0000520 $$ = $1;
521 }
522 ;
523
524/*
525 * ASN.1 Module body.
526 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000527ModuleBody:
528 optExports optImports AssignmentList {
529 $$ = asn1p_module_new();
530 AL_IMPORT($$, exports, $1, xp_next);
531 AL_IMPORT($$, imports, $2, xp_next);
532 AL_IMPORT($$, members, $3, next);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800533
534 asn1p_module_free($1);
535 asn1p_module_free($2);
536 asn1p_module_free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000537 }
538 ;
539
Lev Walkin866bd7f2006-09-14 10:35:20 +0000540AssignmentList:
541 Assignment {
542 $$ = $1;
543 }
544 | AssignmentList Assignment {
545 if($1) {
546 $$ = $1;
547 } else {
548 $$ = $2;
549 break;
550 }
551 AL_IMPORT($$, members, $2, next);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800552 asn1p_module_free($2);
Lev Walkin866bd7f2006-09-14 10:35:20 +0000553 }
554 ;
555
556
Lev Walkinf15320b2004-06-03 03:38:44 +0000557/*
558 * One of the elements of ASN.1 module specification.
559 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000560Assignment:
561 DataTypeReference {
Lev Walkinf15320b2004-06-03 03:38:44 +0000562 $$ = asn1p_module_new();
563 checkmem($$);
564 assert($1->expr_type != A1TC_INVALID);
565 assert($1->meta_type != AMT_INVALID);
566 TQ_ADD(&($$->members), $1, next);
567 }
Lev Walkinc6ab03c2006-10-21 05:54:49 +0000568 | ValueAssignment {
Lev Walkinf15320b2004-06-03 03:38:44 +0000569 $$ = asn1p_module_new();
570 checkmem($$);
571 assert($1->expr_type != A1TC_INVALID);
572 assert($1->meta_type != AMT_INVALID);
573 TQ_ADD(&($$->members), $1, next);
574 }
575 /*
576 * Value set definition
577 * === EXAMPLE ===
578 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
579 * === EOF ===
580 */
Lev Walkin557f27d2006-03-21 07:46:48 +0000581 | ValueSetTypeAssignment {
Lev Walkinf15320b2004-06-03 03:38:44 +0000582 $$ = asn1p_module_new();
583 checkmem($$);
584 assert($1->expr_type != A1TC_INVALID);
585 assert($1->meta_type != AMT_INVALID);
586 TQ_ADD(&($$->members), $1, next);
587 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000588 | TOK_ENCODING_CONTROL TOK_capitalreference
589 { asn1p_lexer_hack_push_encoding_control(); }
590 {
591 fprintf(stderr,
592 "WARNING: ENCODING-CONTROL %s "
593 "specification at line %d ignored\n",
594 $2, yylineno);
595 free($2);
596 $$ = 0;
597 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000598
599 /*
600 * Erroneous attemps
601 */
602 | BasicString {
603 return yyerror(
Lev Walkin70853052005-11-26 11:21:55 +0000604 "Attempt to redefine a standard basic string type, "
605 "please comment out or remove this type redefinition.");
Lev Walkinf15320b2004-06-03 03:38:44 +0000606 }
607 ;
608
609/*
610 * === EXAMPLE ===
611 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
612 * === EOF ===
613 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000614optImports:
615 { $$ = 0; }
616 | ImportsDefinition;
617
Lev Walkinf15320b2004-06-03 03:38:44 +0000618ImportsDefinition:
Lev Walkin4a4543f2006-10-13 12:37:39 +0000619 TOK_IMPORTS optImportsBundleSet ';' {
Lev Walkin1ed22092005-08-12 10:06:17 +0000620 if(!saved_aid && 0)
621 return yyerror("Unterminated IMPORTS FROM, "
622 "expected semicolon ';'");
623 saved_aid = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +0000624 $$ = $2;
625 }
626 /*
627 * Some error cases.
628 */
629 | TOK_IMPORTS TOK_FROM /* ... */ {
630 return yyerror("Empty IMPORTS list");
631 }
632 ;
633
Lev Walkin4a4543f2006-10-13 12:37:39 +0000634optImportsBundleSet:
635 { $$ = asn1p_module_new(); }
636 | ImportsBundleSet;
637
Lev Walkinf15320b2004-06-03 03:38:44 +0000638ImportsBundleSet:
639 ImportsBundle {
640 $$ = asn1p_module_new();
641 checkmem($$);
642 TQ_ADD(&($$->imports), $1, xp_next);
643 }
644 | ImportsBundleSet ImportsBundle {
645 $$ = $1;
646 TQ_ADD(&($$->imports), $2, xp_next);
647 }
648 ;
649
Lev Walkin1ed22092005-08-12 10:06:17 +0000650AssignedIdentifier:
651 { memset(&$$, 0, sizeof($$)); }
652 | ObjectIdentifier { $$.oid = $1; };
653 /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
654
Lev Walkinf15320b2004-06-03 03:38:44 +0000655ImportsBundle:
Lev Walkin1ed22092005-08-12 10:06:17 +0000656 ImportsList TOK_FROM TypeRefName AssignedIdentifier {
Lev Walkinf15320b2004-06-03 03:38:44 +0000657 $$ = $1;
Lev Walkin1ed22092005-08-12 10:06:17 +0000658 $$->fromModuleName = $3;
659 $$->identifier = $4;
660 /* This stupid thing is used for look-back hack. */
661 saved_aid = $$->identifier.oid ? 0 : &($$->identifier);
Lev Walkinf15320b2004-06-03 03:38:44 +0000662 checkmem($$);
663 }
664 ;
665
666ImportsList:
667 ImportsElement {
668 $$ = asn1p_xports_new();
669 checkmem($$);
670 TQ_ADD(&($$->members), $1, next);
671 }
672 | ImportsList ',' ImportsElement {
673 $$ = $1;
674 TQ_ADD(&($$->members), $3, next);
675 }
676 ;
677
678ImportsElement:
679 TypeRefName {
Lev Walkina9532f42006-09-17 04:52:50 +0000680 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000681 checkmem($$);
682 $$->Identifier = $1;
683 $$->expr_type = A1TC_REFERENCE;
684 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000685 | TypeRefName '{' '}' { /* Completely equivalent to above */
Lev Walkina9532f42006-09-17 04:52:50 +0000686 $$ = NEW_EXPR();
Lev Walkin144db9b2004-10-12 23:26:53 +0000687 checkmem($$);
688 $$->Identifier = $1;
689 $$->expr_type = A1TC_REFERENCE;
690 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000691 | Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +0000692 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000693 checkmem($$);
694 $$->Identifier = $1;
695 $$->expr_type = A1TC_REFERENCE;
696 }
697 ;
698
Lev Walkin866bd7f2006-09-14 10:35:20 +0000699
700optExports:
701 { $$ = 0; }
702 | ExportsDefinition {
703 $$ = asn1p_module_new();
704 checkmem($$);
705 if($1) {
706 TQ_ADD(&($$->exports), $1, xp_next);
707 } else {
708 /* "EXPORTS ALL;" */
709 }
710 }
711 ;
712
Lev Walkinf15320b2004-06-03 03:38:44 +0000713ExportsDefinition:
714 TOK_EXPORTS ExportsBody ';' {
715 $$ = $2;
716 }
717 | TOK_EXPORTS TOK_ALL ';' {
718 $$ = 0;
719 }
720 | TOK_EXPORTS ';' {
721 /* Empty EXPORTS clause effectively prohibits export. */
722 $$ = asn1p_xports_new();
723 checkmem($$);
724 }
725 ;
726
727ExportsBody:
728 ExportsElement {
729 $$ = asn1p_xports_new();
730 assert($$);
731 TQ_ADD(&($$->members), $1, next);
732 }
733 | ExportsBody ',' ExportsElement {
734 $$ = $1;
735 TQ_ADD(&($$->members), $3, next);
736 }
737 ;
738
739ExportsElement:
740 TypeRefName {
Lev Walkina9532f42006-09-17 04:52:50 +0000741 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000742 checkmem($$);
743 $$->Identifier = $1;
744 $$->expr_type = A1TC_EXPORTVAR;
745 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000746 | TypeRefName '{' '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000747 $$ = NEW_EXPR();
Lev Walkin144db9b2004-10-12 23:26:53 +0000748 checkmem($$);
749 $$->Identifier = $1;
750 $$->expr_type = A1TC_EXPORTVAR;
751 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000752 | Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +0000753 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000754 checkmem($$);
755 $$->Identifier = $1;
756 $$->expr_type = A1TC_EXPORTVAR;
757 }
758 ;
759
760
Lev Walkin418298d2006-07-13 08:24:20 +0000761ValueSet: '{' ElementSetSpecs '}' { $$ = $2; };
Lev Walkin557f27d2006-03-21 07:46:48 +0000762
763ValueSetTypeAssignment:
764 TypeRefName DefinedType TOK_PPEQ ValueSet {
Lev Walkinf15320b2004-06-03 03:38:44 +0000765 $$ = $2;
766 assert($$->Identifier == 0);
767 $$->Identifier = $1;
768 $$->meta_type = AMT_VALUESET;
Lev Walkin557f27d2006-03-21 07:46:48 +0000769 $$->constraints = $4;
Lev Walkinf15320b2004-06-03 03:38:44 +0000770 }
771 ;
772
Lev Walkin0c0bca62006-03-21 04:48:15 +0000773DefinedType:
774 BasicType {
775 $$ = $1;
776 }
777 /*
778 * A DefinedType reference.
779 * "CLASS1.&id.&id2"
780 * or
781 * "Module.Type"
782 * or
783 * "Module.identifier"
784 * or
785 * "Type"
786 */
787 | ComplexTypeReference {
Lev Walkina9532f42006-09-17 04:52:50 +0000788 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000789 checkmem($$);
790 $$->reference = $1;
791 $$->expr_type = A1TC_REFERENCE;
792 $$->meta_type = AMT_TYPEREF;
793 }
Lev Walkin0c0bca62006-03-21 04:48:15 +0000794 /*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000795 * A parameterized assignment.
Lev Walkin0c0bca62006-03-21 04:48:15 +0000796 */
Lev Walkin5045dfa2006-03-21 09:41:28 +0000797 | ComplexTypeReference '{' ActualParameterList '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000798 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000799 checkmem($$);
Lev Walkin0c0bca62006-03-21 04:48:15 +0000800 $$->reference = $1;
801 $$->rhs_pspecs = $3;
802 $$->expr_type = A1TC_REFERENCE;
803 $$->meta_type = AMT_TYPEREF;
Lev Walkinf15320b2004-06-03 03:38:44 +0000804 }
805 ;
806
Lev Walkinf15320b2004-06-03 03:38:44 +0000807/*
808 * Data Type Reference.
809 * === EXAMPLE ===
810 * Type3 ::= CHOICE { a Type1, b Type 2 }
811 * === EOF ===
812 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000813DataTypeReference:
814 /*
815 * Optionally tagged type definition.
816 */
Lev Walkin9c2285a2006-03-09 08:49:26 +0000817 TypeRefName TOK_PPEQ Type {
Lev Walkinaf120f72004-09-14 02:36:39 +0000818 $$ = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000819 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000820 assert($$->expr_type);
821 assert($$->meta_type);
822 }
Lev Walkin9c2285a2006-03-09 08:49:26 +0000823 | TypeRefName TOK_PPEQ ObjectClass {
Lev Walkinf15320b2004-06-03 03:38:44 +0000824 $$ = $3;
825 $$->Identifier = $1;
826 assert($$->expr_type == A1TC_CLASSDEF);
Lev Walkin9c2285a2006-03-09 08:49:26 +0000827 assert($$->meta_type == AMT_OBJECTCLASS);
Lev Walkinf15320b2004-06-03 03:38:44 +0000828 }
829 /*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000830 * Parameterized <Type> declaration:
Lev Walkinf15320b2004-06-03 03:38:44 +0000831 * === EXAMPLE ===
832 * SIGNED { ToBeSigned } ::= SEQUENCE {
833 * toBeSigned ToBeSigned,
834 * algorithm AlgorithmIdentifier,
835 * signature BIT STRING
836 * }
837 * === EOF ===
838 */
Lev Walkin070a52d2004-08-22 03:19:54 +0000839 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000840 $$ = $6;
Lev Walkin5045dfa2006-03-21 09:41:28 +0000841 $$->Identifier = $1;
842 $$->lhs_params = $3;
843 }
844 /* Parameterized CLASS declaration */
845 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ ObjectClass {
846 $$ = $6;
Lev Walkinf15320b2004-06-03 03:38:44 +0000847 $$->Identifier = $1;
Lev Walkina00d6b32006-03-21 03:40:38 +0000848 $$->lhs_params = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000849 }
850 ;
851
852ParameterArgumentList:
853 ParameterArgumentName {
854 int ret;
855 $$ = asn1p_paramlist_new(yylineno);
856 checkmem($$);
857 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
858 checkmem(ret == 0);
Lev Walkina964e032017-03-26 03:48:06 -0700859 asn1p_ref_free($1.governor);
860 free($1.argument);
Lev Walkinf15320b2004-06-03 03:38:44 +0000861 }
862 | ParameterArgumentList ',' ParameterArgumentName {
863 int ret;
864 $$ = $1;
865 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
866 checkmem(ret == 0);
Lev Walkina964e032017-03-26 03:48:06 -0700867 asn1p_ref_free($3.governor);
868 free($3.argument);
Lev Walkinf15320b2004-06-03 03:38:44 +0000869 }
870 ;
871
872ParameterArgumentName:
873 TypeRefName {
874 $$.governor = NULL;
875 $$.argument = $1;
876 }
877 | TypeRefName ':' Identifier {
878 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800879 $$.governor = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +0000880 ret = asn1p_ref_add_component($$.governor, $1, 0);
881 checkmem(ret == 0);
882 $$.argument = $3;
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800883 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000884 }
Lev Walkinc8092cb2005-02-18 16:34:21 +0000885 | TypeRefName ':' TypeRefName {
886 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800887 $$.governor = asn1p_ref_new(yylineno, currentModule);
Lev Walkinc8092cb2005-02-18 16:34:21 +0000888 ret = asn1p_ref_add_component($$.governor, $1, 0);
889 checkmem(ret == 0);
890 $$.argument = $3;
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800891 free($1);
Lev Walkinc8092cb2005-02-18 16:34:21 +0000892 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000893 | BasicTypeId ':' Identifier {
894 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800895 $$.governor = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +0000896 ret = asn1p_ref_add_component($$.governor,
897 ASN_EXPR_TYPE2STR($1), 1);
898 checkmem(ret == 0);
899 $$.argument = $3;
900 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000901 | BasicTypeId ':' TypeRefName {
902 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800903 $$.governor = asn1p_ref_new(yylineno, currentModule);
Lev Walkin5045dfa2006-03-21 09:41:28 +0000904 ret = asn1p_ref_add_component($$.governor,
905 ASN_EXPR_TYPE2STR($1), 1);
906 checkmem(ret == 0);
907 $$.argument = $3;
908 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000909 ;
910
Lev Walkin5045dfa2006-03-21 09:41:28 +0000911ActualParameterList:
912 ActualParameter {
Lev Walkina9532f42006-09-17 04:52:50 +0000913 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000914 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000915 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000916 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000917 | ActualParameterList ',' ActualParameter {
Lev Walkinf15320b2004-06-03 03:38:44 +0000918 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000919 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000920 }
921 ;
922
Lev Walkin5045dfa2006-03-21 09:41:28 +0000923ActualParameter:
Lev Walkin070a52d2004-08-22 03:19:54 +0000924 Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000925 $$ = $1;
926 }
Lev Walkin0c0bca62006-03-21 04:48:15 +0000927 | SimpleValue {
Lev Walkina9532f42006-09-17 04:52:50 +0000928 $$ = NEW_EXPR();
Lev Walkin0c0bca62006-03-21 04:48:15 +0000929 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800930 $$->Identifier = strdup("?");
Lev Walkin0c0bca62006-03-21 04:48:15 +0000931 $$->expr_type = A1TC_REFERENCE;
932 $$->meta_type = AMT_VALUE;
933 $$->value = $1;
934 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000935 | Identifier {
Lev Walkina00d6b32006-03-21 03:40:38 +0000936 asn1p_ref_t *ref;
Lev Walkina9532f42006-09-17 04:52:50 +0000937 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000938 checkmem($$);
939 $$->Identifier = $1;
940 $$->expr_type = A1TC_REFERENCE;
941 $$->meta_type = AMT_VALUE;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800942 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkina00d6b32006-03-21 03:40:38 +0000943 asn1p_ref_add_component(ref, $1, RLT_lowercase);
944 $$->value = asn1p_value_fromref(ref, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +0000945 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000946 | ValueSet {
Lev Walkina9532f42006-09-17 04:52:50 +0000947 $$ = NEW_EXPR();
Lev Walkin5045dfa2006-03-21 09:41:28 +0000948 $$->expr_type = A1TC_VALUESET;
949 $$->meta_type = AMT_VALUESET;
950 $$->constraints = $1;
951 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000952 ;
953
954/*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000955 | '{' ActualParameter '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000956 $$ = NEW_EXPR();
Lev Walkinc8092cb2005-02-18 16:34:21 +0000957 checkmem($$);
958 asn1p_expr_add($$, $2);
959 $$->expr_type = A1TC_PARAMETRIZED;
960 $$->meta_type = AMT_TYPE;
961 }
962 ;
963*/
964
965/*
Lev Walkinf15320b2004-06-03 03:38:44 +0000966 * A collection of constructed data type members.
967 */
Lev Walkin144db9b2004-10-12 23:26:53 +0000968optComponentTypeLists:
Lev Walkina9532f42006-09-17 04:52:50 +0000969 { $$ = NEW_EXPR(); }
Lev Walkin144db9b2004-10-12 23:26:53 +0000970 | ComponentTypeLists { $$ = $1; };
971
Lev Walkin070a52d2004-08-22 03:19:54 +0000972ComponentTypeLists:
973 ComponentType {
Lev Walkina9532f42006-09-17 04:52:50 +0000974 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000975 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000976 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000977 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000978 | ComponentTypeLists ',' ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +0000979 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000980 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000981 }
Lev Walkin0e90aa02013-03-19 16:17:13 -0700982 | ComponentTypeLists ',' TOK_VBracketLeft ComponentTypeLists TOK_VBracketRight {
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800983 $$ = $1;
Lev Walkin0e90aa02013-03-19 16:17:13 -0700984 asn1p_expr_add_many($$, $4);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800985 asn1p_expr_free($4);
Lev Walkin0e90aa02013-03-19 16:17:13 -0700986 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000987 ;
988
Lev Walkin070a52d2004-08-22 03:19:54 +0000989ComponentType:
Lev Walkinaf120f72004-09-14 02:36:39 +0000990 Identifier Type optMarker {
Lev Walkin070a52d2004-08-22 03:19:54 +0000991 $$ = $2;
992 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +0000993 $$->Identifier = $1;
Lev Walkinef625402005-09-05 05:17:57 +0000994 $3.flags |= $$->marker.flags;
Lev Walkin070a52d2004-08-22 03:19:54 +0000995 $$->marker = $3;
996 }
Lev Walkinef625402005-09-05 05:17:57 +0000997 | Type optMarker {
998 $$ = $1;
999 $2.flags |= $$->marker.flags;
1000 $$->marker = $2;
1001 _fixup_anonymous_identifier($$);
1002 }
Lev Walkin070a52d2004-08-22 03:19:54 +00001003 | TOK_COMPONENTS TOK_OF Type {
Lev Walkina9532f42006-09-17 04:52:50 +00001004 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001005 checkmem($$);
1006 $$->meta_type = $3->meta_type;
1007 $$->expr_type = A1TC_COMPONENTS_OF;
Lev Walkin1004aa92004-09-08 00:28:11 +00001008 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +00001009 }
1010 | ExtensionAndException {
1011 $$ = $1;
1012 }
1013 ;
1014
1015AlternativeTypeLists:
1016 AlternativeType {
Lev Walkina9532f42006-09-17 04:52:50 +00001017 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001018 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00001019 asn1p_expr_add($$, $1);
Lev Walkin070a52d2004-08-22 03:19:54 +00001020 }
1021 | AlternativeTypeLists ',' AlternativeType {
1022 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001023 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +00001024 }
1025 ;
1026
1027AlternativeType:
Lev Walkinaf120f72004-09-14 02:36:39 +00001028 Identifier Type {
Lev Walkin070a52d2004-08-22 03:19:54 +00001029 $$ = $2;
1030 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +00001031 $$->Identifier = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001032 }
1033 | ExtensionAndException {
1034 $$ = $1;
1035 }
Lev Walkin2e9bd5c2005-08-13 09:07:11 +00001036 | Type {
1037 $$ = $1;
1038 _fixup_anonymous_identifier($$);
1039 }
Lev Walkin070a52d2004-08-22 03:19:54 +00001040 ;
1041
Lev Walkin9c2285a2006-03-09 08:49:26 +00001042ObjectClass:
1043 TOK_CLASS '{' FieldSpec '}' optWithSyntax {
Lev Walkinf15320b2004-06-03 03:38:44 +00001044 $$ = $3;
1045 checkmem($$);
1046 $$->with_syntax = $5;
1047 assert($$->expr_type == A1TC_CLASSDEF);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001048 assert($$->meta_type == AMT_OBJECTCLASS);
Lev Walkinf15320b2004-06-03 03:38:44 +00001049 }
1050 ;
1051
1052optUnique:
1053 { $$ = 0; }
1054 | TOK_UNIQUE { $$ = 1; }
1055 ;
1056
Lev Walkin9c2285a2006-03-09 08:49:26 +00001057FieldSpec:
Lev Walkinf15320b2004-06-03 03:38:44 +00001058 ClassField {
Lev Walkina9532f42006-09-17 04:52:50 +00001059 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001060 checkmem($$);
1061 $$->expr_type = A1TC_CLASSDEF;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001062 $$->meta_type = AMT_OBJECTCLASS;
Lev Walkin1004aa92004-09-08 00:28:11 +00001063 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001064 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001065 | FieldSpec ',' ClassField {
Lev Walkinf15320b2004-06-03 03:38:44 +00001066 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001067 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001068 }
1069 ;
1070
Lev Walkin9c2285a2006-03-09 08:49:26 +00001071 /* X.681 */
Lev Walkinf15320b2004-06-03 03:38:44 +00001072ClassField:
Lev Walkin9c2285a2006-03-09 08:49:26 +00001073
1074 /* TypeFieldSpec ::= typefieldreference TypeOptionalitySpec? */
1075 TOK_typefieldreference optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001076 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001077 checkmem($$);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001078 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001079 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001080 $$->expr_type = A1TC_CLASSFIELD_TFS; /* TypeFieldSpec */
Lev Walkinf15320b2004-06-03 03:38:44 +00001081 $$->marker = $2;
1082 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001083
1084 /* FixedTypeValueFieldSpec ::= valuefieldreference Type UNIQUE ? ValueOptionalitySpec ? */
1085 | TOK_valuefieldreference Type optUnique optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001086 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001087 $$->Identifier = $1;
1088 $$->meta_type = AMT_OBJECTFIELD;
1089 $$->expr_type = A1TC_CLASSFIELD_FTVFS; /* FixedTypeValueFieldSpec */
Lev Walkinb7c45ca2004-11-24 17:43:29 +00001090 $$->unique = $3;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001091 $$->marker = $4;
1092 asn1p_expr_add($$, $2);
Lev Walkinf15320b2004-06-03 03:38:44 +00001093 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001094
1095 /* VariableTypeValueFieldSpec ::= valuefieldreference FieldName ValueOptionalitySpec ? */
1096 | TOK_valuefieldreference FieldName optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001097 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001098 $$->Identifier = $1;
1099 $$->meta_type = AMT_OBJECTFIELD;
1100 $$->expr_type = A1TC_CLASSFIELD_VTVFS;
1101 $$->reference = $2;
1102 $$->marker = $3;
1103 }
1104
Lev Walkin9c2285a2006-03-09 08:49:26 +00001105 /* ObjectFieldSpec ::= objectfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1106 | TOK_valuefieldreference DefinedObjectClass optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001107 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001108 checkmem($$);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001109 $$->Identifier = $1;
1110 $$->reference = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00001111 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001112 $$->expr_type = A1TC_CLASSFIELD_OFS;
1113 $$->marker = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +00001114 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001115
Lev Walkin54868752006-03-09 09:08:49 +00001116 /* VariableTypeValueSetFieldSpec ::= valuesetfieldreference FieldName ValueOptionalitySpec ? */
1117 | TOK_typefieldreference FieldName optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001118 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001119 $$->Identifier = $1;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001120 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin54868752006-03-09 09:08:49 +00001121 $$->expr_type = A1TC_CLASSFIELD_VTVSFS;
1122 $$->reference = $2;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001123 $$->marker = $3;
1124 }
1125
1126 /* FixedTypeValueSetFieldSpec ::= valuesetfieldreference Type ValueSetOptionalitySpec ? */
1127 | TOK_typefieldreference Type optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001128 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001129 checkmem($$);
1130 $$->Identifier = $1;
1131 $$->meta_type = AMT_OBJECTFIELD;
1132 $$->expr_type = A1TC_CLASSFIELD_FTVSFS;
1133 asn1p_expr_add($$, $2);
1134 $$->marker = $3;
1135 }
1136
Lev Walkin54868752006-03-09 09:08:49 +00001137 /* ObjectSetFieldSpec ::= objectsetfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1138 | TOK_typefieldreference DefinedObjectClass optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001139 $$ = NEW_EXPR();
Lev Walkin54868752006-03-09 09:08:49 +00001140 checkmem($$);
1141 $$->Identifier = $1;
1142 $$->reference = $2;
1143 $$->meta_type = AMT_OBJECTFIELD;
1144 $$->expr_type = A1TC_CLASSFIELD_OSFS;
1145 $$->marker = $3;
1146 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001147 ;
1148
1149optWithSyntax:
1150 { $$ = 0; }
1151 | WithSyntax {
1152 $$ = $1;
1153 }
1154 ;
1155
1156WithSyntax:
1157 TOK_WITH TOK_SYNTAX '{'
1158 { asn1p_lexer_hack_enable_with_syntax(); }
Lev Walkin9d542d22006-03-14 16:31:37 +00001159 WithSyntaxList
Lev Walkinf15320b2004-06-03 03:38:44 +00001160 '}' {
1161 $$ = $5;
1162 }
1163 ;
1164
Lev Walkin9d542d22006-03-14 16:31:37 +00001165WithSyntaxList:
1166 WithSyntaxToken {
Lev Walkinf15320b2004-06-03 03:38:44 +00001167 $$ = asn1p_wsyntx_new();
1168 TQ_ADD(&($$->chunks), $1, next);
1169 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001170 | WithSyntaxList WithSyntaxToken {
Lev Walkinf15320b2004-06-03 03:38:44 +00001171 $$ = $1;
1172 TQ_ADD(&($$->chunks), $2, next);
1173 }
1174 ;
1175
Lev Walkin9d542d22006-03-14 16:31:37 +00001176WithSyntaxToken:
Lev Walkin57074f12006-03-16 05:11:14 +00001177 TOK_whitespace {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001178 $$ = asn1p_wsyntx_chunk_fromstring($1.buf, 0);
Lev Walkin57074f12006-03-16 05:11:14 +00001179 $$->type = WC_WHITESPACE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001180 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001181 | TOK_Literal {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001182 $$ = asn1p_wsyntx_chunk_fromstring($1, 0);
Lev Walkin9d542d22006-03-14 16:31:37 +00001183 }
Lev Walkind370e9f2006-03-16 10:03:35 +00001184 | PrimitiveFieldReference {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001185 $$ = asn1p_wsyntx_chunk_fromstring($1.name, 0);
Lev Walkind370e9f2006-03-16 10:03:35 +00001186 $$->type = WC_FIELD;
Lev Walkinf15320b2004-06-03 03:38:44 +00001187 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001188 | '[' WithSyntaxList ']' {
1189 $$ = asn1p_wsyntx_chunk_fromsyntax($2);
1190 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001191 ;
1192
Lev Walkinf15320b2004-06-03 03:38:44 +00001193ExtensionAndException:
1194 TOK_ThreeDots {
Lev Walkina9532f42006-09-17 04:52:50 +00001195 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001196 checkmem($$);
1197 $$->Identifier = strdup("...");
1198 checkmem($$->Identifier);
1199 $$->expr_type = A1TC_EXTENSIBLE;
1200 $$->meta_type = AMT_TYPE;
1201 }
1202 | TOK_ThreeDots '!' DefinedValue {
Lev Walkina9532f42006-09-17 04:52:50 +00001203 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001204 checkmem($$);
1205 $$->Identifier = strdup("...");
1206 checkmem($$->Identifier);
1207 $$->value = $3;
1208 $$->expr_type = A1TC_EXTENSIBLE;
1209 $$->meta_type = AMT_TYPE;
1210 }
1211 | TOK_ThreeDots '!' SignedNumber {
Lev Walkina9532f42006-09-17 04:52:50 +00001212 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001213 checkmem($$);
1214 $$->Identifier = strdup("...");
1215 $$->value = $3;
1216 checkmem($$->Identifier);
1217 $$->expr_type = A1TC_EXTENSIBLE;
1218 $$->meta_type = AMT_TYPE;
1219 }
1220 ;
1221
Lev Walkin070a52d2004-08-22 03:19:54 +00001222Type:
Lev Walkinaf120f72004-09-14 02:36:39 +00001223 optTag TypeDeclaration optConstraints {
1224 $$ = $2;
1225 $$->tag = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001226 /*
1227 * Outer constraint for SEQUENCE OF and SET OF applies
1228 * to the inner type.
1229 */
1230 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1231 || $$->expr_type == ASN_CONSTR_SET_OF) {
1232 assert(!TQ_FIRST(&($$->members))->constraints);
Lev Walkinaf120f72004-09-14 02:36:39 +00001233 TQ_FIRST(&($$->members))->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001234 } else {
1235 if($$->constraints) {
1236 assert(!$2);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001237 /* Check this : optConstraints is not used ?! */
1238 asn1p_constraint_free($3);
Lev Walkin070a52d2004-08-22 03:19:54 +00001239 } else {
Lev Walkinaf120f72004-09-14 02:36:39 +00001240 $$->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001241 }
1242 }
Lev Walkinef625402005-09-05 05:17:57 +00001243 }
1244 ;
1245
1246NSTD_IndirectMarker:
1247 {
1248 $$ = asn1p_as_pointer ? EM_INDIRECT : 0;
1249 asn1p_as_pointer = 0;
Lev Walkin070a52d2004-08-22 03:19:54 +00001250 }
1251 ;
1252
1253TypeDeclaration:
Lev Walkinef625402005-09-05 05:17:57 +00001254 NSTD_IndirectMarker TypeDeclarationSet {
Lev Walkin4696c742005-08-22 12:23:54 +00001255 $$ = $2;
Lev Walkinef625402005-09-05 05:17:57 +00001256 $$->marker.flags |= $1;
1257
1258 if(($$->marker.flags & EM_INDIRECT)
1259 && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
1260 fprintf(stderr,
1261 "INFO: Directive <ASN1C:RepresentAsPointer> "
1262 "applied to %s at line %d\n",
1263 ASN_EXPR_TYPE2STR($$->expr_type)
1264 ? ASN_EXPR_TYPE2STR($$->expr_type)
1265 : "member",
1266 $$->_lineno
1267 );
1268 }
Lev Walkin4696c742005-08-22 12:23:54 +00001269 }
Lev Walkinef625402005-09-05 05:17:57 +00001270 ;
Lev Walkin4696c742005-08-22 12:23:54 +00001271
1272TypeDeclarationSet:
Lev Walkin0c0bca62006-03-21 04:48:15 +00001273 DefinedType {
Lev Walkinf15320b2004-06-03 03:38:44 +00001274 $$ = $1;
1275 }
Lev Walkinef625402005-09-05 05:17:57 +00001276 | TOK_CHOICE '{' AlternativeTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001277 $$ = $3;
1278 assert($$->expr_type == A1TC_INVALID);
1279 $$->expr_type = ASN_CONSTR_CHOICE;
1280 $$->meta_type = AMT_TYPE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001281 }
Lev Walkinef625402005-09-05 05:17:57 +00001282 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001283 $$ = $3;
1284 assert($$->expr_type == A1TC_INVALID);
1285 $$->expr_type = ASN_CONSTR_SEQUENCE;
1286 $$->meta_type = AMT_TYPE;
1287 }
Lev Walkinef625402005-09-05 05:17:57 +00001288 | TOK_SET '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001289 $$ = $3;
1290 assert($$->expr_type == A1TC_INVALID);
1291 $$->expr_type = ASN_CONSTR_SET;
1292 $$->meta_type = AMT_TYPE;
1293 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001294 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkina9532f42006-09-17 04:52:50 +00001295 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001296 checkmem($$);
1297 $$->constraints = $2;
1298 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1299 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001300 $6->Identifier = $4;
1301 $6->tag = $5;
1302 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001303 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001304 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkina9532f42006-09-17 04:52:50 +00001305 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001306 checkmem($$);
1307 $$->constraints = $2;
1308 $$->expr_type = ASN_CONSTR_SET_OF;
1309 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001310 $6->Identifier = $4;
1311 $6->tag = $5;
1312 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001313 }
1314 | TOK_ANY {
Lev Walkina9532f42006-09-17 04:52:50 +00001315 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001316 checkmem($$);
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 }
1320 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1321 int ret;
Lev Walkina9532f42006-09-17 04:52:50 +00001322 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001323 checkmem($$);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001324 $$->reference = asn1p_ref_new(yylineno, currentModule);
Lev Walkin070a52d2004-08-22 03:19:54 +00001325 ret = asn1p_ref_add_component($$->reference,
1326 $4, RLT_lowercase);
1327 checkmem(ret == 0);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001328 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001329 $$->meta_type = AMT_TYPE;
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001330 free($4);
Lev Walkin070a52d2004-08-22 03:19:54 +00001331 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001332 | TOK_INSTANCE TOK_OF ComplexTypeReference {
Lev Walkina9532f42006-09-17 04:52:50 +00001333 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001334 checkmem($$);
1335 $$->reference = $3;
1336 $$->expr_type = A1TC_INSTANCE;
1337 $$->meta_type = AMT_TYPE;
1338 }
1339 ;
1340
1341/*
1342 * A type name consisting of several components.
1343 * === EXAMPLE ===
1344 * === EOF ===
1345 */
1346ComplexTypeReference:
1347 TOK_typereference {
1348 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001349 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001350 checkmem($$);
1351 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1352 checkmem(ret == 0);
1353 free($1);
1354 }
1355 | TOK_typereference '.' TypeRefName {
1356 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001357 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001358 checkmem($$);
1359 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1360 checkmem(ret == 0);
1361 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1362 checkmem(ret == 0);
1363 free($1);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001364 free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001365 }
Lev Walkin9c974182004-09-15 11:59:51 +00001366 | ObjectClassReference '.' TypeRefName {
1367 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001368 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkin9c974182004-09-15 11:59:51 +00001369 checkmem($$);
1370 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1371 checkmem(ret == 0);
1372 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1373 checkmem(ret == 0);
1374 free($1);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001375 free($3);
Lev Walkin9c974182004-09-15 11:59:51 +00001376 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001377 | TOK_typereference '.' Identifier {
1378 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001379 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001380 checkmem($$);
1381 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1382 checkmem(ret == 0);
1383 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1384 checkmem(ret == 0);
1385 free($1);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001386 free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001387 }
1388 | ObjectClassReference {
1389 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001390 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001391 checkmem($$);
1392 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1393 free($1);
1394 checkmem(ret == 0);
1395 }
1396 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1397 int ret;
1398 $$ = $3;
1399 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1400 free($1);
1401 checkmem(ret == 0);
1402 /*
1403 * Move the last element infront.
1404 */
1405 {
1406 struct asn1p_ref_component_s tmp_comp;
1407 tmp_comp = $$->components[$$->comp_count-1];
1408 memmove(&$$->components[1],
1409 &$$->components[0],
1410 sizeof($$->components[0])
1411 * ($$->comp_count - 1));
1412 $$->components[0] = tmp_comp;
1413 }
1414 }
1415 ;
1416
1417ComplexTypeReferenceAmpList:
1418 ComplexTypeReferenceElement {
1419 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001420 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001421 checkmem($$);
1422 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1423 free($1.name);
1424 checkmem(ret == 0);
1425 }
1426 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1427 int ret;
1428 $$ = $1;
1429 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1430 free($3.name);
1431 checkmem(ret == 0);
1432 }
1433 ;
1434
Lev Walkind370e9f2006-03-16 10:03:35 +00001435ComplexTypeReferenceElement: PrimitiveFieldReference;
Lev Walkinf15320b2004-06-03 03:38:44 +00001436
Lev Walkind370e9f2006-03-16 10:03:35 +00001437PrimitiveFieldReference:
Lev Walkinf15320b2004-06-03 03:38:44 +00001438 /* "&Type1" */
1439 TOK_typefieldreference {
1440 $$.lex_type = RLT_AmpUppercase;
1441 $$.name = $1;
1442 }
1443 /* "&id" */
1444 | TOK_valuefieldreference {
1445 $$.lex_type = RLT_Amplowercase;
1446 $$.name = $1;
1447 }
1448 ;
1449
1450
Lev Walkin9c2285a2006-03-09 08:49:26 +00001451FieldName:
1452 /* "&Type1" */
1453 TOK_typefieldreference {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001454 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001455 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001456 free($1);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001457 }
1458 | FieldName '.' TOK_typefieldreference {
1459 $$ = $$;
1460 asn1p_ref_add_component($$, $3, RLT_AmpUppercase);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001461 free($3);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001462 }
1463 | FieldName '.' TOK_valuefieldreference {
1464 $$ = $$;
1465 asn1p_ref_add_component($$, $3, RLT_Amplowercase);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001466 free($3);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001467 }
1468 ;
1469
1470DefinedObjectClass:
1471 TOK_capitalreference {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001472 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001473 asn1p_ref_add_component($$, $1, RLT_CAPITALS);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001474 free($1);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001475 }
Lev Walkin54868752006-03-09 09:08:49 +00001476/*
Lev Walkin9c2285a2006-03-09 08:49:26 +00001477 | TypeRefName '.' TOK_capitalreference {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001478 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001479 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1480 asn1p_ref_add_component($$, $3, RLT_CAPITALS);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001481 free($1);
1482 free($3);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001483 }
Lev Walkin54868752006-03-09 09:08:49 +00001484*/
Lev Walkin9c2285a2006-03-09 08:49:26 +00001485 ;
1486
1487
Lev Walkinf15320b2004-06-03 03:38:44 +00001488/*
1489 * === EXAMPLE ===
1490 * value INTEGER ::= 1
1491 * === EOF ===
1492 */
Lev Walkinc6ab03c2006-10-21 05:54:49 +00001493ValueAssignment:
1494 Identifier Type TOK_PPEQ Value {
Lev Walkinf15320b2004-06-03 03:38:44 +00001495 $$ = $2;
1496 assert($$->Identifier == NULL);
1497 $$->Identifier = $1;
1498 $$->meta_type = AMT_VALUE;
1499 $$->value = $4;
1500 }
1501 ;
1502
Lev Walkin9c974182004-09-15 11:59:51 +00001503Value:
Lev Walkin0c0bca62006-03-21 04:48:15 +00001504 SimpleValue
1505 | DefinedValue
1506 | Identifier ':' Value {
Lev Walkin9c974182004-09-15 11:59:51 +00001507 $$ = asn1p_value_fromint(0);
1508 checkmem($$);
1509 $$->type = ATV_CHOICE_IDENTIFIER;
1510 $$->value.choice_identifier.identifier = $1;
1511 $$->value.choice_identifier.value = $3;
1512 }
Lev Walkincbad2512005-03-24 16:27:02 +00001513 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Lev Walkinf15320b2004-06-03 03:38:44 +00001514 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1515 checkmem($$);
1516 $$->type = ATV_UNPARSED;
1517 }
Lev Walkin9c974182004-09-15 11:59:51 +00001518 | TOK_NULL {
1519 $$ = asn1p_value_fromint(0);
1520 checkmem($$);
1521 $$->type = ATV_NULL;
1522 }
Lev Walkin0c0bca62006-03-21 04:48:15 +00001523 ;
1524
1525SimpleValue:
1526 TOK_FALSE {
Lev Walkin9c974182004-09-15 11:59:51 +00001527 $$ = asn1p_value_fromint(0);
1528 checkmem($$);
1529 $$->type = ATV_FALSE;
1530 }
1531 | TOK_TRUE {
1532 $$ = asn1p_value_fromint(0);
1533 checkmem($$);
1534 $$->type = ATV_TRUE;
1535 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001536 | TOK_bstring {
1537 $$ = _convert_bitstring2binary($1, 'B');
1538 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001539 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001540 }
1541 | TOK_hstring {
1542 $$ = _convert_bitstring2binary($1, 'H');
1543 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001544 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001545 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001546 | RestrictedCharacterStringValue {
1547 $$ = $$;
Lev Walkinf15320b2004-06-03 03:38:44 +00001548 }
1549 | SignedNumber {
1550 $$ = $1;
1551 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001552 ;
1553
1554DefinedValue:
1555 Identifier {
1556 asn1p_ref_t *ref;
1557 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001558 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001559 checkmem(ref);
1560 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1561 checkmem(ret == 0);
1562 $$ = asn1p_value_fromref(ref, 0);
1563 checkmem($$);
1564 free($1);
1565 }
1566 | TypeRefName '.' Identifier {
1567 asn1p_ref_t *ref;
1568 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001569 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001570 checkmem(ref);
1571 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1572 checkmem(ret == 0);
1573 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1574 checkmem(ret == 0);
1575 $$ = asn1p_value_fromref(ref, 0);
1576 checkmem($$);
1577 free($1);
1578 free($3);
1579 }
1580 ;
1581
Lev Walkin1e448d32005-03-24 14:26:38 +00001582
1583RestrictedCharacterStringValue:
1584 TOK_cstring {
1585 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1586 checkmem($$);
1587 }
Lev Walkind9574ae2005-03-24 16:22:35 +00001588 | TOK_tuple {
1589 $$ = asn1p_value_fromint($1);
1590 checkmem($$);
1591 $$->type = ATV_TUPLE;
1592 }
1593 | TOK_quadruple {
1594 $$ = asn1p_value_fromint($1);
1595 checkmem($$);
1596 $$->type = ATV_QUADRUPLE;
1597 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001598 ;
1599
Lev Walkinf15320b2004-06-03 03:38:44 +00001600Opaque:
1601 TOK_opaque {
Lev Walkin1893ddf2005-03-20 14:28:32 +00001602 $$.len = $1.len + 1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001603 $$.buf = malloc($$.len + 1);
1604 checkmem($$.buf);
1605 $$.buf[0] = '{';
Lev Walkin1893ddf2005-03-20 14:28:32 +00001606 memcpy($$.buf + 1, $1.buf, $1.len);
Lev Walkinf15320b2004-06-03 03:38:44 +00001607 $$.buf[$$.len] = '\0';
1608 free($1.buf);
1609 }
1610 | Opaque TOK_opaque {
1611 int newsize = $1.len + $2.len;
1612 char *p = malloc(newsize + 1);
1613 checkmem(p);
1614 memcpy(p , $1.buf, $1.len);
1615 memcpy(p + $1.len, $2.buf, $2.len);
1616 p[newsize] = '\0';
1617 free($1.buf);
1618 free($2.buf);
1619 $$.buf = p;
1620 $$.len = newsize;
1621 }
1622 ;
1623
1624BasicTypeId:
1625 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1626 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1627 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1628 | BasicTypeId_UniverationCompatible { $$ = $1; }
1629 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1630 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1631 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1632 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1633 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1634 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1635 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1636 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
Lev Walkinc7d939d2005-03-20 11:12:40 +00001637 | BasicString { $$ = $1; }
Lev Walkinf15320b2004-06-03 03:38:44 +00001638 ;
1639
1640/*
1641 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1642 */
1643BasicTypeId_UniverationCompatible:
1644 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1645 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1646 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1647 ;
1648
1649BasicType:
1650 BasicTypeId {
Lev Walkina9532f42006-09-17 04:52:50 +00001651 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001652 checkmem($$);
1653 $$->expr_type = $1;
1654 $$->meta_type = AMT_TYPE;
1655 }
1656 | BasicTypeId_UniverationCompatible UniverationDefinition {
1657 if($2) {
1658 $$ = $2;
1659 } else {
Lev Walkina9532f42006-09-17 04:52:50 +00001660 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001661 checkmem($$);
1662 }
1663 $$->expr_type = $1;
1664 $$->meta_type = AMT_TYPE;
1665 }
1666 ;
1667
1668BasicString:
1669 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1670 | TOK_GeneralString {
1671 $$ = ASN_STRING_GeneralString;
Lev Walkin9c974182004-09-15 11:59:51 +00001672 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001673 }
1674 | TOK_GraphicString {
1675 $$ = ASN_STRING_GraphicString;
Lev Walkin9c974182004-09-15 11:59:51 +00001676 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001677 }
1678 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1679 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1680 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1681 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1682 | TOK_T61String {
1683 $$ = ASN_STRING_T61String;
Lev Walkin9c974182004-09-15 11:59:51 +00001684 fprintf(stderr, "WARNING: T61String is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001685 }
1686 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1687 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1688 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1689 | TOK_VideotexString {
1690 $$ = ASN_STRING_VideotexString;
Lev Walkin9c974182004-09-15 11:59:51 +00001691 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001692 }
1693 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1694 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1695 ;
1696
Lev Walkind2ea1de2004-08-20 13:25:29 +00001697
Lev Walkinf15320b2004-06-03 03:38:44 +00001698/*
1699 * Data type constraints.
1700 */
Lev Walkinf1727152006-09-21 01:50:37 +00001701UnionMark: '|' | TOK_UNION;
1702IntersectionMark: '^' | TOK_INTERSECTION;
Lev Walkinf15320b2004-06-03 03:38:44 +00001703
Lev Walkinf59d0752004-08-18 04:59:12 +00001704optConstraints:
1705 { $$ = 0; }
Lev Walkina9532f42006-09-17 04:52:50 +00001706 | Constraint {
Lev Walkind2ea1de2004-08-20 13:25:29 +00001707 $$ = $1;
1708 }
1709 ;
1710
Lev Walkina9532f42006-09-17 04:52:50 +00001711Constraint:
1712 SubtypeConstraint
Lev Walkina9532f42006-09-17 04:52:50 +00001713 ;
1714
1715SubtypeConstraint:
Lev Walkind2ea1de2004-08-20 13:25:29 +00001716 SetOfConstraints {
Lev Walkin2c14a692005-08-12 10:08:45 +00001717 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
Lev Walkinf59d0752004-08-18 04:59:12 +00001718 }
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001719 | TOK_SIZE '(' ConstraintSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001720 /*
1721 * This is a special case, for compatibility purposes.
Lev Walkinf59d0752004-08-18 04:59:12 +00001722 * It goes without parentheses.
Lev Walkinf15320b2004-06-03 03:38:44 +00001723 */
Lev Walkin2c14a692005-08-12 10:08:45 +00001724 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001725 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001726 ;
1727
Lev Walkinf59d0752004-08-18 04:59:12 +00001728SetOfConstraints:
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001729 '(' ConstraintSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001730 $$ = $2;
1731 }
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001732 | SetOfConstraints '(' ConstraintSpecs ')' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001733 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
Lev Walkinf59d0752004-08-18 04:59:12 +00001734 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001735 ;
1736
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001737ConstraintSpecs:
1738 ElementSetSpecs {
1739 $$ = $1;
1740 }
1741 | GeneralConstraint {
1742 $$ = $1;
1743 }
1744 ;
1745
Lev Walkinf59d0752004-08-18 04:59:12 +00001746ElementSetSpecs:
Lev Walkin5045dfa2006-03-21 09:41:28 +00001747 TOK_ThreeDots {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001748 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkin5045dfa2006-03-21 09:41:28 +00001749 $$->type = ACT_EL_EXT;
1750 }
1751 | ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001752 $$ = $1;
1753 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001754 | ElementSetSpec ',' TOK_ThreeDots {
Lev Walkinf15320b2004-06-03 03:38:44 +00001755 asn1p_constraint_t *ct;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001756 ct = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001757 ct->type = ACT_EL_EXT;
Lev Walkin2c14a692005-08-12 10:08:45 +00001758 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00001759 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001760 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001761 asn1p_constraint_t *ct;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001762 ct = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001763 ct->type = ACT_EL_EXT;
Lev Walkin2c14a692005-08-12 10:08:45 +00001764 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinb4fcdd22004-08-13 12:35:09 +00001765 ct = $$;
Lev Walkin2c14a692005-08-12 10:08:45 +00001766 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
Lev Walkinf15320b2004-06-03 03:38:44 +00001767 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001768 ;
1769
Lev Walkinf59d0752004-08-18 04:59:12 +00001770ElementSetSpec:
Lev Walkinf1727152006-09-21 01:50:37 +00001771 Unions
Lev Walkin1e448d32005-03-24 14:26:38 +00001772 | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001773 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
Lev Walkin1e448d32005-03-24 14:26:38 +00001774 }
Lev Walkinf1727152006-09-21 01:50:37 +00001775 ;
1776
1777Unions:
1778 Intersections
1779 | Unions UnionMark Intersections {
Lev Walkin2c14a692005-08-12 10:08:45 +00001780 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001781 }
Lev Walkinf1727152006-09-21 01:50:37 +00001782 ;
1783
1784Intersections:
1785 IntersectionElements
1786 | Intersections IntersectionMark IntersectionElements {
Lev Walkin2c14a692005-08-12 10:08:45 +00001787 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001788 }
Lev Walkinf1727152006-09-21 01:50:37 +00001789 ;
1790
1791
1792IntersectionElements:
1793 ConstraintSubtypeElement
1794 | ConstraintSubtypeElement TOK_EXCEPT ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001795 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001796 }
1797 ;
1798
1799ConstraintSubtypeElement:
Lev Walkinf59d0752004-08-18 04:59:12 +00001800 ConstraintSpec '(' ElementSetSpecs ')' {
1801 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001802 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf59d0752004-08-18 04:59:12 +00001803 checkmem($$);
1804 $$->type = $1;
1805 ret = asn1p_constraint_insert($$, $3);
1806 checkmem(ret == 0);
1807 }
1808 | '(' ElementSetSpecs ')' {
1809 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001810 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf59d0752004-08-18 04:59:12 +00001811 checkmem($$);
1812 $$->type = ACT_CA_SET;
1813 ret = asn1p_constraint_insert($$, $2);
1814 checkmem(ret == 0);
1815 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001816 | SingleValue {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001817 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001818 checkmem($$);
1819 $$->type = ACT_EL_VALUE;
1820 $$->value = $1;
1821 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001822 | ContainedSubtype {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001823 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinff7dd142005-03-20 12:58:00 +00001824 checkmem($$);
1825 $$->type = ACT_EL_TYPE;
1826 $$->containedSubtype = $1;
1827 }
1828 | SingleValue ConstraintRangeSpec SingleValue {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001829 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001830 checkmem($$);
1831 $$->type = $2;
1832 $$->range_start = $1;
1833 $$->range_stop = $3;
1834 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001835 | TOK_MIN ConstraintRangeSpec SingleValue {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001836 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001837 checkmem($$);
Lev Walkinf59d0752004-08-18 04:59:12 +00001838 $$->type = $2;
1839 $$->range_start = asn1p_value_fromint(-123);
1840 $$->range_stop = $3;
1841 $$->range_start->type = ATV_MIN;
1842 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001843 | SingleValue ConstraintRangeSpec TOK_MAX {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001844 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf59d0752004-08-18 04:59:12 +00001845 checkmem($$);
1846 $$->type = $2;
1847 $$->range_start = $1;
1848 $$->range_stop = asn1p_value_fromint(321);
1849 $$->range_stop->type = ATV_MAX;
1850 }
1851 | TOK_MIN ConstraintRangeSpec TOK_MAX {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001852 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf59d0752004-08-18 04:59:12 +00001853 checkmem($$);
1854 $$->type = $2;
1855 $$->range_start = asn1p_value_fromint(-123);
1856 $$->range_stop = asn1p_value_fromint(321);
1857 $$->range_start->type = ATV_MIN;
1858 $$->range_stop->type = ATV_MAX;
Lev Walkinf15320b2004-06-03 03:38:44 +00001859 }
Lev Walkine596bf02005-03-28 15:01:27 +00001860 | InnerTypeConstraint {
Lev Walkinf15320b2004-06-03 03:38:44 +00001861 $$ = $1;
1862 }
Lev Walkin5c541f12006-10-18 18:40:14 +00001863 | PatternConstraint {
1864 $$ = $1;
1865 }
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001866 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1867 $$ = asn1p_constraint_new(yylineno, currentModule);
1868 checkmem($$);
1869 $$->type = ACT_EL_VALUE;
1870 $$->value = asn1p_value_frombuf($3.buf, $3.len, 0);
1871 $$->value->type = ATV_UNPARSED;
1872 }
Lev Walkin5c541f12006-10-18 18:40:14 +00001873 ;
1874
1875PatternConstraint:
1876 TOK_PATTERN TOK_cstring {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001877 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkin5c541f12006-10-18 18:40:14 +00001878 $$->type = ACT_CT_PATTERN;
1879 $$->value = asn1p_value_frombuf($2.buf, $2.len, 0);
1880 }
1881 | TOK_PATTERN Identifier {
1882 asn1p_ref_t *ref;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001883 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkin5c541f12006-10-18 18:40:14 +00001884 $$->type = ACT_CT_PATTERN;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001885 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkin5c541f12006-10-18 18:40:14 +00001886 asn1p_ref_add_component(ref, $2, RLT_lowercase);
1887 $$->value = asn1p_value_fromref(ref, 0);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001888 free($2);
Lev Walkin5c541f12006-10-18 18:40:14 +00001889 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001890 ;
1891
1892ConstraintSpec:
1893 TOK_SIZE {
1894 $$ = ACT_CT_SIZE;
1895 }
1896 | TOK_FROM {
1897 $$ = ACT_CT_FROM;
1898 }
1899 ;
1900
Lev Walkinff7dd142005-03-20 12:58:00 +00001901SingleValue:
Lev Walkinc8092cb2005-02-18 16:34:21 +00001902 TOK_FALSE {
1903 $$ = asn1p_value_fromint(0);
1904 checkmem($$);
1905 $$->type = ATV_FALSE;
1906 }
1907 | TOK_TRUE {
1908 $$ = asn1p_value_fromint(1);
1909 checkmem($$);
1910 $$->type = ATV_TRUE;
1911 }
Lev Walkinadf863f2006-09-05 16:18:34 +00001912 | RealValue
1913 | RestrictedCharacterStringValue
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001914 | BitStringValue
Lev Walkinf15320b2004-06-03 03:38:44 +00001915 | Identifier {
1916 asn1p_ref_t *ref;
1917 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001918 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001919 checkmem(ref);
1920 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1921 checkmem(ret == 0);
1922 $$ = asn1p_value_fromref(ref, 0);
1923 checkmem($$);
1924 free($1);
1925 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001926 ;
1927
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001928BitStringValue:
1929 TOK_bstring {
1930 $$ = _convert_bitstring2binary($1, 'B');
1931 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001932 free($1);
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001933 }
1934 | TOK_hstring {
1935 $$ = _convert_bitstring2binary($1, 'H');
1936 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001937 free($1);
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001938 }
1939 ;
1940
Lev Walkinff7dd142005-03-20 12:58:00 +00001941ContainedSubtype:
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001942 ComplexTypeReference {
1943 $$ = asn1p_value_fromref($1, 0);
1944 checkmem($$);
1945 }
1946/*
Lev Walkinff7dd142005-03-20 12:58:00 +00001947 TypeRefName {
Lev Walkinc8092cb2005-02-18 16:34:21 +00001948 asn1p_ref_t *ref;
1949 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001950 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkinc8092cb2005-02-18 16:34:21 +00001951 checkmem(ref);
1952 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1953 checkmem(ret == 0);
1954 $$ = asn1p_value_fromref(ref, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001955 checkmem($$);
Lev Walkinc8092cb2005-02-18 16:34:21 +00001956 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001957 }
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001958*/
Lev Walkinf15320b2004-06-03 03:38:44 +00001959 ;
1960
Lev Walkine596bf02005-03-28 15:01:27 +00001961InnerTypeConstraint:
1962 TOK_WITH TOK_COMPONENT SetOfConstraints {
Lev Walkin2c14a692005-08-12 10:08:45 +00001963 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
Lev Walkine596bf02005-03-28 15:01:27 +00001964 }
1965 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001966 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001967 }
1968 ;
1969
1970WithComponentsList:
1971 WithComponentsElement {
1972 $$ = $1;
1973 }
1974 | WithComponentsList ',' WithComponentsElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001975 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001976 }
1977 ;
1978
1979WithComponentsElement:
1980 TOK_ThreeDots {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001981 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001982 checkmem($$);
1983 $$->type = ACT_EL_EXT;
Lev Walkin418298d2006-07-13 08:24:20 +00001984 $$->value = asn1p_value_frombuf("...", 3, 1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001985 }
1986 | Identifier optConstraints optPresenceConstraint {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001987 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001988 checkmem($$);
1989 $$->type = ACT_EL_VALUE;
1990 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1991 $$->presence = $3;
Lev Walkine596bf02005-03-28 15:01:27 +00001992 if($2) asn1p_constraint_insert($$, $2);
Lev Walkinf15320b2004-06-03 03:38:44 +00001993 }
1994 ;
1995
1996/*
1997 * presence constraint for WithComponents
1998 */
1999optPresenceConstraint:
2000 { $$ = ACPRES_DEFAULT; }
2001 | PresenceConstraint { $$ = $1; }
2002 ;
2003
2004PresenceConstraint:
2005 TOK_PRESENT {
2006 $$ = ACPRES_PRESENT;
2007 }
2008 | TOK_ABSENT {
2009 $$ = ACPRES_ABSENT;
2010 }
2011 | TOK_OPTIONAL {
2012 $$ = ACPRES_OPTIONAL;
2013 }
2014 ;
2015
Lev Walkina9532f42006-09-17 04:52:50 +00002016
2017/* X.682 */
2018GeneralConstraint:
2019 UserDefinedConstraint
2020 | TableConstraint
2021 | ContentsConstraint
2022 ;
2023
2024UserDefinedConstraint:
2025 TOK_CONSTRAINED TOK_BY '{'
2026 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002027 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkina9532f42006-09-17 04:52:50 +00002028 checkmem($$);
2029 $$->type = ACT_CT_CTDBY;
2030 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
2031 checkmem($$->value);
2032 $$->value->type = ATV_UNPARSED;
2033 }
2034 ;
2035
2036ContentsConstraint:
2037 TOK_CONTAINING Type {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002038 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkina9532f42006-09-17 04:52:50 +00002039 $$->type = ACT_CT_CTNG;
2040 $$->value = asn1p_value_fromtype($2);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08002041 asn1p_expr_free($2);
Lev Walkina9532f42006-09-17 04:52:50 +00002042 }
2043 ;
2044
2045ConstraintRangeSpec:
2046 TOK_TwoDots { $$ = ACT_EL_RANGE; }
2047 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
2048 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
2049 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
2050 ;
Lev Walkinf15320b2004-06-03 03:38:44 +00002051TableConstraint:
2052 SimpleTableConstraint {
2053 $$ = $1;
2054 }
2055 | ComponentRelationConstraint {
2056 $$ = $1;
2057 }
2058 ;
2059
2060/*
2061 * "{ExtensionSet}"
2062 */
2063SimpleTableConstraint:
2064 '{' TypeRefName '}' {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002065 asn1p_ref_t *ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002066 asn1p_constraint_t *ct;
2067 int ret;
2068 ret = asn1p_ref_add_component(ref, $2, 0);
2069 checkmem(ret == 0);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002070 ct = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002071 checkmem($$);
2072 ct->type = ACT_EL_VALUE;
2073 ct->value = asn1p_value_fromref(ref, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00002074 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08002075 free($2);
Lev Walkinf15320b2004-06-03 03:38:44 +00002076 }
2077 ;
2078
2079ComponentRelationConstraint:
2080 SimpleTableConstraint '{' AtNotationList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00002081 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002082 }
2083 ;
2084
2085AtNotationList:
2086 AtNotationElement {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002087 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002088 checkmem($$);
2089 $$->type = ACT_EL_VALUE;
2090 $$->value = asn1p_value_fromref($1, 0);
2091 }
2092 | AtNotationList ',' AtNotationElement {
2093 asn1p_constraint_t *ct;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002094 ct = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002095 checkmem(ct);
2096 ct->type = ACT_EL_VALUE;
2097 ct->value = asn1p_value_fromref($3, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00002098 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00002099 }
2100 ;
2101
2102/*
2103 * @blah
2104 */
2105AtNotationElement:
2106 '@' ComponentIdList {
2107 char *p = malloc(strlen($2) + 2);
2108 int ret;
2109 *p = '@';
2110 strcpy(p + 1, $2);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002111 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002112 ret = asn1p_ref_add_component($$, p, 0);
2113 checkmem(ret == 0);
2114 free(p);
2115 free($2);
2116 }
2117 | '@' '.' ComponentIdList {
2118 char *p = malloc(strlen($3) + 3);
2119 int ret;
2120 p[0] = '@';
2121 p[1] = '.';
2122 strcpy(p + 2, $3);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002123 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002124 ret = asn1p_ref_add_component($$, p, 0);
2125 checkmem(ret == 0);
2126 free(p);
2127 free($3);
2128 }
2129 ;
2130
2131/* identifier "." ... */
2132ComponentIdList:
2133 Identifier {
2134 $$ = $1;
2135 }
2136 | ComponentIdList '.' Identifier {
2137 int l1 = strlen($1);
2138 int l3 = strlen($3);
2139 $$ = malloc(l1 + 1 + l3 + 1);
2140 memcpy($$, $1, l1);
2141 $$[l1] = '.';
2142 memcpy($$ + l1 + 1, $3, l3);
2143 $$[l1 + 1 + l3] = '\0';
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08002144 free($1);
2145 free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002146 }
2147 ;
2148
2149
2150
2151/*
2152 * MARKERS
2153 */
2154
2155optMarker:
Lev Walkin9c974182004-09-15 11:59:51 +00002156 {
2157 $$.flags = EM_NOMARK;
2158 $$.default_value = 0;
2159 }
Lev Walkinf15320b2004-06-03 03:38:44 +00002160 | Marker { $$ = $1; }
2161 ;
2162
2163Marker:
2164 TOK_OPTIONAL {
Lev Walkin70853052005-11-26 11:21:55 +00002165 $$.flags = EM_OPTIONAL | EM_INDIRECT;
Lev Walkin9c974182004-09-15 11:59:51 +00002166 $$.default_value = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +00002167 }
Lev Walkin9c974182004-09-15 11:59:51 +00002168 | TOK_DEFAULT Value {
2169 $$.flags = EM_DEFAULT;
2170 $$.default_value = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00002171 }
2172 ;
2173
2174/*
2175 * Universal enumeration definition to use in INTEGER and ENUMERATED.
2176 * === EXAMPLE ===
2177 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
2178 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
2179 * === EOF ===
2180 */
2181/*
2182optUniverationDefinition:
2183 { $$ = 0; }
2184 | UniverationDefinition {
2185 $$ = $1;
2186 }
2187 ;
2188*/
2189
2190UniverationDefinition:
2191 '{' '}' {
Lev Walkina9532f42006-09-17 04:52:50 +00002192 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002193 checkmem($$);
2194 }
2195 | '{' UniverationList '}' {
2196 $$ = $2;
2197 }
2198 ;
2199
2200UniverationList:
2201 UniverationElement {
Lev Walkina9532f42006-09-17 04:52:50 +00002202 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002203 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00002204 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00002205 }
2206 | UniverationList ',' UniverationElement {
2207 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00002208 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002209 }
2210 ;
2211
2212UniverationElement:
2213 Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +00002214 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002215 checkmem($$);
2216 $$->expr_type = A1TC_UNIVERVAL;
2217 $$->meta_type = AMT_VALUE;
2218 $$->Identifier = $1;
2219 }
2220 | Identifier '(' SignedNumber ')' {
Lev Walkina9532f42006-09-17 04:52:50 +00002221 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002222 checkmem($$);
2223 $$->expr_type = A1TC_UNIVERVAL;
2224 $$->meta_type = AMT_VALUE;
2225 $$->Identifier = $1;
2226 $$->value = $3;
2227 }
2228 | Identifier '(' DefinedValue ')' {
Lev Walkina9532f42006-09-17 04:52:50 +00002229 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002230 checkmem($$);
2231 $$->expr_type = A1TC_UNIVERVAL;
2232 $$->meta_type = AMT_VALUE;
2233 $$->Identifier = $1;
2234 $$->value = $3;
2235 }
2236 | SignedNumber {
Lev Walkina9532f42006-09-17 04:52:50 +00002237 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002238 checkmem($$);
2239 $$->expr_type = A1TC_UNIVERVAL;
2240 $$->meta_type = AMT_VALUE;
2241 $$->value = $1;
2242 }
2243 | TOK_ThreeDots {
Lev Walkina9532f42006-09-17 04:52:50 +00002244 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002245 checkmem($$);
2246 $$->Identifier = strdup("...");
2247 checkmem($$->Identifier);
2248 $$->expr_type = A1TC_EXTENSIBLE;
2249 $$->meta_type = AMT_VALUE;
2250 }
2251 ;
2252
2253SignedNumber:
2254 TOK_number {
2255 $$ = asn1p_value_fromint($1);
2256 checkmem($$);
2257 }
2258 | TOK_number_negative {
2259 $$ = asn1p_value_fromint($1);
2260 checkmem($$);
2261 }
2262 ;
2263
Lev Walkinadf863f2006-09-05 16:18:34 +00002264RealValue:
2265 SignedNumber
2266 | TOK_realnumber {
2267 $$ = asn1p_value_fromdouble($1);
2268 checkmem($$);
2269 }
2270 ;
2271
Lev Walkinf15320b2004-06-03 03:38:44 +00002272/*
2273 * SEQUENCE definition.
2274 * === EXAMPLE ===
2275 * Struct1 ::= SEQUENCE {
2276 * memb1 Struct2,
2277 * memb2 SEQUENCE OF {
2278 * memb2-1 Struct 3
2279 * }
2280 * }
2281 * === EOF ===
2282 */
2283
2284
2285
2286/*
2287 * SET definition.
2288 * === EXAMPLE ===
2289 * Person ::= SET {
2290 * name [0] PrintableString (SIZE(1..20)),
2291 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2292 * }
2293 * === EOF ===
2294 */
2295
2296optTag:
2297 { memset(&$$, 0, sizeof($$)); }
2298 | Tag { $$ = $1; }
2299 ;
2300
2301Tag:
Lev Walkinc603f102005-01-23 09:51:44 +00002302 TagTypeValue TagPlicit {
Lev Walkinf15320b2004-06-03 03:38:44 +00002303 $$ = $1;
Lev Walkinc603f102005-01-23 09:51:44 +00002304 $$.tag_mode = $2.tag_mode;
Lev Walkinf15320b2004-06-03 03:38:44 +00002305 }
Lev Walkinc603f102005-01-23 09:51:44 +00002306 ;
2307
2308TagTypeValue:
2309 '[' TagClass TOK_number ']' {
2310 $$ = $2;
2311 $$.tag_value = $3;
2312 };
2313
2314TagClass:
2315 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2316 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2317 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2318 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2319 ;
2320
2321TagPlicit:
2322 { $$.tag_mode = TM_DEFAULT; }
2323 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2324 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
Lev Walkinf15320b2004-06-03 03:38:44 +00002325 ;
2326
2327TypeRefName:
2328 TOK_typereference {
2329 checkmem($1);
2330 $$ = $1;
2331 }
Lev Walkinf59d0752004-08-18 04:59:12 +00002332 | TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002333 checkmem($1);
2334 $$ = $1;
2335 }
2336 ;
2337
Lev Walkinf59d0752004-08-18 04:59:12 +00002338
Lev Walkinf15320b2004-06-03 03:38:44 +00002339ObjectClassReference:
Lev Walkinf59d0752004-08-18 04:59:12 +00002340 TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002341 checkmem($1);
2342 $$ = $1;
2343 }
2344 ;
2345
Lev Walkin83cac2f2004-09-22 16:03:36 +00002346optIdentifier:
2347 { $$ = 0; }
2348 | Identifier {
2349 $$ = $1;
2350 }
Lev Walkin8f294e02005-06-06 08:28:58 +00002351 ;
Lev Walkin83cac2f2004-09-22 16:03:36 +00002352
Lev Walkinf15320b2004-06-03 03:38:44 +00002353Identifier:
2354 TOK_identifier {
2355 checkmem($1);
2356 $$ = $1;
2357 }
2358 ;
2359
Lev Walkinf15320b2004-06-03 03:38:44 +00002360%%
2361
2362
2363/*
2364 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2365 */
2366static asn1p_value_t *
2367_convert_bitstring2binary(char *str, int base) {
2368 asn1p_value_t *val;
2369 int slen;
2370 int memlen;
2371 int baselen;
2372 int bits;
2373 uint8_t *binary_vector;
2374 uint8_t *bv_ptr;
2375 uint8_t cur_val;
2376
2377 assert(str);
2378 assert(str[0] == '\'');
2379
2380 switch(base) {
2381 case 'B':
2382 baselen = 1;
2383 break;
2384 case 'H':
2385 baselen = 4;
2386 break;
2387 default:
2388 assert(base == 'B' || base == 'H');
2389 errno = EINVAL;
2390 return NULL;
2391 }
2392
2393 slen = strlen(str);
2394 assert(str[slen - 1] == base);
2395 assert(str[slen - 2] == '\'');
2396
2397 memlen = slen / (8 / baselen); /* Conservative estimate */
2398
2399 bv_ptr = binary_vector = malloc(memlen + 1);
2400 if(bv_ptr == NULL)
2401 /* ENOMEM */
2402 return NULL;
2403
2404 cur_val = 0;
2405 bits = 0;
2406 while(*(++str) != '\'') {
2407 switch(baselen) {
2408 case 1:
2409 switch(*str) {
2410 case '1':
2411 cur_val |= 1 << (7 - (bits % 8));
2412 case '0':
2413 break;
2414 default:
2415 assert(!"_y UNREACH1");
2416 case ' ': case '\r': case '\n':
2417 continue;
2418 }
2419 break;
2420 case 4:
2421 switch(*str) {
2422 case '0': case '1': case '2': case '3': case '4':
2423 case '5': case '6': case '7': case '8': case '9':
2424 cur_val |= (*str - '0') << (4 - (bits % 8));
2425 break;
2426 case 'A': case 'B': case 'C':
2427 case 'D': case 'E': case 'F':
2428 cur_val |= ((*str - 'A') + 10)
2429 << (4 - (bits % 8));
2430 break;
2431 default:
2432 assert(!"_y UNREACH2");
2433 case ' ': case '\r': case '\n':
2434 continue;
2435 }
2436 break;
2437 }
2438
2439 bits += baselen;
2440 if((bits % 8) == 0) {
2441 *bv_ptr++ = cur_val;
2442 cur_val = 0;
2443 }
2444 }
2445
2446 *bv_ptr = cur_val;
2447 assert((bv_ptr - binary_vector) <= memlen);
2448
2449 val = asn1p_value_frombits(binary_vector, bits, 0);
2450 if(val == NULL) {
2451 free(binary_vector);
2452 }
2453
2454 return val;
2455}
2456
Lev Walkin2e9bd5c2005-08-13 09:07:11 +00002457/*
2458 * For unnamed types (used in old X.208 compliant modules)
2459 * generate some sort of interim names, to not to force human being to fix
2460 * the specification's compliance to modern ASN.1 standards.
2461 */
2462static void
2463_fixup_anonymous_identifier(asn1p_expr_t *expr) {
2464 char *p;
2465 assert(expr->Identifier == 0);
2466
2467 /*
2468 * Try to figure out the type name
2469 * without going too much into details
2470 */
2471 expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type);
2472 if(expr->reference && expr->reference->comp_count > 0)
2473 expr->Identifier = expr->reference->components[0].name;
2474
2475 fprintf(stderr,
2476 "WARNING: Line %d: expected lower-case member identifier, "
2477 "found an unnamed %s.\n"
2478 "WARNING: Obsolete X.208 syntax detected, "
2479 "please give the member a name.\n",
2480 yylineno, expr->Identifier ? expr->Identifier : "type");
2481
2482 if(!expr->Identifier)
2483 expr->Identifier = "unnamed";
2484 expr->Identifier = strdup(expr->Identifier);
2485 assert(expr->Identifier);
2486 /* Make a lowercase identifier from the type name */
2487 for(p = expr->Identifier; *p; p++) {
2488 switch(*p) {
2489 case 'A' ... 'Z': *p += 32; break;
2490 case ' ': *p = '_'; break;
2491 case '-': *p = '_'; break;
2492 }
2493 }
2494 fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". "
2495 "Name clash may occur later.\n",
2496 expr->Identifier);
2497}
2498
Lev Walkinf15320b2004-06-03 03:38:44 +00002499int
2500yyerror(const char *msg) {
Lev Walkin9d542d22006-03-14 16:31:37 +00002501 extern char *asn1p_text;
Lev Walkinf15320b2004-06-03 03:38:44 +00002502 fprintf(stderr,
2503 "ASN.1 grammar parse error "
2504 "near line %d (token \"%s\"): %s\n",
Lev Walkinceb20e72004-09-05 10:40:41 +00002505 yylineno, asn1p_text, msg);
Lev Walkinf15320b2004-06-03 03:38:44 +00002506 return -1;
2507}
2508