blob: 4d209c3528c50392145df739d9d1ad99db4a46e7 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001%{
2
3#include <stdlib.h>
4#include <stdio.h>
5#include <string.h>
Lev Walkin0c686452017-09-07 22:59:36 -07006#include <stdarg.h>
Lev Walkinf15320b2004-06-03 03:38:44 +00007#include <errno.h>
8#include <assert.h>
9
10#include "asn1parser.h"
11
12#define YYPARSE_PARAM param
Lev Walkin4354b442005-06-07 21:25:42 +000013#define YYPARSE_PARAM_TYPE void **
Lev Walkinf15320b2004-06-03 03:38:44 +000014#define YYERROR_VERBOSE
Lev Walkin0c686452017-09-07 22:59:36 -070015#define YYDEBUG 1
16#define YYFPRINTF prefixed_fprintf
17
18/*
19 * Prefix parser debug with "PARSER: " for easier human eye scanning.
20 */
21static int
22__attribute__((format(printf, 2, 3)))
23prefixed_fprintf(FILE *f, const char *fmt, ...) {
24 static int line_ended = 1;
25 va_list ap;
26 va_start(ap, fmt);
27 if(line_ended) {
28 fprintf(f, "PARSER: ");
29 line_ended = 0;
30 }
31 size_t len = strlen(fmt);
32 if(len && fmt[len-1] == '\n') {
33 line_ended = 1;
34 }
35 int ret = vfprintf(f, fmt, ap);
36 va_end(ap);
37 return ret;
38}
Lev Walkinf15320b2004-06-03 03:38:44 +000039
40int yylex(void);
Lev Walkin59165cf2017-09-11 06:24:45 -070041static int yyerror(const char *msg);
42
Lev Walkin8daab912005-06-07 21:32:16 +000043#ifdef YYBYACC
44int yyparse(void **param); /* byacc does not produce a prototype */
45#endif
Lev Walkinf15320b2004-06-03 03:38:44 +000046void asn1p_lexer_hack_push_opaque_state(void);
47void asn1p_lexer_hack_enable_with_syntax(void);
Lev Walkinf59d0752004-08-18 04:59:12 +000048void asn1p_lexer_hack_push_encoding_control(void);
Lev Walkinf15320b2004-06-03 03:38:44 +000049#define yylineno asn1p_lineno
50extern int asn1p_lineno;
Lev Walkind523ea42017-09-06 22:15:08 -070051const char *asn1p_parse_debug_filename;
52#define ASN_FILENAME asn1p_parse_debug_filename
Lev Walkinf15320b2004-06-03 03:38:44 +000053
Lev Walkin1ed22092005-08-12 10:06:17 +000054/*
Lev Walkinef625402005-09-05 05:17:57 +000055 * Process directives as <ASN1C:RepresentAsPointer>
Lev Walkin4696c742005-08-22 12:23:54 +000056 */
57extern int asn1p_as_pointer;
Lev Walkin4696c742005-08-22 12:23:54 +000058
59/*
Lev Walkin1ed22092005-08-12 10:06:17 +000060 * This temporary variable is used to solve the shortcomings of 1-lookahead
61 * parser.
62 */
63static struct AssignedIdentifier *saved_aid;
Lev Walkinf15320b2004-06-03 03:38:44 +000064
Lev Walkin2e9bd5c2005-08-13 09:07:11 +000065static asn1p_value_t *_convert_bitstring2binary(char *str, int base);
66static void _fixup_anonymous_identifier(asn1p_expr_t *expr);
Lev Walkinf15320b2004-06-03 03:38:44 +000067
Lev Walkina9532f42006-09-17 04:52:50 +000068static asn1p_module_t *currentModule;
69#define NEW_EXPR() (asn1p_expr_new(yylineno, currentModule))
70
Lev Walkin1ed22092005-08-12 10:06:17 +000071#define checkmem(ptr) do { \
72 if(!(ptr)) \
73 return yyerror("Memory failure"); \
Lev Walkinf15320b2004-06-03 03:38:44 +000074 } while(0)
75
Lev Walkin2c14a692005-08-12 10:08:45 +000076#define CONSTRAINT_INSERT(root, constr_type, arg1, arg2) do { \
Lev Walkin1ed22092005-08-12 10:06:17 +000077 if(arg1->type != constr_type) { \
78 int __ret; \
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +080079 root = asn1p_constraint_new(yylineno, currentModule); \
Lev Walkin1ed22092005-08-12 10:06:17 +000080 checkmem(root); \
81 root->type = constr_type; \
82 __ret = asn1p_constraint_insert(root, \
83 arg1); \
84 checkmem(__ret == 0); \
85 } else { \
86 root = arg1; \
87 } \
88 if(arg2) { \
89 int __ret \
90 = asn1p_constraint_insert(root, arg2); \
91 checkmem(__ret == 0); \
92 } \
Lev Walkinf15320b2004-06-03 03:38:44 +000093 } while(0)
94
Lev Walkin866bd7f2006-09-14 10:35:20 +000095#ifdef AL_IMPORT
96#error AL_IMPORT DEFINED ELSEWHERE!
97#endif
98#define AL_IMPORT(to,where,from,field) do { \
99 if(!(from)) break; \
100 while(TQ_FIRST(&((from)->where))) { \
101 TQ_ADD(&((to)->where), \
102 TQ_REMOVE(&((from)->where), field), \
103 field); \
104 } \
105 assert(TQ_FIRST(&((from)->where)) == 0); \
106 } while(0)
107
Lev Walkinf15320b2004-06-03 03:38:44 +0000108%}
109
110
111/*
112 * Token value definition.
113 * a_*: ASN-specific types.
114 * tv_*: Locally meaningful types.
115 */
116%union {
117 asn1p_t *a_grammar;
118 asn1p_module_flags_e a_module_flags;
119 asn1p_module_t *a_module;
120 asn1p_expr_type_e a_type; /* ASN.1 Type */
121 asn1p_expr_t *a_expr; /* Constructed collection */
122 asn1p_constraint_t *a_constr; /* Constraint */
123 enum asn1p_constraint_type_e a_ctype;/* Constraint type */
124 asn1p_xports_t *a_xports; /* IMports/EXports */
Lev Walkin1ed22092005-08-12 10:06:17 +0000125 struct AssignedIdentifier a_aid; /* Assigned Identifier */
Lev Walkinf15320b2004-06-03 03:38:44 +0000126 asn1p_oid_t *a_oid; /* Object Identifier */
127 asn1p_oid_arc_t a_oid_arc; /* Single OID's arc */
128 struct asn1p_type_tag_s a_tag; /* A tag */
129 asn1p_ref_t *a_ref; /* Reference to custom type */
130 asn1p_wsyntx_t *a_wsynt; /* WITH SYNTAX contents */
131 asn1p_wsyntx_chunk_t *a_wchunk; /* WITH SYNTAX chunk */
132 struct asn1p_ref_component_s a_refcomp; /* Component of a reference */
133 asn1p_value_t *a_value; /* Number, DefinedValue, etc */
134 struct asn1p_param_s a_parg; /* A parameter argument */
135 asn1p_paramlist_t *a_plist; /* A pargs list */
Lev Walkin9c974182004-09-15 11:59:51 +0000136 struct asn1p_expr_marker_s a_marker; /* OPTIONAL/DEFAULT */
Lev Walkinf15320b2004-06-03 03:38:44 +0000137 enum asn1p_constr_pres_e a_pres; /* PRESENT/ABSENT/OPTIONAL */
Lev Walkin144db9b2004-10-12 23:26:53 +0000138 asn1c_integer_t a_int;
Lev Walkinadf863f2006-09-05 16:18:34 +0000139 double a_dbl;
Lev Walkinf15320b2004-06-03 03:38:44 +0000140 char *tv_str;
141 struct {
142 char *buf;
143 int len;
144 } tv_opaque;
145 struct {
146 char *name;
147 struct asn1p_type_tag_s tag;
148 } tv_nametag;
149};
150
151/*
152 * Token types returned by scanner.
153 */
154%token TOK_PPEQ /* "::=", Pseudo Pascal EQuality */
Lev Walkin0e90aa02013-03-19 16:17:13 -0700155%token TOK_VBracketLeft TOK_VBracketRight /* "[[", "]]" */
Lev Walkin57074f12006-03-16 05:11:14 +0000156%token <tv_opaque> TOK_whitespace /* A span of whitespace */
Lev Walkinf15320b2004-06-03 03:38:44 +0000157%token <tv_opaque> TOK_opaque /* opaque data (driven from .y) */
158%token <tv_str> TOK_bstring
159%token <tv_opaque> TOK_cstring
160%token <tv_str> TOK_hstring
Lev Walkinbe518fa2017-09-07 02:05:28 -0700161%token <tv_str> TOK_identifier "identifier"
162%token <a_int> TOK_number "number"
163%token <a_int> TOK_number_negative "negative number"
Lev Walkinadf863f2006-09-05 16:18:34 +0000164%token <a_dbl> TOK_realnumber
Lev Walkind9574ae2005-03-24 16:22:35 +0000165%token <a_int> TOK_tuple
166%token <a_int> TOK_quadruple
Lev Walkinf15320b2004-06-03 03:38:44 +0000167%token <tv_str> TOK_typereference
Lev Walkinf59d0752004-08-18 04:59:12 +0000168%token <tv_str> TOK_capitalreference /* "CLASS1" */
Lev Walkinf15320b2004-06-03 03:38:44 +0000169%token <tv_str> TOK_typefieldreference /* "&Pork" */
170%token <tv_str> TOK_valuefieldreference /* "&id" */
Lev Walkin9d542d22006-03-14 16:31:37 +0000171%token <tv_str> TOK_Literal /* "BY" */
Lev Walkinf15320b2004-06-03 03:38:44 +0000172
173/*
Lev Walkinbe518fa2017-09-07 02:05:28 -0700174 * Tokens available with asn1p_lexer_hack_push_extended_values().
175 */
176%token TOK_ExtValue_BIT_STRING
177
178/*
Lev Walkinf15320b2004-06-03 03:38:44 +0000179 * Token types representing ASN.1 standard keywords.
180 */
181%token TOK_ABSENT
182%token TOK_ABSTRACT_SYNTAX
183%token TOK_ALL
184%token TOK_ANY
185%token TOK_APPLICATION
186%token TOK_AUTOMATIC
187%token TOK_BEGIN
188%token TOK_BIT
189%token TOK_BMPString
190%token TOK_BOOLEAN
191%token TOK_BY
192%token TOK_CHARACTER
193%token TOK_CHOICE
194%token TOK_CLASS
195%token TOK_COMPONENT
196%token TOK_COMPONENTS
197%token TOK_CONSTRAINED
198%token TOK_CONTAINING
199%token TOK_DEFAULT
200%token TOK_DEFINITIONS
201%token TOK_DEFINED
202%token TOK_EMBEDDED
203%token TOK_ENCODED
Lev Walkinf59d0752004-08-18 04:59:12 +0000204%token TOK_ENCODING_CONTROL
Lev Walkinf15320b2004-06-03 03:38:44 +0000205%token TOK_END
206%token TOK_ENUMERATED
207%token TOK_EXPLICIT
208%token TOK_EXPORTS
209%token TOK_EXTENSIBILITY
210%token TOK_EXTERNAL
211%token TOK_FALSE
212%token TOK_FROM
213%token TOK_GeneralizedTime
214%token TOK_GeneralString
215%token TOK_GraphicString
216%token TOK_IA5String
217%token TOK_IDENTIFIER
218%token TOK_IMPLICIT
219%token TOK_IMPLIED
220%token TOK_IMPORTS
221%token TOK_INCLUDES
222%token TOK_INSTANCE
Lev Walkinf59d0752004-08-18 04:59:12 +0000223%token TOK_INSTRUCTIONS
Lev Walkinf15320b2004-06-03 03:38:44 +0000224%token TOK_INTEGER
225%token TOK_ISO646String
226%token TOK_MAX
227%token TOK_MIN
228%token TOK_MINUS_INFINITY
229%token TOK_NULL
230%token TOK_NumericString
231%token TOK_OBJECT
232%token TOK_ObjectDescriptor
233%token TOK_OCTET
234%token TOK_OF
235%token TOK_OPTIONAL
236%token TOK_PATTERN
237%token TOK_PDV
238%token TOK_PLUS_INFINITY
239%token TOK_PRESENT
240%token TOK_PrintableString
241%token TOK_PRIVATE
242%token TOK_REAL
243%token TOK_RELATIVE_OID
244%token TOK_SEQUENCE
245%token TOK_SET
246%token TOK_SIZE
247%token TOK_STRING
248%token TOK_SYNTAX
249%token TOK_T61String
250%token TOK_TAGS
251%token TOK_TeletexString
252%token TOK_TRUE
253%token TOK_TYPE_IDENTIFIER
254%token TOK_UNIQUE
255%token TOK_UNIVERSAL
256%token TOK_UniversalString
257%token TOK_UTCTime
258%token TOK_UTF8String
259%token TOK_VideotexString
260%token TOK_VisibleString
261%token TOK_WITH
Lev Walkin752e9732017-08-04 02:06:22 -0700262%token UTF8_BOM "UTF-8 byte order mark"
Lev Walkinf15320b2004-06-03 03:38:44 +0000263
Lev Walkinf1727152006-09-21 01:50:37 +0000264%nonassoc TOK_EXCEPT
Lev Walkinf59d0752004-08-18 04:59:12 +0000265%left '^' TOK_INTERSECTION
266%left '|' TOK_UNION
Lev Walkinf15320b2004-06-03 03:38:44 +0000267
268/* Misc tags */
Lev Walkinbe518fa2017-09-07 02:05:28 -0700269%token TOK_TwoDots ".."
270%token TOK_ThreeDots "..."
Lev Walkinf15320b2004-06-03 03:38:44 +0000271
272
273/*
274 * Types defined herein.
275 */
276%type <a_grammar> ModuleList
Lev Walkin866bd7f2006-09-14 10:35:20 +0000277%type <a_module> ModuleDefinition
278%type <a_module> ModuleBody
279%type <a_module> AssignmentList
280%type <a_module> Assignment
281%type <a_module> optModuleBody /* Optional */
282%type <a_module_flags> optModuleDefinitionFlags
283%type <a_module_flags> ModuleDefinitionFlags /* Set of FL */
284%type <a_module_flags> ModuleDefinitionFlag /* Single FL */
285%type <a_module> optImports
286%type <a_module> optExports
Lev Walkinf15320b2004-06-03 03:38:44 +0000287%type <a_module> ImportsDefinition
Lev Walkin4a4543f2006-10-13 12:37:39 +0000288%type <a_module> optImportsBundleSet
Lev Walkinf15320b2004-06-03 03:38:44 +0000289%type <a_module> ImportsBundleSet
290%type <a_xports> ImportsBundle
291%type <a_xports> ImportsList
292%type <a_xports> ExportsDefinition
293%type <a_xports> ExportsBody
294%type <a_expr> ImportsElement
295%type <a_expr> ExportsElement
Lev Walkinf15320b2004-06-03 03:38:44 +0000296%type <a_expr> ExtensionAndException
Lev Walkina9532f42006-09-17 04:52:50 +0000297%type <a_expr> Type
Lev Walkin59165cf2017-09-11 06:24:45 -0700298%type <a_expr> TaggedType
299%type <a_expr> MaybeIndirectTaggedType
300%type <a_expr> UntaggedType
301%type <a_expr> DefinedUntaggedType
302%type <a_expr> ConcreteTypeDeclaration "concrete TypeDeclaration"
Lev Walkin070a52d2004-08-22 03:19:54 +0000303%type <a_expr> TypeDeclaration
Lev Walkin59165cf2017-09-11 06:24:45 -0700304%type <a_expr> MaybeIndirectTypeDeclaration
Lev Walkinf15320b2004-06-03 03:38:44 +0000305%type <a_ref> ComplexTypeReference
306%type <a_ref> ComplexTypeReferenceAmpList
307%type <a_refcomp> ComplexTypeReferenceElement
Lev Walkind370e9f2006-03-16 10:03:35 +0000308%type <a_refcomp> PrimitiveFieldReference
Lev Walkin9c2285a2006-03-09 08:49:26 +0000309%type <a_expr> FieldSpec
310%type <a_ref> FieldName
311%type <a_ref> DefinedObjectClass
Lev Walkinf15320b2004-06-03 03:38:44 +0000312%type <a_expr> ClassField
Lev Walkin9c2285a2006-03-09 08:49:26 +0000313%type <a_expr> ObjectClass
Lev Walkinf15320b2004-06-03 03:38:44 +0000314%type <a_expr> DataTypeReference /* Type1 ::= Type2 */
Lev Walkin0c0bca62006-03-21 04:48:15 +0000315%type <a_expr> DefinedType
Lev Walkin557f27d2006-03-21 07:46:48 +0000316%type <a_constr> ValueSet /* {a|b|c}*/
317%type <a_expr> ValueSetTypeAssignment /* Val INTEGER ::= {1|2} */
Lev Walkinc6ab03c2006-10-21 05:54:49 +0000318%type <a_expr> ValueAssignment /* val INTEGER ::= 1*/
Lev Walkin9c974182004-09-15 11:59:51 +0000319%type <a_value> Value
Lev Walkin0c0bca62006-03-21 04:48:15 +0000320%type <a_value> SimpleValue
Lev Walkinf15320b2004-06-03 03:38:44 +0000321%type <a_value> DefinedValue
322%type <a_value> SignedNumber
Lev Walkinadf863f2006-09-05 16:18:34 +0000323%type <a_value> RealValue
Lev Walkin1c8d5aa2006-10-27 05:37:39 +0000324%type <a_value> BitStringValue
Lev Walkin144db9b2004-10-12 23:26:53 +0000325%type <a_expr> optComponentTypeLists
Lev Walkin070a52d2004-08-22 03:19:54 +0000326%type <a_expr> ComponentTypeLists
327%type <a_expr> ComponentType
328%type <a_expr> AlternativeTypeLists
329%type <a_expr> AlternativeType
Lev Walkinf15320b2004-06-03 03:38:44 +0000330%type <a_expr> UniverationList
Lev Walkinbe518fa2017-09-07 02:05:28 -0700331%type <a_expr> Enumerations
332%type <a_expr> NamedBitList
333%type <a_expr> NamedBit
334%type <a_expr> NamedNumberList
335%type <a_expr> NamedNumber
336%type <a_expr> IdentifierList
337%type <a_expr> IdentifierElement
Lev Walkinf15320b2004-06-03 03:38:44 +0000338%type <a_expr> UniverationElement
339%type <tv_str> TypeRefName
Lev Walkinf15320b2004-06-03 03:38:44 +0000340%type <tv_str> Identifier
Lev Walkind523ea42017-09-06 22:15:08 -0700341%type <a_ref> IdentifierAsReference
342%type <a_value> IdentifierAsValue
Lev Walkin83cac2f2004-09-22 16:03:36 +0000343%type <tv_str> optIdentifier
Lev Walkinf15320b2004-06-03 03:38:44 +0000344%type <a_parg> ParameterArgumentName
345%type <a_plist> ParameterArgumentList
Lev Walkin5045dfa2006-03-21 09:41:28 +0000346%type <a_expr> ActualParameter
347%type <a_expr> ActualParameterList
Lev Walkin1ed22092005-08-12 10:06:17 +0000348%type <a_aid> AssignedIdentifier /* OID/DefinedValue */
Lev Walkinf15320b2004-06-03 03:38:44 +0000349%type <a_oid> ObjectIdentifier /* OID */
350%type <a_oid> optObjectIdentifier /* Optional OID */
351%type <a_oid> ObjectIdentifierBody
352%type <a_oid_arc> ObjectIdentifierElement
Lev Walkin59165cf2017-09-11 06:24:45 -0700353%type <a_expr> BuiltinType
Lev Walkinf15320b2004-06-03 03:38:44 +0000354%type <a_type> BasicTypeId
355%type <a_type> BasicTypeId_UniverationCompatible
356%type <a_type> BasicString
357%type <tv_opaque> Opaque
Lev Walkinbf979152017-09-07 23:36:11 -0700358%type <tv_opaque> OpaqueFirstToken
Lev Walkinc603f102005-01-23 09:51:44 +0000359%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
360%type <a_tag> TagClass TagTypeValue TagPlicit
Lev Walkinf15320b2004-06-03 03:38:44 +0000361%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
Lev Walkin0c686452017-09-07 22:59:36 -0700362%type <a_constr> optConstraint
363%type <a_constr> optManyConstraints /* Only for Type */
364%type <a_constr> ManyConstraints
365%type <a_constr> optSizeOrConstraint
Lev Walkina9532f42006-09-17 04:52:50 +0000366%type <a_constr> Constraint
Lev Walkin0c686452017-09-07 22:59:36 -0700367%type <a_constr> PermittedAlphabet
368%type <a_constr> SizeConstraint
Lev Walkind523ea42017-09-06 22:15:08 -0700369%type <a_constr> SingleTypeConstraint
370%type <a_constr> MultipleTypeConstraints
371%type <a_constr> NamedConstraint
372%type <a_constr> FullSpecification
373%type <a_constr> PartialSpecification
374%type <a_constr> TypeConstraints
375%type <a_constr> ConstraintSpec
Lev Walkina9532f42006-09-17 04:52:50 +0000376%type <a_constr> SubtypeConstraint
377%type <a_constr> GeneralConstraint
Lev Walkinf59d0752004-08-18 04:59:12 +0000378%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
Lev Walkin0c686452017-09-07 22:59:36 -0700379%type <a_constr> ElementSetSpec /* 1..2 */
Lev Walkinf1727152006-09-21 01:50:37 +0000380%type <a_constr> Unions
381%type <a_constr> Intersections
382%type <a_constr> IntersectionElements
Lev Walkin0c686452017-09-07 22:59:36 -0700383%type <a_constr> Elements
384%type <a_constr> SubtypeElements /* 1..2 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000385%type <a_constr> SimpleTableConstraint
Lev Walkina9532f42006-09-17 04:52:50 +0000386%type <a_constr> UserDefinedConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +0000387%type <a_constr> TableConstraint
Lev Walkina9532f42006-09-17 04:52:50 +0000388%type <a_constr> ContentsConstraint
Lev Walkin5c541f12006-10-18 18:40:14 +0000389%type <a_constr> PatternConstraint
Lev Walkin0c686452017-09-07 22:59:36 -0700390%type <a_constr> InnerTypeConstraints
391%type <a_constr> ValueRange
Lev Walkinf15320b2004-06-03 03:38:44 +0000392%type <a_constr> ComponentRelationConstraint
393%type <a_constr> AtNotationList
394%type <a_ref> AtNotationElement
Lev Walkinff7dd142005-03-20 12:58:00 +0000395%type <a_value> SingleValue
Lev Walkin0c686452017-09-07 22:59:36 -0700396%type <a_value> LowerEndValue
397%type <a_value> UpperEndValue
Lev Walkinff7dd142005-03-20 12:58:00 +0000398%type <a_value> ContainedSubtype
Lev Walkinf15320b2004-06-03 03:38:44 +0000399%type <a_ctype> ConstraintRangeSpec
Lev Walkin1e448d32005-03-24 14:26:38 +0000400%type <a_value> RestrictedCharacterStringValue
Lev Walkinf15320b2004-06-03 03:38:44 +0000401%type <a_wsynt> optWithSyntax
402%type <a_wsynt> WithSyntax
Lev Walkin9d542d22006-03-14 16:31:37 +0000403%type <a_wsynt> WithSyntaxList
404%type <a_wchunk> WithSyntaxToken
Lev Walkinf15320b2004-06-03 03:38:44 +0000405%type <a_marker> optMarker Marker
Lev Walkin0c686452017-09-07 22:59:36 -0700406%type <a_int> optUNIQUE
Lev Walkinf15320b2004-06-03 03:38:44 +0000407%type <a_pres> optPresenceConstraint PresenceConstraint
408%type <tv_str> ComponentIdList
Lev Walkinef625402005-09-05 05:17:57 +0000409%type <a_int> NSTD_IndirectMarker
Lev Walkinf15320b2004-06-03 03:38:44 +0000410
Lev Walkinf15320b2004-06-03 03:38:44 +0000411%%
412
413
414ParsedGrammar:
Lev Walkin752e9732017-08-04 02:06:22 -0700415 UTF8_BOM ModuleList {
416 *(void **)param = $2;
417 }
418 | ModuleList {
Lev Walkinf15320b2004-06-03 03:38:44 +0000419 *(void **)param = $1;
420 }
421 ;
422
423ModuleList:
Lev Walkin866bd7f2006-09-14 10:35:20 +0000424 ModuleDefinition {
Lev Walkinf15320b2004-06-03 03:38:44 +0000425 $$ = asn1p_new();
426 checkmem($$);
427 TQ_ADD(&($$->modules), $1, mod_next);
428 }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000429 | ModuleList ModuleDefinition {
Lev Walkinf15320b2004-06-03 03:38:44 +0000430 $$ = $1;
431 TQ_ADD(&($$->modules), $2, mod_next);
432 }
433 ;
434
435/*
436 * ASN module definition.
437 * === EXAMPLE ===
438 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
439 * BEGIN
440 * ...
441 * END
442 * === EOF ===
443 */
444
Lev Walkin866bd7f2006-09-14 10:35:20 +0000445ModuleDefinition:
Lev Walkina9532f42006-09-17 04:52:50 +0000446 TypeRefName { currentModule = asn1p_module_new(); }
447 optObjectIdentifier TOK_DEFINITIONS
Lev Walkin866bd7f2006-09-14 10:35:20 +0000448 optModuleDefinitionFlags
Lev Walkinf15320b2004-06-03 03:38:44 +0000449 TOK_PPEQ TOK_BEGIN
Lev Walkin866bd7f2006-09-14 10:35:20 +0000450 optModuleBody
Lev Walkinf15320b2004-06-03 03:38:44 +0000451 TOK_END {
452
Lev Walkina9532f42006-09-17 04:52:50 +0000453 $$ = currentModule;
454
455 if($8) {
456 asn1p_module_t tmp = *($$);
457 *($$) = *($8);
458 *($8) = tmp;
459 asn1p_module_free($8);
Lev Walkinf15320b2004-06-03 03:38:44 +0000460 } else {
461 /* There's a chance that a module is just plain empty */
Lev Walkinf15320b2004-06-03 03:38:44 +0000462 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000463
Lev Walkin1ed22092005-08-12 10:06:17 +0000464 $$->ModuleName = $1;
Lev Walkina9532f42006-09-17 04:52:50 +0000465 $$->module_oid = $3;
466 $$->module_flags = $5;
Lev Walkinf15320b2004-06-03 03:38:44 +0000467 }
468 ;
469
470/*
471 * Object Identifier Definition
472 * { iso member-body(2) 3 }
473 */
474optObjectIdentifier:
475 { $$ = 0; }
476 | ObjectIdentifier { $$ = $1; }
477 ;
478
479ObjectIdentifier:
480 '{' ObjectIdentifierBody '}' {
481 $$ = $2;
482 }
483 | '{' '}' {
484 $$ = 0;
485 }
486 ;
487
488ObjectIdentifierBody:
489 ObjectIdentifierElement {
490 $$ = asn1p_oid_new();
491 asn1p_oid_add_arc($$, &$1);
492 if($1.name)
493 free($1.name);
494 }
495 | ObjectIdentifierBody ObjectIdentifierElement {
496 $$ = $1;
497 asn1p_oid_add_arc($$, &$2);
498 if($2.name)
499 free($2.name);
500 }
501 ;
502
503ObjectIdentifierElement:
504 Identifier { /* iso */
505 $$.name = $1;
506 $$.number = -1;
507 }
508 | Identifier '(' TOK_number ')' { /* iso(1) */
509 $$.name = $1;
510 $$.number = $3;
511 }
512 | TOK_number { /* 1 */
513 $$.name = 0;
514 $$.number = $1;
515 }
516 ;
517
518/*
519 * Optional module flags.
520 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000521optModuleDefinitionFlags:
Lev Walkinf15320b2004-06-03 03:38:44 +0000522 { $$ = MSF_NOFLAGS; }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000523 | ModuleDefinitionFlags {
Lev Walkinf15320b2004-06-03 03:38:44 +0000524 $$ = $1;
525 }
526 ;
527
528/*
529 * Module flags.
530 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000531ModuleDefinitionFlags:
532 ModuleDefinitionFlag {
Lev Walkinf15320b2004-06-03 03:38:44 +0000533 $$ = $1;
534 }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000535 | ModuleDefinitionFlags ModuleDefinitionFlag {
Lev Walkinf15320b2004-06-03 03:38:44 +0000536 $$ = $1 | $2;
537 }
538 ;
539
540/*
541 * Single module flag.
542 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000543ModuleDefinitionFlag:
Lev Walkinf15320b2004-06-03 03:38:44 +0000544 TOK_EXPLICIT TOK_TAGS {
545 $$ = MSF_EXPLICIT_TAGS;
546 }
547 | TOK_IMPLICIT TOK_TAGS {
548 $$ = MSF_IMPLICIT_TAGS;
549 }
550 | TOK_AUTOMATIC TOK_TAGS {
551 $$ = MSF_AUTOMATIC_TAGS;
552 }
553 | TOK_EXTENSIBILITY TOK_IMPLIED {
554 $$ = MSF_EXTENSIBILITY_IMPLIED;
555 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000556 /* EncodingReferenceDefault */
557 | TOK_capitalreference TOK_INSTRUCTIONS {
558 /* X.680Amd1 specifies TAG and XER */
559 if(strcmp($1, "TAG") == 0) {
560 $$ = MSF_TAG_INSTRUCTIONS;
561 } else if(strcmp($1, "XER") == 0) {
562 $$ = MSF_XER_INSTRUCTIONS;
563 } else {
564 fprintf(stderr,
Lev Walkind523ea42017-09-06 22:15:08 -0700565 "WARNING: %s INSTRUCTIONS at %s:%d: "
Lev Walkinf59d0752004-08-18 04:59:12 +0000566 "Unrecognized encoding reference\n",
Lev Walkind523ea42017-09-06 22:15:08 -0700567 $1, ASN_FILENAME, yylineno);
Lev Walkinf59d0752004-08-18 04:59:12 +0000568 $$ = MSF_unk_INSTRUCTIONS;
569 }
570 free($1);
571 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000572 ;
573
574/*
575 * Optional module body.
576 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000577optModuleBody:
Lev Walkinf15320b2004-06-03 03:38:44 +0000578 { $$ = 0; }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000579 | ModuleBody {
Lev Walkinf15320b2004-06-03 03:38:44 +0000580 $$ = $1;
581 }
582 ;
583
584/*
585 * ASN.1 Module body.
586 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000587ModuleBody:
588 optExports optImports AssignmentList {
589 $$ = asn1p_module_new();
590 AL_IMPORT($$, exports, $1, xp_next);
591 AL_IMPORT($$, imports, $2, xp_next);
592 AL_IMPORT($$, members, $3, next);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800593
594 asn1p_module_free($1);
595 asn1p_module_free($2);
596 asn1p_module_free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000597 }
598 ;
599
Lev Walkin866bd7f2006-09-14 10:35:20 +0000600AssignmentList:
601 Assignment {
602 $$ = $1;
603 }
604 | AssignmentList Assignment {
605 if($1) {
606 $$ = $1;
607 } else {
608 $$ = $2;
609 break;
610 }
611 AL_IMPORT($$, members, $2, next);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800612 asn1p_module_free($2);
Lev Walkin866bd7f2006-09-14 10:35:20 +0000613 }
614 ;
615
616
Lev Walkinf15320b2004-06-03 03:38:44 +0000617/*
618 * One of the elements of ASN.1 module specification.
619 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000620Assignment:
621 DataTypeReference {
Lev Walkinf15320b2004-06-03 03:38:44 +0000622 $$ = asn1p_module_new();
623 checkmem($$);
624 assert($1->expr_type != A1TC_INVALID);
625 assert($1->meta_type != AMT_INVALID);
626 TQ_ADD(&($$->members), $1, next);
627 }
Lev Walkinc6ab03c2006-10-21 05:54:49 +0000628 | ValueAssignment {
Lev Walkinf15320b2004-06-03 03:38:44 +0000629 $$ = asn1p_module_new();
630 checkmem($$);
631 assert($1->expr_type != A1TC_INVALID);
632 assert($1->meta_type != AMT_INVALID);
633 TQ_ADD(&($$->members), $1, next);
634 }
635 /*
636 * Value set definition
637 * === EXAMPLE ===
638 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
639 * === EOF ===
Lev Walkine700b202017-08-06 23:21:32 -0700640 * Also ObjectClassSet.
Lev Walkinf15320b2004-06-03 03:38:44 +0000641 */
Lev Walkin557f27d2006-03-21 07:46:48 +0000642 | ValueSetTypeAssignment {
Lev Walkinf15320b2004-06-03 03:38:44 +0000643 $$ = asn1p_module_new();
644 checkmem($$);
645 assert($1->expr_type != A1TC_INVALID);
646 assert($1->meta_type != AMT_INVALID);
647 TQ_ADD(&($$->members), $1, next);
648 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000649 | TOK_ENCODING_CONTROL TOK_capitalreference
650 { asn1p_lexer_hack_push_encoding_control(); }
651 {
652 fprintf(stderr,
653 "WARNING: ENCODING-CONTROL %s "
Lev Walkind523ea42017-09-06 22:15:08 -0700654 "specification at %s:%d ignored\n",
655 $2, ASN_FILENAME, yylineno);
Lev Walkinf59d0752004-08-18 04:59:12 +0000656 free($2);
657 $$ = 0;
658 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000659
660 /*
661 * Erroneous attemps
662 */
663 | BasicString {
664 return yyerror(
Lev Walkin70853052005-11-26 11:21:55 +0000665 "Attempt to redefine a standard basic string type, "
666 "please comment out or remove this type redefinition.");
Lev Walkinf15320b2004-06-03 03:38:44 +0000667 }
668 ;
669
670/*
671 * === EXAMPLE ===
672 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
673 * === EOF ===
674 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000675optImports:
676 { $$ = 0; }
677 | ImportsDefinition;
678
Lev Walkinf15320b2004-06-03 03:38:44 +0000679ImportsDefinition:
Lev Walkin4a4543f2006-10-13 12:37:39 +0000680 TOK_IMPORTS optImportsBundleSet ';' {
Lev Walkin1ed22092005-08-12 10:06:17 +0000681 if(!saved_aid && 0)
682 return yyerror("Unterminated IMPORTS FROM, "
683 "expected semicolon ';'");
684 saved_aid = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +0000685 $$ = $2;
686 }
687 /*
688 * Some error cases.
689 */
690 | TOK_IMPORTS TOK_FROM /* ... */ {
691 return yyerror("Empty IMPORTS list");
692 }
693 ;
694
Lev Walkin4a4543f2006-10-13 12:37:39 +0000695optImportsBundleSet:
696 { $$ = asn1p_module_new(); }
697 | ImportsBundleSet;
698
Lev Walkinf15320b2004-06-03 03:38:44 +0000699ImportsBundleSet:
700 ImportsBundle {
701 $$ = asn1p_module_new();
702 checkmem($$);
703 TQ_ADD(&($$->imports), $1, xp_next);
704 }
705 | ImportsBundleSet ImportsBundle {
706 $$ = $1;
707 TQ_ADD(&($$->imports), $2, xp_next);
708 }
709 ;
710
Lev Walkin1ed22092005-08-12 10:06:17 +0000711AssignedIdentifier:
712 { memset(&$$, 0, sizeof($$)); }
713 | ObjectIdentifier { $$.oid = $1; };
714 /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
715
Lev Walkinf15320b2004-06-03 03:38:44 +0000716ImportsBundle:
Lev Walkin1ed22092005-08-12 10:06:17 +0000717 ImportsList TOK_FROM TypeRefName AssignedIdentifier {
Lev Walkinf15320b2004-06-03 03:38:44 +0000718 $$ = $1;
Lev Walkin1ed22092005-08-12 10:06:17 +0000719 $$->fromModuleName = $3;
720 $$->identifier = $4;
721 /* This stupid thing is used for look-back hack. */
722 saved_aid = $$->identifier.oid ? 0 : &($$->identifier);
Lev Walkinf15320b2004-06-03 03:38:44 +0000723 checkmem($$);
724 }
725 ;
726
727ImportsList:
728 ImportsElement {
729 $$ = asn1p_xports_new();
730 checkmem($$);
731 TQ_ADD(&($$->members), $1, next);
732 }
733 | ImportsList ',' ImportsElement {
734 $$ = $1;
735 TQ_ADD(&($$->members), $3, next);
736 }
737 ;
738
739ImportsElement:
740 TypeRefName {
Lev Walkina9532f42006-09-17 04:52:50 +0000741 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000742 checkmem($$);
743 $$->Identifier = $1;
744 $$->expr_type = A1TC_REFERENCE;
745 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000746 | TypeRefName '{' '}' { /* Completely equivalent to above */
Lev Walkina9532f42006-09-17 04:52:50 +0000747 $$ = NEW_EXPR();
Lev Walkin144db9b2004-10-12 23:26:53 +0000748 checkmem($$);
749 $$->Identifier = $1;
750 $$->expr_type = A1TC_REFERENCE;
751 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000752 | Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +0000753 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000754 checkmem($$);
755 $$->Identifier = $1;
756 $$->expr_type = A1TC_REFERENCE;
757 }
758 ;
759
Lev Walkin866bd7f2006-09-14 10:35:20 +0000760
761optExports:
762 { $$ = 0; }
763 | ExportsDefinition {
764 $$ = asn1p_module_new();
765 checkmem($$);
766 if($1) {
767 TQ_ADD(&($$->exports), $1, xp_next);
768 } else {
769 /* "EXPORTS ALL;" */
770 }
771 }
772 ;
773
Lev Walkinf15320b2004-06-03 03:38:44 +0000774ExportsDefinition:
775 TOK_EXPORTS ExportsBody ';' {
776 $$ = $2;
777 }
778 | TOK_EXPORTS TOK_ALL ';' {
779 $$ = 0;
780 }
781 | TOK_EXPORTS ';' {
782 /* Empty EXPORTS clause effectively prohibits export. */
783 $$ = asn1p_xports_new();
784 checkmem($$);
785 }
786 ;
787
788ExportsBody:
789 ExportsElement {
790 $$ = asn1p_xports_new();
791 assert($$);
792 TQ_ADD(&($$->members), $1, next);
793 }
794 | ExportsBody ',' ExportsElement {
795 $$ = $1;
796 TQ_ADD(&($$->members), $3, next);
797 }
798 ;
799
800ExportsElement:
801 TypeRefName {
Lev Walkina9532f42006-09-17 04:52:50 +0000802 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000803 checkmem($$);
804 $$->Identifier = $1;
805 $$->expr_type = A1TC_EXPORTVAR;
806 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000807 | TypeRefName '{' '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000808 $$ = NEW_EXPR();
Lev Walkin144db9b2004-10-12 23:26:53 +0000809 checkmem($$);
810 $$->Identifier = $1;
811 $$->expr_type = A1TC_EXPORTVAR;
812 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000813 | Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +0000814 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000815 checkmem($$);
816 $$->Identifier = $1;
817 $$->expr_type = A1TC_EXPORTVAR;
818 }
819 ;
820
821
Lev Walkin418298d2006-07-13 08:24:20 +0000822ValueSet: '{' ElementSetSpecs '}' { $$ = $2; };
Lev Walkin557f27d2006-03-21 07:46:48 +0000823
824ValueSetTypeAssignment:
Lev Walkin59165cf2017-09-11 06:24:45 -0700825 TypeRefName Type TOK_PPEQ ValueSet {
Lev Walkinf15320b2004-06-03 03:38:44 +0000826 $$ = $2;
827 assert($$->Identifier == 0);
828 $$->Identifier = $1;
829 $$->meta_type = AMT_VALUESET;
Lev Walkin557f27d2006-03-21 07:46:48 +0000830 $$->constraints = $4;
Lev Walkinf15320b2004-06-03 03:38:44 +0000831 }
832 ;
833
Lev Walkin0c0bca62006-03-21 04:48:15 +0000834DefinedType:
Lev Walkin0c0bca62006-03-21 04:48:15 +0000835 /*
836 * A DefinedType reference.
837 * "CLASS1.&id.&id2"
838 * or
839 * "Module.Type"
840 * or
841 * "Module.identifier"
842 * or
843 * "Type"
844 */
Lev Walkin59165cf2017-09-11 06:24:45 -0700845 ComplexTypeReference {
Lev Walkina9532f42006-09-17 04:52:50 +0000846 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000847 checkmem($$);
848 $$->reference = $1;
849 $$->expr_type = A1TC_REFERENCE;
850 $$->meta_type = AMT_TYPEREF;
851 }
Lev Walkin0c0bca62006-03-21 04:48:15 +0000852 /*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000853 * A parameterized assignment.
Lev Walkin0c0bca62006-03-21 04:48:15 +0000854 */
Lev Walkin5045dfa2006-03-21 09:41:28 +0000855 | ComplexTypeReference '{' ActualParameterList '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000856 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000857 checkmem($$);
Lev Walkin0c0bca62006-03-21 04:48:15 +0000858 $$->reference = $1;
859 $$->rhs_pspecs = $3;
860 $$->expr_type = A1TC_REFERENCE;
861 $$->meta_type = AMT_TYPEREF;
Lev Walkinf15320b2004-06-03 03:38:44 +0000862 }
863 ;
864
Lev Walkinf15320b2004-06-03 03:38:44 +0000865/*
866 * Data Type Reference.
867 * === EXAMPLE ===
868 * Type3 ::= CHOICE { a Type1, b Type 2 }
869 * === EOF ===
870 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000871DataTypeReference:
872 /*
873 * Optionally tagged type definition.
874 */
Lev Walkin9c2285a2006-03-09 08:49:26 +0000875 TypeRefName TOK_PPEQ Type {
Lev Walkinaf120f72004-09-14 02:36:39 +0000876 $$ = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000877 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000878 assert($$->expr_type);
879 assert($$->meta_type);
880 }
Lev Walkin9c2285a2006-03-09 08:49:26 +0000881 | TypeRefName TOK_PPEQ ObjectClass {
Lev Walkinf15320b2004-06-03 03:38:44 +0000882 $$ = $3;
883 $$->Identifier = $1;
884 assert($$->expr_type == A1TC_CLASSDEF);
Lev Walkin9c2285a2006-03-09 08:49:26 +0000885 assert($$->meta_type == AMT_OBJECTCLASS);
Lev Walkinf15320b2004-06-03 03:38:44 +0000886 }
887 /*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000888 * Parameterized <Type> declaration:
Lev Walkinf15320b2004-06-03 03:38:44 +0000889 * === EXAMPLE ===
890 * SIGNED { ToBeSigned } ::= SEQUENCE {
891 * toBeSigned ToBeSigned,
892 * algorithm AlgorithmIdentifier,
893 * signature BIT STRING
894 * }
895 * === EOF ===
896 */
Lev Walkin070a52d2004-08-22 03:19:54 +0000897 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000898 $$ = $6;
Lev Walkin5045dfa2006-03-21 09:41:28 +0000899 $$->Identifier = $1;
900 $$->lhs_params = $3;
901 }
902 /* Parameterized CLASS declaration */
903 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ ObjectClass {
904 $$ = $6;
Lev Walkinf15320b2004-06-03 03:38:44 +0000905 $$->Identifier = $1;
Lev Walkina00d6b32006-03-21 03:40:38 +0000906 $$->lhs_params = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000907 }
908 ;
909
910ParameterArgumentList:
911 ParameterArgumentName {
912 int ret;
913 $$ = asn1p_paramlist_new(yylineno);
914 checkmem($$);
915 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
916 checkmem(ret == 0);
Lev Walkina964e032017-03-26 03:48:06 -0700917 asn1p_ref_free($1.governor);
918 free($1.argument);
Lev Walkinf15320b2004-06-03 03:38:44 +0000919 }
920 | ParameterArgumentList ',' ParameterArgumentName {
921 int ret;
922 $$ = $1;
923 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
924 checkmem(ret == 0);
Lev Walkina964e032017-03-26 03:48:06 -0700925 asn1p_ref_free($3.governor);
926 free($3.argument);
Lev Walkinf15320b2004-06-03 03:38:44 +0000927 }
928 ;
929
930ParameterArgumentName:
931 TypeRefName {
932 $$.governor = NULL;
933 $$.argument = $1;
934 }
935 | TypeRefName ':' Identifier {
936 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800937 $$.governor = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +0000938 ret = asn1p_ref_add_component($$.governor, $1, 0);
939 checkmem(ret == 0);
940 $$.argument = $3;
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800941 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000942 }
Lev Walkinc8092cb2005-02-18 16:34:21 +0000943 | TypeRefName ':' TypeRefName {
944 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800945 $$.governor = asn1p_ref_new(yylineno, currentModule);
Lev Walkinc8092cb2005-02-18 16:34:21 +0000946 ret = asn1p_ref_add_component($$.governor, $1, 0);
947 checkmem(ret == 0);
948 $$.argument = $3;
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800949 free($1);
Lev Walkinc8092cb2005-02-18 16:34:21 +0000950 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000951 | BasicTypeId ':' Identifier {
952 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800953 $$.governor = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +0000954 ret = asn1p_ref_add_component($$.governor,
955 ASN_EXPR_TYPE2STR($1), 1);
956 checkmem(ret == 0);
957 $$.argument = $3;
958 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000959 | BasicTypeId ':' TypeRefName {
960 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800961 $$.governor = asn1p_ref_new(yylineno, currentModule);
Lev Walkin5045dfa2006-03-21 09:41:28 +0000962 ret = asn1p_ref_add_component($$.governor,
963 ASN_EXPR_TYPE2STR($1), 1);
964 checkmem(ret == 0);
965 $$.argument = $3;
966 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000967 ;
968
Lev Walkin5045dfa2006-03-21 09:41:28 +0000969ActualParameterList:
970 ActualParameter {
Lev Walkina9532f42006-09-17 04:52:50 +0000971 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000972 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000973 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000974 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000975 | ActualParameterList ',' ActualParameter {
Lev Walkinf15320b2004-06-03 03:38:44 +0000976 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000977 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000978 }
979 ;
980
Lev Walkin5045dfa2006-03-21 09:41:28 +0000981ActualParameter:
Lev Walkin59165cf2017-09-11 06:24:45 -0700982 UntaggedType /* act. Type */
Lev Walkin0c0bca62006-03-21 04:48:15 +0000983 | SimpleValue {
Lev Walkina9532f42006-09-17 04:52:50 +0000984 $$ = NEW_EXPR();
Lev Walkin0c0bca62006-03-21 04:48:15 +0000985 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800986 $$->Identifier = strdup("?");
Lev Walkin0c0bca62006-03-21 04:48:15 +0000987 $$->expr_type = A1TC_REFERENCE;
988 $$->meta_type = AMT_VALUE;
989 $$->value = $1;
990 }
Lev Walkin59165cf2017-09-11 06:24:45 -0700991 | DefinedValue {
Lev Walkina9532f42006-09-17 04:52:50 +0000992 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000993 checkmem($$);
Lev Walkin59165cf2017-09-11 06:24:45 -0700994 $$->Identifier = strdup("?");
Lev Walkinf15320b2004-06-03 03:38:44 +0000995 $$->expr_type = A1TC_REFERENCE;
996 $$->meta_type = AMT_VALUE;
Lev Walkin59165cf2017-09-11 06:24:45 -0700997 $$->value = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000998 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000999 | ValueSet {
Lev Walkina9532f42006-09-17 04:52:50 +00001000 $$ = NEW_EXPR();
Lev Walkin5045dfa2006-03-21 09:41:28 +00001001 $$->expr_type = A1TC_VALUESET;
1002 $$->meta_type = AMT_VALUESET;
1003 $$->constraints = $1;
1004 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001005 ;
1006
1007/*
Lev Walkin5045dfa2006-03-21 09:41:28 +00001008 | '{' ActualParameter '}' {
Lev Walkina9532f42006-09-17 04:52:50 +00001009 $$ = NEW_EXPR();
Lev Walkinc8092cb2005-02-18 16:34:21 +00001010 checkmem($$);
1011 asn1p_expr_add($$, $2);
1012 $$->expr_type = A1TC_PARAMETRIZED;
1013 $$->meta_type = AMT_TYPE;
1014 }
1015 ;
1016*/
1017
1018/*
Lev Walkinf15320b2004-06-03 03:38:44 +00001019 * A collection of constructed data type members.
1020 */
Lev Walkin144db9b2004-10-12 23:26:53 +00001021optComponentTypeLists:
Lev Walkina9532f42006-09-17 04:52:50 +00001022 { $$ = NEW_EXPR(); }
Lev Walkin144db9b2004-10-12 23:26:53 +00001023 | ComponentTypeLists { $$ = $1; };
1024
Lev Walkin070a52d2004-08-22 03:19:54 +00001025ComponentTypeLists:
1026 ComponentType {
Lev Walkina9532f42006-09-17 04:52:50 +00001027 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001028 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00001029 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001030 }
Lev Walkin070a52d2004-08-22 03:19:54 +00001031 | ComponentTypeLists ',' ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +00001032 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001033 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001034 }
Lev Walkin0e90aa02013-03-19 16:17:13 -07001035 | ComponentTypeLists ',' TOK_VBracketLeft ComponentTypeLists TOK_VBracketRight {
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001036 $$ = $1;
Lev Walkin0e90aa02013-03-19 16:17:13 -07001037 asn1p_expr_add_many($$, $4);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001038 asn1p_expr_free($4);
Lev Walkin0e90aa02013-03-19 16:17:13 -07001039 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001040 ;
1041
Lev Walkin070a52d2004-08-22 03:19:54 +00001042ComponentType:
Lev Walkin59165cf2017-09-11 06:24:45 -07001043 Identifier MaybeIndirectTaggedType optMarker {
Lev Walkin070a52d2004-08-22 03:19:54 +00001044 $$ = $2;
1045 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +00001046 $$->Identifier = $1;
Lev Walkinef625402005-09-05 05:17:57 +00001047 $3.flags |= $$->marker.flags;
Lev Walkin070a52d2004-08-22 03:19:54 +00001048 $$->marker = $3;
1049 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001050 | MaybeIndirectTaggedType optMarker {
Lev Walkinef625402005-09-05 05:17:57 +00001051 $$ = $1;
1052 $2.flags |= $$->marker.flags;
1053 $$->marker = $2;
1054 _fixup_anonymous_identifier($$);
1055 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001056 | TOK_COMPONENTS TOK_OF MaybeIndirectTaggedType {
Lev Walkina9532f42006-09-17 04:52:50 +00001057 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001058 checkmem($$);
1059 $$->meta_type = $3->meta_type;
1060 $$->expr_type = A1TC_COMPONENTS_OF;
Lev Walkin1004aa92004-09-08 00:28:11 +00001061 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +00001062 }
1063 | ExtensionAndException {
1064 $$ = $1;
1065 }
1066 ;
1067
1068AlternativeTypeLists:
1069 AlternativeType {
Lev Walkina9532f42006-09-17 04:52:50 +00001070 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001071 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00001072 asn1p_expr_add($$, $1);
Lev Walkin070a52d2004-08-22 03:19:54 +00001073 }
1074 | AlternativeTypeLists ',' AlternativeType {
1075 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001076 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +00001077 }
1078 ;
1079
1080AlternativeType:
Lev Walkin59165cf2017-09-11 06:24:45 -07001081 Identifier MaybeIndirectTaggedType {
Lev Walkin070a52d2004-08-22 03:19:54 +00001082 $$ = $2;
1083 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +00001084 $$->Identifier = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001085 }
1086 | ExtensionAndException {
1087 $$ = $1;
1088 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001089 | MaybeIndirectTaggedType {
Lev Walkin2e9bd5c2005-08-13 09:07:11 +00001090 $$ = $1;
1091 _fixup_anonymous_identifier($$);
1092 }
Lev Walkin070a52d2004-08-22 03:19:54 +00001093 ;
1094
Lev Walkin9c2285a2006-03-09 08:49:26 +00001095ObjectClass:
1096 TOK_CLASS '{' FieldSpec '}' optWithSyntax {
Lev Walkinf15320b2004-06-03 03:38:44 +00001097 $$ = $3;
1098 checkmem($$);
1099 $$->with_syntax = $5;
1100 assert($$->expr_type == A1TC_CLASSDEF);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001101 assert($$->meta_type == AMT_OBJECTCLASS);
Lev Walkinf15320b2004-06-03 03:38:44 +00001102 }
1103 ;
1104
Lev Walkin0c686452017-09-07 22:59:36 -07001105optUNIQUE:
Lev Walkinf15320b2004-06-03 03:38:44 +00001106 { $$ = 0; }
1107 | TOK_UNIQUE { $$ = 1; }
1108 ;
1109
Lev Walkin9c2285a2006-03-09 08:49:26 +00001110FieldSpec:
Lev Walkinf15320b2004-06-03 03:38:44 +00001111 ClassField {
Lev Walkina9532f42006-09-17 04:52:50 +00001112 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001113 checkmem($$);
1114 $$->expr_type = A1TC_CLASSDEF;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001115 $$->meta_type = AMT_OBJECTCLASS;
Lev Walkin1004aa92004-09-08 00:28:11 +00001116 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001117 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001118 | FieldSpec ',' ClassField {
Lev Walkinf15320b2004-06-03 03:38:44 +00001119 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001120 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001121 }
1122 ;
1123
Lev Walkin9c2285a2006-03-09 08:49:26 +00001124 /* X.681 */
Lev Walkinf15320b2004-06-03 03:38:44 +00001125ClassField:
Lev Walkin9c2285a2006-03-09 08:49:26 +00001126
1127 /* TypeFieldSpec ::= typefieldreference TypeOptionalitySpec? */
1128 TOK_typefieldreference optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001129 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001130 checkmem($$);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001131 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001132 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001133 $$->expr_type = A1TC_CLASSFIELD_TFS; /* TypeFieldSpec */
Lev Walkinf15320b2004-06-03 03:38:44 +00001134 $$->marker = $2;
1135 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001136
1137 /* FixedTypeValueFieldSpec ::= valuefieldreference Type UNIQUE ? ValueOptionalitySpec ? */
Lev Walkin0c686452017-09-07 22:59:36 -07001138 | TOK_valuefieldreference Type optUNIQUE optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001139 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001140 $$->Identifier = $1;
1141 $$->meta_type = AMT_OBJECTFIELD;
1142 $$->expr_type = A1TC_CLASSFIELD_FTVFS; /* FixedTypeValueFieldSpec */
Lev Walkinb7c45ca2004-11-24 17:43:29 +00001143 $$->unique = $3;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001144 $$->marker = $4;
1145 asn1p_expr_add($$, $2);
Lev Walkinf15320b2004-06-03 03:38:44 +00001146 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001147
1148 /* VariableTypeValueFieldSpec ::= valuefieldreference FieldName ValueOptionalitySpec ? */
1149 | TOK_valuefieldreference FieldName optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001150 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001151 $$->Identifier = $1;
1152 $$->meta_type = AMT_OBJECTFIELD;
1153 $$->expr_type = A1TC_CLASSFIELD_VTVFS;
1154 $$->reference = $2;
1155 $$->marker = $3;
1156 }
1157
Lev Walkin9c2285a2006-03-09 08:49:26 +00001158 /* ObjectFieldSpec ::= objectfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1159 | TOK_valuefieldreference DefinedObjectClass optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001160 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001161 checkmem($$);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001162 $$->Identifier = $1;
1163 $$->reference = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00001164 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001165 $$->expr_type = A1TC_CLASSFIELD_OFS;
1166 $$->marker = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +00001167 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001168
Lev Walkin54868752006-03-09 09:08:49 +00001169 /* VariableTypeValueSetFieldSpec ::= valuesetfieldreference FieldName ValueOptionalitySpec ? */
1170 | TOK_typefieldreference FieldName optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001171 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001172 $$->Identifier = $1;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001173 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin54868752006-03-09 09:08:49 +00001174 $$->expr_type = A1TC_CLASSFIELD_VTVSFS;
1175 $$->reference = $2;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001176 $$->marker = $3;
1177 }
1178
1179 /* FixedTypeValueSetFieldSpec ::= valuesetfieldreference Type ValueSetOptionalitySpec ? */
1180 | TOK_typefieldreference Type optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001181 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001182 checkmem($$);
1183 $$->Identifier = $1;
1184 $$->meta_type = AMT_OBJECTFIELD;
1185 $$->expr_type = A1TC_CLASSFIELD_FTVSFS;
1186 asn1p_expr_add($$, $2);
1187 $$->marker = $3;
1188 }
1189
Lev Walkin54868752006-03-09 09:08:49 +00001190 /* ObjectSetFieldSpec ::= objectsetfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1191 | TOK_typefieldreference DefinedObjectClass optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001192 $$ = NEW_EXPR();
Lev Walkin54868752006-03-09 09:08:49 +00001193 checkmem($$);
1194 $$->Identifier = $1;
1195 $$->reference = $2;
1196 $$->meta_type = AMT_OBJECTFIELD;
1197 $$->expr_type = A1TC_CLASSFIELD_OSFS;
1198 $$->marker = $3;
1199 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001200 ;
1201
1202optWithSyntax:
1203 { $$ = 0; }
1204 | WithSyntax {
1205 $$ = $1;
1206 }
1207 ;
1208
1209WithSyntax:
1210 TOK_WITH TOK_SYNTAX '{'
1211 { asn1p_lexer_hack_enable_with_syntax(); }
Lev Walkin9d542d22006-03-14 16:31:37 +00001212 WithSyntaxList
Lev Walkinf15320b2004-06-03 03:38:44 +00001213 '}' {
1214 $$ = $5;
1215 }
1216 ;
1217
Lev Walkin9d542d22006-03-14 16:31:37 +00001218WithSyntaxList:
1219 WithSyntaxToken {
Lev Walkinf15320b2004-06-03 03:38:44 +00001220 $$ = asn1p_wsyntx_new();
1221 TQ_ADD(&($$->chunks), $1, next);
1222 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001223 | WithSyntaxList WithSyntaxToken {
Lev Walkinf15320b2004-06-03 03:38:44 +00001224 $$ = $1;
1225 TQ_ADD(&($$->chunks), $2, next);
1226 }
1227 ;
1228
Lev Walkin9d542d22006-03-14 16:31:37 +00001229WithSyntaxToken:
Lev Walkin57074f12006-03-16 05:11:14 +00001230 TOK_whitespace {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001231 $$ = asn1p_wsyntx_chunk_fromstring($1.buf, 0);
Lev Walkin57074f12006-03-16 05:11:14 +00001232 $$->type = WC_WHITESPACE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001233 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001234 | TOK_Literal {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001235 $$ = asn1p_wsyntx_chunk_fromstring($1, 0);
Lev Walkin9d542d22006-03-14 16:31:37 +00001236 }
Lev Walkind370e9f2006-03-16 10:03:35 +00001237 | PrimitiveFieldReference {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001238 $$ = asn1p_wsyntx_chunk_fromstring($1.name, 0);
Lev Walkind370e9f2006-03-16 10:03:35 +00001239 $$->type = WC_FIELD;
Lev Walkinf15320b2004-06-03 03:38:44 +00001240 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001241 | '[' WithSyntaxList ']' {
1242 $$ = asn1p_wsyntx_chunk_fromsyntax($2);
1243 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001244 ;
1245
Lev Walkinf15320b2004-06-03 03:38:44 +00001246ExtensionAndException:
1247 TOK_ThreeDots {
Lev Walkina9532f42006-09-17 04:52:50 +00001248 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001249 checkmem($$);
1250 $$->Identifier = strdup("...");
1251 checkmem($$->Identifier);
1252 $$->expr_type = A1TC_EXTENSIBLE;
1253 $$->meta_type = AMT_TYPE;
1254 }
1255 | TOK_ThreeDots '!' DefinedValue {
Lev Walkina9532f42006-09-17 04:52:50 +00001256 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001257 checkmem($$);
1258 $$->Identifier = strdup("...");
1259 checkmem($$->Identifier);
1260 $$->value = $3;
1261 $$->expr_type = A1TC_EXTENSIBLE;
1262 $$->meta_type = AMT_TYPE;
1263 }
1264 | TOK_ThreeDots '!' SignedNumber {
Lev Walkina9532f42006-09-17 04:52:50 +00001265 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001266 checkmem($$);
1267 $$->Identifier = strdup("...");
1268 $$->value = $3;
1269 checkmem($$->Identifier);
1270 $$->expr_type = A1TC_EXTENSIBLE;
1271 $$->meta_type = AMT_TYPE;
1272 }
1273 ;
1274
Lev Walkin59165cf2017-09-11 06:24:45 -07001275Type: TaggedType;
1276
1277TaggedType:
1278 optTag UntaggedType {
1279 $$ = $2;
1280 $$->tag = $1;
1281 }
1282 ;
1283
1284DefinedUntaggedType:
1285 DefinedType optManyConstraints {
1286 $$ = $1;
1287 /*
1288 * Outer constraint for SEQUENCE OF and SET OF applies
1289 * to the inner type.
1290 */
1291 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1292 || $$->expr_type == ASN_CONSTR_SET_OF) {
1293 assert(!TQ_FIRST(&($$->members))->constraints);
1294 TQ_FIRST(&($$->members))->constraints = $2;
1295 } else {
1296 if($$->constraints) {
1297 assert(!$2);
1298 /* Check this : optManyConstraints is not used ?! */
1299 asn1p_constraint_free($2);
1300 } else {
1301 $$->constraints = $2;
1302 }
1303 }
1304 }
1305 ;
1306
1307UntaggedType:
1308 TypeDeclaration optManyConstraints {
1309 $$ = $1;
1310 /*
1311 * Outer constraint for SEQUENCE OF and SET OF applies
1312 * to the inner type.
1313 */
1314 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1315 || $$->expr_type == ASN_CONSTR_SET_OF) {
1316 assert(!TQ_FIRST(&($$->members))->constraints);
1317 TQ_FIRST(&($$->members))->constraints = $2;
1318 } else {
1319 if($$->constraints) {
1320 assert(!$2);
1321 /* Check this : optManyConstraints is not used ?! */
1322 asn1p_constraint_free($2);
1323 } else {
1324 $$->constraints = $2;
1325 }
1326 }
1327 }
1328 ;
1329
1330MaybeIndirectTaggedType:
1331 optTag MaybeIndirectTypeDeclaration optManyConstraints {
Lev Walkinaf120f72004-09-14 02:36:39 +00001332 $$ = $2;
1333 $$->tag = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001334 /*
1335 * Outer constraint for SEQUENCE OF and SET OF applies
1336 * to the inner type.
1337 */
1338 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1339 || $$->expr_type == ASN_CONSTR_SET_OF) {
1340 assert(!TQ_FIRST(&($$->members))->constraints);
Lev Walkinaf120f72004-09-14 02:36:39 +00001341 TQ_FIRST(&($$->members))->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001342 } else {
1343 if($$->constraints) {
1344 assert(!$2);
Lev Walkin0c686452017-09-07 22:59:36 -07001345 /* Check this : optManyConstraints is not used ?! */
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001346 asn1p_constraint_free($3);
Lev Walkin070a52d2004-08-22 03:19:54 +00001347 } else {
Lev Walkinaf120f72004-09-14 02:36:39 +00001348 $$->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001349 }
1350 }
Lev Walkinef625402005-09-05 05:17:57 +00001351 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001352 ;
Lev Walkinef625402005-09-05 05:17:57 +00001353
1354NSTD_IndirectMarker:
1355 {
1356 $$ = asn1p_as_pointer ? EM_INDIRECT : 0;
1357 asn1p_as_pointer = 0;
Lev Walkin070a52d2004-08-22 03:19:54 +00001358 }
1359 ;
1360
Lev Walkin59165cf2017-09-11 06:24:45 -07001361MaybeIndirectTypeDeclaration:
1362 NSTD_IndirectMarker TypeDeclaration {
1363 $$ = $2;
Lev Walkinef625402005-09-05 05:17:57 +00001364 $$->marker.flags |= $1;
1365
1366 if(($$->marker.flags & EM_INDIRECT)
1367 && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
1368 fprintf(stderr,
1369 "INFO: Directive <ASN1C:RepresentAsPointer> "
Lev Walkind523ea42017-09-06 22:15:08 -07001370 "applied to %s at %s:%d\n",
Lev Walkinef625402005-09-05 05:17:57 +00001371 ASN_EXPR_TYPE2STR($$->expr_type)
1372 ? ASN_EXPR_TYPE2STR($$->expr_type)
1373 : "member",
Lev Walkind523ea42017-09-06 22:15:08 -07001374 ASN_FILENAME, $$->_lineno
Lev Walkinef625402005-09-05 05:17:57 +00001375 );
1376 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001377 }
1378 ;
Lev Walkin4696c742005-08-22 12:23:54 +00001379
Lev Walkin59165cf2017-09-11 06:24:45 -07001380TypeDeclaration:
1381 ConcreteTypeDeclaration
1382 | DefinedType;
1383
1384ConcreteTypeDeclaration:
1385 BuiltinType
Lev Walkinef625402005-09-05 05:17:57 +00001386 | TOK_CHOICE '{' AlternativeTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001387 $$ = $3;
1388 assert($$->expr_type == A1TC_INVALID);
1389 $$->expr_type = ASN_CONSTR_CHOICE;
1390 $$->meta_type = AMT_TYPE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001391 }
Lev Walkinef625402005-09-05 05:17:57 +00001392 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001393 $$ = $3;
1394 assert($$->expr_type == A1TC_INVALID);
1395 $$->expr_type = ASN_CONSTR_SEQUENCE;
1396 $$->meta_type = AMT_TYPE;
1397 }
Lev Walkinef625402005-09-05 05:17:57 +00001398 | TOK_SET '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001399 $$ = $3;
1400 assert($$->expr_type == A1TC_INVALID);
1401 $$->expr_type = ASN_CONSTR_SET;
1402 $$->meta_type = AMT_TYPE;
1403 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001404 | TOK_SEQUENCE optSizeOrConstraint TOK_OF optIdentifier optTag MaybeIndirectTypeDeclaration {
Lev Walkina9532f42006-09-17 04:52:50 +00001405 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001406 checkmem($$);
1407 $$->constraints = $2;
1408 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1409 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001410 $6->Identifier = $4;
1411 $6->tag = $5;
1412 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001413 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001414 | TOK_SET optSizeOrConstraint TOK_OF optIdentifier optTag MaybeIndirectTypeDeclaration {
Lev Walkina9532f42006-09-17 04:52:50 +00001415 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001416 checkmem($$);
1417 $$->constraints = $2;
1418 $$->expr_type = ASN_CONSTR_SET_OF;
1419 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001420 $6->Identifier = $4;
1421 $6->tag = $5;
1422 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001423 }
1424 | TOK_ANY {
Lev Walkina9532f42006-09-17 04:52:50 +00001425 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001426 checkmem($$);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001427 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001428 $$->meta_type = AMT_TYPE;
1429 }
1430 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1431 int ret;
Lev Walkina9532f42006-09-17 04:52:50 +00001432 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001433 checkmem($$);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001434 $$->reference = asn1p_ref_new(yylineno, currentModule);
Lev Walkin070a52d2004-08-22 03:19:54 +00001435 ret = asn1p_ref_add_component($$->reference,
1436 $4, RLT_lowercase);
1437 checkmem(ret == 0);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001438 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001439 $$->meta_type = AMT_TYPE;
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001440 free($4);
Lev Walkin070a52d2004-08-22 03:19:54 +00001441 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001442 | TOK_INSTANCE TOK_OF ComplexTypeReference {
Lev Walkina9532f42006-09-17 04:52:50 +00001443 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001444 checkmem($$);
1445 $$->reference = $3;
1446 $$->expr_type = A1TC_INSTANCE;
1447 $$->meta_type = AMT_TYPE;
1448 }
1449 ;
1450
1451/*
1452 * A type name consisting of several components.
1453 * === EXAMPLE ===
1454 * === EOF ===
1455 */
1456ComplexTypeReference:
1457 TOK_typereference {
1458 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001459 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001460 checkmem($$);
1461 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1462 checkmem(ret == 0);
1463 free($1);
1464 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001465 | TOK_capitalreference {
1466 int ret;
1467 $$ = asn1p_ref_new(yylineno, currentModule);
1468 checkmem($$);
1469 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1470 free($1);
1471 checkmem(ret == 0);
1472 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001473 | TOK_typereference '.' TypeRefName {
1474 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001475 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001476 checkmem($$);
1477 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1478 checkmem(ret == 0);
1479 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1480 checkmem(ret == 0);
1481 free($1);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001482 free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001483 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001484 | TOK_capitalreference '.' TypeRefName {
Lev Walkin9c974182004-09-15 11:59:51 +00001485 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001486 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkin9c974182004-09-15 11:59:51 +00001487 checkmem($$);
1488 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1489 checkmem(ret == 0);
1490 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1491 checkmem(ret == 0);
1492 free($1);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001493 free($3);
Lev Walkin9c974182004-09-15 11:59:51 +00001494 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001495 | TOK_capitalreference '.' ComplexTypeReferenceAmpList {
Lev Walkinf15320b2004-06-03 03:38:44 +00001496 int ret;
1497 $$ = $3;
1498 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1499 free($1);
1500 checkmem(ret == 0);
1501 /*
1502 * Move the last element infront.
1503 */
1504 {
1505 struct asn1p_ref_component_s tmp_comp;
1506 tmp_comp = $$->components[$$->comp_count-1];
1507 memmove(&$$->components[1],
1508 &$$->components[0],
1509 sizeof($$->components[0])
1510 * ($$->comp_count - 1));
1511 $$->components[0] = tmp_comp;
1512 }
1513 }
1514 ;
1515
1516ComplexTypeReferenceAmpList:
1517 ComplexTypeReferenceElement {
1518 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001519 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001520 checkmem($$);
1521 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1522 free($1.name);
1523 checkmem(ret == 0);
1524 }
1525 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1526 int ret;
1527 $$ = $1;
1528 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1529 free($3.name);
1530 checkmem(ret == 0);
1531 }
1532 ;
1533
Lev Walkind370e9f2006-03-16 10:03:35 +00001534ComplexTypeReferenceElement: PrimitiveFieldReference;
Lev Walkinf15320b2004-06-03 03:38:44 +00001535
Lev Walkind370e9f2006-03-16 10:03:35 +00001536PrimitiveFieldReference:
Lev Walkinf15320b2004-06-03 03:38:44 +00001537 /* "&Type1" */
1538 TOK_typefieldreference {
1539 $$.lex_type = RLT_AmpUppercase;
1540 $$.name = $1;
1541 }
1542 /* "&id" */
1543 | TOK_valuefieldreference {
1544 $$.lex_type = RLT_Amplowercase;
1545 $$.name = $1;
1546 }
1547 ;
1548
1549
Lev Walkin9c2285a2006-03-09 08:49:26 +00001550FieldName:
1551 /* "&Type1" */
1552 TOK_typefieldreference {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001553 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001554 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001555 free($1);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001556 }
1557 | FieldName '.' TOK_typefieldreference {
1558 $$ = $$;
1559 asn1p_ref_add_component($$, $3, RLT_AmpUppercase);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001560 free($3);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001561 }
1562 | FieldName '.' TOK_valuefieldreference {
1563 $$ = $$;
1564 asn1p_ref_add_component($$, $3, RLT_Amplowercase);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001565 free($3);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001566 }
1567 ;
1568
1569DefinedObjectClass:
1570 TOK_capitalreference {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001571 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001572 asn1p_ref_add_component($$, $1, RLT_CAPITALS);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001573 free($1);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001574 }
Lev Walkin54868752006-03-09 09:08:49 +00001575/*
Lev Walkin9c2285a2006-03-09 08:49:26 +00001576 | TypeRefName '.' TOK_capitalreference {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001577 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001578 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1579 asn1p_ref_add_component($$, $3, RLT_CAPITALS);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001580 free($1);
1581 free($3);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001582 }
Lev Walkin54868752006-03-09 09:08:49 +00001583*/
Lev Walkin9c2285a2006-03-09 08:49:26 +00001584 ;
1585
1586
Lev Walkinf15320b2004-06-03 03:38:44 +00001587/*
1588 * === EXAMPLE ===
1589 * value INTEGER ::= 1
1590 * === EOF ===
1591 */
Lev Walkinc6ab03c2006-10-21 05:54:49 +00001592ValueAssignment:
1593 Identifier Type TOK_PPEQ Value {
Lev Walkinf15320b2004-06-03 03:38:44 +00001594 $$ = $2;
1595 assert($$->Identifier == NULL);
1596 $$->Identifier = $1;
1597 $$->meta_type = AMT_VALUE;
1598 $$->value = $4;
1599 }
1600 ;
1601
Lev Walkin9c974182004-09-15 11:59:51 +00001602Value:
Lev Walkin0c0bca62006-03-21 04:48:15 +00001603 SimpleValue
1604 | DefinedValue
Lev Walkinbf979152017-09-07 23:36:11 -07001605 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque {
Lev Walkinf15320b2004-06-03 03:38:44 +00001606 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1607 checkmem($$);
1608 $$->type = ATV_UNPARSED;
1609 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001610 ;
1611
1612SimpleValue:
1613 TOK_NULL {
Lev Walkin9c974182004-09-15 11:59:51 +00001614 $$ = asn1p_value_fromint(0);
1615 checkmem($$);
1616 $$->type = ATV_NULL;
1617 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001618 | TOK_FALSE {
Lev Walkin9c974182004-09-15 11:59:51 +00001619 $$ = asn1p_value_fromint(0);
1620 checkmem($$);
1621 $$->type = ATV_FALSE;
1622 }
1623 | TOK_TRUE {
Lev Walkin59165cf2017-09-11 06:24:45 -07001624 $$ = asn1p_value_fromint(1);
Lev Walkin9c974182004-09-15 11:59:51 +00001625 checkmem($$);
1626 $$->type = ATV_TRUE;
1627 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001628 | SignedNumber
1629 | RealValue
1630 | RestrictedCharacterStringValue
1631 | BitStringValue
Lev Walkinf15320b2004-06-03 03:38:44 +00001632 ;
1633
1634DefinedValue:
Lev Walkin59165cf2017-09-11 06:24:45 -07001635 IdentifierAsValue
Lev Walkinf15320b2004-06-03 03:38:44 +00001636 | TypeRefName '.' Identifier {
1637 asn1p_ref_t *ref;
1638 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001639 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001640 checkmem(ref);
1641 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1642 checkmem(ret == 0);
1643 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1644 checkmem(ret == 0);
1645 $$ = asn1p_value_fromref(ref, 0);
1646 checkmem($$);
1647 free($1);
1648 free($3);
1649 }
1650 ;
1651
Lev Walkin1e448d32005-03-24 14:26:38 +00001652
1653RestrictedCharacterStringValue:
1654 TOK_cstring {
1655 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1656 checkmem($$);
1657 }
Lev Walkind9574ae2005-03-24 16:22:35 +00001658 | TOK_tuple {
1659 $$ = asn1p_value_fromint($1);
1660 checkmem($$);
1661 $$->type = ATV_TUPLE;
1662 }
1663 | TOK_quadruple {
1664 $$ = asn1p_value_fromint($1);
1665 checkmem($$);
1666 $$->type = ATV_QUADRUPLE;
1667 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001668 ;
1669
Lev Walkinf15320b2004-06-03 03:38:44 +00001670Opaque:
Lev Walkinbf979152017-09-07 23:36:11 -07001671 OpaqueFirstToken {
Lev Walkin1893ddf2005-03-20 14:28:32 +00001672 $$.len = $1.len + 1;
Lev Walkinbf979152017-09-07 23:36:11 -07001673 $$.buf = malloc(1 + $$.len + 1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001674 checkmem($$.buf);
1675 $$.buf[0] = '{';
Lev Walkin1893ddf2005-03-20 14:28:32 +00001676 memcpy($$.buf + 1, $1.buf, $1.len);
Lev Walkinf15320b2004-06-03 03:38:44 +00001677 $$.buf[$$.len] = '\0';
1678 free($1.buf);
Lev Walkinbf979152017-09-07 23:36:11 -07001679 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001680 | Opaque TOK_opaque {
1681 int newsize = $1.len + $2.len;
1682 char *p = malloc(newsize + 1);
1683 checkmem(p);
1684 memcpy(p , $1.buf, $1.len);
1685 memcpy(p + $1.len, $2.buf, $2.len);
1686 p[newsize] = '\0';
1687 free($1.buf);
1688 free($2.buf);
1689 $$.buf = p;
1690 $$.len = newsize;
1691 }
1692 ;
1693
Lev Walkinbf979152017-09-07 23:36:11 -07001694OpaqueFirstToken:
1695 TOK_opaque
1696 | Identifier {
1697 $$.len = strlen($1);
1698 $$.buf = $1;
1699 };
1700
Lev Walkinf15320b2004-06-03 03:38:44 +00001701BasicTypeId:
1702 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1703 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1704 | TOK_REAL { $$ = ASN_BASIC_REAL; }
Lev Walkinf15320b2004-06-03 03:38:44 +00001705 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1706 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1707 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1708 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1709 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1710 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1711 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1712 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
Lev Walkinbe518fa2017-09-07 02:05:28 -07001713 | BasicString
1714 | BasicTypeId_UniverationCompatible
Lev Walkinf15320b2004-06-03 03:38:44 +00001715 ;
1716
1717/*
1718 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1719 */
1720BasicTypeId_UniverationCompatible:
1721 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
Lev Walkina25584b2017-10-01 13:43:17 -07001722 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
Lev Walkinf15320b2004-06-03 03:38:44 +00001723 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1724 ;
1725
Lev Walkin59165cf2017-09-11 06:24:45 -07001726BuiltinType:
Lev Walkinf15320b2004-06-03 03:38:44 +00001727 BasicTypeId {
Lev Walkina9532f42006-09-17 04:52:50 +00001728 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001729 checkmem($$);
1730 $$->expr_type = $1;
1731 $$->meta_type = AMT_TYPE;
1732 }
Lev Walkinbe518fa2017-09-07 02:05:28 -07001733 | TOK_INTEGER '{' NamedNumberList '}' {
1734 $$ = $3;
1735 $$->expr_type = ASN_BASIC_INTEGER;
1736 $$->meta_type = AMT_TYPE;
1737 }
1738 | TOK_ENUMERATED '{' Enumerations '}' {
1739 $$ = $3;
1740 $$->expr_type = ASN_BASIC_ENUMERATED;
1741 $$->meta_type = AMT_TYPE;
1742 }
1743 | TOK_BIT TOK_STRING '{' NamedBitList '}' {
1744 $$ = $4;
1745 $$->expr_type = ASN_BASIC_BIT_STRING;
1746 $$->meta_type = AMT_TYPE;
1747 }
1748 | TOK_ExtValue_BIT_STRING '{' IdentifierList '}' {
1749 $$ = $3;
1750 $$->expr_type = ASN_BASIC_BIT_STRING;
1751 $$->meta_type = AMT_TYPE;
1752 }
1753 | TOK_ExtValue_BIT_STRING '{' '}' {
1754 $$ = NEW_EXPR();
1755 checkmem($$);
1756 $$->expr_type = ASN_BASIC_BIT_STRING;
1757 $$->meta_type = AMT_TYPE;
1758 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001759 ;
1760
1761BasicString:
1762 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1763 | TOK_GeneralString {
1764 $$ = ASN_STRING_GeneralString;
Lev Walkin9c974182004-09-15 11:59:51 +00001765 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001766 }
1767 | TOK_GraphicString {
1768 $$ = ASN_STRING_GraphicString;
Lev Walkin9c974182004-09-15 11:59:51 +00001769 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001770 }
1771 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1772 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1773 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1774 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1775 | TOK_T61String {
1776 $$ = ASN_STRING_T61String;
Lev Walkin9c974182004-09-15 11:59:51 +00001777 fprintf(stderr, "WARNING: T61String is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001778 }
1779 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1780 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1781 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1782 | TOK_VideotexString {
1783 $$ = ASN_STRING_VideotexString;
Lev Walkin9c974182004-09-15 11:59:51 +00001784 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001785 }
1786 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1787 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1788 ;
1789
Lev Walkind2ea1de2004-08-20 13:25:29 +00001790
Lev Walkinf15320b2004-06-03 03:38:44 +00001791/*
1792 * Data type constraints.
1793 */
Lev Walkinf1727152006-09-21 01:50:37 +00001794UnionMark: '|' | TOK_UNION;
1795IntersectionMark: '^' | TOK_INTERSECTION;
Lev Walkinf15320b2004-06-03 03:38:44 +00001796
Lev Walkind523ea42017-09-06 22:15:08 -07001797/* empty | Constraint */
Lev Walkin0c686452017-09-07 22:59:36 -07001798optConstraint:
Lev Walkinf59d0752004-08-18 04:59:12 +00001799 { $$ = 0; }
Lev Walkind523ea42017-09-06 22:15:08 -07001800 | Constraint;
Lev Walkind2ea1de2004-08-20 13:25:29 +00001801
Lev Walkin0c686452017-09-07 22:59:36 -07001802/* empty | Constraint... */
1803optManyConstraints:
1804 { $$ = 0; }
1805 | ManyConstraints;
1806
Lev Walkind523ea42017-09-06 22:15:08 -07001807/* empty | Constraint | SIZE(...) */
Lev Walkin0c686452017-09-07 22:59:36 -07001808optSizeOrConstraint:
Lev Walkind523ea42017-09-06 22:15:08 -07001809 { $$ = 0; }
1810 | Constraint
Lev Walkin0c686452017-09-07 22:59:36 -07001811 | SizeConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +00001812 ;
1813
Lev Walkind523ea42017-09-06 22:15:08 -07001814Constraint:
Lev Walkin0c686452017-09-07 22:59:36 -07001815 '(' ConstraintSpec ')' {
1816 CONSTRAINT_INSERT($$, ACT_CA_SET, $2, 0);
Lev Walkind523ea42017-09-06 22:15:08 -07001817 }
1818 ;
1819
Lev Walkin0c686452017-09-07 22:59:36 -07001820ManyConstraints:
1821 Constraint
1822 | ManyConstraints Constraint {
1823 if($2->type == ACT_CA_SET && $2->el_count == 1) {
1824 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $2->elements[0]);
1825 } else {
1826 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $2);
1827 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001828 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001829 ;
1830
Lev Walkind523ea42017-09-06 22:15:08 -07001831ConstraintSpec: SubtypeConstraint | GeneralConstraint;
1832
1833SubtypeConstraint: ElementSetSpecs;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001834
Lev Walkinf59d0752004-08-18 04:59:12 +00001835ElementSetSpecs:
Lev Walkin5045dfa2006-03-21 09:41:28 +00001836 TOK_ThreeDots {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001837 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkin5045dfa2006-03-21 09:41:28 +00001838 $$->type = ACT_EL_EXT;
1839 }
Lev Walkin0c686452017-09-07 22:59:36 -07001840 | ElementSetSpec
1841 | ElementSetSpec ',' TOK_ThreeDots {
1842 asn1p_constraint_t *ct;
1843 ct = asn1p_constraint_new(yylineno, currentModule);
1844 ct->type = ACT_EL_EXT;
1845 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
1846 }
1847 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
1848 asn1p_constraint_t *ct;
1849 ct = asn1p_constraint_new(yylineno, currentModule);
1850 ct->type = ACT_EL_EXT;
1851 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
1852 ct = $$;
1853 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
1854 }
1855;
Lev Walkinf15320b2004-06-03 03:38:44 +00001856
Lev Walkinf59d0752004-08-18 04:59:12 +00001857ElementSetSpec:
Lev Walkinf1727152006-09-21 01:50:37 +00001858 Unions
Lev Walkin0c686452017-09-07 22:59:36 -07001859 | TOK_ALL TOK_EXCEPT Elements {
Lev Walkin2c14a692005-08-12 10:08:45 +00001860 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
Lev Walkin1e448d32005-03-24 14:26:38 +00001861 }
Lev Walkinf1727152006-09-21 01:50:37 +00001862 ;
1863
1864Unions:
1865 Intersections
1866 | Unions UnionMark Intersections {
Lev Walkin2c14a692005-08-12 10:08:45 +00001867 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001868 }
Lev Walkinf1727152006-09-21 01:50:37 +00001869 ;
1870
1871Intersections:
1872 IntersectionElements
1873 | Intersections IntersectionMark IntersectionElements {
Lev Walkin2c14a692005-08-12 10:08:45 +00001874 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001875 }
Lev Walkinf1727152006-09-21 01:50:37 +00001876 ;
1877
1878
1879IntersectionElements:
Lev Walkin0c686452017-09-07 22:59:36 -07001880 Elements
1881 | Elements TOK_EXCEPT Elements {
Lev Walkin2c14a692005-08-12 10:08:45 +00001882 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001883 }
1884 ;
1885
Lev Walkin0c686452017-09-07 22:59:36 -07001886Elements:
1887 SubtypeElements
1888 | '(' ElementSetSpec ')' {
1889 int ret;
1890 $$ = asn1p_constraint_new(yylineno, currentModule);
1891 checkmem($$);
1892 $$->type = ACT_CA_SET;
1893 ret = asn1p_constraint_insert($$, $2);
1894 checkmem(ret == 0);
1895 }
1896 ;
1897
1898SubtypeElements:
1899 SingleValue {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001900 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001901 checkmem($$);
1902 $$->type = ACT_EL_VALUE;
1903 $$->value = $1;
1904 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001905 | ContainedSubtype {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001906 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinff7dd142005-03-20 12:58:00 +00001907 checkmem($$);
1908 $$->type = ACT_EL_TYPE;
1909 $$->containedSubtype = $1;
1910 }
Lev Walkin0c686452017-09-07 22:59:36 -07001911 | PermittedAlphabet /* FROM ... */
1912 | SizeConstraint /* SIZE ... */
1913 /* | TypeConstraint is via ContainedSubtype */
1914 | InnerTypeConstraints /* WITH COMPONENT[S] ... */
1915 | PatternConstraint /* PATTERN ... */
1916 | ValueRange
Lev Walkin5c541f12006-10-18 18:40:14 +00001917 ;
1918
Lev Walkin0c686452017-09-07 22:59:36 -07001919
1920PermittedAlphabet:
1921 TOK_FROM Constraint {
1922 CONSTRAINT_INSERT($$, ACT_CT_FROM, $2, 0);
1923 };
1924
1925SizeConstraint:
1926 TOK_SIZE Constraint {
1927 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $2, 0);
1928 };
1929
Lev Walkin5c541f12006-10-18 18:40:14 +00001930PatternConstraint:
1931 TOK_PATTERN TOK_cstring {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001932 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkin5c541f12006-10-18 18:40:14 +00001933 $$->type = ACT_CT_PATTERN;
1934 $$->value = asn1p_value_frombuf($2.buf, $2.len, 0);
1935 }
1936 | TOK_PATTERN Identifier {
1937 asn1p_ref_t *ref;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001938 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkin5c541f12006-10-18 18:40:14 +00001939 $$->type = ACT_CT_PATTERN;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001940 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkin5c541f12006-10-18 18:40:14 +00001941 asn1p_ref_add_component(ref, $2, RLT_lowercase);
1942 $$->value = asn1p_value_fromref(ref, 0);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001943 free($2);
Lev Walkin5c541f12006-10-18 18:40:14 +00001944 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001945 ;
1946
Lev Walkin0c686452017-09-07 22:59:36 -07001947ValueRange:
1948 LowerEndValue ConstraintRangeSpec UpperEndValue {
1949 $$ = asn1p_constraint_new(yylineno, currentModule);
1950 checkmem($$);
1951 $$->type = $2;
1952 $$->range_start = $1;
1953 $$->range_stop = $3;
1954 };
1955
1956LowerEndValue:
1957 SingleValue
1958 | TOK_MIN {
1959 $$ = asn1p_value_fromint(-123);
1960 $$->type = ATV_MIN;
1961 };
1962
1963UpperEndValue:
1964 SingleValue
1965 | TOK_MAX {
1966 $$ = asn1p_value_fromint(321);
1967 $$->type = ATV_MAX;
1968 };
Lev Walkinf15320b2004-06-03 03:38:44 +00001969
Lev Walkin59165cf2017-09-11 06:24:45 -07001970SingleValue: Value;
Lev Walkinff7dd142005-03-20 12:58:00 +00001971
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001972BitStringValue:
1973 TOK_bstring {
1974 $$ = _convert_bitstring2binary($1, 'B');
1975 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001976 free($1);
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001977 }
1978 | TOK_hstring {
1979 $$ = _convert_bitstring2binary($1, 'H');
1980 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001981 free($1);
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001982 }
1983 ;
1984
Lev Walkinff7dd142005-03-20 12:58:00 +00001985ContainedSubtype:
Lev Walkin59165cf2017-09-11 06:24:45 -07001986 TOK_INCLUDES Type {
Lev Walkin0c686452017-09-07 22:59:36 -07001987 $$ = asn1p_value_fromtype($2);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001988 checkmem($$);
Lev Walkined409e22017-09-26 18:07:40 -07001989 asn1p_expr_free($2);
Lev Walkind523ea42017-09-06 22:15:08 -07001990 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001991 /* Can't put Type here because of conflicts. Simplified subset */
1992 | DefinedUntaggedType {
1993 $$ = asn1p_value_fromtype($1);
1994 checkmem($$);
Lev Walkined409e22017-09-26 18:07:40 -07001995 asn1p_expr_free($1);
Lev Walkin59165cf2017-09-11 06:24:45 -07001996 }
Lev Walkin0c686452017-09-07 22:59:36 -07001997 ;
1998
Lev Walkind523ea42017-09-06 22:15:08 -07001999/*
2000 * X.680 08/2015
2001 * #51.8.5
2002 */
Lev Walkin0c686452017-09-07 22:59:36 -07002003InnerTypeConstraints:
Lev Walkind523ea42017-09-06 22:15:08 -07002004 TOK_WITH TOK_COMPONENT SingleTypeConstraint {
Lev Walkin2c14a692005-08-12 10:08:45 +00002005 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
Lev Walkine596bf02005-03-28 15:01:27 +00002006 }
Lev Walkind523ea42017-09-06 22:15:08 -07002007 | TOK_WITH TOK_COMPONENTS MultipleTypeConstraints {
2008 assert($3->type == ACT_CA_CSV);
2009 $3->type = ACT_CT_WCOMPS;
2010 $$ = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +00002011 }
2012 ;
Lev Walkind523ea42017-09-06 22:15:08 -07002013SingleTypeConstraint: Constraint;
2014MultipleTypeConstraints: FullSpecification | PartialSpecification;
2015FullSpecification: '{' TypeConstraints '}' { $$ = $2; };
2016PartialSpecification:
2017 '{' TOK_ThreeDots ',' TypeConstraints '}' {
2018 assert($4->type == ACT_CA_CSV);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002019 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkind523ea42017-09-06 22:15:08 -07002020 $$->type = ACT_CA_CSV;
2021 asn1p_constraint_t *ct = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002022 checkmem($$);
Lev Walkind523ea42017-09-06 22:15:08 -07002023 ct->type = ACT_EL_EXT;
2024 asn1p_constraint_insert($$, ct);
2025 for(unsigned i = 0; i < $4->el_count; i++) {
2026 asn1p_constraint_insert($$, $4->elements[i]);
2027 }
2028 };
2029TypeConstraints:
2030 NamedConstraint {
2031 $$ = asn1p_constraint_new(yylineno, currentModule);
2032 $$->type = ACT_CA_CSV;
2033 asn1p_constraint_insert($$, $1);
2034 }
2035 | TypeConstraints ',' NamedConstraint {
2036 $$ = $1;
2037 asn1p_constraint_insert($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002038 }
2039 ;
Lev Walkind523ea42017-09-06 22:15:08 -07002040NamedConstraint:
Lev Walkin0c686452017-09-07 22:59:36 -07002041 IdentifierAsValue optConstraint optPresenceConstraint {
Lev Walkind523ea42017-09-06 22:15:08 -07002042 $$ = asn1p_constraint_new(yylineno, currentModule);
2043 checkmem($$);
2044 $$->type = ACT_EL_VALUE;
2045 $$->value = $1;
2046 if($2) asn1p_constraint_insert($$, $2);
2047 $$->presence = $3;
2048 }
2049 ;
Lev Walkinf15320b2004-06-03 03:38:44 +00002050
2051/*
Lev Walkind523ea42017-09-06 22:15:08 -07002052 * presence constraint for NamedConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +00002053 */
2054optPresenceConstraint:
2055 { $$ = ACPRES_DEFAULT; }
2056 | PresenceConstraint { $$ = $1; }
2057 ;
2058
2059PresenceConstraint:
2060 TOK_PRESENT {
2061 $$ = ACPRES_PRESENT;
2062 }
2063 | TOK_ABSENT {
2064 $$ = ACPRES_ABSENT;
2065 }
2066 | TOK_OPTIONAL {
2067 $$ = ACPRES_OPTIONAL;
2068 }
2069 ;
2070
Lev Walkina9532f42006-09-17 04:52:50 +00002071
2072/* X.682 */
2073GeneralConstraint:
2074 UserDefinedConstraint
2075 | TableConstraint
2076 | ContentsConstraint
2077 ;
2078
2079UserDefinedConstraint:
2080 TOK_CONSTRAINED TOK_BY '{'
2081 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002082 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkina9532f42006-09-17 04:52:50 +00002083 checkmem($$);
2084 $$->type = ACT_CT_CTDBY;
2085 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
2086 checkmem($$->value);
2087 $$->value->type = ATV_UNPARSED;
2088 }
2089 ;
2090
2091ContentsConstraint:
2092 TOK_CONTAINING Type {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002093 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkina9532f42006-09-17 04:52:50 +00002094 $$->type = ACT_CT_CTNG;
2095 $$->value = asn1p_value_fromtype($2);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08002096 asn1p_expr_free($2);
Lev Walkina9532f42006-09-17 04:52:50 +00002097 }
2098 ;
2099
2100ConstraintRangeSpec:
2101 TOK_TwoDots { $$ = ACT_EL_RANGE; }
2102 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
2103 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
2104 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
2105 ;
Lev Walkinf15320b2004-06-03 03:38:44 +00002106TableConstraint:
2107 SimpleTableConstraint {
2108 $$ = $1;
2109 }
2110 | ComponentRelationConstraint {
2111 $$ = $1;
2112 }
2113 ;
2114
2115/*
2116 * "{ExtensionSet}"
2117 */
2118SimpleTableConstraint:
2119 '{' TypeRefName '}' {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002120 asn1p_ref_t *ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002121 asn1p_constraint_t *ct;
2122 int ret;
2123 ret = asn1p_ref_add_component(ref, $2, 0);
2124 checkmem(ret == 0);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002125 ct = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002126 checkmem($$);
2127 ct->type = ACT_EL_VALUE;
2128 ct->value = asn1p_value_fromref(ref, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00002129 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08002130 free($2);
Lev Walkinf15320b2004-06-03 03:38:44 +00002131 }
2132 ;
2133
2134ComponentRelationConstraint:
2135 SimpleTableConstraint '{' AtNotationList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00002136 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002137 }
2138 ;
2139
2140AtNotationList:
2141 AtNotationElement {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002142 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002143 checkmem($$);
2144 $$->type = ACT_EL_VALUE;
2145 $$->value = asn1p_value_fromref($1, 0);
2146 }
2147 | AtNotationList ',' AtNotationElement {
2148 asn1p_constraint_t *ct;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002149 ct = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002150 checkmem(ct);
2151 ct->type = ACT_EL_VALUE;
2152 ct->value = asn1p_value_fromref($3, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00002153 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00002154 }
2155 ;
2156
2157/*
2158 * @blah
2159 */
2160AtNotationElement:
2161 '@' ComponentIdList {
2162 char *p = malloc(strlen($2) + 2);
2163 int ret;
2164 *p = '@';
2165 strcpy(p + 1, $2);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002166 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002167 ret = asn1p_ref_add_component($$, p, 0);
2168 checkmem(ret == 0);
2169 free(p);
2170 free($2);
2171 }
2172 | '@' '.' ComponentIdList {
2173 char *p = malloc(strlen($3) + 3);
2174 int ret;
2175 p[0] = '@';
2176 p[1] = '.';
2177 strcpy(p + 2, $3);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002178 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002179 ret = asn1p_ref_add_component($$, p, 0);
2180 checkmem(ret == 0);
2181 free(p);
2182 free($3);
2183 }
2184 ;
2185
2186/* identifier "." ... */
2187ComponentIdList:
2188 Identifier {
2189 $$ = $1;
2190 }
2191 | ComponentIdList '.' Identifier {
2192 int l1 = strlen($1);
2193 int l3 = strlen($3);
2194 $$ = malloc(l1 + 1 + l3 + 1);
2195 memcpy($$, $1, l1);
2196 $$[l1] = '.';
2197 memcpy($$ + l1 + 1, $3, l3);
2198 $$[l1 + 1 + l3] = '\0';
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08002199 free($1);
2200 free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002201 }
2202 ;
2203
2204
2205
2206/*
2207 * MARKERS
2208 */
2209
2210optMarker:
Lev Walkin9c974182004-09-15 11:59:51 +00002211 {
2212 $$.flags = EM_NOMARK;
2213 $$.default_value = 0;
2214 }
Lev Walkinf15320b2004-06-03 03:38:44 +00002215 | Marker { $$ = $1; }
2216 ;
2217
2218Marker:
2219 TOK_OPTIONAL {
Lev Walkin70853052005-11-26 11:21:55 +00002220 $$.flags = EM_OPTIONAL | EM_INDIRECT;
Lev Walkin9c974182004-09-15 11:59:51 +00002221 $$.default_value = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +00002222 }
Lev Walkin9c974182004-09-15 11:59:51 +00002223 | TOK_DEFAULT Value {
2224 $$.flags = EM_DEFAULT;
2225 $$.default_value = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00002226 }
2227 ;
2228
Lev Walkinbe518fa2017-09-07 02:05:28 -07002229IdentifierList:
2230 IdentifierElement {
Lev Walkina9532f42006-09-17 04:52:50 +00002231 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002232 checkmem($$);
Lev Walkinbe518fa2017-09-07 02:05:28 -07002233 asn1p_expr_add($$, $1);
2234 }
2235 | IdentifierList ',' IdentifierElement {
2236 $$ = $1;
2237 asn1p_expr_add($$, $3);
2238 };
2239
2240IdentifierElement:
2241 Identifier {
2242 $$ = NEW_EXPR();
2243 checkmem($$);
2244 $$->expr_type = A1TC_UNIVERVAL;
2245 $$->meta_type = AMT_VALUE;
2246 $$->Identifier = $1;
2247 }
2248
2249NamedNumberList:
2250 NamedNumber {
2251 $$ = NEW_EXPR();
2252 checkmem($$);
2253 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00002254 }
Lev Walkinbe518fa2017-09-07 02:05:28 -07002255 | NamedNumberList ',' NamedNumber {
2256 $$ = $1;
2257 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002258 }
2259 ;
2260
Lev Walkinbe518fa2017-09-07 02:05:28 -07002261NamedNumber:
2262 Identifier '(' SignedNumber ')' {
2263 $$ = NEW_EXPR();
2264 checkmem($$);
2265 $$->expr_type = A1TC_UNIVERVAL;
2266 $$->meta_type = AMT_VALUE;
2267 $$->Identifier = $1;
2268 $$->value = $3;
2269 }
2270 | Identifier '(' DefinedValue ')' {
2271 $$ = NEW_EXPR();
2272 checkmem($$);
2273 $$->expr_type = A1TC_UNIVERVAL;
2274 $$->meta_type = AMT_VALUE;
2275 $$->Identifier = $1;
2276 $$->value = $3;
2277 };
2278
2279NamedBitList:
2280 NamedBit {
2281 $$ = NEW_EXPR();
2282 checkmem($$);
2283 asn1p_expr_add($$, $1);
2284 }
2285 | NamedBitList ',' NamedBit {
2286 $$ = $1;
2287 asn1p_expr_add($$, $3);
2288 }
2289 ;
2290
2291NamedBit:
2292 Identifier '(' TOK_number ')' {
2293 $$ = NEW_EXPR();
2294 checkmem($$);
2295 $$->expr_type = A1TC_UNIVERVAL;
2296 $$->meta_type = AMT_VALUE;
2297 $$->Identifier = $1;
2298 $$->value = asn1p_value_fromint($3);
2299 }
2300 | Identifier '(' DefinedValue ')' {
2301 $$ = NEW_EXPR();
2302 checkmem($$);
2303 $$->expr_type = A1TC_UNIVERVAL;
2304 $$->meta_type = AMT_VALUE;
2305 $$->Identifier = $1;
2306 $$->value = $3;
2307 };
2308
2309Enumerations:
2310 UniverationList {
2311 $$ = $1;
2312 asn1p_expr_t *first_memb = TQ_FIRST(&($$->members));
2313 if(first_memb) {
2314 if(first_memb->expr_type == A1TC_EXTENSIBLE) {
2315 return yyerror(
2316 "The ENUMERATION cannot start with extension (...).");
2317 }
2318 } else {
2319 return yyerror(
2320 "The ENUMERATION list cannot be empty.");
2321 }
2322 }
2323
Lev Walkinf15320b2004-06-03 03:38:44 +00002324UniverationList:
2325 UniverationElement {
Lev Walkina9532f42006-09-17 04:52:50 +00002326 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002327 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00002328 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00002329 }
2330 | UniverationList ',' UniverationElement {
2331 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00002332 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002333 }
2334 ;
2335
2336UniverationElement:
2337 Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +00002338 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002339 checkmem($$);
2340 $$->expr_type = A1TC_UNIVERVAL;
2341 $$->meta_type = AMT_VALUE;
2342 $$->Identifier = $1;
2343 }
2344 | Identifier '(' SignedNumber ')' {
Lev Walkina9532f42006-09-17 04:52:50 +00002345 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002346 checkmem($$);
2347 $$->expr_type = A1TC_UNIVERVAL;
2348 $$->meta_type = AMT_VALUE;
2349 $$->Identifier = $1;
2350 $$->value = $3;
2351 }
2352 | Identifier '(' DefinedValue ')' {
Lev Walkina9532f42006-09-17 04:52:50 +00002353 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002354 checkmem($$);
2355 $$->expr_type = A1TC_UNIVERVAL;
2356 $$->meta_type = AMT_VALUE;
2357 $$->Identifier = $1;
2358 $$->value = $3;
2359 }
2360 | SignedNumber {
Lev Walkina9532f42006-09-17 04:52:50 +00002361 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002362 checkmem($$);
2363 $$->expr_type = A1TC_UNIVERVAL;
2364 $$->meta_type = AMT_VALUE;
2365 $$->value = $1;
2366 }
2367 | TOK_ThreeDots {
Lev Walkina9532f42006-09-17 04:52:50 +00002368 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002369 checkmem($$);
2370 $$->Identifier = strdup("...");
2371 checkmem($$->Identifier);
2372 $$->expr_type = A1TC_EXTENSIBLE;
2373 $$->meta_type = AMT_VALUE;
2374 }
2375 ;
2376
2377SignedNumber:
2378 TOK_number {
2379 $$ = asn1p_value_fromint($1);
2380 checkmem($$);
2381 }
2382 | TOK_number_negative {
2383 $$ = asn1p_value_fromint($1);
2384 checkmem($$);
2385 }
2386 ;
2387
Lev Walkinadf863f2006-09-05 16:18:34 +00002388RealValue:
Lev Walkin59165cf2017-09-11 06:24:45 -07002389 TOK_realnumber {
Lev Walkinadf863f2006-09-05 16:18:34 +00002390 $$ = asn1p_value_fromdouble($1);
2391 checkmem($$);
2392 }
2393 ;
2394
Lev Walkinf15320b2004-06-03 03:38:44 +00002395/*
2396 * SEQUENCE definition.
2397 * === EXAMPLE ===
2398 * Struct1 ::= SEQUENCE {
2399 * memb1 Struct2,
2400 * memb2 SEQUENCE OF {
2401 * memb2-1 Struct 3
2402 * }
2403 * }
2404 * === EOF ===
2405 */
2406
2407
2408
2409/*
2410 * SET definition.
2411 * === EXAMPLE ===
2412 * Person ::= SET {
2413 * name [0] PrintableString (SIZE(1..20)),
2414 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2415 * }
2416 * === EOF ===
2417 */
2418
2419optTag:
2420 { memset(&$$, 0, sizeof($$)); }
2421 | Tag { $$ = $1; }
2422 ;
2423
2424Tag:
Lev Walkinc603f102005-01-23 09:51:44 +00002425 TagTypeValue TagPlicit {
Lev Walkinf15320b2004-06-03 03:38:44 +00002426 $$ = $1;
Lev Walkinc603f102005-01-23 09:51:44 +00002427 $$.tag_mode = $2.tag_mode;
Lev Walkinf15320b2004-06-03 03:38:44 +00002428 }
Lev Walkinc603f102005-01-23 09:51:44 +00002429 ;
2430
2431TagTypeValue:
2432 '[' TagClass TOK_number ']' {
2433 $$ = $2;
2434 $$.tag_value = $3;
2435 };
2436
2437TagClass:
2438 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2439 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2440 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2441 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2442 ;
2443
2444TagPlicit:
2445 { $$.tag_mode = TM_DEFAULT; }
2446 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2447 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
Lev Walkinf15320b2004-06-03 03:38:44 +00002448 ;
2449
2450TypeRefName:
2451 TOK_typereference {
2452 checkmem($1);
2453 $$ = $1;
2454 }
Lev Walkinf59d0752004-08-18 04:59:12 +00002455 | TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002456 checkmem($1);
2457 $$ = $1;
2458 }
2459 ;
2460
Lev Walkinf59d0752004-08-18 04:59:12 +00002461
Lev Walkin83cac2f2004-09-22 16:03:36 +00002462optIdentifier:
2463 { $$ = 0; }
2464 | Identifier {
2465 $$ = $1;
2466 }
Lev Walkin8f294e02005-06-06 08:28:58 +00002467 ;
Lev Walkin83cac2f2004-09-22 16:03:36 +00002468
Lev Walkinf15320b2004-06-03 03:38:44 +00002469Identifier:
2470 TOK_identifier {
2471 checkmem($1);
2472 $$ = $1;
2473 }
2474 ;
2475
Lev Walkind523ea42017-09-06 22:15:08 -07002476IdentifierAsReference:
2477 Identifier {
2478 $$ = asn1p_ref_new(yylineno, currentModule);
2479 asn1p_ref_add_component($$, $1, RLT_lowercase);
Lev Walkined409e22017-09-26 18:07:40 -07002480 free($1);
Lev Walkind523ea42017-09-06 22:15:08 -07002481 };
2482
2483IdentifierAsValue:
2484 IdentifierAsReference {
2485 $$ = asn1p_value_fromref($1, 0);
2486 };
2487
Lev Walkinf15320b2004-06-03 03:38:44 +00002488%%
2489
2490
2491/*
2492 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2493 */
2494static asn1p_value_t *
2495_convert_bitstring2binary(char *str, int base) {
2496 asn1p_value_t *val;
2497 int slen;
2498 int memlen;
2499 int baselen;
2500 int bits;
2501 uint8_t *binary_vector;
2502 uint8_t *bv_ptr;
2503 uint8_t cur_val;
2504
2505 assert(str);
2506 assert(str[0] == '\'');
2507
2508 switch(base) {
2509 case 'B':
2510 baselen = 1;
2511 break;
2512 case 'H':
2513 baselen = 4;
2514 break;
2515 default:
2516 assert(base == 'B' || base == 'H');
2517 errno = EINVAL;
2518 return NULL;
2519 }
2520
2521 slen = strlen(str);
2522 assert(str[slen - 1] == base);
2523 assert(str[slen - 2] == '\'');
2524
2525 memlen = slen / (8 / baselen); /* Conservative estimate */
2526
2527 bv_ptr = binary_vector = malloc(memlen + 1);
2528 if(bv_ptr == NULL)
2529 /* ENOMEM */
2530 return NULL;
2531
2532 cur_val = 0;
2533 bits = 0;
2534 while(*(++str) != '\'') {
2535 switch(baselen) {
2536 case 1:
2537 switch(*str) {
2538 case '1':
2539 cur_val |= 1 << (7 - (bits % 8));
2540 case '0':
2541 break;
2542 default:
2543 assert(!"_y UNREACH1");
2544 case ' ': case '\r': case '\n':
2545 continue;
2546 }
2547 break;
2548 case 4:
2549 switch(*str) {
2550 case '0': case '1': case '2': case '3': case '4':
2551 case '5': case '6': case '7': case '8': case '9':
2552 cur_val |= (*str - '0') << (4 - (bits % 8));
2553 break;
2554 case 'A': case 'B': case 'C':
2555 case 'D': case 'E': case 'F':
2556 cur_val |= ((*str - 'A') + 10)
2557 << (4 - (bits % 8));
2558 break;
2559 default:
2560 assert(!"_y UNREACH2");
2561 case ' ': case '\r': case '\n':
2562 continue;
2563 }
2564 break;
2565 }
2566
2567 bits += baselen;
2568 if((bits % 8) == 0) {
2569 *bv_ptr++ = cur_val;
2570 cur_val = 0;
2571 }
2572 }
2573
2574 *bv_ptr = cur_val;
2575 assert((bv_ptr - binary_vector) <= memlen);
2576
2577 val = asn1p_value_frombits(binary_vector, bits, 0);
2578 if(val == NULL) {
2579 free(binary_vector);
2580 }
2581
2582 return val;
2583}
2584
Lev Walkin2e9bd5c2005-08-13 09:07:11 +00002585/*
2586 * For unnamed types (used in old X.208 compliant modules)
2587 * generate some sort of interim names, to not to force human being to fix
2588 * the specification's compliance to modern ASN.1 standards.
2589 */
2590static void
2591_fixup_anonymous_identifier(asn1p_expr_t *expr) {
2592 char *p;
2593 assert(expr->Identifier == 0);
2594
2595 /*
2596 * Try to figure out the type name
2597 * without going too much into details
2598 */
2599 expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type);
2600 if(expr->reference && expr->reference->comp_count > 0)
2601 expr->Identifier = expr->reference->components[0].name;
2602
2603 fprintf(stderr,
2604 "WARNING: Line %d: expected lower-case member identifier, "
2605 "found an unnamed %s.\n"
2606 "WARNING: Obsolete X.208 syntax detected, "
2607 "please give the member a name.\n",
2608 yylineno, expr->Identifier ? expr->Identifier : "type");
2609
2610 if(!expr->Identifier)
2611 expr->Identifier = "unnamed";
2612 expr->Identifier = strdup(expr->Identifier);
2613 assert(expr->Identifier);
2614 /* Make a lowercase identifier from the type name */
2615 for(p = expr->Identifier; *p; p++) {
2616 switch(*p) {
2617 case 'A' ... 'Z': *p += 32; break;
2618 case ' ': *p = '_'; break;
2619 case '-': *p = '_'; break;
2620 }
2621 }
2622 fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". "
2623 "Name clash may occur later.\n",
2624 expr->Identifier);
2625}
2626
Lev Walkin59165cf2017-09-11 06:24:45 -07002627static int
Lev Walkinf15320b2004-06-03 03:38:44 +00002628yyerror(const char *msg) {
Lev Walkin9d542d22006-03-14 16:31:37 +00002629 extern char *asn1p_text;
Lev Walkinf15320b2004-06-03 03:38:44 +00002630 fprintf(stderr,
2631 "ASN.1 grammar parse error "
Lev Walkind523ea42017-09-06 22:15:08 -07002632 "near %s:%d (token \"%s\"): %s\n",
2633 ASN_FILENAME, yylineno, asn1p_text, msg);
Lev Walkinf15320b2004-06-03 03:38:44 +00002634 return -1;
2635}
2636