blob: 3e712509e5d3a26e75b86f3bf148ff62ee08352a [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
26#define checkmem(ptr) do { \
27 if(!(ptr)) \
28 return yyerror("Memory failure"); \
29 } 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 */
77 enum asn1p_expr_marker_e a_marker; /* OPTIONAL/DEFAULT */
78 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*/
236%type <a_value> optValueSetBody
237%type <a_value> InlineOrDefinedValue
238%type <a_value> DefinedValue
239%type <a_value> SignedNumber
vlmec8f6812004-08-22 03:19:54 +0000240%type <a_expr> ComponentTypeLists
241%type <a_expr> ComponentType
242%type <a_expr> AlternativeTypeLists
243%type <a_expr> AlternativeType
vlmfa67ddc2004-06-03 03:38:44 +0000244//%type <a_expr> optUniverationDefinition
245%type <a_expr> UniverationDefinition
246%type <a_expr> UniverationList
247%type <a_expr> UniverationElement
248%type <tv_str> TypeRefName
249%type <tv_str> ObjectClassReference
250%type <tv_nametag> TaggedIdentifier
251%type <tv_str> Identifier
252%type <a_parg> ParameterArgumentName
253%type <a_plist> ParameterArgumentList
254%type <a_expr> ActualParameter
255%type <a_expr> ActualParameterList
256%type <a_oid> ObjectIdentifier /* OID */
257%type <a_oid> optObjectIdentifier /* Optional OID */
258%type <a_oid> ObjectIdentifierBody
259%type <a_oid_arc> ObjectIdentifierElement
260%type <a_expr> BasicType
261%type <a_type> BasicTypeId
262%type <a_type> BasicTypeId_UniverationCompatible
263%type <a_type> BasicString
264%type <tv_opaque> Opaque
265//%type <tv_opaque> StringValue
266%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
267%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
268%type <a_constr> optConstraints
vlm5f0128b2004-08-20 13:25:29 +0000269%type <a_constr> Constraints
vlm9283dbe2004-08-18 04:59:12 +0000270%type <a_constr> SetOfConstraints
271%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
272%type <a_constr> ElementSetSpec /* 1..2,...,3 */
vlmfa67ddc2004-06-03 03:38:44 +0000273%type <a_constr> ConstraintSubtypeElement /* 1..2 */
vlmfa67ddc2004-06-03 03:38:44 +0000274%type <a_constr> SimpleTableConstraint
275%type <a_constr> TableConstraint
276%type <a_constr> WithComponents
277%type <a_constr> WithComponentsList
278%type <a_constr> WithComponentsElement
279%type <a_constr> ComponentRelationConstraint
280%type <a_constr> AtNotationList
281%type <a_ref> AtNotationElement
282%type <a_value> ConstraintValue
283%type <a_ctype> ConstraintSpec
284%type <a_ctype> ConstraintRangeSpec
285%type <a_wsynt> optWithSyntax
286%type <a_wsynt> WithSyntax
287%type <a_wsynt> WithSyntaxFormat
288%type <a_wchunk> WithSyntaxFormatToken
289%type <a_marker> optMarker Marker
290%type <a_int> optUnique
291%type <a_pres> optPresenceConstraint PresenceConstraint
292%type <tv_str> ComponentIdList
293
294
295%%
296
297
298ParsedGrammar:
299 ModuleList {
300 *(void **)param = $1;
301 }
302 ;
303
304ModuleList:
305 ModuleSpecification {
306 $$ = asn1p_new();
307 checkmem($$);
308 TQ_ADD(&($$->modules), $1, mod_next);
309 }
310 | ModuleList ModuleSpecification {
311 $$ = $1;
312 TQ_ADD(&($$->modules), $2, mod_next);
313 }
314 ;
315
316/*
317 * ASN module definition.
318 * === EXAMPLE ===
319 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
320 * BEGIN
321 * ...
322 * END
323 * === EOF ===
324 */
325
326ModuleSpecification:
327 TypeRefName optObjectIdentifier TOK_DEFINITIONS
328 optModuleSpecificationFlags
329 TOK_PPEQ TOK_BEGIN
330 optModuleSpecificationBody
331 TOK_END {
332
333 if($7) {
334 $$ = $7;
335 } else {
336 /* There's a chance that a module is just plain empty */
337 $$ = asn1p_module_new();
338 }
339 checkmem($$);
340
341 $$->Identifier = $1;
342 $$->module_oid = $2;
343 $$->module_flags = $4;
344 }
345 ;
346
347/*
348 * Object Identifier Definition
349 * { iso member-body(2) 3 }
350 */
351optObjectIdentifier:
352 { $$ = 0; }
353 | ObjectIdentifier { $$ = $1; }
354 ;
355
356ObjectIdentifier:
357 '{' ObjectIdentifierBody '}' {
358 $$ = $2;
359 }
360 | '{' '}' {
361 $$ = 0;
362 }
363 ;
364
365ObjectIdentifierBody:
366 ObjectIdentifierElement {
367 $$ = asn1p_oid_new();
368 asn1p_oid_add_arc($$, &$1);
369 if($1.name)
370 free($1.name);
371 }
372 | ObjectIdentifierBody ObjectIdentifierElement {
373 $$ = $1;
374 asn1p_oid_add_arc($$, &$2);
375 if($2.name)
376 free($2.name);
377 }
378 ;
379
380ObjectIdentifierElement:
381 Identifier { /* iso */
382 $$.name = $1;
383 $$.number = -1;
384 }
385 | Identifier '(' TOK_number ')' { /* iso(1) */
386 $$.name = $1;
387 $$.number = $3;
388 }
389 | TOK_number { /* 1 */
390 $$.name = 0;
391 $$.number = $1;
392 }
393 ;
394
395/*
396 * Optional module flags.
397 */
398optModuleSpecificationFlags:
399 { $$ = MSF_NOFLAGS; }
400 | ModuleSpecificationFlags {
401 $$ = $1;
402 }
403 ;
404
405/*
406 * Module flags.
407 */
408ModuleSpecificationFlags:
409 ModuleSpecificationFlag {
410 $$ = $1;
411 }
412 | ModuleSpecificationFlags ModuleSpecificationFlag {
413 $$ = $1 | $2;
414 }
415 ;
416
417/*
418 * Single module flag.
419 */
420ModuleSpecificationFlag:
421 TOK_EXPLICIT TOK_TAGS {
422 $$ = MSF_EXPLICIT_TAGS;
423 }
424 | TOK_IMPLICIT TOK_TAGS {
425 $$ = MSF_IMPLICIT_TAGS;
426 }
427 | TOK_AUTOMATIC TOK_TAGS {
428 $$ = MSF_AUTOMATIC_TAGS;
429 }
430 | TOK_EXTENSIBILITY TOK_IMPLIED {
431 $$ = MSF_EXTENSIBILITY_IMPLIED;
432 }
vlm9283dbe2004-08-18 04:59:12 +0000433 /* EncodingReferenceDefault */
434 | TOK_capitalreference TOK_INSTRUCTIONS {
435 /* X.680Amd1 specifies TAG and XER */
436 if(strcmp($1, "TAG") == 0) {
437 $$ = MSF_TAG_INSTRUCTIONS;
438 } else if(strcmp($1, "XER") == 0) {
439 $$ = MSF_XER_INSTRUCTIONS;
440 } else {
441 fprintf(stderr,
442 "WARNING: %s INSTRUCTIONS at line %d: "
443 "Unrecognized encoding reference\n",
444 $1, yylineno);
445 $$ = MSF_unk_INSTRUCTIONS;
446 }
447 free($1);
448 }
vlmfa67ddc2004-06-03 03:38:44 +0000449 ;
450
451/*
452 * Optional module body.
453 */
454optModuleSpecificationBody:
455 { $$ = 0; }
456 | ModuleSpecificationBody {
vlmfa67ddc2004-06-03 03:38:44 +0000457 $$ = $1;
458 }
459 ;
460
461/*
462 * ASN.1 Module body.
463 */
464ModuleSpecificationBody:
465 ModuleSpecificationElement {
466 $$ = $1;
467 }
468 | ModuleSpecificationBody ModuleSpecificationElement {
469 $$ = $1;
470
vlm9283dbe2004-08-18 04:59:12 +0000471 /* Behave well when one of them is skipped. */
472 if(!($1)) {
473 if($2) $$ = $2;
474 break;
475 }
476
vlmfa67ddc2004-06-03 03:38:44 +0000477#ifdef MY_IMPORT
478#error MY_IMPORT DEFINED ELSEWHERE!
479#endif
480#define MY_IMPORT(foo,field) do { \
vlm97ed7152004-08-13 12:31:09 +0000481 while(TQ_FIRST(&($2->foo))) { \
vlmfa67ddc2004-06-03 03:38:44 +0000482 TQ_ADD(&($$->foo), \
483 TQ_REMOVE(&($2->foo), field), \
484 field); \
vlm97ed7152004-08-13 12:31:09 +0000485 } \
486 assert(TQ_FIRST(&($2->foo)) == 0); \
487 } while(0)
vlmfa67ddc2004-06-03 03:38:44 +0000488
489 MY_IMPORT(imports, xp_next);
490 MY_IMPORT(exports, xp_next);
491 MY_IMPORT(members, next);
492#undef MY_IMPORT
493
494 }
495 ;
496
497/*
498 * One of the elements of ASN.1 module specification.
499 */
500ModuleSpecificationElement:
501 ImportsDefinition {
502 $$ = $1;
503 }
504 | ExportsDefinition {
505 $$ = asn1p_module_new();
506 checkmem($$);
507 if($1) {
508 TQ_ADD(&($$->exports), $1, xp_next);
509 } else {
510 /* "EXPORTS ALL;" ? */
511 }
512 }
513 | DataTypeReference {
514 $$ = asn1p_module_new();
515 checkmem($$);
516 assert($1->expr_type != A1TC_INVALID);
517 assert($1->meta_type != AMT_INVALID);
518 TQ_ADD(&($$->members), $1, next);
519 }
520 | ValueDefinition {
521 $$ = asn1p_module_new();
522 checkmem($$);
523 assert($1->expr_type != A1TC_INVALID);
524 assert($1->meta_type != AMT_INVALID);
525 TQ_ADD(&($$->members), $1, next);
526 }
527 /*
528 * Value set definition
529 * === EXAMPLE ===
530 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
531 * === EOF ===
532 */
533 | ValueSetDefinition {
534 $$ = asn1p_module_new();
535 checkmem($$);
536 assert($1->expr_type != A1TC_INVALID);
537 assert($1->meta_type != AMT_INVALID);
538 TQ_ADD(&($$->members), $1, next);
539 }
vlm9283dbe2004-08-18 04:59:12 +0000540 | TOK_ENCODING_CONTROL TOK_capitalreference
541 { asn1p_lexer_hack_push_encoding_control(); }
542 {
543 fprintf(stderr,
544 "WARNING: ENCODING-CONTROL %s "
545 "specification at line %d ignored\n",
546 $2, yylineno);
547 free($2);
548 $$ = 0;
549 }
vlmfa67ddc2004-06-03 03:38:44 +0000550
551 /*
552 * Erroneous attemps
553 */
554 | BasicString {
555 return yyerror(
556 "Attempt to redefine a standard basic type, "
557 "use -ftypesXY to switch back "
558 "to older version of ASN.1 standard");
559 }
560 ;
561
562/*
563 * === EXAMPLE ===
564 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
565 * === EOF ===
566 */
567ImportsDefinition:
568 TOK_IMPORTS ImportsBundleSet ';' {
569 $$ = $2;
570 }
571 /*
572 * Some error cases.
573 */
574 | TOK_IMPORTS TOK_FROM /* ... */ {
575 return yyerror("Empty IMPORTS list");
576 }
577 ;
578
579ImportsBundleSet:
580 ImportsBundle {
581 $$ = asn1p_module_new();
582 checkmem($$);
583 TQ_ADD(&($$->imports), $1, xp_next);
584 }
585 | ImportsBundleSet ImportsBundle {
586 $$ = $1;
587 TQ_ADD(&($$->imports), $2, xp_next);
588 }
589 ;
590
591ImportsBundle:
592 ImportsList TOK_FROM TypeRefName optObjectIdentifier {
593 $$ = $1;
594 $$->from = $3;
595 $$->from_oid = $4;
596 checkmem($$);
597 }
598 ;
599
600ImportsList:
601 ImportsElement {
602 $$ = asn1p_xports_new();
603 checkmem($$);
604 TQ_ADD(&($$->members), $1, next);
605 }
606 | ImportsList ',' ImportsElement {
607 $$ = $1;
608 TQ_ADD(&($$->members), $3, next);
609 }
610 ;
611
612ImportsElement:
613 TypeRefName {
614 $$ = asn1p_expr_new(yylineno);
615 checkmem($$);
616 $$->Identifier = $1;
617 $$->expr_type = A1TC_REFERENCE;
618 }
619 | Identifier {
620 $$ = asn1p_expr_new(yylineno);
621 checkmem($$);
622 $$->Identifier = $1;
623 $$->expr_type = A1TC_REFERENCE;
624 }
625 ;
626
627ExportsDefinition:
628 TOK_EXPORTS ExportsBody ';' {
629 $$ = $2;
630 }
631 | TOK_EXPORTS TOK_ALL ';' {
632 $$ = 0;
633 }
634 | TOK_EXPORTS ';' {
635 /* Empty EXPORTS clause effectively prohibits export. */
636 $$ = asn1p_xports_new();
637 checkmem($$);
638 }
639 ;
640
641ExportsBody:
642 ExportsElement {
643 $$ = asn1p_xports_new();
644 assert($$);
645 TQ_ADD(&($$->members), $1, next);
646 }
647 | ExportsBody ',' ExportsElement {
648 $$ = $1;
649 TQ_ADD(&($$->members), $3, next);
650 }
651 ;
652
653ExportsElement:
654 TypeRefName {
655 $$ = asn1p_expr_new(yylineno);
656 checkmem($$);
657 $$->Identifier = $1;
658 $$->expr_type = A1TC_EXPORTVAR;
659 }
660 | Identifier {
661 $$ = asn1p_expr_new(yylineno);
662 checkmem($$);
663 $$->Identifier = $1;
664 $$->expr_type = A1TC_EXPORTVAR;
665 }
666 ;
667
668
669ValueSetDefinition:
670 TypeRefName DefinedTypeRef TOK_PPEQ '{' optValueSetBody '}' {
671 $$ = $2;
672 assert($$->Identifier == 0);
673 $$->Identifier = $1;
674 $$->meta_type = AMT_VALUESET;
675 // take care of optValueSetBody
676 }
677 ;
678
679DefinedTypeRef:
680 ComplexTypeReference {
681 $$ = asn1p_expr_new(yylineno);
682 checkmem($$);
683 $$->reference = $1;
684 $$->expr_type = A1TC_REFERENCE;
685 $$->meta_type = AMT_TYPEREF;
686 }
687 | BasicTypeId {
688 $$ = asn1p_expr_new(yylineno);
689 checkmem($$);
690 $$->expr_type = $1;
691 $$->meta_type = AMT_TYPE;
692 }
693 ;
694
695optValueSetBody:
696 { }
vlm9283dbe2004-08-18 04:59:12 +0000697 | ElementSetSpecs {
vlmfa67ddc2004-06-03 03:38:44 +0000698 }
699 ;
700
701
702/*
703 * Data Type Reference.
704 * === EXAMPLE ===
705 * Type3 ::= CHOICE { a Type1, b Type 2 }
706 * === EOF ===
707 */
708
709DataTypeReference:
710 /*
711 * Optionally tagged type definition.
712 */
713 TypeRefName TOK_PPEQ optTag TOK_TYPE_IDENTIFIER {
714 $$ = asn1p_expr_new(yylineno);
715 checkmem($$);
716 $$->Identifier = $1;
717 $$->tag = $3;
718 $$->expr_type = A1TC_TYPEID;
719 $$->meta_type = AMT_TYPE;
720 }
vlmec8f6812004-08-22 03:19:54 +0000721 | TypeRefName TOK_PPEQ optTag Type {
vlmfa67ddc2004-06-03 03:38:44 +0000722 $$ = $4;
723 $$->Identifier = $1;
724 $$->tag = $3;
725 assert($$->expr_type);
726 assert($$->meta_type);
727 }
728 | TypeRefName TOK_PPEQ ClassDeclaration {
729 $$ = $3;
730 $$->Identifier = $1;
731 assert($$->expr_type == A1TC_CLASSDEF);
732 assert($$->meta_type == AMT_OBJECT);
733 }
734 /*
735 * Parametrized <Type> declaration:
736 * === EXAMPLE ===
737 * SIGNED { ToBeSigned } ::= SEQUENCE {
738 * toBeSigned ToBeSigned,
739 * algorithm AlgorithmIdentifier,
740 * signature BIT STRING
741 * }
742 * === EOF ===
743 */
vlmec8f6812004-08-22 03:19:54 +0000744 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
vlmfa67ddc2004-06-03 03:38:44 +0000745 $$ = $6;
746 assert($$->Identifier == 0);
747 $$->Identifier = $1;
748 $$->params = $3;
749 $$->meta_type = AMT_PARAMTYPE;
750 }
751 ;
752
753ParameterArgumentList:
754 ParameterArgumentName {
755 int ret;
756 $$ = asn1p_paramlist_new(yylineno);
757 checkmem($$);
758 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
759 checkmem(ret == 0);
760 if($1.governor) asn1p_ref_free($1.governor);
761 if($1.argument) free($1.argument);
762 }
763 | ParameterArgumentList ',' ParameterArgumentName {
764 int ret;
765 $$ = $1;
766 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
767 checkmem(ret == 0);
768 if($3.governor) asn1p_ref_free($3.governor);
769 if($3.argument) free($3.argument);
770 }
771 ;
772
773ParameterArgumentName:
774 TypeRefName {
775 $$.governor = NULL;
776 $$.argument = $1;
777 }
778 | TypeRefName ':' Identifier {
779 int ret;
780 $$.governor = asn1p_ref_new(yylineno);
781 ret = asn1p_ref_add_component($$.governor, $1, 0);
782 checkmem(ret == 0);
783 $$.argument = $3;
784 }
785 | BasicTypeId ':' Identifier {
786 int ret;
787 $$.governor = asn1p_ref_new(yylineno);
788 ret = asn1p_ref_add_component($$.governor,
789 ASN_EXPR_TYPE2STR($1), 1);
790 checkmem(ret == 0);
791 $$.argument = $3;
792 }
793 ;
794
795ActualParameterList:
796 ActualParameter {
797 $$ = asn1p_expr_new(yylineno);
798 checkmem($$);
799 TQ_ADD(&($$->members), $1, next);
800 }
801 | ActualParameterList ',' ActualParameter {
802 $$ = $1;
803 TQ_ADD(&($$->members), $3, next);
804 }
805 ;
806
807ActualParameter:
vlmec8f6812004-08-22 03:19:54 +0000808 Type {
vlmfa67ddc2004-06-03 03:38:44 +0000809 $$ = $1;
810 }
811 | Identifier {
812 $$ = asn1p_expr_new(yylineno);
813 checkmem($$);
814 $$->Identifier = $1;
815 $$->expr_type = A1TC_REFERENCE;
816 $$->meta_type = AMT_VALUE;
817 }
818 ;
819
820/*
821 * A collection of constructed data type members.
822 */
vlmec8f6812004-08-22 03:19:54 +0000823ComponentTypeLists:
824 ComponentType {
vlmfa67ddc2004-06-03 03:38:44 +0000825 $$ = asn1p_expr_new(yylineno);
826 checkmem($$);
827 TQ_ADD(&($$->members), $1, next);
828 }
vlmec8f6812004-08-22 03:19:54 +0000829 | ComponentTypeLists ',' ComponentType {
vlmfa67ddc2004-06-03 03:38:44 +0000830 $$ = $1;
831 TQ_ADD(&($$->members), $3, next);
832 }
833 ;
834
vlmec8f6812004-08-22 03:19:54 +0000835ComponentType:
836 TaggedIdentifier Type optMarker {
837 $$ = $2;
838 assert($$->Identifier == 0);
839 $$->Identifier = $1.name;
840 $$->tag = $1.tag;
841 $$->marker = $3;
842 }
843 | TOK_COMPONENTS TOK_OF Type {
844 $$ = asn1p_expr_new(yylineno);
845 checkmem($$);
846 $$->meta_type = $3->meta_type;
847 $$->expr_type = A1TC_COMPONENTS_OF;
848 TQ_ADD(&($$->members), $3, next);
849 }
850 | ExtensionAndException {
851 $$ = $1;
852 }
853 ;
854
855AlternativeTypeLists:
856 AlternativeType {
857 $$ = asn1p_expr_new(yylineno);
858 checkmem($$);
859 TQ_ADD(&($$->members), $1, next);
860 }
861 | AlternativeTypeLists ',' AlternativeType {
862 $$ = $1;
863 TQ_ADD(&($$->members), $3, next);
864 }
865 ;
866
867AlternativeType:
868 TaggedIdentifier Type {
869 $$ = $2;
870 assert($$->Identifier == 0);
871 $$->Identifier = $1.name;
872 $$->tag = $1.tag;
873 }
874 | ExtensionAndException {
875 $$ = $1;
876 }
877 ;
878
vlmfa67ddc2004-06-03 03:38:44 +0000879ClassDeclaration:
880 TOK_CLASS '{' ClassFieldList '}' optWithSyntax {
881 $$ = $3;
882 checkmem($$);
883 $$->with_syntax = $5;
884 assert($$->expr_type == A1TC_CLASSDEF);
885 assert($$->meta_type == AMT_OBJECT);
886 }
887 ;
888
889optUnique:
890 { $$ = 0; }
891 | TOK_UNIQUE { $$ = 1; }
892 ;
893
894ClassFieldList:
895 ClassField {
896 $$ = asn1p_expr_new(yylineno);
897 checkmem($$);
898 $$->expr_type = A1TC_CLASSDEF;
899 $$->meta_type = AMT_OBJECT;
900 TQ_ADD(&($$->members), $1, next);
901 }
902 | ClassFieldList ',' ClassField {
903 $$ = $1;
904 TQ_ADD(&($$->members), $3, next);
905 }
906 ;
907
908ClassField:
909 ClassFieldIdentifier optMarker {
910 $$ = asn1p_expr_new(yylineno);
911 checkmem($$);
912 $$->Identifier = $1.name;
913 $$->expr_type = A1TC_CLASSFIELD;
914 $$->meta_type = AMT_OBJECTFIELD;
915 $$->marker = $2;
916 }
vlmec8f6812004-08-22 03:19:54 +0000917 | ClassFieldIdentifier Type optMarker optUnique {
vlmfa67ddc2004-06-03 03:38:44 +0000918 $$ = $2;
919 $$->Identifier = $1.name;
vlmec8f6812004-08-22 03:19:54 +0000920 $$->marker = $3;
921 $$->unique = $4;
vlmfa67ddc2004-06-03 03:38:44 +0000922 }
923 | ClassFieldIdentifier ClassFieldIdentifier optMarker optUnique {
924 int ret;
925 $$ = asn1p_expr_new(yylineno);
926 checkmem($$);
927 $$->Identifier = $1.name;
928 $$->reference = asn1p_ref_new(yylineno);
929 checkmem($$->reference);
930 ret = asn1p_ref_add_component($$->reference,
931 $2.name, $2.lex_type);
932 checkmem(ret == 0);
933 $$->expr_type = A1TC_CLASSFIELD;
934 $$->meta_type = AMT_OBJECTFIELD;
935 $$->marker = $3;
936 $$->unique = $4;
937 }
938 ;
939
940optWithSyntax:
941 { $$ = 0; }
942 | WithSyntax {
943 $$ = $1;
944 }
945 ;
946
947WithSyntax:
948 TOK_WITH TOK_SYNTAX '{'
949 { asn1p_lexer_hack_enable_with_syntax(); }
950 WithSyntaxFormat
951 '}' {
952 $$ = $5;
953 }
954 ;
955
956WithSyntaxFormat:
957 WithSyntaxFormatToken {
958 $$ = asn1p_wsyntx_new();
959 TQ_ADD(&($$->chunks), $1, next);
960 }
961 | WithSyntaxFormat WithSyntaxFormatToken {
962 $$ = $1;
963 TQ_ADD(&($$->chunks), $2, next);
964 }
965 ;
966
967WithSyntaxFormatToken:
968 TOK_opaque {
969 $$ = asn1p_wsyntx_chunk_frombuf($1.buf, $1.len, 0);
970 }
971 | ClassFieldIdentifier {
972 asn1p_ref_t *ref;
973 int ret;
974 ref = asn1p_ref_new(yylineno);
975 checkmem(ref);
976 ret = asn1p_ref_add_component(ref, $1.name, $1.lex_type);
977 checkmem(ret == 0);
978 $$ = asn1p_wsyntx_chunk_fromref(ref, 0);
979 }
980 ;
981
vlmfa67ddc2004-06-03 03:38:44 +0000982ExtensionAndException:
983 TOK_ThreeDots {
984 $$ = asn1p_expr_new(asn1p_lineno);
985 checkmem($$);
986 $$->Identifier = strdup("...");
987 checkmem($$->Identifier);
988 $$->expr_type = A1TC_EXTENSIBLE;
989 $$->meta_type = AMT_TYPE;
990 }
991 | TOK_ThreeDots '!' DefinedValue {
992 $$ = asn1p_expr_new(asn1p_lineno);
993 checkmem($$);
994 $$->Identifier = strdup("...");
995 checkmem($$->Identifier);
996 $$->value = $3;
997 $$->expr_type = A1TC_EXTENSIBLE;
998 $$->meta_type = AMT_TYPE;
999 }
1000 | TOK_ThreeDots '!' SignedNumber {
1001 $$ = asn1p_expr_new(asn1p_lineno);
1002 checkmem($$);
1003 $$->Identifier = strdup("...");
1004 $$->value = $3;
1005 checkmem($$->Identifier);
1006 $$->expr_type = A1TC_EXTENSIBLE;
1007 $$->meta_type = AMT_TYPE;
1008 }
1009 ;
1010
vlmec8f6812004-08-22 03:19:54 +00001011Type:
1012 TypeDeclaration optConstraints {
1013 $$ = $1;
1014 /*
1015 * Outer constraint for SEQUENCE OF and SET OF applies
1016 * to the inner type.
1017 */
1018 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1019 || $$->expr_type == ASN_CONSTR_SET_OF) {
1020 assert(!TQ_FIRST(&($$->members))->constraints);
1021 TQ_FIRST(&($$->members))->constraints = $2;
1022 } else {
1023 if($$->constraints) {
1024 assert(!$2);
1025 } else {
1026 $$->constraints = $2;
1027 }
1028 }
1029 }
1030 ;
1031
1032TypeDeclaration:
vlmfa67ddc2004-06-03 03:38:44 +00001033 BasicType {
1034 $$ = $1;
1035 }
1036 | BasicString {
1037 $$ = asn1p_expr_new(yylineno);
1038 checkmem($$);
1039 $$->expr_type = $1;
1040 $$->meta_type = AMT_TYPE;
1041 }
vlmec8f6812004-08-22 03:19:54 +00001042 | TOK_CHOICE '{' AlternativeTypeLists '}' {
1043 $$ = $3;
1044 assert($$->expr_type == A1TC_INVALID);
1045 $$->expr_type = ASN_CONSTR_CHOICE;
1046 $$->meta_type = AMT_TYPE;
vlmfa67ddc2004-06-03 03:38:44 +00001047 }
vlmec8f6812004-08-22 03:19:54 +00001048 | TOK_SEQUENCE '{' ComponentTypeLists '}' {
1049 $$ = $3;
1050 assert($$->expr_type == A1TC_INVALID);
1051 $$->expr_type = ASN_CONSTR_SEQUENCE;
1052 $$->meta_type = AMT_TYPE;
1053 }
1054 | TOK_SET '{' ComponentTypeLists '}' {
1055 $$ = $3;
1056 assert($$->expr_type == A1TC_INVALID);
1057 $$->expr_type = ASN_CONSTR_SET;
1058 $$->meta_type = AMT_TYPE;
1059 }
1060 | TOK_SEQUENCE optConstraints TOK_OF TypeDeclaration {
1061 $$ = asn1p_expr_new(asn1p_lineno);
1062 checkmem($$);
1063 $$->constraints = $2;
1064 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1065 $$->meta_type = AMT_TYPE;
1066 TQ_ADD(&($$->members), $4, next);
1067 }
1068 | TOK_SET optConstraints TOK_OF TypeDeclaration {
1069 $$ = asn1p_expr_new(asn1p_lineno);
1070 checkmem($$);
1071 $$->constraints = $2;
1072 $$->expr_type = ASN_CONSTR_SET_OF;
1073 $$->meta_type = AMT_TYPE;
1074 TQ_ADD(&($$->members), $4, next);
1075 }
1076 | TOK_ANY {
1077 $$ = asn1p_expr_new(asn1p_lineno);
1078 checkmem($$);
1079 $$->expr_type = ASN_CONSTR_ANY;
1080 $$->meta_type = AMT_TYPE;
1081 }
1082 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1083 int ret;
1084 $$ = asn1p_expr_new(asn1p_lineno);
1085 checkmem($$);
1086 $$->reference = asn1p_ref_new(yylineno);
1087 ret = asn1p_ref_add_component($$->reference,
1088 $4, RLT_lowercase);
1089 checkmem(ret == 0);
1090 $$->expr_type = ASN_CONSTR_ANY;
1091 $$->meta_type = AMT_TYPE;
1092 }
1093 ;
vlmfa67ddc2004-06-03 03:38:44 +00001094 /*
1095 * A parametrized assignment.
1096 */
1097 | TypeRefName '{' ActualParameterList '}' {
1098 int ret;
1099 $$ = $3;
1100 assert($$->expr_type == 0);
1101 assert($$->meta_type == 0);
1102 assert($$->reference == 0);
1103 $$->reference = asn1p_ref_new(yylineno);
1104 checkmem($$->reference);
1105 ret = asn1p_ref_add_component($$->reference, $1, RLT_UNKNOWN);
1106 checkmem(ret == 0);
1107 free($1);
1108 $$->expr_type = A1TC_PARAMETRIZED;
1109 $$->meta_type = AMT_TYPE;
1110 }
1111 /*
1112 * A DefinedType reference.
1113 * "CLASS1.&id.&id2"
1114 * or
1115 * "Module.Type"
1116 * or
1117 * "Module.identifier"
1118 * or
1119 * "Type"
1120 */
1121 | ComplexTypeReference {
1122 $$ = asn1p_expr_new(yylineno);
1123 checkmem($$);
1124 $$->reference = $1;
1125 $$->expr_type = A1TC_REFERENCE;
1126 $$->meta_type = AMT_TYPEREF;
1127 }
1128 | TOK_INSTANCE TOK_OF ComplexTypeReference {
1129 $$ = asn1p_expr_new(yylineno);
1130 checkmem($$);
1131 $$->reference = $3;
1132 $$->expr_type = A1TC_INSTANCE;
1133 $$->meta_type = AMT_TYPE;
1134 }
1135 ;
1136
1137/*
1138 * A type name consisting of several components.
1139 * === EXAMPLE ===
1140 * === EOF ===
1141 */
1142ComplexTypeReference:
1143 TOK_typereference {
1144 int ret;
1145 $$ = asn1p_ref_new(yylineno);
1146 checkmem($$);
1147 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1148 checkmem(ret == 0);
1149 free($1);
1150 }
1151 | TOK_typereference '.' TypeRefName {
1152 int ret;
1153 $$ = asn1p_ref_new(yylineno);
1154 checkmem($$);
1155 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1156 checkmem(ret == 0);
1157 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1158 checkmem(ret == 0);
1159 free($1);
1160 }
1161 | TOK_typereference '.' Identifier {
1162 int ret;
1163 $$ = asn1p_ref_new(yylineno);
1164 checkmem($$);
1165 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1166 checkmem(ret == 0);
1167 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1168 checkmem(ret == 0);
1169 free($1);
1170 }
1171 | ObjectClassReference {
1172 int ret;
1173 $$ = asn1p_ref_new(yylineno);
1174 checkmem($$);
1175 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1176 free($1);
1177 checkmem(ret == 0);
1178 }
1179 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1180 int ret;
1181 $$ = $3;
1182 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1183 free($1);
1184 checkmem(ret == 0);
1185 /*
1186 * Move the last element infront.
1187 */
1188 {
1189 struct asn1p_ref_component_s tmp_comp;
1190 tmp_comp = $$->components[$$->comp_count-1];
1191 memmove(&$$->components[1],
1192 &$$->components[0],
1193 sizeof($$->components[0])
1194 * ($$->comp_count - 1));
1195 $$->components[0] = tmp_comp;
1196 }
1197 }
1198 ;
1199
1200ComplexTypeReferenceAmpList:
1201 ComplexTypeReferenceElement {
1202 int ret;
1203 $$ = asn1p_ref_new(yylineno);
1204 checkmem($$);
1205 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1206 free($1.name);
1207 checkmem(ret == 0);
1208 }
1209 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1210 int ret;
1211 $$ = $1;
1212 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1213 free($3.name);
1214 checkmem(ret == 0);
1215 }
1216 ;
1217
1218ComplexTypeReferenceElement: ClassFieldName;
1219ClassFieldIdentifier: ClassFieldName;
1220
1221ClassFieldName:
1222 /* "&Type1" */
1223 TOK_typefieldreference {
1224 $$.lex_type = RLT_AmpUppercase;
1225 $$.name = $1;
1226 }
1227 /* "&id" */
1228 | TOK_valuefieldreference {
1229 $$.lex_type = RLT_Amplowercase;
1230 $$.name = $1;
1231 }
1232 ;
1233
1234
1235/*
1236 * === EXAMPLE ===
1237 * value INTEGER ::= 1
1238 * === EOF ===
1239 */
1240ValueDefinition:
1241 Identifier DefinedTypeRef TOK_PPEQ InlineOrDefinedValue {
1242 $$ = $2;
1243 assert($$->Identifier == NULL);
1244 $$->Identifier = $1;
1245 $$->meta_type = AMT_VALUE;
1246 $$->value = $4;
1247 }
1248 ;
1249
1250InlineOrDefinedValue:
1251 '{' { asn1p_lexer_hack_push_opaque_state(); }
1252 Opaque /* '}' */ {
1253 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1254 checkmem($$);
1255 $$->type = ATV_UNPARSED;
1256 }
1257 | TOK_bstring {
1258 $$ = _convert_bitstring2binary($1, 'B');
1259 checkmem($$);
1260 }
1261 | TOK_hstring {
1262 $$ = _convert_bitstring2binary($1, 'H');
1263 checkmem($$);
1264 }
1265 | TOK_cstring {
1266 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1267 checkmem($$);
1268 }
1269 | SignedNumber {
1270 $$ = $1;
1271 }
1272 | DefinedValue {
1273 $$ = $1;
1274 }
1275 ;
1276
1277DefinedValue:
1278 Identifier {
1279 asn1p_ref_t *ref;
1280 int ret;
1281 ref = asn1p_ref_new(yylineno);
1282 checkmem(ref);
1283 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1284 checkmem(ret == 0);
1285 $$ = asn1p_value_fromref(ref, 0);
1286 checkmem($$);
1287 free($1);
1288 }
1289 | TypeRefName '.' Identifier {
1290 asn1p_ref_t *ref;
1291 int ret;
1292 ref = asn1p_ref_new(yylineno);
1293 checkmem(ref);
1294 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1295 checkmem(ret == 0);
1296 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1297 checkmem(ret == 0);
1298 $$ = asn1p_value_fromref(ref, 0);
1299 checkmem($$);
1300 free($1);
1301 free($3);
1302 }
1303 ;
1304
1305Opaque:
1306 TOK_opaque {
1307 $$.len = $1.len + 2;
1308 $$.buf = malloc($$.len + 1);
1309 checkmem($$.buf);
1310 $$.buf[0] = '{';
1311 $$.buf[1] = ' ';
1312 memcpy($$.buf + 2, $1.buf, $1.len);
1313 $$.buf[$$.len] = '\0';
1314 free($1.buf);
1315 }
1316 | Opaque TOK_opaque {
1317 int newsize = $1.len + $2.len;
1318 char *p = malloc(newsize + 1);
1319 checkmem(p);
1320 memcpy(p , $1.buf, $1.len);
1321 memcpy(p + $1.len, $2.buf, $2.len);
1322 p[newsize] = '\0';
1323 free($1.buf);
1324 free($2.buf);
1325 $$.buf = p;
1326 $$.len = newsize;
1327 }
1328 ;
1329
1330BasicTypeId:
1331 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1332 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1333 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1334 | BasicTypeId_UniverationCompatible { $$ = $1; }
1335 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1336 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1337 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1338 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1339 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1340 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1341 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1342 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
1343 ;
1344
1345/*
1346 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1347 */
1348BasicTypeId_UniverationCompatible:
1349 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1350 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1351 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1352 ;
1353
1354BasicType:
1355 BasicTypeId {
1356 $$ = asn1p_expr_new(asn1p_lineno);
1357 checkmem($$);
1358 $$->expr_type = $1;
1359 $$->meta_type = AMT_TYPE;
1360 }
1361 | BasicTypeId_UniverationCompatible UniverationDefinition {
1362 if($2) {
1363 $$ = $2;
1364 } else {
1365 $$ = asn1p_expr_new(asn1p_lineno);
1366 checkmem($$);
1367 }
1368 $$->expr_type = $1;
1369 $$->meta_type = AMT_TYPE;
1370 }
1371 ;
1372
1373BasicString:
1374 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1375 | TOK_GeneralString {
1376 $$ = ASN_STRING_GeneralString;
1377 return yyerror("GeneralString is not supported");
1378 }
1379 | TOK_GraphicString {
1380 $$ = ASN_STRING_GraphicString;
1381 return yyerror("GraphicString is not supported");
1382 }
1383 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1384 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1385 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1386 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1387 | TOK_T61String {
1388 $$ = ASN_STRING_T61String;
1389 return yyerror("T61String not implemented yet");
1390 }
1391 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1392 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1393 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1394 | TOK_VideotexString {
1395 $$ = ASN_STRING_VideotexString;
1396 return yyerror("VideotexString is no longer supported");
1397 }
1398 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1399 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1400 ;
1401
vlm5f0128b2004-08-20 13:25:29 +00001402
vlmfa67ddc2004-06-03 03:38:44 +00001403/*
1404 * Data type constraints.
1405 */
vlmfa67ddc2004-06-03 03:38:44 +00001406Union: '|' | TOK_UNION;
1407Intersection: '^' | TOK_INTERSECTION;
1408Except: TOK_EXCEPT;
1409
vlm9283dbe2004-08-18 04:59:12 +00001410optConstraints:
1411 { $$ = 0; }
vlm5f0128b2004-08-20 13:25:29 +00001412 | Constraints {
1413 $$ = $1;
1414 }
1415 ;
1416
1417Constraints:
1418 SetOfConstraints {
vlm9283dbe2004-08-18 04:59:12 +00001419 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
1420 }
1421 | TOK_SIZE '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001422 /*
1423 * This is a special case, for compatibility purposes.
vlm9283dbe2004-08-18 04:59:12 +00001424 * It goes without parentheses.
vlmfa67ddc2004-06-03 03:38:44 +00001425 */
vlm5f0128b2004-08-20 13:25:29 +00001426 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001427 }
vlmfa67ddc2004-06-03 03:38:44 +00001428 ;
1429
vlm9283dbe2004-08-18 04:59:12 +00001430SetOfConstraints:
1431 '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001432 $$ = $2;
1433 }
vlm9283dbe2004-08-18 04:59:12 +00001434 | SetOfConstraints '(' ElementSetSpecs ')' {
1435 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
1436 }
vlmfa67ddc2004-06-03 03:38:44 +00001437 ;
1438
vlm9283dbe2004-08-18 04:59:12 +00001439ElementSetSpecs:
1440 ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001441 $$ = $1;
1442 }
vlm9283dbe2004-08-18 04:59:12 +00001443 | ElementSetSpec ',' TOK_ThreeDots {
vlmfa67ddc2004-06-03 03:38:44 +00001444 asn1p_constraint_t *ct;
1445 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001446 ct->type = ACT_EL_EXT;
1447 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
1448 }
vlm9283dbe2004-08-18 04:59:12 +00001449 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001450 asn1p_constraint_t *ct;
1451 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001452 ct->type = ACT_EL_EXT;
1453 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlm6f5eb0b2004-08-13 12:35:09 +00001454 ct = $$;
1455 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
vlmfa67ddc2004-06-03 03:38:44 +00001456 }
vlmfa67ddc2004-06-03 03:38:44 +00001457 ;
1458
vlm9283dbe2004-08-18 04:59:12 +00001459ElementSetSpec:
1460 ConstraintSubtypeElement {
1461 $$ = $1;
1462 }
1463 | ElementSetSpec Union ConstraintSubtypeElement {
vlmfa67ddc2004-06-03 03:38:44 +00001464 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
1465 }
vlm9283dbe2004-08-18 04:59:12 +00001466 | ElementSetSpec Intersection ConstraintSubtypeElement {
vlmfa67ddc2004-06-03 03:38:44 +00001467 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
1468 }
vlm9283dbe2004-08-18 04:59:12 +00001469 | ConstraintSubtypeElement Except ConstraintSubtypeElement {
vlmfa67ddc2004-06-03 03:38:44 +00001470 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
1471 }
1472 ;
1473
1474ConstraintSubtypeElement:
vlm9283dbe2004-08-18 04:59:12 +00001475 ConstraintSpec '(' ElementSetSpecs ')' {
1476 int ret;
1477 $$ = asn1p_constraint_new(yylineno);
1478 checkmem($$);
1479 $$->type = $1;
1480 ret = asn1p_constraint_insert($$, $3);
1481 checkmem(ret == 0);
1482 }
1483 | '(' ElementSetSpecs ')' {
1484 int ret;
1485 $$ = asn1p_constraint_new(yylineno);
1486 checkmem($$);
1487 $$->type = ACT_CA_SET;
1488 ret = asn1p_constraint_insert($$, $2);
1489 checkmem(ret == 0);
1490 }
1491 | ConstraintValue {
vlmfa67ddc2004-06-03 03:38:44 +00001492 $$ = asn1p_constraint_new(yylineno);
1493 checkmem($$);
1494 $$->type = ACT_EL_VALUE;
1495 $$->value = $1;
1496 }
1497 | ConstraintValue ConstraintRangeSpec ConstraintValue {
1498 $$ = asn1p_constraint_new(yylineno);
1499 checkmem($$);
1500 $$->type = $2;
1501 $$->range_start = $1;
1502 $$->range_stop = $3;
1503 }
vlm9283dbe2004-08-18 04:59:12 +00001504 | TOK_MIN ConstraintRangeSpec ConstraintValue {
vlmfa67ddc2004-06-03 03:38:44 +00001505 $$ = asn1p_constraint_new(yylineno);
1506 checkmem($$);
vlm9283dbe2004-08-18 04:59:12 +00001507 $$->type = $2;
1508 $$->range_start = asn1p_value_fromint(-123);
1509 $$->range_stop = $3;
1510 $$->range_start->type = ATV_MIN;
1511 }
1512 | ConstraintValue ConstraintRangeSpec TOK_MAX {
1513 $$ = asn1p_constraint_new(yylineno);
1514 checkmem($$);
1515 $$->type = $2;
1516 $$->range_start = $1;
1517 $$->range_stop = asn1p_value_fromint(321);
1518 $$->range_stop->type = ATV_MAX;
1519 }
1520 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1521 $$ = asn1p_constraint_new(yylineno);
1522 checkmem($$);
1523 $$->type = $2;
1524 $$->range_start = asn1p_value_fromint(-123);
1525 $$->range_stop = asn1p_value_fromint(321);
1526 $$->range_start->type = ATV_MIN;
1527 $$->range_stop->type = ATV_MAX;
vlmfa67ddc2004-06-03 03:38:44 +00001528 }
1529 | TableConstraint {
1530 $$ = $1;
1531 }
1532 | WithComponents {
1533 $$ = $1;
1534 }
1535 ;
1536
1537ConstraintRangeSpec:
1538 TOK_TwoDots { $$ = ACT_EL_RANGE; }
1539 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
1540 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
1541 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
1542 ;
1543
1544ConstraintSpec:
1545 TOK_SIZE {
1546 $$ = ACT_CT_SIZE;
1547 }
1548 | TOK_FROM {
1549 $$ = ACT_CT_FROM;
1550 }
1551 ;
1552
1553ConstraintValue:
1554 SignedNumber {
1555 $$ = $1;
1556 }
1557 | Identifier {
1558 asn1p_ref_t *ref;
1559 int ret;
1560 ref = asn1p_ref_new(yylineno);
1561 checkmem(ref);
1562 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1563 checkmem(ret == 0);
1564 $$ = asn1p_value_fromref(ref, 0);
1565 checkmem($$);
1566 free($1);
1567 }
1568 | TOK_cstring {
1569 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1570 checkmem($$);
1571 }
vlm9283dbe2004-08-18 04:59:12 +00001572
vlmfa67ddc2004-06-03 03:38:44 +00001573 | TOK_FALSE {
1574 $$ = asn1p_value_fromint(0);
1575 checkmem($$);
1576 $$->type = ATV_FALSE;
1577 }
1578 | TOK_TRUE {
1579 $$ = asn1p_value_fromint(1);
1580 checkmem($$);
1581 $$->type = ATV_TRUE;
1582 }
1583 ;
1584
1585WithComponents:
1586 TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
1587 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
1588 }
1589 ;
1590
1591WithComponentsList:
1592 WithComponentsElement {
1593 $$ = $1;
1594 }
1595 | WithComponentsList ',' WithComponentsElement {
1596 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
1597 }
1598 ;
1599
1600WithComponentsElement:
1601 TOK_ThreeDots {
1602 $$ = asn1p_constraint_new(yylineno);
1603 checkmem($$);
1604 $$->type = ACT_EL_EXT;
1605 }
1606 | Identifier optConstraints optPresenceConstraint {
1607 $$ = asn1p_constraint_new(yylineno);
1608 checkmem($$);
1609 $$->type = ACT_EL_VALUE;
1610 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1611 $$->presence = $3;
1612 }
1613 ;
1614
1615/*
1616 * presence constraint for WithComponents
1617 */
1618optPresenceConstraint:
1619 { $$ = ACPRES_DEFAULT; }
1620 | PresenceConstraint { $$ = $1; }
1621 ;
1622
1623PresenceConstraint:
1624 TOK_PRESENT {
1625 $$ = ACPRES_PRESENT;
1626 }
1627 | TOK_ABSENT {
1628 $$ = ACPRES_ABSENT;
1629 }
1630 | TOK_OPTIONAL {
1631 $$ = ACPRES_OPTIONAL;
1632 }
1633 ;
1634
1635TableConstraint:
1636 SimpleTableConstraint {
1637 $$ = $1;
1638 }
1639 | ComponentRelationConstraint {
1640 $$ = $1;
1641 }
1642 ;
1643
1644/*
1645 * "{ExtensionSet}"
1646 */
1647SimpleTableConstraint:
1648 '{' TypeRefName '}' {
1649 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
1650 asn1p_constraint_t *ct;
1651 int ret;
1652 ret = asn1p_ref_add_component(ref, $2, 0);
1653 checkmem(ret == 0);
1654 ct = asn1p_constraint_new(yylineno);
1655 checkmem($$);
1656 ct->type = ACT_EL_VALUE;
1657 ct->value = asn1p_value_fromref(ref, 0);
1658 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
1659 }
1660 ;
1661
1662ComponentRelationConstraint:
1663 SimpleTableConstraint '{' AtNotationList '}' {
1664 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
1665 }
1666 ;
1667
1668AtNotationList:
1669 AtNotationElement {
1670 $$ = asn1p_constraint_new(yylineno);
1671 checkmem($$);
1672 $$->type = ACT_EL_VALUE;
1673 $$->value = asn1p_value_fromref($1, 0);
1674 }
1675 | AtNotationList ',' AtNotationElement {
1676 asn1p_constraint_t *ct;
1677 ct = asn1p_constraint_new(yylineno);
1678 checkmem(ct);
1679 ct->type = ACT_EL_VALUE;
1680 ct->value = asn1p_value_fromref($3, 0);
1681 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
1682 }
1683 ;
1684
1685/*
1686 * @blah
1687 */
1688AtNotationElement:
1689 '@' ComponentIdList {
1690 char *p = malloc(strlen($2) + 2);
1691 int ret;
1692 *p = '@';
1693 strcpy(p + 1, $2);
1694 $$ = asn1p_ref_new(yylineno);
1695 ret = asn1p_ref_add_component($$, p, 0);
1696 checkmem(ret == 0);
1697 free(p);
1698 free($2);
1699 }
1700 | '@' '.' ComponentIdList {
1701 char *p = malloc(strlen($3) + 3);
1702 int ret;
1703 p[0] = '@';
1704 p[1] = '.';
1705 strcpy(p + 2, $3);
1706 $$ = asn1p_ref_new(yylineno);
1707 ret = asn1p_ref_add_component($$, p, 0);
1708 checkmem(ret == 0);
1709 free(p);
1710 free($3);
1711 }
1712 ;
1713
1714/* identifier "." ... */
1715ComponentIdList:
1716 Identifier {
1717 $$ = $1;
1718 }
1719 | ComponentIdList '.' Identifier {
1720 int l1 = strlen($1);
1721 int l3 = strlen($3);
1722 $$ = malloc(l1 + 1 + l3 + 1);
1723 memcpy($$, $1, l1);
1724 $$[l1] = '.';
1725 memcpy($$ + l1 + 1, $3, l3);
1726 $$[l1 + 1 + l3] = '\0';
1727 }
1728 ;
1729
1730
1731
1732/*
1733 * MARKERS
1734 */
1735
1736optMarker:
1737 { $$ = EM_NOMARK; }
1738 | Marker { $$ = $1; }
1739 ;
1740
1741Marker:
1742 TOK_OPTIONAL {
1743 $$ = EM_OPTIONAL;
1744 }
1745 | TOK_DEFAULT DefaultValue {
1746 $$ = EM_DEFAULT;
1747 /* FIXME: store DefaultValue somewhere */
1748 }
1749 ;
1750
1751DefaultValue:
1752 ConstraintValue {
1753 }
1754 | BasicTypeId {
1755 }
1756 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1757 }
1758 ;
1759
1760/*
1761 * Universal enumeration definition to use in INTEGER and ENUMERATED.
1762 * === EXAMPLE ===
1763 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
1764 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
1765 * === EOF ===
1766 */
1767/*
1768optUniverationDefinition:
1769 { $$ = 0; }
1770 | UniverationDefinition {
1771 $$ = $1;
1772 }
1773 ;
1774*/
1775
1776UniverationDefinition:
1777 '{' '}' {
1778 $$ = asn1p_expr_new(asn1p_lineno);
1779 checkmem($$);
1780 }
1781 | '{' UniverationList '}' {
1782 $$ = $2;
1783 }
1784 ;
1785
1786UniverationList:
1787 UniverationElement {
1788 $$ = asn1p_expr_new(asn1p_lineno);
1789 checkmem($$);
1790 TQ_ADD(&($$->members), $1, next);
1791 }
1792 | UniverationList ',' UniverationElement {
1793 $$ = $1;
1794 TQ_ADD(&($$->members), $3, next);
1795 }
1796 ;
1797
1798UniverationElement:
1799 Identifier {
1800 $$ = asn1p_expr_new(asn1p_lineno);
1801 checkmem($$);
1802 $$->expr_type = A1TC_UNIVERVAL;
1803 $$->meta_type = AMT_VALUE;
1804 $$->Identifier = $1;
1805 }
1806 | Identifier '(' SignedNumber ')' {
1807 $$ = asn1p_expr_new(asn1p_lineno);
1808 checkmem($$);
1809 $$->expr_type = A1TC_UNIVERVAL;
1810 $$->meta_type = AMT_VALUE;
1811 $$->Identifier = $1;
1812 $$->value = $3;
1813 }
1814 | Identifier '(' DefinedValue ')' {
1815 $$ = asn1p_expr_new(asn1p_lineno);
1816 checkmem($$);
1817 $$->expr_type = A1TC_UNIVERVAL;
1818 $$->meta_type = AMT_VALUE;
1819 $$->Identifier = $1;
1820 $$->value = $3;
1821 }
1822 | SignedNumber {
1823 $$ = asn1p_expr_new(asn1p_lineno);
1824 checkmem($$);
1825 $$->expr_type = A1TC_UNIVERVAL;
1826 $$->meta_type = AMT_VALUE;
1827 $$->value = $1;
1828 }
1829 | TOK_ThreeDots {
1830 $$ = asn1p_expr_new(asn1p_lineno);
1831 checkmem($$);
1832 $$->Identifier = strdup("...");
1833 checkmem($$->Identifier);
1834 $$->expr_type = A1TC_EXTENSIBLE;
1835 $$->meta_type = AMT_VALUE;
1836 }
1837 ;
1838
1839SignedNumber:
1840 TOK_number {
1841 $$ = asn1p_value_fromint($1);
1842 checkmem($$);
1843 }
1844 | TOK_number_negative {
1845 $$ = asn1p_value_fromint($1);
1846 checkmem($$);
1847 }
1848 ;
1849
1850/*
1851 * SEQUENCE definition.
1852 * === EXAMPLE ===
1853 * Struct1 ::= SEQUENCE {
1854 * memb1 Struct2,
1855 * memb2 SEQUENCE OF {
1856 * memb2-1 Struct 3
1857 * }
1858 * }
1859 * === EOF ===
1860 */
1861
1862
1863
1864/*
1865 * SET definition.
1866 * === EXAMPLE ===
1867 * Person ::= SET {
1868 * name [0] PrintableString (SIZE(1..20)),
1869 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
1870 * }
1871 * === EOF ===
1872 */
1873
1874optTag:
1875 { memset(&$$, 0, sizeof($$)); }
1876 | Tag { $$ = $1; }
1877 ;
1878
1879Tag:
1880 TOK_tag {
1881 $$ = $1;
1882 $$.tag_mode = TM_DEFAULT;
1883 }
1884 | TOK_tag TOK_IMPLICIT {
1885 $$ = $1;
1886 $$.tag_mode = TM_IMPLICIT;
1887 }
1888 | TOK_tag TOK_EXPLICIT {
1889 $$ = $1;
1890 $$.tag_mode = TM_EXPLICIT;
1891 }
1892 ;
1893
1894TypeRefName:
1895 TOK_typereference {
1896 checkmem($1);
1897 $$ = $1;
1898 }
vlm9283dbe2004-08-18 04:59:12 +00001899 | TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00001900 checkmem($1);
1901 $$ = $1;
1902 }
1903 ;
1904
vlm9283dbe2004-08-18 04:59:12 +00001905
vlmfa67ddc2004-06-03 03:38:44 +00001906ObjectClassReference:
vlm9283dbe2004-08-18 04:59:12 +00001907 TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00001908 checkmem($1);
1909 $$ = $1;
1910 }
1911 ;
1912
1913Identifier:
1914 TOK_identifier {
1915 checkmem($1);
1916 $$ = $1;
1917 }
1918 ;
1919
1920TaggedIdentifier:
1921 Identifier {
1922 memset(&$$, 0, sizeof($$));
1923 $$.name = $1;
1924 }
1925 | Identifier Tag {
1926 $$.name = $1;
1927 $$.tag = $2;
1928 }
1929 ;
1930
1931
1932%%
1933
1934
1935/*
1936 * Convert Xstring ('0101'B or '5'H) to the binary vector.
1937 */
1938static asn1p_value_t *
1939_convert_bitstring2binary(char *str, int base) {
1940 asn1p_value_t *val;
1941 int slen;
1942 int memlen;
1943 int baselen;
1944 int bits;
1945 uint8_t *binary_vector;
1946 uint8_t *bv_ptr;
1947 uint8_t cur_val;
1948
1949 assert(str);
1950 assert(str[0] == '\'');
1951
1952 switch(base) {
1953 case 'B':
1954 baselen = 1;
1955 break;
1956 case 'H':
1957 baselen = 4;
1958 break;
1959 default:
1960 assert(base == 'B' || base == 'H');
1961 errno = EINVAL;
1962 return NULL;
1963 }
1964
1965 slen = strlen(str);
1966 assert(str[slen - 1] == base);
1967 assert(str[slen - 2] == '\'');
1968
1969 memlen = slen / (8 / baselen); /* Conservative estimate */
1970
1971 bv_ptr = binary_vector = malloc(memlen + 1);
1972 if(bv_ptr == NULL)
1973 /* ENOMEM */
1974 return NULL;
1975
1976 cur_val = 0;
1977 bits = 0;
1978 while(*(++str) != '\'') {
1979 switch(baselen) {
1980 case 1:
1981 switch(*str) {
1982 case '1':
1983 cur_val |= 1 << (7 - (bits % 8));
1984 case '0':
1985 break;
1986 default:
1987 assert(!"_y UNREACH1");
1988 case ' ': case '\r': case '\n':
1989 continue;
1990 }
1991 break;
1992 case 4:
1993 switch(*str) {
1994 case '0': case '1': case '2': case '3': case '4':
1995 case '5': case '6': case '7': case '8': case '9':
1996 cur_val |= (*str - '0') << (4 - (bits % 8));
1997 break;
1998 case 'A': case 'B': case 'C':
1999 case 'D': case 'E': case 'F':
2000 cur_val |= ((*str - 'A') + 10)
2001 << (4 - (bits % 8));
2002 break;
2003 default:
2004 assert(!"_y UNREACH2");
2005 case ' ': case '\r': case '\n':
2006 continue;
2007 }
2008 break;
2009 }
2010
2011 bits += baselen;
2012 if((bits % 8) == 0) {
2013 *bv_ptr++ = cur_val;
2014 cur_val = 0;
2015 }
2016 }
2017
2018 *bv_ptr = cur_val;
2019 assert((bv_ptr - binary_vector) <= memlen);
2020
2021 val = asn1p_value_frombits(binary_vector, bits, 0);
2022 if(val == NULL) {
2023 free(binary_vector);
2024 }
2025
2026 return val;
2027}
2028
2029extern char *asn1p_text;
2030
2031int
2032yyerror(const char *msg) {
2033 fprintf(stderr,
2034 "ASN.1 grammar parse error "
2035 "near line %d (token \"%s\"): %s\n",
2036 asn1p_lineno, asn1p_text, msg);
2037 return -1;
2038}
2039
2040