blob: f7df754e4505dd1bdfb283e9e7806b59a51c3e2a [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/*
27 * This temporary variable is used to solve the shortcomings of 1-lookahead
28 * parser.
29 */
30static struct AssignedIdentifier *saved_aid;
Lev Walkinf15320b2004-06-03 03:38:44 +000031
32static asn1p_value_t *
33 _convert_bitstring2binary(char *str, int base);
34
Lev Walkin1ed22092005-08-12 10:06:17 +000035#define checkmem(ptr) do { \
36 if(!(ptr)) \
37 return yyerror("Memory failure"); \
Lev Walkinf15320b2004-06-03 03:38:44 +000038 } while(0)
39
Lev Walkin2c14a692005-08-12 10:08:45 +000040#define CONSTRAINT_INSERT(root, constr_type, arg1, arg2) do { \
Lev Walkin1ed22092005-08-12 10:06:17 +000041 if(arg1->type != constr_type) { \
42 int __ret; \
43 root = asn1p_constraint_new(yylineno); \
44 checkmem(root); \
45 root->type = constr_type; \
46 __ret = asn1p_constraint_insert(root, \
47 arg1); \
48 checkmem(__ret == 0); \
49 } else { \
50 root = arg1; \
51 } \
52 if(arg2) { \
53 int __ret \
54 = asn1p_constraint_insert(root, arg2); \
55 checkmem(__ret == 0); \
56 } \
Lev Walkinf15320b2004-06-03 03:38:44 +000057 } while(0)
58
59%}
60
61
62/*
63 * Token value definition.
64 * a_*: ASN-specific types.
65 * tv_*: Locally meaningful types.
66 */
67%union {
68 asn1p_t *a_grammar;
69 asn1p_module_flags_e a_module_flags;
70 asn1p_module_t *a_module;
71 asn1p_expr_type_e a_type; /* ASN.1 Type */
72 asn1p_expr_t *a_expr; /* Constructed collection */
73 asn1p_constraint_t *a_constr; /* Constraint */
74 enum asn1p_constraint_type_e a_ctype;/* Constraint type */
75 asn1p_xports_t *a_xports; /* IMports/EXports */
Lev Walkin1ed22092005-08-12 10:06:17 +000076 struct AssignedIdentifier a_aid; /* Assigned Identifier */
Lev Walkinf15320b2004-06-03 03:38:44 +000077 asn1p_oid_t *a_oid; /* Object Identifier */
78 asn1p_oid_arc_t a_oid_arc; /* Single OID's arc */
79 struct asn1p_type_tag_s a_tag; /* A tag */
80 asn1p_ref_t *a_ref; /* Reference to custom type */
81 asn1p_wsyntx_t *a_wsynt; /* WITH SYNTAX contents */
82 asn1p_wsyntx_chunk_t *a_wchunk; /* WITH SYNTAX chunk */
83 struct asn1p_ref_component_s a_refcomp; /* Component of a reference */
84 asn1p_value_t *a_value; /* Number, DefinedValue, etc */
85 struct asn1p_param_s a_parg; /* A parameter argument */
86 asn1p_paramlist_t *a_plist; /* A pargs list */
Lev Walkin9c974182004-09-15 11:59:51 +000087 struct asn1p_expr_marker_s a_marker; /* OPTIONAL/DEFAULT */
Lev Walkinf15320b2004-06-03 03:38:44 +000088 enum asn1p_constr_pres_e a_pres; /* PRESENT/ABSENT/OPTIONAL */
Lev Walkin144db9b2004-10-12 23:26:53 +000089 asn1c_integer_t a_int;
Lev Walkinf15320b2004-06-03 03:38:44 +000090 char *tv_str;
91 struct {
92 char *buf;
93 int len;
94 } tv_opaque;
95 struct {
96 char *name;
97 struct asn1p_type_tag_s tag;
98 } tv_nametag;
99};
100
101/*
102 * Token types returned by scanner.
103 */
104%token TOK_PPEQ /* "::=", Pseudo Pascal EQuality */
105%token <tv_opaque> TOK_opaque /* opaque data (driven from .y) */
106%token <tv_str> TOK_bstring
107%token <tv_opaque> TOK_cstring
108%token <tv_str> TOK_hstring
109%token <tv_str> TOK_identifier
110%token <a_int> TOK_number
Lev Walkind9574ae2005-03-24 16:22:35 +0000111%token <a_int> TOK_tuple
112%token <a_int> TOK_quadruple
Lev Walkinf15320b2004-06-03 03:38:44 +0000113%token <a_int> TOK_number_negative
114%token <tv_str> TOK_typereference
Lev Walkinf59d0752004-08-18 04:59:12 +0000115%token <tv_str> TOK_capitalreference /* "CLASS1" */
Lev Walkinf15320b2004-06-03 03:38:44 +0000116%token <tv_str> TOK_typefieldreference /* "&Pork" */
117%token <tv_str> TOK_valuefieldreference /* "&id" */
118
119/*
120 * Token types representing ASN.1 standard keywords.
121 */
122%token TOK_ABSENT
123%token TOK_ABSTRACT_SYNTAX
124%token TOK_ALL
125%token TOK_ANY
126%token TOK_APPLICATION
127%token TOK_AUTOMATIC
128%token TOK_BEGIN
129%token TOK_BIT
130%token TOK_BMPString
131%token TOK_BOOLEAN
132%token TOK_BY
133%token TOK_CHARACTER
134%token TOK_CHOICE
135%token TOK_CLASS
136%token TOK_COMPONENT
137%token TOK_COMPONENTS
138%token TOK_CONSTRAINED
139%token TOK_CONTAINING
140%token TOK_DEFAULT
141%token TOK_DEFINITIONS
142%token TOK_DEFINED
143%token TOK_EMBEDDED
144%token TOK_ENCODED
Lev Walkinf59d0752004-08-18 04:59:12 +0000145%token TOK_ENCODING_CONTROL
Lev Walkinf15320b2004-06-03 03:38:44 +0000146%token TOK_END
147%token TOK_ENUMERATED
148%token TOK_EXPLICIT
149%token TOK_EXPORTS
150%token TOK_EXTENSIBILITY
151%token TOK_EXTERNAL
152%token TOK_FALSE
153%token TOK_FROM
154%token TOK_GeneralizedTime
155%token TOK_GeneralString
156%token TOK_GraphicString
157%token TOK_IA5String
158%token TOK_IDENTIFIER
159%token TOK_IMPLICIT
160%token TOK_IMPLIED
161%token TOK_IMPORTS
162%token TOK_INCLUDES
163%token TOK_INSTANCE
Lev Walkinf59d0752004-08-18 04:59:12 +0000164%token TOK_INSTRUCTIONS
Lev Walkinf15320b2004-06-03 03:38:44 +0000165%token TOK_INTEGER
166%token TOK_ISO646String
167%token TOK_MAX
168%token TOK_MIN
169%token TOK_MINUS_INFINITY
170%token TOK_NULL
171%token TOK_NumericString
172%token TOK_OBJECT
173%token TOK_ObjectDescriptor
174%token TOK_OCTET
175%token TOK_OF
176%token TOK_OPTIONAL
177%token TOK_PATTERN
178%token TOK_PDV
179%token TOK_PLUS_INFINITY
180%token TOK_PRESENT
181%token TOK_PrintableString
182%token TOK_PRIVATE
183%token TOK_REAL
184%token TOK_RELATIVE_OID
185%token TOK_SEQUENCE
186%token TOK_SET
187%token TOK_SIZE
188%token TOK_STRING
189%token TOK_SYNTAX
190%token TOK_T61String
191%token TOK_TAGS
192%token TOK_TeletexString
193%token TOK_TRUE
194%token TOK_TYPE_IDENTIFIER
195%token TOK_UNIQUE
196%token TOK_UNIVERSAL
197%token TOK_UniversalString
198%token TOK_UTCTime
199%token TOK_UTF8String
200%token TOK_VideotexString
201%token TOK_VisibleString
202%token TOK_WITH
203
Lev Walkinf15320b2004-06-03 03:38:44 +0000204%left TOK_EXCEPT
Lev Walkinf59d0752004-08-18 04:59:12 +0000205%left '^' TOK_INTERSECTION
206%left '|' TOK_UNION
Lev Walkinf15320b2004-06-03 03:38:44 +0000207
208/* Misc tags */
209%token TOK_TwoDots /* .. */
210%token TOK_ThreeDots /* ... */
Lev Walkinf15320b2004-06-03 03:38:44 +0000211
212
213/*
214 * Types defined herein.
215 */
216%type <a_grammar> ModuleList
217%type <a_module> ModuleSpecification
218%type <a_module> ModuleSpecificationBody
219%type <a_module> ModuleSpecificationElement
220%type <a_module> optModuleSpecificationBody /* Optional */
221%type <a_module_flags> optModuleSpecificationFlags
222%type <a_module_flags> ModuleSpecificationFlags /* Set of FL */
223%type <a_module_flags> ModuleSpecificationFlag /* Single FL */
224%type <a_module> ImportsDefinition
225%type <a_module> ImportsBundleSet
226%type <a_xports> ImportsBundle
227%type <a_xports> ImportsList
228%type <a_xports> ExportsDefinition
229%type <a_xports> ExportsBody
230%type <a_expr> ImportsElement
231%type <a_expr> ExportsElement
Lev Walkinf15320b2004-06-03 03:38:44 +0000232%type <a_expr> ExtensionAndException
Lev Walkin070a52d2004-08-22 03:19:54 +0000233%type <a_expr> TypeDeclaration
Lev Walkinf15320b2004-06-03 03:38:44 +0000234%type <a_ref> ComplexTypeReference
235%type <a_ref> ComplexTypeReferenceAmpList
236%type <a_refcomp> ComplexTypeReferenceElement
237%type <a_refcomp> ClassFieldIdentifier
238%type <a_refcomp> ClassFieldName
239%type <a_expr> ClassFieldList
240%type <a_expr> ClassField
241%type <a_expr> ClassDeclaration
Lev Walkin070a52d2004-08-22 03:19:54 +0000242%type <a_expr> Type
Lev Walkinf15320b2004-06-03 03:38:44 +0000243%type <a_expr> DataTypeReference /* Type1 ::= Type2 */
244%type <a_expr> DefinedTypeRef
245%type <a_expr> ValueSetDefinition /* Val INTEGER ::= {1|2} */
246%type <a_expr> ValueDefinition /* val INTEGER ::= 1*/
Lev Walkin9c974182004-09-15 11:59:51 +0000247%type <a_value> Value
Lev Walkinf15320b2004-06-03 03:38:44 +0000248%type <a_value> DefinedValue
249%type <a_value> SignedNumber
Lev Walkin144db9b2004-10-12 23:26:53 +0000250%type <a_expr> optComponentTypeLists
Lev Walkin070a52d2004-08-22 03:19:54 +0000251%type <a_expr> ComponentTypeLists
252%type <a_expr> ComponentType
253%type <a_expr> AlternativeTypeLists
254%type <a_expr> AlternativeType
Lev Walkinf15320b2004-06-03 03:38:44 +0000255//%type <a_expr> optUniverationDefinition
256%type <a_expr> UniverationDefinition
257%type <a_expr> UniverationList
258%type <a_expr> UniverationElement
259%type <tv_str> TypeRefName
260%type <tv_str> ObjectClassReference
Lev Walkinf15320b2004-06-03 03:38:44 +0000261%type <tv_str> Identifier
Lev Walkin83cac2f2004-09-22 16:03:36 +0000262%type <tv_str> optIdentifier
Lev Walkinf15320b2004-06-03 03:38:44 +0000263%type <a_parg> ParameterArgumentName
264%type <a_plist> ParameterArgumentList
265%type <a_expr> ActualParameter
266%type <a_expr> ActualParameterList
Lev Walkin1ed22092005-08-12 10:06:17 +0000267%type <a_aid> AssignedIdentifier /* OID/DefinedValue */
Lev Walkinf15320b2004-06-03 03:38:44 +0000268%type <a_oid> ObjectIdentifier /* OID */
269%type <a_oid> optObjectIdentifier /* Optional OID */
270%type <a_oid> ObjectIdentifierBody
271%type <a_oid_arc> ObjectIdentifierElement
272%type <a_expr> BasicType
273%type <a_type> BasicTypeId
274%type <a_type> BasicTypeId_UniverationCompatible
275%type <a_type> BasicString
276%type <tv_opaque> Opaque
277//%type <tv_opaque> StringValue
Lev Walkinc603f102005-01-23 09:51:44 +0000278%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
279%type <a_tag> TagClass TagTypeValue TagPlicit
Lev Walkinf15320b2004-06-03 03:38:44 +0000280%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
281%type <a_constr> optConstraints
Lev Walkind2ea1de2004-08-20 13:25:29 +0000282%type <a_constr> Constraints
Lev Walkinf59d0752004-08-18 04:59:12 +0000283%type <a_constr> SetOfConstraints
284%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
285%type <a_constr> ElementSetSpec /* 1..2,...,3 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000286%type <a_constr> ConstraintSubtypeElement /* 1..2 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000287%type <a_constr> SimpleTableConstraint
288%type <a_constr> TableConstraint
Lev Walkine596bf02005-03-28 15:01:27 +0000289%type <a_constr> InnerTypeConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +0000290%type <a_constr> WithComponentsList
291%type <a_constr> WithComponentsElement
292%type <a_constr> ComponentRelationConstraint
293%type <a_constr> AtNotationList
294%type <a_ref> AtNotationElement
Lev Walkinff7dd142005-03-20 12:58:00 +0000295%type <a_value> SingleValue
296%type <a_value> ContainedSubtype
Lev Walkinf15320b2004-06-03 03:38:44 +0000297%type <a_ctype> ConstraintSpec
298%type <a_ctype> ConstraintRangeSpec
Lev Walkin1e448d32005-03-24 14:26:38 +0000299%type <a_value> RestrictedCharacterStringValue
Lev Walkinf15320b2004-06-03 03:38:44 +0000300%type <a_wsynt> optWithSyntax
301%type <a_wsynt> WithSyntax
302%type <a_wsynt> WithSyntaxFormat
303%type <a_wchunk> WithSyntaxFormatToken
304%type <a_marker> optMarker Marker
305%type <a_int> optUnique
306%type <a_pres> optPresenceConstraint PresenceConstraint
307%type <tv_str> ComponentIdList
308
309
310%%
311
312
313ParsedGrammar:
314 ModuleList {
315 *(void **)param = $1;
316 }
317 ;
318
319ModuleList:
320 ModuleSpecification {
321 $$ = asn1p_new();
322 checkmem($$);
323 TQ_ADD(&($$->modules), $1, mod_next);
324 }
325 | ModuleList ModuleSpecification {
326 $$ = $1;
327 TQ_ADD(&($$->modules), $2, mod_next);
328 }
329 ;
330
331/*
332 * ASN module definition.
333 * === EXAMPLE ===
334 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
335 * BEGIN
336 * ...
337 * END
338 * === EOF ===
339 */
340
341ModuleSpecification:
342 TypeRefName optObjectIdentifier TOK_DEFINITIONS
343 optModuleSpecificationFlags
344 TOK_PPEQ TOK_BEGIN
345 optModuleSpecificationBody
346 TOK_END {
347
348 if($7) {
349 $$ = $7;
350 } else {
351 /* There's a chance that a module is just plain empty */
352 $$ = asn1p_module_new();
353 }
354 checkmem($$);
355
Lev Walkin1ed22092005-08-12 10:06:17 +0000356 $$->ModuleName = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000357 $$->module_oid = $2;
358 $$->module_flags = $4;
359 }
360 ;
361
362/*
363 * Object Identifier Definition
364 * { iso member-body(2) 3 }
365 */
366optObjectIdentifier:
367 { $$ = 0; }
368 | ObjectIdentifier { $$ = $1; }
369 ;
370
371ObjectIdentifier:
372 '{' ObjectIdentifierBody '}' {
373 $$ = $2;
374 }
375 | '{' '}' {
376 $$ = 0;
377 }
378 ;
379
380ObjectIdentifierBody:
381 ObjectIdentifierElement {
382 $$ = asn1p_oid_new();
383 asn1p_oid_add_arc($$, &$1);
384 if($1.name)
385 free($1.name);
386 }
387 | ObjectIdentifierBody ObjectIdentifierElement {
388 $$ = $1;
389 asn1p_oid_add_arc($$, &$2);
390 if($2.name)
391 free($2.name);
392 }
393 ;
394
395ObjectIdentifierElement:
396 Identifier { /* iso */
397 $$.name = $1;
398 $$.number = -1;
399 }
400 | Identifier '(' TOK_number ')' { /* iso(1) */
401 $$.name = $1;
402 $$.number = $3;
403 }
404 | TOK_number { /* 1 */
405 $$.name = 0;
406 $$.number = $1;
407 }
408 ;
409
410/*
411 * Optional module flags.
412 */
413optModuleSpecificationFlags:
414 { $$ = MSF_NOFLAGS; }
415 | ModuleSpecificationFlags {
416 $$ = $1;
417 }
418 ;
419
420/*
421 * Module flags.
422 */
423ModuleSpecificationFlags:
424 ModuleSpecificationFlag {
425 $$ = $1;
426 }
427 | ModuleSpecificationFlags ModuleSpecificationFlag {
428 $$ = $1 | $2;
429 }
430 ;
431
432/*
433 * Single module flag.
434 */
435ModuleSpecificationFlag:
436 TOK_EXPLICIT TOK_TAGS {
437 $$ = MSF_EXPLICIT_TAGS;
438 }
439 | TOK_IMPLICIT TOK_TAGS {
440 $$ = MSF_IMPLICIT_TAGS;
441 }
442 | TOK_AUTOMATIC TOK_TAGS {
443 $$ = MSF_AUTOMATIC_TAGS;
444 }
445 | TOK_EXTENSIBILITY TOK_IMPLIED {
446 $$ = MSF_EXTENSIBILITY_IMPLIED;
447 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000448 /* EncodingReferenceDefault */
449 | TOK_capitalreference TOK_INSTRUCTIONS {
450 /* X.680Amd1 specifies TAG and XER */
451 if(strcmp($1, "TAG") == 0) {
452 $$ = MSF_TAG_INSTRUCTIONS;
453 } else if(strcmp($1, "XER") == 0) {
454 $$ = MSF_XER_INSTRUCTIONS;
455 } else {
456 fprintf(stderr,
457 "WARNING: %s INSTRUCTIONS at line %d: "
458 "Unrecognized encoding reference\n",
459 $1, yylineno);
460 $$ = MSF_unk_INSTRUCTIONS;
461 }
462 free($1);
463 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000464 ;
465
466/*
467 * Optional module body.
468 */
469optModuleSpecificationBody:
470 { $$ = 0; }
471 | ModuleSpecificationBody {
Lev Walkinf15320b2004-06-03 03:38:44 +0000472 $$ = $1;
473 }
474 ;
475
476/*
477 * ASN.1 Module body.
478 */
479ModuleSpecificationBody:
480 ModuleSpecificationElement {
481 $$ = $1;
482 }
483 | ModuleSpecificationBody ModuleSpecificationElement {
484 $$ = $1;
485
Lev Walkinf59d0752004-08-18 04:59:12 +0000486 /* Behave well when one of them is skipped. */
487 if(!($1)) {
488 if($2) $$ = $2;
489 break;
490 }
491
Lev Walkinf15320b2004-06-03 03:38:44 +0000492#ifdef MY_IMPORT
493#error MY_IMPORT DEFINED ELSEWHERE!
494#endif
495#define MY_IMPORT(foo,field) do { \
Lev Walkinbc55d232004-08-13 12:31:09 +0000496 while(TQ_FIRST(&($2->foo))) { \
Lev Walkinf15320b2004-06-03 03:38:44 +0000497 TQ_ADD(&($$->foo), \
498 TQ_REMOVE(&($2->foo), field), \
499 field); \
Lev Walkinbc55d232004-08-13 12:31:09 +0000500 } \
501 assert(TQ_FIRST(&($2->foo)) == 0); \
502 } while(0)
Lev Walkinf15320b2004-06-03 03:38:44 +0000503
504 MY_IMPORT(imports, xp_next);
505 MY_IMPORT(exports, xp_next);
506 MY_IMPORT(members, next);
507#undef MY_IMPORT
508
509 }
510 ;
511
512/*
513 * One of the elements of ASN.1 module specification.
514 */
515ModuleSpecificationElement:
516 ImportsDefinition {
517 $$ = $1;
518 }
519 | ExportsDefinition {
520 $$ = asn1p_module_new();
521 checkmem($$);
522 if($1) {
523 TQ_ADD(&($$->exports), $1, xp_next);
524 } else {
525 /* "EXPORTS ALL;" ? */
526 }
527 }
528 | DataTypeReference {
529 $$ = asn1p_module_new();
530 checkmem($$);
531 assert($1->expr_type != A1TC_INVALID);
532 assert($1->meta_type != AMT_INVALID);
533 TQ_ADD(&($$->members), $1, next);
534 }
535 | ValueDefinition {
536 $$ = asn1p_module_new();
537 checkmem($$);
538 assert($1->expr_type != A1TC_INVALID);
539 assert($1->meta_type != AMT_INVALID);
540 TQ_ADD(&($$->members), $1, next);
541 }
542 /*
543 * Value set definition
544 * === EXAMPLE ===
545 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
546 * === EOF ===
547 */
548 | ValueSetDefinition {
549 $$ = asn1p_module_new();
550 checkmem($$);
551 assert($1->expr_type != A1TC_INVALID);
552 assert($1->meta_type != AMT_INVALID);
553 TQ_ADD(&($$->members), $1, next);
554 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000555 | TOK_ENCODING_CONTROL TOK_capitalreference
556 { asn1p_lexer_hack_push_encoding_control(); }
557 {
558 fprintf(stderr,
559 "WARNING: ENCODING-CONTROL %s "
560 "specification at line %d ignored\n",
561 $2, yylineno);
562 free($2);
563 $$ = 0;
564 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000565
566 /*
567 * Erroneous attemps
568 */
569 | BasicString {
570 return yyerror(
571 "Attempt to redefine a standard basic type, "
572 "use -ftypesXY to switch back "
573 "to older version of ASN.1 standard");
574 }
575 ;
576
577/*
578 * === EXAMPLE ===
579 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
580 * === EOF ===
581 */
582ImportsDefinition:
583 TOK_IMPORTS ImportsBundleSet ';' {
Lev Walkin1ed22092005-08-12 10:06:17 +0000584 if(!saved_aid && 0)
585 return yyerror("Unterminated IMPORTS FROM, "
586 "expected semicolon ';'");
587 saved_aid = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +0000588 $$ = $2;
589 }
590 /*
591 * Some error cases.
592 */
593 | TOK_IMPORTS TOK_FROM /* ... */ {
594 return yyerror("Empty IMPORTS list");
595 }
596 ;
597
598ImportsBundleSet:
599 ImportsBundle {
600 $$ = asn1p_module_new();
601 checkmem($$);
602 TQ_ADD(&($$->imports), $1, xp_next);
603 }
604 | ImportsBundleSet ImportsBundle {
605 $$ = $1;
606 TQ_ADD(&($$->imports), $2, xp_next);
607 }
608 ;
609
Lev Walkin1ed22092005-08-12 10:06:17 +0000610AssignedIdentifier:
611 { memset(&$$, 0, sizeof($$)); }
612 | ObjectIdentifier { $$.oid = $1; };
613 /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
614
Lev Walkinf15320b2004-06-03 03:38:44 +0000615ImportsBundle:
Lev Walkin1ed22092005-08-12 10:06:17 +0000616 ImportsList TOK_FROM TypeRefName AssignedIdentifier {
Lev Walkinf15320b2004-06-03 03:38:44 +0000617 $$ = $1;
Lev Walkin1ed22092005-08-12 10:06:17 +0000618 $$->fromModuleName = $3;
619 $$->identifier = $4;
620 /* This stupid thing is used for look-back hack. */
621 saved_aid = $$->identifier.oid ? 0 : &($$->identifier);
Lev Walkinf15320b2004-06-03 03:38:44 +0000622 checkmem($$);
623 }
624 ;
625
626ImportsList:
627 ImportsElement {
628 $$ = asn1p_xports_new();
629 checkmem($$);
630 TQ_ADD(&($$->members), $1, next);
631 }
632 | ImportsList ',' ImportsElement {
633 $$ = $1;
634 TQ_ADD(&($$->members), $3, next);
635 }
636 ;
637
638ImportsElement:
639 TypeRefName {
640 $$ = asn1p_expr_new(yylineno);
641 checkmem($$);
642 $$->Identifier = $1;
643 $$->expr_type = A1TC_REFERENCE;
644 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000645 | TypeRefName '{' '}' { /* Completely equivalent to above */
646 $$ = asn1p_expr_new(yylineno);
647 checkmem($$);
648 $$->Identifier = $1;
649 $$->expr_type = A1TC_REFERENCE;
650 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000651 | Identifier {
652 $$ = asn1p_expr_new(yylineno);
653 checkmem($$);
654 $$->Identifier = $1;
655 $$->expr_type = A1TC_REFERENCE;
656 }
657 ;
658
659ExportsDefinition:
660 TOK_EXPORTS ExportsBody ';' {
661 $$ = $2;
662 }
663 | TOK_EXPORTS TOK_ALL ';' {
664 $$ = 0;
665 }
666 | TOK_EXPORTS ';' {
667 /* Empty EXPORTS clause effectively prohibits export. */
668 $$ = asn1p_xports_new();
669 checkmem($$);
670 }
671 ;
672
673ExportsBody:
674 ExportsElement {
675 $$ = asn1p_xports_new();
676 assert($$);
677 TQ_ADD(&($$->members), $1, next);
678 }
679 | ExportsBody ',' ExportsElement {
680 $$ = $1;
681 TQ_ADD(&($$->members), $3, next);
682 }
683 ;
684
685ExportsElement:
686 TypeRefName {
687 $$ = asn1p_expr_new(yylineno);
688 checkmem($$);
689 $$->Identifier = $1;
690 $$->expr_type = A1TC_EXPORTVAR;
691 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000692 | TypeRefName '{' '}' {
693 $$ = asn1p_expr_new(yylineno);
694 checkmem($$);
695 $$->Identifier = $1;
696 $$->expr_type = A1TC_EXPORTVAR;
697 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000698 | Identifier {
699 $$ = asn1p_expr_new(yylineno);
700 checkmem($$);
701 $$->Identifier = $1;
702 $$->expr_type = A1TC_EXPORTVAR;
703 }
704 ;
705
706
707ValueSetDefinition:
Lev Walkin8ea99482005-03-31 21:48:13 +0000708 TypeRefName DefinedTypeRef TOK_PPEQ
709 '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Lev Walkinf15320b2004-06-03 03:38:44 +0000710 $$ = $2;
711 assert($$->Identifier == 0);
712 $$->Identifier = $1;
713 $$->meta_type = AMT_VALUESET;
Lev Walkin8ea99482005-03-31 21:48:13 +0000714 // take care of ValueSet body
Lev Walkinf15320b2004-06-03 03:38:44 +0000715 }
716 ;
717
718DefinedTypeRef:
719 ComplexTypeReference {
720 $$ = asn1p_expr_new(yylineno);
721 checkmem($$);
722 $$->reference = $1;
723 $$->expr_type = A1TC_REFERENCE;
724 $$->meta_type = AMT_TYPEREF;
725 }
726 | BasicTypeId {
727 $$ = asn1p_expr_new(yylineno);
728 checkmem($$);
729 $$->expr_type = $1;
730 $$->meta_type = AMT_TYPE;
731 }
732 ;
733
Lev Walkinf15320b2004-06-03 03:38:44 +0000734/*
735 * Data Type Reference.
736 * === EXAMPLE ===
737 * Type3 ::= CHOICE { a Type1, b Type 2 }
738 * === EOF ===
739 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000740DataTypeReference:
741 /*
742 * Optionally tagged type definition.
743 */
744 TypeRefName TOK_PPEQ optTag TOK_TYPE_IDENTIFIER {
745 $$ = asn1p_expr_new(yylineno);
746 checkmem($$);
747 $$->Identifier = $1;
748 $$->tag = $3;
749 $$->expr_type = A1TC_TYPEID;
750 $$->meta_type = AMT_TYPE;
751 }
Lev Walkinaf120f72004-09-14 02:36:39 +0000752 | TypeRefName TOK_PPEQ Type {
753 $$ = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000754 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000755 assert($$->expr_type);
756 assert($$->meta_type);
757 }
758 | TypeRefName TOK_PPEQ ClassDeclaration {
759 $$ = $3;
760 $$->Identifier = $1;
761 assert($$->expr_type == A1TC_CLASSDEF);
762 assert($$->meta_type == AMT_OBJECT);
763 }
764 /*
765 * Parametrized <Type> declaration:
766 * === EXAMPLE ===
767 * SIGNED { ToBeSigned } ::= SEQUENCE {
768 * toBeSigned ToBeSigned,
769 * algorithm AlgorithmIdentifier,
770 * signature BIT STRING
771 * }
772 * === EOF ===
773 */
Lev Walkin070a52d2004-08-22 03:19:54 +0000774 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000775 $$ = $6;
776 assert($$->Identifier == 0);
777 $$->Identifier = $1;
778 $$->params = $3;
779 $$->meta_type = AMT_PARAMTYPE;
780 }
781 ;
782
783ParameterArgumentList:
784 ParameterArgumentName {
785 int ret;
786 $$ = asn1p_paramlist_new(yylineno);
787 checkmem($$);
788 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
789 checkmem(ret == 0);
790 if($1.governor) asn1p_ref_free($1.governor);
791 if($1.argument) free($1.argument);
792 }
793 | ParameterArgumentList ',' ParameterArgumentName {
794 int ret;
795 $$ = $1;
796 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
797 checkmem(ret == 0);
798 if($3.governor) asn1p_ref_free($3.governor);
799 if($3.argument) free($3.argument);
800 }
801 ;
802
803ParameterArgumentName:
804 TypeRefName {
805 $$.governor = NULL;
806 $$.argument = $1;
807 }
808 | TypeRefName ':' Identifier {
809 int ret;
810 $$.governor = asn1p_ref_new(yylineno);
811 ret = asn1p_ref_add_component($$.governor, $1, 0);
812 checkmem(ret == 0);
813 $$.argument = $3;
814 }
Lev Walkinc8092cb2005-02-18 16:34:21 +0000815 | TypeRefName ':' TypeRefName {
816 int ret;
817 $$.governor = asn1p_ref_new(yylineno);
818 ret = asn1p_ref_add_component($$.governor, $1, 0);
819 checkmem(ret == 0);
820 $$.argument = $3;
821 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000822 | BasicTypeId ':' Identifier {
823 int ret;
824 $$.governor = asn1p_ref_new(yylineno);
825 ret = asn1p_ref_add_component($$.governor,
826 ASN_EXPR_TYPE2STR($1), 1);
827 checkmem(ret == 0);
828 $$.argument = $3;
829 }
830 ;
831
832ActualParameterList:
833 ActualParameter {
834 $$ = asn1p_expr_new(yylineno);
835 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000836 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000837 }
838 | ActualParameterList ',' ActualParameter {
839 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000840 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000841 }
842 ;
843
844ActualParameter:
Lev Walkin070a52d2004-08-22 03:19:54 +0000845 Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000846 $$ = $1;
847 }
848 | Identifier {
849 $$ = asn1p_expr_new(yylineno);
850 checkmem($$);
851 $$->Identifier = $1;
852 $$->expr_type = A1TC_REFERENCE;
853 $$->meta_type = AMT_VALUE;
854 }
855 ;
856
857/*
Lev Walkinc8092cb2005-02-18 16:34:21 +0000858 | '{' ActualParameter '}' {
859 $$ = asn1p_expr_new(yylineno);
860 checkmem($$);
861 asn1p_expr_add($$, $2);
862 $$->expr_type = A1TC_PARAMETRIZED;
863 $$->meta_type = AMT_TYPE;
864 }
865 ;
866*/
867
868/*
Lev Walkinf15320b2004-06-03 03:38:44 +0000869 * A collection of constructed data type members.
870 */
Lev Walkin144db9b2004-10-12 23:26:53 +0000871optComponentTypeLists:
872 { $$ = asn1p_expr_new(yylineno); }
873 | ComponentTypeLists { $$ = $1; };
874
Lev Walkin070a52d2004-08-22 03:19:54 +0000875ComponentTypeLists:
876 ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +0000877 $$ = asn1p_expr_new(yylineno);
878 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000879 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000880 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000881 | ComponentTypeLists ',' ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +0000882 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000883 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000884 }
885 ;
886
Lev Walkin070a52d2004-08-22 03:19:54 +0000887ComponentType:
Lev Walkinaf120f72004-09-14 02:36:39 +0000888 Identifier Type optMarker {
Lev Walkin070a52d2004-08-22 03:19:54 +0000889 $$ = $2;
890 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +0000891 $$->Identifier = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +0000892 $$->marker = $3;
893 }
894 | TOK_COMPONENTS TOK_OF Type {
895 $$ = asn1p_expr_new(yylineno);
896 checkmem($$);
897 $$->meta_type = $3->meta_type;
898 $$->expr_type = A1TC_COMPONENTS_OF;
Lev Walkin1004aa92004-09-08 00:28:11 +0000899 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +0000900 }
901 | ExtensionAndException {
902 $$ = $1;
903 }
904 ;
905
906AlternativeTypeLists:
907 AlternativeType {
908 $$ = asn1p_expr_new(yylineno);
909 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000910 asn1p_expr_add($$, $1);
Lev Walkin070a52d2004-08-22 03:19:54 +0000911 }
912 | AlternativeTypeLists ',' AlternativeType {
913 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000914 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +0000915 }
916 ;
917
918AlternativeType:
Lev Walkinaf120f72004-09-14 02:36:39 +0000919 Identifier Type {
Lev Walkin070a52d2004-08-22 03:19:54 +0000920 $$ = $2;
921 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +0000922 $$->Identifier = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +0000923 }
924 | ExtensionAndException {
925 $$ = $1;
926 }
927 ;
928
Lev Walkinf15320b2004-06-03 03:38:44 +0000929ClassDeclaration:
930 TOK_CLASS '{' ClassFieldList '}' optWithSyntax {
931 $$ = $3;
932 checkmem($$);
933 $$->with_syntax = $5;
934 assert($$->expr_type == A1TC_CLASSDEF);
935 assert($$->meta_type == AMT_OBJECT);
936 }
937 ;
938
939optUnique:
940 { $$ = 0; }
941 | TOK_UNIQUE { $$ = 1; }
942 ;
943
944ClassFieldList:
945 ClassField {
946 $$ = asn1p_expr_new(yylineno);
947 checkmem($$);
948 $$->expr_type = A1TC_CLASSDEF;
949 $$->meta_type = AMT_OBJECT;
Lev Walkin1004aa92004-09-08 00:28:11 +0000950 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000951 }
952 | ClassFieldList ',' ClassField {
953 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000954 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000955 }
956 ;
957
958ClassField:
959 ClassFieldIdentifier optMarker {
960 $$ = asn1p_expr_new(yylineno);
961 checkmem($$);
962 $$->Identifier = $1.name;
963 $$->expr_type = A1TC_CLASSFIELD;
964 $$->meta_type = AMT_OBJECTFIELD;
965 $$->marker = $2;
966 }
Lev Walkinb7c45ca2004-11-24 17:43:29 +0000967 | ClassFieldIdentifier Type optUnique optMarker {
Lev Walkinf15320b2004-06-03 03:38:44 +0000968 $$ = $2;
969 $$->Identifier = $1.name;
Lev Walkinb7c45ca2004-11-24 17:43:29 +0000970 $$->marker = $4;
971 $$->unique = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000972 }
Lev Walkinb7c45ca2004-11-24 17:43:29 +0000973 | ClassFieldIdentifier ClassFieldIdentifier optUnique optMarker {
Lev Walkinf15320b2004-06-03 03:38:44 +0000974 int ret;
975 $$ = asn1p_expr_new(yylineno);
976 checkmem($$);
977 $$->Identifier = $1.name;
978 $$->reference = asn1p_ref_new(yylineno);
979 checkmem($$->reference);
980 ret = asn1p_ref_add_component($$->reference,
981 $2.name, $2.lex_type);
982 checkmem(ret == 0);
983 $$->expr_type = A1TC_CLASSFIELD;
984 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkinb7c45ca2004-11-24 17:43:29 +0000985 $$->marker = $4;
986 $$->unique = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000987 }
988 ;
989
990optWithSyntax:
991 { $$ = 0; }
992 | WithSyntax {
993 $$ = $1;
994 }
995 ;
996
997WithSyntax:
998 TOK_WITH TOK_SYNTAX '{'
999 { asn1p_lexer_hack_enable_with_syntax(); }
1000 WithSyntaxFormat
1001 '}' {
1002 $$ = $5;
1003 }
1004 ;
1005
1006WithSyntaxFormat:
1007 WithSyntaxFormatToken {
1008 $$ = asn1p_wsyntx_new();
1009 TQ_ADD(&($$->chunks), $1, next);
1010 }
1011 | WithSyntaxFormat WithSyntaxFormatToken {
1012 $$ = $1;
1013 TQ_ADD(&($$->chunks), $2, next);
1014 }
1015 ;
1016
1017WithSyntaxFormatToken:
1018 TOK_opaque {
1019 $$ = asn1p_wsyntx_chunk_frombuf($1.buf, $1.len, 0);
1020 }
1021 | ClassFieldIdentifier {
1022 asn1p_ref_t *ref;
1023 int ret;
1024 ref = asn1p_ref_new(yylineno);
1025 checkmem(ref);
1026 ret = asn1p_ref_add_component(ref, $1.name, $1.lex_type);
1027 checkmem(ret == 0);
1028 $$ = asn1p_wsyntx_chunk_fromref(ref, 0);
1029 }
1030 ;
1031
Lev Walkinf15320b2004-06-03 03:38:44 +00001032ExtensionAndException:
1033 TOK_ThreeDots {
Lev Walkinceb20e72004-09-05 10:40:41 +00001034 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001035 checkmem($$);
1036 $$->Identifier = strdup("...");
1037 checkmem($$->Identifier);
1038 $$->expr_type = A1TC_EXTENSIBLE;
1039 $$->meta_type = AMT_TYPE;
1040 }
1041 | TOK_ThreeDots '!' DefinedValue {
Lev Walkinceb20e72004-09-05 10:40:41 +00001042 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001043 checkmem($$);
1044 $$->Identifier = strdup("...");
1045 checkmem($$->Identifier);
1046 $$->value = $3;
1047 $$->expr_type = A1TC_EXTENSIBLE;
1048 $$->meta_type = AMT_TYPE;
1049 }
1050 | TOK_ThreeDots '!' SignedNumber {
Lev Walkinceb20e72004-09-05 10:40:41 +00001051 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001052 checkmem($$);
1053 $$->Identifier = strdup("...");
1054 $$->value = $3;
1055 checkmem($$->Identifier);
1056 $$->expr_type = A1TC_EXTENSIBLE;
1057 $$->meta_type = AMT_TYPE;
1058 }
1059 ;
1060
Lev Walkin070a52d2004-08-22 03:19:54 +00001061Type:
Lev Walkinaf120f72004-09-14 02:36:39 +00001062 optTag TypeDeclaration optConstraints {
1063 $$ = $2;
1064 $$->tag = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001065 /*
1066 * Outer constraint for SEQUENCE OF and SET OF applies
1067 * to the inner type.
1068 */
1069 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1070 || $$->expr_type == ASN_CONSTR_SET_OF) {
1071 assert(!TQ_FIRST(&($$->members))->constraints);
Lev Walkinaf120f72004-09-14 02:36:39 +00001072 TQ_FIRST(&($$->members))->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001073 } else {
1074 if($$->constraints) {
1075 assert(!$2);
1076 } else {
Lev Walkinaf120f72004-09-14 02:36:39 +00001077 $$->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001078 }
1079 }
1080 }
1081 ;
1082
1083TypeDeclaration:
Lev Walkinf15320b2004-06-03 03:38:44 +00001084 BasicType {
1085 $$ = $1;
1086 }
Lev Walkin070a52d2004-08-22 03:19:54 +00001087 | TOK_CHOICE '{' AlternativeTypeLists '}' {
1088 $$ = $3;
1089 assert($$->expr_type == A1TC_INVALID);
1090 $$->expr_type = ASN_CONSTR_CHOICE;
1091 $$->meta_type = AMT_TYPE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001092 }
Lev Walkin144db9b2004-10-12 23:26:53 +00001093 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001094 $$ = $3;
1095 assert($$->expr_type == A1TC_INVALID);
1096 $$->expr_type = ASN_CONSTR_SEQUENCE;
1097 $$->meta_type = AMT_TYPE;
1098 }
Lev Walkin144db9b2004-10-12 23:26:53 +00001099 | TOK_SET '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001100 $$ = $3;
1101 assert($$->expr_type == A1TC_INVALID);
1102 $$->expr_type = ASN_CONSTR_SET;
1103 $$->meta_type = AMT_TYPE;
1104 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001105 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkinceb20e72004-09-05 10:40:41 +00001106 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001107 checkmem($$);
1108 $$->constraints = $2;
1109 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1110 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001111 $6->Identifier = $4;
1112 $6->tag = $5;
1113 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001114 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001115 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkinceb20e72004-09-05 10:40:41 +00001116 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001117 checkmem($$);
1118 $$->constraints = $2;
1119 $$->expr_type = ASN_CONSTR_SET_OF;
1120 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001121 $6->Identifier = $4;
1122 $6->tag = $5;
1123 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001124 }
1125 | TOK_ANY {
Lev Walkinceb20e72004-09-05 10:40:41 +00001126 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001127 checkmem($$);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001128 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001129 $$->meta_type = AMT_TYPE;
1130 }
1131 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1132 int ret;
Lev Walkinceb20e72004-09-05 10:40:41 +00001133 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001134 checkmem($$);
1135 $$->reference = asn1p_ref_new(yylineno);
1136 ret = asn1p_ref_add_component($$->reference,
1137 $4, RLT_lowercase);
1138 checkmem(ret == 0);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001139 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001140 $$->meta_type = AMT_TYPE;
1141 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001142 /*
1143 * A parametrized assignment.
1144 */
1145 | TypeRefName '{' ActualParameterList '}' {
1146 int ret;
1147 $$ = $3;
1148 assert($$->expr_type == 0);
1149 assert($$->meta_type == 0);
1150 assert($$->reference == 0);
1151 $$->reference = asn1p_ref_new(yylineno);
1152 checkmem($$->reference);
1153 ret = asn1p_ref_add_component($$->reference, $1, RLT_UNKNOWN);
1154 checkmem(ret == 0);
1155 free($1);
1156 $$->expr_type = A1TC_PARAMETRIZED;
1157 $$->meta_type = AMT_TYPE;
1158 }
1159 /*
1160 * A DefinedType reference.
1161 * "CLASS1.&id.&id2"
1162 * or
1163 * "Module.Type"
1164 * or
1165 * "Module.identifier"
1166 * or
1167 * "Type"
1168 */
1169 | ComplexTypeReference {
1170 $$ = asn1p_expr_new(yylineno);
1171 checkmem($$);
1172 $$->reference = $1;
1173 $$->expr_type = A1TC_REFERENCE;
1174 $$->meta_type = AMT_TYPEREF;
1175 }
1176 | TOK_INSTANCE TOK_OF ComplexTypeReference {
1177 $$ = asn1p_expr_new(yylineno);
1178 checkmem($$);
1179 $$->reference = $3;
1180 $$->expr_type = A1TC_INSTANCE;
1181 $$->meta_type = AMT_TYPE;
1182 }
1183 ;
1184
1185/*
1186 * A type name consisting of several components.
1187 * === EXAMPLE ===
1188 * === EOF ===
1189 */
1190ComplexTypeReference:
1191 TOK_typereference {
1192 int ret;
1193 $$ = asn1p_ref_new(yylineno);
1194 checkmem($$);
1195 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1196 checkmem(ret == 0);
1197 free($1);
1198 }
1199 | TOK_typereference '.' TypeRefName {
1200 int ret;
1201 $$ = asn1p_ref_new(yylineno);
1202 checkmem($$);
1203 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1204 checkmem(ret == 0);
1205 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1206 checkmem(ret == 0);
1207 free($1);
1208 }
Lev Walkin9c974182004-09-15 11:59:51 +00001209 | ObjectClassReference '.' TypeRefName {
1210 int ret;
1211 $$ = asn1p_ref_new(yylineno);
1212 checkmem($$);
1213 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1214 checkmem(ret == 0);
1215 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1216 checkmem(ret == 0);
1217 free($1);
1218 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001219 | TOK_typereference '.' Identifier {
1220 int ret;
1221 $$ = asn1p_ref_new(yylineno);
1222 checkmem($$);
1223 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1224 checkmem(ret == 0);
1225 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1226 checkmem(ret == 0);
1227 free($1);
1228 }
1229 | ObjectClassReference {
1230 int ret;
1231 $$ = asn1p_ref_new(yylineno);
1232 checkmem($$);
1233 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1234 free($1);
1235 checkmem(ret == 0);
1236 }
1237 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1238 int ret;
1239 $$ = $3;
1240 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1241 free($1);
1242 checkmem(ret == 0);
1243 /*
1244 * Move the last element infront.
1245 */
1246 {
1247 struct asn1p_ref_component_s tmp_comp;
1248 tmp_comp = $$->components[$$->comp_count-1];
1249 memmove(&$$->components[1],
1250 &$$->components[0],
1251 sizeof($$->components[0])
1252 * ($$->comp_count - 1));
1253 $$->components[0] = tmp_comp;
1254 }
1255 }
1256 ;
1257
1258ComplexTypeReferenceAmpList:
1259 ComplexTypeReferenceElement {
1260 int ret;
1261 $$ = asn1p_ref_new(yylineno);
1262 checkmem($$);
1263 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1264 free($1.name);
1265 checkmem(ret == 0);
1266 }
1267 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1268 int ret;
1269 $$ = $1;
1270 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1271 free($3.name);
1272 checkmem(ret == 0);
1273 }
1274 ;
1275
1276ComplexTypeReferenceElement: ClassFieldName;
1277ClassFieldIdentifier: ClassFieldName;
1278
1279ClassFieldName:
1280 /* "&Type1" */
1281 TOK_typefieldreference {
1282 $$.lex_type = RLT_AmpUppercase;
1283 $$.name = $1;
1284 }
1285 /* "&id" */
1286 | TOK_valuefieldreference {
1287 $$.lex_type = RLT_Amplowercase;
1288 $$.name = $1;
1289 }
1290 ;
1291
1292
1293/*
1294 * === EXAMPLE ===
1295 * value INTEGER ::= 1
1296 * === EOF ===
1297 */
1298ValueDefinition:
Lev Walkin9c974182004-09-15 11:59:51 +00001299 Identifier DefinedTypeRef TOK_PPEQ Value {
Lev Walkinf15320b2004-06-03 03:38:44 +00001300 $$ = $2;
1301 assert($$->Identifier == NULL);
1302 $$->Identifier = $1;
1303 $$->meta_type = AMT_VALUE;
1304 $$->value = $4;
1305 }
1306 ;
1307
Lev Walkin9c974182004-09-15 11:59:51 +00001308Value:
1309 Identifier ':' Value {
1310 $$ = asn1p_value_fromint(0);
1311 checkmem($$);
1312 $$->type = ATV_CHOICE_IDENTIFIER;
1313 $$->value.choice_identifier.identifier = $1;
1314 $$->value.choice_identifier.value = $3;
1315 }
Lev Walkincbad2512005-03-24 16:27:02 +00001316 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Lev Walkinf15320b2004-06-03 03:38:44 +00001317 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1318 checkmem($$);
1319 $$->type = ATV_UNPARSED;
1320 }
Lev Walkin9c974182004-09-15 11:59:51 +00001321 | TOK_NULL {
1322 $$ = asn1p_value_fromint(0);
1323 checkmem($$);
1324 $$->type = ATV_NULL;
1325 }
1326 | TOK_FALSE {
1327 $$ = asn1p_value_fromint(0);
1328 checkmem($$);
1329 $$->type = ATV_FALSE;
1330 }
1331 | TOK_TRUE {
1332 $$ = asn1p_value_fromint(0);
1333 checkmem($$);
1334 $$->type = ATV_TRUE;
1335 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001336 | TOK_bstring {
1337 $$ = _convert_bitstring2binary($1, 'B');
1338 checkmem($$);
1339 }
1340 | TOK_hstring {
1341 $$ = _convert_bitstring2binary($1, 'H');
1342 checkmem($$);
1343 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001344 | RestrictedCharacterStringValue {
1345 $$ = $$;
Lev Walkinf15320b2004-06-03 03:38:44 +00001346 }
1347 | SignedNumber {
1348 $$ = $1;
1349 }
1350 | DefinedValue {
1351 $$ = $1;
1352 }
1353 ;
1354
1355DefinedValue:
1356 Identifier {
1357 asn1p_ref_t *ref;
1358 int ret;
1359 ref = asn1p_ref_new(yylineno);
1360 checkmem(ref);
1361 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1362 checkmem(ret == 0);
1363 $$ = asn1p_value_fromref(ref, 0);
1364 checkmem($$);
1365 free($1);
1366 }
1367 | TypeRefName '.' Identifier {
1368 asn1p_ref_t *ref;
1369 int ret;
1370 ref = asn1p_ref_new(yylineno);
1371 checkmem(ref);
1372 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1373 checkmem(ret == 0);
1374 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1375 checkmem(ret == 0);
1376 $$ = asn1p_value_fromref(ref, 0);
1377 checkmem($$);
1378 free($1);
1379 free($3);
1380 }
1381 ;
1382
Lev Walkin1e448d32005-03-24 14:26:38 +00001383
1384RestrictedCharacterStringValue:
1385 TOK_cstring {
1386 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1387 checkmem($$);
1388 }
Lev Walkind9574ae2005-03-24 16:22:35 +00001389 | TOK_tuple {
1390 $$ = asn1p_value_fromint($1);
1391 checkmem($$);
1392 $$->type = ATV_TUPLE;
1393 }
1394 | TOK_quadruple {
1395 $$ = asn1p_value_fromint($1);
1396 checkmem($$);
1397 $$->type = ATV_QUADRUPLE;
1398 }
1399 /*
Lev Walkin1e448d32005-03-24 14:26:38 +00001400 | '{' TOK_number ',' TOK_number '}' {
1401 asn1c_integer_t v = ($2 << 4) + $4;
1402 if($2 > 7) return yyerror("X.680:2003, #37.14 "
1403 "mandates 0..7 range for Tuple's TableColumn");
1404 if($4 > 15) return yyerror("X.680:2003, #37.14 "
1405 "mandates 0..15 range for Tuple's TableRow");
1406 $$ = asn1p_value_fromint(v);
1407 checkmem($$);
1408 $$->type = ATV_TUPLE;
1409 }
1410 | '{' TOK_number ',' TOK_number ',' TOK_number ',' TOK_number '}' {
1411 asn1c_integer_t v = ($2 << 24) | ($4 << 16) | ($6 << 8) | $8;
1412 if($2 > 127) return yyerror("X.680:2003, #37.12 "
1413 "mandates 0..127 range for Quadruple's Group");
1414 if($4 > 255) return yyerror("X.680:2003, #37.12 "
1415 "mandates 0..255 range for Quadruple's Plane");
1416 if($6 > 255) return yyerror("X.680:2003, #37.12 "
1417 "mandates 0..255 range for Quadruple's Row");
1418 if($8 > 255) return yyerror("X.680:2003, #37.12 "
1419 "mandates 0..255 range for Quadruple's Cell");
1420 $$ = asn1p_value_fromint(v);
1421 checkmem($$);
1422 $$->type = ATV_QUADRUPLE;
1423 }
Lev Walkind9574ae2005-03-24 16:22:35 +00001424 */
Lev Walkin1e448d32005-03-24 14:26:38 +00001425 ;
1426
Lev Walkinf15320b2004-06-03 03:38:44 +00001427Opaque:
1428 TOK_opaque {
Lev Walkin1893ddf2005-03-20 14:28:32 +00001429 $$.len = $1.len + 1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001430 $$.buf = malloc($$.len + 1);
1431 checkmem($$.buf);
1432 $$.buf[0] = '{';
Lev Walkin1893ddf2005-03-20 14:28:32 +00001433 memcpy($$.buf + 1, $1.buf, $1.len);
Lev Walkinf15320b2004-06-03 03:38:44 +00001434 $$.buf[$$.len] = '\0';
1435 free($1.buf);
1436 }
1437 | Opaque TOK_opaque {
1438 int newsize = $1.len + $2.len;
1439 char *p = malloc(newsize + 1);
1440 checkmem(p);
1441 memcpy(p , $1.buf, $1.len);
1442 memcpy(p + $1.len, $2.buf, $2.len);
1443 p[newsize] = '\0';
1444 free($1.buf);
1445 free($2.buf);
1446 $$.buf = p;
1447 $$.len = newsize;
1448 }
1449 ;
1450
1451BasicTypeId:
1452 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1453 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1454 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1455 | BasicTypeId_UniverationCompatible { $$ = $1; }
1456 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1457 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1458 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1459 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1460 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1461 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1462 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1463 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
Lev Walkinc7d939d2005-03-20 11:12:40 +00001464 | BasicString { $$ = $1; }
Lev Walkinf15320b2004-06-03 03:38:44 +00001465 ;
1466
1467/*
1468 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1469 */
1470BasicTypeId_UniverationCompatible:
1471 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1472 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1473 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1474 ;
1475
1476BasicType:
1477 BasicTypeId {
Lev Walkinceb20e72004-09-05 10:40:41 +00001478 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001479 checkmem($$);
1480 $$->expr_type = $1;
1481 $$->meta_type = AMT_TYPE;
1482 }
1483 | BasicTypeId_UniverationCompatible UniverationDefinition {
1484 if($2) {
1485 $$ = $2;
1486 } else {
Lev Walkinceb20e72004-09-05 10:40:41 +00001487 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001488 checkmem($$);
1489 }
1490 $$->expr_type = $1;
1491 $$->meta_type = AMT_TYPE;
1492 }
1493 ;
1494
1495BasicString:
1496 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1497 | TOK_GeneralString {
1498 $$ = ASN_STRING_GeneralString;
Lev Walkin9c974182004-09-15 11:59:51 +00001499 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001500 }
1501 | TOK_GraphicString {
1502 $$ = ASN_STRING_GraphicString;
Lev Walkin9c974182004-09-15 11:59:51 +00001503 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001504 }
1505 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1506 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1507 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1508 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1509 | TOK_T61String {
1510 $$ = ASN_STRING_T61String;
Lev Walkin9c974182004-09-15 11:59:51 +00001511 fprintf(stderr, "WARNING: T61String is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001512 }
1513 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1514 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1515 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1516 | TOK_VideotexString {
1517 $$ = ASN_STRING_VideotexString;
Lev Walkin9c974182004-09-15 11:59:51 +00001518 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001519 }
1520 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1521 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1522 ;
1523
Lev Walkind2ea1de2004-08-20 13:25:29 +00001524
Lev Walkinf15320b2004-06-03 03:38:44 +00001525/*
1526 * Data type constraints.
1527 */
Lev Walkinf15320b2004-06-03 03:38:44 +00001528Union: '|' | TOK_UNION;
1529Intersection: '^' | TOK_INTERSECTION;
1530Except: TOK_EXCEPT;
1531
Lev Walkinf59d0752004-08-18 04:59:12 +00001532optConstraints:
1533 { $$ = 0; }
Lev Walkind2ea1de2004-08-20 13:25:29 +00001534 | Constraints {
1535 $$ = $1;
1536 }
1537 ;
1538
1539Constraints:
1540 SetOfConstraints {
Lev Walkin2c14a692005-08-12 10:08:45 +00001541 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
Lev Walkinf59d0752004-08-18 04:59:12 +00001542 }
1543 | TOK_SIZE '(' ElementSetSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001544 /*
1545 * This is a special case, for compatibility purposes.
Lev Walkinf59d0752004-08-18 04:59:12 +00001546 * It goes without parentheses.
Lev Walkinf15320b2004-06-03 03:38:44 +00001547 */
Lev Walkin2c14a692005-08-12 10:08:45 +00001548 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001549 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001550 ;
1551
Lev Walkinf59d0752004-08-18 04:59:12 +00001552SetOfConstraints:
1553 '(' ElementSetSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001554 $$ = $2;
1555 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001556 | SetOfConstraints '(' ElementSetSpecs ')' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001557 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
Lev Walkinf59d0752004-08-18 04:59:12 +00001558 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001559 ;
1560
Lev Walkinf59d0752004-08-18 04:59:12 +00001561ElementSetSpecs:
1562 ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001563 $$ = $1;
1564 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001565 | ElementSetSpec ',' TOK_ThreeDots {
Lev Walkinf15320b2004-06-03 03:38:44 +00001566 asn1p_constraint_t *ct;
1567 ct = asn1p_constraint_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001568 ct->type = ACT_EL_EXT;
Lev Walkin2c14a692005-08-12 10:08:45 +00001569 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00001570 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001571 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001572 asn1p_constraint_t *ct;
1573 ct = asn1p_constraint_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001574 ct->type = ACT_EL_EXT;
Lev Walkin2c14a692005-08-12 10:08:45 +00001575 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinb4fcdd22004-08-13 12:35:09 +00001576 ct = $$;
Lev Walkin2c14a692005-08-12 10:08:45 +00001577 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
Lev Walkinf15320b2004-06-03 03:38:44 +00001578 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001579 ;
1580
Lev Walkinf59d0752004-08-18 04:59:12 +00001581ElementSetSpec:
1582 ConstraintSubtypeElement {
1583 $$ = $1;
1584 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001585 | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001586 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
Lev Walkin1e448d32005-03-24 14:26:38 +00001587 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001588 | ElementSetSpec Union ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001589 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001590 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001591 | ElementSetSpec Intersection ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001592 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001593 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001594 | ConstraintSubtypeElement Except ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001595 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001596 }
1597 ;
1598
1599ConstraintSubtypeElement:
Lev Walkinf59d0752004-08-18 04:59:12 +00001600 ConstraintSpec '(' ElementSetSpecs ')' {
1601 int ret;
1602 $$ = asn1p_constraint_new(yylineno);
1603 checkmem($$);
1604 $$->type = $1;
1605 ret = asn1p_constraint_insert($$, $3);
1606 checkmem(ret == 0);
1607 }
1608 | '(' ElementSetSpecs ')' {
1609 int ret;
1610 $$ = asn1p_constraint_new(yylineno);
1611 checkmem($$);
1612 $$->type = ACT_CA_SET;
1613 ret = asn1p_constraint_insert($$, $2);
1614 checkmem(ret == 0);
1615 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001616 | SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001617 $$ = asn1p_constraint_new(yylineno);
1618 checkmem($$);
1619 $$->type = ACT_EL_VALUE;
1620 $$->value = $1;
1621 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001622 | ContainedSubtype {
1623 $$ = asn1p_constraint_new(yylineno);
1624 checkmem($$);
1625 $$->type = ACT_EL_TYPE;
1626 $$->containedSubtype = $1;
1627 }
1628 | SingleValue ConstraintRangeSpec SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001629 $$ = asn1p_constraint_new(yylineno);
1630 checkmem($$);
1631 $$->type = $2;
1632 $$->range_start = $1;
1633 $$->range_stop = $3;
1634 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001635 | TOK_MIN ConstraintRangeSpec SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001636 $$ = asn1p_constraint_new(yylineno);
1637 checkmem($$);
Lev Walkinf59d0752004-08-18 04:59:12 +00001638 $$->type = $2;
1639 $$->range_start = asn1p_value_fromint(-123);
1640 $$->range_stop = $3;
1641 $$->range_start->type = ATV_MIN;
1642 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001643 | SingleValue ConstraintRangeSpec TOK_MAX {
Lev Walkinf59d0752004-08-18 04:59:12 +00001644 $$ = asn1p_constraint_new(yylineno);
1645 checkmem($$);
1646 $$->type = $2;
1647 $$->range_start = $1;
1648 $$->range_stop = asn1p_value_fromint(321);
1649 $$->range_stop->type = ATV_MAX;
1650 }
1651 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1652 $$ = asn1p_constraint_new(yylineno);
1653 checkmem($$);
1654 $$->type = $2;
1655 $$->range_start = asn1p_value_fromint(-123);
1656 $$->range_stop = asn1p_value_fromint(321);
1657 $$->range_start->type = ATV_MIN;
1658 $$->range_stop->type = ATV_MAX;
Lev Walkinf15320b2004-06-03 03:38:44 +00001659 }
1660 | TableConstraint {
1661 $$ = $1;
1662 }
Lev Walkine596bf02005-03-28 15:01:27 +00001663 | InnerTypeConstraint {
Lev Walkinf15320b2004-06-03 03:38:44 +00001664 $$ = $1;
1665 }
Lev Walkin1893ddf2005-03-20 14:28:32 +00001666 | TOK_CONSTRAINED TOK_BY '{'
1667 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1668 $$ = asn1p_constraint_new(yylineno);
1669 checkmem($$);
1670 $$->type = ACT_CT_CTDBY;
1671 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
1672 checkmem($$->value);
1673 $$->value->type = ATV_UNPARSED;
1674 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001675 ;
1676
1677ConstraintRangeSpec:
1678 TOK_TwoDots { $$ = ACT_EL_RANGE; }
1679 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
1680 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
1681 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
1682 ;
1683
1684ConstraintSpec:
1685 TOK_SIZE {
1686 $$ = ACT_CT_SIZE;
1687 }
1688 | TOK_FROM {
1689 $$ = ACT_CT_FROM;
1690 }
1691 ;
1692
Lev Walkinff7dd142005-03-20 12:58:00 +00001693SingleValue:
Lev Walkinc8092cb2005-02-18 16:34:21 +00001694 TOK_FALSE {
1695 $$ = asn1p_value_fromint(0);
1696 checkmem($$);
1697 $$->type = ATV_FALSE;
1698 }
1699 | TOK_TRUE {
1700 $$ = asn1p_value_fromint(1);
1701 checkmem($$);
1702 $$->type = ATV_TRUE;
1703 }
1704 | SignedNumber {
Lev Walkinf15320b2004-06-03 03:38:44 +00001705 $$ = $1;
1706 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001707 | RestrictedCharacterStringValue {
1708 $$ = $1;
Lev Walkinc8092cb2005-02-18 16:34:21 +00001709 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001710 | Identifier {
1711 asn1p_ref_t *ref;
1712 int ret;
1713 ref = asn1p_ref_new(yylineno);
1714 checkmem(ref);
1715 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1716 checkmem(ret == 0);
1717 $$ = asn1p_value_fromref(ref, 0);
1718 checkmem($$);
1719 free($1);
1720 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001721 ;
1722
1723ContainedSubtype:
1724 TypeRefName {
Lev Walkinc8092cb2005-02-18 16:34:21 +00001725 asn1p_ref_t *ref;
1726 int ret;
1727 ref = asn1p_ref_new(yylineno);
1728 checkmem(ref);
1729 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1730 checkmem(ret == 0);
1731 $$ = asn1p_value_fromref(ref, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001732 checkmem($$);
Lev Walkinc8092cb2005-02-18 16:34:21 +00001733 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001734 }
1735 ;
1736
Lev Walkine596bf02005-03-28 15:01:27 +00001737InnerTypeConstraint:
1738 TOK_WITH TOK_COMPONENT SetOfConstraints {
Lev Walkin2c14a692005-08-12 10:08:45 +00001739 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
Lev Walkine596bf02005-03-28 15:01:27 +00001740 }
1741 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001742 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001743 }
1744 ;
1745
1746WithComponentsList:
1747 WithComponentsElement {
1748 $$ = $1;
1749 }
1750 | WithComponentsList ',' WithComponentsElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001751 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001752 }
1753 ;
1754
1755WithComponentsElement:
1756 TOK_ThreeDots {
1757 $$ = asn1p_constraint_new(yylineno);
1758 checkmem($$);
1759 $$->type = ACT_EL_EXT;
Lev Walkine596bf02005-03-28 15:01:27 +00001760 $$->value = asn1p_value_frombuf("...", 3, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001761 }
1762 | Identifier optConstraints optPresenceConstraint {
1763 $$ = asn1p_constraint_new(yylineno);
1764 checkmem($$);
1765 $$->type = ACT_EL_VALUE;
1766 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1767 $$->presence = $3;
Lev Walkine596bf02005-03-28 15:01:27 +00001768 if($2) asn1p_constraint_insert($$, $2);
Lev Walkinf15320b2004-06-03 03:38:44 +00001769 }
1770 ;
1771
1772/*
1773 * presence constraint for WithComponents
1774 */
1775optPresenceConstraint:
1776 { $$ = ACPRES_DEFAULT; }
1777 | PresenceConstraint { $$ = $1; }
1778 ;
1779
1780PresenceConstraint:
1781 TOK_PRESENT {
1782 $$ = ACPRES_PRESENT;
1783 }
1784 | TOK_ABSENT {
1785 $$ = ACPRES_ABSENT;
1786 }
1787 | TOK_OPTIONAL {
1788 $$ = ACPRES_OPTIONAL;
1789 }
1790 ;
1791
1792TableConstraint:
1793 SimpleTableConstraint {
1794 $$ = $1;
1795 }
1796 | ComponentRelationConstraint {
1797 $$ = $1;
1798 }
1799 ;
1800
1801/*
1802 * "{ExtensionSet}"
1803 */
1804SimpleTableConstraint:
1805 '{' TypeRefName '}' {
1806 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
1807 asn1p_constraint_t *ct;
1808 int ret;
1809 ret = asn1p_ref_add_component(ref, $2, 0);
1810 checkmem(ret == 0);
1811 ct = asn1p_constraint_new(yylineno);
1812 checkmem($$);
1813 ct->type = ACT_EL_VALUE;
1814 ct->value = asn1p_value_fromref(ref, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00001815 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001816 }
1817 ;
1818
1819ComponentRelationConstraint:
1820 SimpleTableConstraint '{' AtNotationList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001821 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001822 }
1823 ;
1824
1825AtNotationList:
1826 AtNotationElement {
1827 $$ = asn1p_constraint_new(yylineno);
1828 checkmem($$);
1829 $$->type = ACT_EL_VALUE;
1830 $$->value = asn1p_value_fromref($1, 0);
1831 }
1832 | AtNotationList ',' AtNotationElement {
1833 asn1p_constraint_t *ct;
1834 ct = asn1p_constraint_new(yylineno);
1835 checkmem(ct);
1836 ct->type = ACT_EL_VALUE;
1837 ct->value = asn1p_value_fromref($3, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00001838 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00001839 }
1840 ;
1841
1842/*
1843 * @blah
1844 */
1845AtNotationElement:
1846 '@' ComponentIdList {
1847 char *p = malloc(strlen($2) + 2);
1848 int ret;
1849 *p = '@';
1850 strcpy(p + 1, $2);
1851 $$ = asn1p_ref_new(yylineno);
1852 ret = asn1p_ref_add_component($$, p, 0);
1853 checkmem(ret == 0);
1854 free(p);
1855 free($2);
1856 }
1857 | '@' '.' ComponentIdList {
1858 char *p = malloc(strlen($3) + 3);
1859 int ret;
1860 p[0] = '@';
1861 p[1] = '.';
1862 strcpy(p + 2, $3);
1863 $$ = asn1p_ref_new(yylineno);
1864 ret = asn1p_ref_add_component($$, p, 0);
1865 checkmem(ret == 0);
1866 free(p);
1867 free($3);
1868 }
1869 ;
1870
1871/* identifier "." ... */
1872ComponentIdList:
1873 Identifier {
1874 $$ = $1;
1875 }
1876 | ComponentIdList '.' Identifier {
1877 int l1 = strlen($1);
1878 int l3 = strlen($3);
1879 $$ = malloc(l1 + 1 + l3 + 1);
1880 memcpy($$, $1, l1);
1881 $$[l1] = '.';
1882 memcpy($$ + l1 + 1, $3, l3);
1883 $$[l1 + 1 + l3] = '\0';
1884 }
1885 ;
1886
1887
1888
1889/*
1890 * MARKERS
1891 */
1892
1893optMarker:
Lev Walkin9c974182004-09-15 11:59:51 +00001894 {
1895 $$.flags = EM_NOMARK;
1896 $$.default_value = 0;
1897 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001898 | Marker { $$ = $1; }
1899 ;
1900
1901Marker:
1902 TOK_OPTIONAL {
Lev Walkin9c974182004-09-15 11:59:51 +00001903 $$.flags = EM_OPTIONAL;
1904 $$.default_value = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +00001905 }
Lev Walkin9c974182004-09-15 11:59:51 +00001906 | TOK_DEFAULT Value {
1907 $$.flags = EM_DEFAULT;
1908 $$.default_value = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00001909 }
1910 ;
1911
1912/*
1913 * Universal enumeration definition to use in INTEGER and ENUMERATED.
1914 * === EXAMPLE ===
1915 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
1916 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
1917 * === EOF ===
1918 */
1919/*
1920optUniverationDefinition:
1921 { $$ = 0; }
1922 | UniverationDefinition {
1923 $$ = $1;
1924 }
1925 ;
1926*/
1927
1928UniverationDefinition:
1929 '{' '}' {
Lev Walkinceb20e72004-09-05 10:40:41 +00001930 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001931 checkmem($$);
1932 }
1933 | '{' UniverationList '}' {
1934 $$ = $2;
1935 }
1936 ;
1937
1938UniverationList:
1939 UniverationElement {
Lev Walkinceb20e72004-09-05 10:40:41 +00001940 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001941 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00001942 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001943 }
1944 | UniverationList ',' UniverationElement {
1945 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001946 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001947 }
1948 ;
1949
1950UniverationElement:
1951 Identifier {
Lev Walkinceb20e72004-09-05 10:40:41 +00001952 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001953 checkmem($$);
1954 $$->expr_type = A1TC_UNIVERVAL;
1955 $$->meta_type = AMT_VALUE;
1956 $$->Identifier = $1;
1957 }
1958 | Identifier '(' SignedNumber ')' {
Lev Walkinceb20e72004-09-05 10:40:41 +00001959 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001960 checkmem($$);
1961 $$->expr_type = A1TC_UNIVERVAL;
1962 $$->meta_type = AMT_VALUE;
1963 $$->Identifier = $1;
1964 $$->value = $3;
1965 }
1966 | Identifier '(' DefinedValue ')' {
Lev Walkinceb20e72004-09-05 10:40:41 +00001967 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001968 checkmem($$);
1969 $$->expr_type = A1TC_UNIVERVAL;
1970 $$->meta_type = AMT_VALUE;
1971 $$->Identifier = $1;
1972 $$->value = $3;
1973 }
1974 | SignedNumber {
Lev Walkinceb20e72004-09-05 10:40:41 +00001975 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001976 checkmem($$);
1977 $$->expr_type = A1TC_UNIVERVAL;
1978 $$->meta_type = AMT_VALUE;
1979 $$->value = $1;
1980 }
1981 | TOK_ThreeDots {
Lev Walkinceb20e72004-09-05 10:40:41 +00001982 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001983 checkmem($$);
1984 $$->Identifier = strdup("...");
1985 checkmem($$->Identifier);
1986 $$->expr_type = A1TC_EXTENSIBLE;
1987 $$->meta_type = AMT_VALUE;
1988 }
1989 ;
1990
1991SignedNumber:
1992 TOK_number {
1993 $$ = asn1p_value_fromint($1);
1994 checkmem($$);
1995 }
1996 | TOK_number_negative {
1997 $$ = asn1p_value_fromint($1);
1998 checkmem($$);
1999 }
2000 ;
2001
2002/*
2003 * SEQUENCE definition.
2004 * === EXAMPLE ===
2005 * Struct1 ::= SEQUENCE {
2006 * memb1 Struct2,
2007 * memb2 SEQUENCE OF {
2008 * memb2-1 Struct 3
2009 * }
2010 * }
2011 * === EOF ===
2012 */
2013
2014
2015
2016/*
2017 * SET definition.
2018 * === EXAMPLE ===
2019 * Person ::= SET {
2020 * name [0] PrintableString (SIZE(1..20)),
2021 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2022 * }
2023 * === EOF ===
2024 */
2025
2026optTag:
2027 { memset(&$$, 0, sizeof($$)); }
2028 | Tag { $$ = $1; }
2029 ;
2030
2031Tag:
Lev Walkinc603f102005-01-23 09:51:44 +00002032 TagTypeValue TagPlicit {
Lev Walkinf15320b2004-06-03 03:38:44 +00002033 $$ = $1;
Lev Walkinc603f102005-01-23 09:51:44 +00002034 $$.tag_mode = $2.tag_mode;
Lev Walkinf15320b2004-06-03 03:38:44 +00002035 }
Lev Walkinc603f102005-01-23 09:51:44 +00002036 ;
2037
2038TagTypeValue:
2039 '[' TagClass TOK_number ']' {
2040 $$ = $2;
2041 $$.tag_value = $3;
2042 };
2043
2044TagClass:
2045 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2046 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2047 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2048 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2049 ;
2050
2051TagPlicit:
2052 { $$.tag_mode = TM_DEFAULT; }
2053 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2054 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
Lev Walkinf15320b2004-06-03 03:38:44 +00002055 ;
2056
2057TypeRefName:
2058 TOK_typereference {
2059 checkmem($1);
2060 $$ = $1;
2061 }
Lev Walkinf59d0752004-08-18 04:59:12 +00002062 | TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002063 checkmem($1);
2064 $$ = $1;
2065 }
2066 ;
2067
Lev Walkinf59d0752004-08-18 04:59:12 +00002068
Lev Walkinf15320b2004-06-03 03:38:44 +00002069ObjectClassReference:
Lev Walkinf59d0752004-08-18 04:59:12 +00002070 TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002071 checkmem($1);
2072 $$ = $1;
2073 }
2074 ;
2075
Lev Walkin83cac2f2004-09-22 16:03:36 +00002076optIdentifier:
2077 { $$ = 0; }
2078 | Identifier {
2079 $$ = $1;
2080 }
Lev Walkin8f294e02005-06-06 08:28:58 +00002081 ;
Lev Walkin83cac2f2004-09-22 16:03:36 +00002082
Lev Walkinf15320b2004-06-03 03:38:44 +00002083Identifier:
2084 TOK_identifier {
2085 checkmem($1);
2086 $$ = $1;
2087 }
2088 ;
2089
Lev Walkinf15320b2004-06-03 03:38:44 +00002090%%
2091
2092
2093/*
2094 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2095 */
2096static asn1p_value_t *
2097_convert_bitstring2binary(char *str, int base) {
2098 asn1p_value_t *val;
2099 int slen;
2100 int memlen;
2101 int baselen;
2102 int bits;
2103 uint8_t *binary_vector;
2104 uint8_t *bv_ptr;
2105 uint8_t cur_val;
2106
2107 assert(str);
2108 assert(str[0] == '\'');
2109
2110 switch(base) {
2111 case 'B':
2112 baselen = 1;
2113 break;
2114 case 'H':
2115 baselen = 4;
2116 break;
2117 default:
2118 assert(base == 'B' || base == 'H');
2119 errno = EINVAL;
2120 return NULL;
2121 }
2122
2123 slen = strlen(str);
2124 assert(str[slen - 1] == base);
2125 assert(str[slen - 2] == '\'');
2126
2127 memlen = slen / (8 / baselen); /* Conservative estimate */
2128
2129 bv_ptr = binary_vector = malloc(memlen + 1);
2130 if(bv_ptr == NULL)
2131 /* ENOMEM */
2132 return NULL;
2133
2134 cur_val = 0;
2135 bits = 0;
2136 while(*(++str) != '\'') {
2137 switch(baselen) {
2138 case 1:
2139 switch(*str) {
2140 case '1':
2141 cur_val |= 1 << (7 - (bits % 8));
2142 case '0':
2143 break;
2144 default:
2145 assert(!"_y UNREACH1");
2146 case ' ': case '\r': case '\n':
2147 continue;
2148 }
2149 break;
2150 case 4:
2151 switch(*str) {
2152 case '0': case '1': case '2': case '3': case '4':
2153 case '5': case '6': case '7': case '8': case '9':
2154 cur_val |= (*str - '0') << (4 - (bits % 8));
2155 break;
2156 case 'A': case 'B': case 'C':
2157 case 'D': case 'E': case 'F':
2158 cur_val |= ((*str - 'A') + 10)
2159 << (4 - (bits % 8));
2160 break;
2161 default:
2162 assert(!"_y UNREACH2");
2163 case ' ': case '\r': case '\n':
2164 continue;
2165 }
2166 break;
2167 }
2168
2169 bits += baselen;
2170 if((bits % 8) == 0) {
2171 *bv_ptr++ = cur_val;
2172 cur_val = 0;
2173 }
2174 }
2175
2176 *bv_ptr = cur_val;
2177 assert((bv_ptr - binary_vector) <= memlen);
2178
2179 val = asn1p_value_frombits(binary_vector, bits, 0);
2180 if(val == NULL) {
2181 free(binary_vector);
2182 }
2183
2184 return val;
2185}
2186
2187extern char *asn1p_text;
2188
2189int
2190yyerror(const char *msg) {
2191 fprintf(stderr,
2192 "ASN.1 grammar parse error "
2193 "near line %d (token \"%s\"): %s\n",
Lev Walkinceb20e72004-09-05 10:40:41 +00002194 yylineno, asn1p_text, msg);
Lev Walkinf15320b2004-06-03 03:38:44 +00002195 return -1;
2196}
2197
2198