blob: 13af5a283596567d19028db2b3befb3c408792b9 [file] [log] [blame]
vlmfa67ddc2004-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
vlmfbf6bf62005-06-07 21:25:42 +000012#define YYPARSE_PARAM_TYPE void **
vlmfa67ddc2004-06-03 03:38:44 +000013#define YYERROR_VERBOSE
14
15int yylex(void);
16int yyerror(const char *msg);
vlmd2f87602005-06-07 21:32:16 +000017#ifdef YYBYACC
18int yyparse(void **param); /* byacc does not produce a prototype */
19#endif
vlmfa67ddc2004-06-03 03:38:44 +000020void asn1p_lexer_hack_push_opaque_state(void);
21void asn1p_lexer_hack_enable_with_syntax(void);
vlm9283dbe2004-08-18 04:59:12 +000022void asn1p_lexer_hack_push_encoding_control(void);
vlmfa67ddc2004-06-03 03:38:44 +000023#define yylineno asn1p_lineno
24extern int asn1p_lineno;
25
vlm04a08da2005-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;
vlmfa67ddc2004-06-03 03:38:44 +000031
vlm5d89c3d2005-08-13 09:07:11 +000032static asn1p_value_t *_convert_bitstring2binary(char *str, int base);
33static void _fixup_anonymous_identifier(asn1p_expr_t *expr);
vlmfa67ddc2004-06-03 03:38:44 +000034
vlm04a08da2005-08-12 10:06:17 +000035#define checkmem(ptr) do { \
36 if(!(ptr)) \
37 return yyerror("Memory failure"); \
vlmfa67ddc2004-06-03 03:38:44 +000038 } while(0)
39
vlm9fe7c922005-08-12 10:08:45 +000040#define CONSTRAINT_INSERT(root, constr_type, arg1, arg2) do { \
vlm04a08da2005-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 } \
vlmfa67ddc2004-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 */
vlm04a08da2005-08-12 10:06:17 +000076 struct AssignedIdentifier a_aid; /* Assigned Identifier */
vlmfa67ddc2004-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 */
vlmc94e28f2004-09-15 11:59:51 +000087 struct asn1p_expr_marker_s a_marker; /* OPTIONAL/DEFAULT */
vlmfa67ddc2004-06-03 03:38:44 +000088 enum asn1p_constr_pres_e a_pres; /* PRESENT/ABSENT/OPTIONAL */
vlm0aa86902004-10-12 23:26:53 +000089 asn1c_integer_t a_int;
vlmfa67ddc2004-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
vlm2c8c44d2005-03-24 16:22:35 +0000111%token <a_int> TOK_tuple
112%token <a_int> TOK_quadruple
vlmfa67ddc2004-06-03 03:38:44 +0000113%token <a_int> TOK_number_negative
114%token <tv_str> TOK_typereference
vlm9283dbe2004-08-18 04:59:12 +0000115%token <tv_str> TOK_capitalreference /* "CLASS1" */
vlmfa67ddc2004-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
vlm9283dbe2004-08-18 04:59:12 +0000145%token TOK_ENCODING_CONTROL
vlmfa67ddc2004-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
vlm9283dbe2004-08-18 04:59:12 +0000164%token TOK_INSTRUCTIONS
vlmfa67ddc2004-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
vlmfa67ddc2004-06-03 03:38:44 +0000204%left TOK_EXCEPT
vlm9283dbe2004-08-18 04:59:12 +0000205%left '^' TOK_INTERSECTION
206%left '|' TOK_UNION
vlmfa67ddc2004-06-03 03:38:44 +0000207
208/* Misc tags */
209%token TOK_TwoDots /* .. */
210%token TOK_ThreeDots /* ... */
vlmfa67ddc2004-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
vlmfa67ddc2004-06-03 03:38:44 +0000232%type <a_expr> ExtensionAndException
vlmec8f6812004-08-22 03:19:54 +0000233%type <a_expr> TypeDeclaration
vlmfa67ddc2004-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
vlmec8f6812004-08-22 03:19:54 +0000242%type <a_expr> Type
vlmfa67ddc2004-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*/
vlmc94e28f2004-09-15 11:59:51 +0000247%type <a_value> Value
vlmfa67ddc2004-06-03 03:38:44 +0000248%type <a_value> DefinedValue
249%type <a_value> SignedNumber
vlm0aa86902004-10-12 23:26:53 +0000250%type <a_expr> optComponentTypeLists
vlmec8f6812004-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
vlmfa67ddc2004-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
vlmfa67ddc2004-06-03 03:38:44 +0000261%type <tv_str> Identifier
vlm151c0b22004-09-22 16:03:36 +0000262%type <tv_str> optIdentifier
vlmfa67ddc2004-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
vlm04a08da2005-08-12 10:06:17 +0000267%type <a_aid> AssignedIdentifier /* OID/DefinedValue */
vlmfa67ddc2004-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
vlm2728a8d2005-01-23 09:51:44 +0000278%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
279%type <a_tag> TagClass TagTypeValue TagPlicit
vlmfa67ddc2004-06-03 03:38:44 +0000280%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
281%type <a_constr> optConstraints
vlm5f0128b2004-08-20 13:25:29 +0000282%type <a_constr> Constraints
vlm9283dbe2004-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 */
vlmfa67ddc2004-06-03 03:38:44 +0000286%type <a_constr> ConstraintSubtypeElement /* 1..2 */
vlmfa67ddc2004-06-03 03:38:44 +0000287%type <a_constr> SimpleTableConstraint
288%type <a_constr> TableConstraint
vlm7bbdc9f2005-03-28 15:01:27 +0000289%type <a_constr> InnerTypeConstraint
vlmfa67ddc2004-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
vlma6a12e32005-03-20 12:58:00 +0000295%type <a_value> SingleValue
296%type <a_value> ContainedSubtype
vlmfa67ddc2004-06-03 03:38:44 +0000297%type <a_ctype> ConstraintSpec
298%type <a_ctype> ConstraintRangeSpec
vlme1e6ed82005-03-24 14:26:38 +0000299%type <a_value> RestrictedCharacterStringValue
vlmfa67ddc2004-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
vlm04a08da2005-08-12 10:06:17 +0000356 $$->ModuleName = $1;
vlmfa67ddc2004-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 }
vlm9283dbe2004-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 }
vlmfa67ddc2004-06-03 03:38:44 +0000464 ;
465
466/*
467 * Optional module body.
468 */
469optModuleSpecificationBody:
470 { $$ = 0; }
471 | ModuleSpecificationBody {
vlmfa67ddc2004-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
vlm9283dbe2004-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
vlmfa67ddc2004-06-03 03:38:44 +0000492#ifdef MY_IMPORT
493#error MY_IMPORT DEFINED ELSEWHERE!
494#endif
495#define MY_IMPORT(foo,field) do { \
vlm97ed7152004-08-13 12:31:09 +0000496 while(TQ_FIRST(&($2->foo))) { \
vlmfa67ddc2004-06-03 03:38:44 +0000497 TQ_ADD(&($$->foo), \
498 TQ_REMOVE(&($2->foo), field), \
499 field); \
vlm97ed7152004-08-13 12:31:09 +0000500 } \
501 assert(TQ_FIRST(&($2->foo)) == 0); \
502 } while(0)
vlmfa67ddc2004-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 }
vlm9283dbe2004-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 }
vlmfa67ddc2004-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 ';' {
vlm04a08da2005-08-12 10:06:17 +0000584 if(!saved_aid && 0)
585 return yyerror("Unterminated IMPORTS FROM, "
586 "expected semicolon ';'");
587 saved_aid = 0;
vlmfa67ddc2004-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
vlm04a08da2005-08-12 10:06:17 +0000610AssignedIdentifier:
611 { memset(&$$, 0, sizeof($$)); }
612 | ObjectIdentifier { $$.oid = $1; };
613 /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
614
vlmfa67ddc2004-06-03 03:38:44 +0000615ImportsBundle:
vlm04a08da2005-08-12 10:06:17 +0000616 ImportsList TOK_FROM TypeRefName AssignedIdentifier {
vlmfa67ddc2004-06-03 03:38:44 +0000617 $$ = $1;
vlm04a08da2005-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);
vlmfa67ddc2004-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 }
vlm0aa86902004-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 }
vlmfa67ddc2004-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 }
vlm0aa86902004-10-12 23:26:53 +0000692 | TypeRefName '{' '}' {
693 $$ = asn1p_expr_new(yylineno);
694 checkmem($$);
695 $$->Identifier = $1;
696 $$->expr_type = A1TC_EXPORTVAR;
697 }
vlmfa67ddc2004-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:
vlm7388db02005-03-31 21:48:13 +0000708 TypeRefName DefinedTypeRef TOK_PPEQ
709 '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
vlmfa67ddc2004-06-03 03:38:44 +0000710 $$ = $2;
711 assert($$->Identifier == 0);
712 $$->Identifier = $1;
713 $$->meta_type = AMT_VALUESET;
vlm7388db02005-03-31 21:48:13 +0000714 // take care of ValueSet body
vlmfa67ddc2004-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
vlmfa67ddc2004-06-03 03:38:44 +0000734/*
735 * Data Type Reference.
736 * === EXAMPLE ===
737 * Type3 ::= CHOICE { a Type1, b Type 2 }
738 * === EOF ===
739 */
vlmfa67ddc2004-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 }
vlmfce48a42004-09-14 02:36:39 +0000752 | TypeRefName TOK_PPEQ Type {
753 $$ = $3;
vlmfa67ddc2004-06-03 03:38:44 +0000754 $$->Identifier = $1;
vlmfa67ddc2004-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 */
vlmec8f6812004-08-22 03:19:54 +0000774 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
vlmfa67ddc2004-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 }
vlm4053ca52005-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 }
vlmfa67ddc2004-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($$);
vlm6a02a8a2004-09-08 00:28:11 +0000836 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000837 }
838 | ActualParameterList ',' ActualParameter {
839 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000840 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000841 }
842 ;
843
844ActualParameter:
vlmec8f6812004-08-22 03:19:54 +0000845 Type {
vlmfa67ddc2004-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/*
vlm4053ca52005-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/*
vlmfa67ddc2004-06-03 03:38:44 +0000869 * A collection of constructed data type members.
870 */
vlm0aa86902004-10-12 23:26:53 +0000871optComponentTypeLists:
872 { $$ = asn1p_expr_new(yylineno); }
873 | ComponentTypeLists { $$ = $1; };
874
vlmec8f6812004-08-22 03:19:54 +0000875ComponentTypeLists:
876 ComponentType {
vlmfa67ddc2004-06-03 03:38:44 +0000877 $$ = asn1p_expr_new(yylineno);
878 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000879 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000880 }
vlmec8f6812004-08-22 03:19:54 +0000881 | ComponentTypeLists ',' ComponentType {
vlmfa67ddc2004-06-03 03:38:44 +0000882 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000883 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000884 }
885 ;
886
vlmec8f6812004-08-22 03:19:54 +0000887ComponentType:
vlmfce48a42004-09-14 02:36:39 +0000888 Identifier Type optMarker {
vlmec8f6812004-08-22 03:19:54 +0000889 $$ = $2;
890 assert($$->Identifier == 0);
vlmfce48a42004-09-14 02:36:39 +0000891 $$->Identifier = $1;
vlmec8f6812004-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;
vlm6a02a8a2004-09-08 00:28:11 +0000899 asn1p_expr_add($$, $3);
vlmec8f6812004-08-22 03:19:54 +0000900 }
901 | ExtensionAndException {
902 $$ = $1;
903 }
vlm5d89c3d2005-08-13 09:07:11 +0000904 | Type optMarker {
905 $$ = $1;
906 $$->marker = $2;
907 _fixup_anonymous_identifier($$);
908 }
vlmec8f6812004-08-22 03:19:54 +0000909 ;
910
911AlternativeTypeLists:
912 AlternativeType {
913 $$ = asn1p_expr_new(yylineno);
914 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000915 asn1p_expr_add($$, $1);
vlmec8f6812004-08-22 03:19:54 +0000916 }
917 | AlternativeTypeLists ',' AlternativeType {
918 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000919 asn1p_expr_add($$, $3);
vlmec8f6812004-08-22 03:19:54 +0000920 }
921 ;
922
923AlternativeType:
vlmfce48a42004-09-14 02:36:39 +0000924 Identifier Type {
vlmec8f6812004-08-22 03:19:54 +0000925 $$ = $2;
926 assert($$->Identifier == 0);
vlmfce48a42004-09-14 02:36:39 +0000927 $$->Identifier = $1;
vlmec8f6812004-08-22 03:19:54 +0000928 }
929 | ExtensionAndException {
930 $$ = $1;
931 }
vlm5d89c3d2005-08-13 09:07:11 +0000932 | Type {
933 $$ = $1;
934 _fixup_anonymous_identifier($$);
935 }
vlmec8f6812004-08-22 03:19:54 +0000936 ;
937
vlmfa67ddc2004-06-03 03:38:44 +0000938ClassDeclaration:
939 TOK_CLASS '{' ClassFieldList '}' optWithSyntax {
940 $$ = $3;
941 checkmem($$);
942 $$->with_syntax = $5;
943 assert($$->expr_type == A1TC_CLASSDEF);
944 assert($$->meta_type == AMT_OBJECT);
945 }
946 ;
947
948optUnique:
949 { $$ = 0; }
950 | TOK_UNIQUE { $$ = 1; }
951 ;
952
953ClassFieldList:
954 ClassField {
955 $$ = asn1p_expr_new(yylineno);
956 checkmem($$);
957 $$->expr_type = A1TC_CLASSDEF;
958 $$->meta_type = AMT_OBJECT;
vlm6a02a8a2004-09-08 00:28:11 +0000959 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000960 }
961 | ClassFieldList ',' ClassField {
962 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000963 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000964 }
965 ;
966
967ClassField:
968 ClassFieldIdentifier optMarker {
969 $$ = asn1p_expr_new(yylineno);
970 checkmem($$);
971 $$->Identifier = $1.name;
972 $$->expr_type = A1TC_CLASSFIELD;
973 $$->meta_type = AMT_OBJECTFIELD;
974 $$->marker = $2;
975 }
vlmbde35d42004-11-24 17:43:29 +0000976 | ClassFieldIdentifier Type optUnique optMarker {
vlmfa67ddc2004-06-03 03:38:44 +0000977 $$ = $2;
978 $$->Identifier = $1.name;
vlmbde35d42004-11-24 17:43:29 +0000979 $$->marker = $4;
980 $$->unique = $3;
vlmfa67ddc2004-06-03 03:38:44 +0000981 }
vlmbde35d42004-11-24 17:43:29 +0000982 | ClassFieldIdentifier ClassFieldIdentifier optUnique optMarker {
vlmfa67ddc2004-06-03 03:38:44 +0000983 int ret;
984 $$ = asn1p_expr_new(yylineno);
985 checkmem($$);
986 $$->Identifier = $1.name;
987 $$->reference = asn1p_ref_new(yylineno);
988 checkmem($$->reference);
989 ret = asn1p_ref_add_component($$->reference,
990 $2.name, $2.lex_type);
991 checkmem(ret == 0);
992 $$->expr_type = A1TC_CLASSFIELD;
993 $$->meta_type = AMT_OBJECTFIELD;
vlmbde35d42004-11-24 17:43:29 +0000994 $$->marker = $4;
995 $$->unique = $3;
vlmfa67ddc2004-06-03 03:38:44 +0000996 }
997 ;
998
999optWithSyntax:
1000 { $$ = 0; }
1001 | WithSyntax {
1002 $$ = $1;
1003 }
1004 ;
1005
1006WithSyntax:
1007 TOK_WITH TOK_SYNTAX '{'
1008 { asn1p_lexer_hack_enable_with_syntax(); }
1009 WithSyntaxFormat
1010 '}' {
1011 $$ = $5;
1012 }
1013 ;
1014
1015WithSyntaxFormat:
1016 WithSyntaxFormatToken {
1017 $$ = asn1p_wsyntx_new();
1018 TQ_ADD(&($$->chunks), $1, next);
1019 }
1020 | WithSyntaxFormat WithSyntaxFormatToken {
1021 $$ = $1;
1022 TQ_ADD(&($$->chunks), $2, next);
1023 }
1024 ;
1025
1026WithSyntaxFormatToken:
1027 TOK_opaque {
1028 $$ = asn1p_wsyntx_chunk_frombuf($1.buf, $1.len, 0);
1029 }
1030 | ClassFieldIdentifier {
1031 asn1p_ref_t *ref;
1032 int ret;
1033 ref = asn1p_ref_new(yylineno);
1034 checkmem(ref);
1035 ret = asn1p_ref_add_component(ref, $1.name, $1.lex_type);
1036 checkmem(ret == 0);
1037 $$ = asn1p_wsyntx_chunk_fromref(ref, 0);
1038 }
1039 ;
1040
vlmfa67ddc2004-06-03 03:38:44 +00001041ExtensionAndException:
1042 TOK_ThreeDots {
vlm39e5ed72004-09-05 10:40:41 +00001043 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001044 checkmem($$);
1045 $$->Identifier = strdup("...");
1046 checkmem($$->Identifier);
1047 $$->expr_type = A1TC_EXTENSIBLE;
1048 $$->meta_type = AMT_TYPE;
1049 }
1050 | TOK_ThreeDots '!' DefinedValue {
vlm39e5ed72004-09-05 10:40:41 +00001051 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001052 checkmem($$);
1053 $$->Identifier = strdup("...");
1054 checkmem($$->Identifier);
1055 $$->value = $3;
1056 $$->expr_type = A1TC_EXTENSIBLE;
1057 $$->meta_type = AMT_TYPE;
1058 }
1059 | TOK_ThreeDots '!' SignedNumber {
vlm39e5ed72004-09-05 10:40:41 +00001060 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001061 checkmem($$);
1062 $$->Identifier = strdup("...");
1063 $$->value = $3;
1064 checkmem($$->Identifier);
1065 $$->expr_type = A1TC_EXTENSIBLE;
1066 $$->meta_type = AMT_TYPE;
1067 }
1068 ;
1069
vlmec8f6812004-08-22 03:19:54 +00001070Type:
vlmfce48a42004-09-14 02:36:39 +00001071 optTag TypeDeclaration optConstraints {
1072 $$ = $2;
1073 $$->tag = $1;
vlmec8f6812004-08-22 03:19:54 +00001074 /*
1075 * Outer constraint for SEQUENCE OF and SET OF applies
1076 * to the inner type.
1077 */
1078 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1079 || $$->expr_type == ASN_CONSTR_SET_OF) {
1080 assert(!TQ_FIRST(&($$->members))->constraints);
vlmfce48a42004-09-14 02:36:39 +00001081 TQ_FIRST(&($$->members))->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001082 } else {
1083 if($$->constraints) {
1084 assert(!$2);
1085 } else {
vlmfce48a42004-09-14 02:36:39 +00001086 $$->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001087 }
1088 }
1089 }
1090 ;
1091
1092TypeDeclaration:
vlmfa67ddc2004-06-03 03:38:44 +00001093 BasicType {
1094 $$ = $1;
1095 }
vlmec8f6812004-08-22 03:19:54 +00001096 | TOK_CHOICE '{' AlternativeTypeLists '}' {
1097 $$ = $3;
1098 assert($$->expr_type == A1TC_INVALID);
1099 $$->expr_type = ASN_CONSTR_CHOICE;
1100 $$->meta_type = AMT_TYPE;
vlmfa67ddc2004-06-03 03:38:44 +00001101 }
vlm0aa86902004-10-12 23:26:53 +00001102 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001103 $$ = $3;
1104 assert($$->expr_type == A1TC_INVALID);
1105 $$->expr_type = ASN_CONSTR_SEQUENCE;
1106 $$->meta_type = AMT_TYPE;
1107 }
vlm0aa86902004-10-12 23:26:53 +00001108 | TOK_SET '{' optComponentTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001109 $$ = $3;
1110 assert($$->expr_type == A1TC_INVALID);
1111 $$->expr_type = ASN_CONSTR_SET;
1112 $$->meta_type = AMT_TYPE;
1113 }
vlm151c0b22004-09-22 16:03:36 +00001114 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
vlm39e5ed72004-09-05 10:40:41 +00001115 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001116 checkmem($$);
1117 $$->constraints = $2;
1118 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1119 $$->meta_type = AMT_TYPE;
vlm151c0b22004-09-22 16:03:36 +00001120 $6->Identifier = $4;
1121 $6->tag = $5;
1122 asn1p_expr_add($$, $6);
vlmec8f6812004-08-22 03:19:54 +00001123 }
vlm151c0b22004-09-22 16:03:36 +00001124 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
vlm39e5ed72004-09-05 10:40:41 +00001125 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001126 checkmem($$);
1127 $$->constraints = $2;
1128 $$->expr_type = ASN_CONSTR_SET_OF;
1129 $$->meta_type = AMT_TYPE;
vlm151c0b22004-09-22 16:03:36 +00001130 $6->Identifier = $4;
1131 $6->tag = $5;
1132 asn1p_expr_add($$, $6);
vlmec8f6812004-08-22 03:19:54 +00001133 }
1134 | TOK_ANY {
vlm39e5ed72004-09-05 10:40:41 +00001135 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001136 checkmem($$);
vlm044f7442004-09-04 04:49:21 +00001137 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001138 $$->meta_type = AMT_TYPE;
1139 }
1140 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1141 int ret;
vlm39e5ed72004-09-05 10:40:41 +00001142 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001143 checkmem($$);
1144 $$->reference = asn1p_ref_new(yylineno);
1145 ret = asn1p_ref_add_component($$->reference,
1146 $4, RLT_lowercase);
1147 checkmem(ret == 0);
vlm044f7442004-09-04 04:49:21 +00001148 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001149 $$->meta_type = AMT_TYPE;
1150 }
vlmfa67ddc2004-06-03 03:38:44 +00001151 /*
1152 * A parametrized assignment.
1153 */
1154 | TypeRefName '{' ActualParameterList '}' {
1155 int ret;
1156 $$ = $3;
1157 assert($$->expr_type == 0);
1158 assert($$->meta_type == 0);
1159 assert($$->reference == 0);
1160 $$->reference = asn1p_ref_new(yylineno);
1161 checkmem($$->reference);
1162 ret = asn1p_ref_add_component($$->reference, $1, RLT_UNKNOWN);
1163 checkmem(ret == 0);
1164 free($1);
1165 $$->expr_type = A1TC_PARAMETRIZED;
1166 $$->meta_type = AMT_TYPE;
1167 }
1168 /*
1169 * A DefinedType reference.
1170 * "CLASS1.&id.&id2"
1171 * or
1172 * "Module.Type"
1173 * or
1174 * "Module.identifier"
1175 * or
1176 * "Type"
1177 */
1178 | ComplexTypeReference {
1179 $$ = asn1p_expr_new(yylineno);
1180 checkmem($$);
1181 $$->reference = $1;
1182 $$->expr_type = A1TC_REFERENCE;
1183 $$->meta_type = AMT_TYPEREF;
1184 }
1185 | TOK_INSTANCE TOK_OF ComplexTypeReference {
1186 $$ = asn1p_expr_new(yylineno);
1187 checkmem($$);
1188 $$->reference = $3;
1189 $$->expr_type = A1TC_INSTANCE;
1190 $$->meta_type = AMT_TYPE;
1191 }
1192 ;
1193
1194/*
1195 * A type name consisting of several components.
1196 * === EXAMPLE ===
1197 * === EOF ===
1198 */
1199ComplexTypeReference:
1200 TOK_typereference {
1201 int ret;
1202 $$ = asn1p_ref_new(yylineno);
1203 checkmem($$);
1204 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1205 checkmem(ret == 0);
1206 free($1);
1207 }
1208 | TOK_typereference '.' TypeRefName {
1209 int ret;
1210 $$ = asn1p_ref_new(yylineno);
1211 checkmem($$);
1212 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1213 checkmem(ret == 0);
1214 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1215 checkmem(ret == 0);
1216 free($1);
1217 }
vlmc94e28f2004-09-15 11:59:51 +00001218 | ObjectClassReference '.' TypeRefName {
1219 int ret;
1220 $$ = asn1p_ref_new(yylineno);
1221 checkmem($$);
1222 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1223 checkmem(ret == 0);
1224 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1225 checkmem(ret == 0);
1226 free($1);
1227 }
vlmfa67ddc2004-06-03 03:38:44 +00001228 | TOK_typereference '.' Identifier {
1229 int ret;
1230 $$ = asn1p_ref_new(yylineno);
1231 checkmem($$);
1232 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1233 checkmem(ret == 0);
1234 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1235 checkmem(ret == 0);
1236 free($1);
1237 }
1238 | ObjectClassReference {
1239 int ret;
1240 $$ = asn1p_ref_new(yylineno);
1241 checkmem($$);
1242 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1243 free($1);
1244 checkmem(ret == 0);
1245 }
1246 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1247 int ret;
1248 $$ = $3;
1249 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1250 free($1);
1251 checkmem(ret == 0);
1252 /*
1253 * Move the last element infront.
1254 */
1255 {
1256 struct asn1p_ref_component_s tmp_comp;
1257 tmp_comp = $$->components[$$->comp_count-1];
1258 memmove(&$$->components[1],
1259 &$$->components[0],
1260 sizeof($$->components[0])
1261 * ($$->comp_count - 1));
1262 $$->components[0] = tmp_comp;
1263 }
1264 }
1265 ;
1266
1267ComplexTypeReferenceAmpList:
1268 ComplexTypeReferenceElement {
1269 int ret;
1270 $$ = asn1p_ref_new(yylineno);
1271 checkmem($$);
1272 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1273 free($1.name);
1274 checkmem(ret == 0);
1275 }
1276 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1277 int ret;
1278 $$ = $1;
1279 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1280 free($3.name);
1281 checkmem(ret == 0);
1282 }
1283 ;
1284
1285ComplexTypeReferenceElement: ClassFieldName;
1286ClassFieldIdentifier: ClassFieldName;
1287
1288ClassFieldName:
1289 /* "&Type1" */
1290 TOK_typefieldreference {
1291 $$.lex_type = RLT_AmpUppercase;
1292 $$.name = $1;
1293 }
1294 /* "&id" */
1295 | TOK_valuefieldreference {
1296 $$.lex_type = RLT_Amplowercase;
1297 $$.name = $1;
1298 }
1299 ;
1300
1301
1302/*
1303 * === EXAMPLE ===
1304 * value INTEGER ::= 1
1305 * === EOF ===
1306 */
1307ValueDefinition:
vlmc94e28f2004-09-15 11:59:51 +00001308 Identifier DefinedTypeRef TOK_PPEQ Value {
vlmfa67ddc2004-06-03 03:38:44 +00001309 $$ = $2;
1310 assert($$->Identifier == NULL);
1311 $$->Identifier = $1;
1312 $$->meta_type = AMT_VALUE;
1313 $$->value = $4;
1314 }
1315 ;
1316
vlmc94e28f2004-09-15 11:59:51 +00001317Value:
1318 Identifier ':' Value {
1319 $$ = asn1p_value_fromint(0);
1320 checkmem($$);
1321 $$->type = ATV_CHOICE_IDENTIFIER;
1322 $$->value.choice_identifier.identifier = $1;
1323 $$->value.choice_identifier.value = $3;
1324 }
vlmd30bc6c2005-03-24 16:27:02 +00001325 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
vlmfa67ddc2004-06-03 03:38:44 +00001326 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1327 checkmem($$);
1328 $$->type = ATV_UNPARSED;
1329 }
vlmc94e28f2004-09-15 11:59:51 +00001330 | TOK_NULL {
1331 $$ = asn1p_value_fromint(0);
1332 checkmem($$);
1333 $$->type = ATV_NULL;
1334 }
1335 | TOK_FALSE {
1336 $$ = asn1p_value_fromint(0);
1337 checkmem($$);
1338 $$->type = ATV_FALSE;
1339 }
1340 | TOK_TRUE {
1341 $$ = asn1p_value_fromint(0);
1342 checkmem($$);
1343 $$->type = ATV_TRUE;
1344 }
vlmfa67ddc2004-06-03 03:38:44 +00001345 | TOK_bstring {
1346 $$ = _convert_bitstring2binary($1, 'B');
1347 checkmem($$);
1348 }
1349 | TOK_hstring {
1350 $$ = _convert_bitstring2binary($1, 'H');
1351 checkmem($$);
1352 }
vlme1e6ed82005-03-24 14:26:38 +00001353 | RestrictedCharacterStringValue {
1354 $$ = $$;
vlmfa67ddc2004-06-03 03:38:44 +00001355 }
1356 | SignedNumber {
1357 $$ = $1;
1358 }
1359 | DefinedValue {
1360 $$ = $1;
1361 }
1362 ;
1363
1364DefinedValue:
1365 Identifier {
1366 asn1p_ref_t *ref;
1367 int ret;
1368 ref = asn1p_ref_new(yylineno);
1369 checkmem(ref);
1370 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1371 checkmem(ret == 0);
1372 $$ = asn1p_value_fromref(ref, 0);
1373 checkmem($$);
1374 free($1);
1375 }
1376 | TypeRefName '.' Identifier {
1377 asn1p_ref_t *ref;
1378 int ret;
1379 ref = asn1p_ref_new(yylineno);
1380 checkmem(ref);
1381 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1382 checkmem(ret == 0);
1383 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1384 checkmem(ret == 0);
1385 $$ = asn1p_value_fromref(ref, 0);
1386 checkmem($$);
1387 free($1);
1388 free($3);
1389 }
1390 ;
1391
vlme1e6ed82005-03-24 14:26:38 +00001392
1393RestrictedCharacterStringValue:
1394 TOK_cstring {
1395 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1396 checkmem($$);
1397 }
vlm2c8c44d2005-03-24 16:22:35 +00001398 | TOK_tuple {
1399 $$ = asn1p_value_fromint($1);
1400 checkmem($$);
1401 $$->type = ATV_TUPLE;
1402 }
1403 | TOK_quadruple {
1404 $$ = asn1p_value_fromint($1);
1405 checkmem($$);
1406 $$->type = ATV_QUADRUPLE;
1407 }
1408 /*
vlme1e6ed82005-03-24 14:26:38 +00001409 | '{' TOK_number ',' TOK_number '}' {
1410 asn1c_integer_t v = ($2 << 4) + $4;
1411 if($2 > 7) return yyerror("X.680:2003, #37.14 "
1412 "mandates 0..7 range for Tuple's TableColumn");
1413 if($4 > 15) return yyerror("X.680:2003, #37.14 "
1414 "mandates 0..15 range for Tuple's TableRow");
1415 $$ = asn1p_value_fromint(v);
1416 checkmem($$);
1417 $$->type = ATV_TUPLE;
1418 }
1419 | '{' TOK_number ',' TOK_number ',' TOK_number ',' TOK_number '}' {
1420 asn1c_integer_t v = ($2 << 24) | ($4 << 16) | ($6 << 8) | $8;
1421 if($2 > 127) return yyerror("X.680:2003, #37.12 "
1422 "mandates 0..127 range for Quadruple's Group");
1423 if($4 > 255) return yyerror("X.680:2003, #37.12 "
1424 "mandates 0..255 range for Quadruple's Plane");
1425 if($6 > 255) return yyerror("X.680:2003, #37.12 "
1426 "mandates 0..255 range for Quadruple's Row");
1427 if($8 > 255) return yyerror("X.680:2003, #37.12 "
1428 "mandates 0..255 range for Quadruple's Cell");
1429 $$ = asn1p_value_fromint(v);
1430 checkmem($$);
1431 $$->type = ATV_QUADRUPLE;
1432 }
vlm2c8c44d2005-03-24 16:22:35 +00001433 */
vlme1e6ed82005-03-24 14:26:38 +00001434 ;
1435
vlmfa67ddc2004-06-03 03:38:44 +00001436Opaque:
1437 TOK_opaque {
vlm6611add2005-03-20 14:28:32 +00001438 $$.len = $1.len + 1;
vlmfa67ddc2004-06-03 03:38:44 +00001439 $$.buf = malloc($$.len + 1);
1440 checkmem($$.buf);
1441 $$.buf[0] = '{';
vlm6611add2005-03-20 14:28:32 +00001442 memcpy($$.buf + 1, $1.buf, $1.len);
vlmfa67ddc2004-06-03 03:38:44 +00001443 $$.buf[$$.len] = '\0';
1444 free($1.buf);
1445 }
1446 | Opaque TOK_opaque {
1447 int newsize = $1.len + $2.len;
1448 char *p = malloc(newsize + 1);
1449 checkmem(p);
1450 memcpy(p , $1.buf, $1.len);
1451 memcpy(p + $1.len, $2.buf, $2.len);
1452 p[newsize] = '\0';
1453 free($1.buf);
1454 free($2.buf);
1455 $$.buf = p;
1456 $$.len = newsize;
1457 }
1458 ;
1459
1460BasicTypeId:
1461 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1462 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1463 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1464 | BasicTypeId_UniverationCompatible { $$ = $1; }
1465 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1466 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1467 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1468 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1469 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1470 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1471 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1472 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
vlm5e2c4b92005-03-20 11:12:40 +00001473 | BasicString { $$ = $1; }
vlmfa67ddc2004-06-03 03:38:44 +00001474 ;
1475
1476/*
1477 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1478 */
1479BasicTypeId_UniverationCompatible:
1480 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1481 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1482 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1483 ;
1484
1485BasicType:
1486 BasicTypeId {
vlm39e5ed72004-09-05 10:40:41 +00001487 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001488 checkmem($$);
1489 $$->expr_type = $1;
1490 $$->meta_type = AMT_TYPE;
1491 }
1492 | BasicTypeId_UniverationCompatible UniverationDefinition {
1493 if($2) {
1494 $$ = $2;
1495 } else {
vlm39e5ed72004-09-05 10:40:41 +00001496 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001497 checkmem($$);
1498 }
1499 $$->expr_type = $1;
1500 $$->meta_type = AMT_TYPE;
1501 }
1502 ;
1503
1504BasicString:
1505 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1506 | TOK_GeneralString {
1507 $$ = ASN_STRING_GeneralString;
vlmc94e28f2004-09-15 11:59:51 +00001508 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001509 }
1510 | TOK_GraphicString {
1511 $$ = ASN_STRING_GraphicString;
vlmc94e28f2004-09-15 11:59:51 +00001512 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001513 }
1514 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1515 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1516 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1517 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1518 | TOK_T61String {
1519 $$ = ASN_STRING_T61String;
vlmc94e28f2004-09-15 11:59:51 +00001520 fprintf(stderr, "WARNING: T61String is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001521 }
1522 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1523 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1524 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1525 | TOK_VideotexString {
1526 $$ = ASN_STRING_VideotexString;
vlmc94e28f2004-09-15 11:59:51 +00001527 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001528 }
1529 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1530 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1531 ;
1532
vlm5f0128b2004-08-20 13:25:29 +00001533
vlmfa67ddc2004-06-03 03:38:44 +00001534/*
1535 * Data type constraints.
1536 */
vlmfa67ddc2004-06-03 03:38:44 +00001537Union: '|' | TOK_UNION;
1538Intersection: '^' | TOK_INTERSECTION;
1539Except: TOK_EXCEPT;
1540
vlm9283dbe2004-08-18 04:59:12 +00001541optConstraints:
1542 { $$ = 0; }
vlm5f0128b2004-08-20 13:25:29 +00001543 | Constraints {
1544 $$ = $1;
1545 }
1546 ;
1547
1548Constraints:
1549 SetOfConstraints {
vlm9fe7c922005-08-12 10:08:45 +00001550 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
vlm9283dbe2004-08-18 04:59:12 +00001551 }
1552 | TOK_SIZE '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001553 /*
1554 * This is a special case, for compatibility purposes.
vlm9283dbe2004-08-18 04:59:12 +00001555 * It goes without parentheses.
vlmfa67ddc2004-06-03 03:38:44 +00001556 */
vlm9fe7c922005-08-12 10:08:45 +00001557 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001558 }
vlmfa67ddc2004-06-03 03:38:44 +00001559 ;
1560
vlm9283dbe2004-08-18 04:59:12 +00001561SetOfConstraints:
1562 '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001563 $$ = $2;
1564 }
vlm9283dbe2004-08-18 04:59:12 +00001565 | SetOfConstraints '(' ElementSetSpecs ')' {
vlm9fe7c922005-08-12 10:08:45 +00001566 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
vlm9283dbe2004-08-18 04:59:12 +00001567 }
vlmfa67ddc2004-06-03 03:38:44 +00001568 ;
1569
vlm9283dbe2004-08-18 04:59:12 +00001570ElementSetSpecs:
1571 ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001572 $$ = $1;
1573 }
vlm9283dbe2004-08-18 04:59:12 +00001574 | ElementSetSpec ',' TOK_ThreeDots {
vlmfa67ddc2004-06-03 03:38:44 +00001575 asn1p_constraint_t *ct;
1576 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001577 ct->type = ACT_EL_EXT;
vlm9fe7c922005-08-12 10:08:45 +00001578 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlmfa67ddc2004-06-03 03:38:44 +00001579 }
vlm9283dbe2004-08-18 04:59:12 +00001580 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001581 asn1p_constraint_t *ct;
1582 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001583 ct->type = ACT_EL_EXT;
vlm9fe7c922005-08-12 10:08:45 +00001584 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlm6f5eb0b2004-08-13 12:35:09 +00001585 ct = $$;
vlm9fe7c922005-08-12 10:08:45 +00001586 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
vlmfa67ddc2004-06-03 03:38:44 +00001587 }
vlmfa67ddc2004-06-03 03:38:44 +00001588 ;
1589
vlm9283dbe2004-08-18 04:59:12 +00001590ElementSetSpec:
1591 ConstraintSubtypeElement {
1592 $$ = $1;
1593 }
vlme1e6ed82005-03-24 14:26:38 +00001594 | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001595 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
vlme1e6ed82005-03-24 14:26:38 +00001596 }
vlm9283dbe2004-08-18 04:59:12 +00001597 | ElementSetSpec Union ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001598 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001599 }
vlm9283dbe2004-08-18 04:59:12 +00001600 | ElementSetSpec Intersection ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001601 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001602 }
vlm9283dbe2004-08-18 04:59:12 +00001603 | ConstraintSubtypeElement Except ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001604 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001605 }
1606 ;
1607
1608ConstraintSubtypeElement:
vlm9283dbe2004-08-18 04:59:12 +00001609 ConstraintSpec '(' ElementSetSpecs ')' {
1610 int ret;
1611 $$ = asn1p_constraint_new(yylineno);
1612 checkmem($$);
1613 $$->type = $1;
1614 ret = asn1p_constraint_insert($$, $3);
1615 checkmem(ret == 0);
1616 }
1617 | '(' ElementSetSpecs ')' {
1618 int ret;
1619 $$ = asn1p_constraint_new(yylineno);
1620 checkmem($$);
1621 $$->type = ACT_CA_SET;
1622 ret = asn1p_constraint_insert($$, $2);
1623 checkmem(ret == 0);
1624 }
vlma6a12e32005-03-20 12:58:00 +00001625 | SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001626 $$ = asn1p_constraint_new(yylineno);
1627 checkmem($$);
1628 $$->type = ACT_EL_VALUE;
1629 $$->value = $1;
1630 }
vlma6a12e32005-03-20 12:58:00 +00001631 | ContainedSubtype {
1632 $$ = asn1p_constraint_new(yylineno);
1633 checkmem($$);
1634 $$->type = ACT_EL_TYPE;
1635 $$->containedSubtype = $1;
1636 }
1637 | SingleValue ConstraintRangeSpec SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001638 $$ = asn1p_constraint_new(yylineno);
1639 checkmem($$);
1640 $$->type = $2;
1641 $$->range_start = $1;
1642 $$->range_stop = $3;
1643 }
vlma6a12e32005-03-20 12:58:00 +00001644 | TOK_MIN ConstraintRangeSpec SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001645 $$ = asn1p_constraint_new(yylineno);
1646 checkmem($$);
vlm9283dbe2004-08-18 04:59:12 +00001647 $$->type = $2;
1648 $$->range_start = asn1p_value_fromint(-123);
1649 $$->range_stop = $3;
1650 $$->range_start->type = ATV_MIN;
1651 }
vlma6a12e32005-03-20 12:58:00 +00001652 | SingleValue ConstraintRangeSpec TOK_MAX {
vlm9283dbe2004-08-18 04:59:12 +00001653 $$ = asn1p_constraint_new(yylineno);
1654 checkmem($$);
1655 $$->type = $2;
1656 $$->range_start = $1;
1657 $$->range_stop = asn1p_value_fromint(321);
1658 $$->range_stop->type = ATV_MAX;
1659 }
1660 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1661 $$ = asn1p_constraint_new(yylineno);
1662 checkmem($$);
1663 $$->type = $2;
1664 $$->range_start = asn1p_value_fromint(-123);
1665 $$->range_stop = asn1p_value_fromint(321);
1666 $$->range_start->type = ATV_MIN;
1667 $$->range_stop->type = ATV_MAX;
vlmfa67ddc2004-06-03 03:38:44 +00001668 }
1669 | TableConstraint {
1670 $$ = $1;
1671 }
vlm7bbdc9f2005-03-28 15:01:27 +00001672 | InnerTypeConstraint {
vlmfa67ddc2004-06-03 03:38:44 +00001673 $$ = $1;
1674 }
vlm6611add2005-03-20 14:28:32 +00001675 | TOK_CONSTRAINED TOK_BY '{'
1676 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1677 $$ = asn1p_constraint_new(yylineno);
1678 checkmem($$);
1679 $$->type = ACT_CT_CTDBY;
1680 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
1681 checkmem($$->value);
1682 $$->value->type = ATV_UNPARSED;
1683 }
vlmfa67ddc2004-06-03 03:38:44 +00001684 ;
1685
1686ConstraintRangeSpec:
1687 TOK_TwoDots { $$ = ACT_EL_RANGE; }
1688 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
1689 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
1690 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
1691 ;
1692
1693ConstraintSpec:
1694 TOK_SIZE {
1695 $$ = ACT_CT_SIZE;
1696 }
1697 | TOK_FROM {
1698 $$ = ACT_CT_FROM;
1699 }
1700 ;
1701
vlma6a12e32005-03-20 12:58:00 +00001702SingleValue:
vlm4053ca52005-02-18 16:34:21 +00001703 TOK_FALSE {
1704 $$ = asn1p_value_fromint(0);
1705 checkmem($$);
1706 $$->type = ATV_FALSE;
1707 }
1708 | TOK_TRUE {
1709 $$ = asn1p_value_fromint(1);
1710 checkmem($$);
1711 $$->type = ATV_TRUE;
1712 }
1713 | SignedNumber {
vlmfa67ddc2004-06-03 03:38:44 +00001714 $$ = $1;
1715 }
vlme1e6ed82005-03-24 14:26:38 +00001716 | RestrictedCharacterStringValue {
1717 $$ = $1;
vlm4053ca52005-02-18 16:34:21 +00001718 }
vlmfa67ddc2004-06-03 03:38:44 +00001719 | Identifier {
1720 asn1p_ref_t *ref;
1721 int ret;
1722 ref = asn1p_ref_new(yylineno);
1723 checkmem(ref);
1724 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1725 checkmem(ret == 0);
1726 $$ = asn1p_value_fromref(ref, 0);
1727 checkmem($$);
1728 free($1);
1729 }
vlma6a12e32005-03-20 12:58:00 +00001730 ;
1731
1732ContainedSubtype:
1733 TypeRefName {
vlm4053ca52005-02-18 16:34:21 +00001734 asn1p_ref_t *ref;
1735 int ret;
1736 ref = asn1p_ref_new(yylineno);
1737 checkmem(ref);
1738 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1739 checkmem(ret == 0);
1740 $$ = asn1p_value_fromref(ref, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001741 checkmem($$);
vlm4053ca52005-02-18 16:34:21 +00001742 free($1);
vlmfa67ddc2004-06-03 03:38:44 +00001743 }
1744 ;
1745
vlm7bbdc9f2005-03-28 15:01:27 +00001746InnerTypeConstraint:
1747 TOK_WITH TOK_COMPONENT SetOfConstraints {
vlm9fe7c922005-08-12 10:08:45 +00001748 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
vlm7bbdc9f2005-03-28 15:01:27 +00001749 }
1750 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
vlm9fe7c922005-08-12 10:08:45 +00001751 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001752 }
1753 ;
1754
1755WithComponentsList:
1756 WithComponentsElement {
1757 $$ = $1;
1758 }
1759 | WithComponentsList ',' WithComponentsElement {
vlm9fe7c922005-08-12 10:08:45 +00001760 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001761 }
1762 ;
1763
1764WithComponentsElement:
1765 TOK_ThreeDots {
1766 $$ = asn1p_constraint_new(yylineno);
1767 checkmem($$);
1768 $$->type = ACT_EL_EXT;
vlm7bbdc9f2005-03-28 15:01:27 +00001769 $$->value = asn1p_value_frombuf("...", 3, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001770 }
1771 | Identifier optConstraints optPresenceConstraint {
1772 $$ = asn1p_constraint_new(yylineno);
1773 checkmem($$);
1774 $$->type = ACT_EL_VALUE;
1775 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1776 $$->presence = $3;
vlm7bbdc9f2005-03-28 15:01:27 +00001777 if($2) asn1p_constraint_insert($$, $2);
vlmfa67ddc2004-06-03 03:38:44 +00001778 }
1779 ;
1780
1781/*
1782 * presence constraint for WithComponents
1783 */
1784optPresenceConstraint:
1785 { $$ = ACPRES_DEFAULT; }
1786 | PresenceConstraint { $$ = $1; }
1787 ;
1788
1789PresenceConstraint:
1790 TOK_PRESENT {
1791 $$ = ACPRES_PRESENT;
1792 }
1793 | TOK_ABSENT {
1794 $$ = ACPRES_ABSENT;
1795 }
1796 | TOK_OPTIONAL {
1797 $$ = ACPRES_OPTIONAL;
1798 }
1799 ;
1800
1801TableConstraint:
1802 SimpleTableConstraint {
1803 $$ = $1;
1804 }
1805 | ComponentRelationConstraint {
1806 $$ = $1;
1807 }
1808 ;
1809
1810/*
1811 * "{ExtensionSet}"
1812 */
1813SimpleTableConstraint:
1814 '{' TypeRefName '}' {
1815 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
1816 asn1p_constraint_t *ct;
1817 int ret;
1818 ret = asn1p_ref_add_component(ref, $2, 0);
1819 checkmem(ret == 0);
1820 ct = asn1p_constraint_new(yylineno);
1821 checkmem($$);
1822 ct->type = ACT_EL_VALUE;
1823 ct->value = asn1p_value_fromref(ref, 0);
vlm9fe7c922005-08-12 10:08:45 +00001824 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001825 }
1826 ;
1827
1828ComponentRelationConstraint:
1829 SimpleTableConstraint '{' AtNotationList '}' {
vlm9fe7c922005-08-12 10:08:45 +00001830 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001831 }
1832 ;
1833
1834AtNotationList:
1835 AtNotationElement {
1836 $$ = asn1p_constraint_new(yylineno);
1837 checkmem($$);
1838 $$->type = ACT_EL_VALUE;
1839 $$->value = asn1p_value_fromref($1, 0);
1840 }
1841 | AtNotationList ',' AtNotationElement {
1842 asn1p_constraint_t *ct;
1843 ct = asn1p_constraint_new(yylineno);
1844 checkmem(ct);
1845 ct->type = ACT_EL_VALUE;
1846 ct->value = asn1p_value_fromref($3, 0);
vlm9fe7c922005-08-12 10:08:45 +00001847 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlmfa67ddc2004-06-03 03:38:44 +00001848 }
1849 ;
1850
1851/*
1852 * @blah
1853 */
1854AtNotationElement:
1855 '@' ComponentIdList {
1856 char *p = malloc(strlen($2) + 2);
1857 int ret;
1858 *p = '@';
1859 strcpy(p + 1, $2);
1860 $$ = asn1p_ref_new(yylineno);
1861 ret = asn1p_ref_add_component($$, p, 0);
1862 checkmem(ret == 0);
1863 free(p);
1864 free($2);
1865 }
1866 | '@' '.' ComponentIdList {
1867 char *p = malloc(strlen($3) + 3);
1868 int ret;
1869 p[0] = '@';
1870 p[1] = '.';
1871 strcpy(p + 2, $3);
1872 $$ = asn1p_ref_new(yylineno);
1873 ret = asn1p_ref_add_component($$, p, 0);
1874 checkmem(ret == 0);
1875 free(p);
1876 free($3);
1877 }
1878 ;
1879
1880/* identifier "." ... */
1881ComponentIdList:
1882 Identifier {
1883 $$ = $1;
1884 }
1885 | ComponentIdList '.' Identifier {
1886 int l1 = strlen($1);
1887 int l3 = strlen($3);
1888 $$ = malloc(l1 + 1 + l3 + 1);
1889 memcpy($$, $1, l1);
1890 $$[l1] = '.';
1891 memcpy($$ + l1 + 1, $3, l3);
1892 $$[l1 + 1 + l3] = '\0';
1893 }
1894 ;
1895
1896
1897
1898/*
1899 * MARKERS
1900 */
1901
1902optMarker:
vlmc94e28f2004-09-15 11:59:51 +00001903 {
1904 $$.flags = EM_NOMARK;
1905 $$.default_value = 0;
1906 }
vlmfa67ddc2004-06-03 03:38:44 +00001907 | Marker { $$ = $1; }
1908 ;
1909
1910Marker:
1911 TOK_OPTIONAL {
vlmc94e28f2004-09-15 11:59:51 +00001912 $$.flags = EM_OPTIONAL;
1913 $$.default_value = 0;
vlmfa67ddc2004-06-03 03:38:44 +00001914 }
vlmc94e28f2004-09-15 11:59:51 +00001915 | TOK_DEFAULT Value {
1916 $$.flags = EM_DEFAULT;
1917 $$.default_value = $2;
vlmfa67ddc2004-06-03 03:38:44 +00001918 }
1919 ;
1920
1921/*
1922 * Universal enumeration definition to use in INTEGER and ENUMERATED.
1923 * === EXAMPLE ===
1924 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
1925 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
1926 * === EOF ===
1927 */
1928/*
1929optUniverationDefinition:
1930 { $$ = 0; }
1931 | UniverationDefinition {
1932 $$ = $1;
1933 }
1934 ;
1935*/
1936
1937UniverationDefinition:
1938 '{' '}' {
vlm39e5ed72004-09-05 10:40:41 +00001939 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001940 checkmem($$);
1941 }
1942 | '{' UniverationList '}' {
1943 $$ = $2;
1944 }
1945 ;
1946
1947UniverationList:
1948 UniverationElement {
vlm39e5ed72004-09-05 10:40:41 +00001949 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001950 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +00001951 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +00001952 }
1953 | UniverationList ',' UniverationElement {
1954 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +00001955 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001956 }
1957 ;
1958
1959UniverationElement:
1960 Identifier {
vlm39e5ed72004-09-05 10:40:41 +00001961 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001962 checkmem($$);
1963 $$->expr_type = A1TC_UNIVERVAL;
1964 $$->meta_type = AMT_VALUE;
1965 $$->Identifier = $1;
1966 }
1967 | Identifier '(' SignedNumber ')' {
vlm39e5ed72004-09-05 10:40:41 +00001968 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001969 checkmem($$);
1970 $$->expr_type = A1TC_UNIVERVAL;
1971 $$->meta_type = AMT_VALUE;
1972 $$->Identifier = $1;
1973 $$->value = $3;
1974 }
1975 | Identifier '(' DefinedValue ')' {
vlm39e5ed72004-09-05 10:40:41 +00001976 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001977 checkmem($$);
1978 $$->expr_type = A1TC_UNIVERVAL;
1979 $$->meta_type = AMT_VALUE;
1980 $$->Identifier = $1;
1981 $$->value = $3;
1982 }
1983 | SignedNumber {
vlm39e5ed72004-09-05 10:40:41 +00001984 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001985 checkmem($$);
1986 $$->expr_type = A1TC_UNIVERVAL;
1987 $$->meta_type = AMT_VALUE;
1988 $$->value = $1;
1989 }
1990 | TOK_ThreeDots {
vlm39e5ed72004-09-05 10:40:41 +00001991 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001992 checkmem($$);
1993 $$->Identifier = strdup("...");
1994 checkmem($$->Identifier);
1995 $$->expr_type = A1TC_EXTENSIBLE;
1996 $$->meta_type = AMT_VALUE;
1997 }
1998 ;
1999
2000SignedNumber:
2001 TOK_number {
2002 $$ = asn1p_value_fromint($1);
2003 checkmem($$);
2004 }
2005 | TOK_number_negative {
2006 $$ = asn1p_value_fromint($1);
2007 checkmem($$);
2008 }
2009 ;
2010
2011/*
2012 * SEQUENCE definition.
2013 * === EXAMPLE ===
2014 * Struct1 ::= SEQUENCE {
2015 * memb1 Struct2,
2016 * memb2 SEQUENCE OF {
2017 * memb2-1 Struct 3
2018 * }
2019 * }
2020 * === EOF ===
2021 */
2022
2023
2024
2025/*
2026 * SET definition.
2027 * === EXAMPLE ===
2028 * Person ::= SET {
2029 * name [0] PrintableString (SIZE(1..20)),
2030 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2031 * }
2032 * === EOF ===
2033 */
2034
2035optTag:
2036 { memset(&$$, 0, sizeof($$)); }
2037 | Tag { $$ = $1; }
2038 ;
2039
2040Tag:
vlm2728a8d2005-01-23 09:51:44 +00002041 TagTypeValue TagPlicit {
vlmfa67ddc2004-06-03 03:38:44 +00002042 $$ = $1;
vlm2728a8d2005-01-23 09:51:44 +00002043 $$.tag_mode = $2.tag_mode;
vlmfa67ddc2004-06-03 03:38:44 +00002044 }
vlm2728a8d2005-01-23 09:51:44 +00002045 ;
2046
2047TagTypeValue:
2048 '[' TagClass TOK_number ']' {
2049 $$ = $2;
2050 $$.tag_value = $3;
2051 };
2052
2053TagClass:
2054 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2055 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2056 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2057 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2058 ;
2059
2060TagPlicit:
2061 { $$.tag_mode = TM_DEFAULT; }
2062 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2063 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
vlmfa67ddc2004-06-03 03:38:44 +00002064 ;
2065
2066TypeRefName:
2067 TOK_typereference {
2068 checkmem($1);
2069 $$ = $1;
2070 }
vlm9283dbe2004-08-18 04:59:12 +00002071 | TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00002072 checkmem($1);
2073 $$ = $1;
2074 }
2075 ;
2076
vlm9283dbe2004-08-18 04:59:12 +00002077
vlmfa67ddc2004-06-03 03:38:44 +00002078ObjectClassReference:
vlm9283dbe2004-08-18 04:59:12 +00002079 TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00002080 checkmem($1);
2081 $$ = $1;
2082 }
2083 ;
2084
vlm151c0b22004-09-22 16:03:36 +00002085optIdentifier:
2086 { $$ = 0; }
2087 | Identifier {
2088 $$ = $1;
2089 }
vlma5b977d2005-06-06 08:28:58 +00002090 ;
vlm151c0b22004-09-22 16:03:36 +00002091
vlmfa67ddc2004-06-03 03:38:44 +00002092Identifier:
2093 TOK_identifier {
2094 checkmem($1);
2095 $$ = $1;
2096 }
2097 ;
2098
vlmfa67ddc2004-06-03 03:38:44 +00002099%%
2100
2101
2102/*
2103 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2104 */
2105static asn1p_value_t *
2106_convert_bitstring2binary(char *str, int base) {
2107 asn1p_value_t *val;
2108 int slen;
2109 int memlen;
2110 int baselen;
2111 int bits;
2112 uint8_t *binary_vector;
2113 uint8_t *bv_ptr;
2114 uint8_t cur_val;
2115
2116 assert(str);
2117 assert(str[0] == '\'');
2118
2119 switch(base) {
2120 case 'B':
2121 baselen = 1;
2122 break;
2123 case 'H':
2124 baselen = 4;
2125 break;
2126 default:
2127 assert(base == 'B' || base == 'H');
2128 errno = EINVAL;
2129 return NULL;
2130 }
2131
2132 slen = strlen(str);
2133 assert(str[slen - 1] == base);
2134 assert(str[slen - 2] == '\'');
2135
2136 memlen = slen / (8 / baselen); /* Conservative estimate */
2137
2138 bv_ptr = binary_vector = malloc(memlen + 1);
2139 if(bv_ptr == NULL)
2140 /* ENOMEM */
2141 return NULL;
2142
2143 cur_val = 0;
2144 bits = 0;
2145 while(*(++str) != '\'') {
2146 switch(baselen) {
2147 case 1:
2148 switch(*str) {
2149 case '1':
2150 cur_val |= 1 << (7 - (bits % 8));
2151 case '0':
2152 break;
2153 default:
2154 assert(!"_y UNREACH1");
2155 case ' ': case '\r': case '\n':
2156 continue;
2157 }
2158 break;
2159 case 4:
2160 switch(*str) {
2161 case '0': case '1': case '2': case '3': case '4':
2162 case '5': case '6': case '7': case '8': case '9':
2163 cur_val |= (*str - '0') << (4 - (bits % 8));
2164 break;
2165 case 'A': case 'B': case 'C':
2166 case 'D': case 'E': case 'F':
2167 cur_val |= ((*str - 'A') + 10)
2168 << (4 - (bits % 8));
2169 break;
2170 default:
2171 assert(!"_y UNREACH2");
2172 case ' ': case '\r': case '\n':
2173 continue;
2174 }
2175 break;
2176 }
2177
2178 bits += baselen;
2179 if((bits % 8) == 0) {
2180 *bv_ptr++ = cur_val;
2181 cur_val = 0;
2182 }
2183 }
2184
2185 *bv_ptr = cur_val;
2186 assert((bv_ptr - binary_vector) <= memlen);
2187
2188 val = asn1p_value_frombits(binary_vector, bits, 0);
2189 if(val == NULL) {
2190 free(binary_vector);
2191 }
2192
2193 return val;
2194}
2195
vlm5d89c3d2005-08-13 09:07:11 +00002196/*
2197 * For unnamed types (used in old X.208 compliant modules)
2198 * generate some sort of interim names, to not to force human being to fix
2199 * the specification's compliance to modern ASN.1 standards.
2200 */
2201static void
2202_fixup_anonymous_identifier(asn1p_expr_t *expr) {
2203 char *p;
2204 assert(expr->Identifier == 0);
2205
2206 /*
2207 * Try to figure out the type name
2208 * without going too much into details
2209 */
2210 expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type);
2211 if(expr->reference && expr->reference->comp_count > 0)
2212 expr->Identifier = expr->reference->components[0].name;
2213
2214 fprintf(stderr,
2215 "WARNING: Line %d: expected lower-case member identifier, "
2216 "found an unnamed %s.\n"
2217 "WARNING: Obsolete X.208 syntax detected, "
2218 "please give the member a name.\n",
2219 yylineno, expr->Identifier ? expr->Identifier : "type");
2220
2221 if(!expr->Identifier)
2222 expr->Identifier = "unnamed";
2223 expr->Identifier = strdup(expr->Identifier);
2224 assert(expr->Identifier);
2225 /* Make a lowercase identifier from the type name */
2226 for(p = expr->Identifier; *p; p++) {
2227 switch(*p) {
2228 case 'A' ... 'Z': *p += 32; break;
2229 case ' ': *p = '_'; break;
2230 case '-': *p = '_'; break;
2231 }
2232 }
2233 fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". "
2234 "Name clash may occur later.\n",
2235 expr->Identifier);
2236}
2237
vlmfa67ddc2004-06-03 03:38:44 +00002238extern char *asn1p_text;
2239
2240int
2241yyerror(const char *msg) {
2242 fprintf(stderr,
2243 "ASN.1 grammar parse error "
2244 "near line %d (token \"%s\"): %s\n",
vlm39e5ed72004-09-05 10:40:41 +00002245 yylineno, asn1p_text, msg);
vlmfa67ddc2004-06-03 03:38:44 +00002246 return -1;
2247}
2248
2249