blob: bc19522211bbd12431cf82f86f8a0e174a2e481d [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 }
vlma2374a02004-09-14 02:44:07 +00001079 | TOK_SEQUENCE optConstraints TOK_OF optTag TypeDeclaration {
vlm39e5ed72004-09-05 10:40:41 +00001080 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001081 checkmem($$);
1082 $$->constraints = $2;
1083 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1084 $$->meta_type = AMT_TYPE;
vlma2374a02004-09-14 02:44:07 +00001085 $5->tag = $4;
1086 asn1p_expr_add($$, $5);
vlmec8f6812004-08-22 03:19:54 +00001087 }
vlma2374a02004-09-14 02:44:07 +00001088 | TOK_SET optConstraints TOK_OF optTag TypeDeclaration {
vlm39e5ed72004-09-05 10:40:41 +00001089 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001090 checkmem($$);
1091 $$->constraints = $2;
1092 $$->expr_type = ASN_CONSTR_SET_OF;
1093 $$->meta_type = AMT_TYPE;
vlma2374a02004-09-14 02:44:07 +00001094 $5->tag = $4;
1095 asn1p_expr_add($$, $5);
vlmec8f6812004-08-22 03:19:54 +00001096 }
1097 | TOK_ANY {
vlm39e5ed72004-09-05 10:40:41 +00001098 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001099 checkmem($$);
vlm044f7442004-09-04 04:49:21 +00001100 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001101 $$->meta_type = AMT_TYPE;
1102 }
1103 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1104 int ret;
vlm39e5ed72004-09-05 10:40:41 +00001105 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001106 checkmem($$);
1107 $$->reference = asn1p_ref_new(yylineno);
1108 ret = asn1p_ref_add_component($$->reference,
1109 $4, RLT_lowercase);
1110 checkmem(ret == 0);
vlm044f7442004-09-04 04:49:21 +00001111 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001112 $$->meta_type = AMT_TYPE;
1113 }
vlmfa67ddc2004-06-03 03:38:44 +00001114 /*
1115 * A parametrized assignment.
1116 */
1117 | TypeRefName '{' ActualParameterList '}' {
1118 int ret;
1119 $$ = $3;
1120 assert($$->expr_type == 0);
1121 assert($$->meta_type == 0);
1122 assert($$->reference == 0);
1123 $$->reference = asn1p_ref_new(yylineno);
1124 checkmem($$->reference);
1125 ret = asn1p_ref_add_component($$->reference, $1, RLT_UNKNOWN);
1126 checkmem(ret == 0);
1127 free($1);
1128 $$->expr_type = A1TC_PARAMETRIZED;
1129 $$->meta_type = AMT_TYPE;
1130 }
1131 /*
1132 * A DefinedType reference.
1133 * "CLASS1.&id.&id2"
1134 * or
1135 * "Module.Type"
1136 * or
1137 * "Module.identifier"
1138 * or
1139 * "Type"
1140 */
1141 | ComplexTypeReference {
1142 $$ = asn1p_expr_new(yylineno);
1143 checkmem($$);
1144 $$->reference = $1;
1145 $$->expr_type = A1TC_REFERENCE;
1146 $$->meta_type = AMT_TYPEREF;
1147 }
1148 | TOK_INSTANCE TOK_OF ComplexTypeReference {
1149 $$ = asn1p_expr_new(yylineno);
1150 checkmem($$);
1151 $$->reference = $3;
1152 $$->expr_type = A1TC_INSTANCE;
1153 $$->meta_type = AMT_TYPE;
1154 }
1155 ;
1156
1157/*
1158 * A type name consisting of several components.
1159 * === EXAMPLE ===
1160 * === EOF ===
1161 */
1162ComplexTypeReference:
1163 TOK_typereference {
1164 int ret;
1165 $$ = asn1p_ref_new(yylineno);
1166 checkmem($$);
1167 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1168 checkmem(ret == 0);
1169 free($1);
1170 }
1171 | TOK_typereference '.' TypeRefName {
1172 int ret;
1173 $$ = asn1p_ref_new(yylineno);
1174 checkmem($$);
1175 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1176 checkmem(ret == 0);
1177 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1178 checkmem(ret == 0);
1179 free($1);
1180 }
1181 | TOK_typereference '.' Identifier {
1182 int ret;
1183 $$ = asn1p_ref_new(yylineno);
1184 checkmem($$);
1185 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1186 checkmem(ret == 0);
1187 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1188 checkmem(ret == 0);
1189 free($1);
1190 }
1191 | ObjectClassReference {
1192 int ret;
1193 $$ = asn1p_ref_new(yylineno);
1194 checkmem($$);
1195 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1196 free($1);
1197 checkmem(ret == 0);
1198 }
1199 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1200 int ret;
1201 $$ = $3;
1202 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1203 free($1);
1204 checkmem(ret == 0);
1205 /*
1206 * Move the last element infront.
1207 */
1208 {
1209 struct asn1p_ref_component_s tmp_comp;
1210 tmp_comp = $$->components[$$->comp_count-1];
1211 memmove(&$$->components[1],
1212 &$$->components[0],
1213 sizeof($$->components[0])
1214 * ($$->comp_count - 1));
1215 $$->components[0] = tmp_comp;
1216 }
1217 }
1218 ;
1219
1220ComplexTypeReferenceAmpList:
1221 ComplexTypeReferenceElement {
1222 int ret;
1223 $$ = asn1p_ref_new(yylineno);
1224 checkmem($$);
1225 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1226 free($1.name);
1227 checkmem(ret == 0);
1228 }
1229 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1230 int ret;
1231 $$ = $1;
1232 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1233 free($3.name);
1234 checkmem(ret == 0);
1235 }
1236 ;
1237
1238ComplexTypeReferenceElement: ClassFieldName;
1239ClassFieldIdentifier: ClassFieldName;
1240
1241ClassFieldName:
1242 /* "&Type1" */
1243 TOK_typefieldreference {
1244 $$.lex_type = RLT_AmpUppercase;
1245 $$.name = $1;
1246 }
1247 /* "&id" */
1248 | TOK_valuefieldreference {
1249 $$.lex_type = RLT_Amplowercase;
1250 $$.name = $1;
1251 }
1252 ;
1253
1254
1255/*
1256 * === EXAMPLE ===
1257 * value INTEGER ::= 1
1258 * === EOF ===
1259 */
1260ValueDefinition:
1261 Identifier DefinedTypeRef TOK_PPEQ InlineOrDefinedValue {
1262 $$ = $2;
1263 assert($$->Identifier == NULL);
1264 $$->Identifier = $1;
1265 $$->meta_type = AMT_VALUE;
1266 $$->value = $4;
1267 }
1268 ;
1269
1270InlineOrDefinedValue:
1271 '{' { asn1p_lexer_hack_push_opaque_state(); }
1272 Opaque /* '}' */ {
1273 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1274 checkmem($$);
1275 $$->type = ATV_UNPARSED;
1276 }
1277 | TOK_bstring {
1278 $$ = _convert_bitstring2binary($1, 'B');
1279 checkmem($$);
1280 }
1281 | TOK_hstring {
1282 $$ = _convert_bitstring2binary($1, 'H');
1283 checkmem($$);
1284 }
1285 | TOK_cstring {
1286 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1287 checkmem($$);
1288 }
1289 | SignedNumber {
1290 $$ = $1;
1291 }
1292 | DefinedValue {
1293 $$ = $1;
1294 }
1295 ;
1296
1297DefinedValue:
1298 Identifier {
1299 asn1p_ref_t *ref;
1300 int ret;
1301 ref = asn1p_ref_new(yylineno);
1302 checkmem(ref);
1303 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1304 checkmem(ret == 0);
1305 $$ = asn1p_value_fromref(ref, 0);
1306 checkmem($$);
1307 free($1);
1308 }
1309 | TypeRefName '.' Identifier {
1310 asn1p_ref_t *ref;
1311 int ret;
1312 ref = asn1p_ref_new(yylineno);
1313 checkmem(ref);
1314 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1315 checkmem(ret == 0);
1316 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1317 checkmem(ret == 0);
1318 $$ = asn1p_value_fromref(ref, 0);
1319 checkmem($$);
1320 free($1);
1321 free($3);
1322 }
1323 ;
1324
1325Opaque:
1326 TOK_opaque {
1327 $$.len = $1.len + 2;
1328 $$.buf = malloc($$.len + 1);
1329 checkmem($$.buf);
1330 $$.buf[0] = '{';
1331 $$.buf[1] = ' ';
1332 memcpy($$.buf + 2, $1.buf, $1.len);
1333 $$.buf[$$.len] = '\0';
1334 free($1.buf);
1335 }
1336 | Opaque TOK_opaque {
1337 int newsize = $1.len + $2.len;
1338 char *p = malloc(newsize + 1);
1339 checkmem(p);
1340 memcpy(p , $1.buf, $1.len);
1341 memcpy(p + $1.len, $2.buf, $2.len);
1342 p[newsize] = '\0';
1343 free($1.buf);
1344 free($2.buf);
1345 $$.buf = p;
1346 $$.len = newsize;
1347 }
1348 ;
1349
1350BasicTypeId:
1351 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1352 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1353 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1354 | BasicTypeId_UniverationCompatible { $$ = $1; }
1355 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1356 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1357 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1358 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1359 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1360 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1361 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1362 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
1363 ;
1364
1365/*
1366 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1367 */
1368BasicTypeId_UniverationCompatible:
1369 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1370 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1371 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1372 ;
1373
1374BasicType:
1375 BasicTypeId {
vlm39e5ed72004-09-05 10:40:41 +00001376 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001377 checkmem($$);
1378 $$->expr_type = $1;
1379 $$->meta_type = AMT_TYPE;
1380 }
1381 | BasicTypeId_UniverationCompatible UniverationDefinition {
1382 if($2) {
1383 $$ = $2;
1384 } else {
vlm39e5ed72004-09-05 10:40:41 +00001385 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001386 checkmem($$);
1387 }
1388 $$->expr_type = $1;
1389 $$->meta_type = AMT_TYPE;
1390 }
1391 ;
1392
1393BasicString:
1394 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1395 | TOK_GeneralString {
1396 $$ = ASN_STRING_GeneralString;
vlm80103492004-09-07 10:39:09 +00001397 fprintf(stderr, "WARNING: GeneralString is not fully supported");
vlmfa67ddc2004-06-03 03:38:44 +00001398 }
1399 | TOK_GraphicString {
1400 $$ = ASN_STRING_GraphicString;
vlm80103492004-09-07 10:39:09 +00001401 fprintf(stderr, "WARNING: GraphicString is not fully supported");
vlmfa67ddc2004-06-03 03:38:44 +00001402 }
1403 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1404 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1405 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1406 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1407 | TOK_T61String {
1408 $$ = ASN_STRING_T61String;
vlm80103492004-09-07 10:39:09 +00001409 fprintf(stderr, "WARNING: T61String is not fully supported");
vlmfa67ddc2004-06-03 03:38:44 +00001410 }
1411 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1412 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1413 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1414 | TOK_VideotexString {
1415 $$ = ASN_STRING_VideotexString;
vlm80103492004-09-07 10:39:09 +00001416 fprintf(stderr, "WARNING: VideotexString is not fully supported");
vlmfa67ddc2004-06-03 03:38:44 +00001417 }
1418 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1419 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1420 ;
1421
vlm5f0128b2004-08-20 13:25:29 +00001422
vlmfa67ddc2004-06-03 03:38:44 +00001423/*
1424 * Data type constraints.
1425 */
vlmfa67ddc2004-06-03 03:38:44 +00001426Union: '|' | TOK_UNION;
1427Intersection: '^' | TOK_INTERSECTION;
1428Except: TOK_EXCEPT;
1429
vlm9283dbe2004-08-18 04:59:12 +00001430optConstraints:
1431 { $$ = 0; }
vlm5f0128b2004-08-20 13:25:29 +00001432 | Constraints {
1433 $$ = $1;
1434 }
1435 ;
1436
1437Constraints:
1438 SetOfConstraints {
vlm9283dbe2004-08-18 04:59:12 +00001439 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
1440 }
1441 | TOK_SIZE '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001442 /*
1443 * This is a special case, for compatibility purposes.
vlm9283dbe2004-08-18 04:59:12 +00001444 * It goes without parentheses.
vlmfa67ddc2004-06-03 03:38:44 +00001445 */
vlm5f0128b2004-08-20 13:25:29 +00001446 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001447 }
vlmfa67ddc2004-06-03 03:38:44 +00001448 ;
1449
vlm9283dbe2004-08-18 04:59:12 +00001450SetOfConstraints:
1451 '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001452 $$ = $2;
1453 }
vlm9283dbe2004-08-18 04:59:12 +00001454 | SetOfConstraints '(' ElementSetSpecs ')' {
1455 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
1456 }
vlmfa67ddc2004-06-03 03:38:44 +00001457 ;
1458
vlm9283dbe2004-08-18 04:59:12 +00001459ElementSetSpecs:
1460 ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001461 $$ = $1;
1462 }
vlm9283dbe2004-08-18 04:59:12 +00001463 | ElementSetSpec ',' TOK_ThreeDots {
vlmfa67ddc2004-06-03 03:38:44 +00001464 asn1p_constraint_t *ct;
1465 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001466 ct->type = ACT_EL_EXT;
1467 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
1468 }
vlm9283dbe2004-08-18 04:59:12 +00001469 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001470 asn1p_constraint_t *ct;
1471 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001472 ct->type = ACT_EL_EXT;
1473 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlm6f5eb0b2004-08-13 12:35:09 +00001474 ct = $$;
1475 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
vlmfa67ddc2004-06-03 03:38:44 +00001476 }
vlmfa67ddc2004-06-03 03:38:44 +00001477 ;
1478
vlm9283dbe2004-08-18 04:59:12 +00001479ElementSetSpec:
1480 ConstraintSubtypeElement {
1481 $$ = $1;
1482 }
1483 | ElementSetSpec Union ConstraintSubtypeElement {
vlmfa67ddc2004-06-03 03:38:44 +00001484 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
1485 }
vlm9283dbe2004-08-18 04:59:12 +00001486 | ElementSetSpec Intersection ConstraintSubtypeElement {
vlmfa67ddc2004-06-03 03:38:44 +00001487 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
1488 }
vlm9283dbe2004-08-18 04:59:12 +00001489 | ConstraintSubtypeElement Except ConstraintSubtypeElement {
vlmfa67ddc2004-06-03 03:38:44 +00001490 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
1491 }
1492 ;
1493
1494ConstraintSubtypeElement:
vlm9283dbe2004-08-18 04:59:12 +00001495 ConstraintSpec '(' ElementSetSpecs ')' {
1496 int ret;
1497 $$ = asn1p_constraint_new(yylineno);
1498 checkmem($$);
1499 $$->type = $1;
1500 ret = asn1p_constraint_insert($$, $3);
1501 checkmem(ret == 0);
1502 }
1503 | '(' ElementSetSpecs ')' {
1504 int ret;
1505 $$ = asn1p_constraint_new(yylineno);
1506 checkmem($$);
1507 $$->type = ACT_CA_SET;
1508 ret = asn1p_constraint_insert($$, $2);
1509 checkmem(ret == 0);
1510 }
1511 | ConstraintValue {
vlmfa67ddc2004-06-03 03:38:44 +00001512 $$ = asn1p_constraint_new(yylineno);
1513 checkmem($$);
1514 $$->type = ACT_EL_VALUE;
1515 $$->value = $1;
1516 }
1517 | ConstraintValue ConstraintRangeSpec ConstraintValue {
1518 $$ = asn1p_constraint_new(yylineno);
1519 checkmem($$);
1520 $$->type = $2;
1521 $$->range_start = $1;
1522 $$->range_stop = $3;
1523 }
vlm9283dbe2004-08-18 04:59:12 +00001524 | TOK_MIN ConstraintRangeSpec ConstraintValue {
vlmfa67ddc2004-06-03 03:38:44 +00001525 $$ = asn1p_constraint_new(yylineno);
1526 checkmem($$);
vlm9283dbe2004-08-18 04:59:12 +00001527 $$->type = $2;
1528 $$->range_start = asn1p_value_fromint(-123);
1529 $$->range_stop = $3;
1530 $$->range_start->type = ATV_MIN;
1531 }
1532 | ConstraintValue ConstraintRangeSpec TOK_MAX {
1533 $$ = asn1p_constraint_new(yylineno);
1534 checkmem($$);
1535 $$->type = $2;
1536 $$->range_start = $1;
1537 $$->range_stop = asn1p_value_fromint(321);
1538 $$->range_stop->type = ATV_MAX;
1539 }
1540 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1541 $$ = asn1p_constraint_new(yylineno);
1542 checkmem($$);
1543 $$->type = $2;
1544 $$->range_start = asn1p_value_fromint(-123);
1545 $$->range_stop = asn1p_value_fromint(321);
1546 $$->range_start->type = ATV_MIN;
1547 $$->range_stop->type = ATV_MAX;
vlmfa67ddc2004-06-03 03:38:44 +00001548 }
1549 | TableConstraint {
1550 $$ = $1;
1551 }
1552 | WithComponents {
1553 $$ = $1;
1554 }
1555 ;
1556
1557ConstraintRangeSpec:
1558 TOK_TwoDots { $$ = ACT_EL_RANGE; }
1559 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
1560 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
1561 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
1562 ;
1563
1564ConstraintSpec:
1565 TOK_SIZE {
1566 $$ = ACT_CT_SIZE;
1567 }
1568 | TOK_FROM {
1569 $$ = ACT_CT_FROM;
1570 }
1571 ;
1572
1573ConstraintValue:
1574 SignedNumber {
1575 $$ = $1;
1576 }
1577 | Identifier {
1578 asn1p_ref_t *ref;
1579 int ret;
1580 ref = asn1p_ref_new(yylineno);
1581 checkmem(ref);
1582 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1583 checkmem(ret == 0);
1584 $$ = asn1p_value_fromref(ref, 0);
1585 checkmem($$);
1586 free($1);
1587 }
1588 | TOK_cstring {
1589 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1590 checkmem($$);
1591 }
vlm9283dbe2004-08-18 04:59:12 +00001592
vlmfa67ddc2004-06-03 03:38:44 +00001593 | TOK_FALSE {
1594 $$ = asn1p_value_fromint(0);
1595 checkmem($$);
1596 $$->type = ATV_FALSE;
1597 }
1598 | TOK_TRUE {
1599 $$ = asn1p_value_fromint(1);
1600 checkmem($$);
1601 $$->type = ATV_TRUE;
1602 }
1603 ;
1604
1605WithComponents:
1606 TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
1607 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
1608 }
1609 ;
1610
1611WithComponentsList:
1612 WithComponentsElement {
1613 $$ = $1;
1614 }
1615 | WithComponentsList ',' WithComponentsElement {
1616 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
1617 }
1618 ;
1619
1620WithComponentsElement:
1621 TOK_ThreeDots {
1622 $$ = asn1p_constraint_new(yylineno);
1623 checkmem($$);
1624 $$->type = ACT_EL_EXT;
1625 }
1626 | Identifier optConstraints optPresenceConstraint {
1627 $$ = asn1p_constraint_new(yylineno);
1628 checkmem($$);
1629 $$->type = ACT_EL_VALUE;
1630 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1631 $$->presence = $3;
1632 }
1633 ;
1634
1635/*
1636 * presence constraint for WithComponents
1637 */
1638optPresenceConstraint:
1639 { $$ = ACPRES_DEFAULT; }
1640 | PresenceConstraint { $$ = $1; }
1641 ;
1642
1643PresenceConstraint:
1644 TOK_PRESENT {
1645 $$ = ACPRES_PRESENT;
1646 }
1647 | TOK_ABSENT {
1648 $$ = ACPRES_ABSENT;
1649 }
1650 | TOK_OPTIONAL {
1651 $$ = ACPRES_OPTIONAL;
1652 }
1653 ;
1654
1655TableConstraint:
1656 SimpleTableConstraint {
1657 $$ = $1;
1658 }
1659 | ComponentRelationConstraint {
1660 $$ = $1;
1661 }
1662 ;
1663
1664/*
1665 * "{ExtensionSet}"
1666 */
1667SimpleTableConstraint:
1668 '{' TypeRefName '}' {
1669 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
1670 asn1p_constraint_t *ct;
1671 int ret;
1672 ret = asn1p_ref_add_component(ref, $2, 0);
1673 checkmem(ret == 0);
1674 ct = asn1p_constraint_new(yylineno);
1675 checkmem($$);
1676 ct->type = ACT_EL_VALUE;
1677 ct->value = asn1p_value_fromref(ref, 0);
1678 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
1679 }
1680 ;
1681
1682ComponentRelationConstraint:
1683 SimpleTableConstraint '{' AtNotationList '}' {
1684 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
1685 }
1686 ;
1687
1688AtNotationList:
1689 AtNotationElement {
1690 $$ = asn1p_constraint_new(yylineno);
1691 checkmem($$);
1692 $$->type = ACT_EL_VALUE;
1693 $$->value = asn1p_value_fromref($1, 0);
1694 }
1695 | AtNotationList ',' AtNotationElement {
1696 asn1p_constraint_t *ct;
1697 ct = asn1p_constraint_new(yylineno);
1698 checkmem(ct);
1699 ct->type = ACT_EL_VALUE;
1700 ct->value = asn1p_value_fromref($3, 0);
1701 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
1702 }
1703 ;
1704
1705/*
1706 * @blah
1707 */
1708AtNotationElement:
1709 '@' ComponentIdList {
1710 char *p = malloc(strlen($2) + 2);
1711 int ret;
1712 *p = '@';
1713 strcpy(p + 1, $2);
1714 $$ = asn1p_ref_new(yylineno);
1715 ret = asn1p_ref_add_component($$, p, 0);
1716 checkmem(ret == 0);
1717 free(p);
1718 free($2);
1719 }
1720 | '@' '.' ComponentIdList {
1721 char *p = malloc(strlen($3) + 3);
1722 int ret;
1723 p[0] = '@';
1724 p[1] = '.';
1725 strcpy(p + 2, $3);
1726 $$ = asn1p_ref_new(yylineno);
1727 ret = asn1p_ref_add_component($$, p, 0);
1728 checkmem(ret == 0);
1729 free(p);
1730 free($3);
1731 }
1732 ;
1733
1734/* identifier "." ... */
1735ComponentIdList:
1736 Identifier {
1737 $$ = $1;
1738 }
1739 | ComponentIdList '.' Identifier {
1740 int l1 = strlen($1);
1741 int l3 = strlen($3);
1742 $$ = malloc(l1 + 1 + l3 + 1);
1743 memcpy($$, $1, l1);
1744 $$[l1] = '.';
1745 memcpy($$ + l1 + 1, $3, l3);
1746 $$[l1 + 1 + l3] = '\0';
1747 }
1748 ;
1749
1750
1751
1752/*
1753 * MARKERS
1754 */
1755
1756optMarker:
1757 { $$ = EM_NOMARK; }
1758 | Marker { $$ = $1; }
1759 ;
1760
1761Marker:
1762 TOK_OPTIONAL {
1763 $$ = EM_OPTIONAL;
1764 }
1765 | TOK_DEFAULT DefaultValue {
1766 $$ = EM_DEFAULT;
1767 /* FIXME: store DefaultValue somewhere */
1768 }
1769 ;
1770
1771DefaultValue:
1772 ConstraintValue {
1773 }
1774 | BasicTypeId {
1775 }
1776 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1777 }
1778 ;
1779
1780/*
1781 * Universal enumeration definition to use in INTEGER and ENUMERATED.
1782 * === EXAMPLE ===
1783 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
1784 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
1785 * === EOF ===
1786 */
1787/*
1788optUniverationDefinition:
1789 { $$ = 0; }
1790 | UniverationDefinition {
1791 $$ = $1;
1792 }
1793 ;
1794*/
1795
1796UniverationDefinition:
1797 '{' '}' {
vlm39e5ed72004-09-05 10:40:41 +00001798 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001799 checkmem($$);
1800 }
1801 | '{' UniverationList '}' {
1802 $$ = $2;
1803 }
1804 ;
1805
1806UniverationList:
1807 UniverationElement {
vlm39e5ed72004-09-05 10:40:41 +00001808 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001809 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +00001810 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +00001811 }
1812 | UniverationList ',' UniverationElement {
1813 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +00001814 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001815 }
1816 ;
1817
1818UniverationElement:
1819 Identifier {
vlm39e5ed72004-09-05 10:40:41 +00001820 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001821 checkmem($$);
1822 $$->expr_type = A1TC_UNIVERVAL;
1823 $$->meta_type = AMT_VALUE;
1824 $$->Identifier = $1;
1825 }
1826 | Identifier '(' SignedNumber ')' {
vlm39e5ed72004-09-05 10:40:41 +00001827 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001828 checkmem($$);
1829 $$->expr_type = A1TC_UNIVERVAL;
1830 $$->meta_type = AMT_VALUE;
1831 $$->Identifier = $1;
1832 $$->value = $3;
1833 }
1834 | Identifier '(' DefinedValue ')' {
vlm39e5ed72004-09-05 10:40:41 +00001835 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001836 checkmem($$);
1837 $$->expr_type = A1TC_UNIVERVAL;
1838 $$->meta_type = AMT_VALUE;
1839 $$->Identifier = $1;
1840 $$->value = $3;
1841 }
1842 | SignedNumber {
vlm39e5ed72004-09-05 10:40:41 +00001843 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001844 checkmem($$);
1845 $$->expr_type = A1TC_UNIVERVAL;
1846 $$->meta_type = AMT_VALUE;
1847 $$->value = $1;
1848 }
1849 | TOK_ThreeDots {
vlm39e5ed72004-09-05 10:40:41 +00001850 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001851 checkmem($$);
1852 $$->Identifier = strdup("...");
1853 checkmem($$->Identifier);
1854 $$->expr_type = A1TC_EXTENSIBLE;
1855 $$->meta_type = AMT_VALUE;
1856 }
1857 ;
1858
1859SignedNumber:
1860 TOK_number {
1861 $$ = asn1p_value_fromint($1);
1862 checkmem($$);
1863 }
1864 | TOK_number_negative {
1865 $$ = asn1p_value_fromint($1);
1866 checkmem($$);
1867 }
1868 ;
1869
1870/*
1871 * SEQUENCE definition.
1872 * === EXAMPLE ===
1873 * Struct1 ::= SEQUENCE {
1874 * memb1 Struct2,
1875 * memb2 SEQUENCE OF {
1876 * memb2-1 Struct 3
1877 * }
1878 * }
1879 * === EOF ===
1880 */
1881
1882
1883
1884/*
1885 * SET definition.
1886 * === EXAMPLE ===
1887 * Person ::= SET {
1888 * name [0] PrintableString (SIZE(1..20)),
1889 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
1890 * }
1891 * === EOF ===
1892 */
1893
1894optTag:
1895 { memset(&$$, 0, sizeof($$)); }
1896 | Tag { $$ = $1; }
1897 ;
1898
1899Tag:
1900 TOK_tag {
1901 $$ = $1;
1902 $$.tag_mode = TM_DEFAULT;
1903 }
1904 | TOK_tag TOK_IMPLICIT {
1905 $$ = $1;
1906 $$.tag_mode = TM_IMPLICIT;
1907 }
1908 | TOK_tag TOK_EXPLICIT {
1909 $$ = $1;
1910 $$.tag_mode = TM_EXPLICIT;
1911 }
1912 ;
1913
1914TypeRefName:
1915 TOK_typereference {
1916 checkmem($1);
1917 $$ = $1;
1918 }
vlm9283dbe2004-08-18 04:59:12 +00001919 | TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00001920 checkmem($1);
1921 $$ = $1;
1922 }
1923 ;
1924
vlm9283dbe2004-08-18 04:59:12 +00001925
vlmfa67ddc2004-06-03 03:38:44 +00001926ObjectClassReference:
vlm9283dbe2004-08-18 04:59:12 +00001927 TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00001928 checkmem($1);
1929 $$ = $1;
1930 }
1931 ;
1932
1933Identifier:
1934 TOK_identifier {
1935 checkmem($1);
1936 $$ = $1;
1937 }
1938 ;
1939
vlmfa67ddc2004-06-03 03:38:44 +00001940%%
1941
1942
1943/*
1944 * Convert Xstring ('0101'B or '5'H) to the binary vector.
1945 */
1946static asn1p_value_t *
1947_convert_bitstring2binary(char *str, int base) {
1948 asn1p_value_t *val;
1949 int slen;
1950 int memlen;
1951 int baselen;
1952 int bits;
1953 uint8_t *binary_vector;
1954 uint8_t *bv_ptr;
1955 uint8_t cur_val;
1956
1957 assert(str);
1958 assert(str[0] == '\'');
1959
1960 switch(base) {
1961 case 'B':
1962 baselen = 1;
1963 break;
1964 case 'H':
1965 baselen = 4;
1966 break;
1967 default:
1968 assert(base == 'B' || base == 'H');
1969 errno = EINVAL;
1970 return NULL;
1971 }
1972
1973 slen = strlen(str);
1974 assert(str[slen - 1] == base);
1975 assert(str[slen - 2] == '\'');
1976
1977 memlen = slen / (8 / baselen); /* Conservative estimate */
1978
1979 bv_ptr = binary_vector = malloc(memlen + 1);
1980 if(bv_ptr == NULL)
1981 /* ENOMEM */
1982 return NULL;
1983
1984 cur_val = 0;
1985 bits = 0;
1986 while(*(++str) != '\'') {
1987 switch(baselen) {
1988 case 1:
1989 switch(*str) {
1990 case '1':
1991 cur_val |= 1 << (7 - (bits % 8));
1992 case '0':
1993 break;
1994 default:
1995 assert(!"_y UNREACH1");
1996 case ' ': case '\r': case '\n':
1997 continue;
1998 }
1999 break;
2000 case 4:
2001 switch(*str) {
2002 case '0': case '1': case '2': case '3': case '4':
2003 case '5': case '6': case '7': case '8': case '9':
2004 cur_val |= (*str - '0') << (4 - (bits % 8));
2005 break;
2006 case 'A': case 'B': case 'C':
2007 case 'D': case 'E': case 'F':
2008 cur_val |= ((*str - 'A') + 10)
2009 << (4 - (bits % 8));
2010 break;
2011 default:
2012 assert(!"_y UNREACH2");
2013 case ' ': case '\r': case '\n':
2014 continue;
2015 }
2016 break;
2017 }
2018
2019 bits += baselen;
2020 if((bits % 8) == 0) {
2021 *bv_ptr++ = cur_val;
2022 cur_val = 0;
2023 }
2024 }
2025
2026 *bv_ptr = cur_val;
2027 assert((bv_ptr - binary_vector) <= memlen);
2028
2029 val = asn1p_value_frombits(binary_vector, bits, 0);
2030 if(val == NULL) {
2031 free(binary_vector);
2032 }
2033
2034 return val;
2035}
2036
2037extern char *asn1p_text;
2038
2039int
2040yyerror(const char *msg) {
2041 fprintf(stderr,
2042 "ASN.1 grammar parse error "
2043 "near line %d (token \"%s\"): %s\n",
vlm39e5ed72004-09-05 10:40:41 +00002044 yylineno, asn1p_text, msg);
vlmfa67ddc2004-06-03 03:38:44 +00002045 return -1;
2046}
2047
2048