blob: 8289fa9af1ec28803606a8ff383154eb87215236 [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; \
51 root = asn1p_constraint_new(yylineno); \
52 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 Walkin57074f12006-03-16 05:11:14 +0000127%token <tv_opaque> TOK_whitespace /* A span of whitespace */
Lev Walkinf15320b2004-06-03 03:38:44 +0000128%token <tv_opaque> TOK_opaque /* opaque data (driven from .y) */
129%token <tv_str> TOK_bstring
130%token <tv_opaque> TOK_cstring
131%token <tv_str> TOK_hstring
132%token <tv_str> TOK_identifier
133%token <a_int> TOK_number
Lev Walkinadf863f2006-09-05 16:18:34 +0000134%token <a_int> TOK_number_negative
135%token <a_dbl> TOK_realnumber
Lev Walkind9574ae2005-03-24 16:22:35 +0000136%token <a_int> TOK_tuple
137%token <a_int> TOK_quadruple
Lev Walkinf15320b2004-06-03 03:38:44 +0000138%token <tv_str> TOK_typereference
Lev Walkinf59d0752004-08-18 04:59:12 +0000139%token <tv_str> TOK_capitalreference /* "CLASS1" */
Lev Walkinf15320b2004-06-03 03:38:44 +0000140%token <tv_str> TOK_typefieldreference /* "&Pork" */
141%token <tv_str> TOK_valuefieldreference /* "&id" */
Lev Walkin9d542d22006-03-14 16:31:37 +0000142%token <tv_str> TOK_Literal /* "BY" */
Lev Walkinf15320b2004-06-03 03:38:44 +0000143
144/*
145 * Token types representing ASN.1 standard keywords.
146 */
147%token TOK_ABSENT
148%token TOK_ABSTRACT_SYNTAX
149%token TOK_ALL
150%token TOK_ANY
151%token TOK_APPLICATION
152%token TOK_AUTOMATIC
153%token TOK_BEGIN
154%token TOK_BIT
155%token TOK_BMPString
156%token TOK_BOOLEAN
157%token TOK_BY
158%token TOK_CHARACTER
159%token TOK_CHOICE
160%token TOK_CLASS
161%token TOK_COMPONENT
162%token TOK_COMPONENTS
163%token TOK_CONSTRAINED
164%token TOK_CONTAINING
165%token TOK_DEFAULT
166%token TOK_DEFINITIONS
167%token TOK_DEFINED
168%token TOK_EMBEDDED
169%token TOK_ENCODED
Lev Walkinf59d0752004-08-18 04:59:12 +0000170%token TOK_ENCODING_CONTROL
Lev Walkinf15320b2004-06-03 03:38:44 +0000171%token TOK_END
172%token TOK_ENUMERATED
173%token TOK_EXPLICIT
174%token TOK_EXPORTS
175%token TOK_EXTENSIBILITY
176%token TOK_EXTERNAL
177%token TOK_FALSE
178%token TOK_FROM
179%token TOK_GeneralizedTime
180%token TOK_GeneralString
181%token TOK_GraphicString
182%token TOK_IA5String
183%token TOK_IDENTIFIER
184%token TOK_IMPLICIT
185%token TOK_IMPLIED
186%token TOK_IMPORTS
187%token TOK_INCLUDES
188%token TOK_INSTANCE
Lev Walkinf59d0752004-08-18 04:59:12 +0000189%token TOK_INSTRUCTIONS
Lev Walkinf15320b2004-06-03 03:38:44 +0000190%token TOK_INTEGER
191%token TOK_ISO646String
192%token TOK_MAX
193%token TOK_MIN
194%token TOK_MINUS_INFINITY
195%token TOK_NULL
196%token TOK_NumericString
197%token TOK_OBJECT
198%token TOK_ObjectDescriptor
199%token TOK_OCTET
200%token TOK_OF
201%token TOK_OPTIONAL
202%token TOK_PATTERN
203%token TOK_PDV
204%token TOK_PLUS_INFINITY
205%token TOK_PRESENT
206%token TOK_PrintableString
207%token TOK_PRIVATE
208%token TOK_REAL
209%token TOK_RELATIVE_OID
210%token TOK_SEQUENCE
211%token TOK_SET
212%token TOK_SIZE
213%token TOK_STRING
214%token TOK_SYNTAX
215%token TOK_T61String
216%token TOK_TAGS
217%token TOK_TeletexString
218%token TOK_TRUE
219%token TOK_TYPE_IDENTIFIER
220%token TOK_UNIQUE
221%token TOK_UNIVERSAL
222%token TOK_UniversalString
223%token TOK_UTCTime
224%token TOK_UTF8String
225%token TOK_VideotexString
226%token TOK_VisibleString
227%token TOK_WITH
228
Lev Walkinf1727152006-09-21 01:50:37 +0000229%nonassoc TOK_EXCEPT
Lev Walkinf59d0752004-08-18 04:59:12 +0000230%left '^' TOK_INTERSECTION
231%left '|' TOK_UNION
Lev Walkinf15320b2004-06-03 03:38:44 +0000232
233/* Misc tags */
234%token TOK_TwoDots /* .. */
235%token TOK_ThreeDots /* ... */
Lev Walkinf15320b2004-06-03 03:38:44 +0000236
237
238/*
239 * Types defined herein.
240 */
241%type <a_grammar> ModuleList
Lev Walkin866bd7f2006-09-14 10:35:20 +0000242%type <a_module> ModuleDefinition
243%type <a_module> ModuleBody
244%type <a_module> AssignmentList
245%type <a_module> Assignment
246%type <a_module> optModuleBody /* Optional */
247%type <a_module_flags> optModuleDefinitionFlags
248%type <a_module_flags> ModuleDefinitionFlags /* Set of FL */
249%type <a_module_flags> ModuleDefinitionFlag /* Single FL */
250%type <a_module> optImports
251%type <a_module> optExports
Lev Walkinf15320b2004-06-03 03:38:44 +0000252%type <a_module> ImportsDefinition
Lev Walkin4a4543f2006-10-13 12:37:39 +0000253%type <a_module> optImportsBundleSet
Lev Walkinf15320b2004-06-03 03:38:44 +0000254%type <a_module> ImportsBundleSet
255%type <a_xports> ImportsBundle
256%type <a_xports> ImportsList
257%type <a_xports> ExportsDefinition
258%type <a_xports> ExportsBody
259%type <a_expr> ImportsElement
260%type <a_expr> ExportsElement
Lev Walkinf15320b2004-06-03 03:38:44 +0000261%type <a_expr> ExtensionAndException
Lev Walkina9532f42006-09-17 04:52:50 +0000262%type <a_expr> Type
Lev Walkin070a52d2004-08-22 03:19:54 +0000263%type <a_expr> TypeDeclaration
Lev Walkin4696c742005-08-22 12:23:54 +0000264%type <a_expr> TypeDeclarationSet
Lev Walkinf15320b2004-06-03 03:38:44 +0000265%type <a_ref> ComplexTypeReference
266%type <a_ref> ComplexTypeReferenceAmpList
267%type <a_refcomp> ComplexTypeReferenceElement
Lev Walkind370e9f2006-03-16 10:03:35 +0000268%type <a_refcomp> PrimitiveFieldReference
Lev Walkin9c2285a2006-03-09 08:49:26 +0000269%type <a_expr> FieldSpec
270%type <a_ref> FieldName
271%type <a_ref> DefinedObjectClass
Lev Walkinf15320b2004-06-03 03:38:44 +0000272%type <a_expr> ClassField
Lev Walkin9c2285a2006-03-09 08:49:26 +0000273%type <a_expr> ObjectClass
Lev Walkinf15320b2004-06-03 03:38:44 +0000274%type <a_expr> DataTypeReference /* Type1 ::= Type2 */
Lev Walkin0c0bca62006-03-21 04:48:15 +0000275%type <a_expr> DefinedType
Lev Walkin557f27d2006-03-21 07:46:48 +0000276%type <a_constr> ValueSet /* {a|b|c}*/
277%type <a_expr> ValueSetTypeAssignment /* Val INTEGER ::= {1|2} */
Lev Walkinf15320b2004-06-03 03:38:44 +0000278%type <a_expr> ValueDefinition /* val INTEGER ::= 1*/
Lev Walkin9c974182004-09-15 11:59:51 +0000279%type <a_value> Value
Lev Walkin0c0bca62006-03-21 04:48:15 +0000280%type <a_value> SimpleValue
Lev Walkinf15320b2004-06-03 03:38:44 +0000281%type <a_value> DefinedValue
282%type <a_value> SignedNumber
Lev Walkinadf863f2006-09-05 16:18:34 +0000283%type <a_value> RealValue
Lev Walkin144db9b2004-10-12 23:26:53 +0000284%type <a_expr> optComponentTypeLists
Lev Walkin070a52d2004-08-22 03:19:54 +0000285%type <a_expr> ComponentTypeLists
286%type <a_expr> ComponentType
287%type <a_expr> AlternativeTypeLists
288%type <a_expr> AlternativeType
Lev Walkinf15320b2004-06-03 03:38:44 +0000289%type <a_expr> UniverationDefinition
290%type <a_expr> UniverationList
291%type <a_expr> UniverationElement
292%type <tv_str> TypeRefName
293%type <tv_str> ObjectClassReference
Lev Walkinf15320b2004-06-03 03:38:44 +0000294%type <tv_str> Identifier
Lev Walkin83cac2f2004-09-22 16:03:36 +0000295%type <tv_str> optIdentifier
Lev Walkinf15320b2004-06-03 03:38:44 +0000296%type <a_parg> ParameterArgumentName
297%type <a_plist> ParameterArgumentList
Lev Walkin5045dfa2006-03-21 09:41:28 +0000298%type <a_expr> ActualParameter
299%type <a_expr> ActualParameterList
Lev Walkin1ed22092005-08-12 10:06:17 +0000300%type <a_aid> AssignedIdentifier /* OID/DefinedValue */
Lev Walkinf15320b2004-06-03 03:38:44 +0000301%type <a_oid> ObjectIdentifier /* OID */
302%type <a_oid> optObjectIdentifier /* Optional OID */
303%type <a_oid> ObjectIdentifierBody
304%type <a_oid_arc> ObjectIdentifierElement
305%type <a_expr> BasicType
306%type <a_type> BasicTypeId
307%type <a_type> BasicTypeId_UniverationCompatible
308%type <a_type> BasicString
309%type <tv_opaque> Opaque
Lev Walkinc603f102005-01-23 09:51:44 +0000310%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
311%type <a_tag> TagClass TagTypeValue TagPlicit
Lev Walkinf15320b2004-06-03 03:38:44 +0000312%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
313%type <a_constr> optConstraints
Lev Walkina9532f42006-09-17 04:52:50 +0000314%type <a_constr> Constraint
315%type <a_constr> SubtypeConstraint
316%type <a_constr> GeneralConstraint
Lev Walkinf59d0752004-08-18 04:59:12 +0000317%type <a_constr> SetOfConstraints
318%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
319%type <a_constr> ElementSetSpec /* 1..2,...,3 */
Lev Walkinf1727152006-09-21 01:50:37 +0000320%type <a_constr> Unions
321%type <a_constr> Intersections
322%type <a_constr> IntersectionElements
Lev Walkinf15320b2004-06-03 03:38:44 +0000323%type <a_constr> ConstraintSubtypeElement /* 1..2 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000324%type <a_constr> SimpleTableConstraint
Lev Walkina9532f42006-09-17 04:52:50 +0000325%type <a_constr> UserDefinedConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +0000326%type <a_constr> TableConstraint
Lev Walkina9532f42006-09-17 04:52:50 +0000327%type <a_constr> ContentsConstraint
Lev Walkin5c541f12006-10-18 18:40:14 +0000328%type <a_constr> PatternConstraint
Lev Walkine596bf02005-03-28 15:01:27 +0000329%type <a_constr> InnerTypeConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +0000330%type <a_constr> WithComponentsList
331%type <a_constr> WithComponentsElement
332%type <a_constr> ComponentRelationConstraint
333%type <a_constr> AtNotationList
334%type <a_ref> AtNotationElement
Lev Walkinff7dd142005-03-20 12:58:00 +0000335%type <a_value> SingleValue
336%type <a_value> ContainedSubtype
Lev Walkinf15320b2004-06-03 03:38:44 +0000337%type <a_ctype> ConstraintSpec
338%type <a_ctype> ConstraintRangeSpec
Lev Walkin1e448d32005-03-24 14:26:38 +0000339%type <a_value> RestrictedCharacterStringValue
Lev Walkinf15320b2004-06-03 03:38:44 +0000340%type <a_wsynt> optWithSyntax
341%type <a_wsynt> WithSyntax
Lev Walkin9d542d22006-03-14 16:31:37 +0000342%type <a_wsynt> WithSyntaxList
343%type <a_wchunk> WithSyntaxToken
Lev Walkinf15320b2004-06-03 03:38:44 +0000344%type <a_marker> optMarker Marker
345%type <a_int> optUnique
346%type <a_pres> optPresenceConstraint PresenceConstraint
347%type <tv_str> ComponentIdList
Lev Walkinef625402005-09-05 05:17:57 +0000348%type <a_int> NSTD_IndirectMarker
Lev Walkinf15320b2004-06-03 03:38:44 +0000349
350
351%%
352
353
354ParsedGrammar:
355 ModuleList {
356 *(void **)param = $1;
357 }
358 ;
359
360ModuleList:
Lev Walkin866bd7f2006-09-14 10:35:20 +0000361 ModuleDefinition {
Lev Walkinf15320b2004-06-03 03:38:44 +0000362 $$ = asn1p_new();
363 checkmem($$);
364 TQ_ADD(&($$->modules), $1, mod_next);
365 }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000366 | ModuleList ModuleDefinition {
Lev Walkinf15320b2004-06-03 03:38:44 +0000367 $$ = $1;
368 TQ_ADD(&($$->modules), $2, mod_next);
369 }
370 ;
371
372/*
373 * ASN module definition.
374 * === EXAMPLE ===
375 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
376 * BEGIN
377 * ...
378 * END
379 * === EOF ===
380 */
381
Lev Walkin866bd7f2006-09-14 10:35:20 +0000382ModuleDefinition:
Lev Walkina9532f42006-09-17 04:52:50 +0000383 TypeRefName { currentModule = asn1p_module_new(); }
384 optObjectIdentifier TOK_DEFINITIONS
Lev Walkin866bd7f2006-09-14 10:35:20 +0000385 optModuleDefinitionFlags
Lev Walkinf15320b2004-06-03 03:38:44 +0000386 TOK_PPEQ TOK_BEGIN
Lev Walkin866bd7f2006-09-14 10:35:20 +0000387 optModuleBody
Lev Walkinf15320b2004-06-03 03:38:44 +0000388 TOK_END {
389
Lev Walkina9532f42006-09-17 04:52:50 +0000390 $$ = currentModule;
391
392 if($8) {
393 asn1p_module_t tmp = *($$);
394 *($$) = *($8);
395 *($8) = tmp;
396 asn1p_module_free($8);
Lev Walkinf15320b2004-06-03 03:38:44 +0000397 } else {
398 /* There's a chance that a module is just plain empty */
Lev Walkinf15320b2004-06-03 03:38:44 +0000399 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000400
Lev Walkin1ed22092005-08-12 10:06:17 +0000401 $$->ModuleName = $1;
Lev Walkina9532f42006-09-17 04:52:50 +0000402 $$->module_oid = $3;
403 $$->module_flags = $5;
Lev Walkinf15320b2004-06-03 03:38:44 +0000404 }
405 ;
406
407/*
408 * Object Identifier Definition
409 * { iso member-body(2) 3 }
410 */
411optObjectIdentifier:
412 { $$ = 0; }
413 | ObjectIdentifier { $$ = $1; }
414 ;
415
416ObjectIdentifier:
417 '{' ObjectIdentifierBody '}' {
418 $$ = $2;
419 }
420 | '{' '}' {
421 $$ = 0;
422 }
423 ;
424
425ObjectIdentifierBody:
426 ObjectIdentifierElement {
427 $$ = asn1p_oid_new();
428 asn1p_oid_add_arc($$, &$1);
429 if($1.name)
430 free($1.name);
431 }
432 | ObjectIdentifierBody ObjectIdentifierElement {
433 $$ = $1;
434 asn1p_oid_add_arc($$, &$2);
435 if($2.name)
436 free($2.name);
437 }
438 ;
439
440ObjectIdentifierElement:
441 Identifier { /* iso */
442 $$.name = $1;
443 $$.number = -1;
444 }
445 | Identifier '(' TOK_number ')' { /* iso(1) */
446 $$.name = $1;
447 $$.number = $3;
448 }
449 | TOK_number { /* 1 */
450 $$.name = 0;
451 $$.number = $1;
452 }
453 ;
454
455/*
456 * Optional module flags.
457 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000458optModuleDefinitionFlags:
Lev Walkinf15320b2004-06-03 03:38:44 +0000459 { $$ = MSF_NOFLAGS; }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000460 | ModuleDefinitionFlags {
Lev Walkinf15320b2004-06-03 03:38:44 +0000461 $$ = $1;
462 }
463 ;
464
465/*
466 * Module flags.
467 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000468ModuleDefinitionFlags:
469 ModuleDefinitionFlag {
Lev Walkinf15320b2004-06-03 03:38:44 +0000470 $$ = $1;
471 }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000472 | ModuleDefinitionFlags ModuleDefinitionFlag {
Lev Walkinf15320b2004-06-03 03:38:44 +0000473 $$ = $1 | $2;
474 }
475 ;
476
477/*
478 * Single module flag.
479 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000480ModuleDefinitionFlag:
Lev Walkinf15320b2004-06-03 03:38:44 +0000481 TOK_EXPLICIT TOK_TAGS {
482 $$ = MSF_EXPLICIT_TAGS;
483 }
484 | TOK_IMPLICIT TOK_TAGS {
485 $$ = MSF_IMPLICIT_TAGS;
486 }
487 | TOK_AUTOMATIC TOK_TAGS {
488 $$ = MSF_AUTOMATIC_TAGS;
489 }
490 | TOK_EXTENSIBILITY TOK_IMPLIED {
491 $$ = MSF_EXTENSIBILITY_IMPLIED;
492 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000493 /* EncodingReferenceDefault */
494 | TOK_capitalreference TOK_INSTRUCTIONS {
495 /* X.680Amd1 specifies TAG and XER */
496 if(strcmp($1, "TAG") == 0) {
497 $$ = MSF_TAG_INSTRUCTIONS;
498 } else if(strcmp($1, "XER") == 0) {
499 $$ = MSF_XER_INSTRUCTIONS;
500 } else {
501 fprintf(stderr,
502 "WARNING: %s INSTRUCTIONS at line %d: "
503 "Unrecognized encoding reference\n",
504 $1, yylineno);
505 $$ = MSF_unk_INSTRUCTIONS;
506 }
507 free($1);
508 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000509 ;
510
511/*
512 * Optional module body.
513 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000514optModuleBody:
Lev Walkinf15320b2004-06-03 03:38:44 +0000515 { $$ = 0; }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000516 | ModuleBody {
Lev Walkinf15320b2004-06-03 03:38:44 +0000517 $$ = $1;
518 }
519 ;
520
521/*
522 * ASN.1 Module body.
523 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000524ModuleBody:
525 optExports optImports AssignmentList {
526 $$ = asn1p_module_new();
527 AL_IMPORT($$, exports, $1, xp_next);
528 AL_IMPORT($$, imports, $2, xp_next);
529 AL_IMPORT($$, members, $3, next);
Lev Walkinf15320b2004-06-03 03:38:44 +0000530 }
531 ;
532
Lev Walkin866bd7f2006-09-14 10:35:20 +0000533AssignmentList:
534 Assignment {
535 $$ = $1;
536 }
537 | AssignmentList Assignment {
538 if($1) {
539 $$ = $1;
540 } else {
541 $$ = $2;
542 break;
543 }
544 AL_IMPORT($$, members, $2, next);
545 }
546 ;
547
548
Lev Walkinf15320b2004-06-03 03:38:44 +0000549/*
550 * One of the elements of ASN.1 module specification.
551 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000552Assignment:
553 DataTypeReference {
Lev Walkinf15320b2004-06-03 03:38:44 +0000554 $$ = asn1p_module_new();
555 checkmem($$);
556 assert($1->expr_type != A1TC_INVALID);
557 assert($1->meta_type != AMT_INVALID);
558 TQ_ADD(&($$->members), $1, next);
559 }
560 | ValueDefinition {
561 $$ = asn1p_module_new();
562 checkmem($$);
563 assert($1->expr_type != A1TC_INVALID);
564 assert($1->meta_type != AMT_INVALID);
565 TQ_ADD(&($$->members), $1, next);
566 }
567 /*
568 * Value set definition
569 * === EXAMPLE ===
570 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
571 * === EOF ===
572 */
Lev Walkin557f27d2006-03-21 07:46:48 +0000573 | ValueSetTypeAssignment {
Lev Walkinf15320b2004-06-03 03:38:44 +0000574 $$ = asn1p_module_new();
575 checkmem($$);
576 assert($1->expr_type != A1TC_INVALID);
577 assert($1->meta_type != AMT_INVALID);
578 TQ_ADD(&($$->members), $1, next);
579 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000580 | TOK_ENCODING_CONTROL TOK_capitalreference
581 { asn1p_lexer_hack_push_encoding_control(); }
582 {
583 fprintf(stderr,
584 "WARNING: ENCODING-CONTROL %s "
585 "specification at line %d ignored\n",
586 $2, yylineno);
587 free($2);
588 $$ = 0;
589 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000590
591 /*
592 * Erroneous attemps
593 */
594 | BasicString {
595 return yyerror(
Lev Walkin70853052005-11-26 11:21:55 +0000596 "Attempt to redefine a standard basic string type, "
597 "please comment out or remove this type redefinition.");
Lev Walkinf15320b2004-06-03 03:38:44 +0000598 }
599 ;
600
601/*
602 * === EXAMPLE ===
603 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
604 * === EOF ===
605 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000606optImports:
607 { $$ = 0; }
608 | ImportsDefinition;
609
Lev Walkinf15320b2004-06-03 03:38:44 +0000610ImportsDefinition:
Lev Walkin4a4543f2006-10-13 12:37:39 +0000611 TOK_IMPORTS optImportsBundleSet ';' {
Lev Walkin1ed22092005-08-12 10:06:17 +0000612 if(!saved_aid && 0)
613 return yyerror("Unterminated IMPORTS FROM, "
614 "expected semicolon ';'");
615 saved_aid = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +0000616 $$ = $2;
617 }
618 /*
619 * Some error cases.
620 */
621 | TOK_IMPORTS TOK_FROM /* ... */ {
622 return yyerror("Empty IMPORTS list");
623 }
624 ;
625
Lev Walkin4a4543f2006-10-13 12:37:39 +0000626optImportsBundleSet:
627 { $$ = asn1p_module_new(); }
628 | ImportsBundleSet;
629
Lev Walkinf15320b2004-06-03 03:38:44 +0000630ImportsBundleSet:
631 ImportsBundle {
632 $$ = asn1p_module_new();
633 checkmem($$);
634 TQ_ADD(&($$->imports), $1, xp_next);
635 }
636 | ImportsBundleSet ImportsBundle {
637 $$ = $1;
638 TQ_ADD(&($$->imports), $2, xp_next);
639 }
640 ;
641
Lev Walkin1ed22092005-08-12 10:06:17 +0000642AssignedIdentifier:
643 { memset(&$$, 0, sizeof($$)); }
644 | ObjectIdentifier { $$.oid = $1; };
645 /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
646
Lev Walkinf15320b2004-06-03 03:38:44 +0000647ImportsBundle:
Lev Walkin1ed22092005-08-12 10:06:17 +0000648 ImportsList TOK_FROM TypeRefName AssignedIdentifier {
Lev Walkinf15320b2004-06-03 03:38:44 +0000649 $$ = $1;
Lev Walkin1ed22092005-08-12 10:06:17 +0000650 $$->fromModuleName = $3;
651 $$->identifier = $4;
652 /* This stupid thing is used for look-back hack. */
653 saved_aid = $$->identifier.oid ? 0 : &($$->identifier);
Lev Walkinf15320b2004-06-03 03:38:44 +0000654 checkmem($$);
655 }
656 ;
657
658ImportsList:
659 ImportsElement {
660 $$ = asn1p_xports_new();
661 checkmem($$);
662 TQ_ADD(&($$->members), $1, next);
663 }
664 | ImportsList ',' ImportsElement {
665 $$ = $1;
666 TQ_ADD(&($$->members), $3, next);
667 }
668 ;
669
670ImportsElement:
671 TypeRefName {
Lev Walkina9532f42006-09-17 04:52:50 +0000672 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000673 checkmem($$);
674 $$->Identifier = $1;
675 $$->expr_type = A1TC_REFERENCE;
676 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000677 | TypeRefName '{' '}' { /* Completely equivalent to above */
Lev Walkina9532f42006-09-17 04:52:50 +0000678 $$ = NEW_EXPR();
Lev Walkin144db9b2004-10-12 23:26:53 +0000679 checkmem($$);
680 $$->Identifier = $1;
681 $$->expr_type = A1TC_REFERENCE;
682 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000683 | Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +0000684 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000685 checkmem($$);
686 $$->Identifier = $1;
687 $$->expr_type = A1TC_REFERENCE;
688 }
689 ;
690
Lev Walkin866bd7f2006-09-14 10:35:20 +0000691
692optExports:
693 { $$ = 0; }
694 | ExportsDefinition {
695 $$ = asn1p_module_new();
696 checkmem($$);
697 if($1) {
698 TQ_ADD(&($$->exports), $1, xp_next);
699 } else {
700 /* "EXPORTS ALL;" */
701 }
702 }
703 ;
704
Lev Walkinf15320b2004-06-03 03:38:44 +0000705ExportsDefinition:
706 TOK_EXPORTS ExportsBody ';' {
707 $$ = $2;
708 }
709 | TOK_EXPORTS TOK_ALL ';' {
710 $$ = 0;
711 }
712 | TOK_EXPORTS ';' {
713 /* Empty EXPORTS clause effectively prohibits export. */
714 $$ = asn1p_xports_new();
715 checkmem($$);
716 }
717 ;
718
719ExportsBody:
720 ExportsElement {
721 $$ = asn1p_xports_new();
722 assert($$);
723 TQ_ADD(&($$->members), $1, next);
724 }
725 | ExportsBody ',' ExportsElement {
726 $$ = $1;
727 TQ_ADD(&($$->members), $3, next);
728 }
729 ;
730
731ExportsElement:
732 TypeRefName {
Lev Walkina9532f42006-09-17 04:52:50 +0000733 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000734 checkmem($$);
735 $$->Identifier = $1;
736 $$->expr_type = A1TC_EXPORTVAR;
737 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000738 | TypeRefName '{' '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000739 $$ = NEW_EXPR();
Lev Walkin144db9b2004-10-12 23:26:53 +0000740 checkmem($$);
741 $$->Identifier = $1;
742 $$->expr_type = A1TC_EXPORTVAR;
743 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000744 | Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +0000745 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000746 checkmem($$);
747 $$->Identifier = $1;
748 $$->expr_type = A1TC_EXPORTVAR;
749 }
750 ;
751
752
Lev Walkin418298d2006-07-13 08:24:20 +0000753ValueSet: '{' ElementSetSpecs '}' { $$ = $2; };
Lev Walkin557f27d2006-03-21 07:46:48 +0000754
755ValueSetTypeAssignment:
756 TypeRefName DefinedType TOK_PPEQ ValueSet {
Lev Walkinf15320b2004-06-03 03:38:44 +0000757 $$ = $2;
758 assert($$->Identifier == 0);
759 $$->Identifier = $1;
760 $$->meta_type = AMT_VALUESET;
Lev Walkin557f27d2006-03-21 07:46:48 +0000761 $$->constraints = $4;
Lev Walkinf15320b2004-06-03 03:38:44 +0000762 }
763 ;
764
Lev Walkin0c0bca62006-03-21 04:48:15 +0000765DefinedType:
766 BasicType {
767 $$ = $1;
768 }
769 /*
770 * A DefinedType reference.
771 * "CLASS1.&id.&id2"
772 * or
773 * "Module.Type"
774 * or
775 * "Module.identifier"
776 * or
777 * "Type"
778 */
779 | ComplexTypeReference {
Lev Walkina9532f42006-09-17 04:52:50 +0000780 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000781 checkmem($$);
782 $$->reference = $1;
783 $$->expr_type = A1TC_REFERENCE;
784 $$->meta_type = AMT_TYPEREF;
785 }
Lev Walkin0c0bca62006-03-21 04:48:15 +0000786 /*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000787 * A parameterized assignment.
Lev Walkin0c0bca62006-03-21 04:48:15 +0000788 */
Lev Walkin5045dfa2006-03-21 09:41:28 +0000789 | ComplexTypeReference '{' ActualParameterList '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000790 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000791 checkmem($$);
Lev Walkin0c0bca62006-03-21 04:48:15 +0000792 $$->reference = $1;
793 $$->rhs_pspecs = $3;
794 $$->expr_type = A1TC_REFERENCE;
795 $$->meta_type = AMT_TYPEREF;
Lev Walkinf15320b2004-06-03 03:38:44 +0000796 }
797 ;
798
Lev Walkinf15320b2004-06-03 03:38:44 +0000799/*
800 * Data Type Reference.
801 * === EXAMPLE ===
802 * Type3 ::= CHOICE { a Type1, b Type 2 }
803 * === EOF ===
804 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000805DataTypeReference:
806 /*
807 * Optionally tagged type definition.
808 */
Lev Walkin9c2285a2006-03-09 08:49:26 +0000809 TypeRefName TOK_PPEQ Type {
Lev Walkinaf120f72004-09-14 02:36:39 +0000810 $$ = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000811 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000812 assert($$->expr_type);
813 assert($$->meta_type);
814 }
Lev Walkin9c2285a2006-03-09 08:49:26 +0000815 | TypeRefName TOK_PPEQ ObjectClass {
Lev Walkinf15320b2004-06-03 03:38:44 +0000816 $$ = $3;
817 $$->Identifier = $1;
818 assert($$->expr_type == A1TC_CLASSDEF);
Lev Walkin9c2285a2006-03-09 08:49:26 +0000819 assert($$->meta_type == AMT_OBJECTCLASS);
Lev Walkinf15320b2004-06-03 03:38:44 +0000820 }
821 /*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000822 * Parameterized <Type> declaration:
Lev Walkinf15320b2004-06-03 03:38:44 +0000823 * === EXAMPLE ===
824 * SIGNED { ToBeSigned } ::= SEQUENCE {
825 * toBeSigned ToBeSigned,
826 * algorithm AlgorithmIdentifier,
827 * signature BIT STRING
828 * }
829 * === EOF ===
830 */
Lev Walkin070a52d2004-08-22 03:19:54 +0000831 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000832 $$ = $6;
Lev Walkin5045dfa2006-03-21 09:41:28 +0000833 $$->Identifier = $1;
834 $$->lhs_params = $3;
835 }
836 /* Parameterized CLASS declaration */
837 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ ObjectClass {
838 $$ = $6;
Lev Walkinf15320b2004-06-03 03:38:44 +0000839 $$->Identifier = $1;
Lev Walkina00d6b32006-03-21 03:40:38 +0000840 $$->lhs_params = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000841 }
842 ;
843
844ParameterArgumentList:
845 ParameterArgumentName {
846 int ret;
847 $$ = asn1p_paramlist_new(yylineno);
848 checkmem($$);
849 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
850 checkmem(ret == 0);
851 if($1.governor) asn1p_ref_free($1.governor);
852 if($1.argument) free($1.argument);
853 }
854 | ParameterArgumentList ',' ParameterArgumentName {
855 int ret;
856 $$ = $1;
857 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
858 checkmem(ret == 0);
859 if($3.governor) asn1p_ref_free($3.governor);
860 if($3.argument) free($3.argument);
861 }
862 ;
863
864ParameterArgumentName:
865 TypeRefName {
866 $$.governor = NULL;
867 $$.argument = $1;
868 }
869 | TypeRefName ':' Identifier {
870 int ret;
871 $$.governor = asn1p_ref_new(yylineno);
872 ret = asn1p_ref_add_component($$.governor, $1, 0);
873 checkmem(ret == 0);
874 $$.argument = $3;
875 }
Lev Walkinc8092cb2005-02-18 16:34:21 +0000876 | TypeRefName ':' TypeRefName {
877 int ret;
878 $$.governor = asn1p_ref_new(yylineno);
879 ret = asn1p_ref_add_component($$.governor, $1, 0);
880 checkmem(ret == 0);
881 $$.argument = $3;
882 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000883 | BasicTypeId ':' Identifier {
884 int ret;
885 $$.governor = asn1p_ref_new(yylineno);
886 ret = asn1p_ref_add_component($$.governor,
887 ASN_EXPR_TYPE2STR($1), 1);
888 checkmem(ret == 0);
889 $$.argument = $3;
890 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000891 | BasicTypeId ':' TypeRefName {
892 int ret;
893 $$.governor = asn1p_ref_new(yylineno);
894 ret = asn1p_ref_add_component($$.governor,
895 ASN_EXPR_TYPE2STR($1), 1);
896 checkmem(ret == 0);
897 $$.argument = $3;
898 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000899 ;
900
Lev Walkin5045dfa2006-03-21 09:41:28 +0000901ActualParameterList:
902 ActualParameter {
Lev Walkina9532f42006-09-17 04:52:50 +0000903 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000904 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000905 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000906 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000907 | ActualParameterList ',' ActualParameter {
Lev Walkinf15320b2004-06-03 03:38:44 +0000908 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000909 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000910 }
911 ;
912
Lev Walkin5045dfa2006-03-21 09:41:28 +0000913ActualParameter:
Lev Walkin070a52d2004-08-22 03:19:54 +0000914 Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000915 $$ = $1;
916 }
Lev Walkin0c0bca62006-03-21 04:48:15 +0000917 | SimpleValue {
Lev Walkina9532f42006-09-17 04:52:50 +0000918 $$ = NEW_EXPR();
Lev Walkin0c0bca62006-03-21 04:48:15 +0000919 checkmem($$);
920 $$->Identifier = "?";
921 $$->expr_type = A1TC_REFERENCE;
922 $$->meta_type = AMT_VALUE;
923 $$->value = $1;
924 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000925 | Identifier {
Lev Walkina00d6b32006-03-21 03:40:38 +0000926 asn1p_ref_t *ref;
Lev Walkina9532f42006-09-17 04:52:50 +0000927 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000928 checkmem($$);
929 $$->Identifier = $1;
930 $$->expr_type = A1TC_REFERENCE;
931 $$->meta_type = AMT_VALUE;
Lev Walkina00d6b32006-03-21 03:40:38 +0000932 ref = asn1p_ref_new(yylineno);
933 asn1p_ref_add_component(ref, $1, RLT_lowercase);
934 $$->value = asn1p_value_fromref(ref, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +0000935 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000936 | ValueSet {
Lev Walkina9532f42006-09-17 04:52:50 +0000937 $$ = NEW_EXPR();
Lev Walkin5045dfa2006-03-21 09:41:28 +0000938 $$->expr_type = A1TC_VALUESET;
939 $$->meta_type = AMT_VALUESET;
940 $$->constraints = $1;
941 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000942 ;
943
944/*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000945 | '{' ActualParameter '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000946 $$ = NEW_EXPR();
Lev Walkinc8092cb2005-02-18 16:34:21 +0000947 checkmem($$);
948 asn1p_expr_add($$, $2);
949 $$->expr_type = A1TC_PARAMETRIZED;
950 $$->meta_type = AMT_TYPE;
951 }
952 ;
953*/
954
955/*
Lev Walkinf15320b2004-06-03 03:38:44 +0000956 * A collection of constructed data type members.
957 */
Lev Walkin144db9b2004-10-12 23:26:53 +0000958optComponentTypeLists:
Lev Walkina9532f42006-09-17 04:52:50 +0000959 { $$ = NEW_EXPR(); }
Lev Walkin144db9b2004-10-12 23:26:53 +0000960 | ComponentTypeLists { $$ = $1; };
961
Lev Walkin070a52d2004-08-22 03:19:54 +0000962ComponentTypeLists:
963 ComponentType {
Lev Walkina9532f42006-09-17 04:52:50 +0000964 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000965 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000966 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000967 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000968 | ComponentTypeLists ',' ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +0000969 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000970 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000971 }
972 ;
973
Lev Walkin070a52d2004-08-22 03:19:54 +0000974ComponentType:
Lev Walkinaf120f72004-09-14 02:36:39 +0000975 Identifier Type optMarker {
Lev Walkin070a52d2004-08-22 03:19:54 +0000976 $$ = $2;
977 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +0000978 $$->Identifier = $1;
Lev Walkinef625402005-09-05 05:17:57 +0000979 $3.flags |= $$->marker.flags;
Lev Walkin070a52d2004-08-22 03:19:54 +0000980 $$->marker = $3;
981 }
Lev Walkinef625402005-09-05 05:17:57 +0000982 | Type optMarker {
983 $$ = $1;
984 $2.flags |= $$->marker.flags;
985 $$->marker = $2;
986 _fixup_anonymous_identifier($$);
987 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000988 | TOK_COMPONENTS TOK_OF Type {
Lev Walkina9532f42006-09-17 04:52:50 +0000989 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +0000990 checkmem($$);
991 $$->meta_type = $3->meta_type;
992 $$->expr_type = A1TC_COMPONENTS_OF;
Lev Walkin1004aa92004-09-08 00:28:11 +0000993 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +0000994 }
995 | ExtensionAndException {
996 $$ = $1;
997 }
998 ;
999
1000AlternativeTypeLists:
1001 AlternativeType {
Lev Walkina9532f42006-09-17 04:52:50 +00001002 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001003 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00001004 asn1p_expr_add($$, $1);
Lev Walkin070a52d2004-08-22 03:19:54 +00001005 }
1006 | AlternativeTypeLists ',' AlternativeType {
1007 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001008 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +00001009 }
1010 ;
1011
1012AlternativeType:
Lev Walkinaf120f72004-09-14 02:36:39 +00001013 Identifier Type {
Lev Walkin070a52d2004-08-22 03:19:54 +00001014 $$ = $2;
1015 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +00001016 $$->Identifier = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001017 }
1018 | ExtensionAndException {
1019 $$ = $1;
1020 }
Lev Walkin2e9bd5c2005-08-13 09:07:11 +00001021 | Type {
1022 $$ = $1;
1023 _fixup_anonymous_identifier($$);
1024 }
Lev Walkin070a52d2004-08-22 03:19:54 +00001025 ;
1026
Lev Walkin9c2285a2006-03-09 08:49:26 +00001027ObjectClass:
1028 TOK_CLASS '{' FieldSpec '}' optWithSyntax {
Lev Walkinf15320b2004-06-03 03:38:44 +00001029 $$ = $3;
1030 checkmem($$);
1031 $$->with_syntax = $5;
1032 assert($$->expr_type == A1TC_CLASSDEF);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001033 assert($$->meta_type == AMT_OBJECTCLASS);
Lev Walkinf15320b2004-06-03 03:38:44 +00001034 }
1035 ;
1036
1037optUnique:
1038 { $$ = 0; }
1039 | TOK_UNIQUE { $$ = 1; }
1040 ;
1041
Lev Walkin9c2285a2006-03-09 08:49:26 +00001042FieldSpec:
Lev Walkinf15320b2004-06-03 03:38:44 +00001043 ClassField {
Lev Walkina9532f42006-09-17 04:52:50 +00001044 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001045 checkmem($$);
1046 $$->expr_type = A1TC_CLASSDEF;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001047 $$->meta_type = AMT_OBJECTCLASS;
Lev Walkin1004aa92004-09-08 00:28:11 +00001048 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001049 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001050 | FieldSpec ',' ClassField {
Lev Walkinf15320b2004-06-03 03:38:44 +00001051 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001052 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001053 }
1054 ;
1055
Lev Walkin9c2285a2006-03-09 08:49:26 +00001056 /* X.681 */
Lev Walkinf15320b2004-06-03 03:38:44 +00001057ClassField:
Lev Walkin9c2285a2006-03-09 08:49:26 +00001058
1059 /* TypeFieldSpec ::= typefieldreference TypeOptionalitySpec? */
1060 TOK_typefieldreference optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001061 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001062 checkmem($$);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001063 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001064 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001065 $$->expr_type = A1TC_CLASSFIELD_TFS; /* TypeFieldSpec */
Lev Walkinf15320b2004-06-03 03:38:44 +00001066 $$->marker = $2;
1067 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001068
1069 /* FixedTypeValueFieldSpec ::= valuefieldreference Type UNIQUE ? ValueOptionalitySpec ? */
1070 | TOK_valuefieldreference Type optUnique optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001071 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001072 $$->Identifier = $1;
1073 $$->meta_type = AMT_OBJECTFIELD;
1074 $$->expr_type = A1TC_CLASSFIELD_FTVFS; /* FixedTypeValueFieldSpec */
Lev Walkinb7c45ca2004-11-24 17:43:29 +00001075 $$->unique = $3;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001076 $$->marker = $4;
1077 asn1p_expr_add($$, $2);
Lev Walkinf15320b2004-06-03 03:38:44 +00001078 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001079
1080 /* VariableTypeValueFieldSpec ::= valuefieldreference FieldName ValueOptionalitySpec ? */
1081 | TOK_valuefieldreference FieldName optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001082 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001083 $$->Identifier = $1;
1084 $$->meta_type = AMT_OBJECTFIELD;
1085 $$->expr_type = A1TC_CLASSFIELD_VTVFS;
1086 $$->reference = $2;
1087 $$->marker = $3;
1088 }
1089
Lev Walkin9c2285a2006-03-09 08:49:26 +00001090 /* ObjectFieldSpec ::= objectfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1091 | TOK_valuefieldreference DefinedObjectClass optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001092 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001093 checkmem($$);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001094 $$->Identifier = $1;
1095 $$->reference = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00001096 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001097 $$->expr_type = A1TC_CLASSFIELD_OFS;
1098 $$->marker = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +00001099 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001100
Lev Walkin54868752006-03-09 09:08:49 +00001101 /* VariableTypeValueSetFieldSpec ::= valuesetfieldreference FieldName ValueOptionalitySpec ? */
1102 | TOK_typefieldreference FieldName optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001103 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001104 $$->Identifier = $1;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001105 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin54868752006-03-09 09:08:49 +00001106 $$->expr_type = A1TC_CLASSFIELD_VTVSFS;
1107 $$->reference = $2;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001108 $$->marker = $3;
1109 }
1110
1111 /* FixedTypeValueSetFieldSpec ::= valuesetfieldreference Type ValueSetOptionalitySpec ? */
1112 | TOK_typefieldreference Type optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001113 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001114 checkmem($$);
1115 $$->Identifier = $1;
1116 $$->meta_type = AMT_OBJECTFIELD;
1117 $$->expr_type = A1TC_CLASSFIELD_FTVSFS;
1118 asn1p_expr_add($$, $2);
1119 $$->marker = $3;
1120 }
1121
Lev Walkin54868752006-03-09 09:08:49 +00001122 /* ObjectSetFieldSpec ::= objectsetfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1123 | TOK_typefieldreference DefinedObjectClass optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001124 $$ = NEW_EXPR();
Lev Walkin54868752006-03-09 09:08:49 +00001125 checkmem($$);
1126 $$->Identifier = $1;
1127 $$->reference = $2;
1128 $$->meta_type = AMT_OBJECTFIELD;
1129 $$->expr_type = A1TC_CLASSFIELD_OSFS;
1130 $$->marker = $3;
1131 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001132 ;
1133
1134optWithSyntax:
1135 { $$ = 0; }
1136 | WithSyntax {
1137 $$ = $1;
1138 }
1139 ;
1140
1141WithSyntax:
1142 TOK_WITH TOK_SYNTAX '{'
1143 { asn1p_lexer_hack_enable_with_syntax(); }
Lev Walkin9d542d22006-03-14 16:31:37 +00001144 WithSyntaxList
Lev Walkinf15320b2004-06-03 03:38:44 +00001145 '}' {
1146 $$ = $5;
1147 }
1148 ;
1149
Lev Walkin9d542d22006-03-14 16:31:37 +00001150WithSyntaxList:
1151 WithSyntaxToken {
Lev Walkinf15320b2004-06-03 03:38:44 +00001152 $$ = asn1p_wsyntx_new();
1153 TQ_ADD(&($$->chunks), $1, next);
1154 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001155 | WithSyntaxList WithSyntaxToken {
Lev Walkinf15320b2004-06-03 03:38:44 +00001156 $$ = $1;
1157 TQ_ADD(&($$->chunks), $2, next);
1158 }
1159 ;
1160
Lev Walkin9d542d22006-03-14 16:31:37 +00001161WithSyntaxToken:
Lev Walkin57074f12006-03-16 05:11:14 +00001162 TOK_whitespace {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001163 $$ = asn1p_wsyntx_chunk_fromstring($1.buf, 0);
Lev Walkin57074f12006-03-16 05:11:14 +00001164 $$->type = WC_WHITESPACE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001165 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001166 | TOK_Literal {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001167 $$ = asn1p_wsyntx_chunk_fromstring($1, 0);
Lev Walkin9d542d22006-03-14 16:31:37 +00001168 }
Lev Walkind370e9f2006-03-16 10:03:35 +00001169 | PrimitiveFieldReference {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001170 $$ = asn1p_wsyntx_chunk_fromstring($1.name, 0);
Lev Walkind370e9f2006-03-16 10:03:35 +00001171 $$->type = WC_FIELD;
Lev Walkinf15320b2004-06-03 03:38:44 +00001172 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001173 | '[' WithSyntaxList ']' {
1174 $$ = asn1p_wsyntx_chunk_fromsyntax($2);
1175 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001176 ;
1177
Lev Walkinf15320b2004-06-03 03:38:44 +00001178ExtensionAndException:
1179 TOK_ThreeDots {
Lev Walkina9532f42006-09-17 04:52:50 +00001180 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001181 checkmem($$);
1182 $$->Identifier = strdup("...");
1183 checkmem($$->Identifier);
1184 $$->expr_type = A1TC_EXTENSIBLE;
1185 $$->meta_type = AMT_TYPE;
1186 }
1187 | TOK_ThreeDots '!' DefinedValue {
Lev Walkina9532f42006-09-17 04:52:50 +00001188 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001189 checkmem($$);
1190 $$->Identifier = strdup("...");
1191 checkmem($$->Identifier);
1192 $$->value = $3;
1193 $$->expr_type = A1TC_EXTENSIBLE;
1194 $$->meta_type = AMT_TYPE;
1195 }
1196 | TOK_ThreeDots '!' SignedNumber {
Lev Walkina9532f42006-09-17 04:52:50 +00001197 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001198 checkmem($$);
1199 $$->Identifier = strdup("...");
1200 $$->value = $3;
1201 checkmem($$->Identifier);
1202 $$->expr_type = A1TC_EXTENSIBLE;
1203 $$->meta_type = AMT_TYPE;
1204 }
1205 ;
1206
Lev Walkin070a52d2004-08-22 03:19:54 +00001207Type:
Lev Walkinaf120f72004-09-14 02:36:39 +00001208 optTag TypeDeclaration optConstraints {
1209 $$ = $2;
1210 $$->tag = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001211 /*
1212 * Outer constraint for SEQUENCE OF and SET OF applies
1213 * to the inner type.
1214 */
1215 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1216 || $$->expr_type == ASN_CONSTR_SET_OF) {
1217 assert(!TQ_FIRST(&($$->members))->constraints);
Lev Walkinaf120f72004-09-14 02:36:39 +00001218 TQ_FIRST(&($$->members))->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001219 } else {
1220 if($$->constraints) {
1221 assert(!$2);
1222 } else {
Lev Walkinaf120f72004-09-14 02:36:39 +00001223 $$->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001224 }
1225 }
Lev Walkinef625402005-09-05 05:17:57 +00001226 }
1227 ;
1228
1229NSTD_IndirectMarker:
1230 {
1231 $$ = asn1p_as_pointer ? EM_INDIRECT : 0;
1232 asn1p_as_pointer = 0;
Lev Walkin070a52d2004-08-22 03:19:54 +00001233 }
1234 ;
1235
1236TypeDeclaration:
Lev Walkinef625402005-09-05 05:17:57 +00001237 NSTD_IndirectMarker TypeDeclarationSet {
Lev Walkin4696c742005-08-22 12:23:54 +00001238 $$ = $2;
Lev Walkinef625402005-09-05 05:17:57 +00001239 $$->marker.flags |= $1;
1240
1241 if(($$->marker.flags & EM_INDIRECT)
1242 && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
1243 fprintf(stderr,
1244 "INFO: Directive <ASN1C:RepresentAsPointer> "
1245 "applied to %s at line %d\n",
1246 ASN_EXPR_TYPE2STR($$->expr_type)
1247 ? ASN_EXPR_TYPE2STR($$->expr_type)
1248 : "member",
1249 $$->_lineno
1250 );
1251 }
Lev Walkin4696c742005-08-22 12:23:54 +00001252 }
Lev Walkinef625402005-09-05 05:17:57 +00001253 ;
Lev Walkin4696c742005-08-22 12:23:54 +00001254
1255TypeDeclarationSet:
Lev Walkin0c0bca62006-03-21 04:48:15 +00001256 DefinedType {
Lev Walkinf15320b2004-06-03 03:38:44 +00001257 $$ = $1;
1258 }
Lev Walkinef625402005-09-05 05:17:57 +00001259 | TOK_CHOICE '{' AlternativeTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001260 $$ = $3;
1261 assert($$->expr_type == A1TC_INVALID);
1262 $$->expr_type = ASN_CONSTR_CHOICE;
1263 $$->meta_type = AMT_TYPE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001264 }
Lev Walkinef625402005-09-05 05:17:57 +00001265 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001266 $$ = $3;
1267 assert($$->expr_type == A1TC_INVALID);
1268 $$->expr_type = ASN_CONSTR_SEQUENCE;
1269 $$->meta_type = AMT_TYPE;
1270 }
Lev Walkinef625402005-09-05 05:17:57 +00001271 | TOK_SET '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001272 $$ = $3;
1273 assert($$->expr_type == A1TC_INVALID);
1274 $$->expr_type = ASN_CONSTR_SET;
1275 $$->meta_type = AMT_TYPE;
1276 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001277 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkina9532f42006-09-17 04:52:50 +00001278 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001279 checkmem($$);
1280 $$->constraints = $2;
1281 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1282 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001283 $6->Identifier = $4;
1284 $6->tag = $5;
1285 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001286 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001287 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkina9532f42006-09-17 04:52:50 +00001288 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001289 checkmem($$);
1290 $$->constraints = $2;
1291 $$->expr_type = ASN_CONSTR_SET_OF;
1292 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001293 $6->Identifier = $4;
1294 $6->tag = $5;
1295 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001296 }
1297 | TOK_ANY {
Lev Walkina9532f42006-09-17 04:52:50 +00001298 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001299 checkmem($$);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001300 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001301 $$->meta_type = AMT_TYPE;
1302 }
1303 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1304 int ret;
Lev Walkina9532f42006-09-17 04:52:50 +00001305 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001306 checkmem($$);
1307 $$->reference = asn1p_ref_new(yylineno);
1308 ret = asn1p_ref_add_component($$->reference,
1309 $4, RLT_lowercase);
1310 checkmem(ret == 0);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001311 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001312 $$->meta_type = AMT_TYPE;
1313 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001314 | TOK_INSTANCE TOK_OF ComplexTypeReference {
Lev Walkina9532f42006-09-17 04:52:50 +00001315 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001316 checkmem($$);
1317 $$->reference = $3;
1318 $$->expr_type = A1TC_INSTANCE;
1319 $$->meta_type = AMT_TYPE;
1320 }
1321 ;
1322
1323/*
1324 * A type name consisting of several components.
1325 * === EXAMPLE ===
1326 * === EOF ===
1327 */
1328ComplexTypeReference:
1329 TOK_typereference {
1330 int ret;
1331 $$ = asn1p_ref_new(yylineno);
1332 checkmem($$);
1333 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1334 checkmem(ret == 0);
1335 free($1);
1336 }
1337 | TOK_typereference '.' TypeRefName {
1338 int ret;
1339 $$ = asn1p_ref_new(yylineno);
1340 checkmem($$);
1341 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1342 checkmem(ret == 0);
1343 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1344 checkmem(ret == 0);
1345 free($1);
1346 }
Lev Walkin9c974182004-09-15 11:59:51 +00001347 | ObjectClassReference '.' TypeRefName {
1348 int ret;
1349 $$ = asn1p_ref_new(yylineno);
1350 checkmem($$);
1351 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1352 checkmem(ret == 0);
1353 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1354 checkmem(ret == 0);
1355 free($1);
1356 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001357 | TOK_typereference '.' Identifier {
1358 int ret;
1359 $$ = asn1p_ref_new(yylineno);
1360 checkmem($$);
1361 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1362 checkmem(ret == 0);
1363 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1364 checkmem(ret == 0);
1365 free($1);
1366 }
1367 | ObjectClassReference {
1368 int ret;
1369 $$ = asn1p_ref_new(yylineno);
1370 checkmem($$);
1371 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1372 free($1);
1373 checkmem(ret == 0);
1374 }
1375 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1376 int ret;
1377 $$ = $3;
1378 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1379 free($1);
1380 checkmem(ret == 0);
1381 /*
1382 * Move the last element infront.
1383 */
1384 {
1385 struct asn1p_ref_component_s tmp_comp;
1386 tmp_comp = $$->components[$$->comp_count-1];
1387 memmove(&$$->components[1],
1388 &$$->components[0],
1389 sizeof($$->components[0])
1390 * ($$->comp_count - 1));
1391 $$->components[0] = tmp_comp;
1392 }
1393 }
1394 ;
1395
1396ComplexTypeReferenceAmpList:
1397 ComplexTypeReferenceElement {
1398 int ret;
1399 $$ = asn1p_ref_new(yylineno);
1400 checkmem($$);
1401 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1402 free($1.name);
1403 checkmem(ret == 0);
1404 }
1405 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1406 int ret;
1407 $$ = $1;
1408 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1409 free($3.name);
1410 checkmem(ret == 0);
1411 }
1412 ;
1413
Lev Walkind370e9f2006-03-16 10:03:35 +00001414ComplexTypeReferenceElement: PrimitiveFieldReference;
Lev Walkinf15320b2004-06-03 03:38:44 +00001415
Lev Walkind370e9f2006-03-16 10:03:35 +00001416PrimitiveFieldReference:
Lev Walkinf15320b2004-06-03 03:38:44 +00001417 /* "&Type1" */
1418 TOK_typefieldreference {
1419 $$.lex_type = RLT_AmpUppercase;
1420 $$.name = $1;
1421 }
1422 /* "&id" */
1423 | TOK_valuefieldreference {
1424 $$.lex_type = RLT_Amplowercase;
1425 $$.name = $1;
1426 }
1427 ;
1428
1429
Lev Walkin9c2285a2006-03-09 08:49:26 +00001430FieldName:
1431 /* "&Type1" */
1432 TOK_typefieldreference {
1433 $$ = asn1p_ref_new(yylineno);
1434 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1435 }
1436 | FieldName '.' TOK_typefieldreference {
1437 $$ = $$;
1438 asn1p_ref_add_component($$, $3, RLT_AmpUppercase);
1439 }
1440 | FieldName '.' TOK_valuefieldreference {
1441 $$ = $$;
1442 asn1p_ref_add_component($$, $3, RLT_Amplowercase);
1443 }
1444 ;
1445
1446DefinedObjectClass:
1447 TOK_capitalreference {
1448 $$ = asn1p_ref_new(yylineno);
1449 asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1450 }
Lev Walkin54868752006-03-09 09:08:49 +00001451/*
Lev Walkin9c2285a2006-03-09 08:49:26 +00001452 | TypeRefName '.' TOK_capitalreference {
1453 $$ = asn1p_ref_new(yylineno);
1454 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1455 asn1p_ref_add_component($$, $3, RLT_CAPITALS);
1456 }
Lev Walkin54868752006-03-09 09:08:49 +00001457*/
Lev Walkin9c2285a2006-03-09 08:49:26 +00001458 ;
1459
1460
Lev Walkinf15320b2004-06-03 03:38:44 +00001461/*
1462 * === EXAMPLE ===
1463 * value INTEGER ::= 1
1464 * === EOF ===
1465 */
1466ValueDefinition:
Lev Walkin0c0bca62006-03-21 04:48:15 +00001467 Identifier DefinedType TOK_PPEQ Value {
Lev Walkinf15320b2004-06-03 03:38:44 +00001468 $$ = $2;
1469 assert($$->Identifier == NULL);
1470 $$->Identifier = $1;
1471 $$->meta_type = AMT_VALUE;
1472 $$->value = $4;
1473 }
1474 ;
1475
Lev Walkin9c974182004-09-15 11:59:51 +00001476Value:
Lev Walkin0c0bca62006-03-21 04:48:15 +00001477 SimpleValue
1478 | DefinedValue
1479 | Identifier ':' Value {
Lev Walkin9c974182004-09-15 11:59:51 +00001480 $$ = asn1p_value_fromint(0);
1481 checkmem($$);
1482 $$->type = ATV_CHOICE_IDENTIFIER;
1483 $$->value.choice_identifier.identifier = $1;
1484 $$->value.choice_identifier.value = $3;
1485 }
Lev Walkincbad2512005-03-24 16:27:02 +00001486 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Lev Walkinf15320b2004-06-03 03:38:44 +00001487 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1488 checkmem($$);
1489 $$->type = ATV_UNPARSED;
1490 }
Lev Walkin9c974182004-09-15 11:59:51 +00001491 | TOK_NULL {
1492 $$ = asn1p_value_fromint(0);
1493 checkmem($$);
1494 $$->type = ATV_NULL;
1495 }
Lev Walkin0c0bca62006-03-21 04:48:15 +00001496 ;
1497
1498SimpleValue:
1499 TOK_FALSE {
Lev Walkin9c974182004-09-15 11:59:51 +00001500 $$ = asn1p_value_fromint(0);
1501 checkmem($$);
1502 $$->type = ATV_FALSE;
1503 }
1504 | TOK_TRUE {
1505 $$ = asn1p_value_fromint(0);
1506 checkmem($$);
1507 $$->type = ATV_TRUE;
1508 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001509 | TOK_bstring {
1510 $$ = _convert_bitstring2binary($1, 'B');
1511 checkmem($$);
1512 }
1513 | TOK_hstring {
1514 $$ = _convert_bitstring2binary($1, 'H');
1515 checkmem($$);
1516 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001517 | RestrictedCharacterStringValue {
1518 $$ = $$;
Lev Walkinf15320b2004-06-03 03:38:44 +00001519 }
1520 | SignedNumber {
1521 $$ = $1;
1522 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001523 ;
1524
1525DefinedValue:
1526 Identifier {
1527 asn1p_ref_t *ref;
1528 int ret;
1529 ref = asn1p_ref_new(yylineno);
1530 checkmem(ref);
1531 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1532 checkmem(ret == 0);
1533 $$ = asn1p_value_fromref(ref, 0);
1534 checkmem($$);
1535 free($1);
1536 }
1537 | TypeRefName '.' Identifier {
1538 asn1p_ref_t *ref;
1539 int ret;
1540 ref = asn1p_ref_new(yylineno);
1541 checkmem(ref);
1542 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1543 checkmem(ret == 0);
1544 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1545 checkmem(ret == 0);
1546 $$ = asn1p_value_fromref(ref, 0);
1547 checkmem($$);
1548 free($1);
1549 free($3);
1550 }
1551 ;
1552
Lev Walkin1e448d32005-03-24 14:26:38 +00001553
1554RestrictedCharacterStringValue:
1555 TOK_cstring {
1556 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1557 checkmem($$);
1558 }
Lev Walkind9574ae2005-03-24 16:22:35 +00001559 | TOK_tuple {
1560 $$ = asn1p_value_fromint($1);
1561 checkmem($$);
1562 $$->type = ATV_TUPLE;
1563 }
1564 | TOK_quadruple {
1565 $$ = asn1p_value_fromint($1);
1566 checkmem($$);
1567 $$->type = ATV_QUADRUPLE;
1568 }
1569 /*
Lev Walkin1e448d32005-03-24 14:26:38 +00001570 | '{' TOK_number ',' TOK_number '}' {
1571 asn1c_integer_t v = ($2 << 4) + $4;
1572 if($2 > 7) return yyerror("X.680:2003, #37.14 "
1573 "mandates 0..7 range for Tuple's TableColumn");
1574 if($4 > 15) return yyerror("X.680:2003, #37.14 "
1575 "mandates 0..15 range for Tuple's TableRow");
1576 $$ = asn1p_value_fromint(v);
1577 checkmem($$);
1578 $$->type = ATV_TUPLE;
1579 }
1580 | '{' TOK_number ',' TOK_number ',' TOK_number ',' TOK_number '}' {
1581 asn1c_integer_t v = ($2 << 24) | ($4 << 16) | ($6 << 8) | $8;
1582 if($2 > 127) return yyerror("X.680:2003, #37.12 "
1583 "mandates 0..127 range for Quadruple's Group");
1584 if($4 > 255) return yyerror("X.680:2003, #37.12 "
1585 "mandates 0..255 range for Quadruple's Plane");
1586 if($6 > 255) return yyerror("X.680:2003, #37.12 "
1587 "mandates 0..255 range for Quadruple's Row");
1588 if($8 > 255) return yyerror("X.680:2003, #37.12 "
1589 "mandates 0..255 range for Quadruple's Cell");
1590 $$ = asn1p_value_fromint(v);
1591 checkmem($$);
1592 $$->type = ATV_QUADRUPLE;
1593 }
Lev Walkind9574ae2005-03-24 16:22:35 +00001594 */
Lev Walkin1e448d32005-03-24 14:26:38 +00001595 ;
1596
Lev Walkinf15320b2004-06-03 03:38:44 +00001597Opaque:
1598 TOK_opaque {
Lev Walkin1893ddf2005-03-20 14:28:32 +00001599 $$.len = $1.len + 1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001600 $$.buf = malloc($$.len + 1);
1601 checkmem($$.buf);
1602 $$.buf[0] = '{';
Lev Walkin1893ddf2005-03-20 14:28:32 +00001603 memcpy($$.buf + 1, $1.buf, $1.len);
Lev Walkinf15320b2004-06-03 03:38:44 +00001604 $$.buf[$$.len] = '\0';
1605 free($1.buf);
1606 }
1607 | Opaque TOK_opaque {
1608 int newsize = $1.len + $2.len;
1609 char *p = malloc(newsize + 1);
1610 checkmem(p);
1611 memcpy(p , $1.buf, $1.len);
1612 memcpy(p + $1.len, $2.buf, $2.len);
1613 p[newsize] = '\0';
1614 free($1.buf);
1615 free($2.buf);
1616 $$.buf = p;
1617 $$.len = newsize;
1618 }
1619 ;
1620
1621BasicTypeId:
1622 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1623 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1624 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1625 | BasicTypeId_UniverationCompatible { $$ = $1; }
1626 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1627 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1628 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1629 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1630 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1631 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1632 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1633 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
Lev Walkinc7d939d2005-03-20 11:12:40 +00001634 | BasicString { $$ = $1; }
Lev Walkinf15320b2004-06-03 03:38:44 +00001635 ;
1636
1637/*
1638 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1639 */
1640BasicTypeId_UniverationCompatible:
1641 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1642 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1643 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1644 ;
1645
1646BasicType:
1647 BasicTypeId {
Lev Walkina9532f42006-09-17 04:52:50 +00001648 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001649 checkmem($$);
1650 $$->expr_type = $1;
1651 $$->meta_type = AMT_TYPE;
1652 }
1653 | BasicTypeId_UniverationCompatible UniverationDefinition {
1654 if($2) {
1655 $$ = $2;
1656 } else {
Lev Walkina9532f42006-09-17 04:52:50 +00001657 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001658 checkmem($$);
1659 }
1660 $$->expr_type = $1;
1661 $$->meta_type = AMT_TYPE;
1662 }
1663 ;
1664
1665BasicString:
1666 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1667 | TOK_GeneralString {
1668 $$ = ASN_STRING_GeneralString;
Lev Walkin9c974182004-09-15 11:59:51 +00001669 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001670 }
1671 | TOK_GraphicString {
1672 $$ = ASN_STRING_GraphicString;
Lev Walkin9c974182004-09-15 11:59:51 +00001673 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001674 }
1675 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1676 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1677 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1678 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1679 | TOK_T61String {
1680 $$ = ASN_STRING_T61String;
Lev Walkin9c974182004-09-15 11:59:51 +00001681 fprintf(stderr, "WARNING: T61String is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001682 }
1683 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1684 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1685 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1686 | TOK_VideotexString {
1687 $$ = ASN_STRING_VideotexString;
Lev Walkin9c974182004-09-15 11:59:51 +00001688 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001689 }
1690 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1691 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1692 ;
1693
Lev Walkind2ea1de2004-08-20 13:25:29 +00001694
Lev Walkinf15320b2004-06-03 03:38:44 +00001695/*
1696 * Data type constraints.
1697 */
Lev Walkinf1727152006-09-21 01:50:37 +00001698UnionMark: '|' | TOK_UNION;
1699IntersectionMark: '^' | TOK_INTERSECTION;
Lev Walkinf15320b2004-06-03 03:38:44 +00001700
Lev Walkinf59d0752004-08-18 04:59:12 +00001701optConstraints:
1702 { $$ = 0; }
Lev Walkina9532f42006-09-17 04:52:50 +00001703 | Constraint {
Lev Walkind2ea1de2004-08-20 13:25:29 +00001704 $$ = $1;
1705 }
1706 ;
1707
Lev Walkina9532f42006-09-17 04:52:50 +00001708Constraint:
1709 SubtypeConstraint
1710 | '(' GeneralConstraint ')' {
1711 $$ = $2;
1712 }
1713 ;
1714
1715SubtypeConstraint:
Lev Walkind2ea1de2004-08-20 13:25:29 +00001716 SetOfConstraints {
Lev Walkin2c14a692005-08-12 10:08:45 +00001717 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
Lev Walkinf59d0752004-08-18 04:59:12 +00001718 }
1719 | TOK_SIZE '(' ElementSetSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001720 /*
1721 * This is a special case, for compatibility purposes.
Lev Walkinf59d0752004-08-18 04:59:12 +00001722 * It goes without parentheses.
Lev Walkinf15320b2004-06-03 03:38:44 +00001723 */
Lev Walkin2c14a692005-08-12 10:08:45 +00001724 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001725 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001726 ;
1727
Lev Walkinf59d0752004-08-18 04:59:12 +00001728SetOfConstraints:
1729 '(' ElementSetSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001730 $$ = $2;
1731 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001732 | SetOfConstraints '(' ElementSetSpecs ')' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001733 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
Lev Walkinf59d0752004-08-18 04:59:12 +00001734 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001735 ;
1736
Lev Walkinf59d0752004-08-18 04:59:12 +00001737ElementSetSpecs:
Lev Walkin5045dfa2006-03-21 09:41:28 +00001738 TOK_ThreeDots {
1739 $$ = asn1p_constraint_new(yylineno);
1740 $$->type = ACT_EL_EXT;
1741 }
1742 | ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001743 $$ = $1;
1744 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001745 | ElementSetSpec ',' TOK_ThreeDots {
Lev Walkinf15320b2004-06-03 03:38:44 +00001746 asn1p_constraint_t *ct;
1747 ct = asn1p_constraint_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001748 ct->type = ACT_EL_EXT;
Lev Walkin2c14a692005-08-12 10:08:45 +00001749 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00001750 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001751 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001752 asn1p_constraint_t *ct;
1753 ct = asn1p_constraint_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001754 ct->type = ACT_EL_EXT;
Lev Walkin2c14a692005-08-12 10:08:45 +00001755 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinb4fcdd22004-08-13 12:35:09 +00001756 ct = $$;
Lev Walkin2c14a692005-08-12 10:08:45 +00001757 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
Lev Walkinf15320b2004-06-03 03:38:44 +00001758 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001759 ;
1760
Lev Walkinf59d0752004-08-18 04:59:12 +00001761ElementSetSpec:
Lev Walkinf1727152006-09-21 01:50:37 +00001762 Unions
Lev Walkin1e448d32005-03-24 14:26:38 +00001763 | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001764 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
Lev Walkin1e448d32005-03-24 14:26:38 +00001765 }
Lev Walkinf1727152006-09-21 01:50:37 +00001766 ;
1767
1768Unions:
1769 Intersections
1770 | Unions UnionMark Intersections {
Lev Walkin2c14a692005-08-12 10:08:45 +00001771 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001772 }
Lev Walkinf1727152006-09-21 01:50:37 +00001773 ;
1774
1775Intersections:
1776 IntersectionElements
1777 | Intersections IntersectionMark IntersectionElements {
Lev Walkin2c14a692005-08-12 10:08:45 +00001778 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001779 }
Lev Walkinf1727152006-09-21 01:50:37 +00001780 ;
1781
1782
1783IntersectionElements:
1784 ConstraintSubtypeElement
1785 | ConstraintSubtypeElement TOK_EXCEPT ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001786 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001787 }
1788 ;
1789
1790ConstraintSubtypeElement:
Lev Walkinf59d0752004-08-18 04:59:12 +00001791 ConstraintSpec '(' ElementSetSpecs ')' {
1792 int ret;
1793 $$ = asn1p_constraint_new(yylineno);
1794 checkmem($$);
1795 $$->type = $1;
1796 ret = asn1p_constraint_insert($$, $3);
1797 checkmem(ret == 0);
1798 }
1799 | '(' ElementSetSpecs ')' {
1800 int ret;
1801 $$ = asn1p_constraint_new(yylineno);
1802 checkmem($$);
1803 $$->type = ACT_CA_SET;
1804 ret = asn1p_constraint_insert($$, $2);
1805 checkmem(ret == 0);
1806 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001807 | SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001808 $$ = asn1p_constraint_new(yylineno);
1809 checkmem($$);
1810 $$->type = ACT_EL_VALUE;
1811 $$->value = $1;
1812 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001813 | ContainedSubtype {
1814 $$ = asn1p_constraint_new(yylineno);
1815 checkmem($$);
1816 $$->type = ACT_EL_TYPE;
1817 $$->containedSubtype = $1;
1818 }
1819 | SingleValue ConstraintRangeSpec SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001820 $$ = asn1p_constraint_new(yylineno);
1821 checkmem($$);
1822 $$->type = $2;
1823 $$->range_start = $1;
1824 $$->range_stop = $3;
1825 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001826 | TOK_MIN ConstraintRangeSpec SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001827 $$ = asn1p_constraint_new(yylineno);
1828 checkmem($$);
Lev Walkinf59d0752004-08-18 04:59:12 +00001829 $$->type = $2;
1830 $$->range_start = asn1p_value_fromint(-123);
1831 $$->range_stop = $3;
1832 $$->range_start->type = ATV_MIN;
1833 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001834 | SingleValue ConstraintRangeSpec TOK_MAX {
Lev Walkinf59d0752004-08-18 04:59:12 +00001835 $$ = asn1p_constraint_new(yylineno);
1836 checkmem($$);
1837 $$->type = $2;
1838 $$->range_start = $1;
1839 $$->range_stop = asn1p_value_fromint(321);
1840 $$->range_stop->type = ATV_MAX;
1841 }
1842 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1843 $$ = asn1p_constraint_new(yylineno);
1844 checkmem($$);
1845 $$->type = $2;
1846 $$->range_start = asn1p_value_fromint(-123);
1847 $$->range_stop = asn1p_value_fromint(321);
1848 $$->range_start->type = ATV_MIN;
1849 $$->range_stop->type = ATV_MAX;
Lev Walkinf15320b2004-06-03 03:38:44 +00001850 }
Lev Walkine596bf02005-03-28 15:01:27 +00001851 | InnerTypeConstraint {
Lev Walkinf15320b2004-06-03 03:38:44 +00001852 $$ = $1;
1853 }
Lev Walkin5c541f12006-10-18 18:40:14 +00001854 | PatternConstraint {
1855 $$ = $1;
1856 }
1857 ;
1858
1859PatternConstraint:
1860 TOK_PATTERN TOK_cstring {
1861 $$ = asn1p_constraint_new(yylineno);
1862 $$->type = ACT_CT_PATTERN;
1863 $$->value = asn1p_value_frombuf($2.buf, $2.len, 0);
1864 }
1865 | TOK_PATTERN Identifier {
1866 asn1p_ref_t *ref;
1867 $$ = asn1p_constraint_new(yylineno);
1868 $$->type = ACT_CT_PATTERN;
1869 ref = asn1p_ref_new(yylineno);
1870 asn1p_ref_add_component(ref, $2, RLT_lowercase);
1871 $$->value = asn1p_value_fromref(ref, 0);
1872 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001873 ;
1874
1875ConstraintSpec:
1876 TOK_SIZE {
1877 $$ = ACT_CT_SIZE;
1878 }
1879 | TOK_FROM {
1880 $$ = ACT_CT_FROM;
1881 }
1882 ;
1883
Lev Walkinff7dd142005-03-20 12:58:00 +00001884SingleValue:
Lev Walkinc8092cb2005-02-18 16:34:21 +00001885 TOK_FALSE {
1886 $$ = asn1p_value_fromint(0);
1887 checkmem($$);
1888 $$->type = ATV_FALSE;
1889 }
1890 | TOK_TRUE {
1891 $$ = asn1p_value_fromint(1);
1892 checkmem($$);
1893 $$->type = ATV_TRUE;
1894 }
Lev Walkinadf863f2006-09-05 16:18:34 +00001895 | RealValue
1896 | RestrictedCharacterStringValue
Lev Walkinf15320b2004-06-03 03:38:44 +00001897 | Identifier {
1898 asn1p_ref_t *ref;
1899 int ret;
1900 ref = asn1p_ref_new(yylineno);
1901 checkmem(ref);
1902 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1903 checkmem(ret == 0);
1904 $$ = asn1p_value_fromref(ref, 0);
1905 checkmem($$);
1906 free($1);
1907 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001908 ;
1909
1910ContainedSubtype:
1911 TypeRefName {
Lev Walkinc8092cb2005-02-18 16:34:21 +00001912 asn1p_ref_t *ref;
1913 int ret;
1914 ref = asn1p_ref_new(yylineno);
1915 checkmem(ref);
1916 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1917 checkmem(ret == 0);
1918 $$ = asn1p_value_fromref(ref, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001919 checkmem($$);
Lev Walkinc8092cb2005-02-18 16:34:21 +00001920 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001921 }
1922 ;
1923
Lev Walkine596bf02005-03-28 15:01:27 +00001924InnerTypeConstraint:
1925 TOK_WITH TOK_COMPONENT SetOfConstraints {
Lev Walkin2c14a692005-08-12 10:08:45 +00001926 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
Lev Walkine596bf02005-03-28 15:01:27 +00001927 }
1928 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001929 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001930 }
1931 ;
1932
1933WithComponentsList:
1934 WithComponentsElement {
1935 $$ = $1;
1936 }
1937 | WithComponentsList ',' WithComponentsElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001938 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001939 }
1940 ;
1941
1942WithComponentsElement:
1943 TOK_ThreeDots {
1944 $$ = asn1p_constraint_new(yylineno);
1945 checkmem($$);
1946 $$->type = ACT_EL_EXT;
Lev Walkin418298d2006-07-13 08:24:20 +00001947 $$->value = asn1p_value_frombuf("...", 3, 1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001948 }
1949 | Identifier optConstraints optPresenceConstraint {
1950 $$ = asn1p_constraint_new(yylineno);
1951 checkmem($$);
1952 $$->type = ACT_EL_VALUE;
1953 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1954 $$->presence = $3;
Lev Walkine596bf02005-03-28 15:01:27 +00001955 if($2) asn1p_constraint_insert($$, $2);
Lev Walkinf15320b2004-06-03 03:38:44 +00001956 }
1957 ;
1958
1959/*
1960 * presence constraint for WithComponents
1961 */
1962optPresenceConstraint:
1963 { $$ = ACPRES_DEFAULT; }
1964 | PresenceConstraint { $$ = $1; }
1965 ;
1966
1967PresenceConstraint:
1968 TOK_PRESENT {
1969 $$ = ACPRES_PRESENT;
1970 }
1971 | TOK_ABSENT {
1972 $$ = ACPRES_ABSENT;
1973 }
1974 | TOK_OPTIONAL {
1975 $$ = ACPRES_OPTIONAL;
1976 }
1977 ;
1978
Lev Walkina9532f42006-09-17 04:52:50 +00001979
1980/* X.682 */
1981GeneralConstraint:
1982 UserDefinedConstraint
1983 | TableConstraint
1984 | ContentsConstraint
1985 ;
1986
1987UserDefinedConstraint:
1988 TOK_CONSTRAINED TOK_BY '{'
1989 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1990 $$ = asn1p_constraint_new(yylineno);
1991 checkmem($$);
1992 $$->type = ACT_CT_CTDBY;
1993 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
1994 checkmem($$->value);
1995 $$->value->type = ATV_UNPARSED;
1996 }
1997 ;
1998
1999ContentsConstraint:
2000 TOK_CONTAINING Type {
2001 $$ = asn1p_constraint_new(yylineno);
2002 $$->type = ACT_CT_CTNG;
2003 $$->value = asn1p_value_fromtype($2);
2004 }
2005 ;
2006
2007ConstraintRangeSpec:
2008 TOK_TwoDots { $$ = ACT_EL_RANGE; }
2009 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
2010 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
2011 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
2012 ;
Lev Walkinf15320b2004-06-03 03:38:44 +00002013TableConstraint:
2014 SimpleTableConstraint {
2015 $$ = $1;
2016 }
2017 | ComponentRelationConstraint {
2018 $$ = $1;
2019 }
2020 ;
2021
2022/*
2023 * "{ExtensionSet}"
2024 */
2025SimpleTableConstraint:
2026 '{' TypeRefName '}' {
2027 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
2028 asn1p_constraint_t *ct;
2029 int ret;
2030 ret = asn1p_ref_add_component(ref, $2, 0);
2031 checkmem(ret == 0);
2032 ct = asn1p_constraint_new(yylineno);
2033 checkmem($$);
2034 ct->type = ACT_EL_VALUE;
2035 ct->value = asn1p_value_fromref(ref, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00002036 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00002037 }
2038 ;
2039
2040ComponentRelationConstraint:
2041 SimpleTableConstraint '{' AtNotationList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00002042 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002043 }
2044 ;
2045
2046AtNotationList:
2047 AtNotationElement {
2048 $$ = asn1p_constraint_new(yylineno);
2049 checkmem($$);
2050 $$->type = ACT_EL_VALUE;
2051 $$->value = asn1p_value_fromref($1, 0);
2052 }
2053 | AtNotationList ',' AtNotationElement {
2054 asn1p_constraint_t *ct;
2055 ct = asn1p_constraint_new(yylineno);
2056 checkmem(ct);
2057 ct->type = ACT_EL_VALUE;
2058 ct->value = asn1p_value_fromref($3, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00002059 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00002060 }
2061 ;
2062
2063/*
2064 * @blah
2065 */
2066AtNotationElement:
2067 '@' ComponentIdList {
2068 char *p = malloc(strlen($2) + 2);
2069 int ret;
2070 *p = '@';
2071 strcpy(p + 1, $2);
2072 $$ = asn1p_ref_new(yylineno);
2073 ret = asn1p_ref_add_component($$, p, 0);
2074 checkmem(ret == 0);
2075 free(p);
2076 free($2);
2077 }
2078 | '@' '.' ComponentIdList {
2079 char *p = malloc(strlen($3) + 3);
2080 int ret;
2081 p[0] = '@';
2082 p[1] = '.';
2083 strcpy(p + 2, $3);
2084 $$ = asn1p_ref_new(yylineno);
2085 ret = asn1p_ref_add_component($$, p, 0);
2086 checkmem(ret == 0);
2087 free(p);
2088 free($3);
2089 }
2090 ;
2091
2092/* identifier "." ... */
2093ComponentIdList:
2094 Identifier {
2095 $$ = $1;
2096 }
2097 | ComponentIdList '.' Identifier {
2098 int l1 = strlen($1);
2099 int l3 = strlen($3);
2100 $$ = malloc(l1 + 1 + l3 + 1);
2101 memcpy($$, $1, l1);
2102 $$[l1] = '.';
2103 memcpy($$ + l1 + 1, $3, l3);
2104 $$[l1 + 1 + l3] = '\0';
2105 }
2106 ;
2107
2108
2109
2110/*
2111 * MARKERS
2112 */
2113
2114optMarker:
Lev Walkin9c974182004-09-15 11:59:51 +00002115 {
2116 $$.flags = EM_NOMARK;
2117 $$.default_value = 0;
2118 }
Lev Walkinf15320b2004-06-03 03:38:44 +00002119 | Marker { $$ = $1; }
2120 ;
2121
2122Marker:
2123 TOK_OPTIONAL {
Lev Walkin70853052005-11-26 11:21:55 +00002124 $$.flags = EM_OPTIONAL | EM_INDIRECT;
Lev Walkin9c974182004-09-15 11:59:51 +00002125 $$.default_value = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +00002126 }
Lev Walkin9c974182004-09-15 11:59:51 +00002127 | TOK_DEFAULT Value {
2128 $$.flags = EM_DEFAULT;
2129 $$.default_value = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00002130 }
2131 ;
2132
2133/*
2134 * Universal enumeration definition to use in INTEGER and ENUMERATED.
2135 * === EXAMPLE ===
2136 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
2137 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
2138 * === EOF ===
2139 */
2140/*
2141optUniverationDefinition:
2142 { $$ = 0; }
2143 | UniverationDefinition {
2144 $$ = $1;
2145 }
2146 ;
2147*/
2148
2149UniverationDefinition:
2150 '{' '}' {
Lev Walkina9532f42006-09-17 04:52:50 +00002151 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002152 checkmem($$);
2153 }
2154 | '{' UniverationList '}' {
2155 $$ = $2;
2156 }
2157 ;
2158
2159UniverationList:
2160 UniverationElement {
Lev Walkina9532f42006-09-17 04:52:50 +00002161 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002162 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00002163 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00002164 }
2165 | UniverationList ',' UniverationElement {
2166 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00002167 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002168 }
2169 ;
2170
2171UniverationElement:
2172 Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +00002173 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002174 checkmem($$);
2175 $$->expr_type = A1TC_UNIVERVAL;
2176 $$->meta_type = AMT_VALUE;
2177 $$->Identifier = $1;
2178 }
2179 | Identifier '(' SignedNumber ')' {
Lev Walkina9532f42006-09-17 04:52:50 +00002180 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002181 checkmem($$);
2182 $$->expr_type = A1TC_UNIVERVAL;
2183 $$->meta_type = AMT_VALUE;
2184 $$->Identifier = $1;
2185 $$->value = $3;
2186 }
2187 | Identifier '(' DefinedValue ')' {
Lev Walkina9532f42006-09-17 04:52:50 +00002188 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002189 checkmem($$);
2190 $$->expr_type = A1TC_UNIVERVAL;
2191 $$->meta_type = AMT_VALUE;
2192 $$->Identifier = $1;
2193 $$->value = $3;
2194 }
2195 | SignedNumber {
Lev Walkina9532f42006-09-17 04:52:50 +00002196 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002197 checkmem($$);
2198 $$->expr_type = A1TC_UNIVERVAL;
2199 $$->meta_type = AMT_VALUE;
2200 $$->value = $1;
2201 }
2202 | TOK_ThreeDots {
Lev Walkina9532f42006-09-17 04:52:50 +00002203 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002204 checkmem($$);
2205 $$->Identifier = strdup("...");
2206 checkmem($$->Identifier);
2207 $$->expr_type = A1TC_EXTENSIBLE;
2208 $$->meta_type = AMT_VALUE;
2209 }
2210 ;
2211
2212SignedNumber:
2213 TOK_number {
2214 $$ = asn1p_value_fromint($1);
2215 checkmem($$);
2216 }
2217 | TOK_number_negative {
2218 $$ = asn1p_value_fromint($1);
2219 checkmem($$);
2220 }
2221 ;
2222
Lev Walkinadf863f2006-09-05 16:18:34 +00002223RealValue:
2224 SignedNumber
2225 | TOK_realnumber {
2226 $$ = asn1p_value_fromdouble($1);
2227 checkmem($$);
2228 }
2229 ;
2230
Lev Walkinf15320b2004-06-03 03:38:44 +00002231/*
2232 * SEQUENCE definition.
2233 * === EXAMPLE ===
2234 * Struct1 ::= SEQUENCE {
2235 * memb1 Struct2,
2236 * memb2 SEQUENCE OF {
2237 * memb2-1 Struct 3
2238 * }
2239 * }
2240 * === EOF ===
2241 */
2242
2243
2244
2245/*
2246 * SET definition.
2247 * === EXAMPLE ===
2248 * Person ::= SET {
2249 * name [0] PrintableString (SIZE(1..20)),
2250 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2251 * }
2252 * === EOF ===
2253 */
2254
2255optTag:
2256 { memset(&$$, 0, sizeof($$)); }
2257 | Tag { $$ = $1; }
2258 ;
2259
2260Tag:
Lev Walkinc603f102005-01-23 09:51:44 +00002261 TagTypeValue TagPlicit {
Lev Walkinf15320b2004-06-03 03:38:44 +00002262 $$ = $1;
Lev Walkinc603f102005-01-23 09:51:44 +00002263 $$.tag_mode = $2.tag_mode;
Lev Walkinf15320b2004-06-03 03:38:44 +00002264 }
Lev Walkinc603f102005-01-23 09:51:44 +00002265 ;
2266
2267TagTypeValue:
2268 '[' TagClass TOK_number ']' {
2269 $$ = $2;
2270 $$.tag_value = $3;
2271 };
2272
2273TagClass:
2274 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2275 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2276 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2277 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2278 ;
2279
2280TagPlicit:
2281 { $$.tag_mode = TM_DEFAULT; }
2282 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2283 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
Lev Walkinf15320b2004-06-03 03:38:44 +00002284 ;
2285
2286TypeRefName:
2287 TOK_typereference {
2288 checkmem($1);
2289 $$ = $1;
2290 }
Lev Walkinf59d0752004-08-18 04:59:12 +00002291 | TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002292 checkmem($1);
2293 $$ = $1;
2294 }
2295 ;
2296
Lev Walkinf59d0752004-08-18 04:59:12 +00002297
Lev Walkinf15320b2004-06-03 03:38:44 +00002298ObjectClassReference:
Lev Walkinf59d0752004-08-18 04:59:12 +00002299 TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002300 checkmem($1);
2301 $$ = $1;
2302 }
2303 ;
2304
Lev Walkin83cac2f2004-09-22 16:03:36 +00002305optIdentifier:
2306 { $$ = 0; }
2307 | Identifier {
2308 $$ = $1;
2309 }
Lev Walkin8f294e02005-06-06 08:28:58 +00002310 ;
Lev Walkin83cac2f2004-09-22 16:03:36 +00002311
Lev Walkinf15320b2004-06-03 03:38:44 +00002312Identifier:
2313 TOK_identifier {
2314 checkmem($1);
2315 $$ = $1;
2316 }
2317 ;
2318
Lev Walkinf15320b2004-06-03 03:38:44 +00002319%%
2320
2321
2322/*
2323 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2324 */
2325static asn1p_value_t *
2326_convert_bitstring2binary(char *str, int base) {
2327 asn1p_value_t *val;
2328 int slen;
2329 int memlen;
2330 int baselen;
2331 int bits;
2332 uint8_t *binary_vector;
2333 uint8_t *bv_ptr;
2334 uint8_t cur_val;
2335
2336 assert(str);
2337 assert(str[0] == '\'');
2338
2339 switch(base) {
2340 case 'B':
2341 baselen = 1;
2342 break;
2343 case 'H':
2344 baselen = 4;
2345 break;
2346 default:
2347 assert(base == 'B' || base == 'H');
2348 errno = EINVAL;
2349 return NULL;
2350 }
2351
2352 slen = strlen(str);
2353 assert(str[slen - 1] == base);
2354 assert(str[slen - 2] == '\'');
2355
2356 memlen = slen / (8 / baselen); /* Conservative estimate */
2357
2358 bv_ptr = binary_vector = malloc(memlen + 1);
2359 if(bv_ptr == NULL)
2360 /* ENOMEM */
2361 return NULL;
2362
2363 cur_val = 0;
2364 bits = 0;
2365 while(*(++str) != '\'') {
2366 switch(baselen) {
2367 case 1:
2368 switch(*str) {
2369 case '1':
2370 cur_val |= 1 << (7 - (bits % 8));
2371 case '0':
2372 break;
2373 default:
2374 assert(!"_y UNREACH1");
2375 case ' ': case '\r': case '\n':
2376 continue;
2377 }
2378 break;
2379 case 4:
2380 switch(*str) {
2381 case '0': case '1': case '2': case '3': case '4':
2382 case '5': case '6': case '7': case '8': case '9':
2383 cur_val |= (*str - '0') << (4 - (bits % 8));
2384 break;
2385 case 'A': case 'B': case 'C':
2386 case 'D': case 'E': case 'F':
2387 cur_val |= ((*str - 'A') + 10)
2388 << (4 - (bits % 8));
2389 break;
2390 default:
2391 assert(!"_y UNREACH2");
2392 case ' ': case '\r': case '\n':
2393 continue;
2394 }
2395 break;
2396 }
2397
2398 bits += baselen;
2399 if((bits % 8) == 0) {
2400 *bv_ptr++ = cur_val;
2401 cur_val = 0;
2402 }
2403 }
2404
2405 *bv_ptr = cur_val;
2406 assert((bv_ptr - binary_vector) <= memlen);
2407
2408 val = asn1p_value_frombits(binary_vector, bits, 0);
2409 if(val == NULL) {
2410 free(binary_vector);
2411 }
2412
2413 return val;
2414}
2415
Lev Walkin2e9bd5c2005-08-13 09:07:11 +00002416/*
2417 * For unnamed types (used in old X.208 compliant modules)
2418 * generate some sort of interim names, to not to force human being to fix
2419 * the specification's compliance to modern ASN.1 standards.
2420 */
2421static void
2422_fixup_anonymous_identifier(asn1p_expr_t *expr) {
2423 char *p;
2424 assert(expr->Identifier == 0);
2425
2426 /*
2427 * Try to figure out the type name
2428 * without going too much into details
2429 */
2430 expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type);
2431 if(expr->reference && expr->reference->comp_count > 0)
2432 expr->Identifier = expr->reference->components[0].name;
2433
2434 fprintf(stderr,
2435 "WARNING: Line %d: expected lower-case member identifier, "
2436 "found an unnamed %s.\n"
2437 "WARNING: Obsolete X.208 syntax detected, "
2438 "please give the member a name.\n",
2439 yylineno, expr->Identifier ? expr->Identifier : "type");
2440
2441 if(!expr->Identifier)
2442 expr->Identifier = "unnamed";
2443 expr->Identifier = strdup(expr->Identifier);
2444 assert(expr->Identifier);
2445 /* Make a lowercase identifier from the type name */
2446 for(p = expr->Identifier; *p; p++) {
2447 switch(*p) {
2448 case 'A' ... 'Z': *p += 32; break;
2449 case ' ': *p = '_'; break;
2450 case '-': *p = '_'; break;
2451 }
2452 }
2453 fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". "
2454 "Name clash may occur later.\n",
2455 expr->Identifier);
2456}
2457
Lev Walkinf15320b2004-06-03 03:38:44 +00002458int
2459yyerror(const char *msg) {
Lev Walkin9d542d22006-03-14 16:31:37 +00002460 extern char *asn1p_text;
Lev Walkinf15320b2004-06-03 03:38:44 +00002461 fprintf(stderr,
2462 "ASN.1 grammar parse error "
2463 "near line %d (token \"%s\"): %s\n",
Lev Walkinceb20e72004-09-05 10:40:41 +00002464 yylineno, asn1p_text, msg);
Lev Walkinf15320b2004-06-03 03:38:44 +00002465 return -1;
2466}
2467