blob: 317bba0440c283d441f37a8d2ca82adc20e9b4f8 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001%{
2
3#include <stdlib.h>
4#include <stdio.h>
5#include <string.h>
6#include <errno.h>
7#include <assert.h>
8
9#include "asn1parser.h"
10
11#define YYPARSE_PARAM param
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);
Lev Walkinf59d0752004-08-18 04:59:12 +000018void asn1p_lexer_hack_push_encoding_control(void);
Lev Walkinf15320b2004-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
Lev Walkinf59d0752004-08-18 04:59:12 +0000103%token <tv_str> TOK_capitalreference /* "CLASS1" */
Lev Walkinf15320b2004-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
Lev Walkinf59d0752004-08-18 04:59:12 +0000133%token TOK_ENCODING_CONTROL
Lev Walkinf15320b2004-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
Lev Walkinf59d0752004-08-18 04:59:12 +0000152%token TOK_INSTRUCTIONS
Lev Walkinf15320b2004-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
Lev Walkinf15320b2004-06-03 03:38:44 +0000192%left TOK_EXCEPT
Lev Walkinf59d0752004-08-18 04:59:12 +0000193%left '^' TOK_INTERSECTION
194%left '|' TOK_UNION
Lev Walkinf15320b2004-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
Lev Walkinf15320b2004-06-03 03:38:44 +0000221%type <a_expr> ExtensionAndException
Lev Walkin070a52d2004-08-22 03:19:54 +0000222%type <a_expr> TypeDeclaration
Lev Walkinf15320b2004-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
Lev Walkin070a52d2004-08-22 03:19:54 +0000231%type <a_expr> Type
Lev Walkinf15320b2004-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
Lev Walkin070a52d2004-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
Lev Walkinf15320b2004-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
Lev Walkind2ea1de2004-08-20 13:25:29 +0000269%type <a_constr> Constraints
Lev Walkinf59d0752004-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 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000273%type <a_constr> ConstraintSubtypeElement /* 1..2 */
Lev Walkinf15320b2004-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 }
Lev Walkinf59d0752004-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 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000449 ;
450
451/*
452 * Optional module body.
453 */
454optModuleSpecificationBody:
455 { $$ = 0; }
456 | ModuleSpecificationBody {
Lev Walkinf15320b2004-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
Lev Walkinf59d0752004-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
Lev Walkinf15320b2004-06-03 03:38:44 +0000477#ifdef MY_IMPORT
478#error MY_IMPORT DEFINED ELSEWHERE!
479#endif
480#define MY_IMPORT(foo,field) do { \
Lev Walkinbc55d232004-08-13 12:31:09 +0000481 while(TQ_FIRST(&($2->foo))) { \
Lev Walkinf15320b2004-06-03 03:38:44 +0000482 TQ_ADD(&($$->foo), \
483 TQ_REMOVE(&($2->foo), field), \
484 field); \
Lev Walkinbc55d232004-08-13 12:31:09 +0000485 } \
486 assert(TQ_FIRST(&($2->foo)) == 0); \
487 } while(0)
Lev Walkinf15320b2004-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 }
Lev Walkinf59d0752004-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 }
Lev Walkinf15320b2004-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 { }
Lev Walkinf59d0752004-08-18 04:59:12 +0000697 | ElementSetSpecs {
Lev Walkinf15320b2004-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 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000721 | TypeRefName TOK_PPEQ optTag Type {
Lev Walkinf15320b2004-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 */
Lev Walkin070a52d2004-08-22 03:19:54 +0000744 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
Lev Walkinf15320b2004-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:
Lev Walkin070a52d2004-08-22 03:19:54 +0000808 Type {
Lev Walkinf15320b2004-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 */
Lev Walkin070a52d2004-08-22 03:19:54 +0000823ComponentTypeLists:
824 ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +0000825 $$ = asn1p_expr_new(yylineno);
826 checkmem($$);
827 TQ_ADD(&($$->members), $1, next);
828 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000829 | ComponentTypeLists ',' ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +0000830 $$ = $1;
831 TQ_ADD(&($$->members), $3, next);
832 }
833 ;
834
Lev Walkin070a52d2004-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
Lev Walkinf15320b2004-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 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000917 | ClassFieldIdentifier Type optMarker optUnique {
Lev Walkinf15320b2004-06-03 03:38:44 +0000918 $$ = $2;
919 $$->Identifier = $1.name;
Lev Walkin070a52d2004-08-22 03:19:54 +0000920 $$->marker = $3;
921 $$->unique = $4;
Lev Walkinf15320b2004-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
Lev Walkinf15320b2004-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
Lev Walkin070a52d2004-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:
Lev Walkinf15320b2004-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 }
Lev Walkin070a52d2004-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;
Lev Walkinf15320b2004-06-03 03:38:44 +00001047 }
Lev Walkin070a52d2004-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($$);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001079 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001080 $$->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);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001090 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001091 $$->meta_type = AMT_TYPE;
1092 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001093 /*
1094 * A parametrized assignment.
1095 */
1096 | TypeRefName '{' ActualParameterList '}' {
1097 int ret;
1098 $$ = $3;
1099 assert($$->expr_type == 0);
1100 assert($$->meta_type == 0);
1101 assert($$->reference == 0);
1102 $$->reference = asn1p_ref_new(yylineno);
1103 checkmem($$->reference);
1104 ret = asn1p_ref_add_component($$->reference, $1, RLT_UNKNOWN);
1105 checkmem(ret == 0);
1106 free($1);
1107 $$->expr_type = A1TC_PARAMETRIZED;
1108 $$->meta_type = AMT_TYPE;
1109 }
1110 /*
1111 * A DefinedType reference.
1112 * "CLASS1.&id.&id2"
1113 * or
1114 * "Module.Type"
1115 * or
1116 * "Module.identifier"
1117 * or
1118 * "Type"
1119 */
1120 | ComplexTypeReference {
1121 $$ = asn1p_expr_new(yylineno);
1122 checkmem($$);
1123 $$->reference = $1;
1124 $$->expr_type = A1TC_REFERENCE;
1125 $$->meta_type = AMT_TYPEREF;
1126 }
1127 | TOK_INSTANCE TOK_OF ComplexTypeReference {
1128 $$ = asn1p_expr_new(yylineno);
1129 checkmem($$);
1130 $$->reference = $3;
1131 $$->expr_type = A1TC_INSTANCE;
1132 $$->meta_type = AMT_TYPE;
1133 }
1134 ;
1135
1136/*
1137 * A type name consisting of several components.
1138 * === EXAMPLE ===
1139 * === EOF ===
1140 */
1141ComplexTypeReference:
1142 TOK_typereference {
1143 int ret;
1144 $$ = asn1p_ref_new(yylineno);
1145 checkmem($$);
1146 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1147 checkmem(ret == 0);
1148 free($1);
1149 }
1150 | TOK_typereference '.' TypeRefName {
1151 int ret;
1152 $$ = asn1p_ref_new(yylineno);
1153 checkmem($$);
1154 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1155 checkmem(ret == 0);
1156 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1157 checkmem(ret == 0);
1158 free($1);
1159 }
1160 | TOK_typereference '.' Identifier {
1161 int ret;
1162 $$ = asn1p_ref_new(yylineno);
1163 checkmem($$);
1164 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1165 checkmem(ret == 0);
1166 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1167 checkmem(ret == 0);
1168 free($1);
1169 }
1170 | ObjectClassReference {
1171 int ret;
1172 $$ = asn1p_ref_new(yylineno);
1173 checkmem($$);
1174 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1175 free($1);
1176 checkmem(ret == 0);
1177 }
1178 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1179 int ret;
1180 $$ = $3;
1181 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1182 free($1);
1183 checkmem(ret == 0);
1184 /*
1185 * Move the last element infront.
1186 */
1187 {
1188 struct asn1p_ref_component_s tmp_comp;
1189 tmp_comp = $$->components[$$->comp_count-1];
1190 memmove(&$$->components[1],
1191 &$$->components[0],
1192 sizeof($$->components[0])
1193 * ($$->comp_count - 1));
1194 $$->components[0] = tmp_comp;
1195 }
1196 }
1197 ;
1198
1199ComplexTypeReferenceAmpList:
1200 ComplexTypeReferenceElement {
1201 int ret;
1202 $$ = asn1p_ref_new(yylineno);
1203 checkmem($$);
1204 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1205 free($1.name);
1206 checkmem(ret == 0);
1207 }
1208 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1209 int ret;
1210 $$ = $1;
1211 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1212 free($3.name);
1213 checkmem(ret == 0);
1214 }
1215 ;
1216
1217ComplexTypeReferenceElement: ClassFieldName;
1218ClassFieldIdentifier: ClassFieldName;
1219
1220ClassFieldName:
1221 /* "&Type1" */
1222 TOK_typefieldreference {
1223 $$.lex_type = RLT_AmpUppercase;
1224 $$.name = $1;
1225 }
1226 /* "&id" */
1227 | TOK_valuefieldreference {
1228 $$.lex_type = RLT_Amplowercase;
1229 $$.name = $1;
1230 }
1231 ;
1232
1233
1234/*
1235 * === EXAMPLE ===
1236 * value INTEGER ::= 1
1237 * === EOF ===
1238 */
1239ValueDefinition:
1240 Identifier DefinedTypeRef TOK_PPEQ InlineOrDefinedValue {
1241 $$ = $2;
1242 assert($$->Identifier == NULL);
1243 $$->Identifier = $1;
1244 $$->meta_type = AMT_VALUE;
1245 $$->value = $4;
1246 }
1247 ;
1248
1249InlineOrDefinedValue:
1250 '{' { asn1p_lexer_hack_push_opaque_state(); }
1251 Opaque /* '}' */ {
1252 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1253 checkmem($$);
1254 $$->type = ATV_UNPARSED;
1255 }
1256 | TOK_bstring {
1257 $$ = _convert_bitstring2binary($1, 'B');
1258 checkmem($$);
1259 }
1260 | TOK_hstring {
1261 $$ = _convert_bitstring2binary($1, 'H');
1262 checkmem($$);
1263 }
1264 | TOK_cstring {
1265 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1266 checkmem($$);
1267 }
1268 | SignedNumber {
1269 $$ = $1;
1270 }
1271 | DefinedValue {
1272 $$ = $1;
1273 }
1274 ;
1275
1276DefinedValue:
1277 Identifier {
1278 asn1p_ref_t *ref;
1279 int ret;
1280 ref = asn1p_ref_new(yylineno);
1281 checkmem(ref);
1282 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1283 checkmem(ret == 0);
1284 $$ = asn1p_value_fromref(ref, 0);
1285 checkmem($$);
1286 free($1);
1287 }
1288 | TypeRefName '.' Identifier {
1289 asn1p_ref_t *ref;
1290 int ret;
1291 ref = asn1p_ref_new(yylineno);
1292 checkmem(ref);
1293 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1294 checkmem(ret == 0);
1295 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1296 checkmem(ret == 0);
1297 $$ = asn1p_value_fromref(ref, 0);
1298 checkmem($$);
1299 free($1);
1300 free($3);
1301 }
1302 ;
1303
1304Opaque:
1305 TOK_opaque {
1306 $$.len = $1.len + 2;
1307 $$.buf = malloc($$.len + 1);
1308 checkmem($$.buf);
1309 $$.buf[0] = '{';
1310 $$.buf[1] = ' ';
1311 memcpy($$.buf + 2, $1.buf, $1.len);
1312 $$.buf[$$.len] = '\0';
1313 free($1.buf);
1314 }
1315 | Opaque TOK_opaque {
1316 int newsize = $1.len + $2.len;
1317 char *p = malloc(newsize + 1);
1318 checkmem(p);
1319 memcpy(p , $1.buf, $1.len);
1320 memcpy(p + $1.len, $2.buf, $2.len);
1321 p[newsize] = '\0';
1322 free($1.buf);
1323 free($2.buf);
1324 $$.buf = p;
1325 $$.len = newsize;
1326 }
1327 ;
1328
1329BasicTypeId:
1330 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1331 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1332 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1333 | BasicTypeId_UniverationCompatible { $$ = $1; }
1334 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1335 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1336 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1337 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1338 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1339 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1340 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1341 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
1342 ;
1343
1344/*
1345 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1346 */
1347BasicTypeId_UniverationCompatible:
1348 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1349 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1350 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1351 ;
1352
1353BasicType:
1354 BasicTypeId {
1355 $$ = asn1p_expr_new(asn1p_lineno);
1356 checkmem($$);
1357 $$->expr_type = $1;
1358 $$->meta_type = AMT_TYPE;
1359 }
1360 | BasicTypeId_UniverationCompatible UniverationDefinition {
1361 if($2) {
1362 $$ = $2;
1363 } else {
1364 $$ = asn1p_expr_new(asn1p_lineno);
1365 checkmem($$);
1366 }
1367 $$->expr_type = $1;
1368 $$->meta_type = AMT_TYPE;
1369 }
1370 ;
1371
1372BasicString:
1373 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1374 | TOK_GeneralString {
1375 $$ = ASN_STRING_GeneralString;
1376 return yyerror("GeneralString is not supported");
1377 }
1378 | TOK_GraphicString {
1379 $$ = ASN_STRING_GraphicString;
1380 return yyerror("GraphicString is not supported");
1381 }
1382 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1383 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1384 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1385 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1386 | TOK_T61String {
1387 $$ = ASN_STRING_T61String;
1388 return yyerror("T61String not implemented yet");
1389 }
1390 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1391 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1392 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1393 | TOK_VideotexString {
1394 $$ = ASN_STRING_VideotexString;
1395 return yyerror("VideotexString is no longer supported");
1396 }
1397 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1398 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1399 ;
1400
Lev Walkind2ea1de2004-08-20 13:25:29 +00001401
Lev Walkinf15320b2004-06-03 03:38:44 +00001402/*
1403 * Data type constraints.
1404 */
Lev Walkinf15320b2004-06-03 03:38:44 +00001405Union: '|' | TOK_UNION;
1406Intersection: '^' | TOK_INTERSECTION;
1407Except: TOK_EXCEPT;
1408
Lev Walkinf59d0752004-08-18 04:59:12 +00001409optConstraints:
1410 { $$ = 0; }
Lev Walkind2ea1de2004-08-20 13:25:29 +00001411 | Constraints {
1412 $$ = $1;
1413 }
1414 ;
1415
1416Constraints:
1417 SetOfConstraints {
Lev Walkinf59d0752004-08-18 04:59:12 +00001418 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
1419 }
1420 | TOK_SIZE '(' ElementSetSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001421 /*
1422 * This is a special case, for compatibility purposes.
Lev Walkinf59d0752004-08-18 04:59:12 +00001423 * It goes without parentheses.
Lev Walkinf15320b2004-06-03 03:38:44 +00001424 */
Lev Walkind2ea1de2004-08-20 13:25:29 +00001425 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001426 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001427 ;
1428
Lev Walkinf59d0752004-08-18 04:59:12 +00001429SetOfConstraints:
1430 '(' ElementSetSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001431 $$ = $2;
1432 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001433 | SetOfConstraints '(' ElementSetSpecs ')' {
1434 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
1435 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001436 ;
1437
Lev Walkinf59d0752004-08-18 04:59:12 +00001438ElementSetSpecs:
1439 ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001440 $$ = $1;
1441 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001442 | ElementSetSpec ',' TOK_ThreeDots {
Lev Walkinf15320b2004-06-03 03:38:44 +00001443 asn1p_constraint_t *ct;
1444 ct = asn1p_constraint_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001445 ct->type = ACT_EL_EXT;
1446 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
1447 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001448 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001449 asn1p_constraint_t *ct;
1450 ct = asn1p_constraint_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001451 ct->type = ACT_EL_EXT;
1452 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinb4fcdd22004-08-13 12:35:09 +00001453 ct = $$;
1454 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
Lev Walkinf15320b2004-06-03 03:38:44 +00001455 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001456 ;
1457
Lev Walkinf59d0752004-08-18 04:59:12 +00001458ElementSetSpec:
1459 ConstraintSubtypeElement {
1460 $$ = $1;
1461 }
1462 | ElementSetSpec Union ConstraintSubtypeElement {
Lev Walkinf15320b2004-06-03 03:38:44 +00001463 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
1464 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001465 | ElementSetSpec Intersection ConstraintSubtypeElement {
Lev Walkinf15320b2004-06-03 03:38:44 +00001466 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
1467 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001468 | ConstraintSubtypeElement Except ConstraintSubtypeElement {
Lev Walkinf15320b2004-06-03 03:38:44 +00001469 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
1470 }
1471 ;
1472
1473ConstraintSubtypeElement:
Lev Walkinf59d0752004-08-18 04:59:12 +00001474 ConstraintSpec '(' ElementSetSpecs ')' {
1475 int ret;
1476 $$ = asn1p_constraint_new(yylineno);
1477 checkmem($$);
1478 $$->type = $1;
1479 ret = asn1p_constraint_insert($$, $3);
1480 checkmem(ret == 0);
1481 }
1482 | '(' ElementSetSpecs ')' {
1483 int ret;
1484 $$ = asn1p_constraint_new(yylineno);
1485 checkmem($$);
1486 $$->type = ACT_CA_SET;
1487 ret = asn1p_constraint_insert($$, $2);
1488 checkmem(ret == 0);
1489 }
1490 | ConstraintValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001491 $$ = asn1p_constraint_new(yylineno);
1492 checkmem($$);
1493 $$->type = ACT_EL_VALUE;
1494 $$->value = $1;
1495 }
1496 | ConstraintValue ConstraintRangeSpec ConstraintValue {
1497 $$ = asn1p_constraint_new(yylineno);
1498 checkmem($$);
1499 $$->type = $2;
1500 $$->range_start = $1;
1501 $$->range_stop = $3;
1502 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001503 | TOK_MIN ConstraintRangeSpec ConstraintValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001504 $$ = asn1p_constraint_new(yylineno);
1505 checkmem($$);
Lev Walkinf59d0752004-08-18 04:59:12 +00001506 $$->type = $2;
1507 $$->range_start = asn1p_value_fromint(-123);
1508 $$->range_stop = $3;
1509 $$->range_start->type = ATV_MIN;
1510 }
1511 | ConstraintValue ConstraintRangeSpec TOK_MAX {
1512 $$ = asn1p_constraint_new(yylineno);
1513 checkmem($$);
1514 $$->type = $2;
1515 $$->range_start = $1;
1516 $$->range_stop = asn1p_value_fromint(321);
1517 $$->range_stop->type = ATV_MAX;
1518 }
1519 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1520 $$ = asn1p_constraint_new(yylineno);
1521 checkmem($$);
1522 $$->type = $2;
1523 $$->range_start = asn1p_value_fromint(-123);
1524 $$->range_stop = asn1p_value_fromint(321);
1525 $$->range_start->type = ATV_MIN;
1526 $$->range_stop->type = ATV_MAX;
Lev Walkinf15320b2004-06-03 03:38:44 +00001527 }
1528 | TableConstraint {
1529 $$ = $1;
1530 }
1531 | WithComponents {
1532 $$ = $1;
1533 }
1534 ;
1535
1536ConstraintRangeSpec:
1537 TOK_TwoDots { $$ = ACT_EL_RANGE; }
1538 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
1539 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
1540 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
1541 ;
1542
1543ConstraintSpec:
1544 TOK_SIZE {
1545 $$ = ACT_CT_SIZE;
1546 }
1547 | TOK_FROM {
1548 $$ = ACT_CT_FROM;
1549 }
1550 ;
1551
1552ConstraintValue:
1553 SignedNumber {
1554 $$ = $1;
1555 }
1556 | Identifier {
1557 asn1p_ref_t *ref;
1558 int ret;
1559 ref = asn1p_ref_new(yylineno);
1560 checkmem(ref);
1561 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1562 checkmem(ret == 0);
1563 $$ = asn1p_value_fromref(ref, 0);
1564 checkmem($$);
1565 free($1);
1566 }
1567 | TOK_cstring {
1568 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1569 checkmem($$);
1570 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001571
Lev Walkinf15320b2004-06-03 03:38:44 +00001572 | TOK_FALSE {
1573 $$ = asn1p_value_fromint(0);
1574 checkmem($$);
1575 $$->type = ATV_FALSE;
1576 }
1577 | TOK_TRUE {
1578 $$ = asn1p_value_fromint(1);
1579 checkmem($$);
1580 $$->type = ATV_TRUE;
1581 }
1582 ;
1583
1584WithComponents:
1585 TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
1586 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
1587 }
1588 ;
1589
1590WithComponentsList:
1591 WithComponentsElement {
1592 $$ = $1;
1593 }
1594 | WithComponentsList ',' WithComponentsElement {
1595 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
1596 }
1597 ;
1598
1599WithComponentsElement:
1600 TOK_ThreeDots {
1601 $$ = asn1p_constraint_new(yylineno);
1602 checkmem($$);
1603 $$->type = ACT_EL_EXT;
1604 }
1605 | Identifier optConstraints optPresenceConstraint {
1606 $$ = asn1p_constraint_new(yylineno);
1607 checkmem($$);
1608 $$->type = ACT_EL_VALUE;
1609 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1610 $$->presence = $3;
1611 }
1612 ;
1613
1614/*
1615 * presence constraint for WithComponents
1616 */
1617optPresenceConstraint:
1618 { $$ = ACPRES_DEFAULT; }
1619 | PresenceConstraint { $$ = $1; }
1620 ;
1621
1622PresenceConstraint:
1623 TOK_PRESENT {
1624 $$ = ACPRES_PRESENT;
1625 }
1626 | TOK_ABSENT {
1627 $$ = ACPRES_ABSENT;
1628 }
1629 | TOK_OPTIONAL {
1630 $$ = ACPRES_OPTIONAL;
1631 }
1632 ;
1633
1634TableConstraint:
1635 SimpleTableConstraint {
1636 $$ = $1;
1637 }
1638 | ComponentRelationConstraint {
1639 $$ = $1;
1640 }
1641 ;
1642
1643/*
1644 * "{ExtensionSet}"
1645 */
1646SimpleTableConstraint:
1647 '{' TypeRefName '}' {
1648 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
1649 asn1p_constraint_t *ct;
1650 int ret;
1651 ret = asn1p_ref_add_component(ref, $2, 0);
1652 checkmem(ret == 0);
1653 ct = asn1p_constraint_new(yylineno);
1654 checkmem($$);
1655 ct->type = ACT_EL_VALUE;
1656 ct->value = asn1p_value_fromref(ref, 0);
1657 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
1658 }
1659 ;
1660
1661ComponentRelationConstraint:
1662 SimpleTableConstraint '{' AtNotationList '}' {
1663 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
1664 }
1665 ;
1666
1667AtNotationList:
1668 AtNotationElement {
1669 $$ = asn1p_constraint_new(yylineno);
1670 checkmem($$);
1671 $$->type = ACT_EL_VALUE;
1672 $$->value = asn1p_value_fromref($1, 0);
1673 }
1674 | AtNotationList ',' AtNotationElement {
1675 asn1p_constraint_t *ct;
1676 ct = asn1p_constraint_new(yylineno);
1677 checkmem(ct);
1678 ct->type = ACT_EL_VALUE;
1679 ct->value = asn1p_value_fromref($3, 0);
1680 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
1681 }
1682 ;
1683
1684/*
1685 * @blah
1686 */
1687AtNotationElement:
1688 '@' ComponentIdList {
1689 char *p = malloc(strlen($2) + 2);
1690 int ret;
1691 *p = '@';
1692 strcpy(p + 1, $2);
1693 $$ = asn1p_ref_new(yylineno);
1694 ret = asn1p_ref_add_component($$, p, 0);
1695 checkmem(ret == 0);
1696 free(p);
1697 free($2);
1698 }
1699 | '@' '.' ComponentIdList {
1700 char *p = malloc(strlen($3) + 3);
1701 int ret;
1702 p[0] = '@';
1703 p[1] = '.';
1704 strcpy(p + 2, $3);
1705 $$ = asn1p_ref_new(yylineno);
1706 ret = asn1p_ref_add_component($$, p, 0);
1707 checkmem(ret == 0);
1708 free(p);
1709 free($3);
1710 }
1711 ;
1712
1713/* identifier "." ... */
1714ComponentIdList:
1715 Identifier {
1716 $$ = $1;
1717 }
1718 | ComponentIdList '.' Identifier {
1719 int l1 = strlen($1);
1720 int l3 = strlen($3);
1721 $$ = malloc(l1 + 1 + l3 + 1);
1722 memcpy($$, $1, l1);
1723 $$[l1] = '.';
1724 memcpy($$ + l1 + 1, $3, l3);
1725 $$[l1 + 1 + l3] = '\0';
1726 }
1727 ;
1728
1729
1730
1731/*
1732 * MARKERS
1733 */
1734
1735optMarker:
1736 { $$ = EM_NOMARK; }
1737 | Marker { $$ = $1; }
1738 ;
1739
1740Marker:
1741 TOK_OPTIONAL {
1742 $$ = EM_OPTIONAL;
1743 }
1744 | TOK_DEFAULT DefaultValue {
1745 $$ = EM_DEFAULT;
1746 /* FIXME: store DefaultValue somewhere */
1747 }
1748 ;
1749
1750DefaultValue:
1751 ConstraintValue {
1752 }
1753 | BasicTypeId {
1754 }
1755 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1756 }
1757 ;
1758
1759/*
1760 * Universal enumeration definition to use in INTEGER and ENUMERATED.
1761 * === EXAMPLE ===
1762 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
1763 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
1764 * === EOF ===
1765 */
1766/*
1767optUniverationDefinition:
1768 { $$ = 0; }
1769 | UniverationDefinition {
1770 $$ = $1;
1771 }
1772 ;
1773*/
1774
1775UniverationDefinition:
1776 '{' '}' {
1777 $$ = asn1p_expr_new(asn1p_lineno);
1778 checkmem($$);
1779 }
1780 | '{' UniverationList '}' {
1781 $$ = $2;
1782 }
1783 ;
1784
1785UniverationList:
1786 UniverationElement {
1787 $$ = asn1p_expr_new(asn1p_lineno);
1788 checkmem($$);
1789 TQ_ADD(&($$->members), $1, next);
1790 }
1791 | UniverationList ',' UniverationElement {
1792 $$ = $1;
1793 TQ_ADD(&($$->members), $3, next);
1794 }
1795 ;
1796
1797UniverationElement:
1798 Identifier {
1799 $$ = asn1p_expr_new(asn1p_lineno);
1800 checkmem($$);
1801 $$->expr_type = A1TC_UNIVERVAL;
1802 $$->meta_type = AMT_VALUE;
1803 $$->Identifier = $1;
1804 }
1805 | Identifier '(' SignedNumber ')' {
1806 $$ = asn1p_expr_new(asn1p_lineno);
1807 checkmem($$);
1808 $$->expr_type = A1TC_UNIVERVAL;
1809 $$->meta_type = AMT_VALUE;
1810 $$->Identifier = $1;
1811 $$->value = $3;
1812 }
1813 | Identifier '(' DefinedValue ')' {
1814 $$ = asn1p_expr_new(asn1p_lineno);
1815 checkmem($$);
1816 $$->expr_type = A1TC_UNIVERVAL;
1817 $$->meta_type = AMT_VALUE;
1818 $$->Identifier = $1;
1819 $$->value = $3;
1820 }
1821 | SignedNumber {
1822 $$ = asn1p_expr_new(asn1p_lineno);
1823 checkmem($$);
1824 $$->expr_type = A1TC_UNIVERVAL;
1825 $$->meta_type = AMT_VALUE;
1826 $$->value = $1;
1827 }
1828 | TOK_ThreeDots {
1829 $$ = asn1p_expr_new(asn1p_lineno);
1830 checkmem($$);
1831 $$->Identifier = strdup("...");
1832 checkmem($$->Identifier);
1833 $$->expr_type = A1TC_EXTENSIBLE;
1834 $$->meta_type = AMT_VALUE;
1835 }
1836 ;
1837
1838SignedNumber:
1839 TOK_number {
1840 $$ = asn1p_value_fromint($1);
1841 checkmem($$);
1842 }
1843 | TOK_number_negative {
1844 $$ = asn1p_value_fromint($1);
1845 checkmem($$);
1846 }
1847 ;
1848
1849/*
1850 * SEQUENCE definition.
1851 * === EXAMPLE ===
1852 * Struct1 ::= SEQUENCE {
1853 * memb1 Struct2,
1854 * memb2 SEQUENCE OF {
1855 * memb2-1 Struct 3
1856 * }
1857 * }
1858 * === EOF ===
1859 */
1860
1861
1862
1863/*
1864 * SET definition.
1865 * === EXAMPLE ===
1866 * Person ::= SET {
1867 * name [0] PrintableString (SIZE(1..20)),
1868 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
1869 * }
1870 * === EOF ===
1871 */
1872
1873optTag:
1874 { memset(&$$, 0, sizeof($$)); }
1875 | Tag { $$ = $1; }
1876 ;
1877
1878Tag:
1879 TOK_tag {
1880 $$ = $1;
1881 $$.tag_mode = TM_DEFAULT;
1882 }
1883 | TOK_tag TOK_IMPLICIT {
1884 $$ = $1;
1885 $$.tag_mode = TM_IMPLICIT;
1886 }
1887 | TOK_tag TOK_EXPLICIT {
1888 $$ = $1;
1889 $$.tag_mode = TM_EXPLICIT;
1890 }
1891 ;
1892
1893TypeRefName:
1894 TOK_typereference {
1895 checkmem($1);
1896 $$ = $1;
1897 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001898 | TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00001899 checkmem($1);
1900 $$ = $1;
1901 }
1902 ;
1903
Lev Walkinf59d0752004-08-18 04:59:12 +00001904
Lev Walkinf15320b2004-06-03 03:38:44 +00001905ObjectClassReference:
Lev Walkinf59d0752004-08-18 04:59:12 +00001906 TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00001907 checkmem($1);
1908 $$ = $1;
1909 }
1910 ;
1911
1912Identifier:
1913 TOK_identifier {
1914 checkmem($1);
1915 $$ = $1;
1916 }
1917 ;
1918
1919TaggedIdentifier:
1920 Identifier {
1921 memset(&$$, 0, sizeof($$));
1922 $$.name = $1;
1923 }
1924 | Identifier Tag {
1925 $$.name = $1;
1926 $$.tag = $2;
1927 }
1928 ;
1929
1930
1931%%
1932
1933
1934/*
1935 * Convert Xstring ('0101'B or '5'H) to the binary vector.
1936 */
1937static asn1p_value_t *
1938_convert_bitstring2binary(char *str, int base) {
1939 asn1p_value_t *val;
1940 int slen;
1941 int memlen;
1942 int baselen;
1943 int bits;
1944 uint8_t *binary_vector;
1945 uint8_t *bv_ptr;
1946 uint8_t cur_val;
1947
1948 assert(str);
1949 assert(str[0] == '\'');
1950
1951 switch(base) {
1952 case 'B':
1953 baselen = 1;
1954 break;
1955 case 'H':
1956 baselen = 4;
1957 break;
1958 default:
1959 assert(base == 'B' || base == 'H');
1960 errno = EINVAL;
1961 return NULL;
1962 }
1963
1964 slen = strlen(str);
1965 assert(str[slen - 1] == base);
1966 assert(str[slen - 2] == '\'');
1967
1968 memlen = slen / (8 / baselen); /* Conservative estimate */
1969
1970 bv_ptr = binary_vector = malloc(memlen + 1);
1971 if(bv_ptr == NULL)
1972 /* ENOMEM */
1973 return NULL;
1974
1975 cur_val = 0;
1976 bits = 0;
1977 while(*(++str) != '\'') {
1978 switch(baselen) {
1979 case 1:
1980 switch(*str) {
1981 case '1':
1982 cur_val |= 1 << (7 - (bits % 8));
1983 case '0':
1984 break;
1985 default:
1986 assert(!"_y UNREACH1");
1987 case ' ': case '\r': case '\n':
1988 continue;
1989 }
1990 break;
1991 case 4:
1992 switch(*str) {
1993 case '0': case '1': case '2': case '3': case '4':
1994 case '5': case '6': case '7': case '8': case '9':
1995 cur_val |= (*str - '0') << (4 - (bits % 8));
1996 break;
1997 case 'A': case 'B': case 'C':
1998 case 'D': case 'E': case 'F':
1999 cur_val |= ((*str - 'A') + 10)
2000 << (4 - (bits % 8));
2001 break;
2002 default:
2003 assert(!"_y UNREACH2");
2004 case ' ': case '\r': case '\n':
2005 continue;
2006 }
2007 break;
2008 }
2009
2010 bits += baselen;
2011 if((bits % 8) == 0) {
2012 *bv_ptr++ = cur_val;
2013 cur_val = 0;
2014 }
2015 }
2016
2017 *bv_ptr = cur_val;
2018 assert((bv_ptr - binary_vector) <= memlen);
2019
2020 val = asn1p_value_frombits(binary_vector, bits, 0);
2021 if(val == NULL) {
2022 free(binary_vector);
2023 }
2024
2025 return val;
2026}
2027
2028extern char *asn1p_text;
2029
2030int
2031yyerror(const char *msg) {
2032 fprintf(stderr,
2033 "ASN.1 grammar parse error "
2034 "near line %d (token \"%s\"): %s\n",
2035 asn1p_lineno, asn1p_text, msg);
2036 return -1;
2037}
2038
2039