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