blob: e316119ab7b20e8cfe2e986a7cd663297e5a92f0 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001%{
2
3#include <stdlib.h>
4#include <stdio.h>
5#include <string.h>
6#include <errno.h>
7#include <assert.h>
8
9#include "asn1parser.h"
10
11#define YYPARSE_PARAM param
12#define YYERROR_VERBOSE
13
14int yylex(void);
15int yyerror(const char *msg);
16void asn1p_lexer_hack_push_opaque_state(void);
17void asn1p_lexer_hack_enable_with_syntax(void);
Lev Walkinf59d0752004-08-18 04:59:12 +000018void asn1p_lexer_hack_push_encoding_control(void);
Lev Walkinf15320b2004-06-03 03:38:44 +000019#define yylineno asn1p_lineno
20extern int asn1p_lineno;
21
22
23static asn1p_value_t *
24 _convert_bitstring2binary(char *str, int base);
25
Lev Walkin1004aa92004-09-08 00:28:11 +000026#define checkmem(ptr) do { \
27 if(!(ptr)) \
28 return yyerror("Memory failure"); \
Lev Walkinf15320b2004-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 */
Lev Walkin9c974182004-09-15 11:59:51 +000077 struct asn1p_expr_marker_s a_marker; /* OPTIONAL/DEFAULT */
Lev Walkinf15320b2004-06-03 03:38:44 +000078 enum asn1p_constr_pres_e a_pres; /* PRESENT/ABSENT/OPTIONAL */
Lev Walkin144db9b2004-10-12 23:26:53 +000079 asn1c_integer_t a_int;
Lev Walkinf15320b2004-06-03 03:38:44 +000080 char *tv_str;
81 struct {
82 char *buf;
83 int len;
84 } tv_opaque;
85 struct {
86 char *name;
87 struct asn1p_type_tag_s tag;
88 } tv_nametag;
89};
90
91/*
92 * Token types returned by scanner.
93 */
94%token TOK_PPEQ /* "::=", Pseudo Pascal EQuality */
95%token <tv_opaque> TOK_opaque /* opaque data (driven from .y) */
96%token <tv_str> TOK_bstring
97%token <tv_opaque> TOK_cstring
98%token <tv_str> TOK_hstring
99%token <tv_str> TOK_identifier
100%token <a_int> TOK_number
101%token <a_int> TOK_number_negative
102%token <tv_str> TOK_typereference
Lev Walkinf59d0752004-08-18 04:59:12 +0000103%token <tv_str> TOK_capitalreference /* "CLASS1" */
Lev Walkinf15320b2004-06-03 03:38:44 +0000104%token <tv_str> TOK_typefieldreference /* "&Pork" */
105%token <tv_str> TOK_valuefieldreference /* "&id" */
106
107/*
108 * Token types representing ASN.1 standard keywords.
109 */
110%token TOK_ABSENT
111%token TOK_ABSTRACT_SYNTAX
112%token TOK_ALL
113%token TOK_ANY
114%token TOK_APPLICATION
115%token TOK_AUTOMATIC
116%token TOK_BEGIN
117%token TOK_BIT
118%token TOK_BMPString
119%token TOK_BOOLEAN
120%token TOK_BY
121%token TOK_CHARACTER
122%token TOK_CHOICE
123%token TOK_CLASS
124%token TOK_COMPONENT
125%token TOK_COMPONENTS
126%token TOK_CONSTRAINED
127%token TOK_CONTAINING
128%token TOK_DEFAULT
129%token TOK_DEFINITIONS
130%token TOK_DEFINED
131%token TOK_EMBEDDED
132%token TOK_ENCODED
Lev Walkinf59d0752004-08-18 04:59:12 +0000133%token TOK_ENCODING_CONTROL
Lev Walkinf15320b2004-06-03 03:38:44 +0000134%token TOK_END
135%token TOK_ENUMERATED
136%token TOK_EXPLICIT
137%token TOK_EXPORTS
138%token TOK_EXTENSIBILITY
139%token TOK_EXTERNAL
140%token TOK_FALSE
141%token TOK_FROM
142%token TOK_GeneralizedTime
143%token TOK_GeneralString
144%token TOK_GraphicString
145%token TOK_IA5String
146%token TOK_IDENTIFIER
147%token TOK_IMPLICIT
148%token TOK_IMPLIED
149%token TOK_IMPORTS
150%token TOK_INCLUDES
151%token TOK_INSTANCE
Lev Walkinf59d0752004-08-18 04:59:12 +0000152%token TOK_INSTRUCTIONS
Lev Walkinf15320b2004-06-03 03:38:44 +0000153%token TOK_INTEGER
154%token TOK_ISO646String
155%token TOK_MAX
156%token TOK_MIN
157%token TOK_MINUS_INFINITY
158%token TOK_NULL
159%token TOK_NumericString
160%token TOK_OBJECT
161%token TOK_ObjectDescriptor
162%token TOK_OCTET
163%token TOK_OF
164%token TOK_OPTIONAL
165%token TOK_PATTERN
166%token TOK_PDV
167%token TOK_PLUS_INFINITY
168%token TOK_PRESENT
169%token TOK_PrintableString
170%token TOK_PRIVATE
171%token TOK_REAL
172%token TOK_RELATIVE_OID
173%token TOK_SEQUENCE
174%token TOK_SET
175%token TOK_SIZE
176%token TOK_STRING
177%token TOK_SYNTAX
178%token TOK_T61String
179%token TOK_TAGS
180%token TOK_TeletexString
181%token TOK_TRUE
182%token TOK_TYPE_IDENTIFIER
183%token TOK_UNIQUE
184%token TOK_UNIVERSAL
185%token TOK_UniversalString
186%token TOK_UTCTime
187%token TOK_UTF8String
188%token TOK_VideotexString
189%token TOK_VisibleString
190%token TOK_WITH
191
Lev Walkinf15320b2004-06-03 03:38:44 +0000192%left TOK_EXCEPT
Lev Walkinf59d0752004-08-18 04:59:12 +0000193%left '^' TOK_INTERSECTION
194%left '|' TOK_UNION
Lev Walkinf15320b2004-06-03 03:38:44 +0000195
196/* Misc tags */
197%token TOK_TwoDots /* .. */
198%token TOK_ThreeDots /* ... */
Lev Walkinf15320b2004-06-03 03:38:44 +0000199
200
201/*
202 * Types defined herein.
203 */
204%type <a_grammar> ModuleList
205%type <a_module> ModuleSpecification
206%type <a_module> ModuleSpecificationBody
207%type <a_module> ModuleSpecificationElement
208%type <a_module> optModuleSpecificationBody /* Optional */
209%type <a_module_flags> optModuleSpecificationFlags
210%type <a_module_flags> ModuleSpecificationFlags /* Set of FL */
211%type <a_module_flags> ModuleSpecificationFlag /* Single FL */
212%type <a_module> ImportsDefinition
213%type <a_module> ImportsBundleSet
214%type <a_xports> ImportsBundle
215%type <a_xports> ImportsList
216%type <a_xports> ExportsDefinition
217%type <a_xports> ExportsBody
218%type <a_expr> ImportsElement
219%type <a_expr> ExportsElement
Lev Walkinf15320b2004-06-03 03:38:44 +0000220%type <a_expr> ExtensionAndException
Lev Walkin070a52d2004-08-22 03:19:54 +0000221%type <a_expr> TypeDeclaration
Lev Walkinf15320b2004-06-03 03:38:44 +0000222%type <a_ref> ComplexTypeReference
223%type <a_ref> ComplexTypeReferenceAmpList
224%type <a_refcomp> ComplexTypeReferenceElement
225%type <a_refcomp> ClassFieldIdentifier
226%type <a_refcomp> ClassFieldName
227%type <a_expr> ClassFieldList
228%type <a_expr> ClassField
229%type <a_expr> ClassDeclaration
Lev Walkin070a52d2004-08-22 03:19:54 +0000230%type <a_expr> Type
Lev Walkinf15320b2004-06-03 03:38:44 +0000231%type <a_expr> DataTypeReference /* Type1 ::= Type2 */
232%type <a_expr> DefinedTypeRef
233%type <a_expr> ValueSetDefinition /* Val INTEGER ::= {1|2} */
234%type <a_expr> ValueDefinition /* val INTEGER ::= 1*/
Lev Walkinceb20e72004-09-05 10:40:41 +0000235%type <a_expr> optValueSetBody
236%type <a_expr> ValueSetBody
237%type <a_expr> ValueSetElement
Lev Walkin9c974182004-09-15 11:59:51 +0000238%type <a_value> Value
Lev Walkinf15320b2004-06-03 03:38:44 +0000239%type <a_value> DefinedValue
240%type <a_value> SignedNumber
Lev Walkin144db9b2004-10-12 23:26:53 +0000241%type <a_expr> optComponentTypeLists
Lev Walkin070a52d2004-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
Lev Walkinf15320b2004-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
Lev Walkinf15320b2004-06-03 03:38:44 +0000252%type <tv_str> Identifier
Lev Walkin83cac2f2004-09-22 16:03:36 +0000253%type <tv_str> optIdentifier
Lev Walkinf15320b2004-06-03 03:38:44 +0000254%type <a_parg> ParameterArgumentName
255%type <a_plist> ParameterArgumentList
256%type <a_expr> ActualParameter
257%type <a_expr> ActualParameterList
258%type <a_oid> ObjectIdentifier /* OID */
259%type <a_oid> optObjectIdentifier /* Optional OID */
260%type <a_oid> ObjectIdentifierBody
261%type <a_oid_arc> ObjectIdentifierElement
262%type <a_expr> BasicType
263%type <a_type> BasicTypeId
264%type <a_type> BasicTypeId_UniverationCompatible
265%type <a_type> BasicString
266%type <tv_opaque> Opaque
267//%type <tv_opaque> StringValue
Lev Walkinc603f102005-01-23 09:51:44 +0000268%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
269%type <a_tag> TagClass TagTypeValue TagPlicit
Lev Walkinf15320b2004-06-03 03:38:44 +0000270%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
271%type <a_constr> optConstraints
Lev Walkind2ea1de2004-08-20 13:25:29 +0000272%type <a_constr> Constraints
Lev Walkinf59d0752004-08-18 04:59:12 +0000273%type <a_constr> SetOfConstraints
274%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
275%type <a_constr> ElementSetSpec /* 1..2,...,3 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000276%type <a_constr> ConstraintSubtypeElement /* 1..2 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000277%type <a_constr> SimpleTableConstraint
278%type <a_constr> TableConstraint
279%type <a_constr> WithComponents
280%type <a_constr> WithComponentsList
281%type <a_constr> WithComponentsElement
282%type <a_constr> ComponentRelationConstraint
283%type <a_constr> AtNotationList
284%type <a_ref> AtNotationElement
285%type <a_value> ConstraintValue
286%type <a_ctype> ConstraintSpec
287%type <a_ctype> ConstraintRangeSpec
288%type <a_wsynt> optWithSyntax
289%type <a_wsynt> WithSyntax
290%type <a_wsynt> WithSyntaxFormat
291%type <a_wchunk> WithSyntaxFormatToken
292%type <a_marker> optMarker Marker
293%type <a_int> optUnique
294%type <a_pres> optPresenceConstraint PresenceConstraint
295%type <tv_str> ComponentIdList
296
297
298%%
299
300
301ParsedGrammar:
302 ModuleList {
303 *(void **)param = $1;
304 }
305 ;
306
307ModuleList:
308 ModuleSpecification {
309 $$ = asn1p_new();
310 checkmem($$);
311 TQ_ADD(&($$->modules), $1, mod_next);
312 }
313 | ModuleList ModuleSpecification {
314 $$ = $1;
315 TQ_ADD(&($$->modules), $2, mod_next);
316 }
317 ;
318
319/*
320 * ASN module definition.
321 * === EXAMPLE ===
322 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
323 * BEGIN
324 * ...
325 * END
326 * === EOF ===
327 */
328
329ModuleSpecification:
330 TypeRefName optObjectIdentifier TOK_DEFINITIONS
331 optModuleSpecificationFlags
332 TOK_PPEQ TOK_BEGIN
333 optModuleSpecificationBody
334 TOK_END {
335
336 if($7) {
337 $$ = $7;
338 } else {
339 /* There's a chance that a module is just plain empty */
340 $$ = asn1p_module_new();
341 }
342 checkmem($$);
343
344 $$->Identifier = $1;
345 $$->module_oid = $2;
346 $$->module_flags = $4;
347 }
348 ;
349
350/*
351 * Object Identifier Definition
352 * { iso member-body(2) 3 }
353 */
354optObjectIdentifier:
355 { $$ = 0; }
356 | ObjectIdentifier { $$ = $1; }
357 ;
358
359ObjectIdentifier:
360 '{' ObjectIdentifierBody '}' {
361 $$ = $2;
362 }
363 | '{' '}' {
364 $$ = 0;
365 }
366 ;
367
368ObjectIdentifierBody:
369 ObjectIdentifierElement {
370 $$ = asn1p_oid_new();
371 asn1p_oid_add_arc($$, &$1);
372 if($1.name)
373 free($1.name);
374 }
375 | ObjectIdentifierBody ObjectIdentifierElement {
376 $$ = $1;
377 asn1p_oid_add_arc($$, &$2);
378 if($2.name)
379 free($2.name);
380 }
381 ;
382
383ObjectIdentifierElement:
384 Identifier { /* iso */
385 $$.name = $1;
386 $$.number = -1;
387 }
388 | Identifier '(' TOK_number ')' { /* iso(1) */
389 $$.name = $1;
390 $$.number = $3;
391 }
392 | TOK_number { /* 1 */
393 $$.name = 0;
394 $$.number = $1;
395 }
396 ;
397
398/*
399 * Optional module flags.
400 */
401optModuleSpecificationFlags:
402 { $$ = MSF_NOFLAGS; }
403 | ModuleSpecificationFlags {
404 $$ = $1;
405 }
406 ;
407
408/*
409 * Module flags.
410 */
411ModuleSpecificationFlags:
412 ModuleSpecificationFlag {
413 $$ = $1;
414 }
415 | ModuleSpecificationFlags ModuleSpecificationFlag {
416 $$ = $1 | $2;
417 }
418 ;
419
420/*
421 * Single module flag.
422 */
423ModuleSpecificationFlag:
424 TOK_EXPLICIT TOK_TAGS {
425 $$ = MSF_EXPLICIT_TAGS;
426 }
427 | TOK_IMPLICIT TOK_TAGS {
428 $$ = MSF_IMPLICIT_TAGS;
429 }
430 | TOK_AUTOMATIC TOK_TAGS {
431 $$ = MSF_AUTOMATIC_TAGS;
432 }
433 | TOK_EXTENSIBILITY TOK_IMPLIED {
434 $$ = MSF_EXTENSIBILITY_IMPLIED;
435 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000436 /* EncodingReferenceDefault */
437 | TOK_capitalreference TOK_INSTRUCTIONS {
438 /* X.680Amd1 specifies TAG and XER */
439 if(strcmp($1, "TAG") == 0) {
440 $$ = MSF_TAG_INSTRUCTIONS;
441 } else if(strcmp($1, "XER") == 0) {
442 $$ = MSF_XER_INSTRUCTIONS;
443 } else {
444 fprintf(stderr,
445 "WARNING: %s INSTRUCTIONS at line %d: "
446 "Unrecognized encoding reference\n",
447 $1, yylineno);
448 $$ = MSF_unk_INSTRUCTIONS;
449 }
450 free($1);
451 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000452 ;
453
454/*
455 * Optional module body.
456 */
457optModuleSpecificationBody:
458 { $$ = 0; }
459 | ModuleSpecificationBody {
Lev Walkinf15320b2004-06-03 03:38:44 +0000460 $$ = $1;
461 }
462 ;
463
464/*
465 * ASN.1 Module body.
466 */
467ModuleSpecificationBody:
468 ModuleSpecificationElement {
469 $$ = $1;
470 }
471 | ModuleSpecificationBody ModuleSpecificationElement {
472 $$ = $1;
473
Lev Walkinf59d0752004-08-18 04:59:12 +0000474 /* Behave well when one of them is skipped. */
475 if(!($1)) {
476 if($2) $$ = $2;
477 break;
478 }
479
Lev Walkinf15320b2004-06-03 03:38:44 +0000480#ifdef MY_IMPORT
481#error MY_IMPORT DEFINED ELSEWHERE!
482#endif
483#define MY_IMPORT(foo,field) do { \
Lev Walkinbc55d232004-08-13 12:31:09 +0000484 while(TQ_FIRST(&($2->foo))) { \
Lev Walkinf15320b2004-06-03 03:38:44 +0000485 TQ_ADD(&($$->foo), \
486 TQ_REMOVE(&($2->foo), field), \
487 field); \
Lev Walkinbc55d232004-08-13 12:31:09 +0000488 } \
489 assert(TQ_FIRST(&($2->foo)) == 0); \
490 } while(0)
Lev Walkinf15320b2004-06-03 03:38:44 +0000491
492 MY_IMPORT(imports, xp_next);
493 MY_IMPORT(exports, xp_next);
494 MY_IMPORT(members, next);
495#undef MY_IMPORT
496
497 }
498 ;
499
500/*
501 * One of the elements of ASN.1 module specification.
502 */
503ModuleSpecificationElement:
504 ImportsDefinition {
505 $$ = $1;
506 }
507 | ExportsDefinition {
508 $$ = asn1p_module_new();
509 checkmem($$);
510 if($1) {
511 TQ_ADD(&($$->exports), $1, xp_next);
512 } else {
513 /* "EXPORTS ALL;" ? */
514 }
515 }
516 | DataTypeReference {
517 $$ = asn1p_module_new();
518 checkmem($$);
519 assert($1->expr_type != A1TC_INVALID);
520 assert($1->meta_type != AMT_INVALID);
521 TQ_ADD(&($$->members), $1, next);
522 }
523 | ValueDefinition {
524 $$ = asn1p_module_new();
525 checkmem($$);
526 assert($1->expr_type != A1TC_INVALID);
527 assert($1->meta_type != AMT_INVALID);
528 TQ_ADD(&($$->members), $1, next);
529 }
530 /*
531 * Value set definition
532 * === EXAMPLE ===
533 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
534 * === EOF ===
535 */
536 | ValueSetDefinition {
537 $$ = asn1p_module_new();
538 checkmem($$);
539 assert($1->expr_type != A1TC_INVALID);
540 assert($1->meta_type != AMT_INVALID);
541 TQ_ADD(&($$->members), $1, next);
542 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000543 | TOK_ENCODING_CONTROL TOK_capitalreference
544 { asn1p_lexer_hack_push_encoding_control(); }
545 {
546 fprintf(stderr,
547 "WARNING: ENCODING-CONTROL %s "
548 "specification at line %d ignored\n",
549 $2, yylineno);
550 free($2);
551 $$ = 0;
552 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000553
554 /*
555 * Erroneous attemps
556 */
557 | BasicString {
558 return yyerror(
559 "Attempt to redefine a standard basic type, "
560 "use -ftypesXY to switch back "
561 "to older version of ASN.1 standard");
562 }
563 ;
564
565/*
566 * === EXAMPLE ===
567 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
568 * === EOF ===
569 */
570ImportsDefinition:
571 TOK_IMPORTS ImportsBundleSet ';' {
572 $$ = $2;
573 }
574 /*
575 * Some error cases.
576 */
577 | TOK_IMPORTS TOK_FROM /* ... */ {
578 return yyerror("Empty IMPORTS list");
579 }
580 ;
581
582ImportsBundleSet:
583 ImportsBundle {
584 $$ = asn1p_module_new();
585 checkmem($$);
586 TQ_ADD(&($$->imports), $1, xp_next);
587 }
588 | ImportsBundleSet ImportsBundle {
589 $$ = $1;
590 TQ_ADD(&($$->imports), $2, xp_next);
591 }
592 ;
593
594ImportsBundle:
595 ImportsList TOK_FROM TypeRefName optObjectIdentifier {
596 $$ = $1;
597 $$->from = $3;
598 $$->from_oid = $4;
599 checkmem($$);
600 }
601 ;
602
603ImportsList:
604 ImportsElement {
605 $$ = asn1p_xports_new();
606 checkmem($$);
607 TQ_ADD(&($$->members), $1, next);
608 }
609 | ImportsList ',' ImportsElement {
610 $$ = $1;
611 TQ_ADD(&($$->members), $3, next);
612 }
613 ;
614
615ImportsElement:
616 TypeRefName {
617 $$ = asn1p_expr_new(yylineno);
618 checkmem($$);
619 $$->Identifier = $1;
620 $$->expr_type = A1TC_REFERENCE;
621 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000622 | TypeRefName '{' '}' { /* Completely equivalent to above */
623 $$ = asn1p_expr_new(yylineno);
624 checkmem($$);
625 $$->Identifier = $1;
626 $$->expr_type = A1TC_REFERENCE;
627 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000628 | Identifier {
629 $$ = asn1p_expr_new(yylineno);
630 checkmem($$);
631 $$->Identifier = $1;
632 $$->expr_type = A1TC_REFERENCE;
633 }
634 ;
635
636ExportsDefinition:
637 TOK_EXPORTS ExportsBody ';' {
638 $$ = $2;
639 }
640 | TOK_EXPORTS TOK_ALL ';' {
641 $$ = 0;
642 }
643 | TOK_EXPORTS ';' {
644 /* Empty EXPORTS clause effectively prohibits export. */
645 $$ = asn1p_xports_new();
646 checkmem($$);
647 }
648 ;
649
650ExportsBody:
651 ExportsElement {
652 $$ = asn1p_xports_new();
653 assert($$);
654 TQ_ADD(&($$->members), $1, next);
655 }
656 | ExportsBody ',' ExportsElement {
657 $$ = $1;
658 TQ_ADD(&($$->members), $3, next);
659 }
660 ;
661
662ExportsElement:
663 TypeRefName {
664 $$ = asn1p_expr_new(yylineno);
665 checkmem($$);
666 $$->Identifier = $1;
667 $$->expr_type = A1TC_EXPORTVAR;
668 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000669 | TypeRefName '{' '}' {
670 $$ = asn1p_expr_new(yylineno);
671 checkmem($$);
672 $$->Identifier = $1;
673 $$->expr_type = A1TC_EXPORTVAR;
674 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000675 | Identifier {
676 $$ = asn1p_expr_new(yylineno);
677 checkmem($$);
678 $$->Identifier = $1;
679 $$->expr_type = A1TC_EXPORTVAR;
680 }
681 ;
682
683
684ValueSetDefinition:
685 TypeRefName DefinedTypeRef TOK_PPEQ '{' optValueSetBody '}' {
686 $$ = $2;
687 assert($$->Identifier == 0);
688 $$->Identifier = $1;
689 $$->meta_type = AMT_VALUESET;
690 // take care of optValueSetBody
691 }
692 ;
693
694DefinedTypeRef:
695 ComplexTypeReference {
696 $$ = asn1p_expr_new(yylineno);
697 checkmem($$);
698 $$->reference = $1;
699 $$->expr_type = A1TC_REFERENCE;
700 $$->meta_type = AMT_TYPEREF;
701 }
702 | BasicTypeId {
703 $$ = asn1p_expr_new(yylineno);
704 checkmem($$);
705 $$->expr_type = $1;
706 $$->meta_type = AMT_TYPE;
707 }
708 ;
709
710optValueSetBody:
711 { }
Lev Walkinceb20e72004-09-05 10:40:41 +0000712 | ValueSetBody {
713 }
714 ;
715
716/*
717 * X.680 does not permit ElementSetSpecs starting with ellipsis,
718 * i.e. (..., A, B). This is very strange: the ElementSetSpecs is used
719 * inside ValueSet, and ValueSets "in the wild" tend to have the first
720 * ellipsis.
721 */
722ValueSetBody:
723 ValueSetElement {
724 }
725 | ValueSetBody ',' ValueSetElement {
726 }
727 ;
728
729ValueSetElement:
730 TOK_ThreeDots {
731 }
732 | ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +0000733 }
734 ;
735
736
737/*
738 * Data Type Reference.
739 * === EXAMPLE ===
740 * Type3 ::= CHOICE { a Type1, b Type 2 }
741 * === EOF ===
742 */
743
744DataTypeReference:
745 /*
746 * Optionally tagged type definition.
747 */
748 TypeRefName TOK_PPEQ optTag TOK_TYPE_IDENTIFIER {
749 $$ = asn1p_expr_new(yylineno);
750 checkmem($$);
751 $$->Identifier = $1;
752 $$->tag = $3;
753 $$->expr_type = A1TC_TYPEID;
754 $$->meta_type = AMT_TYPE;
755 }
Lev Walkinaf120f72004-09-14 02:36:39 +0000756 | TypeRefName TOK_PPEQ Type {
757 $$ = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000758 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000759 assert($$->expr_type);
760 assert($$->meta_type);
761 }
762 | TypeRefName TOK_PPEQ ClassDeclaration {
763 $$ = $3;
764 $$->Identifier = $1;
765 assert($$->expr_type == A1TC_CLASSDEF);
766 assert($$->meta_type == AMT_OBJECT);
767 }
768 /*
769 * Parametrized <Type> declaration:
770 * === EXAMPLE ===
771 * SIGNED { ToBeSigned } ::= SEQUENCE {
772 * toBeSigned ToBeSigned,
773 * algorithm AlgorithmIdentifier,
774 * signature BIT STRING
775 * }
776 * === EOF ===
777 */
Lev Walkin070a52d2004-08-22 03:19:54 +0000778 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000779 $$ = $6;
780 assert($$->Identifier == 0);
781 $$->Identifier = $1;
782 $$->params = $3;
783 $$->meta_type = AMT_PARAMTYPE;
784 }
785 ;
786
787ParameterArgumentList:
788 ParameterArgumentName {
789 int ret;
790 $$ = asn1p_paramlist_new(yylineno);
791 checkmem($$);
792 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
793 checkmem(ret == 0);
794 if($1.governor) asn1p_ref_free($1.governor);
795 if($1.argument) free($1.argument);
796 }
797 | ParameterArgumentList ',' ParameterArgumentName {
798 int ret;
799 $$ = $1;
800 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
801 checkmem(ret == 0);
802 if($3.governor) asn1p_ref_free($3.governor);
803 if($3.argument) free($3.argument);
804 }
805 ;
806
807ParameterArgumentName:
808 TypeRefName {
809 $$.governor = NULL;
810 $$.argument = $1;
811 }
812 | TypeRefName ':' Identifier {
813 int ret;
814 $$.governor = asn1p_ref_new(yylineno);
815 ret = asn1p_ref_add_component($$.governor, $1, 0);
816 checkmem(ret == 0);
817 $$.argument = $3;
818 }
Lev Walkinc8092cb2005-02-18 16:34:21 +0000819 | TypeRefName ':' TypeRefName {
820 int ret;
821 $$.governor = asn1p_ref_new(yylineno);
822 ret = asn1p_ref_add_component($$.governor, $1, 0);
823 checkmem(ret == 0);
824 $$.argument = $3;
825 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000826 | BasicTypeId ':' Identifier {
827 int ret;
828 $$.governor = asn1p_ref_new(yylineno);
829 ret = asn1p_ref_add_component($$.governor,
830 ASN_EXPR_TYPE2STR($1), 1);
831 checkmem(ret == 0);
832 $$.argument = $3;
833 }
834 ;
835
836ActualParameterList:
837 ActualParameter {
838 $$ = asn1p_expr_new(yylineno);
839 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000840 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000841 }
842 | ActualParameterList ',' ActualParameter {
843 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000844 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000845 }
846 ;
847
848ActualParameter:
Lev Walkin070a52d2004-08-22 03:19:54 +0000849 Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000850 $$ = $1;
851 }
852 | Identifier {
853 $$ = asn1p_expr_new(yylineno);
854 checkmem($$);
855 $$->Identifier = $1;
856 $$->expr_type = A1TC_REFERENCE;
857 $$->meta_type = AMT_VALUE;
858 }
859 ;
860
861/*
Lev Walkinc8092cb2005-02-18 16:34:21 +0000862 | '{' ActualParameter '}' {
863 $$ = asn1p_expr_new(yylineno);
864 checkmem($$);
865 asn1p_expr_add($$, $2);
866 $$->expr_type = A1TC_PARAMETRIZED;
867 $$->meta_type = AMT_TYPE;
868 }
869 ;
870*/
871
872/*
Lev Walkinf15320b2004-06-03 03:38:44 +0000873 * A collection of constructed data type members.
874 */
Lev Walkin144db9b2004-10-12 23:26:53 +0000875optComponentTypeLists:
876 { $$ = asn1p_expr_new(yylineno); }
877 | ComponentTypeLists { $$ = $1; };
878
Lev Walkin070a52d2004-08-22 03:19:54 +0000879ComponentTypeLists:
880 ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +0000881 $$ = asn1p_expr_new(yylineno);
882 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000883 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000884 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000885 | ComponentTypeLists ',' ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +0000886 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000887 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000888 }
889 ;
890
Lev Walkin070a52d2004-08-22 03:19:54 +0000891ComponentType:
Lev Walkinaf120f72004-09-14 02:36:39 +0000892 Identifier Type optMarker {
Lev Walkin070a52d2004-08-22 03:19:54 +0000893 $$ = $2;
894 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +0000895 $$->Identifier = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +0000896 $$->marker = $3;
897 }
898 | TOK_COMPONENTS TOK_OF Type {
899 $$ = asn1p_expr_new(yylineno);
900 checkmem($$);
901 $$->meta_type = $3->meta_type;
902 $$->expr_type = A1TC_COMPONENTS_OF;
Lev Walkin1004aa92004-09-08 00:28:11 +0000903 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +0000904 }
905 | ExtensionAndException {
906 $$ = $1;
907 }
908 ;
909
910AlternativeTypeLists:
911 AlternativeType {
912 $$ = asn1p_expr_new(yylineno);
913 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000914 asn1p_expr_add($$, $1);
Lev Walkin070a52d2004-08-22 03:19:54 +0000915 }
916 | AlternativeTypeLists ',' AlternativeType {
917 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000918 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +0000919 }
920 ;
921
922AlternativeType:
Lev Walkinaf120f72004-09-14 02:36:39 +0000923 Identifier Type {
Lev Walkin070a52d2004-08-22 03:19:54 +0000924 $$ = $2;
925 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +0000926 $$->Identifier = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +0000927 }
928 | ExtensionAndException {
929 $$ = $1;
930 }
931 ;
932
Lev Walkinf15320b2004-06-03 03:38:44 +0000933ClassDeclaration:
934 TOK_CLASS '{' ClassFieldList '}' optWithSyntax {
935 $$ = $3;
936 checkmem($$);
937 $$->with_syntax = $5;
938 assert($$->expr_type == A1TC_CLASSDEF);
939 assert($$->meta_type == AMT_OBJECT);
940 }
941 ;
942
943optUnique:
944 { $$ = 0; }
945 | TOK_UNIQUE { $$ = 1; }
946 ;
947
948ClassFieldList:
949 ClassField {
950 $$ = asn1p_expr_new(yylineno);
951 checkmem($$);
952 $$->expr_type = A1TC_CLASSDEF;
953 $$->meta_type = AMT_OBJECT;
Lev Walkin1004aa92004-09-08 00:28:11 +0000954 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000955 }
956 | ClassFieldList ',' ClassField {
957 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000958 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000959 }
960 ;
961
962ClassField:
963 ClassFieldIdentifier optMarker {
964 $$ = asn1p_expr_new(yylineno);
965 checkmem($$);
966 $$->Identifier = $1.name;
967 $$->expr_type = A1TC_CLASSFIELD;
968 $$->meta_type = AMT_OBJECTFIELD;
969 $$->marker = $2;
970 }
Lev Walkinb7c45ca2004-11-24 17:43:29 +0000971 | ClassFieldIdentifier Type optUnique optMarker {
Lev Walkinf15320b2004-06-03 03:38:44 +0000972 $$ = $2;
973 $$->Identifier = $1.name;
Lev Walkinb7c45ca2004-11-24 17:43:29 +0000974 $$->marker = $4;
975 $$->unique = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000976 }
Lev Walkinb7c45ca2004-11-24 17:43:29 +0000977 | ClassFieldIdentifier ClassFieldIdentifier optUnique optMarker {
Lev Walkinf15320b2004-06-03 03:38:44 +0000978 int ret;
979 $$ = asn1p_expr_new(yylineno);
980 checkmem($$);
981 $$->Identifier = $1.name;
982 $$->reference = asn1p_ref_new(yylineno);
983 checkmem($$->reference);
984 ret = asn1p_ref_add_component($$->reference,
985 $2.name, $2.lex_type);
986 checkmem(ret == 0);
987 $$->expr_type = A1TC_CLASSFIELD;
988 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkinb7c45ca2004-11-24 17:43:29 +0000989 $$->marker = $4;
990 $$->unique = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000991 }
992 ;
993
994optWithSyntax:
995 { $$ = 0; }
996 | WithSyntax {
997 $$ = $1;
998 }
999 ;
1000
1001WithSyntax:
1002 TOK_WITH TOK_SYNTAX '{'
1003 { asn1p_lexer_hack_enable_with_syntax(); }
1004 WithSyntaxFormat
1005 '}' {
1006 $$ = $5;
1007 }
1008 ;
1009
1010WithSyntaxFormat:
1011 WithSyntaxFormatToken {
1012 $$ = asn1p_wsyntx_new();
1013 TQ_ADD(&($$->chunks), $1, next);
1014 }
1015 | WithSyntaxFormat WithSyntaxFormatToken {
1016 $$ = $1;
1017 TQ_ADD(&($$->chunks), $2, next);
1018 }
1019 ;
1020
1021WithSyntaxFormatToken:
1022 TOK_opaque {
1023 $$ = asn1p_wsyntx_chunk_frombuf($1.buf, $1.len, 0);
1024 }
1025 | ClassFieldIdentifier {
1026 asn1p_ref_t *ref;
1027 int ret;
1028 ref = asn1p_ref_new(yylineno);
1029 checkmem(ref);
1030 ret = asn1p_ref_add_component(ref, $1.name, $1.lex_type);
1031 checkmem(ret == 0);
1032 $$ = asn1p_wsyntx_chunk_fromref(ref, 0);
1033 }
1034 ;
1035
Lev Walkinf15320b2004-06-03 03:38:44 +00001036ExtensionAndException:
1037 TOK_ThreeDots {
Lev Walkinceb20e72004-09-05 10:40:41 +00001038 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001039 checkmem($$);
1040 $$->Identifier = strdup("...");
1041 checkmem($$->Identifier);
1042 $$->expr_type = A1TC_EXTENSIBLE;
1043 $$->meta_type = AMT_TYPE;
1044 }
1045 | TOK_ThreeDots '!' DefinedValue {
Lev Walkinceb20e72004-09-05 10:40:41 +00001046 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001047 checkmem($$);
1048 $$->Identifier = strdup("...");
1049 checkmem($$->Identifier);
1050 $$->value = $3;
1051 $$->expr_type = A1TC_EXTENSIBLE;
1052 $$->meta_type = AMT_TYPE;
1053 }
1054 | TOK_ThreeDots '!' SignedNumber {
Lev Walkinceb20e72004-09-05 10:40:41 +00001055 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001056 checkmem($$);
1057 $$->Identifier = strdup("...");
1058 $$->value = $3;
1059 checkmem($$->Identifier);
1060 $$->expr_type = A1TC_EXTENSIBLE;
1061 $$->meta_type = AMT_TYPE;
1062 }
1063 ;
1064
Lev Walkin070a52d2004-08-22 03:19:54 +00001065Type:
Lev Walkinaf120f72004-09-14 02:36:39 +00001066 optTag TypeDeclaration optConstraints {
1067 $$ = $2;
1068 $$->tag = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001069 /*
1070 * Outer constraint for SEQUENCE OF and SET OF applies
1071 * to the inner type.
1072 */
1073 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1074 || $$->expr_type == ASN_CONSTR_SET_OF) {
1075 assert(!TQ_FIRST(&($$->members))->constraints);
Lev Walkinaf120f72004-09-14 02:36:39 +00001076 TQ_FIRST(&($$->members))->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001077 } else {
1078 if($$->constraints) {
1079 assert(!$2);
1080 } else {
Lev Walkinaf120f72004-09-14 02:36:39 +00001081 $$->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001082 }
1083 }
1084 }
1085 ;
1086
1087TypeDeclaration:
Lev Walkinf15320b2004-06-03 03:38:44 +00001088 BasicType {
1089 $$ = $1;
1090 }
1091 | BasicString {
1092 $$ = asn1p_expr_new(yylineno);
1093 checkmem($$);
1094 $$->expr_type = $1;
1095 $$->meta_type = AMT_TYPE;
1096 }
Lev Walkin070a52d2004-08-22 03:19:54 +00001097 | TOK_CHOICE '{' AlternativeTypeLists '}' {
1098 $$ = $3;
1099 assert($$->expr_type == A1TC_INVALID);
1100 $$->expr_type = ASN_CONSTR_CHOICE;
1101 $$->meta_type = AMT_TYPE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001102 }
Lev Walkin144db9b2004-10-12 23:26:53 +00001103 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001104 $$ = $3;
1105 assert($$->expr_type == A1TC_INVALID);
1106 $$->expr_type = ASN_CONSTR_SEQUENCE;
1107 $$->meta_type = AMT_TYPE;
1108 }
Lev Walkin144db9b2004-10-12 23:26:53 +00001109 | TOK_SET '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001110 $$ = $3;
1111 assert($$->expr_type == A1TC_INVALID);
1112 $$->expr_type = ASN_CONSTR_SET;
1113 $$->meta_type = AMT_TYPE;
1114 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001115 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkinceb20e72004-09-05 10:40:41 +00001116 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001117 checkmem($$);
1118 $$->constraints = $2;
1119 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1120 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001121 $6->Identifier = $4;
1122 $6->tag = $5;
1123 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001124 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001125 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkinceb20e72004-09-05 10:40:41 +00001126 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001127 checkmem($$);
1128 $$->constraints = $2;
1129 $$->expr_type = ASN_CONSTR_SET_OF;
1130 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001131 $6->Identifier = $4;
1132 $6->tag = $5;
1133 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001134 }
1135 | TOK_ANY {
Lev Walkinceb20e72004-09-05 10:40:41 +00001136 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001137 checkmem($$);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001138 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001139 $$->meta_type = AMT_TYPE;
1140 }
1141 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1142 int ret;
Lev Walkinceb20e72004-09-05 10:40:41 +00001143 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001144 checkmem($$);
1145 $$->reference = asn1p_ref_new(yylineno);
1146 ret = asn1p_ref_add_component($$->reference,
1147 $4, RLT_lowercase);
1148 checkmem(ret == 0);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001149 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001150 $$->meta_type = AMT_TYPE;
1151 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001152 /*
1153 * A parametrized assignment.
1154 */
1155 | TypeRefName '{' ActualParameterList '}' {
1156 int ret;
1157 $$ = $3;
1158 assert($$->expr_type == 0);
1159 assert($$->meta_type == 0);
1160 assert($$->reference == 0);
1161 $$->reference = asn1p_ref_new(yylineno);
1162 checkmem($$->reference);
1163 ret = asn1p_ref_add_component($$->reference, $1, RLT_UNKNOWN);
1164 checkmem(ret == 0);
1165 free($1);
1166 $$->expr_type = A1TC_PARAMETRIZED;
1167 $$->meta_type = AMT_TYPE;
1168 }
1169 /*
1170 * A DefinedType reference.
1171 * "CLASS1.&id.&id2"
1172 * or
1173 * "Module.Type"
1174 * or
1175 * "Module.identifier"
1176 * or
1177 * "Type"
1178 */
1179 | ComplexTypeReference {
1180 $$ = asn1p_expr_new(yylineno);
1181 checkmem($$);
1182 $$->reference = $1;
1183 $$->expr_type = A1TC_REFERENCE;
1184 $$->meta_type = AMT_TYPEREF;
1185 }
1186 | TOK_INSTANCE TOK_OF ComplexTypeReference {
1187 $$ = asn1p_expr_new(yylineno);
1188 checkmem($$);
1189 $$->reference = $3;
1190 $$->expr_type = A1TC_INSTANCE;
1191 $$->meta_type = AMT_TYPE;
1192 }
1193 ;
1194
1195/*
1196 * A type name consisting of several components.
1197 * === EXAMPLE ===
1198 * === EOF ===
1199 */
1200ComplexTypeReference:
1201 TOK_typereference {
1202 int ret;
1203 $$ = asn1p_ref_new(yylineno);
1204 checkmem($$);
1205 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1206 checkmem(ret == 0);
1207 free($1);
1208 }
1209 | TOK_typereference '.' TypeRefName {
1210 int ret;
1211 $$ = asn1p_ref_new(yylineno);
1212 checkmem($$);
1213 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1214 checkmem(ret == 0);
1215 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1216 checkmem(ret == 0);
1217 free($1);
1218 }
Lev Walkin9c974182004-09-15 11:59:51 +00001219 | ObjectClassReference '.' TypeRefName {
1220 int ret;
1221 $$ = asn1p_ref_new(yylineno);
1222 checkmem($$);
1223 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1224 checkmem(ret == 0);
1225 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1226 checkmem(ret == 0);
1227 free($1);
1228 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001229 | TOK_typereference '.' Identifier {
1230 int ret;
1231 $$ = asn1p_ref_new(yylineno);
1232 checkmem($$);
1233 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1234 checkmem(ret == 0);
1235 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1236 checkmem(ret == 0);
1237 free($1);
1238 }
1239 | ObjectClassReference {
1240 int ret;
1241 $$ = asn1p_ref_new(yylineno);
1242 checkmem($$);
1243 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1244 free($1);
1245 checkmem(ret == 0);
1246 }
1247 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1248 int ret;
1249 $$ = $3;
1250 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1251 free($1);
1252 checkmem(ret == 0);
1253 /*
1254 * Move the last element infront.
1255 */
1256 {
1257 struct asn1p_ref_component_s tmp_comp;
1258 tmp_comp = $$->components[$$->comp_count-1];
1259 memmove(&$$->components[1],
1260 &$$->components[0],
1261 sizeof($$->components[0])
1262 * ($$->comp_count - 1));
1263 $$->components[0] = tmp_comp;
1264 }
1265 }
1266 ;
1267
1268ComplexTypeReferenceAmpList:
1269 ComplexTypeReferenceElement {
1270 int ret;
1271 $$ = asn1p_ref_new(yylineno);
1272 checkmem($$);
1273 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1274 free($1.name);
1275 checkmem(ret == 0);
1276 }
1277 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1278 int ret;
1279 $$ = $1;
1280 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1281 free($3.name);
1282 checkmem(ret == 0);
1283 }
1284 ;
1285
1286ComplexTypeReferenceElement: ClassFieldName;
1287ClassFieldIdentifier: ClassFieldName;
1288
1289ClassFieldName:
1290 /* "&Type1" */
1291 TOK_typefieldreference {
1292 $$.lex_type = RLT_AmpUppercase;
1293 $$.name = $1;
1294 }
1295 /* "&id" */
1296 | TOK_valuefieldreference {
1297 $$.lex_type = RLT_Amplowercase;
1298 $$.name = $1;
1299 }
1300 ;
1301
1302
1303/*
1304 * === EXAMPLE ===
1305 * value INTEGER ::= 1
1306 * === EOF ===
1307 */
1308ValueDefinition:
Lev Walkin9c974182004-09-15 11:59:51 +00001309 Identifier DefinedTypeRef TOK_PPEQ Value {
Lev Walkinf15320b2004-06-03 03:38:44 +00001310 $$ = $2;
1311 assert($$->Identifier == NULL);
1312 $$->Identifier = $1;
1313 $$->meta_type = AMT_VALUE;
1314 $$->value = $4;
1315 }
1316 ;
1317
Lev Walkin9c974182004-09-15 11:59:51 +00001318Value:
1319 Identifier ':' Value {
1320 $$ = asn1p_value_fromint(0);
1321 checkmem($$);
1322 $$->type = ATV_CHOICE_IDENTIFIER;
1323 $$->value.choice_identifier.identifier = $1;
1324 $$->value.choice_identifier.value = $3;
1325 }
1326 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Lev Walkinf15320b2004-06-03 03:38:44 +00001327 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1328 checkmem($$);
1329 $$->type = ATV_UNPARSED;
1330 }
Lev Walkin9c974182004-09-15 11:59:51 +00001331 | TOK_NULL {
1332 $$ = asn1p_value_fromint(0);
1333 checkmem($$);
1334 $$->type = ATV_NULL;
1335 }
1336 | TOK_FALSE {
1337 $$ = asn1p_value_fromint(0);
1338 checkmem($$);
1339 $$->type = ATV_FALSE;
1340 }
1341 | TOK_TRUE {
1342 $$ = asn1p_value_fromint(0);
1343 checkmem($$);
1344 $$->type = ATV_TRUE;
1345 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001346 | TOK_bstring {
1347 $$ = _convert_bitstring2binary($1, 'B');
1348 checkmem($$);
1349 }
1350 | TOK_hstring {
1351 $$ = _convert_bitstring2binary($1, 'H');
1352 checkmem($$);
1353 }
1354 | TOK_cstring {
1355 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1356 checkmem($$);
1357 }
1358 | SignedNumber {
1359 $$ = $1;
1360 }
1361 | DefinedValue {
1362 $$ = $1;
1363 }
1364 ;
1365
1366DefinedValue:
1367 Identifier {
1368 asn1p_ref_t *ref;
1369 int ret;
1370 ref = asn1p_ref_new(yylineno);
1371 checkmem(ref);
1372 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1373 checkmem(ret == 0);
1374 $$ = asn1p_value_fromref(ref, 0);
1375 checkmem($$);
1376 free($1);
1377 }
1378 | TypeRefName '.' Identifier {
1379 asn1p_ref_t *ref;
1380 int ret;
1381 ref = asn1p_ref_new(yylineno);
1382 checkmem(ref);
1383 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1384 checkmem(ret == 0);
1385 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1386 checkmem(ret == 0);
1387 $$ = asn1p_value_fromref(ref, 0);
1388 checkmem($$);
1389 free($1);
1390 free($3);
1391 }
1392 ;
1393
1394Opaque:
1395 TOK_opaque {
1396 $$.len = $1.len + 2;
1397 $$.buf = malloc($$.len + 1);
1398 checkmem($$.buf);
1399 $$.buf[0] = '{';
1400 $$.buf[1] = ' ';
1401 memcpy($$.buf + 2, $1.buf, $1.len);
1402 $$.buf[$$.len] = '\0';
1403 free($1.buf);
1404 }
1405 | Opaque TOK_opaque {
1406 int newsize = $1.len + $2.len;
1407 char *p = malloc(newsize + 1);
1408 checkmem(p);
1409 memcpy(p , $1.buf, $1.len);
1410 memcpy(p + $1.len, $2.buf, $2.len);
1411 p[newsize] = '\0';
1412 free($1.buf);
1413 free($2.buf);
1414 $$.buf = p;
1415 $$.len = newsize;
1416 }
1417 ;
1418
1419BasicTypeId:
1420 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1421 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1422 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1423 | BasicTypeId_UniverationCompatible { $$ = $1; }
1424 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1425 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1426 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1427 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1428 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1429 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1430 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1431 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
1432 ;
1433
1434/*
1435 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1436 */
1437BasicTypeId_UniverationCompatible:
1438 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1439 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1440 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1441 ;
1442
1443BasicType:
1444 BasicTypeId {
Lev Walkinceb20e72004-09-05 10:40:41 +00001445 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001446 checkmem($$);
1447 $$->expr_type = $1;
1448 $$->meta_type = AMT_TYPE;
1449 }
1450 | BasicTypeId_UniverationCompatible UniverationDefinition {
1451 if($2) {
1452 $$ = $2;
1453 } else {
Lev Walkinceb20e72004-09-05 10:40:41 +00001454 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001455 checkmem($$);
1456 }
1457 $$->expr_type = $1;
1458 $$->meta_type = AMT_TYPE;
1459 }
1460 ;
1461
1462BasicString:
1463 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1464 | TOK_GeneralString {
1465 $$ = ASN_STRING_GeneralString;
Lev Walkin9c974182004-09-15 11:59:51 +00001466 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001467 }
1468 | TOK_GraphicString {
1469 $$ = ASN_STRING_GraphicString;
Lev Walkin9c974182004-09-15 11:59:51 +00001470 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001471 }
1472 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1473 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1474 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1475 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1476 | TOK_T61String {
1477 $$ = ASN_STRING_T61String;
Lev Walkin9c974182004-09-15 11:59:51 +00001478 fprintf(stderr, "WARNING: T61String is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001479 }
1480 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1481 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1482 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1483 | TOK_VideotexString {
1484 $$ = ASN_STRING_VideotexString;
Lev Walkin9c974182004-09-15 11:59:51 +00001485 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001486 }
1487 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1488 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1489 ;
1490
Lev Walkind2ea1de2004-08-20 13:25:29 +00001491
Lev Walkinf15320b2004-06-03 03:38:44 +00001492/*
1493 * Data type constraints.
1494 */
Lev Walkinf15320b2004-06-03 03:38:44 +00001495Union: '|' | TOK_UNION;
1496Intersection: '^' | TOK_INTERSECTION;
1497Except: TOK_EXCEPT;
1498
Lev Walkinf59d0752004-08-18 04:59:12 +00001499optConstraints:
1500 { $$ = 0; }
Lev Walkind2ea1de2004-08-20 13:25:29 +00001501 | Constraints {
1502 $$ = $1;
1503 }
1504 ;
1505
1506Constraints:
1507 SetOfConstraints {
Lev Walkinf59d0752004-08-18 04:59:12 +00001508 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
1509 }
1510 | TOK_SIZE '(' ElementSetSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001511 /*
1512 * This is a special case, for compatibility purposes.
Lev Walkinf59d0752004-08-18 04:59:12 +00001513 * It goes without parentheses.
Lev Walkinf15320b2004-06-03 03:38:44 +00001514 */
Lev Walkind2ea1de2004-08-20 13:25:29 +00001515 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001516 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001517 ;
1518
Lev Walkinf59d0752004-08-18 04:59:12 +00001519SetOfConstraints:
1520 '(' ElementSetSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001521 $$ = $2;
1522 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001523 | SetOfConstraints '(' ElementSetSpecs ')' {
1524 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
1525 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001526 ;
1527
Lev Walkinf59d0752004-08-18 04:59:12 +00001528ElementSetSpecs:
1529 ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001530 $$ = $1;
1531 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001532 | ElementSetSpec ',' TOK_ThreeDots {
Lev Walkinf15320b2004-06-03 03:38:44 +00001533 asn1p_constraint_t *ct;
1534 ct = asn1p_constraint_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001535 ct->type = ACT_EL_EXT;
1536 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
1537 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001538 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001539 asn1p_constraint_t *ct;
1540 ct = asn1p_constraint_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001541 ct->type = ACT_EL_EXT;
1542 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinb4fcdd22004-08-13 12:35:09 +00001543 ct = $$;
1544 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
Lev Walkinf15320b2004-06-03 03:38:44 +00001545 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001546 ;
1547
Lev Walkinf59d0752004-08-18 04:59:12 +00001548ElementSetSpec:
1549 ConstraintSubtypeElement {
1550 $$ = $1;
1551 }
1552 | ElementSetSpec Union ConstraintSubtypeElement {
Lev Walkinf15320b2004-06-03 03:38:44 +00001553 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
1554 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001555 | ElementSetSpec Intersection ConstraintSubtypeElement {
Lev Walkinf15320b2004-06-03 03:38:44 +00001556 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
1557 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001558 | ConstraintSubtypeElement Except ConstraintSubtypeElement {
Lev Walkinf15320b2004-06-03 03:38:44 +00001559 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
1560 }
1561 ;
1562
1563ConstraintSubtypeElement:
Lev Walkinf59d0752004-08-18 04:59:12 +00001564 ConstraintSpec '(' ElementSetSpecs ')' {
1565 int ret;
1566 $$ = asn1p_constraint_new(yylineno);
1567 checkmem($$);
1568 $$->type = $1;
1569 ret = asn1p_constraint_insert($$, $3);
1570 checkmem(ret == 0);
1571 }
1572 | '(' ElementSetSpecs ')' {
1573 int ret;
1574 $$ = asn1p_constraint_new(yylineno);
1575 checkmem($$);
1576 $$->type = ACT_CA_SET;
1577 ret = asn1p_constraint_insert($$, $2);
1578 checkmem(ret == 0);
1579 }
1580 | ConstraintValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001581 $$ = asn1p_constraint_new(yylineno);
1582 checkmem($$);
1583 $$->type = ACT_EL_VALUE;
1584 $$->value = $1;
1585 }
1586 | ConstraintValue ConstraintRangeSpec ConstraintValue {
1587 $$ = asn1p_constraint_new(yylineno);
1588 checkmem($$);
1589 $$->type = $2;
1590 $$->range_start = $1;
1591 $$->range_stop = $3;
1592 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001593 | TOK_MIN ConstraintRangeSpec ConstraintValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001594 $$ = asn1p_constraint_new(yylineno);
1595 checkmem($$);
Lev Walkinf59d0752004-08-18 04:59:12 +00001596 $$->type = $2;
1597 $$->range_start = asn1p_value_fromint(-123);
1598 $$->range_stop = $3;
1599 $$->range_start->type = ATV_MIN;
1600 }
1601 | ConstraintValue ConstraintRangeSpec TOK_MAX {
1602 $$ = asn1p_constraint_new(yylineno);
1603 checkmem($$);
1604 $$->type = $2;
1605 $$->range_start = $1;
1606 $$->range_stop = asn1p_value_fromint(321);
1607 $$->range_stop->type = ATV_MAX;
1608 }
1609 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1610 $$ = asn1p_constraint_new(yylineno);
1611 checkmem($$);
1612 $$->type = $2;
1613 $$->range_start = asn1p_value_fromint(-123);
1614 $$->range_stop = asn1p_value_fromint(321);
1615 $$->range_start->type = ATV_MIN;
1616 $$->range_stop->type = ATV_MAX;
Lev Walkinf15320b2004-06-03 03:38:44 +00001617 }
1618 | TableConstraint {
1619 $$ = $1;
1620 }
1621 | WithComponents {
1622 $$ = $1;
1623 }
1624 ;
1625
1626ConstraintRangeSpec:
1627 TOK_TwoDots { $$ = ACT_EL_RANGE; }
1628 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
1629 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
1630 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
1631 ;
1632
1633ConstraintSpec:
1634 TOK_SIZE {
1635 $$ = ACT_CT_SIZE;
1636 }
1637 | TOK_FROM {
1638 $$ = ACT_CT_FROM;
1639 }
1640 ;
1641
1642ConstraintValue:
Lev Walkinc8092cb2005-02-18 16:34:21 +00001643 TOK_FALSE {
1644 $$ = asn1p_value_fromint(0);
1645 checkmem($$);
1646 $$->type = ATV_FALSE;
1647 }
1648 | TOK_TRUE {
1649 $$ = asn1p_value_fromint(1);
1650 checkmem($$);
1651 $$->type = ATV_TRUE;
1652 }
1653 | SignedNumber {
Lev Walkinf15320b2004-06-03 03:38:44 +00001654 $$ = $1;
1655 }
Lev Walkinc8092cb2005-02-18 16:34:21 +00001656 | TOK_cstring {
1657 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1658 checkmem($$);
1659 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001660 | Identifier {
1661 asn1p_ref_t *ref;
1662 int ret;
1663 ref = asn1p_ref_new(yylineno);
1664 checkmem(ref);
1665 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1666 checkmem(ret == 0);
1667 $$ = asn1p_value_fromref(ref, 0);
1668 checkmem($$);
1669 free($1);
1670 }
Lev Walkinc8092cb2005-02-18 16:34:21 +00001671 | TypeRefName {
1672 asn1p_ref_t *ref;
1673 int ret;
1674 ref = asn1p_ref_new(yylineno);
1675 checkmem(ref);
1676 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1677 checkmem(ret == 0);
1678 $$ = asn1p_value_fromref(ref, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001679 checkmem($$);
Lev Walkinc8092cb2005-02-18 16:34:21 +00001680 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001681 }
1682 ;
1683
1684WithComponents:
1685 TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
1686 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
1687 }
1688 ;
1689
1690WithComponentsList:
1691 WithComponentsElement {
1692 $$ = $1;
1693 }
1694 | WithComponentsList ',' WithComponentsElement {
1695 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
1696 }
1697 ;
1698
1699WithComponentsElement:
1700 TOK_ThreeDots {
1701 $$ = asn1p_constraint_new(yylineno);
1702 checkmem($$);
1703 $$->type = ACT_EL_EXT;
1704 }
1705 | Identifier optConstraints optPresenceConstraint {
1706 $$ = asn1p_constraint_new(yylineno);
1707 checkmem($$);
1708 $$->type = ACT_EL_VALUE;
1709 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1710 $$->presence = $3;
1711 }
1712 ;
1713
1714/*
1715 * presence constraint for WithComponents
1716 */
1717optPresenceConstraint:
1718 { $$ = ACPRES_DEFAULT; }
1719 | PresenceConstraint { $$ = $1; }
1720 ;
1721
1722PresenceConstraint:
1723 TOK_PRESENT {
1724 $$ = ACPRES_PRESENT;
1725 }
1726 | TOK_ABSENT {
1727 $$ = ACPRES_ABSENT;
1728 }
1729 | TOK_OPTIONAL {
1730 $$ = ACPRES_OPTIONAL;
1731 }
1732 ;
1733
1734TableConstraint:
1735 SimpleTableConstraint {
1736 $$ = $1;
1737 }
1738 | ComponentRelationConstraint {
1739 $$ = $1;
1740 }
1741 ;
1742
1743/*
1744 * "{ExtensionSet}"
1745 */
1746SimpleTableConstraint:
1747 '{' TypeRefName '}' {
1748 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
1749 asn1p_constraint_t *ct;
1750 int ret;
1751 ret = asn1p_ref_add_component(ref, $2, 0);
1752 checkmem(ret == 0);
1753 ct = asn1p_constraint_new(yylineno);
1754 checkmem($$);
1755 ct->type = ACT_EL_VALUE;
1756 ct->value = asn1p_value_fromref(ref, 0);
1757 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
1758 }
1759 ;
1760
1761ComponentRelationConstraint:
1762 SimpleTableConstraint '{' AtNotationList '}' {
1763 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
1764 }
1765 ;
1766
1767AtNotationList:
1768 AtNotationElement {
1769 $$ = asn1p_constraint_new(yylineno);
1770 checkmem($$);
1771 $$->type = ACT_EL_VALUE;
1772 $$->value = asn1p_value_fromref($1, 0);
1773 }
1774 | AtNotationList ',' AtNotationElement {
1775 asn1p_constraint_t *ct;
1776 ct = asn1p_constraint_new(yylineno);
1777 checkmem(ct);
1778 ct->type = ACT_EL_VALUE;
1779 ct->value = asn1p_value_fromref($3, 0);
1780 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
1781 }
1782 ;
1783
1784/*
1785 * @blah
1786 */
1787AtNotationElement:
1788 '@' ComponentIdList {
1789 char *p = malloc(strlen($2) + 2);
1790 int ret;
1791 *p = '@';
1792 strcpy(p + 1, $2);
1793 $$ = asn1p_ref_new(yylineno);
1794 ret = asn1p_ref_add_component($$, p, 0);
1795 checkmem(ret == 0);
1796 free(p);
1797 free($2);
1798 }
1799 | '@' '.' ComponentIdList {
1800 char *p = malloc(strlen($3) + 3);
1801 int ret;
1802 p[0] = '@';
1803 p[1] = '.';
1804 strcpy(p + 2, $3);
1805 $$ = asn1p_ref_new(yylineno);
1806 ret = asn1p_ref_add_component($$, p, 0);
1807 checkmem(ret == 0);
1808 free(p);
1809 free($3);
1810 }
1811 ;
1812
1813/* identifier "." ... */
1814ComponentIdList:
1815 Identifier {
1816 $$ = $1;
1817 }
1818 | ComponentIdList '.' Identifier {
1819 int l1 = strlen($1);
1820 int l3 = strlen($3);
1821 $$ = malloc(l1 + 1 + l3 + 1);
1822 memcpy($$, $1, l1);
1823 $$[l1] = '.';
1824 memcpy($$ + l1 + 1, $3, l3);
1825 $$[l1 + 1 + l3] = '\0';
1826 }
1827 ;
1828
1829
1830
1831/*
1832 * MARKERS
1833 */
1834
1835optMarker:
Lev Walkin9c974182004-09-15 11:59:51 +00001836 {
1837 $$.flags = EM_NOMARK;
1838 $$.default_value = 0;
1839 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001840 | Marker { $$ = $1; }
1841 ;
1842
1843Marker:
1844 TOK_OPTIONAL {
Lev Walkin9c974182004-09-15 11:59:51 +00001845 $$.flags = EM_OPTIONAL;
1846 $$.default_value = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +00001847 }
Lev Walkin9c974182004-09-15 11:59:51 +00001848 | TOK_DEFAULT Value {
1849 $$.flags = EM_DEFAULT;
1850 $$.default_value = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00001851 }
1852 ;
1853
1854/*
1855 * Universal enumeration definition to use in INTEGER and ENUMERATED.
1856 * === EXAMPLE ===
1857 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
1858 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
1859 * === EOF ===
1860 */
1861/*
1862optUniverationDefinition:
1863 { $$ = 0; }
1864 | UniverationDefinition {
1865 $$ = $1;
1866 }
1867 ;
1868*/
1869
1870UniverationDefinition:
1871 '{' '}' {
Lev Walkinceb20e72004-09-05 10:40:41 +00001872 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001873 checkmem($$);
1874 }
1875 | '{' UniverationList '}' {
1876 $$ = $2;
1877 }
1878 ;
1879
1880UniverationList:
1881 UniverationElement {
Lev Walkinceb20e72004-09-05 10:40:41 +00001882 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001883 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00001884 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001885 }
1886 | UniverationList ',' UniverationElement {
1887 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001888 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001889 }
1890 ;
1891
1892UniverationElement:
1893 Identifier {
Lev Walkinceb20e72004-09-05 10:40:41 +00001894 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001895 checkmem($$);
1896 $$->expr_type = A1TC_UNIVERVAL;
1897 $$->meta_type = AMT_VALUE;
1898 $$->Identifier = $1;
1899 }
1900 | Identifier '(' SignedNumber ')' {
Lev Walkinceb20e72004-09-05 10:40:41 +00001901 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001902 checkmem($$);
1903 $$->expr_type = A1TC_UNIVERVAL;
1904 $$->meta_type = AMT_VALUE;
1905 $$->Identifier = $1;
1906 $$->value = $3;
1907 }
1908 | Identifier '(' DefinedValue ')' {
Lev Walkinceb20e72004-09-05 10:40:41 +00001909 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001910 checkmem($$);
1911 $$->expr_type = A1TC_UNIVERVAL;
1912 $$->meta_type = AMT_VALUE;
1913 $$->Identifier = $1;
1914 $$->value = $3;
1915 }
1916 | SignedNumber {
Lev Walkinceb20e72004-09-05 10:40:41 +00001917 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001918 checkmem($$);
1919 $$->expr_type = A1TC_UNIVERVAL;
1920 $$->meta_type = AMT_VALUE;
1921 $$->value = $1;
1922 }
1923 | TOK_ThreeDots {
Lev Walkinceb20e72004-09-05 10:40:41 +00001924 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001925 checkmem($$);
1926 $$->Identifier = strdup("...");
1927 checkmem($$->Identifier);
1928 $$->expr_type = A1TC_EXTENSIBLE;
1929 $$->meta_type = AMT_VALUE;
1930 }
1931 ;
1932
1933SignedNumber:
1934 TOK_number {
1935 $$ = asn1p_value_fromint($1);
1936 checkmem($$);
1937 }
1938 | TOK_number_negative {
1939 $$ = asn1p_value_fromint($1);
1940 checkmem($$);
1941 }
1942 ;
1943
1944/*
1945 * SEQUENCE definition.
1946 * === EXAMPLE ===
1947 * Struct1 ::= SEQUENCE {
1948 * memb1 Struct2,
1949 * memb2 SEQUENCE OF {
1950 * memb2-1 Struct 3
1951 * }
1952 * }
1953 * === EOF ===
1954 */
1955
1956
1957
1958/*
1959 * SET definition.
1960 * === EXAMPLE ===
1961 * Person ::= SET {
1962 * name [0] PrintableString (SIZE(1..20)),
1963 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
1964 * }
1965 * === EOF ===
1966 */
1967
1968optTag:
1969 { memset(&$$, 0, sizeof($$)); }
1970 | Tag { $$ = $1; }
1971 ;
1972
1973Tag:
Lev Walkinc603f102005-01-23 09:51:44 +00001974 TagTypeValue TagPlicit {
Lev Walkinf15320b2004-06-03 03:38:44 +00001975 $$ = $1;
Lev Walkinc603f102005-01-23 09:51:44 +00001976 $$.tag_mode = $2.tag_mode;
Lev Walkinf15320b2004-06-03 03:38:44 +00001977 }
Lev Walkinc603f102005-01-23 09:51:44 +00001978 ;
1979
1980TagTypeValue:
1981 '[' TagClass TOK_number ']' {
1982 $$ = $2;
1983 $$.tag_value = $3;
1984 };
1985
1986TagClass:
1987 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
1988 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
1989 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
1990 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
1991 ;
1992
1993TagPlicit:
1994 { $$.tag_mode = TM_DEFAULT; }
1995 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
1996 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
Lev Walkinf15320b2004-06-03 03:38:44 +00001997 ;
1998
1999TypeRefName:
2000 TOK_typereference {
2001 checkmem($1);
2002 $$ = $1;
2003 }
Lev Walkinf59d0752004-08-18 04:59:12 +00002004 | TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002005 checkmem($1);
2006 $$ = $1;
2007 }
2008 ;
2009
Lev Walkinf59d0752004-08-18 04:59:12 +00002010
Lev Walkinf15320b2004-06-03 03:38:44 +00002011ObjectClassReference:
Lev Walkinf59d0752004-08-18 04:59:12 +00002012 TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002013 checkmem($1);
2014 $$ = $1;
2015 }
2016 ;
2017
Lev Walkin83cac2f2004-09-22 16:03:36 +00002018optIdentifier:
2019 { $$ = 0; }
2020 | Identifier {
2021 $$ = $1;
2022 }
2023
Lev Walkinf15320b2004-06-03 03:38:44 +00002024Identifier:
2025 TOK_identifier {
2026 checkmem($1);
2027 $$ = $1;
2028 }
2029 ;
2030
Lev Walkinf15320b2004-06-03 03:38:44 +00002031%%
2032
2033
2034/*
2035 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2036 */
2037static asn1p_value_t *
2038_convert_bitstring2binary(char *str, int base) {
2039 asn1p_value_t *val;
2040 int slen;
2041 int memlen;
2042 int baselen;
2043 int bits;
2044 uint8_t *binary_vector;
2045 uint8_t *bv_ptr;
2046 uint8_t cur_val;
2047
2048 assert(str);
2049 assert(str[0] == '\'');
2050
2051 switch(base) {
2052 case 'B':
2053 baselen = 1;
2054 break;
2055 case 'H':
2056 baselen = 4;
2057 break;
2058 default:
2059 assert(base == 'B' || base == 'H');
2060 errno = EINVAL;
2061 return NULL;
2062 }
2063
2064 slen = strlen(str);
2065 assert(str[slen - 1] == base);
2066 assert(str[slen - 2] == '\'');
2067
2068 memlen = slen / (8 / baselen); /* Conservative estimate */
2069
2070 bv_ptr = binary_vector = malloc(memlen + 1);
2071 if(bv_ptr == NULL)
2072 /* ENOMEM */
2073 return NULL;
2074
2075 cur_val = 0;
2076 bits = 0;
2077 while(*(++str) != '\'') {
2078 switch(baselen) {
2079 case 1:
2080 switch(*str) {
2081 case '1':
2082 cur_val |= 1 << (7 - (bits % 8));
2083 case '0':
2084 break;
2085 default:
2086 assert(!"_y UNREACH1");
2087 case ' ': case '\r': case '\n':
2088 continue;
2089 }
2090 break;
2091 case 4:
2092 switch(*str) {
2093 case '0': case '1': case '2': case '3': case '4':
2094 case '5': case '6': case '7': case '8': case '9':
2095 cur_val |= (*str - '0') << (4 - (bits % 8));
2096 break;
2097 case 'A': case 'B': case 'C':
2098 case 'D': case 'E': case 'F':
2099 cur_val |= ((*str - 'A') + 10)
2100 << (4 - (bits % 8));
2101 break;
2102 default:
2103 assert(!"_y UNREACH2");
2104 case ' ': case '\r': case '\n':
2105 continue;
2106 }
2107 break;
2108 }
2109
2110 bits += baselen;
2111 if((bits % 8) == 0) {
2112 *bv_ptr++ = cur_val;
2113 cur_val = 0;
2114 }
2115 }
2116
2117 *bv_ptr = cur_val;
2118 assert((bv_ptr - binary_vector) <= memlen);
2119
2120 val = asn1p_value_frombits(binary_vector, bits, 0);
2121 if(val == NULL) {
2122 free(binary_vector);
2123 }
2124
2125 return val;
2126}
2127
2128extern char *asn1p_text;
2129
2130int
2131yyerror(const char *msg) {
2132 fprintf(stderr,
2133 "ASN.1 grammar parse error "
2134 "near line %d (token \"%s\"): %s\n",
Lev Walkinceb20e72004-09-05 10:40:41 +00002135 yylineno, asn1p_text, msg);
Lev Walkinf15320b2004-06-03 03:38:44 +00002136 return -1;
2137}
2138
2139