blob: ae63090ea14144e530a2c24e7ae1be68d17c6ac8 [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
12#define YYERROR_VERBOSE
13
14int yylex(void);
15int yyerror(const char *msg);
16void asn1p_lexer_hack_push_opaque_state(void);
17void asn1p_lexer_hack_enable_with_syntax(void);
vlm9283dbe2004-08-18 04:59:12 +000018void asn1p_lexer_hack_push_encoding_control(void);
vlmfa67ddc2004-06-03 03:38:44 +000019#define yylineno asn1p_lineno
20extern int asn1p_lineno;
21
22
23static asn1p_value_t *
24 _convert_bitstring2binary(char *str, int base);
25
vlm6a02a8a2004-09-08 00:28:11 +000026#define checkmem(ptr) do { \
27 if(!(ptr)) \
28 return yyerror("Memory failure"); \
vlmfa67ddc2004-06-03 03:38:44 +000029 } while(0)
30
31#define CONSTRAINT_INSERT(root, constr_type, arg1, arg2) do { \
32 if(arg1->type != constr_type) { \
33 int __ret; \
34 root = asn1p_constraint_new(yylineno); \
35 checkmem(root); \
36 root->type = constr_type; \
37 __ret = asn1p_constraint_insert(root, \
38 arg1); \
39 checkmem(__ret == 0); \
40 } else { \
41 root = arg1; \
42 } \
43 if(arg2) { \
44 int __ret \
45 = asn1p_constraint_insert(root, arg2); \
46 checkmem(__ret == 0); \
47 } \
48 } while(0)
49
50%}
51
52
53/*
54 * Token value definition.
55 * a_*: ASN-specific types.
56 * tv_*: Locally meaningful types.
57 */
58%union {
59 asn1p_t *a_grammar;
60 asn1p_module_flags_e a_module_flags;
61 asn1p_module_t *a_module;
62 asn1p_expr_type_e a_type; /* ASN.1 Type */
63 asn1p_expr_t *a_expr; /* Constructed collection */
64 asn1p_constraint_t *a_constr; /* Constraint */
65 enum asn1p_constraint_type_e a_ctype;/* Constraint type */
66 asn1p_xports_t *a_xports; /* IMports/EXports */
67 asn1p_oid_t *a_oid; /* Object Identifier */
68 asn1p_oid_arc_t a_oid_arc; /* Single OID's arc */
69 struct asn1p_type_tag_s a_tag; /* A tag */
70 asn1p_ref_t *a_ref; /* Reference to custom type */
71 asn1p_wsyntx_t *a_wsynt; /* WITH SYNTAX contents */
72 asn1p_wsyntx_chunk_t *a_wchunk; /* WITH SYNTAX chunk */
73 struct asn1p_ref_component_s a_refcomp; /* Component of a reference */
74 asn1p_value_t *a_value; /* Number, DefinedValue, etc */
75 struct asn1p_param_s a_parg; /* A parameter argument */
76 asn1p_paramlist_t *a_plist; /* A pargs list */
vlmc94e28f2004-09-15 11:59:51 +000077 struct asn1p_expr_marker_s a_marker; /* OPTIONAL/DEFAULT */
vlmfa67ddc2004-06-03 03:38:44 +000078 enum asn1p_constr_pres_e a_pres; /* PRESENT/ABSENT/OPTIONAL */
79 asn1_integer_t a_int;
80 char *tv_str;
81 struct {
82 char *buf;
83 int len;
84 } tv_opaque;
85 struct {
86 char *name;
87 struct asn1p_type_tag_s tag;
88 } tv_nametag;
89};
90
91/*
92 * Token types returned by scanner.
93 */
94%token TOK_PPEQ /* "::=", Pseudo Pascal EQuality */
95%token <tv_opaque> TOK_opaque /* opaque data (driven from .y) */
96%token <tv_str> TOK_bstring
97%token <tv_opaque> TOK_cstring
98%token <tv_str> TOK_hstring
99%token <tv_str> TOK_identifier
100%token <a_int> TOK_number
101%token <a_int> TOK_number_negative
102%token <tv_str> TOK_typereference
vlm9283dbe2004-08-18 04:59:12 +0000103%token <tv_str> TOK_capitalreference /* "CLASS1" */
vlmfa67ddc2004-06-03 03:38:44 +0000104%token <tv_str> TOK_typefieldreference /* "&Pork" */
105%token <tv_str> TOK_valuefieldreference /* "&id" */
106
107/*
108 * Token types representing ASN.1 standard keywords.
109 */
110%token TOK_ABSENT
111%token TOK_ABSTRACT_SYNTAX
112%token TOK_ALL
113%token TOK_ANY
114%token TOK_APPLICATION
115%token TOK_AUTOMATIC
116%token TOK_BEGIN
117%token TOK_BIT
118%token TOK_BMPString
119%token TOK_BOOLEAN
120%token TOK_BY
121%token TOK_CHARACTER
122%token TOK_CHOICE
123%token TOK_CLASS
124%token TOK_COMPONENT
125%token TOK_COMPONENTS
126%token TOK_CONSTRAINED
127%token TOK_CONTAINING
128%token TOK_DEFAULT
129%token TOK_DEFINITIONS
130%token TOK_DEFINED
131%token TOK_EMBEDDED
132%token TOK_ENCODED
vlm9283dbe2004-08-18 04:59:12 +0000133%token TOK_ENCODING_CONTROL
vlmfa67ddc2004-06-03 03:38:44 +0000134%token TOK_END
135%token TOK_ENUMERATED
136%token TOK_EXPLICIT
137%token TOK_EXPORTS
138%token TOK_EXTENSIBILITY
139%token TOK_EXTERNAL
140%token TOK_FALSE
141%token TOK_FROM
142%token TOK_GeneralizedTime
143%token TOK_GeneralString
144%token TOK_GraphicString
145%token TOK_IA5String
146%token TOK_IDENTIFIER
147%token TOK_IMPLICIT
148%token TOK_IMPLIED
149%token TOK_IMPORTS
150%token TOK_INCLUDES
151%token TOK_INSTANCE
vlm9283dbe2004-08-18 04:59:12 +0000152%token TOK_INSTRUCTIONS
vlmfa67ddc2004-06-03 03:38:44 +0000153%token TOK_INTEGER
154%token TOK_ISO646String
155%token TOK_MAX
156%token TOK_MIN
157%token TOK_MINUS_INFINITY
158%token TOK_NULL
159%token TOK_NumericString
160%token TOK_OBJECT
161%token TOK_ObjectDescriptor
162%token TOK_OCTET
163%token TOK_OF
164%token TOK_OPTIONAL
165%token TOK_PATTERN
166%token TOK_PDV
167%token TOK_PLUS_INFINITY
168%token TOK_PRESENT
169%token TOK_PrintableString
170%token TOK_PRIVATE
171%token TOK_REAL
172%token TOK_RELATIVE_OID
173%token TOK_SEQUENCE
174%token TOK_SET
175%token TOK_SIZE
176%token TOK_STRING
177%token TOK_SYNTAX
178%token TOK_T61String
179%token TOK_TAGS
180%token TOK_TeletexString
181%token TOK_TRUE
182%token TOK_TYPE_IDENTIFIER
183%token TOK_UNIQUE
184%token TOK_UNIVERSAL
185%token TOK_UniversalString
186%token TOK_UTCTime
187%token TOK_UTF8String
188%token TOK_VideotexString
189%token TOK_VisibleString
190%token TOK_WITH
191
vlmfa67ddc2004-06-03 03:38:44 +0000192%left TOK_EXCEPT
vlm9283dbe2004-08-18 04:59:12 +0000193%left '^' TOK_INTERSECTION
194%left '|' TOK_UNION
vlmfa67ddc2004-06-03 03:38:44 +0000195
196/* Misc tags */
197%token TOK_TwoDots /* .. */
198%token TOK_ThreeDots /* ... */
199%token <a_tag> TOK_tag /* [0] */
200
201
202/*
203 * Types defined herein.
204 */
205%type <a_grammar> ModuleList
206%type <a_module> ModuleSpecification
207%type <a_module> ModuleSpecificationBody
208%type <a_module> ModuleSpecificationElement
209%type <a_module> optModuleSpecificationBody /* Optional */
210%type <a_module_flags> optModuleSpecificationFlags
211%type <a_module_flags> ModuleSpecificationFlags /* Set of FL */
212%type <a_module_flags> ModuleSpecificationFlag /* Single FL */
213%type <a_module> ImportsDefinition
214%type <a_module> ImportsBundleSet
215%type <a_xports> ImportsBundle
216%type <a_xports> ImportsList
217%type <a_xports> ExportsDefinition
218%type <a_xports> ExportsBody
219%type <a_expr> ImportsElement
220%type <a_expr> ExportsElement
vlmfa67ddc2004-06-03 03:38:44 +0000221%type <a_expr> ExtensionAndException
vlmec8f6812004-08-22 03:19:54 +0000222%type <a_expr> TypeDeclaration
vlmfa67ddc2004-06-03 03:38:44 +0000223%type <a_ref> ComplexTypeReference
224%type <a_ref> ComplexTypeReferenceAmpList
225%type <a_refcomp> ComplexTypeReferenceElement
226%type <a_refcomp> ClassFieldIdentifier
227%type <a_refcomp> ClassFieldName
228%type <a_expr> ClassFieldList
229%type <a_expr> ClassField
230%type <a_expr> ClassDeclaration
vlmec8f6812004-08-22 03:19:54 +0000231%type <a_expr> Type
vlmfa67ddc2004-06-03 03:38:44 +0000232%type <a_expr> DataTypeReference /* Type1 ::= Type2 */
233%type <a_expr> DefinedTypeRef
234%type <a_expr> ValueSetDefinition /* Val INTEGER ::= {1|2} */
235%type <a_expr> ValueDefinition /* val INTEGER ::= 1*/
vlm39e5ed72004-09-05 10:40:41 +0000236%type <a_expr> optValueSetBody
237%type <a_expr> ValueSetBody
238%type <a_expr> ValueSetElement
vlmc94e28f2004-09-15 11:59:51 +0000239%type <a_value> Value
vlmfa67ddc2004-06-03 03:38:44 +0000240%type <a_value> DefinedValue
241%type <a_value> SignedNumber
vlmec8f6812004-08-22 03:19:54 +0000242%type <a_expr> ComponentTypeLists
243%type <a_expr> ComponentType
244%type <a_expr> AlternativeTypeLists
245%type <a_expr> AlternativeType
vlmfa67ddc2004-06-03 03:38:44 +0000246//%type <a_expr> optUniverationDefinition
247%type <a_expr> UniverationDefinition
248%type <a_expr> UniverationList
249%type <a_expr> UniverationElement
250%type <tv_str> TypeRefName
251%type <tv_str> ObjectClassReference
vlmfa67ddc2004-06-03 03:38:44 +0000252%type <tv_str> Identifier
253%type <a_parg> ParameterArgumentName
254%type <a_plist> ParameterArgumentList
255%type <a_expr> ActualParameter
256%type <a_expr> ActualParameterList
257%type <a_oid> ObjectIdentifier /* OID */
258%type <a_oid> optObjectIdentifier /* Optional OID */
259%type <a_oid> ObjectIdentifierBody
260%type <a_oid_arc> ObjectIdentifierElement
261%type <a_expr> BasicType
262%type <a_type> BasicTypeId
263%type <a_type> BasicTypeId_UniverationCompatible
264%type <a_type> BasicString
265%type <tv_opaque> Opaque
266//%type <tv_opaque> StringValue
267%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
268%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
269%type <a_constr> optConstraints
vlm5f0128b2004-08-20 13:25:29 +0000270%type <a_constr> Constraints
vlm9283dbe2004-08-18 04:59:12 +0000271%type <a_constr> SetOfConstraints
272%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
273%type <a_constr> ElementSetSpec /* 1..2,...,3 */
vlmfa67ddc2004-06-03 03:38:44 +0000274%type <a_constr> ConstraintSubtypeElement /* 1..2 */
vlmfa67ddc2004-06-03 03:38:44 +0000275%type <a_constr> SimpleTableConstraint
276%type <a_constr> TableConstraint
277%type <a_constr> WithComponents
278%type <a_constr> WithComponentsList
279%type <a_constr> WithComponentsElement
280%type <a_constr> ComponentRelationConstraint
281%type <a_constr> AtNotationList
282%type <a_ref> AtNotationElement
283%type <a_value> ConstraintValue
284%type <a_ctype> ConstraintSpec
285%type <a_ctype> ConstraintRangeSpec
286%type <a_wsynt> optWithSyntax
287%type <a_wsynt> WithSyntax
288%type <a_wsynt> WithSyntaxFormat
289%type <a_wchunk> WithSyntaxFormatToken
290%type <a_marker> optMarker Marker
291%type <a_int> optUnique
292%type <a_pres> optPresenceConstraint PresenceConstraint
293%type <tv_str> ComponentIdList
294
295
296%%
297
298
299ParsedGrammar:
300 ModuleList {
301 *(void **)param = $1;
302 }
303 ;
304
305ModuleList:
306 ModuleSpecification {
307 $$ = asn1p_new();
308 checkmem($$);
309 TQ_ADD(&($$->modules), $1, mod_next);
310 }
311 | ModuleList ModuleSpecification {
312 $$ = $1;
313 TQ_ADD(&($$->modules), $2, mod_next);
314 }
315 ;
316
317/*
318 * ASN module definition.
319 * === EXAMPLE ===
320 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
321 * BEGIN
322 * ...
323 * END
324 * === EOF ===
325 */
326
327ModuleSpecification:
328 TypeRefName optObjectIdentifier TOK_DEFINITIONS
329 optModuleSpecificationFlags
330 TOK_PPEQ TOK_BEGIN
331 optModuleSpecificationBody
332 TOK_END {
333
334 if($7) {
335 $$ = $7;
336 } else {
337 /* There's a chance that a module is just plain empty */
338 $$ = asn1p_module_new();
339 }
340 checkmem($$);
341
342 $$->Identifier = $1;
343 $$->module_oid = $2;
344 $$->module_flags = $4;
345 }
346 ;
347
348/*
349 * Object Identifier Definition
350 * { iso member-body(2) 3 }
351 */
352optObjectIdentifier:
353 { $$ = 0; }
354 | ObjectIdentifier { $$ = $1; }
355 ;
356
357ObjectIdentifier:
358 '{' ObjectIdentifierBody '}' {
359 $$ = $2;
360 }
361 | '{' '}' {
362 $$ = 0;
363 }
364 ;
365
366ObjectIdentifierBody:
367 ObjectIdentifierElement {
368 $$ = asn1p_oid_new();
369 asn1p_oid_add_arc($$, &$1);
370 if($1.name)
371 free($1.name);
372 }
373 | ObjectIdentifierBody ObjectIdentifierElement {
374 $$ = $1;
375 asn1p_oid_add_arc($$, &$2);
376 if($2.name)
377 free($2.name);
378 }
379 ;
380
381ObjectIdentifierElement:
382 Identifier { /* iso */
383 $$.name = $1;
384 $$.number = -1;
385 }
386 | Identifier '(' TOK_number ')' { /* iso(1) */
387 $$.name = $1;
388 $$.number = $3;
389 }
390 | TOK_number { /* 1 */
391 $$.name = 0;
392 $$.number = $1;
393 }
394 ;
395
396/*
397 * Optional module flags.
398 */
399optModuleSpecificationFlags:
400 { $$ = MSF_NOFLAGS; }
401 | ModuleSpecificationFlags {
402 $$ = $1;
403 }
404 ;
405
406/*
407 * Module flags.
408 */
409ModuleSpecificationFlags:
410 ModuleSpecificationFlag {
411 $$ = $1;
412 }
413 | ModuleSpecificationFlags ModuleSpecificationFlag {
414 $$ = $1 | $2;
415 }
416 ;
417
418/*
419 * Single module flag.
420 */
421ModuleSpecificationFlag:
422 TOK_EXPLICIT TOK_TAGS {
423 $$ = MSF_EXPLICIT_TAGS;
424 }
425 | TOK_IMPLICIT TOK_TAGS {
426 $$ = MSF_IMPLICIT_TAGS;
427 }
428 | TOK_AUTOMATIC TOK_TAGS {
429 $$ = MSF_AUTOMATIC_TAGS;
430 }
431 | TOK_EXTENSIBILITY TOK_IMPLIED {
432 $$ = MSF_EXTENSIBILITY_IMPLIED;
433 }
vlm9283dbe2004-08-18 04:59:12 +0000434 /* EncodingReferenceDefault */
435 | TOK_capitalreference TOK_INSTRUCTIONS {
436 /* X.680Amd1 specifies TAG and XER */
437 if(strcmp($1, "TAG") == 0) {
438 $$ = MSF_TAG_INSTRUCTIONS;
439 } else if(strcmp($1, "XER") == 0) {
440 $$ = MSF_XER_INSTRUCTIONS;
441 } else {
442 fprintf(stderr,
443 "WARNING: %s INSTRUCTIONS at line %d: "
444 "Unrecognized encoding reference\n",
445 $1, yylineno);
446 $$ = MSF_unk_INSTRUCTIONS;
447 }
448 free($1);
449 }
vlmfa67ddc2004-06-03 03:38:44 +0000450 ;
451
452/*
453 * Optional module body.
454 */
455optModuleSpecificationBody:
456 { $$ = 0; }
457 | ModuleSpecificationBody {
vlmfa67ddc2004-06-03 03:38:44 +0000458 $$ = $1;
459 }
460 ;
461
462/*
463 * ASN.1 Module body.
464 */
465ModuleSpecificationBody:
466 ModuleSpecificationElement {
467 $$ = $1;
468 }
469 | ModuleSpecificationBody ModuleSpecificationElement {
470 $$ = $1;
471
vlm9283dbe2004-08-18 04:59:12 +0000472 /* Behave well when one of them is skipped. */
473 if(!($1)) {
474 if($2) $$ = $2;
475 break;
476 }
477
vlmfa67ddc2004-06-03 03:38:44 +0000478#ifdef MY_IMPORT
479#error MY_IMPORT DEFINED ELSEWHERE!
480#endif
481#define MY_IMPORT(foo,field) do { \
vlm97ed7152004-08-13 12:31:09 +0000482 while(TQ_FIRST(&($2->foo))) { \
vlmfa67ddc2004-06-03 03:38:44 +0000483 TQ_ADD(&($$->foo), \
484 TQ_REMOVE(&($2->foo), field), \
485 field); \
vlm97ed7152004-08-13 12:31:09 +0000486 } \
487 assert(TQ_FIRST(&($2->foo)) == 0); \
488 } while(0)
vlmfa67ddc2004-06-03 03:38:44 +0000489
490 MY_IMPORT(imports, xp_next);
491 MY_IMPORT(exports, xp_next);
492 MY_IMPORT(members, next);
493#undef MY_IMPORT
494
495 }
496 ;
497
498/*
499 * One of the elements of ASN.1 module specification.
500 */
501ModuleSpecificationElement:
502 ImportsDefinition {
503 $$ = $1;
504 }
505 | ExportsDefinition {
506 $$ = asn1p_module_new();
507 checkmem($$);
508 if($1) {
509 TQ_ADD(&($$->exports), $1, xp_next);
510 } else {
511 /* "EXPORTS ALL;" ? */
512 }
513 }
514 | DataTypeReference {
515 $$ = asn1p_module_new();
516 checkmem($$);
517 assert($1->expr_type != A1TC_INVALID);
518 assert($1->meta_type != AMT_INVALID);
519 TQ_ADD(&($$->members), $1, next);
520 }
521 | ValueDefinition {
522 $$ = asn1p_module_new();
523 checkmem($$);
524 assert($1->expr_type != A1TC_INVALID);
525 assert($1->meta_type != AMT_INVALID);
526 TQ_ADD(&($$->members), $1, next);
527 }
528 /*
529 * Value set definition
530 * === EXAMPLE ===
531 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
532 * === EOF ===
533 */
534 | ValueSetDefinition {
535 $$ = asn1p_module_new();
536 checkmem($$);
537 assert($1->expr_type != A1TC_INVALID);
538 assert($1->meta_type != AMT_INVALID);
539 TQ_ADD(&($$->members), $1, next);
540 }
vlm9283dbe2004-08-18 04:59:12 +0000541 | TOK_ENCODING_CONTROL TOK_capitalreference
542 { asn1p_lexer_hack_push_encoding_control(); }
543 {
544 fprintf(stderr,
545 "WARNING: ENCODING-CONTROL %s "
546 "specification at line %d ignored\n",
547 $2, yylineno);
548 free($2);
549 $$ = 0;
550 }
vlmfa67ddc2004-06-03 03:38:44 +0000551
552 /*
553 * Erroneous attemps
554 */
555 | BasicString {
556 return yyerror(
557 "Attempt to redefine a standard basic type, "
558 "use -ftypesXY to switch back "
559 "to older version of ASN.1 standard");
560 }
561 ;
562
563/*
564 * === EXAMPLE ===
565 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
566 * === EOF ===
567 */
568ImportsDefinition:
569 TOK_IMPORTS ImportsBundleSet ';' {
570 $$ = $2;
571 }
572 /*
573 * Some error cases.
574 */
575 | TOK_IMPORTS TOK_FROM /* ... */ {
576 return yyerror("Empty IMPORTS list");
577 }
578 ;
579
580ImportsBundleSet:
581 ImportsBundle {
582 $$ = asn1p_module_new();
583 checkmem($$);
584 TQ_ADD(&($$->imports), $1, xp_next);
585 }
586 | ImportsBundleSet ImportsBundle {
587 $$ = $1;
588 TQ_ADD(&($$->imports), $2, xp_next);
589 }
590 ;
591
592ImportsBundle:
593 ImportsList TOK_FROM TypeRefName optObjectIdentifier {
594 $$ = $1;
595 $$->from = $3;
596 $$->from_oid = $4;
597 checkmem($$);
598 }
599 ;
600
601ImportsList:
602 ImportsElement {
603 $$ = asn1p_xports_new();
604 checkmem($$);
605 TQ_ADD(&($$->members), $1, next);
606 }
607 | ImportsList ',' ImportsElement {
608 $$ = $1;
609 TQ_ADD(&($$->members), $3, next);
610 }
611 ;
612
613ImportsElement:
614 TypeRefName {
615 $$ = asn1p_expr_new(yylineno);
616 checkmem($$);
617 $$->Identifier = $1;
618 $$->expr_type = A1TC_REFERENCE;
619 }
620 | Identifier {
621 $$ = asn1p_expr_new(yylineno);
622 checkmem($$);
623 $$->Identifier = $1;
624 $$->expr_type = A1TC_REFERENCE;
625 }
626 ;
627
628ExportsDefinition:
629 TOK_EXPORTS ExportsBody ';' {
630 $$ = $2;
631 }
632 | TOK_EXPORTS TOK_ALL ';' {
633 $$ = 0;
634 }
635 | TOK_EXPORTS ';' {
636 /* Empty EXPORTS clause effectively prohibits export. */
637 $$ = asn1p_xports_new();
638 checkmem($$);
639 }
640 ;
641
642ExportsBody:
643 ExportsElement {
644 $$ = asn1p_xports_new();
645 assert($$);
646 TQ_ADD(&($$->members), $1, next);
647 }
648 | ExportsBody ',' ExportsElement {
649 $$ = $1;
650 TQ_ADD(&($$->members), $3, next);
651 }
652 ;
653
654ExportsElement:
655 TypeRefName {
656 $$ = asn1p_expr_new(yylineno);
657 checkmem($$);
658 $$->Identifier = $1;
659 $$->expr_type = A1TC_EXPORTVAR;
660 }
661 | Identifier {
662 $$ = asn1p_expr_new(yylineno);
663 checkmem($$);
664 $$->Identifier = $1;
665 $$->expr_type = A1TC_EXPORTVAR;
666 }
667 ;
668
669
670ValueSetDefinition:
671 TypeRefName DefinedTypeRef TOK_PPEQ '{' optValueSetBody '}' {
672 $$ = $2;
673 assert($$->Identifier == 0);
674 $$->Identifier = $1;
675 $$->meta_type = AMT_VALUESET;
676 // take care of optValueSetBody
677 }
678 ;
679
680DefinedTypeRef:
681 ComplexTypeReference {
682 $$ = asn1p_expr_new(yylineno);
683 checkmem($$);
684 $$->reference = $1;
685 $$->expr_type = A1TC_REFERENCE;
686 $$->meta_type = AMT_TYPEREF;
687 }
688 | BasicTypeId {
689 $$ = asn1p_expr_new(yylineno);
690 checkmem($$);
691 $$->expr_type = $1;
692 $$->meta_type = AMT_TYPE;
693 }
694 ;
695
696optValueSetBody:
697 { }
vlm39e5ed72004-09-05 10:40:41 +0000698 | ValueSetBody {
699 }
700 ;
701
702/*
703 * X.680 does not permit ElementSetSpecs starting with ellipsis,
704 * i.e. (..., A, B). This is very strange: the ElementSetSpecs is used
705 * inside ValueSet, and ValueSets "in the wild" tend to have the first
706 * ellipsis.
707 */
708ValueSetBody:
709 ValueSetElement {
710 }
711 | ValueSetBody ',' ValueSetElement {
712 }
713 ;
714
715ValueSetElement:
716 TOK_ThreeDots {
717 }
718 | ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +0000719 }
720 ;
721
722
723/*
724 * Data Type Reference.
725 * === EXAMPLE ===
726 * Type3 ::= CHOICE { a Type1, b Type 2 }
727 * === EOF ===
728 */
729
730DataTypeReference:
731 /*
732 * Optionally tagged type definition.
733 */
734 TypeRefName TOK_PPEQ optTag TOK_TYPE_IDENTIFIER {
735 $$ = asn1p_expr_new(yylineno);
736 checkmem($$);
737 $$->Identifier = $1;
738 $$->tag = $3;
739 $$->expr_type = A1TC_TYPEID;
740 $$->meta_type = AMT_TYPE;
741 }
vlmfce48a42004-09-14 02:36:39 +0000742 | TypeRefName TOK_PPEQ Type {
743 $$ = $3;
vlmfa67ddc2004-06-03 03:38:44 +0000744 $$->Identifier = $1;
vlmfa67ddc2004-06-03 03:38:44 +0000745 assert($$->expr_type);
746 assert($$->meta_type);
747 }
748 | TypeRefName TOK_PPEQ ClassDeclaration {
749 $$ = $3;
750 $$->Identifier = $1;
751 assert($$->expr_type == A1TC_CLASSDEF);
752 assert($$->meta_type == AMT_OBJECT);
753 }
754 /*
755 * Parametrized <Type> declaration:
756 * === EXAMPLE ===
757 * SIGNED { ToBeSigned } ::= SEQUENCE {
758 * toBeSigned ToBeSigned,
759 * algorithm AlgorithmIdentifier,
760 * signature BIT STRING
761 * }
762 * === EOF ===
763 */
vlmec8f6812004-08-22 03:19:54 +0000764 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
vlmfa67ddc2004-06-03 03:38:44 +0000765 $$ = $6;
766 assert($$->Identifier == 0);
767 $$->Identifier = $1;
768 $$->params = $3;
769 $$->meta_type = AMT_PARAMTYPE;
770 }
771 ;
772
773ParameterArgumentList:
774 ParameterArgumentName {
775 int ret;
776 $$ = asn1p_paramlist_new(yylineno);
777 checkmem($$);
778 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
779 checkmem(ret == 0);
780 if($1.governor) asn1p_ref_free($1.governor);
781 if($1.argument) free($1.argument);
782 }
783 | ParameterArgumentList ',' ParameterArgumentName {
784 int ret;
785 $$ = $1;
786 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
787 checkmem(ret == 0);
788 if($3.governor) asn1p_ref_free($3.governor);
789 if($3.argument) free($3.argument);
790 }
791 ;
792
793ParameterArgumentName:
794 TypeRefName {
795 $$.governor = NULL;
796 $$.argument = $1;
797 }
798 | TypeRefName ':' Identifier {
799 int ret;
800 $$.governor = asn1p_ref_new(yylineno);
801 ret = asn1p_ref_add_component($$.governor, $1, 0);
802 checkmem(ret == 0);
803 $$.argument = $3;
804 }
805 | BasicTypeId ':' Identifier {
806 int ret;
807 $$.governor = asn1p_ref_new(yylineno);
808 ret = asn1p_ref_add_component($$.governor,
809 ASN_EXPR_TYPE2STR($1), 1);
810 checkmem(ret == 0);
811 $$.argument = $3;
812 }
813 ;
814
815ActualParameterList:
816 ActualParameter {
817 $$ = asn1p_expr_new(yylineno);
818 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000819 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000820 }
821 | ActualParameterList ',' ActualParameter {
822 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000823 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000824 }
825 ;
826
827ActualParameter:
vlmec8f6812004-08-22 03:19:54 +0000828 Type {
vlmfa67ddc2004-06-03 03:38:44 +0000829 $$ = $1;
830 }
831 | Identifier {
832 $$ = asn1p_expr_new(yylineno);
833 checkmem($$);
834 $$->Identifier = $1;
835 $$->expr_type = A1TC_REFERENCE;
836 $$->meta_type = AMT_VALUE;
837 }
838 ;
839
840/*
841 * A collection of constructed data type members.
842 */
vlmec8f6812004-08-22 03:19:54 +0000843ComponentTypeLists:
844 ComponentType {
vlmfa67ddc2004-06-03 03:38:44 +0000845 $$ = asn1p_expr_new(yylineno);
846 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000847 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000848 }
vlmec8f6812004-08-22 03:19:54 +0000849 | ComponentTypeLists ',' ComponentType {
vlmfa67ddc2004-06-03 03:38:44 +0000850 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000851 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000852 }
853 ;
854
vlmec8f6812004-08-22 03:19:54 +0000855ComponentType:
vlmfce48a42004-09-14 02:36:39 +0000856 Identifier Type optMarker {
vlmec8f6812004-08-22 03:19:54 +0000857 $$ = $2;
858 assert($$->Identifier == 0);
vlmfce48a42004-09-14 02:36:39 +0000859 $$->Identifier = $1;
vlmec8f6812004-08-22 03:19:54 +0000860 $$->marker = $3;
861 }
862 | TOK_COMPONENTS TOK_OF Type {
863 $$ = asn1p_expr_new(yylineno);
864 checkmem($$);
865 $$->meta_type = $3->meta_type;
866 $$->expr_type = A1TC_COMPONENTS_OF;
vlm6a02a8a2004-09-08 00:28:11 +0000867 asn1p_expr_add($$, $3);
vlmec8f6812004-08-22 03:19:54 +0000868 }
869 | ExtensionAndException {
870 $$ = $1;
871 }
872 ;
873
874AlternativeTypeLists:
875 AlternativeType {
876 $$ = asn1p_expr_new(yylineno);
877 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000878 asn1p_expr_add($$, $1);
vlmec8f6812004-08-22 03:19:54 +0000879 }
880 | AlternativeTypeLists ',' AlternativeType {
881 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000882 asn1p_expr_add($$, $3);
vlmec8f6812004-08-22 03:19:54 +0000883 }
884 ;
885
886AlternativeType:
vlmfce48a42004-09-14 02:36:39 +0000887 Identifier Type {
vlmec8f6812004-08-22 03:19:54 +0000888 $$ = $2;
889 assert($$->Identifier == 0);
vlmfce48a42004-09-14 02:36:39 +0000890 $$->Identifier = $1;
vlmec8f6812004-08-22 03:19:54 +0000891 }
892 | ExtensionAndException {
893 $$ = $1;
894 }
895 ;
896
vlmfa67ddc2004-06-03 03:38:44 +0000897ClassDeclaration:
898 TOK_CLASS '{' ClassFieldList '}' optWithSyntax {
899 $$ = $3;
900 checkmem($$);
901 $$->with_syntax = $5;
902 assert($$->expr_type == A1TC_CLASSDEF);
903 assert($$->meta_type == AMT_OBJECT);
904 }
905 ;
906
907optUnique:
908 { $$ = 0; }
909 | TOK_UNIQUE { $$ = 1; }
910 ;
911
912ClassFieldList:
913 ClassField {
914 $$ = asn1p_expr_new(yylineno);
915 checkmem($$);
916 $$->expr_type = A1TC_CLASSDEF;
917 $$->meta_type = AMT_OBJECT;
vlm6a02a8a2004-09-08 00:28:11 +0000918 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000919 }
920 | ClassFieldList ',' ClassField {
921 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000922 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000923 }
924 ;
925
926ClassField:
927 ClassFieldIdentifier optMarker {
928 $$ = asn1p_expr_new(yylineno);
929 checkmem($$);
930 $$->Identifier = $1.name;
931 $$->expr_type = A1TC_CLASSFIELD;
932 $$->meta_type = AMT_OBJECTFIELD;
933 $$->marker = $2;
934 }
vlmec8f6812004-08-22 03:19:54 +0000935 | ClassFieldIdentifier Type optMarker optUnique {
vlmfa67ddc2004-06-03 03:38:44 +0000936 $$ = $2;
937 $$->Identifier = $1.name;
vlmec8f6812004-08-22 03:19:54 +0000938 $$->marker = $3;
939 $$->unique = $4;
vlmfa67ddc2004-06-03 03:38:44 +0000940 }
941 | ClassFieldIdentifier ClassFieldIdentifier optMarker optUnique {
942 int ret;
943 $$ = asn1p_expr_new(yylineno);
944 checkmem($$);
945 $$->Identifier = $1.name;
946 $$->reference = asn1p_ref_new(yylineno);
947 checkmem($$->reference);
948 ret = asn1p_ref_add_component($$->reference,
949 $2.name, $2.lex_type);
950 checkmem(ret == 0);
951 $$->expr_type = A1TC_CLASSFIELD;
952 $$->meta_type = AMT_OBJECTFIELD;
953 $$->marker = $3;
954 $$->unique = $4;
955 }
956 ;
957
958optWithSyntax:
959 { $$ = 0; }
960 | WithSyntax {
961 $$ = $1;
962 }
963 ;
964
965WithSyntax:
966 TOK_WITH TOK_SYNTAX '{'
967 { asn1p_lexer_hack_enable_with_syntax(); }
968 WithSyntaxFormat
969 '}' {
970 $$ = $5;
971 }
972 ;
973
974WithSyntaxFormat:
975 WithSyntaxFormatToken {
976 $$ = asn1p_wsyntx_new();
977 TQ_ADD(&($$->chunks), $1, next);
978 }
979 | WithSyntaxFormat WithSyntaxFormatToken {
980 $$ = $1;
981 TQ_ADD(&($$->chunks), $2, next);
982 }
983 ;
984
985WithSyntaxFormatToken:
986 TOK_opaque {
987 $$ = asn1p_wsyntx_chunk_frombuf($1.buf, $1.len, 0);
988 }
989 | ClassFieldIdentifier {
990 asn1p_ref_t *ref;
991 int ret;
992 ref = asn1p_ref_new(yylineno);
993 checkmem(ref);
994 ret = asn1p_ref_add_component(ref, $1.name, $1.lex_type);
995 checkmem(ret == 0);
996 $$ = asn1p_wsyntx_chunk_fromref(ref, 0);
997 }
998 ;
999
vlmfa67ddc2004-06-03 03:38:44 +00001000ExtensionAndException:
1001 TOK_ThreeDots {
vlm39e5ed72004-09-05 10:40:41 +00001002 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001003 checkmem($$);
1004 $$->Identifier = strdup("...");
1005 checkmem($$->Identifier);
1006 $$->expr_type = A1TC_EXTENSIBLE;
1007 $$->meta_type = AMT_TYPE;
1008 }
1009 | TOK_ThreeDots '!' DefinedValue {
vlm39e5ed72004-09-05 10:40:41 +00001010 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001011 checkmem($$);
1012 $$->Identifier = strdup("...");
1013 checkmem($$->Identifier);
1014 $$->value = $3;
1015 $$->expr_type = A1TC_EXTENSIBLE;
1016 $$->meta_type = AMT_TYPE;
1017 }
1018 | TOK_ThreeDots '!' SignedNumber {
vlm39e5ed72004-09-05 10:40:41 +00001019 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001020 checkmem($$);
1021 $$->Identifier = strdup("...");
1022 $$->value = $3;
1023 checkmem($$->Identifier);
1024 $$->expr_type = A1TC_EXTENSIBLE;
1025 $$->meta_type = AMT_TYPE;
1026 }
1027 ;
1028
vlmec8f6812004-08-22 03:19:54 +00001029Type:
vlmfce48a42004-09-14 02:36:39 +00001030 optTag TypeDeclaration optConstraints {
1031 $$ = $2;
1032 $$->tag = $1;
vlmec8f6812004-08-22 03:19:54 +00001033 /*
1034 * Outer constraint for SEQUENCE OF and SET OF applies
1035 * to the inner type.
1036 */
1037 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1038 || $$->expr_type == ASN_CONSTR_SET_OF) {
1039 assert(!TQ_FIRST(&($$->members))->constraints);
vlmfce48a42004-09-14 02:36:39 +00001040 TQ_FIRST(&($$->members))->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001041 } else {
1042 if($$->constraints) {
1043 assert(!$2);
1044 } else {
vlmfce48a42004-09-14 02:36:39 +00001045 $$->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001046 }
1047 }
1048 }
1049 ;
1050
1051TypeDeclaration:
vlmfa67ddc2004-06-03 03:38:44 +00001052 BasicType {
1053 $$ = $1;
1054 }
1055 | BasicString {
1056 $$ = asn1p_expr_new(yylineno);
1057 checkmem($$);
1058 $$->expr_type = $1;
1059 $$->meta_type = AMT_TYPE;
1060 }
vlmec8f6812004-08-22 03:19:54 +00001061 | TOK_CHOICE '{' AlternativeTypeLists '}' {
1062 $$ = $3;
1063 assert($$->expr_type == A1TC_INVALID);
1064 $$->expr_type = ASN_CONSTR_CHOICE;
1065 $$->meta_type = AMT_TYPE;
vlmfa67ddc2004-06-03 03:38:44 +00001066 }
vlmec8f6812004-08-22 03:19:54 +00001067 | TOK_SEQUENCE '{' ComponentTypeLists '}' {
1068 $$ = $3;
1069 assert($$->expr_type == A1TC_INVALID);
1070 $$->expr_type = ASN_CONSTR_SEQUENCE;
1071 $$->meta_type = AMT_TYPE;
1072 }
1073 | TOK_SET '{' ComponentTypeLists '}' {
1074 $$ = $3;
1075 assert($$->expr_type == A1TC_INVALID);
1076 $$->expr_type = ASN_CONSTR_SET;
1077 $$->meta_type = AMT_TYPE;
1078 }
vlma2374a02004-09-14 02:44:07 +00001079 | TOK_SEQUENCE optConstraints TOK_OF optTag TypeDeclaration {
vlm39e5ed72004-09-05 10:40:41 +00001080 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001081 checkmem($$);
1082 $$->constraints = $2;
1083 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1084 $$->meta_type = AMT_TYPE;
vlma2374a02004-09-14 02:44:07 +00001085 $5->tag = $4;
1086 asn1p_expr_add($$, $5);
vlmec8f6812004-08-22 03:19:54 +00001087 }
vlma2374a02004-09-14 02:44:07 +00001088 | TOK_SET optConstraints TOK_OF optTag TypeDeclaration {
vlm39e5ed72004-09-05 10:40:41 +00001089 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001090 checkmem($$);
1091 $$->constraints = $2;
1092 $$->expr_type = ASN_CONSTR_SET_OF;
1093 $$->meta_type = AMT_TYPE;
vlma2374a02004-09-14 02:44:07 +00001094 $5->tag = $4;
1095 asn1p_expr_add($$, $5);
vlmec8f6812004-08-22 03:19:54 +00001096 }
1097 | TOK_ANY {
vlm39e5ed72004-09-05 10:40:41 +00001098 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001099 checkmem($$);
vlm044f7442004-09-04 04:49:21 +00001100 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001101 $$->meta_type = AMT_TYPE;
1102 }
1103 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1104 int ret;
vlm39e5ed72004-09-05 10:40:41 +00001105 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001106 checkmem($$);
1107 $$->reference = asn1p_ref_new(yylineno);
1108 ret = asn1p_ref_add_component($$->reference,
1109 $4, RLT_lowercase);
1110 checkmem(ret == 0);
vlm044f7442004-09-04 04:49:21 +00001111 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001112 $$->meta_type = AMT_TYPE;
1113 }
vlmfa67ddc2004-06-03 03:38:44 +00001114 /*
1115 * A parametrized assignment.
1116 */
1117 | TypeRefName '{' ActualParameterList '}' {
1118 int ret;
1119 $$ = $3;
1120 assert($$->expr_type == 0);
1121 assert($$->meta_type == 0);
1122 assert($$->reference == 0);
1123 $$->reference = asn1p_ref_new(yylineno);
1124 checkmem($$->reference);
1125 ret = asn1p_ref_add_component($$->reference, $1, RLT_UNKNOWN);
1126 checkmem(ret == 0);
1127 free($1);
1128 $$->expr_type = A1TC_PARAMETRIZED;
1129 $$->meta_type = AMT_TYPE;
1130 }
1131 /*
1132 * A DefinedType reference.
1133 * "CLASS1.&id.&id2"
1134 * or
1135 * "Module.Type"
1136 * or
1137 * "Module.identifier"
1138 * or
1139 * "Type"
1140 */
1141 | ComplexTypeReference {
1142 $$ = asn1p_expr_new(yylineno);
1143 checkmem($$);
1144 $$->reference = $1;
1145 $$->expr_type = A1TC_REFERENCE;
1146 $$->meta_type = AMT_TYPEREF;
1147 }
1148 | TOK_INSTANCE TOK_OF ComplexTypeReference {
1149 $$ = asn1p_expr_new(yylineno);
1150 checkmem($$);
1151 $$->reference = $3;
1152 $$->expr_type = A1TC_INSTANCE;
1153 $$->meta_type = AMT_TYPE;
1154 }
1155 ;
1156
1157/*
1158 * A type name consisting of several components.
1159 * === EXAMPLE ===
1160 * === EOF ===
1161 */
1162ComplexTypeReference:
1163 TOK_typereference {
1164 int ret;
1165 $$ = asn1p_ref_new(yylineno);
1166 checkmem($$);
1167 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1168 checkmem(ret == 0);
1169 free($1);
1170 }
1171 | TOK_typereference '.' TypeRefName {
1172 int ret;
1173 $$ = asn1p_ref_new(yylineno);
1174 checkmem($$);
1175 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1176 checkmem(ret == 0);
1177 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1178 checkmem(ret == 0);
1179 free($1);
1180 }
vlmc94e28f2004-09-15 11:59:51 +00001181 | ObjectClassReference '.' TypeRefName {
1182 int ret;
1183 $$ = asn1p_ref_new(yylineno);
1184 checkmem($$);
1185 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1186 checkmem(ret == 0);
1187 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1188 checkmem(ret == 0);
1189 free($1);
1190 }
vlmfa67ddc2004-06-03 03:38:44 +00001191 | TOK_typereference '.' Identifier {
1192 int ret;
1193 $$ = asn1p_ref_new(yylineno);
1194 checkmem($$);
1195 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1196 checkmem(ret == 0);
1197 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1198 checkmem(ret == 0);
1199 free($1);
1200 }
1201 | ObjectClassReference {
1202 int ret;
1203 $$ = asn1p_ref_new(yylineno);
1204 checkmem($$);
1205 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1206 free($1);
1207 checkmem(ret == 0);
1208 }
1209 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1210 int ret;
1211 $$ = $3;
1212 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1213 free($1);
1214 checkmem(ret == 0);
1215 /*
1216 * Move the last element infront.
1217 */
1218 {
1219 struct asn1p_ref_component_s tmp_comp;
1220 tmp_comp = $$->components[$$->comp_count-1];
1221 memmove(&$$->components[1],
1222 &$$->components[0],
1223 sizeof($$->components[0])
1224 * ($$->comp_count - 1));
1225 $$->components[0] = tmp_comp;
1226 }
1227 }
1228 ;
1229
1230ComplexTypeReferenceAmpList:
1231 ComplexTypeReferenceElement {
1232 int ret;
1233 $$ = asn1p_ref_new(yylineno);
1234 checkmem($$);
1235 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1236 free($1.name);
1237 checkmem(ret == 0);
1238 }
1239 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1240 int ret;
1241 $$ = $1;
1242 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1243 free($3.name);
1244 checkmem(ret == 0);
1245 }
1246 ;
1247
1248ComplexTypeReferenceElement: ClassFieldName;
1249ClassFieldIdentifier: ClassFieldName;
1250
1251ClassFieldName:
1252 /* "&Type1" */
1253 TOK_typefieldreference {
1254 $$.lex_type = RLT_AmpUppercase;
1255 $$.name = $1;
1256 }
1257 /* "&id" */
1258 | TOK_valuefieldreference {
1259 $$.lex_type = RLT_Amplowercase;
1260 $$.name = $1;
1261 }
1262 ;
1263
1264
1265/*
1266 * === EXAMPLE ===
1267 * value INTEGER ::= 1
1268 * === EOF ===
1269 */
1270ValueDefinition:
vlmc94e28f2004-09-15 11:59:51 +00001271 Identifier DefinedTypeRef TOK_PPEQ Value {
vlmfa67ddc2004-06-03 03:38:44 +00001272 $$ = $2;
1273 assert($$->Identifier == NULL);
1274 $$->Identifier = $1;
1275 $$->meta_type = AMT_VALUE;
1276 $$->value = $4;
1277 }
1278 ;
1279
vlmc94e28f2004-09-15 11:59:51 +00001280Value:
1281 Identifier ':' Value {
1282 $$ = asn1p_value_fromint(0);
1283 checkmem($$);
1284 $$->type = ATV_CHOICE_IDENTIFIER;
1285 $$->value.choice_identifier.identifier = $1;
1286 $$->value.choice_identifier.value = $3;
1287 }
1288 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
vlmfa67ddc2004-06-03 03:38:44 +00001289 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1290 checkmem($$);
1291 $$->type = ATV_UNPARSED;
1292 }
vlmc94e28f2004-09-15 11:59:51 +00001293 | TOK_NULL {
1294 $$ = asn1p_value_fromint(0);
1295 checkmem($$);
1296 $$->type = ATV_NULL;
1297 }
1298 | TOK_FALSE {
1299 $$ = asn1p_value_fromint(0);
1300 checkmem($$);
1301 $$->type = ATV_FALSE;
1302 }
1303 | TOK_TRUE {
1304 $$ = asn1p_value_fromint(0);
1305 checkmem($$);
1306 $$->type = ATV_TRUE;
1307 }
vlmfa67ddc2004-06-03 03:38:44 +00001308 | TOK_bstring {
1309 $$ = _convert_bitstring2binary($1, 'B');
1310 checkmem($$);
1311 }
1312 | TOK_hstring {
1313 $$ = _convert_bitstring2binary($1, 'H');
1314 checkmem($$);
1315 }
1316 | TOK_cstring {
1317 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1318 checkmem($$);
1319 }
1320 | SignedNumber {
1321 $$ = $1;
1322 }
1323 | DefinedValue {
1324 $$ = $1;
1325 }
1326 ;
1327
1328DefinedValue:
1329 Identifier {
1330 asn1p_ref_t *ref;
1331 int ret;
1332 ref = asn1p_ref_new(yylineno);
1333 checkmem(ref);
1334 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1335 checkmem(ret == 0);
1336 $$ = asn1p_value_fromref(ref, 0);
1337 checkmem($$);
1338 free($1);
1339 }
1340 | TypeRefName '.' Identifier {
1341 asn1p_ref_t *ref;
1342 int ret;
1343 ref = asn1p_ref_new(yylineno);
1344 checkmem(ref);
1345 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1346 checkmem(ret == 0);
1347 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1348 checkmem(ret == 0);
1349 $$ = asn1p_value_fromref(ref, 0);
1350 checkmem($$);
1351 free($1);
1352 free($3);
1353 }
1354 ;
1355
1356Opaque:
1357 TOK_opaque {
1358 $$.len = $1.len + 2;
1359 $$.buf = malloc($$.len + 1);
1360 checkmem($$.buf);
1361 $$.buf[0] = '{';
1362 $$.buf[1] = ' ';
1363 memcpy($$.buf + 2, $1.buf, $1.len);
1364 $$.buf[$$.len] = '\0';
1365 free($1.buf);
1366 }
1367 | Opaque TOK_opaque {
1368 int newsize = $1.len + $2.len;
1369 char *p = malloc(newsize + 1);
1370 checkmem(p);
1371 memcpy(p , $1.buf, $1.len);
1372 memcpy(p + $1.len, $2.buf, $2.len);
1373 p[newsize] = '\0';
1374 free($1.buf);
1375 free($2.buf);
1376 $$.buf = p;
1377 $$.len = newsize;
1378 }
1379 ;
1380
1381BasicTypeId:
1382 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1383 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1384 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1385 | BasicTypeId_UniverationCompatible { $$ = $1; }
1386 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1387 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1388 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1389 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1390 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1391 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1392 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1393 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
1394 ;
1395
1396/*
1397 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1398 */
1399BasicTypeId_UniverationCompatible:
1400 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1401 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1402 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1403 ;
1404
1405BasicType:
1406 BasicTypeId {
vlm39e5ed72004-09-05 10:40:41 +00001407 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001408 checkmem($$);
1409 $$->expr_type = $1;
1410 $$->meta_type = AMT_TYPE;
1411 }
1412 | BasicTypeId_UniverationCompatible UniverationDefinition {
1413 if($2) {
1414 $$ = $2;
1415 } else {
vlm39e5ed72004-09-05 10:40:41 +00001416 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001417 checkmem($$);
1418 }
1419 $$->expr_type = $1;
1420 $$->meta_type = AMT_TYPE;
1421 }
1422 ;
1423
1424BasicString:
1425 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1426 | TOK_GeneralString {
1427 $$ = ASN_STRING_GeneralString;
vlmc94e28f2004-09-15 11:59:51 +00001428 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001429 }
1430 | TOK_GraphicString {
1431 $$ = ASN_STRING_GraphicString;
vlmc94e28f2004-09-15 11:59:51 +00001432 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001433 }
1434 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1435 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1436 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1437 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1438 | TOK_T61String {
1439 $$ = ASN_STRING_T61String;
vlmc94e28f2004-09-15 11:59:51 +00001440 fprintf(stderr, "WARNING: T61String is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001441 }
1442 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1443 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1444 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1445 | TOK_VideotexString {
1446 $$ = ASN_STRING_VideotexString;
vlmc94e28f2004-09-15 11:59:51 +00001447 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001448 }
1449 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1450 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1451 ;
1452
vlm5f0128b2004-08-20 13:25:29 +00001453
vlmfa67ddc2004-06-03 03:38:44 +00001454/*
1455 * Data type constraints.
1456 */
vlmfa67ddc2004-06-03 03:38:44 +00001457Union: '|' | TOK_UNION;
1458Intersection: '^' | TOK_INTERSECTION;
1459Except: TOK_EXCEPT;
1460
vlm9283dbe2004-08-18 04:59:12 +00001461optConstraints:
1462 { $$ = 0; }
vlm5f0128b2004-08-20 13:25:29 +00001463 | Constraints {
1464 $$ = $1;
1465 }
1466 ;
1467
1468Constraints:
1469 SetOfConstraints {
vlm9283dbe2004-08-18 04:59:12 +00001470 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
1471 }
1472 | TOK_SIZE '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001473 /*
1474 * This is a special case, for compatibility purposes.
vlm9283dbe2004-08-18 04:59:12 +00001475 * It goes without parentheses.
vlmfa67ddc2004-06-03 03:38:44 +00001476 */
vlm5f0128b2004-08-20 13:25:29 +00001477 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001478 }
vlmfa67ddc2004-06-03 03:38:44 +00001479 ;
1480
vlm9283dbe2004-08-18 04:59:12 +00001481SetOfConstraints:
1482 '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001483 $$ = $2;
1484 }
vlm9283dbe2004-08-18 04:59:12 +00001485 | SetOfConstraints '(' ElementSetSpecs ')' {
1486 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
1487 }
vlmfa67ddc2004-06-03 03:38:44 +00001488 ;
1489
vlm9283dbe2004-08-18 04:59:12 +00001490ElementSetSpecs:
1491 ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001492 $$ = $1;
1493 }
vlm9283dbe2004-08-18 04:59:12 +00001494 | ElementSetSpec ',' TOK_ThreeDots {
vlmfa67ddc2004-06-03 03:38:44 +00001495 asn1p_constraint_t *ct;
1496 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001497 ct->type = ACT_EL_EXT;
1498 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
1499 }
vlm9283dbe2004-08-18 04:59:12 +00001500 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001501 asn1p_constraint_t *ct;
1502 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001503 ct->type = ACT_EL_EXT;
1504 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlm6f5eb0b2004-08-13 12:35:09 +00001505 ct = $$;
1506 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
vlmfa67ddc2004-06-03 03:38:44 +00001507 }
vlmfa67ddc2004-06-03 03:38:44 +00001508 ;
1509
vlm9283dbe2004-08-18 04:59:12 +00001510ElementSetSpec:
1511 ConstraintSubtypeElement {
1512 $$ = $1;
1513 }
1514 | ElementSetSpec Union ConstraintSubtypeElement {
vlmfa67ddc2004-06-03 03:38:44 +00001515 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
1516 }
vlm9283dbe2004-08-18 04:59:12 +00001517 | ElementSetSpec Intersection ConstraintSubtypeElement {
vlmfa67ddc2004-06-03 03:38:44 +00001518 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
1519 }
vlm9283dbe2004-08-18 04:59:12 +00001520 | ConstraintSubtypeElement Except ConstraintSubtypeElement {
vlmfa67ddc2004-06-03 03:38:44 +00001521 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
1522 }
1523 ;
1524
1525ConstraintSubtypeElement:
vlm9283dbe2004-08-18 04:59:12 +00001526 ConstraintSpec '(' ElementSetSpecs ')' {
1527 int ret;
1528 $$ = asn1p_constraint_new(yylineno);
1529 checkmem($$);
1530 $$->type = $1;
1531 ret = asn1p_constraint_insert($$, $3);
1532 checkmem(ret == 0);
1533 }
1534 | '(' ElementSetSpecs ')' {
1535 int ret;
1536 $$ = asn1p_constraint_new(yylineno);
1537 checkmem($$);
1538 $$->type = ACT_CA_SET;
1539 ret = asn1p_constraint_insert($$, $2);
1540 checkmem(ret == 0);
1541 }
1542 | ConstraintValue {
vlmfa67ddc2004-06-03 03:38:44 +00001543 $$ = asn1p_constraint_new(yylineno);
1544 checkmem($$);
1545 $$->type = ACT_EL_VALUE;
1546 $$->value = $1;
1547 }
1548 | ConstraintValue ConstraintRangeSpec ConstraintValue {
1549 $$ = asn1p_constraint_new(yylineno);
1550 checkmem($$);
1551 $$->type = $2;
1552 $$->range_start = $1;
1553 $$->range_stop = $3;
1554 }
vlm9283dbe2004-08-18 04:59:12 +00001555 | TOK_MIN ConstraintRangeSpec ConstraintValue {
vlmfa67ddc2004-06-03 03:38:44 +00001556 $$ = asn1p_constraint_new(yylineno);
1557 checkmem($$);
vlm9283dbe2004-08-18 04:59:12 +00001558 $$->type = $2;
1559 $$->range_start = asn1p_value_fromint(-123);
1560 $$->range_stop = $3;
1561 $$->range_start->type = ATV_MIN;
1562 }
1563 | ConstraintValue ConstraintRangeSpec TOK_MAX {
1564 $$ = asn1p_constraint_new(yylineno);
1565 checkmem($$);
1566 $$->type = $2;
1567 $$->range_start = $1;
1568 $$->range_stop = asn1p_value_fromint(321);
1569 $$->range_stop->type = ATV_MAX;
1570 }
1571 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1572 $$ = asn1p_constraint_new(yylineno);
1573 checkmem($$);
1574 $$->type = $2;
1575 $$->range_start = asn1p_value_fromint(-123);
1576 $$->range_stop = asn1p_value_fromint(321);
1577 $$->range_start->type = ATV_MIN;
1578 $$->range_stop->type = ATV_MAX;
vlmfa67ddc2004-06-03 03:38:44 +00001579 }
1580 | TableConstraint {
1581 $$ = $1;
1582 }
1583 | WithComponents {
1584 $$ = $1;
1585 }
1586 ;
1587
1588ConstraintRangeSpec:
1589 TOK_TwoDots { $$ = ACT_EL_RANGE; }
1590 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
1591 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
1592 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
1593 ;
1594
1595ConstraintSpec:
1596 TOK_SIZE {
1597 $$ = ACT_CT_SIZE;
1598 }
1599 | TOK_FROM {
1600 $$ = ACT_CT_FROM;
1601 }
1602 ;
1603
1604ConstraintValue:
1605 SignedNumber {
1606 $$ = $1;
1607 }
1608 | Identifier {
1609 asn1p_ref_t *ref;
1610 int ret;
1611 ref = asn1p_ref_new(yylineno);
1612 checkmem(ref);
1613 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1614 checkmem(ret == 0);
1615 $$ = asn1p_value_fromref(ref, 0);
1616 checkmem($$);
1617 free($1);
1618 }
1619 | TOK_cstring {
1620 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1621 checkmem($$);
1622 }
vlmfa67ddc2004-06-03 03:38:44 +00001623 | TOK_FALSE {
1624 $$ = asn1p_value_fromint(0);
1625 checkmem($$);
1626 $$->type = ATV_FALSE;
1627 }
1628 | TOK_TRUE {
1629 $$ = asn1p_value_fromint(1);
1630 checkmem($$);
1631 $$->type = ATV_TRUE;
1632 }
1633 ;
1634
1635WithComponents:
1636 TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
1637 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
1638 }
1639 ;
1640
1641WithComponentsList:
1642 WithComponentsElement {
1643 $$ = $1;
1644 }
1645 | WithComponentsList ',' WithComponentsElement {
1646 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
1647 }
1648 ;
1649
1650WithComponentsElement:
1651 TOK_ThreeDots {
1652 $$ = asn1p_constraint_new(yylineno);
1653 checkmem($$);
1654 $$->type = ACT_EL_EXT;
1655 }
1656 | Identifier optConstraints optPresenceConstraint {
1657 $$ = asn1p_constraint_new(yylineno);
1658 checkmem($$);
1659 $$->type = ACT_EL_VALUE;
1660 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1661 $$->presence = $3;
1662 }
1663 ;
1664
1665/*
1666 * presence constraint for WithComponents
1667 */
1668optPresenceConstraint:
1669 { $$ = ACPRES_DEFAULT; }
1670 | PresenceConstraint { $$ = $1; }
1671 ;
1672
1673PresenceConstraint:
1674 TOK_PRESENT {
1675 $$ = ACPRES_PRESENT;
1676 }
1677 | TOK_ABSENT {
1678 $$ = ACPRES_ABSENT;
1679 }
1680 | TOK_OPTIONAL {
1681 $$ = ACPRES_OPTIONAL;
1682 }
1683 ;
1684
1685TableConstraint:
1686 SimpleTableConstraint {
1687 $$ = $1;
1688 }
1689 | ComponentRelationConstraint {
1690 $$ = $1;
1691 }
1692 ;
1693
1694/*
1695 * "{ExtensionSet}"
1696 */
1697SimpleTableConstraint:
1698 '{' TypeRefName '}' {
1699 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
1700 asn1p_constraint_t *ct;
1701 int ret;
1702 ret = asn1p_ref_add_component(ref, $2, 0);
1703 checkmem(ret == 0);
1704 ct = asn1p_constraint_new(yylineno);
1705 checkmem($$);
1706 ct->type = ACT_EL_VALUE;
1707 ct->value = asn1p_value_fromref(ref, 0);
1708 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
1709 }
1710 ;
1711
1712ComponentRelationConstraint:
1713 SimpleTableConstraint '{' AtNotationList '}' {
1714 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
1715 }
1716 ;
1717
1718AtNotationList:
1719 AtNotationElement {
1720 $$ = asn1p_constraint_new(yylineno);
1721 checkmem($$);
1722 $$->type = ACT_EL_VALUE;
1723 $$->value = asn1p_value_fromref($1, 0);
1724 }
1725 | AtNotationList ',' AtNotationElement {
1726 asn1p_constraint_t *ct;
1727 ct = asn1p_constraint_new(yylineno);
1728 checkmem(ct);
1729 ct->type = ACT_EL_VALUE;
1730 ct->value = asn1p_value_fromref($3, 0);
1731 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
1732 }
1733 ;
1734
1735/*
1736 * @blah
1737 */
1738AtNotationElement:
1739 '@' ComponentIdList {
1740 char *p = malloc(strlen($2) + 2);
1741 int ret;
1742 *p = '@';
1743 strcpy(p + 1, $2);
1744 $$ = asn1p_ref_new(yylineno);
1745 ret = asn1p_ref_add_component($$, p, 0);
1746 checkmem(ret == 0);
1747 free(p);
1748 free($2);
1749 }
1750 | '@' '.' ComponentIdList {
1751 char *p = malloc(strlen($3) + 3);
1752 int ret;
1753 p[0] = '@';
1754 p[1] = '.';
1755 strcpy(p + 2, $3);
1756 $$ = asn1p_ref_new(yylineno);
1757 ret = asn1p_ref_add_component($$, p, 0);
1758 checkmem(ret == 0);
1759 free(p);
1760 free($3);
1761 }
1762 ;
1763
1764/* identifier "." ... */
1765ComponentIdList:
1766 Identifier {
1767 $$ = $1;
1768 }
1769 | ComponentIdList '.' Identifier {
1770 int l1 = strlen($1);
1771 int l3 = strlen($3);
1772 $$ = malloc(l1 + 1 + l3 + 1);
1773 memcpy($$, $1, l1);
1774 $$[l1] = '.';
1775 memcpy($$ + l1 + 1, $3, l3);
1776 $$[l1 + 1 + l3] = '\0';
1777 }
1778 ;
1779
1780
1781
1782/*
1783 * MARKERS
1784 */
1785
1786optMarker:
vlmc94e28f2004-09-15 11:59:51 +00001787 {
1788 $$.flags = EM_NOMARK;
1789 $$.default_value = 0;
1790 }
vlmfa67ddc2004-06-03 03:38:44 +00001791 | Marker { $$ = $1; }
1792 ;
1793
1794Marker:
1795 TOK_OPTIONAL {
vlmc94e28f2004-09-15 11:59:51 +00001796 $$.flags = EM_OPTIONAL;
1797 $$.default_value = 0;
vlmfa67ddc2004-06-03 03:38:44 +00001798 }
vlmc94e28f2004-09-15 11:59:51 +00001799 | TOK_DEFAULT Value {
1800 $$.flags = EM_DEFAULT;
1801 $$.default_value = $2;
vlmfa67ddc2004-06-03 03:38:44 +00001802 }
1803 ;
1804
1805/*
1806 * Universal enumeration definition to use in INTEGER and ENUMERATED.
1807 * === EXAMPLE ===
1808 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
1809 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
1810 * === EOF ===
1811 */
1812/*
1813optUniverationDefinition:
1814 { $$ = 0; }
1815 | UniverationDefinition {
1816 $$ = $1;
1817 }
1818 ;
1819*/
1820
1821UniverationDefinition:
1822 '{' '}' {
vlm39e5ed72004-09-05 10:40:41 +00001823 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001824 checkmem($$);
1825 }
1826 | '{' UniverationList '}' {
1827 $$ = $2;
1828 }
1829 ;
1830
1831UniverationList:
1832 UniverationElement {
vlm39e5ed72004-09-05 10:40:41 +00001833 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001834 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +00001835 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +00001836 }
1837 | UniverationList ',' UniverationElement {
1838 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +00001839 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001840 }
1841 ;
1842
1843UniverationElement:
1844 Identifier {
vlm39e5ed72004-09-05 10:40:41 +00001845 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001846 checkmem($$);
1847 $$->expr_type = A1TC_UNIVERVAL;
1848 $$->meta_type = AMT_VALUE;
1849 $$->Identifier = $1;
1850 }
1851 | Identifier '(' SignedNumber ')' {
vlm39e5ed72004-09-05 10:40:41 +00001852 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001853 checkmem($$);
1854 $$->expr_type = A1TC_UNIVERVAL;
1855 $$->meta_type = AMT_VALUE;
1856 $$->Identifier = $1;
1857 $$->value = $3;
1858 }
1859 | Identifier '(' DefinedValue ')' {
vlm39e5ed72004-09-05 10:40:41 +00001860 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001861 checkmem($$);
1862 $$->expr_type = A1TC_UNIVERVAL;
1863 $$->meta_type = AMT_VALUE;
1864 $$->Identifier = $1;
1865 $$->value = $3;
1866 }
1867 | SignedNumber {
vlm39e5ed72004-09-05 10:40:41 +00001868 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001869 checkmem($$);
1870 $$->expr_type = A1TC_UNIVERVAL;
1871 $$->meta_type = AMT_VALUE;
1872 $$->value = $1;
1873 }
1874 | TOK_ThreeDots {
vlm39e5ed72004-09-05 10:40:41 +00001875 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001876 checkmem($$);
1877 $$->Identifier = strdup("...");
1878 checkmem($$->Identifier);
1879 $$->expr_type = A1TC_EXTENSIBLE;
1880 $$->meta_type = AMT_VALUE;
1881 }
1882 ;
1883
1884SignedNumber:
1885 TOK_number {
1886 $$ = asn1p_value_fromint($1);
1887 checkmem($$);
1888 }
1889 | TOK_number_negative {
1890 $$ = asn1p_value_fromint($1);
1891 checkmem($$);
1892 }
1893 ;
1894
1895/*
1896 * SEQUENCE definition.
1897 * === EXAMPLE ===
1898 * Struct1 ::= SEQUENCE {
1899 * memb1 Struct2,
1900 * memb2 SEQUENCE OF {
1901 * memb2-1 Struct 3
1902 * }
1903 * }
1904 * === EOF ===
1905 */
1906
1907
1908
1909/*
1910 * SET definition.
1911 * === EXAMPLE ===
1912 * Person ::= SET {
1913 * name [0] PrintableString (SIZE(1..20)),
1914 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
1915 * }
1916 * === EOF ===
1917 */
1918
1919optTag:
1920 { memset(&$$, 0, sizeof($$)); }
1921 | Tag { $$ = $1; }
1922 ;
1923
1924Tag:
1925 TOK_tag {
1926 $$ = $1;
1927 $$.tag_mode = TM_DEFAULT;
1928 }
1929 | TOK_tag TOK_IMPLICIT {
1930 $$ = $1;
1931 $$.tag_mode = TM_IMPLICIT;
1932 }
1933 | TOK_tag TOK_EXPLICIT {
1934 $$ = $1;
1935 $$.tag_mode = TM_EXPLICIT;
1936 }
1937 ;
1938
1939TypeRefName:
1940 TOK_typereference {
1941 checkmem($1);
1942 $$ = $1;
1943 }
vlm9283dbe2004-08-18 04:59:12 +00001944 | TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00001945 checkmem($1);
1946 $$ = $1;
1947 }
1948 ;
1949
vlm9283dbe2004-08-18 04:59:12 +00001950
vlmfa67ddc2004-06-03 03:38:44 +00001951ObjectClassReference:
vlm9283dbe2004-08-18 04:59:12 +00001952 TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00001953 checkmem($1);
1954 $$ = $1;
1955 }
1956 ;
1957
1958Identifier:
1959 TOK_identifier {
1960 checkmem($1);
1961 $$ = $1;
1962 }
1963 ;
1964
vlmfa67ddc2004-06-03 03:38:44 +00001965%%
1966
1967
1968/*
1969 * Convert Xstring ('0101'B or '5'H) to the binary vector.
1970 */
1971static asn1p_value_t *
1972_convert_bitstring2binary(char *str, int base) {
1973 asn1p_value_t *val;
1974 int slen;
1975 int memlen;
1976 int baselen;
1977 int bits;
1978 uint8_t *binary_vector;
1979 uint8_t *bv_ptr;
1980 uint8_t cur_val;
1981
1982 assert(str);
1983 assert(str[0] == '\'');
1984
1985 switch(base) {
1986 case 'B':
1987 baselen = 1;
1988 break;
1989 case 'H':
1990 baselen = 4;
1991 break;
1992 default:
1993 assert(base == 'B' || base == 'H');
1994 errno = EINVAL;
1995 return NULL;
1996 }
1997
1998 slen = strlen(str);
1999 assert(str[slen - 1] == base);
2000 assert(str[slen - 2] == '\'');
2001
2002 memlen = slen / (8 / baselen); /* Conservative estimate */
2003
2004 bv_ptr = binary_vector = malloc(memlen + 1);
2005 if(bv_ptr == NULL)
2006 /* ENOMEM */
2007 return NULL;
2008
2009 cur_val = 0;
2010 bits = 0;
2011 while(*(++str) != '\'') {
2012 switch(baselen) {
2013 case 1:
2014 switch(*str) {
2015 case '1':
2016 cur_val |= 1 << (7 - (bits % 8));
2017 case '0':
2018 break;
2019 default:
2020 assert(!"_y UNREACH1");
2021 case ' ': case '\r': case '\n':
2022 continue;
2023 }
2024 break;
2025 case 4:
2026 switch(*str) {
2027 case '0': case '1': case '2': case '3': case '4':
2028 case '5': case '6': case '7': case '8': case '9':
2029 cur_val |= (*str - '0') << (4 - (bits % 8));
2030 break;
2031 case 'A': case 'B': case 'C':
2032 case 'D': case 'E': case 'F':
2033 cur_val |= ((*str - 'A') + 10)
2034 << (4 - (bits % 8));
2035 break;
2036 default:
2037 assert(!"_y UNREACH2");
2038 case ' ': case '\r': case '\n':
2039 continue;
2040 }
2041 break;
2042 }
2043
2044 bits += baselen;
2045 if((bits % 8) == 0) {
2046 *bv_ptr++ = cur_val;
2047 cur_val = 0;
2048 }
2049 }
2050
2051 *bv_ptr = cur_val;
2052 assert((bv_ptr - binary_vector) <= memlen);
2053
2054 val = asn1p_value_frombits(binary_vector, bits, 0);
2055 if(val == NULL) {
2056 free(binary_vector);
2057 }
2058
2059 return val;
2060}
2061
2062extern char *asn1p_text;
2063
2064int
2065yyerror(const char *msg) {
2066 fprintf(stderr,
2067 "ASN.1 grammar parse error "
2068 "near line %d (token \"%s\"): %s\n",
vlm39e5ed72004-09-05 10:40:41 +00002069 yylineno, asn1p_text, msg);
vlmfa67ddc2004-06-03 03:38:44 +00002070 return -1;
2071}
2072
2073