blob: 88d5a2ca81e723b50c3a7c8ef26b137dec113038 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001%{
2
3#include <stdlib.h>
4#include <stdio.h>
5#include <string.h>
6#include <errno.h>
7#include <assert.h>
8
9#include "asn1parser.h"
10
11#define YYPARSE_PARAM param
Lev Walkin4354b442005-06-07 21:25:42 +000012#define YYPARSE_PARAM_TYPE void **
Lev Walkinf15320b2004-06-03 03:38:44 +000013#define YYERROR_VERBOSE
14
15int yylex(void);
16int yyerror(const char *msg);
Lev Walkin8daab912005-06-07 21:32:16 +000017#ifdef YYBYACC
18int yyparse(void **param); /* byacc does not produce a prototype */
19#endif
Lev Walkinf15320b2004-06-03 03:38:44 +000020void asn1p_lexer_hack_push_opaque_state(void);
21void asn1p_lexer_hack_enable_with_syntax(void);
Lev Walkinf59d0752004-08-18 04:59:12 +000022void asn1p_lexer_hack_push_encoding_control(void);
Lev Walkinf15320b2004-06-03 03:38:44 +000023#define yylineno asn1p_lineno
24extern int asn1p_lineno;
25
Lev Walkin1ed22092005-08-12 10:06:17 +000026/*
Lev Walkinef625402005-09-05 05:17:57 +000027 * Process directives as <ASN1C:RepresentAsPointer>
Lev Walkin4696c742005-08-22 12:23:54 +000028 */
29extern int asn1p_as_pointer;
Lev Walkin4696c742005-08-22 12:23:54 +000030
31/*
Lev Walkin1ed22092005-08-12 10:06:17 +000032 * This temporary variable is used to solve the shortcomings of 1-lookahead
33 * parser.
34 */
35static struct AssignedIdentifier *saved_aid;
Lev Walkinf15320b2004-06-03 03:38:44 +000036
Lev Walkin2e9bd5c2005-08-13 09:07:11 +000037static asn1p_value_t *_convert_bitstring2binary(char *str, int base);
38static void _fixup_anonymous_identifier(asn1p_expr_t *expr);
Lev Walkinf15320b2004-06-03 03:38:44 +000039
Lev Walkina9532f42006-09-17 04:52:50 +000040static asn1p_module_t *currentModule;
41#define NEW_EXPR() (asn1p_expr_new(yylineno, currentModule))
42
Lev Walkin1ed22092005-08-12 10:06:17 +000043#define checkmem(ptr) do { \
44 if(!(ptr)) \
45 return yyerror("Memory failure"); \
Lev Walkinf15320b2004-06-03 03:38:44 +000046 } while(0)
47
Lev Walkin2c14a692005-08-12 10:08:45 +000048#define CONSTRAINT_INSERT(root, constr_type, arg1, arg2) do { \
Lev Walkin1ed22092005-08-12 10:06:17 +000049 if(arg1->type != constr_type) { \
50 int __ret; \
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +080051 root = asn1p_constraint_new(yylineno, currentModule); \
Lev Walkin1ed22092005-08-12 10:06:17 +000052 checkmem(root); \
53 root->type = constr_type; \
54 __ret = asn1p_constraint_insert(root, \
55 arg1); \
56 checkmem(__ret == 0); \
57 } else { \
58 root = arg1; \
59 } \
60 if(arg2) { \
61 int __ret \
62 = asn1p_constraint_insert(root, arg2); \
63 checkmem(__ret == 0); \
64 } \
Lev Walkinf15320b2004-06-03 03:38:44 +000065 } while(0)
66
Lev Walkin866bd7f2006-09-14 10:35:20 +000067#ifdef AL_IMPORT
68#error AL_IMPORT DEFINED ELSEWHERE!
69#endif
70#define AL_IMPORT(to,where,from,field) do { \
71 if(!(from)) break; \
72 while(TQ_FIRST(&((from)->where))) { \
73 TQ_ADD(&((to)->where), \
74 TQ_REMOVE(&((from)->where), field), \
75 field); \
76 } \
77 assert(TQ_FIRST(&((from)->where)) == 0); \
78 } while(0)
79
Lev Walkinf15320b2004-06-03 03:38:44 +000080%}
81
82
83/*
84 * Token value definition.
85 * a_*: ASN-specific types.
86 * tv_*: Locally meaningful types.
87 */
88%union {
89 asn1p_t *a_grammar;
90 asn1p_module_flags_e a_module_flags;
91 asn1p_module_t *a_module;
92 asn1p_expr_type_e a_type; /* ASN.1 Type */
93 asn1p_expr_t *a_expr; /* Constructed collection */
94 asn1p_constraint_t *a_constr; /* Constraint */
95 enum asn1p_constraint_type_e a_ctype;/* Constraint type */
96 asn1p_xports_t *a_xports; /* IMports/EXports */
Lev Walkin1ed22092005-08-12 10:06:17 +000097 struct AssignedIdentifier a_aid; /* Assigned Identifier */
Lev Walkinf15320b2004-06-03 03:38:44 +000098 asn1p_oid_t *a_oid; /* Object Identifier */
99 asn1p_oid_arc_t a_oid_arc; /* Single OID's arc */
100 struct asn1p_type_tag_s a_tag; /* A tag */
101 asn1p_ref_t *a_ref; /* Reference to custom type */
102 asn1p_wsyntx_t *a_wsynt; /* WITH SYNTAX contents */
103 asn1p_wsyntx_chunk_t *a_wchunk; /* WITH SYNTAX chunk */
104 struct asn1p_ref_component_s a_refcomp; /* Component of a reference */
105 asn1p_value_t *a_value; /* Number, DefinedValue, etc */
106 struct asn1p_param_s a_parg; /* A parameter argument */
107 asn1p_paramlist_t *a_plist; /* A pargs list */
Lev Walkin9c974182004-09-15 11:59:51 +0000108 struct asn1p_expr_marker_s a_marker; /* OPTIONAL/DEFAULT */
Lev Walkinf15320b2004-06-03 03:38:44 +0000109 enum asn1p_constr_pres_e a_pres; /* PRESENT/ABSENT/OPTIONAL */
Lev Walkin144db9b2004-10-12 23:26:53 +0000110 asn1c_integer_t a_int;
Lev Walkinadf863f2006-09-05 16:18:34 +0000111 double a_dbl;
Lev Walkinf15320b2004-06-03 03:38:44 +0000112 char *tv_str;
113 struct {
114 char *buf;
115 int len;
116 } tv_opaque;
117 struct {
118 char *name;
119 struct asn1p_type_tag_s tag;
120 } tv_nametag;
121};
122
123/*
124 * Token types returned by scanner.
125 */
126%token TOK_PPEQ /* "::=", Pseudo Pascal EQuality */
Lev Walkin0e90aa02013-03-19 16:17:13 -0700127%token TOK_VBracketLeft TOK_VBracketRight /* "[[", "]]" */
Lev Walkin57074f12006-03-16 05:11:14 +0000128%token <tv_opaque> TOK_whitespace /* A span of whitespace */
Lev Walkinf15320b2004-06-03 03:38:44 +0000129%token <tv_opaque> TOK_opaque /* opaque data (driven from .y) */
130%token <tv_str> TOK_bstring
131%token <tv_opaque> TOK_cstring
132%token <tv_str> TOK_hstring
133%token <tv_str> TOK_identifier
134%token <a_int> TOK_number
Lev Walkinadf863f2006-09-05 16:18:34 +0000135%token <a_int> TOK_number_negative
136%token <a_dbl> TOK_realnumber
Lev Walkind9574ae2005-03-24 16:22:35 +0000137%token <a_int> TOK_tuple
138%token <a_int> TOK_quadruple
Lev Walkinf15320b2004-06-03 03:38:44 +0000139%token <tv_str> TOK_typereference
Lev Walkinf59d0752004-08-18 04:59:12 +0000140%token <tv_str> TOK_capitalreference /* "CLASS1" */
Lev Walkinf15320b2004-06-03 03:38:44 +0000141%token <tv_str> TOK_typefieldreference /* "&Pork" */
142%token <tv_str> TOK_valuefieldreference /* "&id" */
Lev Walkin9d542d22006-03-14 16:31:37 +0000143%token <tv_str> TOK_Literal /* "BY" */
Lev Walkinf15320b2004-06-03 03:38:44 +0000144
145/*
146 * Token types representing ASN.1 standard keywords.
147 */
148%token TOK_ABSENT
149%token TOK_ABSTRACT_SYNTAX
150%token TOK_ALL
151%token TOK_ANY
152%token TOK_APPLICATION
153%token TOK_AUTOMATIC
154%token TOK_BEGIN
155%token TOK_BIT
156%token TOK_BMPString
157%token TOK_BOOLEAN
158%token TOK_BY
159%token TOK_CHARACTER
160%token TOK_CHOICE
161%token TOK_CLASS
162%token TOK_COMPONENT
163%token TOK_COMPONENTS
164%token TOK_CONSTRAINED
165%token TOK_CONTAINING
166%token TOK_DEFAULT
167%token TOK_DEFINITIONS
168%token TOK_DEFINED
169%token TOK_EMBEDDED
170%token TOK_ENCODED
Lev Walkinf59d0752004-08-18 04:59:12 +0000171%token TOK_ENCODING_CONTROL
Lev Walkinf15320b2004-06-03 03:38:44 +0000172%token TOK_END
173%token TOK_ENUMERATED
174%token TOK_EXPLICIT
175%token TOK_EXPORTS
176%token TOK_EXTENSIBILITY
177%token TOK_EXTERNAL
178%token TOK_FALSE
179%token TOK_FROM
180%token TOK_GeneralizedTime
181%token TOK_GeneralString
182%token TOK_GraphicString
183%token TOK_IA5String
184%token TOK_IDENTIFIER
185%token TOK_IMPLICIT
186%token TOK_IMPLIED
187%token TOK_IMPORTS
188%token TOK_INCLUDES
189%token TOK_INSTANCE
Lev Walkinf59d0752004-08-18 04:59:12 +0000190%token TOK_INSTRUCTIONS
Lev Walkinf15320b2004-06-03 03:38:44 +0000191%token TOK_INTEGER
192%token TOK_ISO646String
193%token TOK_MAX
194%token TOK_MIN
195%token TOK_MINUS_INFINITY
196%token TOK_NULL
197%token TOK_NumericString
198%token TOK_OBJECT
199%token TOK_ObjectDescriptor
200%token TOK_OCTET
201%token TOK_OF
202%token TOK_OPTIONAL
203%token TOK_PATTERN
204%token TOK_PDV
205%token TOK_PLUS_INFINITY
206%token TOK_PRESENT
207%token TOK_PrintableString
208%token TOK_PRIVATE
209%token TOK_REAL
210%token TOK_RELATIVE_OID
211%token TOK_SEQUENCE
212%token TOK_SET
213%token TOK_SIZE
214%token TOK_STRING
215%token TOK_SYNTAX
216%token TOK_T61String
217%token TOK_TAGS
218%token TOK_TeletexString
219%token TOK_TRUE
220%token TOK_TYPE_IDENTIFIER
221%token TOK_UNIQUE
222%token TOK_UNIVERSAL
223%token TOK_UniversalString
224%token TOK_UTCTime
225%token TOK_UTF8String
226%token TOK_VideotexString
227%token TOK_VisibleString
228%token TOK_WITH
Lev Walkin752e9732017-08-04 02:06:22 -0700229%token UTF8_BOM "UTF-8 byte order mark"
Lev Walkinf15320b2004-06-03 03:38:44 +0000230
Lev Walkinf1727152006-09-21 01:50:37 +0000231%nonassoc TOK_EXCEPT
Lev Walkinf59d0752004-08-18 04:59:12 +0000232%left '^' TOK_INTERSECTION
233%left '|' TOK_UNION
Lev Walkinf15320b2004-06-03 03:38:44 +0000234
235/* Misc tags */
236%token TOK_TwoDots /* .. */
237%token TOK_ThreeDots /* ... */
Lev Walkinf15320b2004-06-03 03:38:44 +0000238
239
240/*
241 * Types defined herein.
242 */
243%type <a_grammar> ModuleList
Lev Walkin866bd7f2006-09-14 10:35:20 +0000244%type <a_module> ModuleDefinition
245%type <a_module> ModuleBody
246%type <a_module> AssignmentList
247%type <a_module> Assignment
248%type <a_module> optModuleBody /* Optional */
249%type <a_module_flags> optModuleDefinitionFlags
250%type <a_module_flags> ModuleDefinitionFlags /* Set of FL */
251%type <a_module_flags> ModuleDefinitionFlag /* Single FL */
252%type <a_module> optImports
253%type <a_module> optExports
Lev Walkinf15320b2004-06-03 03:38:44 +0000254%type <a_module> ImportsDefinition
Lev Walkin4a4543f2006-10-13 12:37:39 +0000255%type <a_module> optImportsBundleSet
Lev Walkinf15320b2004-06-03 03:38:44 +0000256%type <a_module> ImportsBundleSet
257%type <a_xports> ImportsBundle
258%type <a_xports> ImportsList
259%type <a_xports> ExportsDefinition
260%type <a_xports> ExportsBody
261%type <a_expr> ImportsElement
262%type <a_expr> ExportsElement
Lev Walkinf15320b2004-06-03 03:38:44 +0000263%type <a_expr> ExtensionAndException
Lev Walkina9532f42006-09-17 04:52:50 +0000264%type <a_expr> Type
Lev Walkin070a52d2004-08-22 03:19:54 +0000265%type <a_expr> TypeDeclaration
Lev Walkin4696c742005-08-22 12:23:54 +0000266%type <a_expr> TypeDeclarationSet
Lev Walkinf15320b2004-06-03 03:38:44 +0000267%type <a_ref> ComplexTypeReference
268%type <a_ref> ComplexTypeReferenceAmpList
269%type <a_refcomp> ComplexTypeReferenceElement
Lev Walkind370e9f2006-03-16 10:03:35 +0000270%type <a_refcomp> PrimitiveFieldReference
Lev Walkin9c2285a2006-03-09 08:49:26 +0000271%type <a_expr> FieldSpec
272%type <a_ref> FieldName
273%type <a_ref> DefinedObjectClass
Lev Walkinf15320b2004-06-03 03:38:44 +0000274%type <a_expr> ClassField
Lev Walkin9c2285a2006-03-09 08:49:26 +0000275%type <a_expr> ObjectClass
Lev Walkinf15320b2004-06-03 03:38:44 +0000276%type <a_expr> DataTypeReference /* Type1 ::= Type2 */
Lev Walkin0c0bca62006-03-21 04:48:15 +0000277%type <a_expr> DefinedType
Lev Walkin557f27d2006-03-21 07:46:48 +0000278%type <a_constr> ValueSet /* {a|b|c}*/
279%type <a_expr> ValueSetTypeAssignment /* Val INTEGER ::= {1|2} */
Lev Walkinc6ab03c2006-10-21 05:54:49 +0000280%type <a_expr> ValueAssignment /* val INTEGER ::= 1*/
Lev Walkin9c974182004-09-15 11:59:51 +0000281%type <a_value> Value
Lev Walkin0c0bca62006-03-21 04:48:15 +0000282%type <a_value> SimpleValue
Lev Walkinf15320b2004-06-03 03:38:44 +0000283%type <a_value> DefinedValue
284%type <a_value> SignedNumber
Lev Walkinadf863f2006-09-05 16:18:34 +0000285%type <a_value> RealValue
Lev Walkin1c8d5aa2006-10-27 05:37:39 +0000286%type <a_value> BitStringValue
Lev Walkin144db9b2004-10-12 23:26:53 +0000287%type <a_expr> optComponentTypeLists
Lev Walkin070a52d2004-08-22 03:19:54 +0000288%type <a_expr> ComponentTypeLists
289%type <a_expr> ComponentType
290%type <a_expr> AlternativeTypeLists
291%type <a_expr> AlternativeType
Lev Walkinf15320b2004-06-03 03:38:44 +0000292%type <a_expr> UniverationDefinition
293%type <a_expr> UniverationList
294%type <a_expr> UniverationElement
295%type <tv_str> TypeRefName
296%type <tv_str> ObjectClassReference
Lev Walkinf15320b2004-06-03 03:38:44 +0000297%type <tv_str> Identifier
Lev Walkin83cac2f2004-09-22 16:03:36 +0000298%type <tv_str> optIdentifier
Lev Walkinf15320b2004-06-03 03:38:44 +0000299%type <a_parg> ParameterArgumentName
300%type <a_plist> ParameterArgumentList
Lev Walkin5045dfa2006-03-21 09:41:28 +0000301%type <a_expr> ActualParameter
302%type <a_expr> ActualParameterList
Lev Walkin1ed22092005-08-12 10:06:17 +0000303%type <a_aid> AssignedIdentifier /* OID/DefinedValue */
Lev Walkinf15320b2004-06-03 03:38:44 +0000304%type <a_oid> ObjectIdentifier /* OID */
305%type <a_oid> optObjectIdentifier /* Optional OID */
306%type <a_oid> ObjectIdentifierBody
307%type <a_oid_arc> ObjectIdentifierElement
308%type <a_expr> BasicType
309%type <a_type> BasicTypeId
310%type <a_type> BasicTypeId_UniverationCompatible
311%type <a_type> BasicString
312%type <tv_opaque> Opaque
Lev Walkinc603f102005-01-23 09:51:44 +0000313%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
314%type <a_tag> TagClass TagTypeValue TagPlicit
Lev Walkinf15320b2004-06-03 03:38:44 +0000315%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
316%type <a_constr> optConstraints
Lev Walkina9532f42006-09-17 04:52:50 +0000317%type <a_constr> Constraint
318%type <a_constr> SubtypeConstraint
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800319%type <a_constr> ConstraintSpecs
Lev Walkina9532f42006-09-17 04:52:50 +0000320%type <a_constr> GeneralConstraint
Lev Walkinf59d0752004-08-18 04:59:12 +0000321%type <a_constr> SetOfConstraints
322%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
323%type <a_constr> ElementSetSpec /* 1..2,...,3 */
Lev Walkinf1727152006-09-21 01:50:37 +0000324%type <a_constr> Unions
325%type <a_constr> Intersections
326%type <a_constr> IntersectionElements
Lev Walkinf15320b2004-06-03 03:38:44 +0000327%type <a_constr> ConstraintSubtypeElement /* 1..2 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000328%type <a_constr> SimpleTableConstraint
Lev Walkina9532f42006-09-17 04:52:50 +0000329%type <a_constr> UserDefinedConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +0000330%type <a_constr> TableConstraint
Lev Walkina9532f42006-09-17 04:52:50 +0000331%type <a_constr> ContentsConstraint
Lev Walkin5c541f12006-10-18 18:40:14 +0000332%type <a_constr> PatternConstraint
Lev Walkine596bf02005-03-28 15:01:27 +0000333%type <a_constr> InnerTypeConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +0000334%type <a_constr> WithComponentsList
335%type <a_constr> WithComponentsElement
336%type <a_constr> ComponentRelationConstraint
337%type <a_constr> AtNotationList
338%type <a_ref> AtNotationElement
Lev Walkinff7dd142005-03-20 12:58:00 +0000339%type <a_value> SingleValue
340%type <a_value> ContainedSubtype
Lev Walkinf15320b2004-06-03 03:38:44 +0000341%type <a_ctype> ConstraintSpec
342%type <a_ctype> ConstraintRangeSpec
Lev Walkin1e448d32005-03-24 14:26:38 +0000343%type <a_value> RestrictedCharacterStringValue
Lev Walkinf15320b2004-06-03 03:38:44 +0000344%type <a_wsynt> optWithSyntax
345%type <a_wsynt> WithSyntax
Lev Walkin9d542d22006-03-14 16:31:37 +0000346%type <a_wsynt> WithSyntaxList
347%type <a_wchunk> WithSyntaxToken
Lev Walkinf15320b2004-06-03 03:38:44 +0000348%type <a_marker> optMarker Marker
349%type <a_int> optUnique
350%type <a_pres> optPresenceConstraint PresenceConstraint
351%type <tv_str> ComponentIdList
Lev Walkinef625402005-09-05 05:17:57 +0000352%type <a_int> NSTD_IndirectMarker
Lev Walkinf15320b2004-06-03 03:38:44 +0000353
Lev Walkinf15320b2004-06-03 03:38:44 +0000354%%
355
356
357ParsedGrammar:
Lev Walkin752e9732017-08-04 02:06:22 -0700358 UTF8_BOM ModuleList {
359 *(void **)param = $2;
360 }
361 | ModuleList {
Lev Walkinf15320b2004-06-03 03:38:44 +0000362 *(void **)param = $1;
363 }
364 ;
365
366ModuleList:
Lev Walkin866bd7f2006-09-14 10:35:20 +0000367 ModuleDefinition {
Lev Walkinf15320b2004-06-03 03:38:44 +0000368 $$ = asn1p_new();
369 checkmem($$);
370 TQ_ADD(&($$->modules), $1, mod_next);
371 }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000372 | ModuleList ModuleDefinition {
Lev Walkinf15320b2004-06-03 03:38:44 +0000373 $$ = $1;
374 TQ_ADD(&($$->modules), $2, mod_next);
375 }
376 ;
377
378/*
379 * ASN module definition.
380 * === EXAMPLE ===
381 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
382 * BEGIN
383 * ...
384 * END
385 * === EOF ===
386 */
387
Lev Walkin866bd7f2006-09-14 10:35:20 +0000388ModuleDefinition:
Lev Walkina9532f42006-09-17 04:52:50 +0000389 TypeRefName { currentModule = asn1p_module_new(); }
390 optObjectIdentifier TOK_DEFINITIONS
Lev Walkin866bd7f2006-09-14 10:35:20 +0000391 optModuleDefinitionFlags
Lev Walkinf15320b2004-06-03 03:38:44 +0000392 TOK_PPEQ TOK_BEGIN
Lev Walkin866bd7f2006-09-14 10:35:20 +0000393 optModuleBody
Lev Walkinf15320b2004-06-03 03:38:44 +0000394 TOK_END {
395
Lev Walkina9532f42006-09-17 04:52:50 +0000396 $$ = currentModule;
397
398 if($8) {
399 asn1p_module_t tmp = *($$);
400 *($$) = *($8);
401 *($8) = tmp;
402 asn1p_module_free($8);
Lev Walkinf15320b2004-06-03 03:38:44 +0000403 } else {
404 /* There's a chance that a module is just plain empty */
Lev Walkinf15320b2004-06-03 03:38:44 +0000405 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000406
Lev Walkin1ed22092005-08-12 10:06:17 +0000407 $$->ModuleName = $1;
Lev Walkina9532f42006-09-17 04:52:50 +0000408 $$->module_oid = $3;
409 $$->module_flags = $5;
Lev Walkinf15320b2004-06-03 03:38:44 +0000410 }
411 ;
412
413/*
414 * Object Identifier Definition
415 * { iso member-body(2) 3 }
416 */
417optObjectIdentifier:
418 { $$ = 0; }
419 | ObjectIdentifier { $$ = $1; }
420 ;
421
422ObjectIdentifier:
423 '{' ObjectIdentifierBody '}' {
424 $$ = $2;
425 }
426 | '{' '}' {
427 $$ = 0;
428 }
429 ;
430
431ObjectIdentifierBody:
432 ObjectIdentifierElement {
433 $$ = asn1p_oid_new();
434 asn1p_oid_add_arc($$, &$1);
435 if($1.name)
436 free($1.name);
437 }
438 | ObjectIdentifierBody ObjectIdentifierElement {
439 $$ = $1;
440 asn1p_oid_add_arc($$, &$2);
441 if($2.name)
442 free($2.name);
443 }
444 ;
445
446ObjectIdentifierElement:
447 Identifier { /* iso */
448 $$.name = $1;
449 $$.number = -1;
450 }
451 | Identifier '(' TOK_number ')' { /* iso(1) */
452 $$.name = $1;
453 $$.number = $3;
454 }
455 | TOK_number { /* 1 */
456 $$.name = 0;
457 $$.number = $1;
458 }
459 ;
460
461/*
462 * Optional module flags.
463 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000464optModuleDefinitionFlags:
Lev Walkinf15320b2004-06-03 03:38:44 +0000465 { $$ = MSF_NOFLAGS; }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000466 | ModuleDefinitionFlags {
Lev Walkinf15320b2004-06-03 03:38:44 +0000467 $$ = $1;
468 }
469 ;
470
471/*
472 * Module flags.
473 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000474ModuleDefinitionFlags:
475 ModuleDefinitionFlag {
Lev Walkinf15320b2004-06-03 03:38:44 +0000476 $$ = $1;
477 }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000478 | ModuleDefinitionFlags ModuleDefinitionFlag {
Lev Walkinf15320b2004-06-03 03:38:44 +0000479 $$ = $1 | $2;
480 }
481 ;
482
483/*
484 * Single module flag.
485 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000486ModuleDefinitionFlag:
Lev Walkinf15320b2004-06-03 03:38:44 +0000487 TOK_EXPLICIT TOK_TAGS {
488 $$ = MSF_EXPLICIT_TAGS;
489 }
490 | TOK_IMPLICIT TOK_TAGS {
491 $$ = MSF_IMPLICIT_TAGS;
492 }
493 | TOK_AUTOMATIC TOK_TAGS {
494 $$ = MSF_AUTOMATIC_TAGS;
495 }
496 | TOK_EXTENSIBILITY TOK_IMPLIED {
497 $$ = MSF_EXTENSIBILITY_IMPLIED;
498 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000499 /* EncodingReferenceDefault */
500 | TOK_capitalreference TOK_INSTRUCTIONS {
501 /* X.680Amd1 specifies TAG and XER */
502 if(strcmp($1, "TAG") == 0) {
503 $$ = MSF_TAG_INSTRUCTIONS;
504 } else if(strcmp($1, "XER") == 0) {
505 $$ = MSF_XER_INSTRUCTIONS;
506 } else {
507 fprintf(stderr,
508 "WARNING: %s INSTRUCTIONS at line %d: "
509 "Unrecognized encoding reference\n",
510 $1, yylineno);
511 $$ = MSF_unk_INSTRUCTIONS;
512 }
513 free($1);
514 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000515 ;
516
517/*
518 * Optional module body.
519 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000520optModuleBody:
Lev Walkinf15320b2004-06-03 03:38:44 +0000521 { $$ = 0; }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000522 | ModuleBody {
Lev Walkinf15320b2004-06-03 03:38:44 +0000523 $$ = $1;
524 }
525 ;
526
527/*
528 * ASN.1 Module body.
529 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000530ModuleBody:
531 optExports optImports AssignmentList {
532 $$ = asn1p_module_new();
533 AL_IMPORT($$, exports, $1, xp_next);
534 AL_IMPORT($$, imports, $2, xp_next);
535 AL_IMPORT($$, members, $3, next);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800536
537 asn1p_module_free($1);
538 asn1p_module_free($2);
539 asn1p_module_free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000540 }
541 ;
542
Lev Walkin866bd7f2006-09-14 10:35:20 +0000543AssignmentList:
544 Assignment {
545 $$ = $1;
546 }
547 | AssignmentList Assignment {
548 if($1) {
549 $$ = $1;
550 } else {
551 $$ = $2;
552 break;
553 }
554 AL_IMPORT($$, members, $2, next);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800555 asn1p_module_free($2);
Lev Walkin866bd7f2006-09-14 10:35:20 +0000556 }
557 ;
558
559
Lev Walkinf15320b2004-06-03 03:38:44 +0000560/*
561 * One of the elements of ASN.1 module specification.
562 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000563Assignment:
564 DataTypeReference {
Lev Walkinf15320b2004-06-03 03:38:44 +0000565 $$ = asn1p_module_new();
566 checkmem($$);
567 assert($1->expr_type != A1TC_INVALID);
568 assert($1->meta_type != AMT_INVALID);
569 TQ_ADD(&($$->members), $1, next);
570 }
Lev Walkinc6ab03c2006-10-21 05:54:49 +0000571 | ValueAssignment {
Lev Walkinf15320b2004-06-03 03:38:44 +0000572 $$ = asn1p_module_new();
573 checkmem($$);
574 assert($1->expr_type != A1TC_INVALID);
575 assert($1->meta_type != AMT_INVALID);
576 TQ_ADD(&($$->members), $1, next);
577 }
578 /*
579 * Value set definition
580 * === EXAMPLE ===
581 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
582 * === EOF ===
Lev Walkine700b202017-08-06 23:21:32 -0700583 * Also ObjectClassSet.
Lev Walkinf15320b2004-06-03 03:38:44 +0000584 */
Lev Walkin557f27d2006-03-21 07:46:48 +0000585 | ValueSetTypeAssignment {
Lev Walkinf15320b2004-06-03 03:38:44 +0000586 $$ = asn1p_module_new();
587 checkmem($$);
588 assert($1->expr_type != A1TC_INVALID);
589 assert($1->meta_type != AMT_INVALID);
590 TQ_ADD(&($$->members), $1, next);
591 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000592 | TOK_ENCODING_CONTROL TOK_capitalreference
593 { asn1p_lexer_hack_push_encoding_control(); }
594 {
595 fprintf(stderr,
596 "WARNING: ENCODING-CONTROL %s "
597 "specification at line %d ignored\n",
598 $2, yylineno);
599 free($2);
600 $$ = 0;
601 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000602
603 /*
604 * Erroneous attemps
605 */
606 | BasicString {
607 return yyerror(
Lev Walkin70853052005-11-26 11:21:55 +0000608 "Attempt to redefine a standard basic string type, "
609 "please comment out or remove this type redefinition.");
Lev Walkinf15320b2004-06-03 03:38:44 +0000610 }
611 ;
612
613/*
614 * === EXAMPLE ===
615 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
616 * === EOF ===
617 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000618optImports:
619 { $$ = 0; }
620 | ImportsDefinition;
621
Lev Walkinf15320b2004-06-03 03:38:44 +0000622ImportsDefinition:
Lev Walkin4a4543f2006-10-13 12:37:39 +0000623 TOK_IMPORTS optImportsBundleSet ';' {
Lev Walkin1ed22092005-08-12 10:06:17 +0000624 if(!saved_aid && 0)
625 return yyerror("Unterminated IMPORTS FROM, "
626 "expected semicolon ';'");
627 saved_aid = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +0000628 $$ = $2;
629 }
630 /*
631 * Some error cases.
632 */
633 | TOK_IMPORTS TOK_FROM /* ... */ {
634 return yyerror("Empty IMPORTS list");
635 }
636 ;
637
Lev Walkin4a4543f2006-10-13 12:37:39 +0000638optImportsBundleSet:
639 { $$ = asn1p_module_new(); }
640 | ImportsBundleSet;
641
Lev Walkinf15320b2004-06-03 03:38:44 +0000642ImportsBundleSet:
643 ImportsBundle {
644 $$ = asn1p_module_new();
645 checkmem($$);
646 TQ_ADD(&($$->imports), $1, xp_next);
647 }
648 | ImportsBundleSet ImportsBundle {
649 $$ = $1;
650 TQ_ADD(&($$->imports), $2, xp_next);
651 }
652 ;
653
Lev Walkin1ed22092005-08-12 10:06:17 +0000654AssignedIdentifier:
655 { memset(&$$, 0, sizeof($$)); }
656 | ObjectIdentifier { $$.oid = $1; };
657 /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
658
Lev Walkinf15320b2004-06-03 03:38:44 +0000659ImportsBundle:
Lev Walkin1ed22092005-08-12 10:06:17 +0000660 ImportsList TOK_FROM TypeRefName AssignedIdentifier {
Lev Walkinf15320b2004-06-03 03:38:44 +0000661 $$ = $1;
Lev Walkin1ed22092005-08-12 10:06:17 +0000662 $$->fromModuleName = $3;
663 $$->identifier = $4;
664 /* This stupid thing is used for look-back hack. */
665 saved_aid = $$->identifier.oid ? 0 : &($$->identifier);
Lev Walkinf15320b2004-06-03 03:38:44 +0000666 checkmem($$);
667 }
668 ;
669
670ImportsList:
671 ImportsElement {
672 $$ = asn1p_xports_new();
673 checkmem($$);
674 TQ_ADD(&($$->members), $1, next);
675 }
676 | ImportsList ',' ImportsElement {
677 $$ = $1;
678 TQ_ADD(&($$->members), $3, next);
679 }
680 ;
681
682ImportsElement:
683 TypeRefName {
Lev Walkina9532f42006-09-17 04:52:50 +0000684 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000685 checkmem($$);
686 $$->Identifier = $1;
687 $$->expr_type = A1TC_REFERENCE;
688 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000689 | TypeRefName '{' '}' { /* Completely equivalent to above */
Lev Walkina9532f42006-09-17 04:52:50 +0000690 $$ = NEW_EXPR();
Lev Walkin144db9b2004-10-12 23:26:53 +0000691 checkmem($$);
692 $$->Identifier = $1;
693 $$->expr_type = A1TC_REFERENCE;
694 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000695 | Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +0000696 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000697 checkmem($$);
698 $$->Identifier = $1;
699 $$->expr_type = A1TC_REFERENCE;
700 }
701 ;
702
Lev Walkin866bd7f2006-09-14 10:35:20 +0000703
704optExports:
705 { $$ = 0; }
706 | ExportsDefinition {
707 $$ = asn1p_module_new();
708 checkmem($$);
709 if($1) {
710 TQ_ADD(&($$->exports), $1, xp_next);
711 } else {
712 /* "EXPORTS ALL;" */
713 }
714 }
715 ;
716
Lev Walkinf15320b2004-06-03 03:38:44 +0000717ExportsDefinition:
718 TOK_EXPORTS ExportsBody ';' {
719 $$ = $2;
720 }
721 | TOK_EXPORTS TOK_ALL ';' {
722 $$ = 0;
723 }
724 | TOK_EXPORTS ';' {
725 /* Empty EXPORTS clause effectively prohibits export. */
726 $$ = asn1p_xports_new();
727 checkmem($$);
728 }
729 ;
730
731ExportsBody:
732 ExportsElement {
733 $$ = asn1p_xports_new();
734 assert($$);
735 TQ_ADD(&($$->members), $1, next);
736 }
737 | ExportsBody ',' ExportsElement {
738 $$ = $1;
739 TQ_ADD(&($$->members), $3, next);
740 }
741 ;
742
743ExportsElement:
744 TypeRefName {
Lev Walkina9532f42006-09-17 04:52:50 +0000745 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000746 checkmem($$);
747 $$->Identifier = $1;
748 $$->expr_type = A1TC_EXPORTVAR;
749 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000750 | TypeRefName '{' '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000751 $$ = NEW_EXPR();
Lev Walkin144db9b2004-10-12 23:26:53 +0000752 checkmem($$);
753 $$->Identifier = $1;
754 $$->expr_type = A1TC_EXPORTVAR;
755 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000756 | Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +0000757 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000758 checkmem($$);
759 $$->Identifier = $1;
760 $$->expr_type = A1TC_EXPORTVAR;
761 }
762 ;
763
764
Lev Walkin418298d2006-07-13 08:24:20 +0000765ValueSet: '{' ElementSetSpecs '}' { $$ = $2; };
Lev Walkin557f27d2006-03-21 07:46:48 +0000766
767ValueSetTypeAssignment:
768 TypeRefName DefinedType TOK_PPEQ ValueSet {
Lev Walkinf15320b2004-06-03 03:38:44 +0000769 $$ = $2;
770 assert($$->Identifier == 0);
771 $$->Identifier = $1;
772 $$->meta_type = AMT_VALUESET;
Lev Walkin557f27d2006-03-21 07:46:48 +0000773 $$->constraints = $4;
Lev Walkinf15320b2004-06-03 03:38:44 +0000774 }
775 ;
776
Lev Walkin0c0bca62006-03-21 04:48:15 +0000777DefinedType:
778 BasicType {
779 $$ = $1;
780 }
781 /*
782 * A DefinedType reference.
783 * "CLASS1.&id.&id2"
784 * or
785 * "Module.Type"
786 * or
787 * "Module.identifier"
788 * or
789 * "Type"
790 */
791 | ComplexTypeReference {
Lev Walkina9532f42006-09-17 04:52:50 +0000792 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000793 checkmem($$);
794 $$->reference = $1;
795 $$->expr_type = A1TC_REFERENCE;
796 $$->meta_type = AMT_TYPEREF;
797 }
Lev Walkin0c0bca62006-03-21 04:48:15 +0000798 /*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000799 * A parameterized assignment.
Lev Walkin0c0bca62006-03-21 04:48:15 +0000800 */
Lev Walkin5045dfa2006-03-21 09:41:28 +0000801 | ComplexTypeReference '{' ActualParameterList '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000802 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000803 checkmem($$);
Lev Walkin0c0bca62006-03-21 04:48:15 +0000804 $$->reference = $1;
805 $$->rhs_pspecs = $3;
806 $$->expr_type = A1TC_REFERENCE;
807 $$->meta_type = AMT_TYPEREF;
Lev Walkinf15320b2004-06-03 03:38:44 +0000808 }
809 ;
810
Lev Walkinf15320b2004-06-03 03:38:44 +0000811/*
812 * Data Type Reference.
813 * === EXAMPLE ===
814 * Type3 ::= CHOICE { a Type1, b Type 2 }
815 * === EOF ===
816 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000817DataTypeReference:
818 /*
819 * Optionally tagged type definition.
820 */
Lev Walkin9c2285a2006-03-09 08:49:26 +0000821 TypeRefName TOK_PPEQ Type {
Lev Walkinaf120f72004-09-14 02:36:39 +0000822 $$ = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000823 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000824 assert($$->expr_type);
825 assert($$->meta_type);
826 }
Lev Walkin9c2285a2006-03-09 08:49:26 +0000827 | TypeRefName TOK_PPEQ ObjectClass {
Lev Walkinf15320b2004-06-03 03:38:44 +0000828 $$ = $3;
829 $$->Identifier = $1;
830 assert($$->expr_type == A1TC_CLASSDEF);
Lev Walkin9c2285a2006-03-09 08:49:26 +0000831 assert($$->meta_type == AMT_OBJECTCLASS);
Lev Walkinf15320b2004-06-03 03:38:44 +0000832 }
833 /*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000834 * Parameterized <Type> declaration:
Lev Walkinf15320b2004-06-03 03:38:44 +0000835 * === EXAMPLE ===
836 * SIGNED { ToBeSigned } ::= SEQUENCE {
837 * toBeSigned ToBeSigned,
838 * algorithm AlgorithmIdentifier,
839 * signature BIT STRING
840 * }
841 * === EOF ===
842 */
Lev Walkin070a52d2004-08-22 03:19:54 +0000843 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000844 $$ = $6;
Lev Walkin5045dfa2006-03-21 09:41:28 +0000845 $$->Identifier = $1;
846 $$->lhs_params = $3;
847 }
848 /* Parameterized CLASS declaration */
849 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ ObjectClass {
850 $$ = $6;
Lev Walkinf15320b2004-06-03 03:38:44 +0000851 $$->Identifier = $1;
Lev Walkina00d6b32006-03-21 03:40:38 +0000852 $$->lhs_params = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000853 }
854 ;
855
856ParameterArgumentList:
857 ParameterArgumentName {
858 int ret;
859 $$ = asn1p_paramlist_new(yylineno);
860 checkmem($$);
861 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
862 checkmem(ret == 0);
Lev Walkina964e032017-03-26 03:48:06 -0700863 asn1p_ref_free($1.governor);
864 free($1.argument);
Lev Walkinf15320b2004-06-03 03:38:44 +0000865 }
866 | ParameterArgumentList ',' ParameterArgumentName {
867 int ret;
868 $$ = $1;
869 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
870 checkmem(ret == 0);
Lev Walkina964e032017-03-26 03:48:06 -0700871 asn1p_ref_free($3.governor);
872 free($3.argument);
Lev Walkinf15320b2004-06-03 03:38:44 +0000873 }
874 ;
875
876ParameterArgumentName:
877 TypeRefName {
878 $$.governor = NULL;
879 $$.argument = $1;
880 }
881 | TypeRefName ':' Identifier {
882 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800883 $$.governor = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +0000884 ret = asn1p_ref_add_component($$.governor, $1, 0);
885 checkmem(ret == 0);
886 $$.argument = $3;
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800887 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000888 }
Lev Walkinc8092cb2005-02-18 16:34:21 +0000889 | TypeRefName ':' TypeRefName {
890 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800891 $$.governor = asn1p_ref_new(yylineno, currentModule);
Lev Walkinc8092cb2005-02-18 16:34:21 +0000892 ret = asn1p_ref_add_component($$.governor, $1, 0);
893 checkmem(ret == 0);
894 $$.argument = $3;
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800895 free($1);
Lev Walkinc8092cb2005-02-18 16:34:21 +0000896 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000897 | BasicTypeId ':' Identifier {
898 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800899 $$.governor = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +0000900 ret = asn1p_ref_add_component($$.governor,
901 ASN_EXPR_TYPE2STR($1), 1);
902 checkmem(ret == 0);
903 $$.argument = $3;
904 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000905 | BasicTypeId ':' TypeRefName {
906 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800907 $$.governor = asn1p_ref_new(yylineno, currentModule);
Lev Walkin5045dfa2006-03-21 09:41:28 +0000908 ret = asn1p_ref_add_component($$.governor,
909 ASN_EXPR_TYPE2STR($1), 1);
910 checkmem(ret == 0);
911 $$.argument = $3;
912 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000913 ;
914
Lev Walkin5045dfa2006-03-21 09:41:28 +0000915ActualParameterList:
916 ActualParameter {
Lev Walkina9532f42006-09-17 04:52:50 +0000917 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000918 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000919 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000920 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000921 | ActualParameterList ',' ActualParameter {
Lev Walkinf15320b2004-06-03 03:38:44 +0000922 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000923 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000924 }
925 ;
926
Lev Walkin5045dfa2006-03-21 09:41:28 +0000927ActualParameter:
Lev Walkin070a52d2004-08-22 03:19:54 +0000928 Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000929 $$ = $1;
930 }
Lev Walkin0c0bca62006-03-21 04:48:15 +0000931 | SimpleValue {
Lev Walkina9532f42006-09-17 04:52:50 +0000932 $$ = NEW_EXPR();
Lev Walkin0c0bca62006-03-21 04:48:15 +0000933 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800934 $$->Identifier = strdup("?");
Lev Walkin0c0bca62006-03-21 04:48:15 +0000935 $$->expr_type = A1TC_REFERENCE;
936 $$->meta_type = AMT_VALUE;
937 $$->value = $1;
938 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000939 | Identifier {
Lev Walkina00d6b32006-03-21 03:40:38 +0000940 asn1p_ref_t *ref;
Lev Walkina9532f42006-09-17 04:52:50 +0000941 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000942 checkmem($$);
943 $$->Identifier = $1;
944 $$->expr_type = A1TC_REFERENCE;
945 $$->meta_type = AMT_VALUE;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800946 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkina00d6b32006-03-21 03:40:38 +0000947 asn1p_ref_add_component(ref, $1, RLT_lowercase);
948 $$->value = asn1p_value_fromref(ref, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +0000949 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000950 | ValueSet {
Lev Walkina9532f42006-09-17 04:52:50 +0000951 $$ = NEW_EXPR();
Lev Walkin5045dfa2006-03-21 09:41:28 +0000952 $$->expr_type = A1TC_VALUESET;
953 $$->meta_type = AMT_VALUESET;
954 $$->constraints = $1;
955 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000956 ;
957
958/*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000959 | '{' ActualParameter '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000960 $$ = NEW_EXPR();
Lev Walkinc8092cb2005-02-18 16:34:21 +0000961 checkmem($$);
962 asn1p_expr_add($$, $2);
963 $$->expr_type = A1TC_PARAMETRIZED;
964 $$->meta_type = AMT_TYPE;
965 }
966 ;
967*/
968
969/*
Lev Walkinf15320b2004-06-03 03:38:44 +0000970 * A collection of constructed data type members.
971 */
Lev Walkin144db9b2004-10-12 23:26:53 +0000972optComponentTypeLists:
Lev Walkina9532f42006-09-17 04:52:50 +0000973 { $$ = NEW_EXPR(); }
Lev Walkin144db9b2004-10-12 23:26:53 +0000974 | ComponentTypeLists { $$ = $1; };
975
Lev Walkin070a52d2004-08-22 03:19:54 +0000976ComponentTypeLists:
977 ComponentType {
Lev Walkina9532f42006-09-17 04:52:50 +0000978 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000979 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000980 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000981 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000982 | ComponentTypeLists ',' ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +0000983 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000984 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000985 }
Lev Walkin0e90aa02013-03-19 16:17:13 -0700986 | ComponentTypeLists ',' TOK_VBracketLeft ComponentTypeLists TOK_VBracketRight {
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800987 $$ = $1;
Lev Walkin0e90aa02013-03-19 16:17:13 -0700988 asn1p_expr_add_many($$, $4);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800989 asn1p_expr_free($4);
Lev Walkin0e90aa02013-03-19 16:17:13 -0700990 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000991 ;
992
Lev Walkin070a52d2004-08-22 03:19:54 +0000993ComponentType:
Lev Walkinaf120f72004-09-14 02:36:39 +0000994 Identifier Type optMarker {
Lev Walkin070a52d2004-08-22 03:19:54 +0000995 $$ = $2;
996 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +0000997 $$->Identifier = $1;
Lev Walkinef625402005-09-05 05:17:57 +0000998 $3.flags |= $$->marker.flags;
Lev Walkin070a52d2004-08-22 03:19:54 +0000999 $$->marker = $3;
1000 }
Lev Walkinef625402005-09-05 05:17:57 +00001001 | Type optMarker {
1002 $$ = $1;
1003 $2.flags |= $$->marker.flags;
1004 $$->marker = $2;
1005 _fixup_anonymous_identifier($$);
1006 }
Lev Walkin070a52d2004-08-22 03:19:54 +00001007 | TOK_COMPONENTS TOK_OF Type {
Lev Walkina9532f42006-09-17 04:52:50 +00001008 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001009 checkmem($$);
1010 $$->meta_type = $3->meta_type;
1011 $$->expr_type = A1TC_COMPONENTS_OF;
Lev Walkin1004aa92004-09-08 00:28:11 +00001012 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +00001013 }
1014 | ExtensionAndException {
1015 $$ = $1;
1016 }
1017 ;
1018
1019AlternativeTypeLists:
1020 AlternativeType {
Lev Walkina9532f42006-09-17 04:52:50 +00001021 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001022 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00001023 asn1p_expr_add($$, $1);
Lev Walkin070a52d2004-08-22 03:19:54 +00001024 }
1025 | AlternativeTypeLists ',' AlternativeType {
1026 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001027 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +00001028 }
1029 ;
1030
1031AlternativeType:
Lev Walkinaf120f72004-09-14 02:36:39 +00001032 Identifier Type {
Lev Walkin070a52d2004-08-22 03:19:54 +00001033 $$ = $2;
1034 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +00001035 $$->Identifier = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001036 }
1037 | ExtensionAndException {
1038 $$ = $1;
1039 }
Lev Walkin2e9bd5c2005-08-13 09:07:11 +00001040 | Type {
1041 $$ = $1;
1042 _fixup_anonymous_identifier($$);
1043 }
Lev Walkin070a52d2004-08-22 03:19:54 +00001044 ;
1045
Lev Walkin9c2285a2006-03-09 08:49:26 +00001046ObjectClass:
1047 TOK_CLASS '{' FieldSpec '}' optWithSyntax {
Lev Walkinf15320b2004-06-03 03:38:44 +00001048 $$ = $3;
1049 checkmem($$);
1050 $$->with_syntax = $5;
1051 assert($$->expr_type == A1TC_CLASSDEF);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001052 assert($$->meta_type == AMT_OBJECTCLASS);
Lev Walkinf15320b2004-06-03 03:38:44 +00001053 }
1054 ;
1055
1056optUnique:
1057 { $$ = 0; }
1058 | TOK_UNIQUE { $$ = 1; }
1059 ;
1060
Lev Walkin9c2285a2006-03-09 08:49:26 +00001061FieldSpec:
Lev Walkinf15320b2004-06-03 03:38:44 +00001062 ClassField {
Lev Walkina9532f42006-09-17 04:52:50 +00001063 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001064 checkmem($$);
1065 $$->expr_type = A1TC_CLASSDEF;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001066 $$->meta_type = AMT_OBJECTCLASS;
Lev Walkin1004aa92004-09-08 00:28:11 +00001067 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001068 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001069 | FieldSpec ',' ClassField {
Lev Walkinf15320b2004-06-03 03:38:44 +00001070 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001071 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001072 }
1073 ;
1074
Lev Walkin9c2285a2006-03-09 08:49:26 +00001075 /* X.681 */
Lev Walkinf15320b2004-06-03 03:38:44 +00001076ClassField:
Lev Walkin9c2285a2006-03-09 08:49:26 +00001077
1078 /* TypeFieldSpec ::= typefieldreference TypeOptionalitySpec? */
1079 TOK_typefieldreference optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001080 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001081 checkmem($$);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001082 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001083 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001084 $$->expr_type = A1TC_CLASSFIELD_TFS; /* TypeFieldSpec */
Lev Walkinf15320b2004-06-03 03:38:44 +00001085 $$->marker = $2;
1086 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001087
1088 /* FixedTypeValueFieldSpec ::= valuefieldreference Type UNIQUE ? ValueOptionalitySpec ? */
1089 | TOK_valuefieldreference Type optUnique optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001090 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001091 $$->Identifier = $1;
1092 $$->meta_type = AMT_OBJECTFIELD;
1093 $$->expr_type = A1TC_CLASSFIELD_FTVFS; /* FixedTypeValueFieldSpec */
Lev Walkinb7c45ca2004-11-24 17:43:29 +00001094 $$->unique = $3;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001095 $$->marker = $4;
1096 asn1p_expr_add($$, $2);
Lev Walkinf15320b2004-06-03 03:38:44 +00001097 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001098
1099 /* VariableTypeValueFieldSpec ::= valuefieldreference FieldName ValueOptionalitySpec ? */
1100 | TOK_valuefieldreference FieldName optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001101 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001102 $$->Identifier = $1;
1103 $$->meta_type = AMT_OBJECTFIELD;
1104 $$->expr_type = A1TC_CLASSFIELD_VTVFS;
1105 $$->reference = $2;
1106 $$->marker = $3;
1107 }
1108
Lev Walkin9c2285a2006-03-09 08:49:26 +00001109 /* ObjectFieldSpec ::= objectfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1110 | TOK_valuefieldreference DefinedObjectClass optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001111 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001112 checkmem($$);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001113 $$->Identifier = $1;
1114 $$->reference = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00001115 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001116 $$->expr_type = A1TC_CLASSFIELD_OFS;
1117 $$->marker = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +00001118 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001119
Lev Walkin54868752006-03-09 09:08:49 +00001120 /* VariableTypeValueSetFieldSpec ::= valuesetfieldreference FieldName ValueOptionalitySpec ? */
1121 | TOK_typefieldreference FieldName optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001122 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001123 $$->Identifier = $1;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001124 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin54868752006-03-09 09:08:49 +00001125 $$->expr_type = A1TC_CLASSFIELD_VTVSFS;
1126 $$->reference = $2;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001127 $$->marker = $3;
1128 }
1129
1130 /* FixedTypeValueSetFieldSpec ::= valuesetfieldreference Type ValueSetOptionalitySpec ? */
1131 | TOK_typefieldreference Type optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001132 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001133 checkmem($$);
1134 $$->Identifier = $1;
1135 $$->meta_type = AMT_OBJECTFIELD;
1136 $$->expr_type = A1TC_CLASSFIELD_FTVSFS;
1137 asn1p_expr_add($$, $2);
1138 $$->marker = $3;
1139 }
1140
Lev Walkin54868752006-03-09 09:08:49 +00001141 /* ObjectSetFieldSpec ::= objectsetfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1142 | TOK_typefieldreference DefinedObjectClass optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001143 $$ = NEW_EXPR();
Lev Walkin54868752006-03-09 09:08:49 +00001144 checkmem($$);
1145 $$->Identifier = $1;
1146 $$->reference = $2;
1147 $$->meta_type = AMT_OBJECTFIELD;
1148 $$->expr_type = A1TC_CLASSFIELD_OSFS;
1149 $$->marker = $3;
1150 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001151 ;
1152
1153optWithSyntax:
1154 { $$ = 0; }
1155 | WithSyntax {
1156 $$ = $1;
1157 }
1158 ;
1159
1160WithSyntax:
1161 TOK_WITH TOK_SYNTAX '{'
1162 { asn1p_lexer_hack_enable_with_syntax(); }
Lev Walkin9d542d22006-03-14 16:31:37 +00001163 WithSyntaxList
Lev Walkinf15320b2004-06-03 03:38:44 +00001164 '}' {
1165 $$ = $5;
1166 }
1167 ;
1168
Lev Walkin9d542d22006-03-14 16:31:37 +00001169WithSyntaxList:
1170 WithSyntaxToken {
Lev Walkinf15320b2004-06-03 03:38:44 +00001171 $$ = asn1p_wsyntx_new();
1172 TQ_ADD(&($$->chunks), $1, next);
1173 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001174 | WithSyntaxList WithSyntaxToken {
Lev Walkinf15320b2004-06-03 03:38:44 +00001175 $$ = $1;
1176 TQ_ADD(&($$->chunks), $2, next);
1177 }
1178 ;
1179
Lev Walkin9d542d22006-03-14 16:31:37 +00001180WithSyntaxToken:
Lev Walkin57074f12006-03-16 05:11:14 +00001181 TOK_whitespace {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001182 $$ = asn1p_wsyntx_chunk_fromstring($1.buf, 0);
Lev Walkin57074f12006-03-16 05:11:14 +00001183 $$->type = WC_WHITESPACE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001184 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001185 | TOK_Literal {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001186 $$ = asn1p_wsyntx_chunk_fromstring($1, 0);
Lev Walkin9d542d22006-03-14 16:31:37 +00001187 }
Lev Walkind370e9f2006-03-16 10:03:35 +00001188 | PrimitiveFieldReference {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001189 $$ = asn1p_wsyntx_chunk_fromstring($1.name, 0);
Lev Walkind370e9f2006-03-16 10:03:35 +00001190 $$->type = WC_FIELD;
Lev Walkinf15320b2004-06-03 03:38:44 +00001191 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001192 | '[' WithSyntaxList ']' {
1193 $$ = asn1p_wsyntx_chunk_fromsyntax($2);
1194 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001195 ;
1196
Lev Walkinf15320b2004-06-03 03:38:44 +00001197ExtensionAndException:
1198 TOK_ThreeDots {
Lev Walkina9532f42006-09-17 04:52:50 +00001199 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001200 checkmem($$);
1201 $$->Identifier = strdup("...");
1202 checkmem($$->Identifier);
1203 $$->expr_type = A1TC_EXTENSIBLE;
1204 $$->meta_type = AMT_TYPE;
1205 }
1206 | TOK_ThreeDots '!' DefinedValue {
Lev Walkina9532f42006-09-17 04:52:50 +00001207 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001208 checkmem($$);
1209 $$->Identifier = strdup("...");
1210 checkmem($$->Identifier);
1211 $$->value = $3;
1212 $$->expr_type = A1TC_EXTENSIBLE;
1213 $$->meta_type = AMT_TYPE;
1214 }
1215 | TOK_ThreeDots '!' SignedNumber {
Lev Walkina9532f42006-09-17 04:52:50 +00001216 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001217 checkmem($$);
1218 $$->Identifier = strdup("...");
1219 $$->value = $3;
1220 checkmem($$->Identifier);
1221 $$->expr_type = A1TC_EXTENSIBLE;
1222 $$->meta_type = AMT_TYPE;
1223 }
1224 ;
1225
Lev Walkin070a52d2004-08-22 03:19:54 +00001226Type:
Lev Walkinaf120f72004-09-14 02:36:39 +00001227 optTag TypeDeclaration optConstraints {
1228 $$ = $2;
1229 $$->tag = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001230 /*
1231 * Outer constraint for SEQUENCE OF and SET OF applies
1232 * to the inner type.
1233 */
1234 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1235 || $$->expr_type == ASN_CONSTR_SET_OF) {
1236 assert(!TQ_FIRST(&($$->members))->constraints);
Lev Walkinaf120f72004-09-14 02:36:39 +00001237 TQ_FIRST(&($$->members))->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001238 } else {
1239 if($$->constraints) {
1240 assert(!$2);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001241 /* Check this : optConstraints is not used ?! */
1242 asn1p_constraint_free($3);
Lev Walkin070a52d2004-08-22 03:19:54 +00001243 } else {
Lev Walkinaf120f72004-09-14 02:36:39 +00001244 $$->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001245 }
1246 }
Lev Walkinef625402005-09-05 05:17:57 +00001247 }
1248 ;
1249
1250NSTD_IndirectMarker:
1251 {
1252 $$ = asn1p_as_pointer ? EM_INDIRECT : 0;
1253 asn1p_as_pointer = 0;
Lev Walkin070a52d2004-08-22 03:19:54 +00001254 }
1255 ;
1256
1257TypeDeclaration:
Lev Walkinef625402005-09-05 05:17:57 +00001258 NSTD_IndirectMarker TypeDeclarationSet {
Lev Walkin4696c742005-08-22 12:23:54 +00001259 $$ = $2;
Lev Walkinef625402005-09-05 05:17:57 +00001260 $$->marker.flags |= $1;
1261
1262 if(($$->marker.flags & EM_INDIRECT)
1263 && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
1264 fprintf(stderr,
1265 "INFO: Directive <ASN1C:RepresentAsPointer> "
1266 "applied to %s at line %d\n",
1267 ASN_EXPR_TYPE2STR($$->expr_type)
1268 ? ASN_EXPR_TYPE2STR($$->expr_type)
1269 : "member",
1270 $$->_lineno
1271 );
1272 }
Lev Walkin4696c742005-08-22 12:23:54 +00001273 }
Lev Walkinef625402005-09-05 05:17:57 +00001274 ;
Lev Walkin4696c742005-08-22 12:23:54 +00001275
1276TypeDeclarationSet:
Lev Walkin0c0bca62006-03-21 04:48:15 +00001277 DefinedType {
Lev Walkinf15320b2004-06-03 03:38:44 +00001278 $$ = $1;
1279 }
Lev Walkinef625402005-09-05 05:17:57 +00001280 | TOK_CHOICE '{' AlternativeTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001281 $$ = $3;
1282 assert($$->expr_type == A1TC_INVALID);
1283 $$->expr_type = ASN_CONSTR_CHOICE;
1284 $$->meta_type = AMT_TYPE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001285 }
Lev Walkinef625402005-09-05 05:17:57 +00001286 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001287 $$ = $3;
1288 assert($$->expr_type == A1TC_INVALID);
1289 $$->expr_type = ASN_CONSTR_SEQUENCE;
1290 $$->meta_type = AMT_TYPE;
1291 }
Lev Walkinef625402005-09-05 05:17:57 +00001292 | TOK_SET '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001293 $$ = $3;
1294 assert($$->expr_type == A1TC_INVALID);
1295 $$->expr_type = ASN_CONSTR_SET;
1296 $$->meta_type = AMT_TYPE;
1297 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001298 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkina9532f42006-09-17 04:52:50 +00001299 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001300 checkmem($$);
1301 $$->constraints = $2;
1302 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1303 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001304 $6->Identifier = $4;
1305 $6->tag = $5;
1306 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001307 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001308 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkina9532f42006-09-17 04:52:50 +00001309 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001310 checkmem($$);
1311 $$->constraints = $2;
1312 $$->expr_type = ASN_CONSTR_SET_OF;
1313 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001314 $6->Identifier = $4;
1315 $6->tag = $5;
1316 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001317 }
1318 | TOK_ANY {
Lev Walkina9532f42006-09-17 04:52:50 +00001319 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001320 checkmem($$);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001321 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001322 $$->meta_type = AMT_TYPE;
1323 }
1324 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1325 int ret;
Lev Walkina9532f42006-09-17 04:52:50 +00001326 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001327 checkmem($$);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001328 $$->reference = asn1p_ref_new(yylineno, currentModule);
Lev Walkin070a52d2004-08-22 03:19:54 +00001329 ret = asn1p_ref_add_component($$->reference,
1330 $4, RLT_lowercase);
1331 checkmem(ret == 0);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001332 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001333 $$->meta_type = AMT_TYPE;
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001334 free($4);
Lev Walkin070a52d2004-08-22 03:19:54 +00001335 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001336 | TOK_INSTANCE TOK_OF ComplexTypeReference {
Lev Walkina9532f42006-09-17 04:52:50 +00001337 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001338 checkmem($$);
1339 $$->reference = $3;
1340 $$->expr_type = A1TC_INSTANCE;
1341 $$->meta_type = AMT_TYPE;
1342 }
1343 ;
1344
1345/*
1346 * A type name consisting of several components.
1347 * === EXAMPLE ===
1348 * === EOF ===
1349 */
1350ComplexTypeReference:
1351 TOK_typereference {
1352 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001353 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001354 checkmem($$);
1355 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1356 checkmem(ret == 0);
1357 free($1);
1358 }
1359 | TOK_typereference '.' TypeRefName {
1360 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001361 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001362 checkmem($$);
1363 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1364 checkmem(ret == 0);
1365 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1366 checkmem(ret == 0);
1367 free($1);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001368 free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001369 }
Lev Walkin9c974182004-09-15 11:59:51 +00001370 | ObjectClassReference '.' TypeRefName {
1371 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001372 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkin9c974182004-09-15 11:59:51 +00001373 checkmem($$);
1374 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1375 checkmem(ret == 0);
1376 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1377 checkmem(ret == 0);
1378 free($1);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001379 free($3);
Lev Walkin9c974182004-09-15 11:59:51 +00001380 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001381 | TOK_typereference '.' Identifier {
1382 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001383 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001384 checkmem($$);
1385 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1386 checkmem(ret == 0);
1387 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1388 checkmem(ret == 0);
1389 free($1);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001390 free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001391 }
1392 | ObjectClassReference {
1393 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001394 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001395 checkmem($$);
1396 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1397 free($1);
1398 checkmem(ret == 0);
1399 }
1400 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1401 int ret;
1402 $$ = $3;
1403 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1404 free($1);
1405 checkmem(ret == 0);
1406 /*
1407 * Move the last element infront.
1408 */
1409 {
1410 struct asn1p_ref_component_s tmp_comp;
1411 tmp_comp = $$->components[$$->comp_count-1];
1412 memmove(&$$->components[1],
1413 &$$->components[0],
1414 sizeof($$->components[0])
1415 * ($$->comp_count - 1));
1416 $$->components[0] = tmp_comp;
1417 }
1418 }
1419 ;
1420
1421ComplexTypeReferenceAmpList:
1422 ComplexTypeReferenceElement {
1423 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001424 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001425 checkmem($$);
1426 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1427 free($1.name);
1428 checkmem(ret == 0);
1429 }
1430 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1431 int ret;
1432 $$ = $1;
1433 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1434 free($3.name);
1435 checkmem(ret == 0);
1436 }
1437 ;
1438
Lev Walkind370e9f2006-03-16 10:03:35 +00001439ComplexTypeReferenceElement: PrimitiveFieldReference;
Lev Walkinf15320b2004-06-03 03:38:44 +00001440
Lev Walkind370e9f2006-03-16 10:03:35 +00001441PrimitiveFieldReference:
Lev Walkinf15320b2004-06-03 03:38:44 +00001442 /* "&Type1" */
1443 TOK_typefieldreference {
1444 $$.lex_type = RLT_AmpUppercase;
1445 $$.name = $1;
1446 }
1447 /* "&id" */
1448 | TOK_valuefieldreference {
1449 $$.lex_type = RLT_Amplowercase;
1450 $$.name = $1;
1451 }
1452 ;
1453
1454
Lev Walkin9c2285a2006-03-09 08:49:26 +00001455FieldName:
1456 /* "&Type1" */
1457 TOK_typefieldreference {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001458 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001459 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001460 free($1);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001461 }
1462 | FieldName '.' TOK_typefieldreference {
1463 $$ = $$;
1464 asn1p_ref_add_component($$, $3, RLT_AmpUppercase);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001465 free($3);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001466 }
1467 | FieldName '.' TOK_valuefieldreference {
1468 $$ = $$;
1469 asn1p_ref_add_component($$, $3, RLT_Amplowercase);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001470 free($3);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001471 }
1472 ;
1473
1474DefinedObjectClass:
1475 TOK_capitalreference {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001476 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001477 asn1p_ref_add_component($$, $1, RLT_CAPITALS);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001478 free($1);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001479 }
Lev Walkin54868752006-03-09 09:08:49 +00001480/*
Lev Walkin9c2285a2006-03-09 08:49:26 +00001481 | TypeRefName '.' TOK_capitalreference {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001482 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001483 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1484 asn1p_ref_add_component($$, $3, RLT_CAPITALS);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001485 free($1);
1486 free($3);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001487 }
Lev Walkin54868752006-03-09 09:08:49 +00001488*/
Lev Walkin9c2285a2006-03-09 08:49:26 +00001489 ;
1490
1491
Lev Walkinf15320b2004-06-03 03:38:44 +00001492/*
1493 * === EXAMPLE ===
1494 * value INTEGER ::= 1
1495 * === EOF ===
1496 */
Lev Walkinc6ab03c2006-10-21 05:54:49 +00001497ValueAssignment:
1498 Identifier Type TOK_PPEQ Value {
Lev Walkinf15320b2004-06-03 03:38:44 +00001499 $$ = $2;
1500 assert($$->Identifier == NULL);
1501 $$->Identifier = $1;
1502 $$->meta_type = AMT_VALUE;
1503 $$->value = $4;
1504 }
1505 ;
1506
Lev Walkin9c974182004-09-15 11:59:51 +00001507Value:
Lev Walkin0c0bca62006-03-21 04:48:15 +00001508 SimpleValue
1509 | DefinedValue
1510 | Identifier ':' Value {
Lev Walkin9c974182004-09-15 11:59:51 +00001511 $$ = asn1p_value_fromint(0);
1512 checkmem($$);
1513 $$->type = ATV_CHOICE_IDENTIFIER;
1514 $$->value.choice_identifier.identifier = $1;
1515 $$->value.choice_identifier.value = $3;
1516 }
Lev Walkincbad2512005-03-24 16:27:02 +00001517 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Lev Walkinf15320b2004-06-03 03:38:44 +00001518 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1519 checkmem($$);
1520 $$->type = ATV_UNPARSED;
1521 }
Lev Walkin9c974182004-09-15 11:59:51 +00001522 | TOK_NULL {
1523 $$ = asn1p_value_fromint(0);
1524 checkmem($$);
1525 $$->type = ATV_NULL;
1526 }
Lev Walkin0c0bca62006-03-21 04:48:15 +00001527 ;
1528
1529SimpleValue:
1530 TOK_FALSE {
Lev Walkin9c974182004-09-15 11:59:51 +00001531 $$ = asn1p_value_fromint(0);
1532 checkmem($$);
1533 $$->type = ATV_FALSE;
1534 }
1535 | TOK_TRUE {
1536 $$ = asn1p_value_fromint(0);
1537 checkmem($$);
1538 $$->type = ATV_TRUE;
1539 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001540 | TOK_bstring {
1541 $$ = _convert_bitstring2binary($1, 'B');
1542 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001543 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001544 }
1545 | TOK_hstring {
1546 $$ = _convert_bitstring2binary($1, 'H');
1547 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001548 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001549 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001550 | RestrictedCharacterStringValue {
1551 $$ = $$;
Lev Walkinf15320b2004-06-03 03:38:44 +00001552 }
1553 | SignedNumber {
1554 $$ = $1;
1555 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001556 ;
1557
1558DefinedValue:
1559 Identifier {
1560 asn1p_ref_t *ref;
1561 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001562 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001563 checkmem(ref);
1564 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1565 checkmem(ret == 0);
1566 $$ = asn1p_value_fromref(ref, 0);
1567 checkmem($$);
1568 free($1);
1569 }
1570 | TypeRefName '.' Identifier {
1571 asn1p_ref_t *ref;
1572 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001573 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001574 checkmem(ref);
1575 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1576 checkmem(ret == 0);
1577 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1578 checkmem(ret == 0);
1579 $$ = asn1p_value_fromref(ref, 0);
1580 checkmem($$);
1581 free($1);
1582 free($3);
1583 }
1584 ;
1585
Lev Walkin1e448d32005-03-24 14:26:38 +00001586
1587RestrictedCharacterStringValue:
1588 TOK_cstring {
1589 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1590 checkmem($$);
1591 }
Lev Walkind9574ae2005-03-24 16:22:35 +00001592 | TOK_tuple {
1593 $$ = asn1p_value_fromint($1);
1594 checkmem($$);
1595 $$->type = ATV_TUPLE;
1596 }
1597 | TOK_quadruple {
1598 $$ = asn1p_value_fromint($1);
1599 checkmem($$);
1600 $$->type = ATV_QUADRUPLE;
1601 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001602 ;
1603
Lev Walkinf15320b2004-06-03 03:38:44 +00001604Opaque:
1605 TOK_opaque {
Lev Walkin1893ddf2005-03-20 14:28:32 +00001606 $$.len = $1.len + 1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001607 $$.buf = malloc($$.len + 1);
1608 checkmem($$.buf);
1609 $$.buf[0] = '{';
Lev Walkin1893ddf2005-03-20 14:28:32 +00001610 memcpy($$.buf + 1, $1.buf, $1.len);
Lev Walkinf15320b2004-06-03 03:38:44 +00001611 $$.buf[$$.len] = '\0';
1612 free($1.buf);
1613 }
1614 | Opaque TOK_opaque {
1615 int newsize = $1.len + $2.len;
1616 char *p = malloc(newsize + 1);
1617 checkmem(p);
1618 memcpy(p , $1.buf, $1.len);
1619 memcpy(p + $1.len, $2.buf, $2.len);
1620 p[newsize] = '\0';
1621 free($1.buf);
1622 free($2.buf);
1623 $$.buf = p;
1624 $$.len = newsize;
1625 }
1626 ;
1627
1628BasicTypeId:
1629 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1630 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1631 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1632 | BasicTypeId_UniverationCompatible { $$ = $1; }
1633 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1634 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1635 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1636 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1637 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1638 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1639 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1640 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
Lev Walkinc7d939d2005-03-20 11:12:40 +00001641 | BasicString { $$ = $1; }
Lev Walkinf15320b2004-06-03 03:38:44 +00001642 ;
1643
1644/*
1645 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1646 */
1647BasicTypeId_UniverationCompatible:
1648 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1649 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1650 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1651 ;
1652
1653BasicType:
1654 BasicTypeId {
Lev Walkina9532f42006-09-17 04:52:50 +00001655 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001656 checkmem($$);
1657 $$->expr_type = $1;
1658 $$->meta_type = AMT_TYPE;
1659 }
1660 | BasicTypeId_UniverationCompatible UniverationDefinition {
1661 if($2) {
1662 $$ = $2;
1663 } else {
Lev Walkina9532f42006-09-17 04:52:50 +00001664 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001665 checkmem($$);
1666 }
1667 $$->expr_type = $1;
1668 $$->meta_type = AMT_TYPE;
1669 }
1670 ;
1671
1672BasicString:
1673 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1674 | TOK_GeneralString {
1675 $$ = ASN_STRING_GeneralString;
Lev Walkin9c974182004-09-15 11:59:51 +00001676 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001677 }
1678 | TOK_GraphicString {
1679 $$ = ASN_STRING_GraphicString;
Lev Walkin9c974182004-09-15 11:59:51 +00001680 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001681 }
1682 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1683 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1684 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1685 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1686 | TOK_T61String {
1687 $$ = ASN_STRING_T61String;
Lev Walkin9c974182004-09-15 11:59:51 +00001688 fprintf(stderr, "WARNING: T61String is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001689 }
1690 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1691 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1692 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1693 | TOK_VideotexString {
1694 $$ = ASN_STRING_VideotexString;
Lev Walkin9c974182004-09-15 11:59:51 +00001695 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001696 }
1697 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1698 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1699 ;
1700
Lev Walkind2ea1de2004-08-20 13:25:29 +00001701
Lev Walkinf15320b2004-06-03 03:38:44 +00001702/*
1703 * Data type constraints.
1704 */
Lev Walkinf1727152006-09-21 01:50:37 +00001705UnionMark: '|' | TOK_UNION;
1706IntersectionMark: '^' | TOK_INTERSECTION;
Lev Walkinf15320b2004-06-03 03:38:44 +00001707
Lev Walkinf59d0752004-08-18 04:59:12 +00001708optConstraints:
1709 { $$ = 0; }
Lev Walkina9532f42006-09-17 04:52:50 +00001710 | Constraint {
Lev Walkind2ea1de2004-08-20 13:25:29 +00001711 $$ = $1;
1712 }
1713 ;
1714
Lev Walkina9532f42006-09-17 04:52:50 +00001715Constraint:
1716 SubtypeConstraint
Lev Walkina9532f42006-09-17 04:52:50 +00001717 ;
1718
1719SubtypeConstraint:
Lev Walkind2ea1de2004-08-20 13:25:29 +00001720 SetOfConstraints {
Lev Walkin2c14a692005-08-12 10:08:45 +00001721 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
Lev Walkinf59d0752004-08-18 04:59:12 +00001722 }
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001723 | TOK_SIZE '(' ConstraintSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001724 /*
1725 * This is a special case, for compatibility purposes.
Lev Walkinf59d0752004-08-18 04:59:12 +00001726 * It goes without parentheses.
Lev Walkinf15320b2004-06-03 03:38:44 +00001727 */
Lev Walkin2c14a692005-08-12 10:08:45 +00001728 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001729 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001730 ;
1731
Lev Walkinf59d0752004-08-18 04:59:12 +00001732SetOfConstraints:
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001733 '(' ConstraintSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001734 $$ = $2;
1735 }
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001736 | SetOfConstraints '(' ConstraintSpecs ')' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001737 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
Lev Walkinf59d0752004-08-18 04:59:12 +00001738 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001739 ;
1740
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001741ConstraintSpecs:
1742 ElementSetSpecs {
1743 $$ = $1;
1744 }
1745 | GeneralConstraint {
1746 $$ = $1;
1747 }
1748 ;
1749
Lev Walkinf59d0752004-08-18 04:59:12 +00001750ElementSetSpecs:
Lev Walkin5045dfa2006-03-21 09:41:28 +00001751 TOK_ThreeDots {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001752 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkin5045dfa2006-03-21 09:41:28 +00001753 $$->type = ACT_EL_EXT;
1754 }
1755 | ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001756 $$ = $1;
1757 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001758 | ElementSetSpec ',' TOK_ThreeDots {
Lev Walkinf15320b2004-06-03 03:38:44 +00001759 asn1p_constraint_t *ct;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001760 ct = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001761 ct->type = ACT_EL_EXT;
Lev Walkin2c14a692005-08-12 10:08:45 +00001762 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00001763 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001764 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001765 asn1p_constraint_t *ct;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001766 ct = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001767 ct->type = ACT_EL_EXT;
Lev Walkin2c14a692005-08-12 10:08:45 +00001768 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinb4fcdd22004-08-13 12:35:09 +00001769 ct = $$;
Lev Walkin2c14a692005-08-12 10:08:45 +00001770 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
Lev Walkinf15320b2004-06-03 03:38:44 +00001771 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001772 ;
1773
Lev Walkinf59d0752004-08-18 04:59:12 +00001774ElementSetSpec:
Lev Walkinf1727152006-09-21 01:50:37 +00001775 Unions
Lev Walkin1e448d32005-03-24 14:26:38 +00001776 | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001777 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
Lev Walkin1e448d32005-03-24 14:26:38 +00001778 }
Lev Walkinf1727152006-09-21 01:50:37 +00001779 ;
1780
1781Unions:
1782 Intersections
1783 | Unions UnionMark Intersections {
Lev Walkin2c14a692005-08-12 10:08:45 +00001784 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001785 }
Lev Walkinf1727152006-09-21 01:50:37 +00001786 ;
1787
1788Intersections:
1789 IntersectionElements
1790 | Intersections IntersectionMark IntersectionElements {
Lev Walkin2c14a692005-08-12 10:08:45 +00001791 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001792 }
Lev Walkinf1727152006-09-21 01:50:37 +00001793 ;
1794
1795
1796IntersectionElements:
1797 ConstraintSubtypeElement
1798 | ConstraintSubtypeElement TOK_EXCEPT ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001799 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001800 }
1801 ;
1802
1803ConstraintSubtypeElement:
Lev Walkinf59d0752004-08-18 04:59:12 +00001804 ConstraintSpec '(' ElementSetSpecs ')' {
1805 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001806 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf59d0752004-08-18 04:59:12 +00001807 checkmem($$);
1808 $$->type = $1;
1809 ret = asn1p_constraint_insert($$, $3);
1810 checkmem(ret == 0);
1811 }
1812 | '(' ElementSetSpecs ')' {
1813 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001814 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf59d0752004-08-18 04:59:12 +00001815 checkmem($$);
1816 $$->type = ACT_CA_SET;
1817 ret = asn1p_constraint_insert($$, $2);
1818 checkmem(ret == 0);
1819 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001820 | SingleValue {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001821 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001822 checkmem($$);
1823 $$->type = ACT_EL_VALUE;
1824 $$->value = $1;
1825 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001826 | ContainedSubtype {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001827 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinff7dd142005-03-20 12:58:00 +00001828 checkmem($$);
1829 $$->type = ACT_EL_TYPE;
1830 $$->containedSubtype = $1;
1831 }
1832 | SingleValue ConstraintRangeSpec SingleValue {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001833 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001834 checkmem($$);
1835 $$->type = $2;
1836 $$->range_start = $1;
1837 $$->range_stop = $3;
1838 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001839 | TOK_MIN ConstraintRangeSpec SingleValue {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001840 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001841 checkmem($$);
Lev Walkinf59d0752004-08-18 04:59:12 +00001842 $$->type = $2;
1843 $$->range_start = asn1p_value_fromint(-123);
1844 $$->range_stop = $3;
1845 $$->range_start->type = ATV_MIN;
1846 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001847 | SingleValue ConstraintRangeSpec TOK_MAX {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001848 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf59d0752004-08-18 04:59:12 +00001849 checkmem($$);
1850 $$->type = $2;
1851 $$->range_start = $1;
1852 $$->range_stop = asn1p_value_fromint(321);
1853 $$->range_stop->type = ATV_MAX;
1854 }
1855 | TOK_MIN ConstraintRangeSpec TOK_MAX {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001856 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf59d0752004-08-18 04:59:12 +00001857 checkmem($$);
1858 $$->type = $2;
1859 $$->range_start = asn1p_value_fromint(-123);
1860 $$->range_stop = asn1p_value_fromint(321);
1861 $$->range_start->type = ATV_MIN;
1862 $$->range_stop->type = ATV_MAX;
Lev Walkinf15320b2004-06-03 03:38:44 +00001863 }
Lev Walkine596bf02005-03-28 15:01:27 +00001864 | InnerTypeConstraint {
Lev Walkinf15320b2004-06-03 03:38:44 +00001865 $$ = $1;
1866 }
Lev Walkin5c541f12006-10-18 18:40:14 +00001867 | PatternConstraint {
1868 $$ = $1;
1869 }
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001870 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1871 $$ = asn1p_constraint_new(yylineno, currentModule);
1872 checkmem($$);
1873 $$->type = ACT_EL_VALUE;
1874 $$->value = asn1p_value_frombuf($3.buf, $3.len, 0);
1875 $$->value->type = ATV_UNPARSED;
1876 }
Lev Walkin5c541f12006-10-18 18:40:14 +00001877 ;
1878
1879PatternConstraint:
1880 TOK_PATTERN TOK_cstring {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001881 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkin5c541f12006-10-18 18:40:14 +00001882 $$->type = ACT_CT_PATTERN;
1883 $$->value = asn1p_value_frombuf($2.buf, $2.len, 0);
1884 }
1885 | TOK_PATTERN Identifier {
1886 asn1p_ref_t *ref;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001887 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkin5c541f12006-10-18 18:40:14 +00001888 $$->type = ACT_CT_PATTERN;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001889 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkin5c541f12006-10-18 18:40:14 +00001890 asn1p_ref_add_component(ref, $2, RLT_lowercase);
1891 $$->value = asn1p_value_fromref(ref, 0);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001892 free($2);
Lev Walkin5c541f12006-10-18 18:40:14 +00001893 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001894 ;
1895
1896ConstraintSpec:
1897 TOK_SIZE {
1898 $$ = ACT_CT_SIZE;
1899 }
1900 | TOK_FROM {
1901 $$ = ACT_CT_FROM;
1902 }
1903 ;
1904
Lev Walkinff7dd142005-03-20 12:58:00 +00001905SingleValue:
Lev Walkinc8092cb2005-02-18 16:34:21 +00001906 TOK_FALSE {
1907 $$ = asn1p_value_fromint(0);
1908 checkmem($$);
1909 $$->type = ATV_FALSE;
1910 }
1911 | TOK_TRUE {
1912 $$ = asn1p_value_fromint(1);
1913 checkmem($$);
1914 $$->type = ATV_TRUE;
1915 }
Lev Walkinadf863f2006-09-05 16:18:34 +00001916 | RealValue
1917 | RestrictedCharacterStringValue
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001918 | BitStringValue
Lev Walkinf15320b2004-06-03 03:38:44 +00001919 | Identifier {
1920 asn1p_ref_t *ref;
1921 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001922 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001923 checkmem(ref);
1924 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1925 checkmem(ret == 0);
1926 $$ = asn1p_value_fromref(ref, 0);
1927 checkmem($$);
1928 free($1);
1929 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001930 ;
1931
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001932BitStringValue:
1933 TOK_bstring {
1934 $$ = _convert_bitstring2binary($1, 'B');
1935 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001936 free($1);
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001937 }
1938 | TOK_hstring {
1939 $$ = _convert_bitstring2binary($1, 'H');
1940 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001941 free($1);
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001942 }
1943 ;
1944
Lev Walkinff7dd142005-03-20 12:58:00 +00001945ContainedSubtype:
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001946 ComplexTypeReference {
1947 $$ = asn1p_value_fromref($1, 0);
1948 checkmem($$);
1949 }
1950/*
Lev Walkinff7dd142005-03-20 12:58:00 +00001951 TypeRefName {
Lev Walkinc8092cb2005-02-18 16:34:21 +00001952 asn1p_ref_t *ref;
1953 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001954 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkinc8092cb2005-02-18 16:34:21 +00001955 checkmem(ref);
1956 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1957 checkmem(ret == 0);
1958 $$ = asn1p_value_fromref(ref, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001959 checkmem($$);
Lev Walkinc8092cb2005-02-18 16:34:21 +00001960 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001961 }
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001962*/
Lev Walkinf15320b2004-06-03 03:38:44 +00001963 ;
1964
Lev Walkine596bf02005-03-28 15:01:27 +00001965InnerTypeConstraint:
1966 TOK_WITH TOK_COMPONENT SetOfConstraints {
Lev Walkin2c14a692005-08-12 10:08:45 +00001967 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
Lev Walkine596bf02005-03-28 15:01:27 +00001968 }
1969 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001970 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001971 }
1972 ;
1973
1974WithComponentsList:
1975 WithComponentsElement {
1976 $$ = $1;
1977 }
1978 | WithComponentsList ',' WithComponentsElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001979 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001980 }
1981 ;
1982
1983WithComponentsElement:
1984 TOK_ThreeDots {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001985 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001986 checkmem($$);
1987 $$->type = ACT_EL_EXT;
Lev Walkin418298d2006-07-13 08:24:20 +00001988 $$->value = asn1p_value_frombuf("...", 3, 1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001989 }
1990 | Identifier optConstraints optPresenceConstraint {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001991 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001992 checkmem($$);
1993 $$->type = ACT_EL_VALUE;
1994 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1995 $$->presence = $3;
Lev Walkine596bf02005-03-28 15:01:27 +00001996 if($2) asn1p_constraint_insert($$, $2);
Lev Walkinf15320b2004-06-03 03:38:44 +00001997 }
1998 ;
1999
2000/*
2001 * presence constraint for WithComponents
2002 */
2003optPresenceConstraint:
2004 { $$ = ACPRES_DEFAULT; }
2005 | PresenceConstraint { $$ = $1; }
2006 ;
2007
2008PresenceConstraint:
2009 TOK_PRESENT {
2010 $$ = ACPRES_PRESENT;
2011 }
2012 | TOK_ABSENT {
2013 $$ = ACPRES_ABSENT;
2014 }
2015 | TOK_OPTIONAL {
2016 $$ = ACPRES_OPTIONAL;
2017 }
2018 ;
2019
Lev Walkina9532f42006-09-17 04:52:50 +00002020
2021/* X.682 */
2022GeneralConstraint:
2023 UserDefinedConstraint
2024 | TableConstraint
2025 | ContentsConstraint
2026 ;
2027
2028UserDefinedConstraint:
2029 TOK_CONSTRAINED TOK_BY '{'
2030 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002031 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkina9532f42006-09-17 04:52:50 +00002032 checkmem($$);
2033 $$->type = ACT_CT_CTDBY;
2034 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
2035 checkmem($$->value);
2036 $$->value->type = ATV_UNPARSED;
2037 }
2038 ;
2039
2040ContentsConstraint:
2041 TOK_CONTAINING Type {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002042 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkina9532f42006-09-17 04:52:50 +00002043 $$->type = ACT_CT_CTNG;
2044 $$->value = asn1p_value_fromtype($2);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08002045 asn1p_expr_free($2);
Lev Walkina9532f42006-09-17 04:52:50 +00002046 }
2047 ;
2048
2049ConstraintRangeSpec:
2050 TOK_TwoDots { $$ = ACT_EL_RANGE; }
2051 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
2052 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
2053 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
2054 ;
Lev Walkinf15320b2004-06-03 03:38:44 +00002055TableConstraint:
2056 SimpleTableConstraint {
2057 $$ = $1;
2058 }
2059 | ComponentRelationConstraint {
2060 $$ = $1;
2061 }
2062 ;
2063
2064/*
2065 * "{ExtensionSet}"
2066 */
2067SimpleTableConstraint:
2068 '{' TypeRefName '}' {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002069 asn1p_ref_t *ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002070 asn1p_constraint_t *ct;
2071 int ret;
2072 ret = asn1p_ref_add_component(ref, $2, 0);
2073 checkmem(ret == 0);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002074 ct = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002075 checkmem($$);
2076 ct->type = ACT_EL_VALUE;
2077 ct->value = asn1p_value_fromref(ref, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00002078 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08002079 free($2);
Lev Walkinf15320b2004-06-03 03:38:44 +00002080 }
2081 ;
2082
2083ComponentRelationConstraint:
2084 SimpleTableConstraint '{' AtNotationList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00002085 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002086 }
2087 ;
2088
2089AtNotationList:
2090 AtNotationElement {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002091 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002092 checkmem($$);
2093 $$->type = ACT_EL_VALUE;
2094 $$->value = asn1p_value_fromref($1, 0);
2095 }
2096 | AtNotationList ',' AtNotationElement {
2097 asn1p_constraint_t *ct;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002098 ct = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002099 checkmem(ct);
2100 ct->type = ACT_EL_VALUE;
2101 ct->value = asn1p_value_fromref($3, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00002102 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00002103 }
2104 ;
2105
2106/*
2107 * @blah
2108 */
2109AtNotationElement:
2110 '@' ComponentIdList {
2111 char *p = malloc(strlen($2) + 2);
2112 int ret;
2113 *p = '@';
2114 strcpy(p + 1, $2);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002115 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002116 ret = asn1p_ref_add_component($$, p, 0);
2117 checkmem(ret == 0);
2118 free(p);
2119 free($2);
2120 }
2121 | '@' '.' ComponentIdList {
2122 char *p = malloc(strlen($3) + 3);
2123 int ret;
2124 p[0] = '@';
2125 p[1] = '.';
2126 strcpy(p + 2, $3);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002127 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002128 ret = asn1p_ref_add_component($$, p, 0);
2129 checkmem(ret == 0);
2130 free(p);
2131 free($3);
2132 }
2133 ;
2134
2135/* identifier "." ... */
2136ComponentIdList:
2137 Identifier {
2138 $$ = $1;
2139 }
2140 | ComponentIdList '.' Identifier {
2141 int l1 = strlen($1);
2142 int l3 = strlen($3);
2143 $$ = malloc(l1 + 1 + l3 + 1);
2144 memcpy($$, $1, l1);
2145 $$[l1] = '.';
2146 memcpy($$ + l1 + 1, $3, l3);
2147 $$[l1 + 1 + l3] = '\0';
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08002148 free($1);
2149 free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002150 }
2151 ;
2152
2153
2154
2155/*
2156 * MARKERS
2157 */
2158
2159optMarker:
Lev Walkin9c974182004-09-15 11:59:51 +00002160 {
2161 $$.flags = EM_NOMARK;
2162 $$.default_value = 0;
2163 }
Lev Walkinf15320b2004-06-03 03:38:44 +00002164 | Marker { $$ = $1; }
2165 ;
2166
2167Marker:
2168 TOK_OPTIONAL {
Lev Walkin70853052005-11-26 11:21:55 +00002169 $$.flags = EM_OPTIONAL | EM_INDIRECT;
Lev Walkin9c974182004-09-15 11:59:51 +00002170 $$.default_value = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +00002171 }
Lev Walkin9c974182004-09-15 11:59:51 +00002172 | TOK_DEFAULT Value {
2173 $$.flags = EM_DEFAULT;
2174 $$.default_value = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00002175 }
2176 ;
2177
2178/*
2179 * Universal enumeration definition to use in INTEGER and ENUMERATED.
2180 * === EXAMPLE ===
2181 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
2182 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
2183 * === EOF ===
2184 */
2185/*
2186optUniverationDefinition:
2187 { $$ = 0; }
2188 | UniverationDefinition {
2189 $$ = $1;
2190 }
2191 ;
2192*/
2193
2194UniverationDefinition:
2195 '{' '}' {
Lev Walkina9532f42006-09-17 04:52:50 +00002196 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002197 checkmem($$);
2198 }
2199 | '{' UniverationList '}' {
2200 $$ = $2;
2201 }
2202 ;
2203
2204UniverationList:
2205 UniverationElement {
Lev Walkina9532f42006-09-17 04:52:50 +00002206 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002207 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00002208 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00002209 }
2210 | UniverationList ',' UniverationElement {
2211 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00002212 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002213 }
2214 ;
2215
2216UniverationElement:
2217 Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +00002218 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002219 checkmem($$);
2220 $$->expr_type = A1TC_UNIVERVAL;
2221 $$->meta_type = AMT_VALUE;
2222 $$->Identifier = $1;
2223 }
2224 | Identifier '(' SignedNumber ')' {
Lev Walkina9532f42006-09-17 04:52:50 +00002225 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002226 checkmem($$);
2227 $$->expr_type = A1TC_UNIVERVAL;
2228 $$->meta_type = AMT_VALUE;
2229 $$->Identifier = $1;
2230 $$->value = $3;
2231 }
2232 | Identifier '(' DefinedValue ')' {
Lev Walkina9532f42006-09-17 04:52:50 +00002233 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002234 checkmem($$);
2235 $$->expr_type = A1TC_UNIVERVAL;
2236 $$->meta_type = AMT_VALUE;
2237 $$->Identifier = $1;
2238 $$->value = $3;
2239 }
2240 | SignedNumber {
Lev Walkina9532f42006-09-17 04:52:50 +00002241 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002242 checkmem($$);
2243 $$->expr_type = A1TC_UNIVERVAL;
2244 $$->meta_type = AMT_VALUE;
2245 $$->value = $1;
2246 }
2247 | TOK_ThreeDots {
Lev Walkina9532f42006-09-17 04:52:50 +00002248 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002249 checkmem($$);
2250 $$->Identifier = strdup("...");
2251 checkmem($$->Identifier);
2252 $$->expr_type = A1TC_EXTENSIBLE;
2253 $$->meta_type = AMT_VALUE;
2254 }
2255 ;
2256
2257SignedNumber:
2258 TOK_number {
2259 $$ = asn1p_value_fromint($1);
2260 checkmem($$);
2261 }
2262 | TOK_number_negative {
2263 $$ = asn1p_value_fromint($1);
2264 checkmem($$);
2265 }
2266 ;
2267
Lev Walkinadf863f2006-09-05 16:18:34 +00002268RealValue:
2269 SignedNumber
2270 | TOK_realnumber {
2271 $$ = asn1p_value_fromdouble($1);
2272 checkmem($$);
2273 }
2274 ;
2275
Lev Walkinf15320b2004-06-03 03:38:44 +00002276/*
2277 * SEQUENCE definition.
2278 * === EXAMPLE ===
2279 * Struct1 ::= SEQUENCE {
2280 * memb1 Struct2,
2281 * memb2 SEQUENCE OF {
2282 * memb2-1 Struct 3
2283 * }
2284 * }
2285 * === EOF ===
2286 */
2287
2288
2289
2290/*
2291 * SET definition.
2292 * === EXAMPLE ===
2293 * Person ::= SET {
2294 * name [0] PrintableString (SIZE(1..20)),
2295 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2296 * }
2297 * === EOF ===
2298 */
2299
2300optTag:
2301 { memset(&$$, 0, sizeof($$)); }
2302 | Tag { $$ = $1; }
2303 ;
2304
2305Tag:
Lev Walkinc603f102005-01-23 09:51:44 +00002306 TagTypeValue TagPlicit {
Lev Walkinf15320b2004-06-03 03:38:44 +00002307 $$ = $1;
Lev Walkinc603f102005-01-23 09:51:44 +00002308 $$.tag_mode = $2.tag_mode;
Lev Walkinf15320b2004-06-03 03:38:44 +00002309 }
Lev Walkinc603f102005-01-23 09:51:44 +00002310 ;
2311
2312TagTypeValue:
2313 '[' TagClass TOK_number ']' {
2314 $$ = $2;
2315 $$.tag_value = $3;
2316 };
2317
2318TagClass:
2319 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2320 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2321 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2322 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2323 ;
2324
2325TagPlicit:
2326 { $$.tag_mode = TM_DEFAULT; }
2327 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2328 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
Lev Walkinf15320b2004-06-03 03:38:44 +00002329 ;
2330
2331TypeRefName:
2332 TOK_typereference {
2333 checkmem($1);
2334 $$ = $1;
2335 }
Lev Walkinf59d0752004-08-18 04:59:12 +00002336 | TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002337 checkmem($1);
2338 $$ = $1;
2339 }
2340 ;
2341
Lev Walkinf59d0752004-08-18 04:59:12 +00002342
Lev Walkinf15320b2004-06-03 03:38:44 +00002343ObjectClassReference:
Lev Walkinf59d0752004-08-18 04:59:12 +00002344 TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002345 checkmem($1);
2346 $$ = $1;
2347 }
2348 ;
2349
Lev Walkin83cac2f2004-09-22 16:03:36 +00002350optIdentifier:
2351 { $$ = 0; }
2352 | Identifier {
2353 $$ = $1;
2354 }
Lev Walkin8f294e02005-06-06 08:28:58 +00002355 ;
Lev Walkin83cac2f2004-09-22 16:03:36 +00002356
Lev Walkinf15320b2004-06-03 03:38:44 +00002357Identifier:
2358 TOK_identifier {
2359 checkmem($1);
2360 $$ = $1;
2361 }
2362 ;
2363
Lev Walkinf15320b2004-06-03 03:38:44 +00002364%%
2365
2366
2367/*
2368 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2369 */
2370static asn1p_value_t *
2371_convert_bitstring2binary(char *str, int base) {
2372 asn1p_value_t *val;
2373 int slen;
2374 int memlen;
2375 int baselen;
2376 int bits;
2377 uint8_t *binary_vector;
2378 uint8_t *bv_ptr;
2379 uint8_t cur_val;
2380
2381 assert(str);
2382 assert(str[0] == '\'');
2383
2384 switch(base) {
2385 case 'B':
2386 baselen = 1;
2387 break;
2388 case 'H':
2389 baselen = 4;
2390 break;
2391 default:
2392 assert(base == 'B' || base == 'H');
2393 errno = EINVAL;
2394 return NULL;
2395 }
2396
2397 slen = strlen(str);
2398 assert(str[slen - 1] == base);
2399 assert(str[slen - 2] == '\'');
2400
2401 memlen = slen / (8 / baselen); /* Conservative estimate */
2402
2403 bv_ptr = binary_vector = malloc(memlen + 1);
2404 if(bv_ptr == NULL)
2405 /* ENOMEM */
2406 return NULL;
2407
2408 cur_val = 0;
2409 bits = 0;
2410 while(*(++str) != '\'') {
2411 switch(baselen) {
2412 case 1:
2413 switch(*str) {
2414 case '1':
2415 cur_val |= 1 << (7 - (bits % 8));
2416 case '0':
2417 break;
2418 default:
2419 assert(!"_y UNREACH1");
2420 case ' ': case '\r': case '\n':
2421 continue;
2422 }
2423 break;
2424 case 4:
2425 switch(*str) {
2426 case '0': case '1': case '2': case '3': case '4':
2427 case '5': case '6': case '7': case '8': case '9':
2428 cur_val |= (*str - '0') << (4 - (bits % 8));
2429 break;
2430 case 'A': case 'B': case 'C':
2431 case 'D': case 'E': case 'F':
2432 cur_val |= ((*str - 'A') + 10)
2433 << (4 - (bits % 8));
2434 break;
2435 default:
2436 assert(!"_y UNREACH2");
2437 case ' ': case '\r': case '\n':
2438 continue;
2439 }
2440 break;
2441 }
2442
2443 bits += baselen;
2444 if((bits % 8) == 0) {
2445 *bv_ptr++ = cur_val;
2446 cur_val = 0;
2447 }
2448 }
2449
2450 *bv_ptr = cur_val;
2451 assert((bv_ptr - binary_vector) <= memlen);
2452
2453 val = asn1p_value_frombits(binary_vector, bits, 0);
2454 if(val == NULL) {
2455 free(binary_vector);
2456 }
2457
2458 return val;
2459}
2460
Lev Walkin2e9bd5c2005-08-13 09:07:11 +00002461/*
2462 * For unnamed types (used in old X.208 compliant modules)
2463 * generate some sort of interim names, to not to force human being to fix
2464 * the specification's compliance to modern ASN.1 standards.
2465 */
2466static void
2467_fixup_anonymous_identifier(asn1p_expr_t *expr) {
2468 char *p;
2469 assert(expr->Identifier == 0);
2470
2471 /*
2472 * Try to figure out the type name
2473 * without going too much into details
2474 */
2475 expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type);
2476 if(expr->reference && expr->reference->comp_count > 0)
2477 expr->Identifier = expr->reference->components[0].name;
2478
2479 fprintf(stderr,
2480 "WARNING: Line %d: expected lower-case member identifier, "
2481 "found an unnamed %s.\n"
2482 "WARNING: Obsolete X.208 syntax detected, "
2483 "please give the member a name.\n",
2484 yylineno, expr->Identifier ? expr->Identifier : "type");
2485
2486 if(!expr->Identifier)
2487 expr->Identifier = "unnamed";
2488 expr->Identifier = strdup(expr->Identifier);
2489 assert(expr->Identifier);
2490 /* Make a lowercase identifier from the type name */
2491 for(p = expr->Identifier; *p; p++) {
2492 switch(*p) {
2493 case 'A' ... 'Z': *p += 32; break;
2494 case ' ': *p = '_'; break;
2495 case '-': *p = '_'; break;
2496 }
2497 }
2498 fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". "
2499 "Name clash may occur later.\n",
2500 expr->Identifier);
2501}
2502
Lev Walkinf15320b2004-06-03 03:38:44 +00002503int
2504yyerror(const char *msg) {
Lev Walkin9d542d22006-03-14 16:31:37 +00002505 extern char *asn1p_text;
Lev Walkinf15320b2004-06-03 03:38:44 +00002506 fprintf(stderr,
2507 "ASN.1 grammar parse error "
2508 "near line %d (token \"%s\"): %s\n",
Lev Walkinceb20e72004-09-05 10:40:41 +00002509 yylineno, asn1p_text, msg);
Lev Walkinf15320b2004-06-03 03:38:44 +00002510 return -1;
2511}
2512