blob: dbad995f65b817ebf6b8c2e8231ae68ea6cf9b06 [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;
Lev Walkind523ea42017-09-06 22:15:08 -070025const char *asn1p_parse_debug_filename;
26#define ASN_FILENAME asn1p_parse_debug_filename
Lev Walkinf15320b2004-06-03 03:38:44 +000027
Lev Walkin1ed22092005-08-12 10:06:17 +000028/*
Lev Walkinef625402005-09-05 05:17:57 +000029 * Process directives as <ASN1C:RepresentAsPointer>
Lev Walkin4696c742005-08-22 12:23:54 +000030 */
31extern int asn1p_as_pointer;
Lev Walkin4696c742005-08-22 12:23:54 +000032
33/*
Lev Walkin1ed22092005-08-12 10:06:17 +000034 * This temporary variable is used to solve the shortcomings of 1-lookahead
35 * parser.
36 */
37static struct AssignedIdentifier *saved_aid;
Lev Walkinf15320b2004-06-03 03:38:44 +000038
Lev Walkin2e9bd5c2005-08-13 09:07:11 +000039static asn1p_value_t *_convert_bitstring2binary(char *str, int base);
40static void _fixup_anonymous_identifier(asn1p_expr_t *expr);
Lev Walkinf15320b2004-06-03 03:38:44 +000041
Lev Walkina9532f42006-09-17 04:52:50 +000042static asn1p_module_t *currentModule;
43#define NEW_EXPR() (asn1p_expr_new(yylineno, currentModule))
44
Lev Walkin1ed22092005-08-12 10:06:17 +000045#define checkmem(ptr) do { \
46 if(!(ptr)) \
47 return yyerror("Memory failure"); \
Lev Walkinf15320b2004-06-03 03:38:44 +000048 } while(0)
49
Lev Walkin2c14a692005-08-12 10:08:45 +000050#define CONSTRAINT_INSERT(root, constr_type, arg1, arg2) do { \
Lev Walkin1ed22092005-08-12 10:06:17 +000051 if(arg1->type != constr_type) { \
52 int __ret; \
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +080053 root = asn1p_constraint_new(yylineno, currentModule); \
Lev Walkin1ed22092005-08-12 10:06:17 +000054 checkmem(root); \
55 root->type = constr_type; \
56 __ret = asn1p_constraint_insert(root, \
57 arg1); \
58 checkmem(__ret == 0); \
59 } else { \
60 root = arg1; \
61 } \
62 if(arg2) { \
63 int __ret \
64 = asn1p_constraint_insert(root, arg2); \
65 checkmem(__ret == 0); \
66 } \
Lev Walkinf15320b2004-06-03 03:38:44 +000067 } while(0)
68
Lev Walkin866bd7f2006-09-14 10:35:20 +000069#ifdef AL_IMPORT
70#error AL_IMPORT DEFINED ELSEWHERE!
71#endif
72#define AL_IMPORT(to,where,from,field) do { \
73 if(!(from)) break; \
74 while(TQ_FIRST(&((from)->where))) { \
75 TQ_ADD(&((to)->where), \
76 TQ_REMOVE(&((from)->where), field), \
77 field); \
78 } \
79 assert(TQ_FIRST(&((from)->where)) == 0); \
80 } while(0)
81
Lev Walkinf15320b2004-06-03 03:38:44 +000082%}
83
84
85/*
86 * Token value definition.
87 * a_*: ASN-specific types.
88 * tv_*: Locally meaningful types.
89 */
90%union {
91 asn1p_t *a_grammar;
92 asn1p_module_flags_e a_module_flags;
93 asn1p_module_t *a_module;
94 asn1p_expr_type_e a_type; /* ASN.1 Type */
95 asn1p_expr_t *a_expr; /* Constructed collection */
96 asn1p_constraint_t *a_constr; /* Constraint */
97 enum asn1p_constraint_type_e a_ctype;/* Constraint type */
98 asn1p_xports_t *a_xports; /* IMports/EXports */
Lev Walkin1ed22092005-08-12 10:06:17 +000099 struct AssignedIdentifier a_aid; /* Assigned Identifier */
Lev Walkinf15320b2004-06-03 03:38:44 +0000100 asn1p_oid_t *a_oid; /* Object Identifier */
101 asn1p_oid_arc_t a_oid_arc; /* Single OID's arc */
102 struct asn1p_type_tag_s a_tag; /* A tag */
103 asn1p_ref_t *a_ref; /* Reference to custom type */
104 asn1p_wsyntx_t *a_wsynt; /* WITH SYNTAX contents */
105 asn1p_wsyntx_chunk_t *a_wchunk; /* WITH SYNTAX chunk */
106 struct asn1p_ref_component_s a_refcomp; /* Component of a reference */
107 asn1p_value_t *a_value; /* Number, DefinedValue, etc */
108 struct asn1p_param_s a_parg; /* A parameter argument */
109 asn1p_paramlist_t *a_plist; /* A pargs list */
Lev Walkin9c974182004-09-15 11:59:51 +0000110 struct asn1p_expr_marker_s a_marker; /* OPTIONAL/DEFAULT */
Lev Walkinf15320b2004-06-03 03:38:44 +0000111 enum asn1p_constr_pres_e a_pres; /* PRESENT/ABSENT/OPTIONAL */
Lev Walkin144db9b2004-10-12 23:26:53 +0000112 asn1c_integer_t a_int;
Lev Walkinadf863f2006-09-05 16:18:34 +0000113 double a_dbl;
Lev Walkinf15320b2004-06-03 03:38:44 +0000114 char *tv_str;
115 struct {
116 char *buf;
117 int len;
118 } tv_opaque;
119 struct {
120 char *name;
121 struct asn1p_type_tag_s tag;
122 } tv_nametag;
123};
124
125/*
126 * Token types returned by scanner.
127 */
128%token TOK_PPEQ /* "::=", Pseudo Pascal EQuality */
Lev Walkin0e90aa02013-03-19 16:17:13 -0700129%token TOK_VBracketLeft TOK_VBracketRight /* "[[", "]]" */
Lev Walkin57074f12006-03-16 05:11:14 +0000130%token <tv_opaque> TOK_whitespace /* A span of whitespace */
Lev Walkinf15320b2004-06-03 03:38:44 +0000131%token <tv_opaque> TOK_opaque /* opaque data (driven from .y) */
132%token <tv_str> TOK_bstring
133%token <tv_opaque> TOK_cstring
134%token <tv_str> TOK_hstring
Lev Walkinbe518fa2017-09-07 02:05:28 -0700135%token <tv_str> TOK_identifier "identifier"
136%token <a_int> TOK_number "number"
137%token <a_int> TOK_number_negative "negative number"
Lev Walkinadf863f2006-09-05 16:18:34 +0000138%token <a_dbl> TOK_realnumber
Lev Walkind9574ae2005-03-24 16:22:35 +0000139%token <a_int> TOK_tuple
140%token <a_int> TOK_quadruple
Lev Walkinf15320b2004-06-03 03:38:44 +0000141%token <tv_str> TOK_typereference
Lev Walkinf59d0752004-08-18 04:59:12 +0000142%token <tv_str> TOK_capitalreference /* "CLASS1" */
Lev Walkinf15320b2004-06-03 03:38:44 +0000143%token <tv_str> TOK_typefieldreference /* "&Pork" */
144%token <tv_str> TOK_valuefieldreference /* "&id" */
Lev Walkin9d542d22006-03-14 16:31:37 +0000145%token <tv_str> TOK_Literal /* "BY" */
Lev Walkinf15320b2004-06-03 03:38:44 +0000146
147/*
Lev Walkinbe518fa2017-09-07 02:05:28 -0700148 * Tokens available with asn1p_lexer_hack_push_extended_values().
149 */
150%token TOK_ExtValue_BIT_STRING
151
152/*
Lev Walkinf15320b2004-06-03 03:38:44 +0000153 * Token types representing ASN.1 standard keywords.
154 */
155%token TOK_ABSENT
156%token TOK_ABSTRACT_SYNTAX
157%token TOK_ALL
158%token TOK_ANY
159%token TOK_APPLICATION
160%token TOK_AUTOMATIC
161%token TOK_BEGIN
162%token TOK_BIT
163%token TOK_BMPString
164%token TOK_BOOLEAN
165%token TOK_BY
166%token TOK_CHARACTER
167%token TOK_CHOICE
168%token TOK_CLASS
169%token TOK_COMPONENT
170%token TOK_COMPONENTS
171%token TOK_CONSTRAINED
172%token TOK_CONTAINING
173%token TOK_DEFAULT
174%token TOK_DEFINITIONS
175%token TOK_DEFINED
176%token TOK_EMBEDDED
177%token TOK_ENCODED
Lev Walkinf59d0752004-08-18 04:59:12 +0000178%token TOK_ENCODING_CONTROL
Lev Walkinf15320b2004-06-03 03:38:44 +0000179%token TOK_END
180%token TOK_ENUMERATED
181%token TOK_EXPLICIT
182%token TOK_EXPORTS
183%token TOK_EXTENSIBILITY
184%token TOK_EXTERNAL
185%token TOK_FALSE
186%token TOK_FROM
187%token TOK_GeneralizedTime
188%token TOK_GeneralString
189%token TOK_GraphicString
190%token TOK_IA5String
191%token TOK_IDENTIFIER
192%token TOK_IMPLICIT
193%token TOK_IMPLIED
194%token TOK_IMPORTS
195%token TOK_INCLUDES
196%token TOK_INSTANCE
Lev Walkinf59d0752004-08-18 04:59:12 +0000197%token TOK_INSTRUCTIONS
Lev Walkinf15320b2004-06-03 03:38:44 +0000198%token TOK_INTEGER
199%token TOK_ISO646String
200%token TOK_MAX
201%token TOK_MIN
202%token TOK_MINUS_INFINITY
203%token TOK_NULL
204%token TOK_NumericString
205%token TOK_OBJECT
206%token TOK_ObjectDescriptor
207%token TOK_OCTET
208%token TOK_OF
209%token TOK_OPTIONAL
210%token TOK_PATTERN
211%token TOK_PDV
212%token TOK_PLUS_INFINITY
213%token TOK_PRESENT
214%token TOK_PrintableString
215%token TOK_PRIVATE
216%token TOK_REAL
217%token TOK_RELATIVE_OID
218%token TOK_SEQUENCE
219%token TOK_SET
220%token TOK_SIZE
221%token TOK_STRING
222%token TOK_SYNTAX
223%token TOK_T61String
224%token TOK_TAGS
225%token TOK_TeletexString
226%token TOK_TRUE
227%token TOK_TYPE_IDENTIFIER
228%token TOK_UNIQUE
229%token TOK_UNIVERSAL
230%token TOK_UniversalString
231%token TOK_UTCTime
232%token TOK_UTF8String
233%token TOK_VideotexString
234%token TOK_VisibleString
235%token TOK_WITH
Lev Walkin752e9732017-08-04 02:06:22 -0700236%token UTF8_BOM "UTF-8 byte order mark"
Lev Walkinf15320b2004-06-03 03:38:44 +0000237
Lev Walkinf1727152006-09-21 01:50:37 +0000238%nonassoc TOK_EXCEPT
Lev Walkinf59d0752004-08-18 04:59:12 +0000239%left '^' TOK_INTERSECTION
240%left '|' TOK_UNION
Lev Walkinf15320b2004-06-03 03:38:44 +0000241
242/* Misc tags */
Lev Walkinbe518fa2017-09-07 02:05:28 -0700243%token TOK_TwoDots ".."
244%token TOK_ThreeDots "..."
Lev Walkinf15320b2004-06-03 03:38:44 +0000245
246
247/*
248 * Types defined herein.
249 */
250%type <a_grammar> ModuleList
Lev Walkin866bd7f2006-09-14 10:35:20 +0000251%type <a_module> ModuleDefinition
252%type <a_module> ModuleBody
253%type <a_module> AssignmentList
254%type <a_module> Assignment
255%type <a_module> optModuleBody /* Optional */
256%type <a_module_flags> optModuleDefinitionFlags
257%type <a_module_flags> ModuleDefinitionFlags /* Set of FL */
258%type <a_module_flags> ModuleDefinitionFlag /* Single FL */
259%type <a_module> optImports
260%type <a_module> optExports
Lev Walkinf15320b2004-06-03 03:38:44 +0000261%type <a_module> ImportsDefinition
Lev Walkin4a4543f2006-10-13 12:37:39 +0000262%type <a_module> optImportsBundleSet
Lev Walkinf15320b2004-06-03 03:38:44 +0000263%type <a_module> ImportsBundleSet
264%type <a_xports> ImportsBundle
265%type <a_xports> ImportsList
266%type <a_xports> ExportsDefinition
267%type <a_xports> ExportsBody
268%type <a_expr> ImportsElement
269%type <a_expr> ExportsElement
Lev Walkinf15320b2004-06-03 03:38:44 +0000270%type <a_expr> ExtensionAndException
Lev Walkina9532f42006-09-17 04:52:50 +0000271%type <a_expr> Type
Lev Walkin070a52d2004-08-22 03:19:54 +0000272%type <a_expr> TypeDeclaration
Lev Walkin4696c742005-08-22 12:23:54 +0000273%type <a_expr> TypeDeclarationSet
Lev Walkinf15320b2004-06-03 03:38:44 +0000274%type <a_ref> ComplexTypeReference
275%type <a_ref> ComplexTypeReferenceAmpList
276%type <a_refcomp> ComplexTypeReferenceElement
Lev Walkind370e9f2006-03-16 10:03:35 +0000277%type <a_refcomp> PrimitiveFieldReference
Lev Walkin9c2285a2006-03-09 08:49:26 +0000278%type <a_expr> FieldSpec
279%type <a_ref> FieldName
280%type <a_ref> DefinedObjectClass
Lev Walkinf15320b2004-06-03 03:38:44 +0000281%type <a_expr> ClassField
Lev Walkin9c2285a2006-03-09 08:49:26 +0000282%type <a_expr> ObjectClass
Lev Walkinf15320b2004-06-03 03:38:44 +0000283%type <a_expr> DataTypeReference /* Type1 ::= Type2 */
Lev Walkin0c0bca62006-03-21 04:48:15 +0000284%type <a_expr> DefinedType
Lev Walkin557f27d2006-03-21 07:46:48 +0000285%type <a_constr> ValueSet /* {a|b|c}*/
286%type <a_expr> ValueSetTypeAssignment /* Val INTEGER ::= {1|2} */
Lev Walkinc6ab03c2006-10-21 05:54:49 +0000287%type <a_expr> ValueAssignment /* val INTEGER ::= 1*/
Lev Walkin9c974182004-09-15 11:59:51 +0000288%type <a_value> Value
Lev Walkin0c0bca62006-03-21 04:48:15 +0000289%type <a_value> SimpleValue
Lev Walkinf15320b2004-06-03 03:38:44 +0000290%type <a_value> DefinedValue
291%type <a_value> SignedNumber
Lev Walkinadf863f2006-09-05 16:18:34 +0000292%type <a_value> RealValue
Lev Walkin1c8d5aa2006-10-27 05:37:39 +0000293%type <a_value> BitStringValue
Lev Walkin144db9b2004-10-12 23:26:53 +0000294%type <a_expr> optComponentTypeLists
Lev Walkin070a52d2004-08-22 03:19:54 +0000295%type <a_expr> ComponentTypeLists
296%type <a_expr> ComponentType
297%type <a_expr> AlternativeTypeLists
298%type <a_expr> AlternativeType
Lev Walkinf15320b2004-06-03 03:38:44 +0000299%type <a_expr> UniverationList
Lev Walkinbe518fa2017-09-07 02:05:28 -0700300%type <a_expr> Enumerations
301%type <a_expr> NamedBitList
302%type <a_expr> NamedBit
303%type <a_expr> NamedNumberList
304%type <a_expr> NamedNumber
305%type <a_expr> IdentifierList
306%type <a_expr> IdentifierElement
Lev Walkinf15320b2004-06-03 03:38:44 +0000307%type <a_expr> UniverationElement
308%type <tv_str> TypeRefName
309%type <tv_str> ObjectClassReference
Lev Walkinf15320b2004-06-03 03:38:44 +0000310%type <tv_str> Identifier
Lev Walkind523ea42017-09-06 22:15:08 -0700311%type <a_ref> IdentifierAsReference
312%type <a_value> IdentifierAsValue
Lev Walkin83cac2f2004-09-22 16:03:36 +0000313%type <tv_str> optIdentifier
Lev Walkinf15320b2004-06-03 03:38:44 +0000314%type <a_parg> ParameterArgumentName
315%type <a_plist> ParameterArgumentList
Lev Walkin5045dfa2006-03-21 09:41:28 +0000316%type <a_expr> ActualParameter
317%type <a_expr> ActualParameterList
Lev Walkin1ed22092005-08-12 10:06:17 +0000318%type <a_aid> AssignedIdentifier /* OID/DefinedValue */
Lev Walkinf15320b2004-06-03 03:38:44 +0000319%type <a_oid> ObjectIdentifier /* OID */
320%type <a_oid> optObjectIdentifier /* Optional OID */
321%type <a_oid> ObjectIdentifierBody
322%type <a_oid_arc> ObjectIdentifierElement
323%type <a_expr> BasicType
324%type <a_type> BasicTypeId
325%type <a_type> BasicTypeId_UniverationCompatible
326%type <a_type> BasicString
327%type <tv_opaque> Opaque
Lev Walkinc603f102005-01-23 09:51:44 +0000328%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
329%type <a_tag> TagClass TagTypeValue TagPlicit
Lev Walkinf15320b2004-06-03 03:38:44 +0000330%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
331%type <a_constr> optConstraints
Lev Walkind523ea42017-09-06 22:15:08 -0700332%type <a_constr> optSizeConstraints
Lev Walkina9532f42006-09-17 04:52:50 +0000333%type <a_constr> Constraint
Lev Walkind523ea42017-09-06 22:15:08 -0700334%type <a_constr> SingleTypeConstraint
335%type <a_constr> MultipleTypeConstraints
336%type <a_constr> NamedConstraint
337%type <a_constr> FullSpecification
338%type <a_constr> PartialSpecification
339%type <a_constr> TypeConstraints
340%type <a_constr> ConstraintSpec
Lev Walkina9532f42006-09-17 04:52:50 +0000341%type <a_constr> SubtypeConstraint
342%type <a_constr> GeneralConstraint
Lev Walkinf59d0752004-08-18 04:59:12 +0000343%type <a_constr> SetOfConstraints
344%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
345%type <a_constr> ElementSetSpec /* 1..2,...,3 */
Lev Walkinf1727152006-09-21 01:50:37 +0000346%type <a_constr> Unions
347%type <a_constr> Intersections
348%type <a_constr> IntersectionElements
Lev Walkinf15320b2004-06-03 03:38:44 +0000349%type <a_constr> ConstraintSubtypeElement /* 1..2 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000350%type <a_constr> SimpleTableConstraint
Lev Walkina9532f42006-09-17 04:52:50 +0000351%type <a_constr> UserDefinedConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +0000352%type <a_constr> TableConstraint
Lev Walkina9532f42006-09-17 04:52:50 +0000353%type <a_constr> ContentsConstraint
Lev Walkin5c541f12006-10-18 18:40:14 +0000354%type <a_constr> PatternConstraint
Lev Walkine596bf02005-03-28 15:01:27 +0000355%type <a_constr> InnerTypeConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +0000356%type <a_constr> ComponentRelationConstraint
357%type <a_constr> AtNotationList
358%type <a_ref> AtNotationElement
Lev Walkinff7dd142005-03-20 12:58:00 +0000359%type <a_value> SingleValue
360%type <a_value> ContainedSubtype
Lev Walkind523ea42017-09-06 22:15:08 -0700361%type <a_ctype> ConstraintType
Lev Walkinf15320b2004-06-03 03:38:44 +0000362%type <a_ctype> ConstraintRangeSpec
Lev Walkin1e448d32005-03-24 14:26:38 +0000363%type <a_value> RestrictedCharacterStringValue
Lev Walkinf15320b2004-06-03 03:38:44 +0000364%type <a_wsynt> optWithSyntax
365%type <a_wsynt> WithSyntax
Lev Walkin9d542d22006-03-14 16:31:37 +0000366%type <a_wsynt> WithSyntaxList
367%type <a_wchunk> WithSyntaxToken
Lev Walkinf15320b2004-06-03 03:38:44 +0000368%type <a_marker> optMarker Marker
369%type <a_int> optUnique
370%type <a_pres> optPresenceConstraint PresenceConstraint
371%type <tv_str> ComponentIdList
Lev Walkinef625402005-09-05 05:17:57 +0000372%type <a_int> NSTD_IndirectMarker
Lev Walkinf15320b2004-06-03 03:38:44 +0000373
Lev Walkinf15320b2004-06-03 03:38:44 +0000374%%
375
376
377ParsedGrammar:
Lev Walkin752e9732017-08-04 02:06:22 -0700378 UTF8_BOM ModuleList {
379 *(void **)param = $2;
380 }
381 | ModuleList {
Lev Walkinf15320b2004-06-03 03:38:44 +0000382 *(void **)param = $1;
383 }
384 ;
385
386ModuleList:
Lev Walkin866bd7f2006-09-14 10:35:20 +0000387 ModuleDefinition {
Lev Walkinf15320b2004-06-03 03:38:44 +0000388 $$ = asn1p_new();
389 checkmem($$);
390 TQ_ADD(&($$->modules), $1, mod_next);
391 }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000392 | ModuleList ModuleDefinition {
Lev Walkinf15320b2004-06-03 03:38:44 +0000393 $$ = $1;
394 TQ_ADD(&($$->modules), $2, mod_next);
395 }
396 ;
397
398/*
399 * ASN module definition.
400 * === EXAMPLE ===
401 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
402 * BEGIN
403 * ...
404 * END
405 * === EOF ===
406 */
407
Lev Walkin866bd7f2006-09-14 10:35:20 +0000408ModuleDefinition:
Lev Walkina9532f42006-09-17 04:52:50 +0000409 TypeRefName { currentModule = asn1p_module_new(); }
410 optObjectIdentifier TOK_DEFINITIONS
Lev Walkin866bd7f2006-09-14 10:35:20 +0000411 optModuleDefinitionFlags
Lev Walkinf15320b2004-06-03 03:38:44 +0000412 TOK_PPEQ TOK_BEGIN
Lev Walkin866bd7f2006-09-14 10:35:20 +0000413 optModuleBody
Lev Walkinf15320b2004-06-03 03:38:44 +0000414 TOK_END {
415
Lev Walkina9532f42006-09-17 04:52:50 +0000416 $$ = currentModule;
417
418 if($8) {
419 asn1p_module_t tmp = *($$);
420 *($$) = *($8);
421 *($8) = tmp;
422 asn1p_module_free($8);
Lev Walkinf15320b2004-06-03 03:38:44 +0000423 } else {
424 /* There's a chance that a module is just plain empty */
Lev Walkinf15320b2004-06-03 03:38:44 +0000425 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000426
Lev Walkin1ed22092005-08-12 10:06:17 +0000427 $$->ModuleName = $1;
Lev Walkina9532f42006-09-17 04:52:50 +0000428 $$->module_oid = $3;
429 $$->module_flags = $5;
Lev Walkinf15320b2004-06-03 03:38:44 +0000430 }
431 ;
432
433/*
434 * Object Identifier Definition
435 * { iso member-body(2) 3 }
436 */
437optObjectIdentifier:
438 { $$ = 0; }
439 | ObjectIdentifier { $$ = $1; }
440 ;
441
442ObjectIdentifier:
443 '{' ObjectIdentifierBody '}' {
444 $$ = $2;
445 }
446 | '{' '}' {
447 $$ = 0;
448 }
449 ;
450
451ObjectIdentifierBody:
452 ObjectIdentifierElement {
453 $$ = asn1p_oid_new();
454 asn1p_oid_add_arc($$, &$1);
455 if($1.name)
456 free($1.name);
457 }
458 | ObjectIdentifierBody ObjectIdentifierElement {
459 $$ = $1;
460 asn1p_oid_add_arc($$, &$2);
461 if($2.name)
462 free($2.name);
463 }
464 ;
465
466ObjectIdentifierElement:
467 Identifier { /* iso */
468 $$.name = $1;
469 $$.number = -1;
470 }
471 | Identifier '(' TOK_number ')' { /* iso(1) */
472 $$.name = $1;
473 $$.number = $3;
474 }
475 | TOK_number { /* 1 */
476 $$.name = 0;
477 $$.number = $1;
478 }
479 ;
480
481/*
482 * Optional module flags.
483 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000484optModuleDefinitionFlags:
Lev Walkinf15320b2004-06-03 03:38:44 +0000485 { $$ = MSF_NOFLAGS; }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000486 | ModuleDefinitionFlags {
Lev Walkinf15320b2004-06-03 03:38:44 +0000487 $$ = $1;
488 }
489 ;
490
491/*
492 * Module flags.
493 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000494ModuleDefinitionFlags:
495 ModuleDefinitionFlag {
Lev Walkinf15320b2004-06-03 03:38:44 +0000496 $$ = $1;
497 }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000498 | ModuleDefinitionFlags ModuleDefinitionFlag {
Lev Walkinf15320b2004-06-03 03:38:44 +0000499 $$ = $1 | $2;
500 }
501 ;
502
503/*
504 * Single module flag.
505 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000506ModuleDefinitionFlag:
Lev Walkinf15320b2004-06-03 03:38:44 +0000507 TOK_EXPLICIT TOK_TAGS {
508 $$ = MSF_EXPLICIT_TAGS;
509 }
510 | TOK_IMPLICIT TOK_TAGS {
511 $$ = MSF_IMPLICIT_TAGS;
512 }
513 | TOK_AUTOMATIC TOK_TAGS {
514 $$ = MSF_AUTOMATIC_TAGS;
515 }
516 | TOK_EXTENSIBILITY TOK_IMPLIED {
517 $$ = MSF_EXTENSIBILITY_IMPLIED;
518 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000519 /* EncodingReferenceDefault */
520 | TOK_capitalreference TOK_INSTRUCTIONS {
521 /* X.680Amd1 specifies TAG and XER */
522 if(strcmp($1, "TAG") == 0) {
523 $$ = MSF_TAG_INSTRUCTIONS;
524 } else if(strcmp($1, "XER") == 0) {
525 $$ = MSF_XER_INSTRUCTIONS;
526 } else {
527 fprintf(stderr,
Lev Walkind523ea42017-09-06 22:15:08 -0700528 "WARNING: %s INSTRUCTIONS at %s:%d: "
Lev Walkinf59d0752004-08-18 04:59:12 +0000529 "Unrecognized encoding reference\n",
Lev Walkind523ea42017-09-06 22:15:08 -0700530 $1, ASN_FILENAME, yylineno);
Lev Walkinf59d0752004-08-18 04:59:12 +0000531 $$ = MSF_unk_INSTRUCTIONS;
532 }
533 free($1);
534 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000535 ;
536
537/*
538 * Optional module body.
539 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000540optModuleBody:
Lev Walkinf15320b2004-06-03 03:38:44 +0000541 { $$ = 0; }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000542 | ModuleBody {
Lev Walkinf15320b2004-06-03 03:38:44 +0000543 $$ = $1;
544 }
545 ;
546
547/*
548 * ASN.1 Module body.
549 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000550ModuleBody:
551 optExports optImports AssignmentList {
552 $$ = asn1p_module_new();
553 AL_IMPORT($$, exports, $1, xp_next);
554 AL_IMPORT($$, imports, $2, xp_next);
555 AL_IMPORT($$, members, $3, next);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800556
557 asn1p_module_free($1);
558 asn1p_module_free($2);
559 asn1p_module_free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000560 }
561 ;
562
Lev Walkin866bd7f2006-09-14 10:35:20 +0000563AssignmentList:
564 Assignment {
565 $$ = $1;
566 }
567 | AssignmentList Assignment {
568 if($1) {
569 $$ = $1;
570 } else {
571 $$ = $2;
572 break;
573 }
574 AL_IMPORT($$, members, $2, next);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800575 asn1p_module_free($2);
Lev Walkin866bd7f2006-09-14 10:35:20 +0000576 }
577 ;
578
579
Lev Walkinf15320b2004-06-03 03:38:44 +0000580/*
581 * One of the elements of ASN.1 module specification.
582 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000583Assignment:
584 DataTypeReference {
Lev Walkinf15320b2004-06-03 03:38:44 +0000585 $$ = asn1p_module_new();
586 checkmem($$);
587 assert($1->expr_type != A1TC_INVALID);
588 assert($1->meta_type != AMT_INVALID);
589 TQ_ADD(&($$->members), $1, next);
590 }
Lev Walkinc6ab03c2006-10-21 05:54:49 +0000591 | ValueAssignment {
Lev Walkinf15320b2004-06-03 03:38:44 +0000592 $$ = asn1p_module_new();
593 checkmem($$);
594 assert($1->expr_type != A1TC_INVALID);
595 assert($1->meta_type != AMT_INVALID);
596 TQ_ADD(&($$->members), $1, next);
597 }
598 /*
599 * Value set definition
600 * === EXAMPLE ===
601 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
602 * === EOF ===
Lev Walkine700b202017-08-06 23:21:32 -0700603 * Also ObjectClassSet.
Lev Walkinf15320b2004-06-03 03:38:44 +0000604 */
Lev Walkin557f27d2006-03-21 07:46:48 +0000605 | ValueSetTypeAssignment {
Lev Walkinf15320b2004-06-03 03:38:44 +0000606 $$ = asn1p_module_new();
607 checkmem($$);
608 assert($1->expr_type != A1TC_INVALID);
609 assert($1->meta_type != AMT_INVALID);
610 TQ_ADD(&($$->members), $1, next);
611 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000612 | TOK_ENCODING_CONTROL TOK_capitalreference
613 { asn1p_lexer_hack_push_encoding_control(); }
614 {
615 fprintf(stderr,
616 "WARNING: ENCODING-CONTROL %s "
Lev Walkind523ea42017-09-06 22:15:08 -0700617 "specification at %s:%d ignored\n",
618 $2, ASN_FILENAME, yylineno);
Lev Walkinf59d0752004-08-18 04:59:12 +0000619 free($2);
620 $$ = 0;
621 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000622
623 /*
624 * Erroneous attemps
625 */
626 | BasicString {
627 return yyerror(
Lev Walkin70853052005-11-26 11:21:55 +0000628 "Attempt to redefine a standard basic string type, "
629 "please comment out or remove this type redefinition.");
Lev Walkinf15320b2004-06-03 03:38:44 +0000630 }
631 ;
632
633/*
634 * === EXAMPLE ===
635 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
636 * === EOF ===
637 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000638optImports:
639 { $$ = 0; }
640 | ImportsDefinition;
641
Lev Walkinf15320b2004-06-03 03:38:44 +0000642ImportsDefinition:
Lev Walkin4a4543f2006-10-13 12:37:39 +0000643 TOK_IMPORTS optImportsBundleSet ';' {
Lev Walkin1ed22092005-08-12 10:06:17 +0000644 if(!saved_aid && 0)
645 return yyerror("Unterminated IMPORTS FROM, "
646 "expected semicolon ';'");
647 saved_aid = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +0000648 $$ = $2;
649 }
650 /*
651 * Some error cases.
652 */
653 | TOK_IMPORTS TOK_FROM /* ... */ {
654 return yyerror("Empty IMPORTS list");
655 }
656 ;
657
Lev Walkin4a4543f2006-10-13 12:37:39 +0000658optImportsBundleSet:
659 { $$ = asn1p_module_new(); }
660 | ImportsBundleSet;
661
Lev Walkinf15320b2004-06-03 03:38:44 +0000662ImportsBundleSet:
663 ImportsBundle {
664 $$ = asn1p_module_new();
665 checkmem($$);
666 TQ_ADD(&($$->imports), $1, xp_next);
667 }
668 | ImportsBundleSet ImportsBundle {
669 $$ = $1;
670 TQ_ADD(&($$->imports), $2, xp_next);
671 }
672 ;
673
Lev Walkin1ed22092005-08-12 10:06:17 +0000674AssignedIdentifier:
675 { memset(&$$, 0, sizeof($$)); }
676 | ObjectIdentifier { $$.oid = $1; };
677 /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
678
Lev Walkinf15320b2004-06-03 03:38:44 +0000679ImportsBundle:
Lev Walkin1ed22092005-08-12 10:06:17 +0000680 ImportsList TOK_FROM TypeRefName AssignedIdentifier {
Lev Walkinf15320b2004-06-03 03:38:44 +0000681 $$ = $1;
Lev Walkin1ed22092005-08-12 10:06:17 +0000682 $$->fromModuleName = $3;
683 $$->identifier = $4;
684 /* This stupid thing is used for look-back hack. */
685 saved_aid = $$->identifier.oid ? 0 : &($$->identifier);
Lev Walkinf15320b2004-06-03 03:38:44 +0000686 checkmem($$);
687 }
688 ;
689
690ImportsList:
691 ImportsElement {
692 $$ = asn1p_xports_new();
693 checkmem($$);
694 TQ_ADD(&($$->members), $1, next);
695 }
696 | ImportsList ',' ImportsElement {
697 $$ = $1;
698 TQ_ADD(&($$->members), $3, next);
699 }
700 ;
701
702ImportsElement:
703 TypeRefName {
Lev Walkina9532f42006-09-17 04:52:50 +0000704 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000705 checkmem($$);
706 $$->Identifier = $1;
707 $$->expr_type = A1TC_REFERENCE;
708 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000709 | TypeRefName '{' '}' { /* Completely equivalent to above */
Lev Walkina9532f42006-09-17 04:52:50 +0000710 $$ = NEW_EXPR();
Lev Walkin144db9b2004-10-12 23:26:53 +0000711 checkmem($$);
712 $$->Identifier = $1;
713 $$->expr_type = A1TC_REFERENCE;
714 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000715 | Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +0000716 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000717 checkmem($$);
718 $$->Identifier = $1;
719 $$->expr_type = A1TC_REFERENCE;
720 }
721 ;
722
Lev Walkin866bd7f2006-09-14 10:35:20 +0000723
724optExports:
725 { $$ = 0; }
726 | ExportsDefinition {
727 $$ = asn1p_module_new();
728 checkmem($$);
729 if($1) {
730 TQ_ADD(&($$->exports), $1, xp_next);
731 } else {
732 /* "EXPORTS ALL;" */
733 }
734 }
735 ;
736
Lev Walkinf15320b2004-06-03 03:38:44 +0000737ExportsDefinition:
738 TOK_EXPORTS ExportsBody ';' {
739 $$ = $2;
740 }
741 | TOK_EXPORTS TOK_ALL ';' {
742 $$ = 0;
743 }
744 | TOK_EXPORTS ';' {
745 /* Empty EXPORTS clause effectively prohibits export. */
746 $$ = asn1p_xports_new();
747 checkmem($$);
748 }
749 ;
750
751ExportsBody:
752 ExportsElement {
753 $$ = asn1p_xports_new();
754 assert($$);
755 TQ_ADD(&($$->members), $1, next);
756 }
757 | ExportsBody ',' ExportsElement {
758 $$ = $1;
759 TQ_ADD(&($$->members), $3, next);
760 }
761 ;
762
763ExportsElement:
764 TypeRefName {
Lev Walkina9532f42006-09-17 04:52:50 +0000765 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000766 checkmem($$);
767 $$->Identifier = $1;
768 $$->expr_type = A1TC_EXPORTVAR;
769 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000770 | TypeRefName '{' '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000771 $$ = NEW_EXPR();
Lev Walkin144db9b2004-10-12 23:26:53 +0000772 checkmem($$);
773 $$->Identifier = $1;
774 $$->expr_type = A1TC_EXPORTVAR;
775 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000776 | Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +0000777 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000778 checkmem($$);
779 $$->Identifier = $1;
780 $$->expr_type = A1TC_EXPORTVAR;
781 }
782 ;
783
784
Lev Walkin418298d2006-07-13 08:24:20 +0000785ValueSet: '{' ElementSetSpecs '}' { $$ = $2; };
Lev Walkin557f27d2006-03-21 07:46:48 +0000786
787ValueSetTypeAssignment:
788 TypeRefName DefinedType TOK_PPEQ ValueSet {
Lev Walkinf15320b2004-06-03 03:38:44 +0000789 $$ = $2;
790 assert($$->Identifier == 0);
791 $$->Identifier = $1;
792 $$->meta_type = AMT_VALUESET;
Lev Walkin557f27d2006-03-21 07:46:48 +0000793 $$->constraints = $4;
Lev Walkinf15320b2004-06-03 03:38:44 +0000794 }
795 ;
796
Lev Walkin0c0bca62006-03-21 04:48:15 +0000797DefinedType:
798 BasicType {
799 $$ = $1;
800 }
801 /*
802 * A DefinedType reference.
803 * "CLASS1.&id.&id2"
804 * or
805 * "Module.Type"
806 * or
807 * "Module.identifier"
808 * or
809 * "Type"
810 */
811 | ComplexTypeReference {
Lev Walkina9532f42006-09-17 04:52:50 +0000812 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000813 checkmem($$);
814 $$->reference = $1;
815 $$->expr_type = A1TC_REFERENCE;
816 $$->meta_type = AMT_TYPEREF;
817 }
Lev Walkin0c0bca62006-03-21 04:48:15 +0000818 /*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000819 * A parameterized assignment.
Lev Walkin0c0bca62006-03-21 04:48:15 +0000820 */
Lev Walkin5045dfa2006-03-21 09:41:28 +0000821 | ComplexTypeReference '{' ActualParameterList '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000822 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000823 checkmem($$);
Lev Walkin0c0bca62006-03-21 04:48:15 +0000824 $$->reference = $1;
825 $$->rhs_pspecs = $3;
826 $$->expr_type = A1TC_REFERENCE;
827 $$->meta_type = AMT_TYPEREF;
Lev Walkinf15320b2004-06-03 03:38:44 +0000828 }
829 ;
830
Lev Walkinf15320b2004-06-03 03:38:44 +0000831/*
832 * Data Type Reference.
833 * === EXAMPLE ===
834 * Type3 ::= CHOICE { a Type1, b Type 2 }
835 * === EOF ===
836 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000837DataTypeReference:
838 /*
839 * Optionally tagged type definition.
840 */
Lev Walkin9c2285a2006-03-09 08:49:26 +0000841 TypeRefName TOK_PPEQ Type {
Lev Walkinaf120f72004-09-14 02:36:39 +0000842 $$ = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000843 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000844 assert($$->expr_type);
845 assert($$->meta_type);
846 }
Lev Walkin9c2285a2006-03-09 08:49:26 +0000847 | TypeRefName TOK_PPEQ ObjectClass {
Lev Walkinf15320b2004-06-03 03:38:44 +0000848 $$ = $3;
849 $$->Identifier = $1;
850 assert($$->expr_type == A1TC_CLASSDEF);
Lev Walkin9c2285a2006-03-09 08:49:26 +0000851 assert($$->meta_type == AMT_OBJECTCLASS);
Lev Walkinf15320b2004-06-03 03:38:44 +0000852 }
853 /*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000854 * Parameterized <Type> declaration:
Lev Walkinf15320b2004-06-03 03:38:44 +0000855 * === EXAMPLE ===
856 * SIGNED { ToBeSigned } ::= SEQUENCE {
857 * toBeSigned ToBeSigned,
858 * algorithm AlgorithmIdentifier,
859 * signature BIT STRING
860 * }
861 * === EOF ===
862 */
Lev Walkin070a52d2004-08-22 03:19:54 +0000863 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000864 $$ = $6;
Lev Walkin5045dfa2006-03-21 09:41:28 +0000865 $$->Identifier = $1;
866 $$->lhs_params = $3;
867 }
868 /* Parameterized CLASS declaration */
869 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ ObjectClass {
870 $$ = $6;
Lev Walkinf15320b2004-06-03 03:38:44 +0000871 $$->Identifier = $1;
Lev Walkina00d6b32006-03-21 03:40:38 +0000872 $$->lhs_params = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000873 }
874 ;
875
876ParameterArgumentList:
877 ParameterArgumentName {
878 int ret;
879 $$ = asn1p_paramlist_new(yylineno);
880 checkmem($$);
881 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
882 checkmem(ret == 0);
Lev Walkina964e032017-03-26 03:48:06 -0700883 asn1p_ref_free($1.governor);
884 free($1.argument);
Lev Walkinf15320b2004-06-03 03:38:44 +0000885 }
886 | ParameterArgumentList ',' ParameterArgumentName {
887 int ret;
888 $$ = $1;
889 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
890 checkmem(ret == 0);
Lev Walkina964e032017-03-26 03:48:06 -0700891 asn1p_ref_free($3.governor);
892 free($3.argument);
Lev Walkinf15320b2004-06-03 03:38:44 +0000893 }
894 ;
895
896ParameterArgumentName:
897 TypeRefName {
898 $$.governor = NULL;
899 $$.argument = $1;
900 }
901 | TypeRefName ':' Identifier {
902 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800903 $$.governor = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +0000904 ret = asn1p_ref_add_component($$.governor, $1, 0);
905 checkmem(ret == 0);
906 $$.argument = $3;
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800907 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000908 }
Lev Walkinc8092cb2005-02-18 16:34:21 +0000909 | TypeRefName ':' TypeRefName {
910 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800911 $$.governor = asn1p_ref_new(yylineno, currentModule);
Lev Walkinc8092cb2005-02-18 16:34:21 +0000912 ret = asn1p_ref_add_component($$.governor, $1, 0);
913 checkmem(ret == 0);
914 $$.argument = $3;
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800915 free($1);
Lev Walkinc8092cb2005-02-18 16:34:21 +0000916 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000917 | BasicTypeId ':' Identifier {
918 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800919 $$.governor = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +0000920 ret = asn1p_ref_add_component($$.governor,
921 ASN_EXPR_TYPE2STR($1), 1);
922 checkmem(ret == 0);
923 $$.argument = $3;
924 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000925 | BasicTypeId ':' TypeRefName {
926 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800927 $$.governor = asn1p_ref_new(yylineno, currentModule);
Lev Walkin5045dfa2006-03-21 09:41:28 +0000928 ret = asn1p_ref_add_component($$.governor,
929 ASN_EXPR_TYPE2STR($1), 1);
930 checkmem(ret == 0);
931 $$.argument = $3;
932 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000933 ;
934
Lev Walkin5045dfa2006-03-21 09:41:28 +0000935ActualParameterList:
936 ActualParameter {
Lev Walkina9532f42006-09-17 04:52:50 +0000937 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000938 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000939 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000940 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000941 | ActualParameterList ',' ActualParameter {
Lev Walkinf15320b2004-06-03 03:38:44 +0000942 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000943 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000944 }
945 ;
946
Lev Walkin5045dfa2006-03-21 09:41:28 +0000947ActualParameter:
Lev Walkin070a52d2004-08-22 03:19:54 +0000948 Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000949 $$ = $1;
950 }
Lev Walkin0c0bca62006-03-21 04:48:15 +0000951 | SimpleValue {
Lev Walkina9532f42006-09-17 04:52:50 +0000952 $$ = NEW_EXPR();
Lev Walkin0c0bca62006-03-21 04:48:15 +0000953 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800954 $$->Identifier = strdup("?");
Lev Walkin0c0bca62006-03-21 04:48:15 +0000955 $$->expr_type = A1TC_REFERENCE;
956 $$->meta_type = AMT_VALUE;
957 $$->value = $1;
958 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000959 | Identifier {
Lev Walkina00d6b32006-03-21 03:40:38 +0000960 asn1p_ref_t *ref;
Lev Walkina9532f42006-09-17 04:52:50 +0000961 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000962 checkmem($$);
963 $$->Identifier = $1;
964 $$->expr_type = A1TC_REFERENCE;
965 $$->meta_type = AMT_VALUE;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800966 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkina00d6b32006-03-21 03:40:38 +0000967 asn1p_ref_add_component(ref, $1, RLT_lowercase);
968 $$->value = asn1p_value_fromref(ref, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +0000969 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000970 | ValueSet {
Lev Walkina9532f42006-09-17 04:52:50 +0000971 $$ = NEW_EXPR();
Lev Walkin5045dfa2006-03-21 09:41:28 +0000972 $$->expr_type = A1TC_VALUESET;
973 $$->meta_type = AMT_VALUESET;
974 $$->constraints = $1;
975 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000976 ;
977
978/*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000979 | '{' ActualParameter '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000980 $$ = NEW_EXPR();
Lev Walkinc8092cb2005-02-18 16:34:21 +0000981 checkmem($$);
982 asn1p_expr_add($$, $2);
983 $$->expr_type = A1TC_PARAMETRIZED;
984 $$->meta_type = AMT_TYPE;
985 }
986 ;
987*/
988
989/*
Lev Walkinf15320b2004-06-03 03:38:44 +0000990 * A collection of constructed data type members.
991 */
Lev Walkin144db9b2004-10-12 23:26:53 +0000992optComponentTypeLists:
Lev Walkina9532f42006-09-17 04:52:50 +0000993 { $$ = NEW_EXPR(); }
Lev Walkin144db9b2004-10-12 23:26:53 +0000994 | ComponentTypeLists { $$ = $1; };
995
Lev Walkin070a52d2004-08-22 03:19:54 +0000996ComponentTypeLists:
997 ComponentType {
Lev Walkina9532f42006-09-17 04:52:50 +0000998 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000999 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00001000 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001001 }
Lev Walkin070a52d2004-08-22 03:19:54 +00001002 | ComponentTypeLists ',' ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +00001003 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001004 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001005 }
Lev Walkin0e90aa02013-03-19 16:17:13 -07001006 | ComponentTypeLists ',' TOK_VBracketLeft ComponentTypeLists TOK_VBracketRight {
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001007 $$ = $1;
Lev Walkin0e90aa02013-03-19 16:17:13 -07001008 asn1p_expr_add_many($$, $4);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001009 asn1p_expr_free($4);
Lev Walkin0e90aa02013-03-19 16:17:13 -07001010 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001011 ;
1012
Lev Walkin070a52d2004-08-22 03:19:54 +00001013ComponentType:
Lev Walkinaf120f72004-09-14 02:36:39 +00001014 Identifier Type optMarker {
Lev Walkin070a52d2004-08-22 03:19:54 +00001015 $$ = $2;
1016 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +00001017 $$->Identifier = $1;
Lev Walkinef625402005-09-05 05:17:57 +00001018 $3.flags |= $$->marker.flags;
Lev Walkin070a52d2004-08-22 03:19:54 +00001019 $$->marker = $3;
1020 }
Lev Walkinef625402005-09-05 05:17:57 +00001021 | Type optMarker {
1022 $$ = $1;
1023 $2.flags |= $$->marker.flags;
1024 $$->marker = $2;
1025 _fixup_anonymous_identifier($$);
1026 }
Lev Walkin070a52d2004-08-22 03:19:54 +00001027 | TOK_COMPONENTS TOK_OF Type {
Lev Walkina9532f42006-09-17 04:52:50 +00001028 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001029 checkmem($$);
1030 $$->meta_type = $3->meta_type;
1031 $$->expr_type = A1TC_COMPONENTS_OF;
Lev Walkin1004aa92004-09-08 00:28:11 +00001032 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +00001033 }
1034 | ExtensionAndException {
1035 $$ = $1;
1036 }
1037 ;
1038
1039AlternativeTypeLists:
1040 AlternativeType {
Lev Walkina9532f42006-09-17 04:52:50 +00001041 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001042 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00001043 asn1p_expr_add($$, $1);
Lev Walkin070a52d2004-08-22 03:19:54 +00001044 }
1045 | AlternativeTypeLists ',' AlternativeType {
1046 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001047 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +00001048 }
1049 ;
1050
1051AlternativeType:
Lev Walkinaf120f72004-09-14 02:36:39 +00001052 Identifier Type {
Lev Walkin070a52d2004-08-22 03:19:54 +00001053 $$ = $2;
1054 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +00001055 $$->Identifier = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001056 }
1057 | ExtensionAndException {
1058 $$ = $1;
1059 }
Lev Walkin2e9bd5c2005-08-13 09:07:11 +00001060 | Type {
1061 $$ = $1;
1062 _fixup_anonymous_identifier($$);
1063 }
Lev Walkin070a52d2004-08-22 03:19:54 +00001064 ;
1065
Lev Walkin9c2285a2006-03-09 08:49:26 +00001066ObjectClass:
1067 TOK_CLASS '{' FieldSpec '}' optWithSyntax {
Lev Walkinf15320b2004-06-03 03:38:44 +00001068 $$ = $3;
1069 checkmem($$);
1070 $$->with_syntax = $5;
1071 assert($$->expr_type == A1TC_CLASSDEF);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001072 assert($$->meta_type == AMT_OBJECTCLASS);
Lev Walkinf15320b2004-06-03 03:38:44 +00001073 }
1074 ;
1075
1076optUnique:
1077 { $$ = 0; }
1078 | TOK_UNIQUE { $$ = 1; }
1079 ;
1080
Lev Walkin9c2285a2006-03-09 08:49:26 +00001081FieldSpec:
Lev Walkinf15320b2004-06-03 03:38:44 +00001082 ClassField {
Lev Walkina9532f42006-09-17 04:52:50 +00001083 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001084 checkmem($$);
1085 $$->expr_type = A1TC_CLASSDEF;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001086 $$->meta_type = AMT_OBJECTCLASS;
Lev Walkin1004aa92004-09-08 00:28:11 +00001087 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001088 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001089 | FieldSpec ',' ClassField {
Lev Walkinf15320b2004-06-03 03:38:44 +00001090 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001091 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001092 }
1093 ;
1094
Lev Walkin9c2285a2006-03-09 08:49:26 +00001095 /* X.681 */
Lev Walkinf15320b2004-06-03 03:38:44 +00001096ClassField:
Lev Walkin9c2285a2006-03-09 08:49:26 +00001097
1098 /* TypeFieldSpec ::= typefieldreference TypeOptionalitySpec? */
1099 TOK_typefieldreference optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001100 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001101 checkmem($$);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001102 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001103 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001104 $$->expr_type = A1TC_CLASSFIELD_TFS; /* TypeFieldSpec */
Lev Walkinf15320b2004-06-03 03:38:44 +00001105 $$->marker = $2;
1106 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001107
1108 /* FixedTypeValueFieldSpec ::= valuefieldreference Type UNIQUE ? ValueOptionalitySpec ? */
1109 | TOK_valuefieldreference Type optUnique optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001110 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001111 $$->Identifier = $1;
1112 $$->meta_type = AMT_OBJECTFIELD;
1113 $$->expr_type = A1TC_CLASSFIELD_FTVFS; /* FixedTypeValueFieldSpec */
Lev Walkinb7c45ca2004-11-24 17:43:29 +00001114 $$->unique = $3;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001115 $$->marker = $4;
1116 asn1p_expr_add($$, $2);
Lev Walkinf15320b2004-06-03 03:38:44 +00001117 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001118
1119 /* VariableTypeValueFieldSpec ::= valuefieldreference FieldName ValueOptionalitySpec ? */
1120 | TOK_valuefieldreference FieldName optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001121 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001122 $$->Identifier = $1;
1123 $$->meta_type = AMT_OBJECTFIELD;
1124 $$->expr_type = A1TC_CLASSFIELD_VTVFS;
1125 $$->reference = $2;
1126 $$->marker = $3;
1127 }
1128
Lev Walkin9c2285a2006-03-09 08:49:26 +00001129 /* ObjectFieldSpec ::= objectfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1130 | TOK_valuefieldreference DefinedObjectClass optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001131 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001132 checkmem($$);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001133 $$->Identifier = $1;
1134 $$->reference = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00001135 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001136 $$->expr_type = A1TC_CLASSFIELD_OFS;
1137 $$->marker = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +00001138 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001139
Lev Walkin54868752006-03-09 09:08:49 +00001140 /* VariableTypeValueSetFieldSpec ::= valuesetfieldreference FieldName ValueOptionalitySpec ? */
1141 | TOK_typefieldreference FieldName optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001142 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001143 $$->Identifier = $1;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001144 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin54868752006-03-09 09:08:49 +00001145 $$->expr_type = A1TC_CLASSFIELD_VTVSFS;
1146 $$->reference = $2;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001147 $$->marker = $3;
1148 }
1149
1150 /* FixedTypeValueSetFieldSpec ::= valuesetfieldreference Type ValueSetOptionalitySpec ? */
1151 | TOK_typefieldreference Type optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001152 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001153 checkmem($$);
1154 $$->Identifier = $1;
1155 $$->meta_type = AMT_OBJECTFIELD;
1156 $$->expr_type = A1TC_CLASSFIELD_FTVSFS;
1157 asn1p_expr_add($$, $2);
1158 $$->marker = $3;
1159 }
1160
Lev Walkin54868752006-03-09 09:08:49 +00001161 /* ObjectSetFieldSpec ::= objectsetfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1162 | TOK_typefieldreference DefinedObjectClass optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001163 $$ = NEW_EXPR();
Lev Walkin54868752006-03-09 09:08:49 +00001164 checkmem($$);
1165 $$->Identifier = $1;
1166 $$->reference = $2;
1167 $$->meta_type = AMT_OBJECTFIELD;
1168 $$->expr_type = A1TC_CLASSFIELD_OSFS;
1169 $$->marker = $3;
1170 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001171 ;
1172
1173optWithSyntax:
1174 { $$ = 0; }
1175 | WithSyntax {
1176 $$ = $1;
1177 }
1178 ;
1179
1180WithSyntax:
1181 TOK_WITH TOK_SYNTAX '{'
1182 { asn1p_lexer_hack_enable_with_syntax(); }
Lev Walkin9d542d22006-03-14 16:31:37 +00001183 WithSyntaxList
Lev Walkinf15320b2004-06-03 03:38:44 +00001184 '}' {
1185 $$ = $5;
1186 }
1187 ;
1188
Lev Walkin9d542d22006-03-14 16:31:37 +00001189WithSyntaxList:
1190 WithSyntaxToken {
Lev Walkinf15320b2004-06-03 03:38:44 +00001191 $$ = asn1p_wsyntx_new();
1192 TQ_ADD(&($$->chunks), $1, next);
1193 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001194 | WithSyntaxList WithSyntaxToken {
Lev Walkinf15320b2004-06-03 03:38:44 +00001195 $$ = $1;
1196 TQ_ADD(&($$->chunks), $2, next);
1197 }
1198 ;
1199
Lev Walkin9d542d22006-03-14 16:31:37 +00001200WithSyntaxToken:
Lev Walkin57074f12006-03-16 05:11:14 +00001201 TOK_whitespace {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001202 $$ = asn1p_wsyntx_chunk_fromstring($1.buf, 0);
Lev Walkin57074f12006-03-16 05:11:14 +00001203 $$->type = WC_WHITESPACE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001204 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001205 | TOK_Literal {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001206 $$ = asn1p_wsyntx_chunk_fromstring($1, 0);
Lev Walkin9d542d22006-03-14 16:31:37 +00001207 }
Lev Walkind370e9f2006-03-16 10:03:35 +00001208 | PrimitiveFieldReference {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001209 $$ = asn1p_wsyntx_chunk_fromstring($1.name, 0);
Lev Walkind370e9f2006-03-16 10:03:35 +00001210 $$->type = WC_FIELD;
Lev Walkinf15320b2004-06-03 03:38:44 +00001211 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001212 | '[' WithSyntaxList ']' {
1213 $$ = asn1p_wsyntx_chunk_fromsyntax($2);
1214 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001215 ;
1216
Lev Walkinf15320b2004-06-03 03:38:44 +00001217ExtensionAndException:
1218 TOK_ThreeDots {
Lev Walkina9532f42006-09-17 04:52:50 +00001219 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001220 checkmem($$);
1221 $$->Identifier = strdup("...");
1222 checkmem($$->Identifier);
1223 $$->expr_type = A1TC_EXTENSIBLE;
1224 $$->meta_type = AMT_TYPE;
1225 }
1226 | TOK_ThreeDots '!' DefinedValue {
Lev Walkina9532f42006-09-17 04:52:50 +00001227 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001228 checkmem($$);
1229 $$->Identifier = strdup("...");
1230 checkmem($$->Identifier);
1231 $$->value = $3;
1232 $$->expr_type = A1TC_EXTENSIBLE;
1233 $$->meta_type = AMT_TYPE;
1234 }
1235 | TOK_ThreeDots '!' SignedNumber {
Lev Walkina9532f42006-09-17 04:52:50 +00001236 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001237 checkmem($$);
1238 $$->Identifier = strdup("...");
1239 $$->value = $3;
1240 checkmem($$->Identifier);
1241 $$->expr_type = A1TC_EXTENSIBLE;
1242 $$->meta_type = AMT_TYPE;
1243 }
1244 ;
1245
Lev Walkin070a52d2004-08-22 03:19:54 +00001246Type:
Lev Walkinaf120f72004-09-14 02:36:39 +00001247 optTag TypeDeclaration optConstraints {
1248 $$ = $2;
1249 $$->tag = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001250 /*
1251 * Outer constraint for SEQUENCE OF and SET OF applies
1252 * to the inner type.
1253 */
1254 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1255 || $$->expr_type == ASN_CONSTR_SET_OF) {
1256 assert(!TQ_FIRST(&($$->members))->constraints);
Lev Walkinaf120f72004-09-14 02:36:39 +00001257 TQ_FIRST(&($$->members))->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001258 } else {
1259 if($$->constraints) {
1260 assert(!$2);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001261 /* Check this : optConstraints is not used ?! */
1262 asn1p_constraint_free($3);
Lev Walkin070a52d2004-08-22 03:19:54 +00001263 } else {
Lev Walkinaf120f72004-09-14 02:36:39 +00001264 $$->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001265 }
1266 }
Lev Walkinef625402005-09-05 05:17:57 +00001267 }
1268 ;
1269
1270NSTD_IndirectMarker:
1271 {
1272 $$ = asn1p_as_pointer ? EM_INDIRECT : 0;
1273 asn1p_as_pointer = 0;
Lev Walkin070a52d2004-08-22 03:19:54 +00001274 }
1275 ;
1276
1277TypeDeclaration:
Lev Walkinef625402005-09-05 05:17:57 +00001278 NSTD_IndirectMarker TypeDeclarationSet {
Lev Walkin4696c742005-08-22 12:23:54 +00001279 $$ = $2;
Lev Walkinef625402005-09-05 05:17:57 +00001280 $$->marker.flags |= $1;
1281
1282 if(($$->marker.flags & EM_INDIRECT)
1283 && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
1284 fprintf(stderr,
1285 "INFO: Directive <ASN1C:RepresentAsPointer> "
Lev Walkind523ea42017-09-06 22:15:08 -07001286 "applied to %s at %s:%d\n",
Lev Walkinef625402005-09-05 05:17:57 +00001287 ASN_EXPR_TYPE2STR($$->expr_type)
1288 ? ASN_EXPR_TYPE2STR($$->expr_type)
1289 : "member",
Lev Walkind523ea42017-09-06 22:15:08 -07001290 ASN_FILENAME, $$->_lineno
Lev Walkinef625402005-09-05 05:17:57 +00001291 );
1292 }
Lev Walkin4696c742005-08-22 12:23:54 +00001293 }
Lev Walkinef625402005-09-05 05:17:57 +00001294 ;
Lev Walkin4696c742005-08-22 12:23:54 +00001295
1296TypeDeclarationSet:
Lev Walkin0c0bca62006-03-21 04:48:15 +00001297 DefinedType {
Lev Walkinf15320b2004-06-03 03:38:44 +00001298 $$ = $1;
1299 }
Lev Walkinef625402005-09-05 05:17:57 +00001300 | TOK_CHOICE '{' AlternativeTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001301 $$ = $3;
1302 assert($$->expr_type == A1TC_INVALID);
1303 $$->expr_type = ASN_CONSTR_CHOICE;
1304 $$->meta_type = AMT_TYPE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001305 }
Lev Walkinef625402005-09-05 05:17:57 +00001306 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001307 $$ = $3;
1308 assert($$->expr_type == A1TC_INVALID);
1309 $$->expr_type = ASN_CONSTR_SEQUENCE;
1310 $$->meta_type = AMT_TYPE;
1311 }
Lev Walkinef625402005-09-05 05:17:57 +00001312 | TOK_SET '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001313 $$ = $3;
1314 assert($$->expr_type == A1TC_INVALID);
1315 $$->expr_type = ASN_CONSTR_SET;
1316 $$->meta_type = AMT_TYPE;
1317 }
Lev Walkind523ea42017-09-06 22:15:08 -07001318 | TOK_SEQUENCE optSizeConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkina9532f42006-09-17 04:52:50 +00001319 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001320 checkmem($$);
1321 $$->constraints = $2;
1322 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1323 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001324 $6->Identifier = $4;
1325 $6->tag = $5;
1326 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001327 }
Lev Walkind523ea42017-09-06 22:15:08 -07001328 | TOK_SET optSizeConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkina9532f42006-09-17 04:52:50 +00001329 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001330 checkmem($$);
1331 $$->constraints = $2;
1332 $$->expr_type = ASN_CONSTR_SET_OF;
1333 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001334 $6->Identifier = $4;
1335 $6->tag = $5;
1336 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001337 }
1338 | TOK_ANY {
Lev Walkina9532f42006-09-17 04:52:50 +00001339 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001340 checkmem($$);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001341 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001342 $$->meta_type = AMT_TYPE;
1343 }
1344 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1345 int ret;
Lev Walkina9532f42006-09-17 04:52:50 +00001346 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001347 checkmem($$);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001348 $$->reference = asn1p_ref_new(yylineno, currentModule);
Lev Walkin070a52d2004-08-22 03:19:54 +00001349 ret = asn1p_ref_add_component($$->reference,
1350 $4, RLT_lowercase);
1351 checkmem(ret == 0);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001352 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001353 $$->meta_type = AMT_TYPE;
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001354 free($4);
Lev Walkin070a52d2004-08-22 03:19:54 +00001355 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001356 | TOK_INSTANCE TOK_OF ComplexTypeReference {
Lev Walkina9532f42006-09-17 04:52:50 +00001357 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001358 checkmem($$);
1359 $$->reference = $3;
1360 $$->expr_type = A1TC_INSTANCE;
1361 $$->meta_type = AMT_TYPE;
1362 }
1363 ;
1364
1365/*
1366 * A type name consisting of several components.
1367 * === EXAMPLE ===
1368 * === EOF ===
1369 */
1370ComplexTypeReference:
1371 TOK_typereference {
1372 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001373 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001374 checkmem($$);
1375 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1376 checkmem(ret == 0);
1377 free($1);
1378 }
1379 | TOK_typereference '.' TypeRefName {
1380 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001381 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001382 checkmem($$);
1383 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1384 checkmem(ret == 0);
1385 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1386 checkmem(ret == 0);
1387 free($1);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001388 free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001389 }
Lev Walkin9c974182004-09-15 11:59:51 +00001390 | ObjectClassReference '.' TypeRefName {
1391 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001392 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkin9c974182004-09-15 11:59:51 +00001393 checkmem($$);
1394 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1395 checkmem(ret == 0);
1396 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1397 checkmem(ret == 0);
1398 free($1);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001399 free($3);
Lev Walkin9c974182004-09-15 11:59:51 +00001400 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001401 | TOK_typereference '.' Identifier {
1402 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001403 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001404 checkmem($$);
1405 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1406 checkmem(ret == 0);
1407 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1408 checkmem(ret == 0);
1409 free($1);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001410 free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001411 }
1412 | ObjectClassReference {
1413 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001414 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001415 checkmem($$);
1416 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1417 free($1);
1418 checkmem(ret == 0);
1419 }
1420 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1421 int ret;
1422 $$ = $3;
1423 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1424 free($1);
1425 checkmem(ret == 0);
1426 /*
1427 * Move the last element infront.
1428 */
1429 {
1430 struct asn1p_ref_component_s tmp_comp;
1431 tmp_comp = $$->components[$$->comp_count-1];
1432 memmove(&$$->components[1],
1433 &$$->components[0],
1434 sizeof($$->components[0])
1435 * ($$->comp_count - 1));
1436 $$->components[0] = tmp_comp;
1437 }
1438 }
1439 ;
1440
1441ComplexTypeReferenceAmpList:
1442 ComplexTypeReferenceElement {
1443 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001444 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001445 checkmem($$);
1446 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1447 free($1.name);
1448 checkmem(ret == 0);
1449 }
1450 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1451 int ret;
1452 $$ = $1;
1453 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1454 free($3.name);
1455 checkmem(ret == 0);
1456 }
1457 ;
1458
Lev Walkind370e9f2006-03-16 10:03:35 +00001459ComplexTypeReferenceElement: PrimitiveFieldReference;
Lev Walkinf15320b2004-06-03 03:38:44 +00001460
Lev Walkind370e9f2006-03-16 10:03:35 +00001461PrimitiveFieldReference:
Lev Walkinf15320b2004-06-03 03:38:44 +00001462 /* "&Type1" */
1463 TOK_typefieldreference {
1464 $$.lex_type = RLT_AmpUppercase;
1465 $$.name = $1;
1466 }
1467 /* "&id" */
1468 | TOK_valuefieldreference {
1469 $$.lex_type = RLT_Amplowercase;
1470 $$.name = $1;
1471 }
1472 ;
1473
1474
Lev Walkin9c2285a2006-03-09 08:49:26 +00001475FieldName:
1476 /* "&Type1" */
1477 TOK_typefieldreference {
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);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001480 free($1);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001481 }
1482 | FieldName '.' TOK_typefieldreference {
1483 $$ = $$;
1484 asn1p_ref_add_component($$, $3, RLT_AmpUppercase);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001485 free($3);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001486 }
1487 | FieldName '.' TOK_valuefieldreference {
1488 $$ = $$;
1489 asn1p_ref_add_component($$, $3, RLT_Amplowercase);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001490 free($3);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001491 }
1492 ;
1493
1494DefinedObjectClass:
1495 TOK_capitalreference {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001496 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001497 asn1p_ref_add_component($$, $1, RLT_CAPITALS);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001498 free($1);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001499 }
Lev Walkin54868752006-03-09 09:08:49 +00001500/*
Lev Walkin9c2285a2006-03-09 08:49:26 +00001501 | TypeRefName '.' TOK_capitalreference {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001502 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001503 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1504 asn1p_ref_add_component($$, $3, RLT_CAPITALS);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001505 free($1);
1506 free($3);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001507 }
Lev Walkin54868752006-03-09 09:08:49 +00001508*/
Lev Walkin9c2285a2006-03-09 08:49:26 +00001509 ;
1510
1511
Lev Walkinf15320b2004-06-03 03:38:44 +00001512/*
1513 * === EXAMPLE ===
1514 * value INTEGER ::= 1
1515 * === EOF ===
1516 */
Lev Walkinc6ab03c2006-10-21 05:54:49 +00001517ValueAssignment:
1518 Identifier Type TOK_PPEQ Value {
Lev Walkinf15320b2004-06-03 03:38:44 +00001519 $$ = $2;
1520 assert($$->Identifier == NULL);
1521 $$->Identifier = $1;
1522 $$->meta_type = AMT_VALUE;
1523 $$->value = $4;
1524 }
1525 ;
1526
Lev Walkin9c974182004-09-15 11:59:51 +00001527Value:
Lev Walkin0c0bca62006-03-21 04:48:15 +00001528 SimpleValue
1529 | DefinedValue
1530 | Identifier ':' Value {
Lev Walkin9c974182004-09-15 11:59:51 +00001531 $$ = asn1p_value_fromint(0);
1532 checkmem($$);
1533 $$->type = ATV_CHOICE_IDENTIFIER;
1534 $$->value.choice_identifier.identifier = $1;
1535 $$->value.choice_identifier.value = $3;
1536 }
Lev Walkincbad2512005-03-24 16:27:02 +00001537 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Lev Walkinf15320b2004-06-03 03:38:44 +00001538 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1539 checkmem($$);
1540 $$->type = ATV_UNPARSED;
1541 }
Lev Walkin9c974182004-09-15 11:59:51 +00001542 | TOK_NULL {
1543 $$ = asn1p_value_fromint(0);
1544 checkmem($$);
1545 $$->type = ATV_NULL;
1546 }
Lev Walkin0c0bca62006-03-21 04:48:15 +00001547 ;
1548
1549SimpleValue:
1550 TOK_FALSE {
Lev Walkin9c974182004-09-15 11:59:51 +00001551 $$ = asn1p_value_fromint(0);
1552 checkmem($$);
1553 $$->type = ATV_FALSE;
1554 }
1555 | TOK_TRUE {
1556 $$ = asn1p_value_fromint(0);
1557 checkmem($$);
1558 $$->type = ATV_TRUE;
1559 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001560 | TOK_bstring {
1561 $$ = _convert_bitstring2binary($1, 'B');
1562 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001563 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001564 }
1565 | TOK_hstring {
1566 $$ = _convert_bitstring2binary($1, 'H');
1567 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001568 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001569 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001570 | RestrictedCharacterStringValue {
1571 $$ = $$;
Lev Walkinf15320b2004-06-03 03:38:44 +00001572 }
1573 | SignedNumber {
1574 $$ = $1;
1575 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001576 ;
1577
1578DefinedValue:
1579 Identifier {
1580 asn1p_ref_t *ref;
1581 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001582 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001583 checkmem(ref);
1584 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1585 checkmem(ret == 0);
1586 $$ = asn1p_value_fromref(ref, 0);
1587 checkmem($$);
1588 free($1);
1589 }
1590 | TypeRefName '.' Identifier {
1591 asn1p_ref_t *ref;
1592 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001593 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001594 checkmem(ref);
1595 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1596 checkmem(ret == 0);
1597 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1598 checkmem(ret == 0);
1599 $$ = asn1p_value_fromref(ref, 0);
1600 checkmem($$);
1601 free($1);
1602 free($3);
1603 }
1604 ;
1605
Lev Walkin1e448d32005-03-24 14:26:38 +00001606
1607RestrictedCharacterStringValue:
1608 TOK_cstring {
1609 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1610 checkmem($$);
1611 }
Lev Walkind9574ae2005-03-24 16:22:35 +00001612 | TOK_tuple {
1613 $$ = asn1p_value_fromint($1);
1614 checkmem($$);
1615 $$->type = ATV_TUPLE;
1616 }
1617 | TOK_quadruple {
1618 $$ = asn1p_value_fromint($1);
1619 checkmem($$);
1620 $$->type = ATV_QUADRUPLE;
1621 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001622 ;
1623
Lev Walkinf15320b2004-06-03 03:38:44 +00001624Opaque:
1625 TOK_opaque {
Lev Walkin1893ddf2005-03-20 14:28:32 +00001626 $$.len = $1.len + 1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001627 $$.buf = malloc($$.len + 1);
1628 checkmem($$.buf);
1629 $$.buf[0] = '{';
Lev Walkin1893ddf2005-03-20 14:28:32 +00001630 memcpy($$.buf + 1, $1.buf, $1.len);
Lev Walkinf15320b2004-06-03 03:38:44 +00001631 $$.buf[$$.len] = '\0';
1632 free($1.buf);
1633 }
1634 | Opaque TOK_opaque {
1635 int newsize = $1.len + $2.len;
1636 char *p = malloc(newsize + 1);
1637 checkmem(p);
1638 memcpy(p , $1.buf, $1.len);
1639 memcpy(p + $1.len, $2.buf, $2.len);
1640 p[newsize] = '\0';
1641 free($1.buf);
1642 free($2.buf);
1643 $$.buf = p;
1644 $$.len = newsize;
1645 }
1646 ;
1647
1648BasicTypeId:
1649 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1650 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1651 | TOK_REAL { $$ = ASN_BASIC_REAL; }
Lev Walkinf15320b2004-06-03 03:38:44 +00001652 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1653 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1654 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1655 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1656 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1657 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1658 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1659 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
Lev Walkinbe518fa2017-09-07 02:05:28 -07001660 | BasicString
1661 | BasicTypeId_UniverationCompatible
Lev Walkinf15320b2004-06-03 03:38:44 +00001662 ;
1663
1664/*
1665 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1666 */
1667BasicTypeId_UniverationCompatible:
1668 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
Lev Walkinbe518fa2017-09-07 02:05:28 -07001669 | TOK_ENUMERATED { $$ = ASN_BASIC_INTEGER; }
Lev Walkinf15320b2004-06-03 03:38:44 +00001670 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1671 ;
1672
1673BasicType:
1674 BasicTypeId {
Lev Walkina9532f42006-09-17 04:52:50 +00001675 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001676 checkmem($$);
1677 $$->expr_type = $1;
1678 $$->meta_type = AMT_TYPE;
1679 }
Lev Walkinbe518fa2017-09-07 02:05:28 -07001680 | TOK_INTEGER '{' NamedNumberList '}' {
1681 $$ = $3;
1682 $$->expr_type = ASN_BASIC_INTEGER;
1683 $$->meta_type = AMT_TYPE;
1684 }
1685 | TOK_ENUMERATED '{' Enumerations '}' {
1686 $$ = $3;
1687 $$->expr_type = ASN_BASIC_ENUMERATED;
1688 $$->meta_type = AMT_TYPE;
1689 }
1690 | TOK_BIT TOK_STRING '{' NamedBitList '}' {
1691 $$ = $4;
1692 $$->expr_type = ASN_BASIC_BIT_STRING;
1693 $$->meta_type = AMT_TYPE;
1694 }
1695 | TOK_ExtValue_BIT_STRING '{' IdentifierList '}' {
1696 $$ = $3;
1697 $$->expr_type = ASN_BASIC_BIT_STRING;
1698 $$->meta_type = AMT_TYPE;
1699 }
1700 | TOK_ExtValue_BIT_STRING '{' '}' {
1701 $$ = NEW_EXPR();
1702 checkmem($$);
1703 $$->expr_type = ASN_BASIC_BIT_STRING;
1704 $$->meta_type = AMT_TYPE;
1705 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001706 ;
1707
1708BasicString:
1709 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1710 | TOK_GeneralString {
1711 $$ = ASN_STRING_GeneralString;
Lev Walkin9c974182004-09-15 11:59:51 +00001712 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001713 }
1714 | TOK_GraphicString {
1715 $$ = ASN_STRING_GraphicString;
Lev Walkin9c974182004-09-15 11:59:51 +00001716 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001717 }
1718 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1719 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1720 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1721 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1722 | TOK_T61String {
1723 $$ = ASN_STRING_T61String;
Lev Walkin9c974182004-09-15 11:59:51 +00001724 fprintf(stderr, "WARNING: T61String is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001725 }
1726 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1727 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1728 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1729 | TOK_VideotexString {
1730 $$ = ASN_STRING_VideotexString;
Lev Walkin9c974182004-09-15 11:59:51 +00001731 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001732 }
1733 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1734 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1735 ;
1736
Lev Walkind2ea1de2004-08-20 13:25:29 +00001737
Lev Walkinf15320b2004-06-03 03:38:44 +00001738/*
1739 * Data type constraints.
1740 */
Lev Walkinf1727152006-09-21 01:50:37 +00001741UnionMark: '|' | TOK_UNION;
1742IntersectionMark: '^' | TOK_INTERSECTION;
Lev Walkinf15320b2004-06-03 03:38:44 +00001743
Lev Walkind523ea42017-09-06 22:15:08 -07001744/* empty | Constraint */
Lev Walkinf59d0752004-08-18 04:59:12 +00001745optConstraints:
1746 { $$ = 0; }
Lev Walkind523ea42017-09-06 22:15:08 -07001747 | Constraint;
Lev Walkind2ea1de2004-08-20 13:25:29 +00001748
Lev Walkind523ea42017-09-06 22:15:08 -07001749/* empty | Constraint | SIZE(...) */
1750optSizeConstraints:
1751 { $$ = 0; }
1752 | Constraint
1753 | TOK_SIZE '(' ConstraintSpec ')' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001754 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001755 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001756 ;
1757
Lev Walkind523ea42017-09-06 22:15:08 -07001758Constraint:
1759 SetOfConstraints {
1760 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
1761 }
1762 ;
1763
Lev Walkinf59d0752004-08-18 04:59:12 +00001764SetOfConstraints:
Lev Walkind523ea42017-09-06 22:15:08 -07001765 '(' ConstraintSpec ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001766 $$ = $2;
1767 }
Lev Walkind523ea42017-09-06 22:15:08 -07001768 | SetOfConstraints '(' ConstraintSpec ')' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001769 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
Lev Walkinf59d0752004-08-18 04:59:12 +00001770 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001771 ;
1772
Lev Walkind523ea42017-09-06 22:15:08 -07001773ConstraintSpec: SubtypeConstraint | GeneralConstraint;
1774
1775SubtypeConstraint: ElementSetSpecs;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001776
Lev Walkinf59d0752004-08-18 04:59:12 +00001777ElementSetSpecs:
Lev Walkin5045dfa2006-03-21 09:41:28 +00001778 TOK_ThreeDots {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001779 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkin5045dfa2006-03-21 09:41:28 +00001780 $$->type = ACT_EL_EXT;
1781 }
Lev Walkind523ea42017-09-06 22:15:08 -07001782 | ElementSetSpec
Lev Walkinf59d0752004-08-18 04:59:12 +00001783 | ElementSetSpec ',' TOK_ThreeDots {
Lev Walkinf15320b2004-06-03 03:38:44 +00001784 asn1p_constraint_t *ct;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001785 ct = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001786 ct->type = ACT_EL_EXT;
Lev Walkin2c14a692005-08-12 10:08:45 +00001787 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00001788 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001789 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001790 asn1p_constraint_t *ct;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001791 ct = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001792 ct->type = ACT_EL_EXT;
Lev Walkin2c14a692005-08-12 10:08:45 +00001793 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinb4fcdd22004-08-13 12:35:09 +00001794 ct = $$;
Lev Walkin2c14a692005-08-12 10:08:45 +00001795 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
Lev Walkinf15320b2004-06-03 03:38:44 +00001796 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001797 ;
1798
Lev Walkinf59d0752004-08-18 04:59:12 +00001799ElementSetSpec:
Lev Walkinf1727152006-09-21 01:50:37 +00001800 Unions
Lev Walkin1e448d32005-03-24 14:26:38 +00001801 | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001802 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
Lev Walkin1e448d32005-03-24 14:26:38 +00001803 }
Lev Walkinf1727152006-09-21 01:50:37 +00001804 ;
1805
1806Unions:
1807 Intersections
1808 | Unions UnionMark Intersections {
Lev Walkin2c14a692005-08-12 10:08:45 +00001809 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001810 }
Lev Walkinf1727152006-09-21 01:50:37 +00001811 ;
1812
1813Intersections:
1814 IntersectionElements
1815 | Intersections IntersectionMark IntersectionElements {
Lev Walkin2c14a692005-08-12 10:08:45 +00001816 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001817 }
Lev Walkinf1727152006-09-21 01:50:37 +00001818 ;
1819
1820
1821IntersectionElements:
1822 ConstraintSubtypeElement
1823 | ConstraintSubtypeElement TOK_EXCEPT ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001824 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001825 }
1826 ;
1827
1828ConstraintSubtypeElement:
Lev Walkind523ea42017-09-06 22:15:08 -07001829 ConstraintType '(' ElementSetSpecs ')' {
Lev Walkinf59d0752004-08-18 04:59:12 +00001830 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001831 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf59d0752004-08-18 04:59:12 +00001832 checkmem($$);
1833 $$->type = $1;
1834 ret = asn1p_constraint_insert($$, $3);
1835 checkmem(ret == 0);
1836 }
1837 | '(' ElementSetSpecs ')' {
1838 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001839 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf59d0752004-08-18 04:59:12 +00001840 checkmem($$);
1841 $$->type = ACT_CA_SET;
1842 ret = asn1p_constraint_insert($$, $2);
1843 checkmem(ret == 0);
1844 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001845 | SingleValue {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001846 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001847 checkmem($$);
1848 $$->type = ACT_EL_VALUE;
1849 $$->value = $1;
1850 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001851 | ContainedSubtype {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001852 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinff7dd142005-03-20 12:58:00 +00001853 checkmem($$);
1854 $$->type = ACT_EL_TYPE;
1855 $$->containedSubtype = $1;
1856 }
1857 | SingleValue ConstraintRangeSpec SingleValue {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001858 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001859 checkmem($$);
1860 $$->type = $2;
1861 $$->range_start = $1;
1862 $$->range_stop = $3;
1863 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001864 | TOK_MIN ConstraintRangeSpec SingleValue {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001865 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001866 checkmem($$);
Lev Walkinf59d0752004-08-18 04:59:12 +00001867 $$->type = $2;
1868 $$->range_start = asn1p_value_fromint(-123);
1869 $$->range_stop = $3;
1870 $$->range_start->type = ATV_MIN;
1871 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001872 | SingleValue ConstraintRangeSpec TOK_MAX {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001873 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf59d0752004-08-18 04:59:12 +00001874 checkmem($$);
1875 $$->type = $2;
1876 $$->range_start = $1;
1877 $$->range_stop = asn1p_value_fromint(321);
1878 $$->range_stop->type = ATV_MAX;
1879 }
1880 | TOK_MIN ConstraintRangeSpec TOK_MAX {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001881 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf59d0752004-08-18 04:59:12 +00001882 checkmem($$);
1883 $$->type = $2;
1884 $$->range_start = asn1p_value_fromint(-123);
1885 $$->range_stop = asn1p_value_fromint(321);
1886 $$->range_start->type = ATV_MIN;
1887 $$->range_stop->type = ATV_MAX;
Lev Walkinf15320b2004-06-03 03:38:44 +00001888 }
Lev Walkind523ea42017-09-06 22:15:08 -07001889 | InnerTypeConstraint
1890 | PatternConstraint
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001891 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1892 $$ = asn1p_constraint_new(yylineno, currentModule);
1893 checkmem($$);
1894 $$->type = ACT_EL_VALUE;
1895 $$->value = asn1p_value_frombuf($3.buf, $3.len, 0);
1896 $$->value->type = ATV_UNPARSED;
1897 }
Lev Walkin5c541f12006-10-18 18:40:14 +00001898 ;
1899
1900PatternConstraint:
1901 TOK_PATTERN TOK_cstring {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001902 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkin5c541f12006-10-18 18:40:14 +00001903 $$->type = ACT_CT_PATTERN;
1904 $$->value = asn1p_value_frombuf($2.buf, $2.len, 0);
1905 }
1906 | TOK_PATTERN Identifier {
1907 asn1p_ref_t *ref;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001908 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkin5c541f12006-10-18 18:40:14 +00001909 $$->type = ACT_CT_PATTERN;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001910 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkin5c541f12006-10-18 18:40:14 +00001911 asn1p_ref_add_component(ref, $2, RLT_lowercase);
1912 $$->value = asn1p_value_fromref(ref, 0);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001913 free($2);
Lev Walkin5c541f12006-10-18 18:40:14 +00001914 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001915 ;
1916
Lev Walkind523ea42017-09-06 22:15:08 -07001917ConstraintType:
Lev Walkinf15320b2004-06-03 03:38:44 +00001918 TOK_SIZE {
1919 $$ = ACT_CT_SIZE;
1920 }
1921 | TOK_FROM {
1922 $$ = ACT_CT_FROM;
1923 }
1924 ;
1925
Lev Walkinff7dd142005-03-20 12:58:00 +00001926SingleValue:
Lev Walkinc8092cb2005-02-18 16:34:21 +00001927 TOK_FALSE {
1928 $$ = asn1p_value_fromint(0);
1929 checkmem($$);
1930 $$->type = ATV_FALSE;
1931 }
1932 | TOK_TRUE {
1933 $$ = asn1p_value_fromint(1);
1934 checkmem($$);
1935 $$->type = ATV_TRUE;
1936 }
Lev Walkinadf863f2006-09-05 16:18:34 +00001937 | RealValue
1938 | RestrictedCharacterStringValue
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001939 | BitStringValue
Lev Walkinf15320b2004-06-03 03:38:44 +00001940 | Identifier {
1941 asn1p_ref_t *ref;
1942 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001943 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001944 checkmem(ref);
1945 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1946 checkmem(ret == 0);
1947 $$ = asn1p_value_fromref(ref, 0);
1948 checkmem($$);
1949 free($1);
1950 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001951 ;
1952
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001953BitStringValue:
1954 TOK_bstring {
1955 $$ = _convert_bitstring2binary($1, 'B');
1956 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001957 free($1);
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001958 }
1959 | TOK_hstring {
1960 $$ = _convert_bitstring2binary($1, 'H');
1961 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001962 free($1);
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001963 }
1964 ;
1965
Lev Walkinff7dd142005-03-20 12:58:00 +00001966ContainedSubtype:
Lev Walkind523ea42017-09-06 22:15:08 -07001967 Type {
1968 $$ = asn1p_value_fromtype($1);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001969 checkmem($$);
Lev Walkind523ea42017-09-06 22:15:08 -07001970 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001971 ;
1972
Lev Walkind523ea42017-09-06 22:15:08 -07001973/*
1974 * X.680 08/2015
1975 * #51.8.5
1976 */
Lev Walkine596bf02005-03-28 15:01:27 +00001977InnerTypeConstraint:
Lev Walkind523ea42017-09-06 22:15:08 -07001978 TOK_WITH TOK_COMPONENT SingleTypeConstraint {
Lev Walkin2c14a692005-08-12 10:08:45 +00001979 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
Lev Walkine596bf02005-03-28 15:01:27 +00001980 }
Lev Walkind523ea42017-09-06 22:15:08 -07001981 | TOK_WITH TOK_COMPONENTS MultipleTypeConstraints {
1982 assert($3->type == ACT_CA_CSV);
1983 $3->type = ACT_CT_WCOMPS;
1984 $$ = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +00001985 }
1986 ;
Lev Walkind523ea42017-09-06 22:15:08 -07001987SingleTypeConstraint: Constraint;
1988MultipleTypeConstraints: FullSpecification | PartialSpecification;
1989FullSpecification: '{' TypeConstraints '}' { $$ = $2; };
1990PartialSpecification:
1991 '{' TOK_ThreeDots ',' TypeConstraints '}' {
1992 assert($4->type == ACT_CA_CSV);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001993 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkind523ea42017-09-06 22:15:08 -07001994 $$->type = ACT_CA_CSV;
1995 asn1p_constraint_t *ct = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001996 checkmem($$);
Lev Walkind523ea42017-09-06 22:15:08 -07001997 ct->type = ACT_EL_EXT;
1998 asn1p_constraint_insert($$, ct);
1999 for(unsigned i = 0; i < $4->el_count; i++) {
2000 asn1p_constraint_insert($$, $4->elements[i]);
2001 }
2002 };
2003TypeConstraints:
2004 NamedConstraint {
2005 $$ = asn1p_constraint_new(yylineno, currentModule);
2006 $$->type = ACT_CA_CSV;
2007 asn1p_constraint_insert($$, $1);
2008 }
2009 | TypeConstraints ',' NamedConstraint {
2010 $$ = $1;
2011 asn1p_constraint_insert($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002012 }
2013 ;
Lev Walkind523ea42017-09-06 22:15:08 -07002014NamedConstraint:
2015 IdentifierAsValue optConstraints optPresenceConstraint {
2016 $$ = asn1p_constraint_new(yylineno, currentModule);
2017 checkmem($$);
2018 $$->type = ACT_EL_VALUE;
2019 $$->value = $1;
2020 if($2) asn1p_constraint_insert($$, $2);
2021 $$->presence = $3;
2022 }
2023 ;
Lev Walkinf15320b2004-06-03 03:38:44 +00002024
2025/*
Lev Walkind523ea42017-09-06 22:15:08 -07002026 * presence constraint for NamedConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +00002027 */
2028optPresenceConstraint:
2029 { $$ = ACPRES_DEFAULT; }
2030 | PresenceConstraint { $$ = $1; }
2031 ;
2032
2033PresenceConstraint:
2034 TOK_PRESENT {
2035 $$ = ACPRES_PRESENT;
2036 }
2037 | TOK_ABSENT {
2038 $$ = ACPRES_ABSENT;
2039 }
2040 | TOK_OPTIONAL {
2041 $$ = ACPRES_OPTIONAL;
2042 }
2043 ;
2044
Lev Walkina9532f42006-09-17 04:52:50 +00002045
2046/* X.682 */
2047GeneralConstraint:
2048 UserDefinedConstraint
2049 | TableConstraint
2050 | ContentsConstraint
2051 ;
2052
2053UserDefinedConstraint:
2054 TOK_CONSTRAINED TOK_BY '{'
2055 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002056 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkina9532f42006-09-17 04:52:50 +00002057 checkmem($$);
2058 $$->type = ACT_CT_CTDBY;
2059 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
2060 checkmem($$->value);
2061 $$->value->type = ATV_UNPARSED;
2062 }
2063 ;
2064
2065ContentsConstraint:
2066 TOK_CONTAINING Type {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002067 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkina9532f42006-09-17 04:52:50 +00002068 $$->type = ACT_CT_CTNG;
2069 $$->value = asn1p_value_fromtype($2);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08002070 asn1p_expr_free($2);
Lev Walkina9532f42006-09-17 04:52:50 +00002071 }
2072 ;
2073
2074ConstraintRangeSpec:
2075 TOK_TwoDots { $$ = ACT_EL_RANGE; }
2076 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
2077 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
2078 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
2079 ;
Lev Walkinf15320b2004-06-03 03:38:44 +00002080TableConstraint:
2081 SimpleTableConstraint {
2082 $$ = $1;
2083 }
2084 | ComponentRelationConstraint {
2085 $$ = $1;
2086 }
2087 ;
2088
2089/*
2090 * "{ExtensionSet}"
2091 */
2092SimpleTableConstraint:
2093 '{' TypeRefName '}' {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002094 asn1p_ref_t *ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002095 asn1p_constraint_t *ct;
2096 int ret;
2097 ret = asn1p_ref_add_component(ref, $2, 0);
2098 checkmem(ret == 0);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002099 ct = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002100 checkmem($$);
2101 ct->type = ACT_EL_VALUE;
2102 ct->value = asn1p_value_fromref(ref, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00002103 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08002104 free($2);
Lev Walkinf15320b2004-06-03 03:38:44 +00002105 }
2106 ;
2107
2108ComponentRelationConstraint:
2109 SimpleTableConstraint '{' AtNotationList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00002110 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002111 }
2112 ;
2113
2114AtNotationList:
2115 AtNotationElement {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002116 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002117 checkmem($$);
2118 $$->type = ACT_EL_VALUE;
2119 $$->value = asn1p_value_fromref($1, 0);
2120 }
2121 | AtNotationList ',' AtNotationElement {
2122 asn1p_constraint_t *ct;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002123 ct = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002124 checkmem(ct);
2125 ct->type = ACT_EL_VALUE;
2126 ct->value = asn1p_value_fromref($3, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00002127 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00002128 }
2129 ;
2130
2131/*
2132 * @blah
2133 */
2134AtNotationElement:
2135 '@' ComponentIdList {
2136 char *p = malloc(strlen($2) + 2);
2137 int ret;
2138 *p = '@';
2139 strcpy(p + 1, $2);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002140 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002141 ret = asn1p_ref_add_component($$, p, 0);
2142 checkmem(ret == 0);
2143 free(p);
2144 free($2);
2145 }
2146 | '@' '.' ComponentIdList {
2147 char *p = malloc(strlen($3) + 3);
2148 int ret;
2149 p[0] = '@';
2150 p[1] = '.';
2151 strcpy(p + 2, $3);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002152 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002153 ret = asn1p_ref_add_component($$, p, 0);
2154 checkmem(ret == 0);
2155 free(p);
2156 free($3);
2157 }
2158 ;
2159
2160/* identifier "." ... */
2161ComponentIdList:
2162 Identifier {
2163 $$ = $1;
2164 }
2165 | ComponentIdList '.' Identifier {
2166 int l1 = strlen($1);
2167 int l3 = strlen($3);
2168 $$ = malloc(l1 + 1 + l3 + 1);
2169 memcpy($$, $1, l1);
2170 $$[l1] = '.';
2171 memcpy($$ + l1 + 1, $3, l3);
2172 $$[l1 + 1 + l3] = '\0';
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08002173 free($1);
2174 free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002175 }
2176 ;
2177
2178
2179
2180/*
2181 * MARKERS
2182 */
2183
2184optMarker:
Lev Walkin9c974182004-09-15 11:59:51 +00002185 {
2186 $$.flags = EM_NOMARK;
2187 $$.default_value = 0;
2188 }
Lev Walkinf15320b2004-06-03 03:38:44 +00002189 | Marker { $$ = $1; }
2190 ;
2191
2192Marker:
2193 TOK_OPTIONAL {
Lev Walkin70853052005-11-26 11:21:55 +00002194 $$.flags = EM_OPTIONAL | EM_INDIRECT;
Lev Walkin9c974182004-09-15 11:59:51 +00002195 $$.default_value = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +00002196 }
Lev Walkin9c974182004-09-15 11:59:51 +00002197 | TOK_DEFAULT Value {
2198 $$.flags = EM_DEFAULT;
2199 $$.default_value = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00002200 }
2201 ;
2202
Lev Walkinbe518fa2017-09-07 02:05:28 -07002203IdentifierList:
2204 IdentifierElement {
Lev Walkina9532f42006-09-17 04:52:50 +00002205 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002206 checkmem($$);
Lev Walkinbe518fa2017-09-07 02:05:28 -07002207 asn1p_expr_add($$, $1);
2208 }
2209 | IdentifierList ',' IdentifierElement {
2210 $$ = $1;
2211 asn1p_expr_add($$, $3);
2212 };
2213
2214IdentifierElement:
2215 Identifier {
2216 $$ = NEW_EXPR();
2217 checkmem($$);
2218 $$->expr_type = A1TC_UNIVERVAL;
2219 $$->meta_type = AMT_VALUE;
2220 $$->Identifier = $1;
2221 }
2222
2223NamedNumberList:
2224 NamedNumber {
2225 $$ = NEW_EXPR();
2226 checkmem($$);
2227 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00002228 }
Lev Walkinbe518fa2017-09-07 02:05:28 -07002229 | NamedNumberList ',' NamedNumber {
2230 $$ = $1;
2231 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002232 }
2233 ;
2234
Lev Walkinbe518fa2017-09-07 02:05:28 -07002235NamedNumber:
2236 Identifier '(' SignedNumber ')' {
2237 $$ = NEW_EXPR();
2238 checkmem($$);
2239 $$->expr_type = A1TC_UNIVERVAL;
2240 $$->meta_type = AMT_VALUE;
2241 $$->Identifier = $1;
2242 $$->value = $3;
2243 }
2244 | Identifier '(' DefinedValue ')' {
2245 $$ = NEW_EXPR();
2246 checkmem($$);
2247 $$->expr_type = A1TC_UNIVERVAL;
2248 $$->meta_type = AMT_VALUE;
2249 $$->Identifier = $1;
2250 $$->value = $3;
2251 };
2252
2253NamedBitList:
2254 NamedBit {
2255 $$ = NEW_EXPR();
2256 checkmem($$);
2257 asn1p_expr_add($$, $1);
2258 }
2259 | NamedBitList ',' NamedBit {
2260 $$ = $1;
2261 asn1p_expr_add($$, $3);
2262 }
2263 ;
2264
2265NamedBit:
2266 Identifier '(' TOK_number ')' {
2267 $$ = NEW_EXPR();
2268 checkmem($$);
2269 $$->expr_type = A1TC_UNIVERVAL;
2270 $$->meta_type = AMT_VALUE;
2271 $$->Identifier = $1;
2272 $$->value = asn1p_value_fromint($3);
2273 }
2274 | Identifier '(' DefinedValue ')' {
2275 $$ = NEW_EXPR();
2276 checkmem($$);
2277 $$->expr_type = A1TC_UNIVERVAL;
2278 $$->meta_type = AMT_VALUE;
2279 $$->Identifier = $1;
2280 $$->value = $3;
2281 };
2282
2283Enumerations:
2284 UniverationList {
2285 $$ = $1;
2286 asn1p_expr_t *first_memb = TQ_FIRST(&($$->members));
2287 if(first_memb) {
2288 if(first_memb->expr_type == A1TC_EXTENSIBLE) {
2289 return yyerror(
2290 "The ENUMERATION cannot start with extension (...).");
2291 }
2292 } else {
2293 return yyerror(
2294 "The ENUMERATION list cannot be empty.");
2295 }
2296 }
2297
Lev Walkinf15320b2004-06-03 03:38:44 +00002298UniverationList:
2299 UniverationElement {
Lev Walkina9532f42006-09-17 04:52:50 +00002300 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002301 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00002302 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00002303 }
2304 | UniverationList ',' UniverationElement {
2305 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00002306 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002307 }
2308 ;
2309
2310UniverationElement:
2311 Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +00002312 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002313 checkmem($$);
2314 $$->expr_type = A1TC_UNIVERVAL;
2315 $$->meta_type = AMT_VALUE;
2316 $$->Identifier = $1;
2317 }
2318 | Identifier '(' SignedNumber ')' {
Lev Walkina9532f42006-09-17 04:52:50 +00002319 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002320 checkmem($$);
2321 $$->expr_type = A1TC_UNIVERVAL;
2322 $$->meta_type = AMT_VALUE;
2323 $$->Identifier = $1;
2324 $$->value = $3;
2325 }
2326 | Identifier '(' DefinedValue ')' {
Lev Walkina9532f42006-09-17 04:52:50 +00002327 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002328 checkmem($$);
2329 $$->expr_type = A1TC_UNIVERVAL;
2330 $$->meta_type = AMT_VALUE;
2331 $$->Identifier = $1;
2332 $$->value = $3;
2333 }
2334 | SignedNumber {
Lev Walkina9532f42006-09-17 04:52:50 +00002335 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002336 checkmem($$);
2337 $$->expr_type = A1TC_UNIVERVAL;
2338 $$->meta_type = AMT_VALUE;
2339 $$->value = $1;
2340 }
2341 | TOK_ThreeDots {
Lev Walkina9532f42006-09-17 04:52:50 +00002342 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002343 checkmem($$);
2344 $$->Identifier = strdup("...");
2345 checkmem($$->Identifier);
2346 $$->expr_type = A1TC_EXTENSIBLE;
2347 $$->meta_type = AMT_VALUE;
2348 }
2349 ;
2350
2351SignedNumber:
2352 TOK_number {
2353 $$ = asn1p_value_fromint($1);
2354 checkmem($$);
2355 }
2356 | TOK_number_negative {
2357 $$ = asn1p_value_fromint($1);
2358 checkmem($$);
2359 }
2360 ;
2361
Lev Walkinadf863f2006-09-05 16:18:34 +00002362RealValue:
2363 SignedNumber
2364 | TOK_realnumber {
2365 $$ = asn1p_value_fromdouble($1);
2366 checkmem($$);
2367 }
2368 ;
2369
Lev Walkinf15320b2004-06-03 03:38:44 +00002370/*
2371 * SEQUENCE definition.
2372 * === EXAMPLE ===
2373 * Struct1 ::= SEQUENCE {
2374 * memb1 Struct2,
2375 * memb2 SEQUENCE OF {
2376 * memb2-1 Struct 3
2377 * }
2378 * }
2379 * === EOF ===
2380 */
2381
2382
2383
2384/*
2385 * SET definition.
2386 * === EXAMPLE ===
2387 * Person ::= SET {
2388 * name [0] PrintableString (SIZE(1..20)),
2389 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2390 * }
2391 * === EOF ===
2392 */
2393
2394optTag:
2395 { memset(&$$, 0, sizeof($$)); }
2396 | Tag { $$ = $1; }
2397 ;
2398
2399Tag:
Lev Walkinc603f102005-01-23 09:51:44 +00002400 TagTypeValue TagPlicit {
Lev Walkinf15320b2004-06-03 03:38:44 +00002401 $$ = $1;
Lev Walkinc603f102005-01-23 09:51:44 +00002402 $$.tag_mode = $2.tag_mode;
Lev Walkinf15320b2004-06-03 03:38:44 +00002403 }
Lev Walkinc603f102005-01-23 09:51:44 +00002404 ;
2405
2406TagTypeValue:
2407 '[' TagClass TOK_number ']' {
2408 $$ = $2;
2409 $$.tag_value = $3;
2410 };
2411
2412TagClass:
2413 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2414 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2415 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2416 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2417 ;
2418
2419TagPlicit:
2420 { $$.tag_mode = TM_DEFAULT; }
2421 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2422 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
Lev Walkinf15320b2004-06-03 03:38:44 +00002423 ;
2424
2425TypeRefName:
2426 TOK_typereference {
2427 checkmem($1);
2428 $$ = $1;
2429 }
Lev Walkinf59d0752004-08-18 04:59:12 +00002430 | TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002431 checkmem($1);
2432 $$ = $1;
2433 }
2434 ;
2435
Lev Walkinf59d0752004-08-18 04:59:12 +00002436
Lev Walkinf15320b2004-06-03 03:38:44 +00002437ObjectClassReference:
Lev Walkinf59d0752004-08-18 04:59:12 +00002438 TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002439 checkmem($1);
2440 $$ = $1;
2441 }
2442 ;
2443
Lev Walkin83cac2f2004-09-22 16:03:36 +00002444optIdentifier:
2445 { $$ = 0; }
2446 | Identifier {
2447 $$ = $1;
2448 }
Lev Walkin8f294e02005-06-06 08:28:58 +00002449 ;
Lev Walkin83cac2f2004-09-22 16:03:36 +00002450
Lev Walkinf15320b2004-06-03 03:38:44 +00002451Identifier:
2452 TOK_identifier {
2453 checkmem($1);
2454 $$ = $1;
2455 }
2456 ;
2457
Lev Walkind523ea42017-09-06 22:15:08 -07002458IdentifierAsReference:
2459 Identifier {
2460 $$ = asn1p_ref_new(yylineno, currentModule);
2461 asn1p_ref_add_component($$, $1, RLT_lowercase);
2462 };
2463
2464IdentifierAsValue:
2465 IdentifierAsReference {
2466 $$ = asn1p_value_fromref($1, 0);
2467 };
2468
Lev Walkinf15320b2004-06-03 03:38:44 +00002469%%
2470
2471
2472/*
2473 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2474 */
2475static asn1p_value_t *
2476_convert_bitstring2binary(char *str, int base) {
2477 asn1p_value_t *val;
2478 int slen;
2479 int memlen;
2480 int baselen;
2481 int bits;
2482 uint8_t *binary_vector;
2483 uint8_t *bv_ptr;
2484 uint8_t cur_val;
2485
2486 assert(str);
2487 assert(str[0] == '\'');
2488
2489 switch(base) {
2490 case 'B':
2491 baselen = 1;
2492 break;
2493 case 'H':
2494 baselen = 4;
2495 break;
2496 default:
2497 assert(base == 'B' || base == 'H');
2498 errno = EINVAL;
2499 return NULL;
2500 }
2501
2502 slen = strlen(str);
2503 assert(str[slen - 1] == base);
2504 assert(str[slen - 2] == '\'');
2505
2506 memlen = slen / (8 / baselen); /* Conservative estimate */
2507
2508 bv_ptr = binary_vector = malloc(memlen + 1);
2509 if(bv_ptr == NULL)
2510 /* ENOMEM */
2511 return NULL;
2512
2513 cur_val = 0;
2514 bits = 0;
2515 while(*(++str) != '\'') {
2516 switch(baselen) {
2517 case 1:
2518 switch(*str) {
2519 case '1':
2520 cur_val |= 1 << (7 - (bits % 8));
2521 case '0':
2522 break;
2523 default:
2524 assert(!"_y UNREACH1");
2525 case ' ': case '\r': case '\n':
2526 continue;
2527 }
2528 break;
2529 case 4:
2530 switch(*str) {
2531 case '0': case '1': case '2': case '3': case '4':
2532 case '5': case '6': case '7': case '8': case '9':
2533 cur_val |= (*str - '0') << (4 - (bits % 8));
2534 break;
2535 case 'A': case 'B': case 'C':
2536 case 'D': case 'E': case 'F':
2537 cur_val |= ((*str - 'A') + 10)
2538 << (4 - (bits % 8));
2539 break;
2540 default:
2541 assert(!"_y UNREACH2");
2542 case ' ': case '\r': case '\n':
2543 continue;
2544 }
2545 break;
2546 }
2547
2548 bits += baselen;
2549 if((bits % 8) == 0) {
2550 *bv_ptr++ = cur_val;
2551 cur_val = 0;
2552 }
2553 }
2554
2555 *bv_ptr = cur_val;
2556 assert((bv_ptr - binary_vector) <= memlen);
2557
2558 val = asn1p_value_frombits(binary_vector, bits, 0);
2559 if(val == NULL) {
2560 free(binary_vector);
2561 }
2562
2563 return val;
2564}
2565
Lev Walkin2e9bd5c2005-08-13 09:07:11 +00002566/*
2567 * For unnamed types (used in old X.208 compliant modules)
2568 * generate some sort of interim names, to not to force human being to fix
2569 * the specification's compliance to modern ASN.1 standards.
2570 */
2571static void
2572_fixup_anonymous_identifier(asn1p_expr_t *expr) {
2573 char *p;
2574 assert(expr->Identifier == 0);
2575
2576 /*
2577 * Try to figure out the type name
2578 * without going too much into details
2579 */
2580 expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type);
2581 if(expr->reference && expr->reference->comp_count > 0)
2582 expr->Identifier = expr->reference->components[0].name;
2583
2584 fprintf(stderr,
2585 "WARNING: Line %d: expected lower-case member identifier, "
2586 "found an unnamed %s.\n"
2587 "WARNING: Obsolete X.208 syntax detected, "
2588 "please give the member a name.\n",
2589 yylineno, expr->Identifier ? expr->Identifier : "type");
2590
2591 if(!expr->Identifier)
2592 expr->Identifier = "unnamed";
2593 expr->Identifier = strdup(expr->Identifier);
2594 assert(expr->Identifier);
2595 /* Make a lowercase identifier from the type name */
2596 for(p = expr->Identifier; *p; p++) {
2597 switch(*p) {
2598 case 'A' ... 'Z': *p += 32; break;
2599 case ' ': *p = '_'; break;
2600 case '-': *p = '_'; break;
2601 }
2602 }
2603 fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". "
2604 "Name clash may occur later.\n",
2605 expr->Identifier);
2606}
2607
Lev Walkinf15320b2004-06-03 03:38:44 +00002608int
2609yyerror(const char *msg) {
Lev Walkin9d542d22006-03-14 16:31:37 +00002610 extern char *asn1p_text;
Lev Walkinf15320b2004-06-03 03:38:44 +00002611 fprintf(stderr,
2612 "ASN.1 grammar parse error "
Lev Walkind523ea42017-09-06 22:15:08 -07002613 "near %s:%d (token \"%s\"): %s\n",
2614 ASN_FILENAME, yylineno, asn1p_text, msg);
Lev Walkinf15320b2004-06-03 03:38:44 +00002615 return -1;
2616}
2617