blob: 8e26eb038b5f19016524139dc53e81ad71888ab2 [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 ===
583 */
Lev Walkin557f27d2006-03-21 07:46:48 +0000584 | ValueSetTypeAssignment {
Lev Walkinf15320b2004-06-03 03:38:44 +0000585 $$ = asn1p_module_new();
586 checkmem($$);
587 assert($1->expr_type != A1TC_INVALID);
588 assert($1->meta_type != AMT_INVALID);
589 TQ_ADD(&($$->members), $1, next);
590 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000591 | TOK_ENCODING_CONTROL TOK_capitalreference
592 { asn1p_lexer_hack_push_encoding_control(); }
593 {
594 fprintf(stderr,
595 "WARNING: ENCODING-CONTROL %s "
596 "specification at line %d ignored\n",
597 $2, yylineno);
598 free($2);
599 $$ = 0;
600 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000601
602 /*
603 * Erroneous attemps
604 */
605 | BasicString {
606 return yyerror(
Lev Walkin70853052005-11-26 11:21:55 +0000607 "Attempt to redefine a standard basic string type, "
608 "please comment out or remove this type redefinition.");
Lev Walkinf15320b2004-06-03 03:38:44 +0000609 }
610 ;
611
612/*
613 * === EXAMPLE ===
614 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
615 * === EOF ===
616 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000617optImports:
618 { $$ = 0; }
619 | ImportsDefinition;
620
Lev Walkinf15320b2004-06-03 03:38:44 +0000621ImportsDefinition:
Lev Walkin4a4543f2006-10-13 12:37:39 +0000622 TOK_IMPORTS optImportsBundleSet ';' {
Lev Walkin1ed22092005-08-12 10:06:17 +0000623 if(!saved_aid && 0)
624 return yyerror("Unterminated IMPORTS FROM, "
625 "expected semicolon ';'");
626 saved_aid = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +0000627 $$ = $2;
628 }
629 /*
630 * Some error cases.
631 */
632 | TOK_IMPORTS TOK_FROM /* ... */ {
633 return yyerror("Empty IMPORTS list");
634 }
635 ;
636
Lev Walkin4a4543f2006-10-13 12:37:39 +0000637optImportsBundleSet:
638 { $$ = asn1p_module_new(); }
639 | ImportsBundleSet;
640
Lev Walkinf15320b2004-06-03 03:38:44 +0000641ImportsBundleSet:
642 ImportsBundle {
643 $$ = asn1p_module_new();
644 checkmem($$);
645 TQ_ADD(&($$->imports), $1, xp_next);
646 }
647 | ImportsBundleSet ImportsBundle {
648 $$ = $1;
649 TQ_ADD(&($$->imports), $2, xp_next);
650 }
651 ;
652
Lev Walkin1ed22092005-08-12 10:06:17 +0000653AssignedIdentifier:
654 { memset(&$$, 0, sizeof($$)); }
655 | ObjectIdentifier { $$.oid = $1; };
656 /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
657
Lev Walkinf15320b2004-06-03 03:38:44 +0000658ImportsBundle:
Lev Walkin1ed22092005-08-12 10:06:17 +0000659 ImportsList TOK_FROM TypeRefName AssignedIdentifier {
Lev Walkinf15320b2004-06-03 03:38:44 +0000660 $$ = $1;
Lev Walkin1ed22092005-08-12 10:06:17 +0000661 $$->fromModuleName = $3;
662 $$->identifier = $4;
663 /* This stupid thing is used for look-back hack. */
664 saved_aid = $$->identifier.oid ? 0 : &($$->identifier);
Lev Walkinf15320b2004-06-03 03:38:44 +0000665 checkmem($$);
666 }
667 ;
668
669ImportsList:
670 ImportsElement {
671 $$ = asn1p_xports_new();
672 checkmem($$);
673 TQ_ADD(&($$->members), $1, next);
674 }
675 | ImportsList ',' ImportsElement {
676 $$ = $1;
677 TQ_ADD(&($$->members), $3, next);
678 }
679 ;
680
681ImportsElement:
682 TypeRefName {
Lev Walkina9532f42006-09-17 04:52:50 +0000683 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000684 checkmem($$);
685 $$->Identifier = $1;
686 $$->expr_type = A1TC_REFERENCE;
687 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000688 | TypeRefName '{' '}' { /* Completely equivalent to above */
Lev Walkina9532f42006-09-17 04:52:50 +0000689 $$ = NEW_EXPR();
Lev Walkin144db9b2004-10-12 23:26:53 +0000690 checkmem($$);
691 $$->Identifier = $1;
692 $$->expr_type = A1TC_REFERENCE;
693 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000694 | Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +0000695 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000696 checkmem($$);
697 $$->Identifier = $1;
698 $$->expr_type = A1TC_REFERENCE;
699 }
700 ;
701
Lev Walkin866bd7f2006-09-14 10:35:20 +0000702
703optExports:
704 { $$ = 0; }
705 | ExportsDefinition {
706 $$ = asn1p_module_new();
707 checkmem($$);
708 if($1) {
709 TQ_ADD(&($$->exports), $1, xp_next);
710 } else {
711 /* "EXPORTS ALL;" */
712 }
713 }
714 ;
715
Lev Walkinf15320b2004-06-03 03:38:44 +0000716ExportsDefinition:
717 TOK_EXPORTS ExportsBody ';' {
718 $$ = $2;
719 }
720 | TOK_EXPORTS TOK_ALL ';' {
721 $$ = 0;
722 }
723 | TOK_EXPORTS ';' {
724 /* Empty EXPORTS clause effectively prohibits export. */
725 $$ = asn1p_xports_new();
726 checkmem($$);
727 }
728 ;
729
730ExportsBody:
731 ExportsElement {
732 $$ = asn1p_xports_new();
733 assert($$);
734 TQ_ADD(&($$->members), $1, next);
735 }
736 | ExportsBody ',' ExportsElement {
737 $$ = $1;
738 TQ_ADD(&($$->members), $3, next);
739 }
740 ;
741
742ExportsElement:
743 TypeRefName {
Lev Walkina9532f42006-09-17 04:52:50 +0000744 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000745 checkmem($$);
746 $$->Identifier = $1;
747 $$->expr_type = A1TC_EXPORTVAR;
748 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000749 | TypeRefName '{' '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000750 $$ = NEW_EXPR();
Lev Walkin144db9b2004-10-12 23:26:53 +0000751 checkmem($$);
752 $$->Identifier = $1;
753 $$->expr_type = A1TC_EXPORTVAR;
754 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000755 | Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +0000756 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000757 checkmem($$);
758 $$->Identifier = $1;
759 $$->expr_type = A1TC_EXPORTVAR;
760 }
761 ;
762
763
Lev Walkin418298d2006-07-13 08:24:20 +0000764ValueSet: '{' ElementSetSpecs '}' { $$ = $2; };
Lev Walkin557f27d2006-03-21 07:46:48 +0000765
766ValueSetTypeAssignment:
767 TypeRefName DefinedType TOK_PPEQ ValueSet {
Lev Walkinf15320b2004-06-03 03:38:44 +0000768 $$ = $2;
769 assert($$->Identifier == 0);
770 $$->Identifier = $1;
771 $$->meta_type = AMT_VALUESET;
Lev Walkin557f27d2006-03-21 07:46:48 +0000772 $$->constraints = $4;
Lev Walkinf15320b2004-06-03 03:38:44 +0000773 }
774 ;
775
Lev Walkin0c0bca62006-03-21 04:48:15 +0000776DefinedType:
777 BasicType {
778 $$ = $1;
779 }
780 /*
781 * A DefinedType reference.
782 * "CLASS1.&id.&id2"
783 * or
784 * "Module.Type"
785 * or
786 * "Module.identifier"
787 * or
788 * "Type"
789 */
790 | ComplexTypeReference {
Lev Walkina9532f42006-09-17 04:52:50 +0000791 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000792 checkmem($$);
793 $$->reference = $1;
794 $$->expr_type = A1TC_REFERENCE;
795 $$->meta_type = AMT_TYPEREF;
796 }
Lev Walkin0c0bca62006-03-21 04:48:15 +0000797 /*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000798 * A parameterized assignment.
Lev Walkin0c0bca62006-03-21 04:48:15 +0000799 */
Lev Walkin5045dfa2006-03-21 09:41:28 +0000800 | ComplexTypeReference '{' ActualParameterList '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000801 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000802 checkmem($$);
Lev Walkin0c0bca62006-03-21 04:48:15 +0000803 $$->reference = $1;
804 $$->rhs_pspecs = $3;
805 $$->expr_type = A1TC_REFERENCE;
806 $$->meta_type = AMT_TYPEREF;
Lev Walkinf15320b2004-06-03 03:38:44 +0000807 }
808 ;
809
Lev Walkinf15320b2004-06-03 03:38:44 +0000810/*
811 * Data Type Reference.
812 * === EXAMPLE ===
813 * Type3 ::= CHOICE { a Type1, b Type 2 }
814 * === EOF ===
815 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000816DataTypeReference:
817 /*
818 * Optionally tagged type definition.
819 */
Lev Walkin9c2285a2006-03-09 08:49:26 +0000820 TypeRefName TOK_PPEQ Type {
Lev Walkinaf120f72004-09-14 02:36:39 +0000821 $$ = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000822 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000823 assert($$->expr_type);
824 assert($$->meta_type);
825 }
Lev Walkin9c2285a2006-03-09 08:49:26 +0000826 | TypeRefName TOK_PPEQ ObjectClass {
Lev Walkinf15320b2004-06-03 03:38:44 +0000827 $$ = $3;
828 $$->Identifier = $1;
829 assert($$->expr_type == A1TC_CLASSDEF);
Lev Walkin9c2285a2006-03-09 08:49:26 +0000830 assert($$->meta_type == AMT_OBJECTCLASS);
Lev Walkinf15320b2004-06-03 03:38:44 +0000831 }
832 /*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000833 * Parameterized <Type> declaration:
Lev Walkinf15320b2004-06-03 03:38:44 +0000834 * === EXAMPLE ===
835 * SIGNED { ToBeSigned } ::= SEQUENCE {
836 * toBeSigned ToBeSigned,
837 * algorithm AlgorithmIdentifier,
838 * signature BIT STRING
839 * }
840 * === EOF ===
841 */
Lev Walkin070a52d2004-08-22 03:19:54 +0000842 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000843 $$ = $6;
Lev Walkin5045dfa2006-03-21 09:41:28 +0000844 $$->Identifier = $1;
845 $$->lhs_params = $3;
846 }
847 /* Parameterized CLASS declaration */
848 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ ObjectClass {
849 $$ = $6;
Lev Walkinf15320b2004-06-03 03:38:44 +0000850 $$->Identifier = $1;
Lev Walkina00d6b32006-03-21 03:40:38 +0000851 $$->lhs_params = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000852 }
853 ;
854
855ParameterArgumentList:
856 ParameterArgumentName {
857 int ret;
858 $$ = asn1p_paramlist_new(yylineno);
859 checkmem($$);
860 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
861 checkmem(ret == 0);
Lev Walkina964e032017-03-26 03:48:06 -0700862 asn1p_ref_free($1.governor);
863 free($1.argument);
Lev Walkinf15320b2004-06-03 03:38:44 +0000864 }
865 | ParameterArgumentList ',' ParameterArgumentName {
866 int ret;
867 $$ = $1;
868 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
869 checkmem(ret == 0);
Lev Walkina964e032017-03-26 03:48:06 -0700870 asn1p_ref_free($3.governor);
871 free($3.argument);
Lev Walkinf15320b2004-06-03 03:38:44 +0000872 }
873 ;
874
875ParameterArgumentName:
876 TypeRefName {
877 $$.governor = NULL;
878 $$.argument = $1;
879 }
880 | TypeRefName ':' Identifier {
881 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800882 $$.governor = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +0000883 ret = asn1p_ref_add_component($$.governor, $1, 0);
884 checkmem(ret == 0);
885 $$.argument = $3;
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800886 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000887 }
Lev Walkinc8092cb2005-02-18 16:34:21 +0000888 | TypeRefName ':' TypeRefName {
889 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800890 $$.governor = asn1p_ref_new(yylineno, currentModule);
Lev Walkinc8092cb2005-02-18 16:34:21 +0000891 ret = asn1p_ref_add_component($$.governor, $1, 0);
892 checkmem(ret == 0);
893 $$.argument = $3;
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800894 free($1);
Lev Walkinc8092cb2005-02-18 16:34:21 +0000895 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000896 | BasicTypeId ':' Identifier {
897 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800898 $$.governor = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +0000899 ret = asn1p_ref_add_component($$.governor,
900 ASN_EXPR_TYPE2STR($1), 1);
901 checkmem(ret == 0);
902 $$.argument = $3;
903 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000904 | BasicTypeId ':' TypeRefName {
905 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800906 $$.governor = asn1p_ref_new(yylineno, currentModule);
Lev Walkin5045dfa2006-03-21 09:41:28 +0000907 ret = asn1p_ref_add_component($$.governor,
908 ASN_EXPR_TYPE2STR($1), 1);
909 checkmem(ret == 0);
910 $$.argument = $3;
911 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000912 ;
913
Lev Walkin5045dfa2006-03-21 09:41:28 +0000914ActualParameterList:
915 ActualParameter {
Lev Walkina9532f42006-09-17 04:52:50 +0000916 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000917 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000918 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000919 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000920 | ActualParameterList ',' ActualParameter {
Lev Walkinf15320b2004-06-03 03:38:44 +0000921 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000922 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000923 }
924 ;
925
Lev Walkin5045dfa2006-03-21 09:41:28 +0000926ActualParameter:
Lev Walkin070a52d2004-08-22 03:19:54 +0000927 Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000928 $$ = $1;
929 }
Lev Walkin0c0bca62006-03-21 04:48:15 +0000930 | SimpleValue {
Lev Walkina9532f42006-09-17 04:52:50 +0000931 $$ = NEW_EXPR();
Lev Walkin0c0bca62006-03-21 04:48:15 +0000932 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800933 $$->Identifier = strdup("?");
Lev Walkin0c0bca62006-03-21 04:48:15 +0000934 $$->expr_type = A1TC_REFERENCE;
935 $$->meta_type = AMT_VALUE;
936 $$->value = $1;
937 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000938 | Identifier {
Lev Walkina00d6b32006-03-21 03:40:38 +0000939 asn1p_ref_t *ref;
Lev Walkina9532f42006-09-17 04:52:50 +0000940 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000941 checkmem($$);
942 $$->Identifier = $1;
943 $$->expr_type = A1TC_REFERENCE;
944 $$->meta_type = AMT_VALUE;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800945 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkina00d6b32006-03-21 03:40:38 +0000946 asn1p_ref_add_component(ref, $1, RLT_lowercase);
947 $$->value = asn1p_value_fromref(ref, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +0000948 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000949 | ValueSet {
Lev Walkina9532f42006-09-17 04:52:50 +0000950 $$ = NEW_EXPR();
Lev Walkin5045dfa2006-03-21 09:41:28 +0000951 $$->expr_type = A1TC_VALUESET;
952 $$->meta_type = AMT_VALUESET;
953 $$->constraints = $1;
954 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000955 ;
956
957/*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000958 | '{' ActualParameter '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000959 $$ = NEW_EXPR();
Lev Walkinc8092cb2005-02-18 16:34:21 +0000960 checkmem($$);
961 asn1p_expr_add($$, $2);
962 $$->expr_type = A1TC_PARAMETRIZED;
963 $$->meta_type = AMT_TYPE;
964 }
965 ;
966*/
967
968/*
Lev Walkinf15320b2004-06-03 03:38:44 +0000969 * A collection of constructed data type members.
970 */
Lev Walkin144db9b2004-10-12 23:26:53 +0000971optComponentTypeLists:
Lev Walkina9532f42006-09-17 04:52:50 +0000972 { $$ = NEW_EXPR(); }
Lev Walkin144db9b2004-10-12 23:26:53 +0000973 | ComponentTypeLists { $$ = $1; };
974
Lev Walkin070a52d2004-08-22 03:19:54 +0000975ComponentTypeLists:
976 ComponentType {
Lev Walkina9532f42006-09-17 04:52:50 +0000977 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000978 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000979 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000980 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000981 | ComponentTypeLists ',' ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +0000982 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000983 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000984 }
Lev Walkin0e90aa02013-03-19 16:17:13 -0700985 | ComponentTypeLists ',' TOK_VBracketLeft ComponentTypeLists TOK_VBracketRight {
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800986 $$ = $1;
Lev Walkin0e90aa02013-03-19 16:17:13 -0700987 asn1p_expr_add_many($$, $4);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800988 asn1p_expr_free($4);
Lev Walkin0e90aa02013-03-19 16:17:13 -0700989 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000990 ;
991
Lev Walkin070a52d2004-08-22 03:19:54 +0000992ComponentType:
Lev Walkinaf120f72004-09-14 02:36:39 +0000993 Identifier Type optMarker {
Lev Walkin070a52d2004-08-22 03:19:54 +0000994 $$ = $2;
995 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +0000996 $$->Identifier = $1;
Lev Walkinef625402005-09-05 05:17:57 +0000997 $3.flags |= $$->marker.flags;
Lev Walkin070a52d2004-08-22 03:19:54 +0000998 $$->marker = $3;
999 }
Lev Walkinef625402005-09-05 05:17:57 +00001000 | Type optMarker {
1001 $$ = $1;
1002 $2.flags |= $$->marker.flags;
1003 $$->marker = $2;
1004 _fixup_anonymous_identifier($$);
1005 }
Lev Walkin070a52d2004-08-22 03:19:54 +00001006 | TOK_COMPONENTS TOK_OF Type {
Lev Walkina9532f42006-09-17 04:52:50 +00001007 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001008 checkmem($$);
1009 $$->meta_type = $3->meta_type;
1010 $$->expr_type = A1TC_COMPONENTS_OF;
Lev Walkin1004aa92004-09-08 00:28:11 +00001011 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +00001012 }
1013 | ExtensionAndException {
1014 $$ = $1;
1015 }
1016 ;
1017
1018AlternativeTypeLists:
1019 AlternativeType {
Lev Walkina9532f42006-09-17 04:52:50 +00001020 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001021 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00001022 asn1p_expr_add($$, $1);
Lev Walkin070a52d2004-08-22 03:19:54 +00001023 }
1024 | AlternativeTypeLists ',' AlternativeType {
1025 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001026 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +00001027 }
1028 ;
1029
1030AlternativeType:
Lev Walkinaf120f72004-09-14 02:36:39 +00001031 Identifier Type {
Lev Walkin070a52d2004-08-22 03:19:54 +00001032 $$ = $2;
1033 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +00001034 $$->Identifier = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001035 }
1036 | ExtensionAndException {
1037 $$ = $1;
1038 }
Lev Walkin2e9bd5c2005-08-13 09:07:11 +00001039 | Type {
1040 $$ = $1;
1041 _fixup_anonymous_identifier($$);
1042 }
Lev Walkin070a52d2004-08-22 03:19:54 +00001043 ;
1044
Lev Walkin9c2285a2006-03-09 08:49:26 +00001045ObjectClass:
1046 TOK_CLASS '{' FieldSpec '}' optWithSyntax {
Lev Walkinf15320b2004-06-03 03:38:44 +00001047 $$ = $3;
1048 checkmem($$);
1049 $$->with_syntax = $5;
1050 assert($$->expr_type == A1TC_CLASSDEF);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001051 assert($$->meta_type == AMT_OBJECTCLASS);
Lev Walkinf15320b2004-06-03 03:38:44 +00001052 }
1053 ;
1054
1055optUnique:
1056 { $$ = 0; }
1057 | TOK_UNIQUE { $$ = 1; }
1058 ;
1059
Lev Walkin9c2285a2006-03-09 08:49:26 +00001060FieldSpec:
Lev Walkinf15320b2004-06-03 03:38:44 +00001061 ClassField {
Lev Walkina9532f42006-09-17 04:52:50 +00001062 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001063 checkmem($$);
1064 $$->expr_type = A1TC_CLASSDEF;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001065 $$->meta_type = AMT_OBJECTCLASS;
Lev Walkin1004aa92004-09-08 00:28:11 +00001066 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001067 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001068 | FieldSpec ',' ClassField {
Lev Walkinf15320b2004-06-03 03:38:44 +00001069 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001070 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001071 }
1072 ;
1073
Lev Walkin9c2285a2006-03-09 08:49:26 +00001074 /* X.681 */
Lev Walkinf15320b2004-06-03 03:38:44 +00001075ClassField:
Lev Walkin9c2285a2006-03-09 08:49:26 +00001076
1077 /* TypeFieldSpec ::= typefieldreference TypeOptionalitySpec? */
1078 TOK_typefieldreference optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001079 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001080 checkmem($$);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001081 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001082 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001083 $$->expr_type = A1TC_CLASSFIELD_TFS; /* TypeFieldSpec */
Lev Walkinf15320b2004-06-03 03:38:44 +00001084 $$->marker = $2;
1085 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001086
1087 /* FixedTypeValueFieldSpec ::= valuefieldreference Type UNIQUE ? ValueOptionalitySpec ? */
1088 | TOK_valuefieldreference Type optUnique optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001089 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001090 $$->Identifier = $1;
1091 $$->meta_type = AMT_OBJECTFIELD;
1092 $$->expr_type = A1TC_CLASSFIELD_FTVFS; /* FixedTypeValueFieldSpec */
Lev Walkinb7c45ca2004-11-24 17:43:29 +00001093 $$->unique = $3;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001094 $$->marker = $4;
1095 asn1p_expr_add($$, $2);
Lev Walkinf15320b2004-06-03 03:38:44 +00001096 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001097
1098 /* VariableTypeValueFieldSpec ::= valuefieldreference FieldName ValueOptionalitySpec ? */
1099 | TOK_valuefieldreference FieldName optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001100 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001101 $$->Identifier = $1;
1102 $$->meta_type = AMT_OBJECTFIELD;
1103 $$->expr_type = A1TC_CLASSFIELD_VTVFS;
1104 $$->reference = $2;
1105 $$->marker = $3;
1106 }
1107
Lev Walkin9c2285a2006-03-09 08:49:26 +00001108 /* ObjectFieldSpec ::= objectfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1109 | TOK_valuefieldreference DefinedObjectClass optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001110 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001111 checkmem($$);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001112 $$->Identifier = $1;
1113 $$->reference = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00001114 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001115 $$->expr_type = A1TC_CLASSFIELD_OFS;
1116 $$->marker = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +00001117 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001118
Lev Walkin54868752006-03-09 09:08:49 +00001119 /* VariableTypeValueSetFieldSpec ::= valuesetfieldreference FieldName ValueOptionalitySpec ? */
1120 | TOK_typefieldreference FieldName optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001121 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001122 $$->Identifier = $1;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001123 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin54868752006-03-09 09:08:49 +00001124 $$->expr_type = A1TC_CLASSFIELD_VTVSFS;
1125 $$->reference = $2;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001126 $$->marker = $3;
1127 }
1128
1129 /* FixedTypeValueSetFieldSpec ::= valuesetfieldreference Type ValueSetOptionalitySpec ? */
1130 | TOK_typefieldreference Type optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001131 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001132 checkmem($$);
1133 $$->Identifier = $1;
1134 $$->meta_type = AMT_OBJECTFIELD;
1135 $$->expr_type = A1TC_CLASSFIELD_FTVSFS;
1136 asn1p_expr_add($$, $2);
1137 $$->marker = $3;
1138 }
1139
Lev Walkin54868752006-03-09 09:08:49 +00001140 /* ObjectSetFieldSpec ::= objectsetfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1141 | TOK_typefieldreference DefinedObjectClass optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001142 $$ = NEW_EXPR();
Lev Walkin54868752006-03-09 09:08:49 +00001143 checkmem($$);
1144 $$->Identifier = $1;
1145 $$->reference = $2;
1146 $$->meta_type = AMT_OBJECTFIELD;
1147 $$->expr_type = A1TC_CLASSFIELD_OSFS;
1148 $$->marker = $3;
1149 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001150 ;
1151
1152optWithSyntax:
1153 { $$ = 0; }
1154 | WithSyntax {
1155 $$ = $1;
1156 }
1157 ;
1158
1159WithSyntax:
1160 TOK_WITH TOK_SYNTAX '{'
1161 { asn1p_lexer_hack_enable_with_syntax(); }
Lev Walkin9d542d22006-03-14 16:31:37 +00001162 WithSyntaxList
Lev Walkinf15320b2004-06-03 03:38:44 +00001163 '}' {
1164 $$ = $5;
1165 }
1166 ;
1167
Lev Walkin9d542d22006-03-14 16:31:37 +00001168WithSyntaxList:
1169 WithSyntaxToken {
Lev Walkinf15320b2004-06-03 03:38:44 +00001170 $$ = asn1p_wsyntx_new();
1171 TQ_ADD(&($$->chunks), $1, next);
1172 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001173 | WithSyntaxList WithSyntaxToken {
Lev Walkinf15320b2004-06-03 03:38:44 +00001174 $$ = $1;
1175 TQ_ADD(&($$->chunks), $2, next);
1176 }
1177 ;
1178
Lev Walkin9d542d22006-03-14 16:31:37 +00001179WithSyntaxToken:
Lev Walkin57074f12006-03-16 05:11:14 +00001180 TOK_whitespace {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001181 $$ = asn1p_wsyntx_chunk_fromstring($1.buf, 0);
Lev Walkin57074f12006-03-16 05:11:14 +00001182 $$->type = WC_WHITESPACE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001183 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001184 | TOK_Literal {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001185 $$ = asn1p_wsyntx_chunk_fromstring($1, 0);
Lev Walkin9d542d22006-03-14 16:31:37 +00001186 }
Lev Walkind370e9f2006-03-16 10:03:35 +00001187 | PrimitiveFieldReference {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001188 $$ = asn1p_wsyntx_chunk_fromstring($1.name, 0);
Lev Walkind370e9f2006-03-16 10:03:35 +00001189 $$->type = WC_FIELD;
Lev Walkinf15320b2004-06-03 03:38:44 +00001190 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001191 | '[' WithSyntaxList ']' {
1192 $$ = asn1p_wsyntx_chunk_fromsyntax($2);
1193 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001194 ;
1195
Lev Walkinf15320b2004-06-03 03:38:44 +00001196ExtensionAndException:
1197 TOK_ThreeDots {
Lev Walkina9532f42006-09-17 04:52:50 +00001198 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001199 checkmem($$);
1200 $$->Identifier = strdup("...");
1201 checkmem($$->Identifier);
1202 $$->expr_type = A1TC_EXTENSIBLE;
1203 $$->meta_type = AMT_TYPE;
1204 }
1205 | TOK_ThreeDots '!' DefinedValue {
Lev Walkina9532f42006-09-17 04:52:50 +00001206 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001207 checkmem($$);
1208 $$->Identifier = strdup("...");
1209 checkmem($$->Identifier);
1210 $$->value = $3;
1211 $$->expr_type = A1TC_EXTENSIBLE;
1212 $$->meta_type = AMT_TYPE;
1213 }
1214 | TOK_ThreeDots '!' SignedNumber {
Lev Walkina9532f42006-09-17 04:52:50 +00001215 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001216 checkmem($$);
1217 $$->Identifier = strdup("...");
1218 $$->value = $3;
1219 checkmem($$->Identifier);
1220 $$->expr_type = A1TC_EXTENSIBLE;
1221 $$->meta_type = AMT_TYPE;
1222 }
1223 ;
1224
Lev Walkin070a52d2004-08-22 03:19:54 +00001225Type:
Lev Walkinaf120f72004-09-14 02:36:39 +00001226 optTag TypeDeclaration optConstraints {
1227 $$ = $2;
1228 $$->tag = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001229 /*
1230 * Outer constraint for SEQUENCE OF and SET OF applies
1231 * to the inner type.
1232 */
1233 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1234 || $$->expr_type == ASN_CONSTR_SET_OF) {
1235 assert(!TQ_FIRST(&($$->members))->constraints);
Lev Walkinaf120f72004-09-14 02:36:39 +00001236 TQ_FIRST(&($$->members))->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001237 } else {
1238 if($$->constraints) {
1239 assert(!$2);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001240 /* Check this : optConstraints is not used ?! */
1241 asn1p_constraint_free($3);
Lev Walkin070a52d2004-08-22 03:19:54 +00001242 } else {
Lev Walkinaf120f72004-09-14 02:36:39 +00001243 $$->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001244 }
1245 }
Lev Walkinef625402005-09-05 05:17:57 +00001246 }
1247 ;
1248
1249NSTD_IndirectMarker:
1250 {
1251 $$ = asn1p_as_pointer ? EM_INDIRECT : 0;
1252 asn1p_as_pointer = 0;
Lev Walkin070a52d2004-08-22 03:19:54 +00001253 }
1254 ;
1255
1256TypeDeclaration:
Lev Walkinef625402005-09-05 05:17:57 +00001257 NSTD_IndirectMarker TypeDeclarationSet {
Lev Walkin4696c742005-08-22 12:23:54 +00001258 $$ = $2;
Lev Walkinef625402005-09-05 05:17:57 +00001259 $$->marker.flags |= $1;
1260
1261 if(($$->marker.flags & EM_INDIRECT)
1262 && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
1263 fprintf(stderr,
1264 "INFO: Directive <ASN1C:RepresentAsPointer> "
1265 "applied to %s at line %d\n",
1266 ASN_EXPR_TYPE2STR($$->expr_type)
1267 ? ASN_EXPR_TYPE2STR($$->expr_type)
1268 : "member",
1269 $$->_lineno
1270 );
1271 }
Lev Walkin4696c742005-08-22 12:23:54 +00001272 }
Lev Walkinef625402005-09-05 05:17:57 +00001273 ;
Lev Walkin4696c742005-08-22 12:23:54 +00001274
1275TypeDeclarationSet:
Lev Walkin0c0bca62006-03-21 04:48:15 +00001276 DefinedType {
Lev Walkinf15320b2004-06-03 03:38:44 +00001277 $$ = $1;
1278 }
Lev Walkinef625402005-09-05 05:17:57 +00001279 | TOK_CHOICE '{' AlternativeTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001280 $$ = $3;
1281 assert($$->expr_type == A1TC_INVALID);
1282 $$->expr_type = ASN_CONSTR_CHOICE;
1283 $$->meta_type = AMT_TYPE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001284 }
Lev Walkinef625402005-09-05 05:17:57 +00001285 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001286 $$ = $3;
1287 assert($$->expr_type == A1TC_INVALID);
1288 $$->expr_type = ASN_CONSTR_SEQUENCE;
1289 $$->meta_type = AMT_TYPE;
1290 }
Lev Walkinef625402005-09-05 05:17:57 +00001291 | TOK_SET '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001292 $$ = $3;
1293 assert($$->expr_type == A1TC_INVALID);
1294 $$->expr_type = ASN_CONSTR_SET;
1295 $$->meta_type = AMT_TYPE;
1296 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001297 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkina9532f42006-09-17 04:52:50 +00001298 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001299 checkmem($$);
1300 $$->constraints = $2;
1301 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1302 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001303 $6->Identifier = $4;
1304 $6->tag = $5;
1305 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001306 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001307 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkina9532f42006-09-17 04:52:50 +00001308 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001309 checkmem($$);
1310 $$->constraints = $2;
1311 $$->expr_type = ASN_CONSTR_SET_OF;
1312 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001313 $6->Identifier = $4;
1314 $6->tag = $5;
1315 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001316 }
1317 | TOK_ANY {
Lev Walkina9532f42006-09-17 04:52:50 +00001318 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001319 checkmem($$);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001320 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001321 $$->meta_type = AMT_TYPE;
1322 }
1323 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1324 int ret;
Lev Walkina9532f42006-09-17 04:52:50 +00001325 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001326 checkmem($$);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001327 $$->reference = asn1p_ref_new(yylineno, currentModule);
Lev Walkin070a52d2004-08-22 03:19:54 +00001328 ret = asn1p_ref_add_component($$->reference,
1329 $4, RLT_lowercase);
1330 checkmem(ret == 0);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001331 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001332 $$->meta_type = AMT_TYPE;
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001333 free($4);
Lev Walkin070a52d2004-08-22 03:19:54 +00001334 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001335 | TOK_INSTANCE TOK_OF ComplexTypeReference {
Lev Walkina9532f42006-09-17 04:52:50 +00001336 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001337 checkmem($$);
1338 $$->reference = $3;
1339 $$->expr_type = A1TC_INSTANCE;
1340 $$->meta_type = AMT_TYPE;
1341 }
1342 ;
1343
1344/*
1345 * A type name consisting of several components.
1346 * === EXAMPLE ===
1347 * === EOF ===
1348 */
1349ComplexTypeReference:
1350 TOK_typereference {
1351 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001352 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001353 checkmem($$);
1354 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1355 checkmem(ret == 0);
1356 free($1);
1357 }
1358 | TOK_typereference '.' TypeRefName {
1359 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001360 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001361 checkmem($$);
1362 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1363 checkmem(ret == 0);
1364 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1365 checkmem(ret == 0);
1366 free($1);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001367 free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001368 }
Lev Walkin9c974182004-09-15 11:59:51 +00001369 | ObjectClassReference '.' TypeRefName {
1370 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001371 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkin9c974182004-09-15 11:59:51 +00001372 checkmem($$);
1373 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1374 checkmem(ret == 0);
1375 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1376 checkmem(ret == 0);
1377 free($1);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001378 free($3);
Lev Walkin9c974182004-09-15 11:59:51 +00001379 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001380 | TOK_typereference '.' Identifier {
1381 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001382 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001383 checkmem($$);
1384 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1385 checkmem(ret == 0);
1386 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1387 checkmem(ret == 0);
1388 free($1);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001389 free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001390 }
1391 | ObjectClassReference {
1392 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001393 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001394 checkmem($$);
1395 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1396 free($1);
1397 checkmem(ret == 0);
1398 }
1399 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1400 int ret;
1401 $$ = $3;
1402 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1403 free($1);
1404 checkmem(ret == 0);
1405 /*
1406 * Move the last element infront.
1407 */
1408 {
1409 struct asn1p_ref_component_s tmp_comp;
1410 tmp_comp = $$->components[$$->comp_count-1];
1411 memmove(&$$->components[1],
1412 &$$->components[0],
1413 sizeof($$->components[0])
1414 * ($$->comp_count - 1));
1415 $$->components[0] = tmp_comp;
1416 }
1417 }
1418 ;
1419
1420ComplexTypeReferenceAmpList:
1421 ComplexTypeReferenceElement {
1422 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001423 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001424 checkmem($$);
1425 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1426 free($1.name);
1427 checkmem(ret == 0);
1428 }
1429 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1430 int ret;
1431 $$ = $1;
1432 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1433 free($3.name);
1434 checkmem(ret == 0);
1435 }
1436 ;
1437
Lev Walkind370e9f2006-03-16 10:03:35 +00001438ComplexTypeReferenceElement: PrimitiveFieldReference;
Lev Walkinf15320b2004-06-03 03:38:44 +00001439
Lev Walkind370e9f2006-03-16 10:03:35 +00001440PrimitiveFieldReference:
Lev Walkinf15320b2004-06-03 03:38:44 +00001441 /* "&Type1" */
1442 TOK_typefieldreference {
1443 $$.lex_type = RLT_AmpUppercase;
1444 $$.name = $1;
1445 }
1446 /* "&id" */
1447 | TOK_valuefieldreference {
1448 $$.lex_type = RLT_Amplowercase;
1449 $$.name = $1;
1450 }
1451 ;
1452
1453
Lev Walkin9c2285a2006-03-09 08:49:26 +00001454FieldName:
1455 /* "&Type1" */
1456 TOK_typefieldreference {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001457 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001458 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001459 free($1);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001460 }
1461 | FieldName '.' TOK_typefieldreference {
1462 $$ = $$;
1463 asn1p_ref_add_component($$, $3, RLT_AmpUppercase);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001464 free($3);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001465 }
1466 | FieldName '.' TOK_valuefieldreference {
1467 $$ = $$;
1468 asn1p_ref_add_component($$, $3, RLT_Amplowercase);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001469 free($3);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001470 }
1471 ;
1472
1473DefinedObjectClass:
1474 TOK_capitalreference {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001475 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001476 asn1p_ref_add_component($$, $1, RLT_CAPITALS);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001477 free($1);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001478 }
Lev Walkin54868752006-03-09 09:08:49 +00001479/*
Lev Walkin9c2285a2006-03-09 08:49:26 +00001480 | TypeRefName '.' TOK_capitalreference {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001481 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001482 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1483 asn1p_ref_add_component($$, $3, RLT_CAPITALS);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001484 free($1);
1485 free($3);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001486 }
Lev Walkin54868752006-03-09 09:08:49 +00001487*/
Lev Walkin9c2285a2006-03-09 08:49:26 +00001488 ;
1489
1490
Lev Walkinf15320b2004-06-03 03:38:44 +00001491/*
1492 * === EXAMPLE ===
1493 * value INTEGER ::= 1
1494 * === EOF ===
1495 */
Lev Walkinc6ab03c2006-10-21 05:54:49 +00001496ValueAssignment:
1497 Identifier Type TOK_PPEQ Value {
Lev Walkinf15320b2004-06-03 03:38:44 +00001498 $$ = $2;
1499 assert($$->Identifier == NULL);
1500 $$->Identifier = $1;
1501 $$->meta_type = AMT_VALUE;
1502 $$->value = $4;
1503 }
1504 ;
1505
Lev Walkin9c974182004-09-15 11:59:51 +00001506Value:
Lev Walkin0c0bca62006-03-21 04:48:15 +00001507 SimpleValue
1508 | DefinedValue
1509 | Identifier ':' Value {
Lev Walkin9c974182004-09-15 11:59:51 +00001510 $$ = asn1p_value_fromint(0);
1511 checkmem($$);
1512 $$->type = ATV_CHOICE_IDENTIFIER;
1513 $$->value.choice_identifier.identifier = $1;
1514 $$->value.choice_identifier.value = $3;
1515 }
Lev Walkincbad2512005-03-24 16:27:02 +00001516 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Lev Walkinf15320b2004-06-03 03:38:44 +00001517 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1518 checkmem($$);
1519 $$->type = ATV_UNPARSED;
1520 }
Lev Walkin9c974182004-09-15 11:59:51 +00001521 | TOK_NULL {
1522 $$ = asn1p_value_fromint(0);
1523 checkmem($$);
1524 $$->type = ATV_NULL;
1525 }
Lev Walkin0c0bca62006-03-21 04:48:15 +00001526 ;
1527
1528SimpleValue:
1529 TOK_FALSE {
Lev Walkin9c974182004-09-15 11:59:51 +00001530 $$ = asn1p_value_fromint(0);
1531 checkmem($$);
1532 $$->type = ATV_FALSE;
1533 }
1534 | TOK_TRUE {
1535 $$ = asn1p_value_fromint(0);
1536 checkmem($$);
1537 $$->type = ATV_TRUE;
1538 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001539 | TOK_bstring {
1540 $$ = _convert_bitstring2binary($1, 'B');
1541 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001542 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001543 }
1544 | TOK_hstring {
1545 $$ = _convert_bitstring2binary($1, 'H');
1546 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001547 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001548 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001549 | RestrictedCharacterStringValue {
1550 $$ = $$;
Lev Walkinf15320b2004-06-03 03:38:44 +00001551 }
1552 | SignedNumber {
1553 $$ = $1;
1554 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001555 ;
1556
1557DefinedValue:
1558 Identifier {
1559 asn1p_ref_t *ref;
1560 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001561 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001562 checkmem(ref);
1563 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1564 checkmem(ret == 0);
1565 $$ = asn1p_value_fromref(ref, 0);
1566 checkmem($$);
1567 free($1);
1568 }
1569 | TypeRefName '.' Identifier {
1570 asn1p_ref_t *ref;
1571 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001572 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001573 checkmem(ref);
1574 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1575 checkmem(ret == 0);
1576 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1577 checkmem(ret == 0);
1578 $$ = asn1p_value_fromref(ref, 0);
1579 checkmem($$);
1580 free($1);
1581 free($3);
1582 }
1583 ;
1584
Lev Walkin1e448d32005-03-24 14:26:38 +00001585
1586RestrictedCharacterStringValue:
1587 TOK_cstring {
1588 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1589 checkmem($$);
1590 }
Lev Walkind9574ae2005-03-24 16:22:35 +00001591 | TOK_tuple {
1592 $$ = asn1p_value_fromint($1);
1593 checkmem($$);
1594 $$->type = ATV_TUPLE;
1595 }
1596 | TOK_quadruple {
1597 $$ = asn1p_value_fromint($1);
1598 checkmem($$);
1599 $$->type = ATV_QUADRUPLE;
1600 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001601 ;
1602
Lev Walkinf15320b2004-06-03 03:38:44 +00001603Opaque:
1604 TOK_opaque {
Lev Walkin1893ddf2005-03-20 14:28:32 +00001605 $$.len = $1.len + 1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001606 $$.buf = malloc($$.len + 1);
1607 checkmem($$.buf);
1608 $$.buf[0] = '{';
Lev Walkin1893ddf2005-03-20 14:28:32 +00001609 memcpy($$.buf + 1, $1.buf, $1.len);
Lev Walkinf15320b2004-06-03 03:38:44 +00001610 $$.buf[$$.len] = '\0';
1611 free($1.buf);
1612 }
1613 | Opaque TOK_opaque {
1614 int newsize = $1.len + $2.len;
1615 char *p = malloc(newsize + 1);
1616 checkmem(p);
1617 memcpy(p , $1.buf, $1.len);
1618 memcpy(p + $1.len, $2.buf, $2.len);
1619 p[newsize] = '\0';
1620 free($1.buf);
1621 free($2.buf);
1622 $$.buf = p;
1623 $$.len = newsize;
1624 }
1625 ;
1626
1627BasicTypeId:
1628 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1629 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1630 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1631 | BasicTypeId_UniverationCompatible { $$ = $1; }
1632 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1633 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1634 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1635 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1636 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1637 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1638 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1639 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
Lev Walkinc7d939d2005-03-20 11:12:40 +00001640 | BasicString { $$ = $1; }
Lev Walkinf15320b2004-06-03 03:38:44 +00001641 ;
1642
1643/*
1644 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1645 */
1646BasicTypeId_UniverationCompatible:
1647 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1648 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1649 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1650 ;
1651
1652BasicType:
1653 BasicTypeId {
Lev Walkina9532f42006-09-17 04:52:50 +00001654 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001655 checkmem($$);
1656 $$->expr_type = $1;
1657 $$->meta_type = AMT_TYPE;
1658 }
1659 | BasicTypeId_UniverationCompatible UniverationDefinition {
1660 if($2) {
1661 $$ = $2;
1662 } else {
Lev Walkina9532f42006-09-17 04:52:50 +00001663 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001664 checkmem($$);
1665 }
1666 $$->expr_type = $1;
1667 $$->meta_type = AMT_TYPE;
1668 }
1669 ;
1670
1671BasicString:
1672 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1673 | TOK_GeneralString {
1674 $$ = ASN_STRING_GeneralString;
Lev Walkin9c974182004-09-15 11:59:51 +00001675 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001676 }
1677 | TOK_GraphicString {
1678 $$ = ASN_STRING_GraphicString;
Lev Walkin9c974182004-09-15 11:59:51 +00001679 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001680 }
1681 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1682 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1683 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1684 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1685 | TOK_T61String {
1686 $$ = ASN_STRING_T61String;
Lev Walkin9c974182004-09-15 11:59:51 +00001687 fprintf(stderr, "WARNING: T61String is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001688 }
1689 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1690 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1691 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1692 | TOK_VideotexString {
1693 $$ = ASN_STRING_VideotexString;
Lev Walkin9c974182004-09-15 11:59:51 +00001694 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001695 }
1696 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1697 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1698 ;
1699
Lev Walkind2ea1de2004-08-20 13:25:29 +00001700
Lev Walkinf15320b2004-06-03 03:38:44 +00001701/*
1702 * Data type constraints.
1703 */
Lev Walkinf1727152006-09-21 01:50:37 +00001704UnionMark: '|' | TOK_UNION;
1705IntersectionMark: '^' | TOK_INTERSECTION;
Lev Walkinf15320b2004-06-03 03:38:44 +00001706
Lev Walkinf59d0752004-08-18 04:59:12 +00001707optConstraints:
1708 { $$ = 0; }
Lev Walkina9532f42006-09-17 04:52:50 +00001709 | Constraint {
Lev Walkind2ea1de2004-08-20 13:25:29 +00001710 $$ = $1;
1711 }
1712 ;
1713
Lev Walkina9532f42006-09-17 04:52:50 +00001714Constraint:
1715 SubtypeConstraint
Lev Walkina9532f42006-09-17 04:52:50 +00001716 ;
1717
1718SubtypeConstraint:
Lev Walkind2ea1de2004-08-20 13:25:29 +00001719 SetOfConstraints {
Lev Walkin2c14a692005-08-12 10:08:45 +00001720 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
Lev Walkinf59d0752004-08-18 04:59:12 +00001721 }
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001722 | TOK_SIZE '(' ConstraintSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001723 /*
1724 * This is a special case, for compatibility purposes.
Lev Walkinf59d0752004-08-18 04:59:12 +00001725 * It goes without parentheses.
Lev Walkinf15320b2004-06-03 03:38:44 +00001726 */
Lev Walkin2c14a692005-08-12 10:08:45 +00001727 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001728 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001729 ;
1730
Lev Walkinf59d0752004-08-18 04:59:12 +00001731SetOfConstraints:
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001732 '(' ConstraintSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001733 $$ = $2;
1734 }
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001735 | SetOfConstraints '(' ConstraintSpecs ')' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001736 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
Lev Walkinf59d0752004-08-18 04:59:12 +00001737 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001738 ;
1739
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001740ConstraintSpecs:
1741 ElementSetSpecs {
1742 $$ = $1;
1743 }
1744 | GeneralConstraint {
1745 $$ = $1;
1746 }
1747 ;
1748
Lev Walkinf59d0752004-08-18 04:59:12 +00001749ElementSetSpecs:
Lev Walkin5045dfa2006-03-21 09:41:28 +00001750 TOK_ThreeDots {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001751 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkin5045dfa2006-03-21 09:41:28 +00001752 $$->type = ACT_EL_EXT;
1753 }
1754 | ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001755 $$ = $1;
1756 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001757 | ElementSetSpec ',' TOK_ThreeDots {
Lev Walkinf15320b2004-06-03 03:38:44 +00001758 asn1p_constraint_t *ct;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001759 ct = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001760 ct->type = ACT_EL_EXT;
Lev Walkin2c14a692005-08-12 10:08:45 +00001761 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00001762 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001763 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001764 asn1p_constraint_t *ct;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001765 ct = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001766 ct->type = ACT_EL_EXT;
Lev Walkin2c14a692005-08-12 10:08:45 +00001767 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinb4fcdd22004-08-13 12:35:09 +00001768 ct = $$;
Lev Walkin2c14a692005-08-12 10:08:45 +00001769 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
Lev Walkinf15320b2004-06-03 03:38:44 +00001770 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001771 ;
1772
Lev Walkinf59d0752004-08-18 04:59:12 +00001773ElementSetSpec:
Lev Walkinf1727152006-09-21 01:50:37 +00001774 Unions
Lev Walkin1e448d32005-03-24 14:26:38 +00001775 | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001776 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
Lev Walkin1e448d32005-03-24 14:26:38 +00001777 }
Lev Walkinf1727152006-09-21 01:50:37 +00001778 ;
1779
1780Unions:
1781 Intersections
1782 | Unions UnionMark Intersections {
Lev Walkin2c14a692005-08-12 10:08:45 +00001783 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001784 }
Lev Walkinf1727152006-09-21 01:50:37 +00001785 ;
1786
1787Intersections:
1788 IntersectionElements
1789 | Intersections IntersectionMark IntersectionElements {
Lev Walkin2c14a692005-08-12 10:08:45 +00001790 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001791 }
Lev Walkinf1727152006-09-21 01:50:37 +00001792 ;
1793
1794
1795IntersectionElements:
1796 ConstraintSubtypeElement
1797 | ConstraintSubtypeElement TOK_EXCEPT ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001798 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001799 }
1800 ;
1801
1802ConstraintSubtypeElement:
Lev Walkinf59d0752004-08-18 04:59:12 +00001803 ConstraintSpec '(' ElementSetSpecs ')' {
1804 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001805 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf59d0752004-08-18 04:59:12 +00001806 checkmem($$);
1807 $$->type = $1;
1808 ret = asn1p_constraint_insert($$, $3);
1809 checkmem(ret == 0);
1810 }
1811 | '(' ElementSetSpecs ')' {
1812 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001813 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf59d0752004-08-18 04:59:12 +00001814 checkmem($$);
1815 $$->type = ACT_CA_SET;
1816 ret = asn1p_constraint_insert($$, $2);
1817 checkmem(ret == 0);
1818 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001819 | SingleValue {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001820 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001821 checkmem($$);
1822 $$->type = ACT_EL_VALUE;
1823 $$->value = $1;
1824 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001825 | ContainedSubtype {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001826 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinff7dd142005-03-20 12:58:00 +00001827 checkmem($$);
1828 $$->type = ACT_EL_TYPE;
1829 $$->containedSubtype = $1;
1830 }
1831 | SingleValue ConstraintRangeSpec SingleValue {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001832 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001833 checkmem($$);
1834 $$->type = $2;
1835 $$->range_start = $1;
1836 $$->range_stop = $3;
1837 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001838 | TOK_MIN ConstraintRangeSpec SingleValue {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001839 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001840 checkmem($$);
Lev Walkinf59d0752004-08-18 04:59:12 +00001841 $$->type = $2;
1842 $$->range_start = asn1p_value_fromint(-123);
1843 $$->range_stop = $3;
1844 $$->range_start->type = ATV_MIN;
1845 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001846 | SingleValue ConstraintRangeSpec TOK_MAX {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001847 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf59d0752004-08-18 04:59:12 +00001848 checkmem($$);
1849 $$->type = $2;
1850 $$->range_start = $1;
1851 $$->range_stop = asn1p_value_fromint(321);
1852 $$->range_stop->type = ATV_MAX;
1853 }
1854 | TOK_MIN ConstraintRangeSpec TOK_MAX {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001855 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf59d0752004-08-18 04:59:12 +00001856 checkmem($$);
1857 $$->type = $2;
1858 $$->range_start = asn1p_value_fromint(-123);
1859 $$->range_stop = asn1p_value_fromint(321);
1860 $$->range_start->type = ATV_MIN;
1861 $$->range_stop->type = ATV_MAX;
Lev Walkinf15320b2004-06-03 03:38:44 +00001862 }
Lev Walkine596bf02005-03-28 15:01:27 +00001863 | InnerTypeConstraint {
Lev Walkinf15320b2004-06-03 03:38:44 +00001864 $$ = $1;
1865 }
Lev Walkin5c541f12006-10-18 18:40:14 +00001866 | PatternConstraint {
1867 $$ = $1;
1868 }
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001869 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1870 $$ = asn1p_constraint_new(yylineno, currentModule);
1871 checkmem($$);
1872 $$->type = ACT_EL_VALUE;
1873 $$->value = asn1p_value_frombuf($3.buf, $3.len, 0);
1874 $$->value->type = ATV_UNPARSED;
1875 }
Lev Walkin5c541f12006-10-18 18:40:14 +00001876 ;
1877
1878PatternConstraint:
1879 TOK_PATTERN TOK_cstring {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001880 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkin5c541f12006-10-18 18:40:14 +00001881 $$->type = ACT_CT_PATTERN;
1882 $$->value = asn1p_value_frombuf($2.buf, $2.len, 0);
1883 }
1884 | TOK_PATTERN Identifier {
1885 asn1p_ref_t *ref;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001886 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkin5c541f12006-10-18 18:40:14 +00001887 $$->type = ACT_CT_PATTERN;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001888 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkin5c541f12006-10-18 18:40:14 +00001889 asn1p_ref_add_component(ref, $2, RLT_lowercase);
1890 $$->value = asn1p_value_fromref(ref, 0);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001891 free($2);
Lev Walkin5c541f12006-10-18 18:40:14 +00001892 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001893 ;
1894
1895ConstraintSpec:
1896 TOK_SIZE {
1897 $$ = ACT_CT_SIZE;
1898 }
1899 | TOK_FROM {
1900 $$ = ACT_CT_FROM;
1901 }
1902 ;
1903
Lev Walkinff7dd142005-03-20 12:58:00 +00001904SingleValue:
Lev Walkinc8092cb2005-02-18 16:34:21 +00001905 TOK_FALSE {
1906 $$ = asn1p_value_fromint(0);
1907 checkmem($$);
1908 $$->type = ATV_FALSE;
1909 }
1910 | TOK_TRUE {
1911 $$ = asn1p_value_fromint(1);
1912 checkmem($$);
1913 $$->type = ATV_TRUE;
1914 }
Lev Walkinadf863f2006-09-05 16:18:34 +00001915 | RealValue
1916 | RestrictedCharacterStringValue
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001917 | BitStringValue
Lev Walkinf15320b2004-06-03 03:38:44 +00001918 | Identifier {
1919 asn1p_ref_t *ref;
1920 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001921 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001922 checkmem(ref);
1923 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1924 checkmem(ret == 0);
1925 $$ = asn1p_value_fromref(ref, 0);
1926 checkmem($$);
1927 free($1);
1928 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001929 ;
1930
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001931BitStringValue:
1932 TOK_bstring {
1933 $$ = _convert_bitstring2binary($1, 'B');
1934 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001935 free($1);
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001936 }
1937 | TOK_hstring {
1938 $$ = _convert_bitstring2binary($1, 'H');
1939 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001940 free($1);
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001941 }
1942 ;
1943
Lev Walkinff7dd142005-03-20 12:58:00 +00001944ContainedSubtype:
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001945 ComplexTypeReference {
1946 $$ = asn1p_value_fromref($1, 0);
1947 checkmem($$);
1948 }
1949/*
Lev Walkinff7dd142005-03-20 12:58:00 +00001950 TypeRefName {
Lev Walkinc8092cb2005-02-18 16:34:21 +00001951 asn1p_ref_t *ref;
1952 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001953 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkinc8092cb2005-02-18 16:34:21 +00001954 checkmem(ref);
1955 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1956 checkmem(ret == 0);
1957 $$ = asn1p_value_fromref(ref, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001958 checkmem($$);
Lev Walkinc8092cb2005-02-18 16:34:21 +00001959 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001960 }
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001961*/
Lev Walkinf15320b2004-06-03 03:38:44 +00001962 ;
1963
Lev Walkine596bf02005-03-28 15:01:27 +00001964InnerTypeConstraint:
1965 TOK_WITH TOK_COMPONENT SetOfConstraints {
Lev Walkin2c14a692005-08-12 10:08:45 +00001966 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
Lev Walkine596bf02005-03-28 15:01:27 +00001967 }
1968 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001969 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001970 }
1971 ;
1972
1973WithComponentsList:
1974 WithComponentsElement {
1975 $$ = $1;
1976 }
1977 | WithComponentsList ',' WithComponentsElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001978 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001979 }
1980 ;
1981
1982WithComponentsElement:
1983 TOK_ThreeDots {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001984 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001985 checkmem($$);
1986 $$->type = ACT_EL_EXT;
Lev Walkin418298d2006-07-13 08:24:20 +00001987 $$->value = asn1p_value_frombuf("...", 3, 1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001988 }
1989 | Identifier optConstraints optPresenceConstraint {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001990 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001991 checkmem($$);
1992 $$->type = ACT_EL_VALUE;
1993 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1994 $$->presence = $3;
Lev Walkine596bf02005-03-28 15:01:27 +00001995 if($2) asn1p_constraint_insert($$, $2);
Lev Walkinf15320b2004-06-03 03:38:44 +00001996 }
1997 ;
1998
1999/*
2000 * presence constraint for WithComponents
2001 */
2002optPresenceConstraint:
2003 { $$ = ACPRES_DEFAULT; }
2004 | PresenceConstraint { $$ = $1; }
2005 ;
2006
2007PresenceConstraint:
2008 TOK_PRESENT {
2009 $$ = ACPRES_PRESENT;
2010 }
2011 | TOK_ABSENT {
2012 $$ = ACPRES_ABSENT;
2013 }
2014 | TOK_OPTIONAL {
2015 $$ = ACPRES_OPTIONAL;
2016 }
2017 ;
2018
Lev Walkina9532f42006-09-17 04:52:50 +00002019
2020/* X.682 */
2021GeneralConstraint:
2022 UserDefinedConstraint
2023 | TableConstraint
2024 | ContentsConstraint
2025 ;
2026
2027UserDefinedConstraint:
2028 TOK_CONSTRAINED TOK_BY '{'
2029 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002030 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkina9532f42006-09-17 04:52:50 +00002031 checkmem($$);
2032 $$->type = ACT_CT_CTDBY;
2033 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
2034 checkmem($$->value);
2035 $$->value->type = ATV_UNPARSED;
2036 }
2037 ;
2038
2039ContentsConstraint:
2040 TOK_CONTAINING Type {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002041 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkina9532f42006-09-17 04:52:50 +00002042 $$->type = ACT_CT_CTNG;
2043 $$->value = asn1p_value_fromtype($2);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08002044 asn1p_expr_free($2);
Lev Walkina9532f42006-09-17 04:52:50 +00002045 }
2046 ;
2047
2048ConstraintRangeSpec:
2049 TOK_TwoDots { $$ = ACT_EL_RANGE; }
2050 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
2051 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
2052 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
2053 ;
Lev Walkinf15320b2004-06-03 03:38:44 +00002054TableConstraint:
2055 SimpleTableConstraint {
2056 $$ = $1;
2057 }
2058 | ComponentRelationConstraint {
2059 $$ = $1;
2060 }
2061 ;
2062
2063/*
2064 * "{ExtensionSet}"
2065 */
2066SimpleTableConstraint:
2067 '{' TypeRefName '}' {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002068 asn1p_ref_t *ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002069 asn1p_constraint_t *ct;
2070 int ret;
2071 ret = asn1p_ref_add_component(ref, $2, 0);
2072 checkmem(ret == 0);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002073 ct = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002074 checkmem($$);
2075 ct->type = ACT_EL_VALUE;
2076 ct->value = asn1p_value_fromref(ref, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00002077 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08002078 free($2);
Lev Walkinf15320b2004-06-03 03:38:44 +00002079 }
2080 ;
2081
2082ComponentRelationConstraint:
2083 SimpleTableConstraint '{' AtNotationList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00002084 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002085 }
2086 ;
2087
2088AtNotationList:
2089 AtNotationElement {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002090 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002091 checkmem($$);
2092 $$->type = ACT_EL_VALUE;
2093 $$->value = asn1p_value_fromref($1, 0);
2094 }
2095 | AtNotationList ',' AtNotationElement {
2096 asn1p_constraint_t *ct;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002097 ct = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002098 checkmem(ct);
2099 ct->type = ACT_EL_VALUE;
2100 ct->value = asn1p_value_fromref($3, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00002101 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00002102 }
2103 ;
2104
2105/*
2106 * @blah
2107 */
2108AtNotationElement:
2109 '@' ComponentIdList {
2110 char *p = malloc(strlen($2) + 2);
2111 int ret;
2112 *p = '@';
2113 strcpy(p + 1, $2);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002114 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002115 ret = asn1p_ref_add_component($$, p, 0);
2116 checkmem(ret == 0);
2117 free(p);
2118 free($2);
2119 }
2120 | '@' '.' ComponentIdList {
2121 char *p = malloc(strlen($3) + 3);
2122 int ret;
2123 p[0] = '@';
2124 p[1] = '.';
2125 strcpy(p + 2, $3);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002126 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002127 ret = asn1p_ref_add_component($$, p, 0);
2128 checkmem(ret == 0);
2129 free(p);
2130 free($3);
2131 }
2132 ;
2133
2134/* identifier "." ... */
2135ComponentIdList:
2136 Identifier {
2137 $$ = $1;
2138 }
2139 | ComponentIdList '.' Identifier {
2140 int l1 = strlen($1);
2141 int l3 = strlen($3);
2142 $$ = malloc(l1 + 1 + l3 + 1);
2143 memcpy($$, $1, l1);
2144 $$[l1] = '.';
2145 memcpy($$ + l1 + 1, $3, l3);
2146 $$[l1 + 1 + l3] = '\0';
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08002147 free($1);
2148 free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002149 }
2150 ;
2151
2152
2153
2154/*
2155 * MARKERS
2156 */
2157
2158optMarker:
Lev Walkin9c974182004-09-15 11:59:51 +00002159 {
2160 $$.flags = EM_NOMARK;
2161 $$.default_value = 0;
2162 }
Lev Walkinf15320b2004-06-03 03:38:44 +00002163 | Marker { $$ = $1; }
2164 ;
2165
2166Marker:
2167 TOK_OPTIONAL {
Lev Walkin70853052005-11-26 11:21:55 +00002168 $$.flags = EM_OPTIONAL | EM_INDIRECT;
Lev Walkin9c974182004-09-15 11:59:51 +00002169 $$.default_value = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +00002170 }
Lev Walkin9c974182004-09-15 11:59:51 +00002171 | TOK_DEFAULT Value {
2172 $$.flags = EM_DEFAULT;
2173 $$.default_value = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00002174 }
2175 ;
2176
2177/*
2178 * Universal enumeration definition to use in INTEGER and ENUMERATED.
2179 * === EXAMPLE ===
2180 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
2181 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
2182 * === EOF ===
2183 */
2184/*
2185optUniverationDefinition:
2186 { $$ = 0; }
2187 | UniverationDefinition {
2188 $$ = $1;
2189 }
2190 ;
2191*/
2192
2193UniverationDefinition:
2194 '{' '}' {
Lev Walkina9532f42006-09-17 04:52:50 +00002195 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002196 checkmem($$);
2197 }
2198 | '{' UniverationList '}' {
2199 $$ = $2;
2200 }
2201 ;
2202
2203UniverationList:
2204 UniverationElement {
Lev Walkina9532f42006-09-17 04:52:50 +00002205 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002206 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00002207 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00002208 }
2209 | UniverationList ',' UniverationElement {
2210 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00002211 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002212 }
2213 ;
2214
2215UniverationElement:
2216 Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +00002217 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002218 checkmem($$);
2219 $$->expr_type = A1TC_UNIVERVAL;
2220 $$->meta_type = AMT_VALUE;
2221 $$->Identifier = $1;
2222 }
2223 | Identifier '(' SignedNumber ')' {
Lev Walkina9532f42006-09-17 04:52:50 +00002224 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002225 checkmem($$);
2226 $$->expr_type = A1TC_UNIVERVAL;
2227 $$->meta_type = AMT_VALUE;
2228 $$->Identifier = $1;
2229 $$->value = $3;
2230 }
2231 | Identifier '(' DefinedValue ')' {
Lev Walkina9532f42006-09-17 04:52:50 +00002232 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002233 checkmem($$);
2234 $$->expr_type = A1TC_UNIVERVAL;
2235 $$->meta_type = AMT_VALUE;
2236 $$->Identifier = $1;
2237 $$->value = $3;
2238 }
2239 | SignedNumber {
Lev Walkina9532f42006-09-17 04:52:50 +00002240 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002241 checkmem($$);
2242 $$->expr_type = A1TC_UNIVERVAL;
2243 $$->meta_type = AMT_VALUE;
2244 $$->value = $1;
2245 }
2246 | TOK_ThreeDots {
Lev Walkina9532f42006-09-17 04:52:50 +00002247 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002248 checkmem($$);
2249 $$->Identifier = strdup("...");
2250 checkmem($$->Identifier);
2251 $$->expr_type = A1TC_EXTENSIBLE;
2252 $$->meta_type = AMT_VALUE;
2253 }
2254 ;
2255
2256SignedNumber:
2257 TOK_number {
2258 $$ = asn1p_value_fromint($1);
2259 checkmem($$);
2260 }
2261 | TOK_number_negative {
2262 $$ = asn1p_value_fromint($1);
2263 checkmem($$);
2264 }
2265 ;
2266
Lev Walkinadf863f2006-09-05 16:18:34 +00002267RealValue:
2268 SignedNumber
2269 | TOK_realnumber {
2270 $$ = asn1p_value_fromdouble($1);
2271 checkmem($$);
2272 }
2273 ;
2274
Lev Walkinf15320b2004-06-03 03:38:44 +00002275/*
2276 * SEQUENCE definition.
2277 * === EXAMPLE ===
2278 * Struct1 ::= SEQUENCE {
2279 * memb1 Struct2,
2280 * memb2 SEQUENCE OF {
2281 * memb2-1 Struct 3
2282 * }
2283 * }
2284 * === EOF ===
2285 */
2286
2287
2288
2289/*
2290 * SET definition.
2291 * === EXAMPLE ===
2292 * Person ::= SET {
2293 * name [0] PrintableString (SIZE(1..20)),
2294 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2295 * }
2296 * === EOF ===
2297 */
2298
2299optTag:
2300 { memset(&$$, 0, sizeof($$)); }
2301 | Tag { $$ = $1; }
2302 ;
2303
2304Tag:
Lev Walkinc603f102005-01-23 09:51:44 +00002305 TagTypeValue TagPlicit {
Lev Walkinf15320b2004-06-03 03:38:44 +00002306 $$ = $1;
Lev Walkinc603f102005-01-23 09:51:44 +00002307 $$.tag_mode = $2.tag_mode;
Lev Walkinf15320b2004-06-03 03:38:44 +00002308 }
Lev Walkinc603f102005-01-23 09:51:44 +00002309 ;
2310
2311TagTypeValue:
2312 '[' TagClass TOK_number ']' {
2313 $$ = $2;
2314 $$.tag_value = $3;
2315 };
2316
2317TagClass:
2318 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2319 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2320 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2321 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2322 ;
2323
2324TagPlicit:
2325 { $$.tag_mode = TM_DEFAULT; }
2326 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2327 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
Lev Walkinf15320b2004-06-03 03:38:44 +00002328 ;
2329
2330TypeRefName:
2331 TOK_typereference {
2332 checkmem($1);
2333 $$ = $1;
2334 }
Lev Walkinf59d0752004-08-18 04:59:12 +00002335 | TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002336 checkmem($1);
2337 $$ = $1;
2338 }
2339 ;
2340
Lev Walkinf59d0752004-08-18 04:59:12 +00002341
Lev Walkinf15320b2004-06-03 03:38:44 +00002342ObjectClassReference:
Lev Walkinf59d0752004-08-18 04:59:12 +00002343 TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002344 checkmem($1);
2345 $$ = $1;
2346 }
2347 ;
2348
Lev Walkin83cac2f2004-09-22 16:03:36 +00002349optIdentifier:
2350 { $$ = 0; }
2351 | Identifier {
2352 $$ = $1;
2353 }
Lev Walkin8f294e02005-06-06 08:28:58 +00002354 ;
Lev Walkin83cac2f2004-09-22 16:03:36 +00002355
Lev Walkinf15320b2004-06-03 03:38:44 +00002356Identifier:
2357 TOK_identifier {
2358 checkmem($1);
2359 $$ = $1;
2360 }
2361 ;
2362
Lev Walkinf15320b2004-06-03 03:38:44 +00002363%%
2364
2365
2366/*
2367 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2368 */
2369static asn1p_value_t *
2370_convert_bitstring2binary(char *str, int base) {
2371 asn1p_value_t *val;
2372 int slen;
2373 int memlen;
2374 int baselen;
2375 int bits;
2376 uint8_t *binary_vector;
2377 uint8_t *bv_ptr;
2378 uint8_t cur_val;
2379
2380 assert(str);
2381 assert(str[0] == '\'');
2382
2383 switch(base) {
2384 case 'B':
2385 baselen = 1;
2386 break;
2387 case 'H':
2388 baselen = 4;
2389 break;
2390 default:
2391 assert(base == 'B' || base == 'H');
2392 errno = EINVAL;
2393 return NULL;
2394 }
2395
2396 slen = strlen(str);
2397 assert(str[slen - 1] == base);
2398 assert(str[slen - 2] == '\'');
2399
2400 memlen = slen / (8 / baselen); /* Conservative estimate */
2401
2402 bv_ptr = binary_vector = malloc(memlen + 1);
2403 if(bv_ptr == NULL)
2404 /* ENOMEM */
2405 return NULL;
2406
2407 cur_val = 0;
2408 bits = 0;
2409 while(*(++str) != '\'') {
2410 switch(baselen) {
2411 case 1:
2412 switch(*str) {
2413 case '1':
2414 cur_val |= 1 << (7 - (bits % 8));
2415 case '0':
2416 break;
2417 default:
2418 assert(!"_y UNREACH1");
2419 case ' ': case '\r': case '\n':
2420 continue;
2421 }
2422 break;
2423 case 4:
2424 switch(*str) {
2425 case '0': case '1': case '2': case '3': case '4':
2426 case '5': case '6': case '7': case '8': case '9':
2427 cur_val |= (*str - '0') << (4 - (bits % 8));
2428 break;
2429 case 'A': case 'B': case 'C':
2430 case 'D': case 'E': case 'F':
2431 cur_val |= ((*str - 'A') + 10)
2432 << (4 - (bits % 8));
2433 break;
2434 default:
2435 assert(!"_y UNREACH2");
2436 case ' ': case '\r': case '\n':
2437 continue;
2438 }
2439 break;
2440 }
2441
2442 bits += baselen;
2443 if((bits % 8) == 0) {
2444 *bv_ptr++ = cur_val;
2445 cur_val = 0;
2446 }
2447 }
2448
2449 *bv_ptr = cur_val;
2450 assert((bv_ptr - binary_vector) <= memlen);
2451
2452 val = asn1p_value_frombits(binary_vector, bits, 0);
2453 if(val == NULL) {
2454 free(binary_vector);
2455 }
2456
2457 return val;
2458}
2459
Lev Walkin2e9bd5c2005-08-13 09:07:11 +00002460/*
2461 * For unnamed types (used in old X.208 compliant modules)
2462 * generate some sort of interim names, to not to force human being to fix
2463 * the specification's compliance to modern ASN.1 standards.
2464 */
2465static void
2466_fixup_anonymous_identifier(asn1p_expr_t *expr) {
2467 char *p;
2468 assert(expr->Identifier == 0);
2469
2470 /*
2471 * Try to figure out the type name
2472 * without going too much into details
2473 */
2474 expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type);
2475 if(expr->reference && expr->reference->comp_count > 0)
2476 expr->Identifier = expr->reference->components[0].name;
2477
2478 fprintf(stderr,
2479 "WARNING: Line %d: expected lower-case member identifier, "
2480 "found an unnamed %s.\n"
2481 "WARNING: Obsolete X.208 syntax detected, "
2482 "please give the member a name.\n",
2483 yylineno, expr->Identifier ? expr->Identifier : "type");
2484
2485 if(!expr->Identifier)
2486 expr->Identifier = "unnamed";
2487 expr->Identifier = strdup(expr->Identifier);
2488 assert(expr->Identifier);
2489 /* Make a lowercase identifier from the type name */
2490 for(p = expr->Identifier; *p; p++) {
2491 switch(*p) {
2492 case 'A' ... 'Z': *p += 32; break;
2493 case ' ': *p = '_'; break;
2494 case '-': *p = '_'; break;
2495 }
2496 }
2497 fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". "
2498 "Name clash may occur later.\n",
2499 expr->Identifier);
2500}
2501
Lev Walkinf15320b2004-06-03 03:38:44 +00002502int
2503yyerror(const char *msg) {
Lev Walkin9d542d22006-03-14 16:31:37 +00002504 extern char *asn1p_text;
Lev Walkinf15320b2004-06-03 03:38:44 +00002505 fprintf(stderr,
2506 "ASN.1 grammar parse error "
2507 "near line %d (token \"%s\"): %s\n",
Lev Walkinceb20e72004-09-05 10:40:41 +00002508 yylineno, asn1p_text, msg);
Lev Walkinf15320b2004-06-03 03:38:44 +00002509 return -1;
2510}
2511