blob: b3796675b57157fca37ed75e89b91aeff009e308 [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 */
vlm0aa86902004-10-12 23:26:53 +000079 asn1c_integer_t a_int;
vlmfa67ddc2004-06-03 03:38:44 +000080 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 /* ... */
vlmfa67ddc2004-06-03 03:38:44 +0000199
200
201/*
202 * Types defined herein.
203 */
204%type <a_grammar> ModuleList
205%type <a_module> ModuleSpecification
206%type <a_module> ModuleSpecificationBody
207%type <a_module> ModuleSpecificationElement
208%type <a_module> optModuleSpecificationBody /* Optional */
209%type <a_module_flags> optModuleSpecificationFlags
210%type <a_module_flags> ModuleSpecificationFlags /* Set of FL */
211%type <a_module_flags> ModuleSpecificationFlag /* Single FL */
212%type <a_module> ImportsDefinition
213%type <a_module> ImportsBundleSet
214%type <a_xports> ImportsBundle
215%type <a_xports> ImportsList
216%type <a_xports> ExportsDefinition
217%type <a_xports> ExportsBody
218%type <a_expr> ImportsElement
219%type <a_expr> ExportsElement
vlmfa67ddc2004-06-03 03:38:44 +0000220%type <a_expr> ExtensionAndException
vlmec8f6812004-08-22 03:19:54 +0000221%type <a_expr> TypeDeclaration
vlmfa67ddc2004-06-03 03:38:44 +0000222%type <a_ref> ComplexTypeReference
223%type <a_ref> ComplexTypeReferenceAmpList
224%type <a_refcomp> ComplexTypeReferenceElement
225%type <a_refcomp> ClassFieldIdentifier
226%type <a_refcomp> ClassFieldName
227%type <a_expr> ClassFieldList
228%type <a_expr> ClassField
229%type <a_expr> ClassDeclaration
vlmec8f6812004-08-22 03:19:54 +0000230%type <a_expr> Type
vlmfa67ddc2004-06-03 03:38:44 +0000231%type <a_expr> DataTypeReference /* Type1 ::= Type2 */
232%type <a_expr> DefinedTypeRef
233%type <a_expr> ValueSetDefinition /* Val INTEGER ::= {1|2} */
234%type <a_expr> ValueDefinition /* val INTEGER ::= 1*/
vlm39e5ed72004-09-05 10:40:41 +0000235%type <a_expr> optValueSetBody
236%type <a_expr> ValueSetBody
237%type <a_expr> ValueSetElement
vlmc94e28f2004-09-15 11:59:51 +0000238%type <a_value> Value
vlmfa67ddc2004-06-03 03:38:44 +0000239%type <a_value> DefinedValue
240%type <a_value> SignedNumber
vlm0aa86902004-10-12 23:26:53 +0000241%type <a_expr> optComponentTypeLists
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
vlm151c0b22004-09-22 16:03:36 +0000253%type <tv_str> optIdentifier
vlmfa67ddc2004-06-03 03:38:44 +0000254%type <a_parg> ParameterArgumentName
255%type <a_plist> ParameterArgumentList
256%type <a_expr> ActualParameter
257%type <a_expr> ActualParameterList
258%type <a_oid> ObjectIdentifier /* OID */
259%type <a_oid> optObjectIdentifier /* Optional OID */
260%type <a_oid> ObjectIdentifierBody
261%type <a_oid_arc> ObjectIdentifierElement
262%type <a_expr> BasicType
263%type <a_type> BasicTypeId
264%type <a_type> BasicTypeId_UniverationCompatible
265%type <a_type> BasicString
266%type <tv_opaque> Opaque
267//%type <tv_opaque> StringValue
vlm2728a8d2005-01-23 09:51:44 +0000268%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
269%type <a_tag> TagClass TagTypeValue TagPlicit
vlmfa67ddc2004-06-03 03:38:44 +0000270%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
271%type <a_constr> optConstraints
vlm5f0128b2004-08-20 13:25:29 +0000272%type <a_constr> Constraints
vlm9283dbe2004-08-18 04:59:12 +0000273%type <a_constr> SetOfConstraints
274%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
275%type <a_constr> ElementSetSpec /* 1..2,...,3 */
vlmfa67ddc2004-06-03 03:38:44 +0000276%type <a_constr> ConstraintSubtypeElement /* 1..2 */
vlmfa67ddc2004-06-03 03:38:44 +0000277%type <a_constr> SimpleTableConstraint
278%type <a_constr> TableConstraint
279%type <a_constr> WithComponents
280%type <a_constr> WithComponentsList
281%type <a_constr> WithComponentsElement
282%type <a_constr> ComponentRelationConstraint
283%type <a_constr> AtNotationList
284%type <a_ref> AtNotationElement
vlma6a12e32005-03-20 12:58:00 +0000285%type <a_value> SingleValue
286%type <a_value> ContainedSubtype
vlmfa67ddc2004-06-03 03:38:44 +0000287%type <a_ctype> ConstraintSpec
288%type <a_ctype> ConstraintRangeSpec
289%type <a_wsynt> optWithSyntax
290%type <a_wsynt> WithSyntax
291%type <a_wsynt> WithSyntaxFormat
292%type <a_wchunk> WithSyntaxFormatToken
293%type <a_marker> optMarker Marker
294%type <a_int> optUnique
295%type <a_pres> optPresenceConstraint PresenceConstraint
296%type <tv_str> ComponentIdList
297
298
299%%
300
301
302ParsedGrammar:
303 ModuleList {
304 *(void **)param = $1;
305 }
306 ;
307
308ModuleList:
309 ModuleSpecification {
310 $$ = asn1p_new();
311 checkmem($$);
312 TQ_ADD(&($$->modules), $1, mod_next);
313 }
314 | ModuleList ModuleSpecification {
315 $$ = $1;
316 TQ_ADD(&($$->modules), $2, mod_next);
317 }
318 ;
319
320/*
321 * ASN module definition.
322 * === EXAMPLE ===
323 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
324 * BEGIN
325 * ...
326 * END
327 * === EOF ===
328 */
329
330ModuleSpecification:
331 TypeRefName optObjectIdentifier TOK_DEFINITIONS
332 optModuleSpecificationFlags
333 TOK_PPEQ TOK_BEGIN
334 optModuleSpecificationBody
335 TOK_END {
336
337 if($7) {
338 $$ = $7;
339 } else {
340 /* There's a chance that a module is just plain empty */
341 $$ = asn1p_module_new();
342 }
343 checkmem($$);
344
345 $$->Identifier = $1;
346 $$->module_oid = $2;
347 $$->module_flags = $4;
348 }
349 ;
350
351/*
352 * Object Identifier Definition
353 * { iso member-body(2) 3 }
354 */
355optObjectIdentifier:
356 { $$ = 0; }
357 | ObjectIdentifier { $$ = $1; }
358 ;
359
360ObjectIdentifier:
361 '{' ObjectIdentifierBody '}' {
362 $$ = $2;
363 }
364 | '{' '}' {
365 $$ = 0;
366 }
367 ;
368
369ObjectIdentifierBody:
370 ObjectIdentifierElement {
371 $$ = asn1p_oid_new();
372 asn1p_oid_add_arc($$, &$1);
373 if($1.name)
374 free($1.name);
375 }
376 | ObjectIdentifierBody ObjectIdentifierElement {
377 $$ = $1;
378 asn1p_oid_add_arc($$, &$2);
379 if($2.name)
380 free($2.name);
381 }
382 ;
383
384ObjectIdentifierElement:
385 Identifier { /* iso */
386 $$.name = $1;
387 $$.number = -1;
388 }
389 | Identifier '(' TOK_number ')' { /* iso(1) */
390 $$.name = $1;
391 $$.number = $3;
392 }
393 | TOK_number { /* 1 */
394 $$.name = 0;
395 $$.number = $1;
396 }
397 ;
398
399/*
400 * Optional module flags.
401 */
402optModuleSpecificationFlags:
403 { $$ = MSF_NOFLAGS; }
404 | ModuleSpecificationFlags {
405 $$ = $1;
406 }
407 ;
408
409/*
410 * Module flags.
411 */
412ModuleSpecificationFlags:
413 ModuleSpecificationFlag {
414 $$ = $1;
415 }
416 | ModuleSpecificationFlags ModuleSpecificationFlag {
417 $$ = $1 | $2;
418 }
419 ;
420
421/*
422 * Single module flag.
423 */
424ModuleSpecificationFlag:
425 TOK_EXPLICIT TOK_TAGS {
426 $$ = MSF_EXPLICIT_TAGS;
427 }
428 | TOK_IMPLICIT TOK_TAGS {
429 $$ = MSF_IMPLICIT_TAGS;
430 }
431 | TOK_AUTOMATIC TOK_TAGS {
432 $$ = MSF_AUTOMATIC_TAGS;
433 }
434 | TOK_EXTENSIBILITY TOK_IMPLIED {
435 $$ = MSF_EXTENSIBILITY_IMPLIED;
436 }
vlm9283dbe2004-08-18 04:59:12 +0000437 /* EncodingReferenceDefault */
438 | TOK_capitalreference TOK_INSTRUCTIONS {
439 /* X.680Amd1 specifies TAG and XER */
440 if(strcmp($1, "TAG") == 0) {
441 $$ = MSF_TAG_INSTRUCTIONS;
442 } else if(strcmp($1, "XER") == 0) {
443 $$ = MSF_XER_INSTRUCTIONS;
444 } else {
445 fprintf(stderr,
446 "WARNING: %s INSTRUCTIONS at line %d: "
447 "Unrecognized encoding reference\n",
448 $1, yylineno);
449 $$ = MSF_unk_INSTRUCTIONS;
450 }
451 free($1);
452 }
vlmfa67ddc2004-06-03 03:38:44 +0000453 ;
454
455/*
456 * Optional module body.
457 */
458optModuleSpecificationBody:
459 { $$ = 0; }
460 | ModuleSpecificationBody {
vlmfa67ddc2004-06-03 03:38:44 +0000461 $$ = $1;
462 }
463 ;
464
465/*
466 * ASN.1 Module body.
467 */
468ModuleSpecificationBody:
469 ModuleSpecificationElement {
470 $$ = $1;
471 }
472 | ModuleSpecificationBody ModuleSpecificationElement {
473 $$ = $1;
474
vlm9283dbe2004-08-18 04:59:12 +0000475 /* Behave well when one of them is skipped. */
476 if(!($1)) {
477 if($2) $$ = $2;
478 break;
479 }
480
vlmfa67ddc2004-06-03 03:38:44 +0000481#ifdef MY_IMPORT
482#error MY_IMPORT DEFINED ELSEWHERE!
483#endif
484#define MY_IMPORT(foo,field) do { \
vlm97ed7152004-08-13 12:31:09 +0000485 while(TQ_FIRST(&($2->foo))) { \
vlmfa67ddc2004-06-03 03:38:44 +0000486 TQ_ADD(&($$->foo), \
487 TQ_REMOVE(&($2->foo), field), \
488 field); \
vlm97ed7152004-08-13 12:31:09 +0000489 } \
490 assert(TQ_FIRST(&($2->foo)) == 0); \
491 } while(0)
vlmfa67ddc2004-06-03 03:38:44 +0000492
493 MY_IMPORT(imports, xp_next);
494 MY_IMPORT(exports, xp_next);
495 MY_IMPORT(members, next);
496#undef MY_IMPORT
497
498 }
499 ;
500
501/*
502 * One of the elements of ASN.1 module specification.
503 */
504ModuleSpecificationElement:
505 ImportsDefinition {
506 $$ = $1;
507 }
508 | ExportsDefinition {
509 $$ = asn1p_module_new();
510 checkmem($$);
511 if($1) {
512 TQ_ADD(&($$->exports), $1, xp_next);
513 } else {
514 /* "EXPORTS ALL;" ? */
515 }
516 }
517 | DataTypeReference {
518 $$ = asn1p_module_new();
519 checkmem($$);
520 assert($1->expr_type != A1TC_INVALID);
521 assert($1->meta_type != AMT_INVALID);
522 TQ_ADD(&($$->members), $1, next);
523 }
524 | ValueDefinition {
525 $$ = asn1p_module_new();
526 checkmem($$);
527 assert($1->expr_type != A1TC_INVALID);
528 assert($1->meta_type != AMT_INVALID);
529 TQ_ADD(&($$->members), $1, next);
530 }
531 /*
532 * Value set definition
533 * === EXAMPLE ===
534 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
535 * === EOF ===
536 */
537 | ValueSetDefinition {
538 $$ = asn1p_module_new();
539 checkmem($$);
540 assert($1->expr_type != A1TC_INVALID);
541 assert($1->meta_type != AMT_INVALID);
542 TQ_ADD(&($$->members), $1, next);
543 }
vlm9283dbe2004-08-18 04:59:12 +0000544 | TOK_ENCODING_CONTROL TOK_capitalreference
545 { asn1p_lexer_hack_push_encoding_control(); }
546 {
547 fprintf(stderr,
548 "WARNING: ENCODING-CONTROL %s "
549 "specification at line %d ignored\n",
550 $2, yylineno);
551 free($2);
552 $$ = 0;
553 }
vlmfa67ddc2004-06-03 03:38:44 +0000554
555 /*
556 * Erroneous attemps
557 */
558 | BasicString {
559 return yyerror(
560 "Attempt to redefine a standard basic type, "
561 "use -ftypesXY to switch back "
562 "to older version of ASN.1 standard");
563 }
564 ;
565
566/*
567 * === EXAMPLE ===
568 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
569 * === EOF ===
570 */
571ImportsDefinition:
572 TOK_IMPORTS ImportsBundleSet ';' {
573 $$ = $2;
574 }
575 /*
576 * Some error cases.
577 */
578 | TOK_IMPORTS TOK_FROM /* ... */ {
579 return yyerror("Empty IMPORTS list");
580 }
581 ;
582
583ImportsBundleSet:
584 ImportsBundle {
585 $$ = asn1p_module_new();
586 checkmem($$);
587 TQ_ADD(&($$->imports), $1, xp_next);
588 }
589 | ImportsBundleSet ImportsBundle {
590 $$ = $1;
591 TQ_ADD(&($$->imports), $2, xp_next);
592 }
593 ;
594
595ImportsBundle:
596 ImportsList TOK_FROM TypeRefName optObjectIdentifier {
597 $$ = $1;
598 $$->from = $3;
599 $$->from_oid = $4;
600 checkmem($$);
601 }
602 ;
603
604ImportsList:
605 ImportsElement {
606 $$ = asn1p_xports_new();
607 checkmem($$);
608 TQ_ADD(&($$->members), $1, next);
609 }
610 | ImportsList ',' ImportsElement {
611 $$ = $1;
612 TQ_ADD(&($$->members), $3, next);
613 }
614 ;
615
616ImportsElement:
617 TypeRefName {
618 $$ = asn1p_expr_new(yylineno);
619 checkmem($$);
620 $$->Identifier = $1;
621 $$->expr_type = A1TC_REFERENCE;
622 }
vlm0aa86902004-10-12 23:26:53 +0000623 | TypeRefName '{' '}' { /* Completely equivalent to above */
624 $$ = asn1p_expr_new(yylineno);
625 checkmem($$);
626 $$->Identifier = $1;
627 $$->expr_type = A1TC_REFERENCE;
628 }
vlmfa67ddc2004-06-03 03:38:44 +0000629 | Identifier {
630 $$ = asn1p_expr_new(yylineno);
631 checkmem($$);
632 $$->Identifier = $1;
633 $$->expr_type = A1TC_REFERENCE;
634 }
635 ;
636
637ExportsDefinition:
638 TOK_EXPORTS ExportsBody ';' {
639 $$ = $2;
640 }
641 | TOK_EXPORTS TOK_ALL ';' {
642 $$ = 0;
643 }
644 | TOK_EXPORTS ';' {
645 /* Empty EXPORTS clause effectively prohibits export. */
646 $$ = asn1p_xports_new();
647 checkmem($$);
648 }
649 ;
650
651ExportsBody:
652 ExportsElement {
653 $$ = asn1p_xports_new();
654 assert($$);
655 TQ_ADD(&($$->members), $1, next);
656 }
657 | ExportsBody ',' ExportsElement {
658 $$ = $1;
659 TQ_ADD(&($$->members), $3, next);
660 }
661 ;
662
663ExportsElement:
664 TypeRefName {
665 $$ = asn1p_expr_new(yylineno);
666 checkmem($$);
667 $$->Identifier = $1;
668 $$->expr_type = A1TC_EXPORTVAR;
669 }
vlm0aa86902004-10-12 23:26:53 +0000670 | TypeRefName '{' '}' {
671 $$ = asn1p_expr_new(yylineno);
672 checkmem($$);
673 $$->Identifier = $1;
674 $$->expr_type = A1TC_EXPORTVAR;
675 }
vlmfa67ddc2004-06-03 03:38:44 +0000676 | Identifier {
677 $$ = asn1p_expr_new(yylineno);
678 checkmem($$);
679 $$->Identifier = $1;
680 $$->expr_type = A1TC_EXPORTVAR;
681 }
682 ;
683
684
685ValueSetDefinition:
686 TypeRefName DefinedTypeRef TOK_PPEQ '{' optValueSetBody '}' {
687 $$ = $2;
688 assert($$->Identifier == 0);
689 $$->Identifier = $1;
690 $$->meta_type = AMT_VALUESET;
691 // take care of optValueSetBody
692 }
693 ;
694
695DefinedTypeRef:
696 ComplexTypeReference {
697 $$ = asn1p_expr_new(yylineno);
698 checkmem($$);
699 $$->reference = $1;
700 $$->expr_type = A1TC_REFERENCE;
701 $$->meta_type = AMT_TYPEREF;
702 }
703 | BasicTypeId {
704 $$ = asn1p_expr_new(yylineno);
705 checkmem($$);
706 $$->expr_type = $1;
707 $$->meta_type = AMT_TYPE;
708 }
709 ;
710
711optValueSetBody:
712 { }
vlm39e5ed72004-09-05 10:40:41 +0000713 | ValueSetBody {
714 }
715 ;
716
717/*
718 * X.680 does not permit ElementSetSpecs starting with ellipsis,
719 * i.e. (..., A, B). This is very strange: the ElementSetSpecs is used
720 * inside ValueSet, and ValueSets "in the wild" tend to have the first
721 * ellipsis.
722 */
723ValueSetBody:
724 ValueSetElement {
725 }
726 | ValueSetBody ',' ValueSetElement {
727 }
728 ;
729
730ValueSetElement:
731 TOK_ThreeDots {
732 }
733 | ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +0000734 }
735 ;
736
737
738/*
739 * Data Type Reference.
740 * === EXAMPLE ===
741 * Type3 ::= CHOICE { a Type1, b Type 2 }
742 * === EOF ===
743 */
744
745DataTypeReference:
746 /*
747 * Optionally tagged type definition.
748 */
749 TypeRefName TOK_PPEQ optTag TOK_TYPE_IDENTIFIER {
750 $$ = asn1p_expr_new(yylineno);
751 checkmem($$);
752 $$->Identifier = $1;
753 $$->tag = $3;
754 $$->expr_type = A1TC_TYPEID;
755 $$->meta_type = AMT_TYPE;
756 }
vlmfce48a42004-09-14 02:36:39 +0000757 | TypeRefName TOK_PPEQ Type {
758 $$ = $3;
vlmfa67ddc2004-06-03 03:38:44 +0000759 $$->Identifier = $1;
vlmfa67ddc2004-06-03 03:38:44 +0000760 assert($$->expr_type);
761 assert($$->meta_type);
762 }
763 | TypeRefName TOK_PPEQ ClassDeclaration {
764 $$ = $3;
765 $$->Identifier = $1;
766 assert($$->expr_type == A1TC_CLASSDEF);
767 assert($$->meta_type == AMT_OBJECT);
768 }
769 /*
770 * Parametrized <Type> declaration:
771 * === EXAMPLE ===
772 * SIGNED { ToBeSigned } ::= SEQUENCE {
773 * toBeSigned ToBeSigned,
774 * algorithm AlgorithmIdentifier,
775 * signature BIT STRING
776 * }
777 * === EOF ===
778 */
vlmec8f6812004-08-22 03:19:54 +0000779 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
vlmfa67ddc2004-06-03 03:38:44 +0000780 $$ = $6;
781 assert($$->Identifier == 0);
782 $$->Identifier = $1;
783 $$->params = $3;
784 $$->meta_type = AMT_PARAMTYPE;
785 }
786 ;
787
788ParameterArgumentList:
789 ParameterArgumentName {
790 int ret;
791 $$ = asn1p_paramlist_new(yylineno);
792 checkmem($$);
793 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
794 checkmem(ret == 0);
795 if($1.governor) asn1p_ref_free($1.governor);
796 if($1.argument) free($1.argument);
797 }
798 | ParameterArgumentList ',' ParameterArgumentName {
799 int ret;
800 $$ = $1;
801 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
802 checkmem(ret == 0);
803 if($3.governor) asn1p_ref_free($3.governor);
804 if($3.argument) free($3.argument);
805 }
806 ;
807
808ParameterArgumentName:
809 TypeRefName {
810 $$.governor = NULL;
811 $$.argument = $1;
812 }
813 | TypeRefName ':' Identifier {
814 int ret;
815 $$.governor = asn1p_ref_new(yylineno);
816 ret = asn1p_ref_add_component($$.governor, $1, 0);
817 checkmem(ret == 0);
818 $$.argument = $3;
819 }
vlm4053ca52005-02-18 16:34:21 +0000820 | TypeRefName ':' TypeRefName {
821 int ret;
822 $$.governor = asn1p_ref_new(yylineno);
823 ret = asn1p_ref_add_component($$.governor, $1, 0);
824 checkmem(ret == 0);
825 $$.argument = $3;
826 }
vlmfa67ddc2004-06-03 03:38:44 +0000827 | BasicTypeId ':' Identifier {
828 int ret;
829 $$.governor = asn1p_ref_new(yylineno);
830 ret = asn1p_ref_add_component($$.governor,
831 ASN_EXPR_TYPE2STR($1), 1);
832 checkmem(ret == 0);
833 $$.argument = $3;
834 }
835 ;
836
837ActualParameterList:
838 ActualParameter {
839 $$ = asn1p_expr_new(yylineno);
840 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000841 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000842 }
843 | ActualParameterList ',' ActualParameter {
844 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000845 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000846 }
847 ;
848
849ActualParameter:
vlmec8f6812004-08-22 03:19:54 +0000850 Type {
vlmfa67ddc2004-06-03 03:38:44 +0000851 $$ = $1;
852 }
853 | Identifier {
854 $$ = asn1p_expr_new(yylineno);
855 checkmem($$);
856 $$->Identifier = $1;
857 $$->expr_type = A1TC_REFERENCE;
858 $$->meta_type = AMT_VALUE;
859 }
860 ;
861
862/*
vlm4053ca52005-02-18 16:34:21 +0000863 | '{' ActualParameter '}' {
864 $$ = asn1p_expr_new(yylineno);
865 checkmem($$);
866 asn1p_expr_add($$, $2);
867 $$->expr_type = A1TC_PARAMETRIZED;
868 $$->meta_type = AMT_TYPE;
869 }
870 ;
871*/
872
873/*
vlmfa67ddc2004-06-03 03:38:44 +0000874 * A collection of constructed data type members.
875 */
vlm0aa86902004-10-12 23:26:53 +0000876optComponentTypeLists:
877 { $$ = asn1p_expr_new(yylineno); }
878 | ComponentTypeLists { $$ = $1; };
879
vlmec8f6812004-08-22 03:19:54 +0000880ComponentTypeLists:
881 ComponentType {
vlmfa67ddc2004-06-03 03:38:44 +0000882 $$ = asn1p_expr_new(yylineno);
883 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000884 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000885 }
vlmec8f6812004-08-22 03:19:54 +0000886 | ComponentTypeLists ',' ComponentType {
vlmfa67ddc2004-06-03 03:38:44 +0000887 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000888 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000889 }
890 ;
891
vlmec8f6812004-08-22 03:19:54 +0000892ComponentType:
vlmfce48a42004-09-14 02:36:39 +0000893 Identifier Type optMarker {
vlmec8f6812004-08-22 03:19:54 +0000894 $$ = $2;
895 assert($$->Identifier == 0);
vlmfce48a42004-09-14 02:36:39 +0000896 $$->Identifier = $1;
vlmec8f6812004-08-22 03:19:54 +0000897 $$->marker = $3;
898 }
899 | TOK_COMPONENTS TOK_OF Type {
900 $$ = asn1p_expr_new(yylineno);
901 checkmem($$);
902 $$->meta_type = $3->meta_type;
903 $$->expr_type = A1TC_COMPONENTS_OF;
vlm6a02a8a2004-09-08 00:28:11 +0000904 asn1p_expr_add($$, $3);
vlmec8f6812004-08-22 03:19:54 +0000905 }
906 | ExtensionAndException {
907 $$ = $1;
908 }
909 ;
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 }
932 ;
933
vlmfa67ddc2004-06-03 03:38:44 +0000934ClassDeclaration:
935 TOK_CLASS '{' ClassFieldList '}' optWithSyntax {
936 $$ = $3;
937 checkmem($$);
938 $$->with_syntax = $5;
939 assert($$->expr_type == A1TC_CLASSDEF);
940 assert($$->meta_type == AMT_OBJECT);
941 }
942 ;
943
944optUnique:
945 { $$ = 0; }
946 | TOK_UNIQUE { $$ = 1; }
947 ;
948
949ClassFieldList:
950 ClassField {
951 $$ = asn1p_expr_new(yylineno);
952 checkmem($$);
953 $$->expr_type = A1TC_CLASSDEF;
954 $$->meta_type = AMT_OBJECT;
vlm6a02a8a2004-09-08 00:28:11 +0000955 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000956 }
957 | ClassFieldList ',' ClassField {
958 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000959 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000960 }
961 ;
962
963ClassField:
964 ClassFieldIdentifier optMarker {
965 $$ = asn1p_expr_new(yylineno);
966 checkmem($$);
967 $$->Identifier = $1.name;
968 $$->expr_type = A1TC_CLASSFIELD;
969 $$->meta_type = AMT_OBJECTFIELD;
970 $$->marker = $2;
971 }
vlmbde35d42004-11-24 17:43:29 +0000972 | ClassFieldIdentifier Type optUnique optMarker {
vlmfa67ddc2004-06-03 03:38:44 +0000973 $$ = $2;
974 $$->Identifier = $1.name;
vlmbde35d42004-11-24 17:43:29 +0000975 $$->marker = $4;
976 $$->unique = $3;
vlmfa67ddc2004-06-03 03:38:44 +0000977 }
vlmbde35d42004-11-24 17:43:29 +0000978 | ClassFieldIdentifier ClassFieldIdentifier optUnique optMarker {
vlmfa67ddc2004-06-03 03:38:44 +0000979 int ret;
980 $$ = asn1p_expr_new(yylineno);
981 checkmem($$);
982 $$->Identifier = $1.name;
983 $$->reference = asn1p_ref_new(yylineno);
984 checkmem($$->reference);
985 ret = asn1p_ref_add_component($$->reference,
986 $2.name, $2.lex_type);
987 checkmem(ret == 0);
988 $$->expr_type = A1TC_CLASSFIELD;
989 $$->meta_type = AMT_OBJECTFIELD;
vlmbde35d42004-11-24 17:43:29 +0000990 $$->marker = $4;
991 $$->unique = $3;
vlmfa67ddc2004-06-03 03:38:44 +0000992 }
993 ;
994
995optWithSyntax:
996 { $$ = 0; }
997 | WithSyntax {
998 $$ = $1;
999 }
1000 ;
1001
1002WithSyntax:
1003 TOK_WITH TOK_SYNTAX '{'
1004 { asn1p_lexer_hack_enable_with_syntax(); }
1005 WithSyntaxFormat
1006 '}' {
1007 $$ = $5;
1008 }
1009 ;
1010
1011WithSyntaxFormat:
1012 WithSyntaxFormatToken {
1013 $$ = asn1p_wsyntx_new();
1014 TQ_ADD(&($$->chunks), $1, next);
1015 }
1016 | WithSyntaxFormat WithSyntaxFormatToken {
1017 $$ = $1;
1018 TQ_ADD(&($$->chunks), $2, next);
1019 }
1020 ;
1021
1022WithSyntaxFormatToken:
1023 TOK_opaque {
1024 $$ = asn1p_wsyntx_chunk_frombuf($1.buf, $1.len, 0);
1025 }
1026 | ClassFieldIdentifier {
1027 asn1p_ref_t *ref;
1028 int ret;
1029 ref = asn1p_ref_new(yylineno);
1030 checkmem(ref);
1031 ret = asn1p_ref_add_component(ref, $1.name, $1.lex_type);
1032 checkmem(ret == 0);
1033 $$ = asn1p_wsyntx_chunk_fromref(ref, 0);
1034 }
1035 ;
1036
vlmfa67ddc2004-06-03 03:38:44 +00001037ExtensionAndException:
1038 TOK_ThreeDots {
vlm39e5ed72004-09-05 10:40:41 +00001039 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001040 checkmem($$);
1041 $$->Identifier = strdup("...");
1042 checkmem($$->Identifier);
1043 $$->expr_type = A1TC_EXTENSIBLE;
1044 $$->meta_type = AMT_TYPE;
1045 }
1046 | TOK_ThreeDots '!' DefinedValue {
vlm39e5ed72004-09-05 10:40:41 +00001047 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001048 checkmem($$);
1049 $$->Identifier = strdup("...");
1050 checkmem($$->Identifier);
1051 $$->value = $3;
1052 $$->expr_type = A1TC_EXTENSIBLE;
1053 $$->meta_type = AMT_TYPE;
1054 }
1055 | TOK_ThreeDots '!' SignedNumber {
vlm39e5ed72004-09-05 10:40:41 +00001056 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001057 checkmem($$);
1058 $$->Identifier = strdup("...");
1059 $$->value = $3;
1060 checkmem($$->Identifier);
1061 $$->expr_type = A1TC_EXTENSIBLE;
1062 $$->meta_type = AMT_TYPE;
1063 }
1064 ;
1065
vlmec8f6812004-08-22 03:19:54 +00001066Type:
vlmfce48a42004-09-14 02:36:39 +00001067 optTag TypeDeclaration optConstraints {
1068 $$ = $2;
1069 $$->tag = $1;
vlmec8f6812004-08-22 03:19:54 +00001070 /*
1071 * Outer constraint for SEQUENCE OF and SET OF applies
1072 * to the inner type.
1073 */
1074 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1075 || $$->expr_type == ASN_CONSTR_SET_OF) {
1076 assert(!TQ_FIRST(&($$->members))->constraints);
vlmfce48a42004-09-14 02:36:39 +00001077 TQ_FIRST(&($$->members))->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001078 } else {
1079 if($$->constraints) {
1080 assert(!$2);
1081 } else {
vlmfce48a42004-09-14 02:36:39 +00001082 $$->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001083 }
1084 }
1085 }
1086 ;
1087
1088TypeDeclaration:
vlmfa67ddc2004-06-03 03:38:44 +00001089 BasicType {
1090 $$ = $1;
1091 }
vlmec8f6812004-08-22 03:19:54 +00001092 | TOK_CHOICE '{' AlternativeTypeLists '}' {
1093 $$ = $3;
1094 assert($$->expr_type == A1TC_INVALID);
1095 $$->expr_type = ASN_CONSTR_CHOICE;
1096 $$->meta_type = AMT_TYPE;
vlmfa67ddc2004-06-03 03:38:44 +00001097 }
vlm0aa86902004-10-12 23:26:53 +00001098 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001099 $$ = $3;
1100 assert($$->expr_type == A1TC_INVALID);
1101 $$->expr_type = ASN_CONSTR_SEQUENCE;
1102 $$->meta_type = AMT_TYPE;
1103 }
vlm0aa86902004-10-12 23:26:53 +00001104 | TOK_SET '{' optComponentTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001105 $$ = $3;
1106 assert($$->expr_type == A1TC_INVALID);
1107 $$->expr_type = ASN_CONSTR_SET;
1108 $$->meta_type = AMT_TYPE;
1109 }
vlm151c0b22004-09-22 16:03:36 +00001110 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
vlm39e5ed72004-09-05 10:40:41 +00001111 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001112 checkmem($$);
1113 $$->constraints = $2;
1114 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1115 $$->meta_type = AMT_TYPE;
vlm151c0b22004-09-22 16:03:36 +00001116 $6->Identifier = $4;
1117 $6->tag = $5;
1118 asn1p_expr_add($$, $6);
vlmec8f6812004-08-22 03:19:54 +00001119 }
vlm151c0b22004-09-22 16:03:36 +00001120 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
vlm39e5ed72004-09-05 10:40:41 +00001121 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001122 checkmem($$);
1123 $$->constraints = $2;
1124 $$->expr_type = ASN_CONSTR_SET_OF;
1125 $$->meta_type = AMT_TYPE;
vlm151c0b22004-09-22 16:03:36 +00001126 $6->Identifier = $4;
1127 $6->tag = $5;
1128 asn1p_expr_add($$, $6);
vlmec8f6812004-08-22 03:19:54 +00001129 }
1130 | TOK_ANY {
vlm39e5ed72004-09-05 10:40:41 +00001131 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001132 checkmem($$);
vlm044f7442004-09-04 04:49:21 +00001133 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001134 $$->meta_type = AMT_TYPE;
1135 }
1136 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1137 int ret;
vlm39e5ed72004-09-05 10:40:41 +00001138 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001139 checkmem($$);
1140 $$->reference = asn1p_ref_new(yylineno);
1141 ret = asn1p_ref_add_component($$->reference,
1142 $4, RLT_lowercase);
1143 checkmem(ret == 0);
vlm044f7442004-09-04 04:49:21 +00001144 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001145 $$->meta_type = AMT_TYPE;
1146 }
vlmfa67ddc2004-06-03 03:38:44 +00001147 /*
1148 * A parametrized assignment.
1149 */
1150 | TypeRefName '{' ActualParameterList '}' {
1151 int ret;
1152 $$ = $3;
1153 assert($$->expr_type == 0);
1154 assert($$->meta_type == 0);
1155 assert($$->reference == 0);
1156 $$->reference = asn1p_ref_new(yylineno);
1157 checkmem($$->reference);
1158 ret = asn1p_ref_add_component($$->reference, $1, RLT_UNKNOWN);
1159 checkmem(ret == 0);
1160 free($1);
1161 $$->expr_type = A1TC_PARAMETRIZED;
1162 $$->meta_type = AMT_TYPE;
1163 }
1164 /*
1165 * A DefinedType reference.
1166 * "CLASS1.&id.&id2"
1167 * or
1168 * "Module.Type"
1169 * or
1170 * "Module.identifier"
1171 * or
1172 * "Type"
1173 */
1174 | ComplexTypeReference {
1175 $$ = asn1p_expr_new(yylineno);
1176 checkmem($$);
1177 $$->reference = $1;
1178 $$->expr_type = A1TC_REFERENCE;
1179 $$->meta_type = AMT_TYPEREF;
1180 }
1181 | TOK_INSTANCE TOK_OF ComplexTypeReference {
1182 $$ = asn1p_expr_new(yylineno);
1183 checkmem($$);
1184 $$->reference = $3;
1185 $$->expr_type = A1TC_INSTANCE;
1186 $$->meta_type = AMT_TYPE;
1187 }
1188 ;
1189
1190/*
1191 * A type name consisting of several components.
1192 * === EXAMPLE ===
1193 * === EOF ===
1194 */
1195ComplexTypeReference:
1196 TOK_typereference {
1197 int ret;
1198 $$ = asn1p_ref_new(yylineno);
1199 checkmem($$);
1200 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1201 checkmem(ret == 0);
1202 free($1);
1203 }
1204 | TOK_typereference '.' TypeRefName {
1205 int ret;
1206 $$ = asn1p_ref_new(yylineno);
1207 checkmem($$);
1208 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1209 checkmem(ret == 0);
1210 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1211 checkmem(ret == 0);
1212 free($1);
1213 }
vlmc94e28f2004-09-15 11:59:51 +00001214 | ObjectClassReference '.' TypeRefName {
1215 int ret;
1216 $$ = asn1p_ref_new(yylineno);
1217 checkmem($$);
1218 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1219 checkmem(ret == 0);
1220 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1221 checkmem(ret == 0);
1222 free($1);
1223 }
vlmfa67ddc2004-06-03 03:38:44 +00001224 | TOK_typereference '.' Identifier {
1225 int ret;
1226 $$ = asn1p_ref_new(yylineno);
1227 checkmem($$);
1228 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1229 checkmem(ret == 0);
1230 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1231 checkmem(ret == 0);
1232 free($1);
1233 }
1234 | ObjectClassReference {
1235 int ret;
1236 $$ = asn1p_ref_new(yylineno);
1237 checkmem($$);
1238 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1239 free($1);
1240 checkmem(ret == 0);
1241 }
1242 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1243 int ret;
1244 $$ = $3;
1245 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1246 free($1);
1247 checkmem(ret == 0);
1248 /*
1249 * Move the last element infront.
1250 */
1251 {
1252 struct asn1p_ref_component_s tmp_comp;
1253 tmp_comp = $$->components[$$->comp_count-1];
1254 memmove(&$$->components[1],
1255 &$$->components[0],
1256 sizeof($$->components[0])
1257 * ($$->comp_count - 1));
1258 $$->components[0] = tmp_comp;
1259 }
1260 }
1261 ;
1262
1263ComplexTypeReferenceAmpList:
1264 ComplexTypeReferenceElement {
1265 int ret;
1266 $$ = asn1p_ref_new(yylineno);
1267 checkmem($$);
1268 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1269 free($1.name);
1270 checkmem(ret == 0);
1271 }
1272 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1273 int ret;
1274 $$ = $1;
1275 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1276 free($3.name);
1277 checkmem(ret == 0);
1278 }
1279 ;
1280
1281ComplexTypeReferenceElement: ClassFieldName;
1282ClassFieldIdentifier: ClassFieldName;
1283
1284ClassFieldName:
1285 /* "&Type1" */
1286 TOK_typefieldreference {
1287 $$.lex_type = RLT_AmpUppercase;
1288 $$.name = $1;
1289 }
1290 /* "&id" */
1291 | TOK_valuefieldreference {
1292 $$.lex_type = RLT_Amplowercase;
1293 $$.name = $1;
1294 }
1295 ;
1296
1297
1298/*
1299 * === EXAMPLE ===
1300 * value INTEGER ::= 1
1301 * === EOF ===
1302 */
1303ValueDefinition:
vlmc94e28f2004-09-15 11:59:51 +00001304 Identifier DefinedTypeRef TOK_PPEQ Value {
vlmfa67ddc2004-06-03 03:38:44 +00001305 $$ = $2;
1306 assert($$->Identifier == NULL);
1307 $$->Identifier = $1;
1308 $$->meta_type = AMT_VALUE;
1309 $$->value = $4;
1310 }
1311 ;
1312
vlmc94e28f2004-09-15 11:59:51 +00001313Value:
1314 Identifier ':' Value {
1315 $$ = asn1p_value_fromint(0);
1316 checkmem($$);
1317 $$->type = ATV_CHOICE_IDENTIFIER;
1318 $$->value.choice_identifier.identifier = $1;
1319 $$->value.choice_identifier.value = $3;
1320 }
1321 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
vlmfa67ddc2004-06-03 03:38:44 +00001322 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1323 checkmem($$);
1324 $$->type = ATV_UNPARSED;
1325 }
vlmc94e28f2004-09-15 11:59:51 +00001326 | TOK_NULL {
1327 $$ = asn1p_value_fromint(0);
1328 checkmem($$);
1329 $$->type = ATV_NULL;
1330 }
1331 | TOK_FALSE {
1332 $$ = asn1p_value_fromint(0);
1333 checkmem($$);
1334 $$->type = ATV_FALSE;
1335 }
1336 | TOK_TRUE {
1337 $$ = asn1p_value_fromint(0);
1338 checkmem($$);
1339 $$->type = ATV_TRUE;
1340 }
vlmfa67ddc2004-06-03 03:38:44 +00001341 | TOK_bstring {
1342 $$ = _convert_bitstring2binary($1, 'B');
1343 checkmem($$);
1344 }
1345 | TOK_hstring {
1346 $$ = _convert_bitstring2binary($1, 'H');
1347 checkmem($$);
1348 }
1349 | TOK_cstring {
1350 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1351 checkmem($$);
1352 }
1353 | SignedNumber {
1354 $$ = $1;
1355 }
1356 | DefinedValue {
1357 $$ = $1;
1358 }
1359 ;
1360
1361DefinedValue:
1362 Identifier {
1363 asn1p_ref_t *ref;
1364 int ret;
1365 ref = asn1p_ref_new(yylineno);
1366 checkmem(ref);
1367 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1368 checkmem(ret == 0);
1369 $$ = asn1p_value_fromref(ref, 0);
1370 checkmem($$);
1371 free($1);
1372 }
1373 | TypeRefName '.' Identifier {
1374 asn1p_ref_t *ref;
1375 int ret;
1376 ref = asn1p_ref_new(yylineno);
1377 checkmem(ref);
1378 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1379 checkmem(ret == 0);
1380 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1381 checkmem(ret == 0);
1382 $$ = asn1p_value_fromref(ref, 0);
1383 checkmem($$);
1384 free($1);
1385 free($3);
1386 }
1387 ;
1388
1389Opaque:
1390 TOK_opaque {
1391 $$.len = $1.len + 2;
1392 $$.buf = malloc($$.len + 1);
1393 checkmem($$.buf);
1394 $$.buf[0] = '{';
1395 $$.buf[1] = ' ';
1396 memcpy($$.buf + 2, $1.buf, $1.len);
1397 $$.buf[$$.len] = '\0';
1398 free($1.buf);
1399 }
1400 | Opaque TOK_opaque {
1401 int newsize = $1.len + $2.len;
1402 char *p = malloc(newsize + 1);
1403 checkmem(p);
1404 memcpy(p , $1.buf, $1.len);
1405 memcpy(p + $1.len, $2.buf, $2.len);
1406 p[newsize] = '\0';
1407 free($1.buf);
1408 free($2.buf);
1409 $$.buf = p;
1410 $$.len = newsize;
1411 }
1412 ;
1413
1414BasicTypeId:
1415 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1416 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1417 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1418 | BasicTypeId_UniverationCompatible { $$ = $1; }
1419 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1420 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1421 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1422 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1423 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1424 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1425 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1426 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
vlm5e2c4b92005-03-20 11:12:40 +00001427 | BasicString { $$ = $1; }
vlmfa67ddc2004-06-03 03:38:44 +00001428 ;
1429
1430/*
1431 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1432 */
1433BasicTypeId_UniverationCompatible:
1434 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1435 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1436 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1437 ;
1438
1439BasicType:
1440 BasicTypeId {
vlm39e5ed72004-09-05 10:40:41 +00001441 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001442 checkmem($$);
1443 $$->expr_type = $1;
1444 $$->meta_type = AMT_TYPE;
1445 }
1446 | BasicTypeId_UniverationCompatible UniverationDefinition {
1447 if($2) {
1448 $$ = $2;
1449 } else {
vlm39e5ed72004-09-05 10:40:41 +00001450 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001451 checkmem($$);
1452 }
1453 $$->expr_type = $1;
1454 $$->meta_type = AMT_TYPE;
1455 }
1456 ;
1457
1458BasicString:
1459 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1460 | TOK_GeneralString {
1461 $$ = ASN_STRING_GeneralString;
vlmc94e28f2004-09-15 11:59:51 +00001462 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001463 }
1464 | TOK_GraphicString {
1465 $$ = ASN_STRING_GraphicString;
vlmc94e28f2004-09-15 11:59:51 +00001466 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001467 }
1468 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1469 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1470 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1471 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1472 | TOK_T61String {
1473 $$ = ASN_STRING_T61String;
vlmc94e28f2004-09-15 11:59:51 +00001474 fprintf(stderr, "WARNING: T61String is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001475 }
1476 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1477 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1478 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1479 | TOK_VideotexString {
1480 $$ = ASN_STRING_VideotexString;
vlmc94e28f2004-09-15 11:59:51 +00001481 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001482 }
1483 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1484 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1485 ;
1486
vlm5f0128b2004-08-20 13:25:29 +00001487
vlmfa67ddc2004-06-03 03:38:44 +00001488/*
1489 * Data type constraints.
1490 */
vlmfa67ddc2004-06-03 03:38:44 +00001491Union: '|' | TOK_UNION;
1492Intersection: '^' | TOK_INTERSECTION;
1493Except: TOK_EXCEPT;
1494
vlm9283dbe2004-08-18 04:59:12 +00001495optConstraints:
1496 { $$ = 0; }
vlm5f0128b2004-08-20 13:25:29 +00001497 | Constraints {
1498 $$ = $1;
1499 }
1500 ;
1501
1502Constraints:
1503 SetOfConstraints {
vlm9283dbe2004-08-18 04:59:12 +00001504 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
1505 }
1506 | TOK_SIZE '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001507 /*
1508 * This is a special case, for compatibility purposes.
vlm9283dbe2004-08-18 04:59:12 +00001509 * It goes without parentheses.
vlmfa67ddc2004-06-03 03:38:44 +00001510 */
vlm5f0128b2004-08-20 13:25:29 +00001511 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001512 }
vlmfa67ddc2004-06-03 03:38:44 +00001513 ;
1514
vlm9283dbe2004-08-18 04:59:12 +00001515SetOfConstraints:
1516 '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001517 $$ = $2;
1518 }
vlm9283dbe2004-08-18 04:59:12 +00001519 | SetOfConstraints '(' ElementSetSpecs ')' {
1520 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
1521 }
vlmfa67ddc2004-06-03 03:38:44 +00001522 ;
1523
vlm9283dbe2004-08-18 04:59:12 +00001524ElementSetSpecs:
1525 ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001526 $$ = $1;
1527 }
vlm9283dbe2004-08-18 04:59:12 +00001528 | ElementSetSpec ',' TOK_ThreeDots {
vlmfa67ddc2004-06-03 03:38:44 +00001529 asn1p_constraint_t *ct;
1530 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001531 ct->type = ACT_EL_EXT;
1532 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
1533 }
vlm9283dbe2004-08-18 04:59:12 +00001534 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001535 asn1p_constraint_t *ct;
1536 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001537 ct->type = ACT_EL_EXT;
1538 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlm6f5eb0b2004-08-13 12:35:09 +00001539 ct = $$;
1540 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
vlmfa67ddc2004-06-03 03:38:44 +00001541 }
vlmfa67ddc2004-06-03 03:38:44 +00001542 ;
1543
vlm9283dbe2004-08-18 04:59:12 +00001544ElementSetSpec:
1545 ConstraintSubtypeElement {
1546 $$ = $1;
1547 }
1548 | ElementSetSpec Union ConstraintSubtypeElement {
vlmfa67ddc2004-06-03 03:38:44 +00001549 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
1550 }
vlm9283dbe2004-08-18 04:59:12 +00001551 | ElementSetSpec Intersection ConstraintSubtypeElement {
vlmfa67ddc2004-06-03 03:38:44 +00001552 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
1553 }
vlm9283dbe2004-08-18 04:59:12 +00001554 | ConstraintSubtypeElement Except ConstraintSubtypeElement {
vlmfa67ddc2004-06-03 03:38:44 +00001555 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
1556 }
1557 ;
1558
1559ConstraintSubtypeElement:
vlm9283dbe2004-08-18 04:59:12 +00001560 ConstraintSpec '(' ElementSetSpecs ')' {
1561 int ret;
1562 $$ = asn1p_constraint_new(yylineno);
1563 checkmem($$);
1564 $$->type = $1;
1565 ret = asn1p_constraint_insert($$, $3);
1566 checkmem(ret == 0);
1567 }
1568 | '(' ElementSetSpecs ')' {
1569 int ret;
1570 $$ = asn1p_constraint_new(yylineno);
1571 checkmem($$);
1572 $$->type = ACT_CA_SET;
1573 ret = asn1p_constraint_insert($$, $2);
1574 checkmem(ret == 0);
1575 }
vlma6a12e32005-03-20 12:58:00 +00001576 | SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001577 $$ = asn1p_constraint_new(yylineno);
1578 checkmem($$);
1579 $$->type = ACT_EL_VALUE;
1580 $$->value = $1;
1581 }
vlma6a12e32005-03-20 12:58:00 +00001582 | ContainedSubtype {
1583 $$ = asn1p_constraint_new(yylineno);
1584 checkmem($$);
1585 $$->type = ACT_EL_TYPE;
1586 $$->containedSubtype = $1;
1587 }
1588 | SingleValue ConstraintRangeSpec SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001589 $$ = asn1p_constraint_new(yylineno);
1590 checkmem($$);
1591 $$->type = $2;
1592 $$->range_start = $1;
1593 $$->range_stop = $3;
1594 }
vlma6a12e32005-03-20 12:58:00 +00001595 | TOK_MIN ConstraintRangeSpec SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001596 $$ = asn1p_constraint_new(yylineno);
1597 checkmem($$);
vlm9283dbe2004-08-18 04:59:12 +00001598 $$->type = $2;
1599 $$->range_start = asn1p_value_fromint(-123);
1600 $$->range_stop = $3;
1601 $$->range_start->type = ATV_MIN;
1602 }
vlma6a12e32005-03-20 12:58:00 +00001603 | SingleValue ConstraintRangeSpec TOK_MAX {
vlm9283dbe2004-08-18 04:59:12 +00001604 $$ = asn1p_constraint_new(yylineno);
1605 checkmem($$);
1606 $$->type = $2;
1607 $$->range_start = $1;
1608 $$->range_stop = asn1p_value_fromint(321);
1609 $$->range_stop->type = ATV_MAX;
1610 }
1611 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1612 $$ = asn1p_constraint_new(yylineno);
1613 checkmem($$);
1614 $$->type = $2;
1615 $$->range_start = asn1p_value_fromint(-123);
1616 $$->range_stop = asn1p_value_fromint(321);
1617 $$->range_start->type = ATV_MIN;
1618 $$->range_stop->type = ATV_MAX;
vlmfa67ddc2004-06-03 03:38:44 +00001619 }
1620 | TableConstraint {
1621 $$ = $1;
1622 }
1623 | WithComponents {
1624 $$ = $1;
1625 }
1626 ;
1627
1628ConstraintRangeSpec:
1629 TOK_TwoDots { $$ = ACT_EL_RANGE; }
1630 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
1631 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
1632 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
1633 ;
1634
1635ConstraintSpec:
1636 TOK_SIZE {
1637 $$ = ACT_CT_SIZE;
1638 }
1639 | TOK_FROM {
1640 $$ = ACT_CT_FROM;
1641 }
1642 ;
1643
vlma6a12e32005-03-20 12:58:00 +00001644SingleValue:
vlm4053ca52005-02-18 16:34:21 +00001645 TOK_FALSE {
1646 $$ = asn1p_value_fromint(0);
1647 checkmem($$);
1648 $$->type = ATV_FALSE;
1649 }
1650 | TOK_TRUE {
1651 $$ = asn1p_value_fromint(1);
1652 checkmem($$);
1653 $$->type = ATV_TRUE;
1654 }
1655 | SignedNumber {
vlmfa67ddc2004-06-03 03:38:44 +00001656 $$ = $1;
1657 }
vlm4053ca52005-02-18 16:34:21 +00001658 | TOK_cstring {
1659 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1660 checkmem($$);
1661 }
vlmfa67ddc2004-06-03 03:38:44 +00001662 | Identifier {
1663 asn1p_ref_t *ref;
1664 int ret;
1665 ref = asn1p_ref_new(yylineno);
1666 checkmem(ref);
1667 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1668 checkmem(ret == 0);
1669 $$ = asn1p_value_fromref(ref, 0);
1670 checkmem($$);
1671 free($1);
1672 }
vlma6a12e32005-03-20 12:58:00 +00001673 ;
1674
1675ContainedSubtype:
1676 TypeRefName {
vlm4053ca52005-02-18 16:34:21 +00001677 asn1p_ref_t *ref;
1678 int ret;
1679 ref = asn1p_ref_new(yylineno);
1680 checkmem(ref);
1681 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1682 checkmem(ret == 0);
1683 $$ = asn1p_value_fromref(ref, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001684 checkmem($$);
vlm4053ca52005-02-18 16:34:21 +00001685 free($1);
vlmfa67ddc2004-06-03 03:38:44 +00001686 }
1687 ;
1688
1689WithComponents:
1690 TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
1691 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
1692 }
1693 ;
1694
1695WithComponentsList:
1696 WithComponentsElement {
1697 $$ = $1;
1698 }
1699 | WithComponentsList ',' WithComponentsElement {
1700 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
1701 }
1702 ;
1703
1704WithComponentsElement:
1705 TOK_ThreeDots {
1706 $$ = asn1p_constraint_new(yylineno);
1707 checkmem($$);
1708 $$->type = ACT_EL_EXT;
1709 }
1710 | Identifier optConstraints optPresenceConstraint {
1711 $$ = asn1p_constraint_new(yylineno);
1712 checkmem($$);
1713 $$->type = ACT_EL_VALUE;
1714 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1715 $$->presence = $3;
1716 }
1717 ;
1718
1719/*
1720 * presence constraint for WithComponents
1721 */
1722optPresenceConstraint:
1723 { $$ = ACPRES_DEFAULT; }
1724 | PresenceConstraint { $$ = $1; }
1725 ;
1726
1727PresenceConstraint:
1728 TOK_PRESENT {
1729 $$ = ACPRES_PRESENT;
1730 }
1731 | TOK_ABSENT {
1732 $$ = ACPRES_ABSENT;
1733 }
1734 | TOK_OPTIONAL {
1735 $$ = ACPRES_OPTIONAL;
1736 }
1737 ;
1738
1739TableConstraint:
1740 SimpleTableConstraint {
1741 $$ = $1;
1742 }
1743 | ComponentRelationConstraint {
1744 $$ = $1;
1745 }
1746 ;
1747
1748/*
1749 * "{ExtensionSet}"
1750 */
1751SimpleTableConstraint:
1752 '{' TypeRefName '}' {
1753 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
1754 asn1p_constraint_t *ct;
1755 int ret;
1756 ret = asn1p_ref_add_component(ref, $2, 0);
1757 checkmem(ret == 0);
1758 ct = asn1p_constraint_new(yylineno);
1759 checkmem($$);
1760 ct->type = ACT_EL_VALUE;
1761 ct->value = asn1p_value_fromref(ref, 0);
1762 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
1763 }
1764 ;
1765
1766ComponentRelationConstraint:
1767 SimpleTableConstraint '{' AtNotationList '}' {
1768 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
1769 }
1770 ;
1771
1772AtNotationList:
1773 AtNotationElement {
1774 $$ = asn1p_constraint_new(yylineno);
1775 checkmem($$);
1776 $$->type = ACT_EL_VALUE;
1777 $$->value = asn1p_value_fromref($1, 0);
1778 }
1779 | AtNotationList ',' AtNotationElement {
1780 asn1p_constraint_t *ct;
1781 ct = asn1p_constraint_new(yylineno);
1782 checkmem(ct);
1783 ct->type = ACT_EL_VALUE;
1784 ct->value = asn1p_value_fromref($3, 0);
1785 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
1786 }
1787 ;
1788
1789/*
1790 * @blah
1791 */
1792AtNotationElement:
1793 '@' ComponentIdList {
1794 char *p = malloc(strlen($2) + 2);
1795 int ret;
1796 *p = '@';
1797 strcpy(p + 1, $2);
1798 $$ = asn1p_ref_new(yylineno);
1799 ret = asn1p_ref_add_component($$, p, 0);
1800 checkmem(ret == 0);
1801 free(p);
1802 free($2);
1803 }
1804 | '@' '.' ComponentIdList {
1805 char *p = malloc(strlen($3) + 3);
1806 int ret;
1807 p[0] = '@';
1808 p[1] = '.';
1809 strcpy(p + 2, $3);
1810 $$ = asn1p_ref_new(yylineno);
1811 ret = asn1p_ref_add_component($$, p, 0);
1812 checkmem(ret == 0);
1813 free(p);
1814 free($3);
1815 }
1816 ;
1817
1818/* identifier "." ... */
1819ComponentIdList:
1820 Identifier {
1821 $$ = $1;
1822 }
1823 | ComponentIdList '.' Identifier {
1824 int l1 = strlen($1);
1825 int l3 = strlen($3);
1826 $$ = malloc(l1 + 1 + l3 + 1);
1827 memcpy($$, $1, l1);
1828 $$[l1] = '.';
1829 memcpy($$ + l1 + 1, $3, l3);
1830 $$[l1 + 1 + l3] = '\0';
1831 }
1832 ;
1833
1834
1835
1836/*
1837 * MARKERS
1838 */
1839
1840optMarker:
vlmc94e28f2004-09-15 11:59:51 +00001841 {
1842 $$.flags = EM_NOMARK;
1843 $$.default_value = 0;
1844 }
vlmfa67ddc2004-06-03 03:38:44 +00001845 | Marker { $$ = $1; }
1846 ;
1847
1848Marker:
1849 TOK_OPTIONAL {
vlmc94e28f2004-09-15 11:59:51 +00001850 $$.flags = EM_OPTIONAL;
1851 $$.default_value = 0;
vlmfa67ddc2004-06-03 03:38:44 +00001852 }
vlmc94e28f2004-09-15 11:59:51 +00001853 | TOK_DEFAULT Value {
1854 $$.flags = EM_DEFAULT;
1855 $$.default_value = $2;
vlmfa67ddc2004-06-03 03:38:44 +00001856 }
1857 ;
1858
1859/*
1860 * Universal enumeration definition to use in INTEGER and ENUMERATED.
1861 * === EXAMPLE ===
1862 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
1863 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
1864 * === EOF ===
1865 */
1866/*
1867optUniverationDefinition:
1868 { $$ = 0; }
1869 | UniverationDefinition {
1870 $$ = $1;
1871 }
1872 ;
1873*/
1874
1875UniverationDefinition:
1876 '{' '}' {
vlm39e5ed72004-09-05 10:40:41 +00001877 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001878 checkmem($$);
1879 }
1880 | '{' UniverationList '}' {
1881 $$ = $2;
1882 }
1883 ;
1884
1885UniverationList:
1886 UniverationElement {
vlm39e5ed72004-09-05 10:40:41 +00001887 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001888 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +00001889 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +00001890 }
1891 | UniverationList ',' UniverationElement {
1892 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +00001893 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001894 }
1895 ;
1896
1897UniverationElement:
1898 Identifier {
vlm39e5ed72004-09-05 10:40:41 +00001899 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001900 checkmem($$);
1901 $$->expr_type = A1TC_UNIVERVAL;
1902 $$->meta_type = AMT_VALUE;
1903 $$->Identifier = $1;
1904 }
1905 | Identifier '(' SignedNumber ')' {
vlm39e5ed72004-09-05 10:40:41 +00001906 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001907 checkmem($$);
1908 $$->expr_type = A1TC_UNIVERVAL;
1909 $$->meta_type = AMT_VALUE;
1910 $$->Identifier = $1;
1911 $$->value = $3;
1912 }
1913 | Identifier '(' DefinedValue ')' {
vlm39e5ed72004-09-05 10:40:41 +00001914 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001915 checkmem($$);
1916 $$->expr_type = A1TC_UNIVERVAL;
1917 $$->meta_type = AMT_VALUE;
1918 $$->Identifier = $1;
1919 $$->value = $3;
1920 }
1921 | SignedNumber {
vlm39e5ed72004-09-05 10:40:41 +00001922 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001923 checkmem($$);
1924 $$->expr_type = A1TC_UNIVERVAL;
1925 $$->meta_type = AMT_VALUE;
1926 $$->value = $1;
1927 }
1928 | TOK_ThreeDots {
vlm39e5ed72004-09-05 10:40:41 +00001929 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001930 checkmem($$);
1931 $$->Identifier = strdup("...");
1932 checkmem($$->Identifier);
1933 $$->expr_type = A1TC_EXTENSIBLE;
1934 $$->meta_type = AMT_VALUE;
1935 }
1936 ;
1937
1938SignedNumber:
1939 TOK_number {
1940 $$ = asn1p_value_fromint($1);
1941 checkmem($$);
1942 }
1943 | TOK_number_negative {
1944 $$ = asn1p_value_fromint($1);
1945 checkmem($$);
1946 }
1947 ;
1948
1949/*
1950 * SEQUENCE definition.
1951 * === EXAMPLE ===
1952 * Struct1 ::= SEQUENCE {
1953 * memb1 Struct2,
1954 * memb2 SEQUENCE OF {
1955 * memb2-1 Struct 3
1956 * }
1957 * }
1958 * === EOF ===
1959 */
1960
1961
1962
1963/*
1964 * SET definition.
1965 * === EXAMPLE ===
1966 * Person ::= SET {
1967 * name [0] PrintableString (SIZE(1..20)),
1968 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
1969 * }
1970 * === EOF ===
1971 */
1972
1973optTag:
1974 { memset(&$$, 0, sizeof($$)); }
1975 | Tag { $$ = $1; }
1976 ;
1977
1978Tag:
vlm2728a8d2005-01-23 09:51:44 +00001979 TagTypeValue TagPlicit {
vlmfa67ddc2004-06-03 03:38:44 +00001980 $$ = $1;
vlm2728a8d2005-01-23 09:51:44 +00001981 $$.tag_mode = $2.tag_mode;
vlmfa67ddc2004-06-03 03:38:44 +00001982 }
vlm2728a8d2005-01-23 09:51:44 +00001983 ;
1984
1985TagTypeValue:
1986 '[' TagClass TOK_number ']' {
1987 $$ = $2;
1988 $$.tag_value = $3;
1989 };
1990
1991TagClass:
1992 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
1993 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
1994 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
1995 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
1996 ;
1997
1998TagPlicit:
1999 { $$.tag_mode = TM_DEFAULT; }
2000 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2001 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
vlmfa67ddc2004-06-03 03:38:44 +00002002 ;
2003
2004TypeRefName:
2005 TOK_typereference {
2006 checkmem($1);
2007 $$ = $1;
2008 }
vlm9283dbe2004-08-18 04:59:12 +00002009 | TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00002010 checkmem($1);
2011 $$ = $1;
2012 }
2013 ;
2014
vlm9283dbe2004-08-18 04:59:12 +00002015
vlmfa67ddc2004-06-03 03:38:44 +00002016ObjectClassReference:
vlm9283dbe2004-08-18 04:59:12 +00002017 TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00002018 checkmem($1);
2019 $$ = $1;
2020 }
2021 ;
2022
vlm151c0b22004-09-22 16:03:36 +00002023optIdentifier:
2024 { $$ = 0; }
2025 | Identifier {
2026 $$ = $1;
2027 }
2028
vlmfa67ddc2004-06-03 03:38:44 +00002029Identifier:
2030 TOK_identifier {
2031 checkmem($1);
2032 $$ = $1;
2033 }
2034 ;
2035
vlmfa67ddc2004-06-03 03:38:44 +00002036%%
2037
2038
2039/*
2040 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2041 */
2042static asn1p_value_t *
2043_convert_bitstring2binary(char *str, int base) {
2044 asn1p_value_t *val;
2045 int slen;
2046 int memlen;
2047 int baselen;
2048 int bits;
2049 uint8_t *binary_vector;
2050 uint8_t *bv_ptr;
2051 uint8_t cur_val;
2052
2053 assert(str);
2054 assert(str[0] == '\'');
2055
2056 switch(base) {
2057 case 'B':
2058 baselen = 1;
2059 break;
2060 case 'H':
2061 baselen = 4;
2062 break;
2063 default:
2064 assert(base == 'B' || base == 'H');
2065 errno = EINVAL;
2066 return NULL;
2067 }
2068
2069 slen = strlen(str);
2070 assert(str[slen - 1] == base);
2071 assert(str[slen - 2] == '\'');
2072
2073 memlen = slen / (8 / baselen); /* Conservative estimate */
2074
2075 bv_ptr = binary_vector = malloc(memlen + 1);
2076 if(bv_ptr == NULL)
2077 /* ENOMEM */
2078 return NULL;
2079
2080 cur_val = 0;
2081 bits = 0;
2082 while(*(++str) != '\'') {
2083 switch(baselen) {
2084 case 1:
2085 switch(*str) {
2086 case '1':
2087 cur_val |= 1 << (7 - (bits % 8));
2088 case '0':
2089 break;
2090 default:
2091 assert(!"_y UNREACH1");
2092 case ' ': case '\r': case '\n':
2093 continue;
2094 }
2095 break;
2096 case 4:
2097 switch(*str) {
2098 case '0': case '1': case '2': case '3': case '4':
2099 case '5': case '6': case '7': case '8': case '9':
2100 cur_val |= (*str - '0') << (4 - (bits % 8));
2101 break;
2102 case 'A': case 'B': case 'C':
2103 case 'D': case 'E': case 'F':
2104 cur_val |= ((*str - 'A') + 10)
2105 << (4 - (bits % 8));
2106 break;
2107 default:
2108 assert(!"_y UNREACH2");
2109 case ' ': case '\r': case '\n':
2110 continue;
2111 }
2112 break;
2113 }
2114
2115 bits += baselen;
2116 if((bits % 8) == 0) {
2117 *bv_ptr++ = cur_val;
2118 cur_val = 0;
2119 }
2120 }
2121
2122 *bv_ptr = cur_val;
2123 assert((bv_ptr - binary_vector) <= memlen);
2124
2125 val = asn1p_value_frombits(binary_vector, bits, 0);
2126 if(val == NULL) {
2127 free(binary_vector);
2128 }
2129
2130 return val;
2131}
2132
2133extern char *asn1p_text;
2134
2135int
2136yyerror(const char *msg) {
2137 fprintf(stderr,
2138 "ASN.1 grammar parse error "
2139 "near line %d (token \"%s\"): %s\n",
vlm39e5ed72004-09-05 10:40:41 +00002140 yylineno, asn1p_text, msg);
vlmfa67ddc2004-06-03 03:38:44 +00002141 return -1;
2142}
2143
2144