blob: da06b4cf39032c7ad279e4cfac903f0b928fe819 [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
Lev Walkind9574ae2005-03-24 16:22:35 +0000101%token <a_int> TOK_tuple
102%token <a_int> TOK_quadruple
Lev Walkinf15320b2004-06-03 03:38:44 +0000103%token <a_int> TOK_number_negative
104%token <tv_str> TOK_typereference
Lev Walkinf59d0752004-08-18 04:59:12 +0000105%token <tv_str> TOK_capitalreference /* "CLASS1" */
Lev Walkinf15320b2004-06-03 03:38:44 +0000106%token <tv_str> TOK_typefieldreference /* "&Pork" */
107%token <tv_str> TOK_valuefieldreference /* "&id" */
108
109/*
110 * Token types representing ASN.1 standard keywords.
111 */
112%token TOK_ABSENT
113%token TOK_ABSTRACT_SYNTAX
114%token TOK_ALL
115%token TOK_ANY
116%token TOK_APPLICATION
117%token TOK_AUTOMATIC
118%token TOK_BEGIN
119%token TOK_BIT
120%token TOK_BMPString
121%token TOK_BOOLEAN
122%token TOK_BY
123%token TOK_CHARACTER
124%token TOK_CHOICE
125%token TOK_CLASS
126%token TOK_COMPONENT
127%token TOK_COMPONENTS
128%token TOK_CONSTRAINED
129%token TOK_CONTAINING
130%token TOK_DEFAULT
131%token TOK_DEFINITIONS
132%token TOK_DEFINED
133%token TOK_EMBEDDED
134%token TOK_ENCODED
Lev Walkinf59d0752004-08-18 04:59:12 +0000135%token TOK_ENCODING_CONTROL
Lev Walkinf15320b2004-06-03 03:38:44 +0000136%token TOK_END
137%token TOK_ENUMERATED
138%token TOK_EXPLICIT
139%token TOK_EXPORTS
140%token TOK_EXTENSIBILITY
141%token TOK_EXTERNAL
142%token TOK_FALSE
143%token TOK_FROM
144%token TOK_GeneralizedTime
145%token TOK_GeneralString
146%token TOK_GraphicString
147%token TOK_IA5String
148%token TOK_IDENTIFIER
149%token TOK_IMPLICIT
150%token TOK_IMPLIED
151%token TOK_IMPORTS
152%token TOK_INCLUDES
153%token TOK_INSTANCE
Lev Walkinf59d0752004-08-18 04:59:12 +0000154%token TOK_INSTRUCTIONS
Lev Walkinf15320b2004-06-03 03:38:44 +0000155%token TOK_INTEGER
156%token TOK_ISO646String
157%token TOK_MAX
158%token TOK_MIN
159%token TOK_MINUS_INFINITY
160%token TOK_NULL
161%token TOK_NumericString
162%token TOK_OBJECT
163%token TOK_ObjectDescriptor
164%token TOK_OCTET
165%token TOK_OF
166%token TOK_OPTIONAL
167%token TOK_PATTERN
168%token TOK_PDV
169%token TOK_PLUS_INFINITY
170%token TOK_PRESENT
171%token TOK_PrintableString
172%token TOK_PRIVATE
173%token TOK_REAL
174%token TOK_RELATIVE_OID
175%token TOK_SEQUENCE
176%token TOK_SET
177%token TOK_SIZE
178%token TOK_STRING
179%token TOK_SYNTAX
180%token TOK_T61String
181%token TOK_TAGS
182%token TOK_TeletexString
183%token TOK_TRUE
184%token TOK_TYPE_IDENTIFIER
185%token TOK_UNIQUE
186%token TOK_UNIVERSAL
187%token TOK_UniversalString
188%token TOK_UTCTime
189%token TOK_UTF8String
190%token TOK_VideotexString
191%token TOK_VisibleString
192%token TOK_WITH
193
Lev Walkinf15320b2004-06-03 03:38:44 +0000194%left TOK_EXCEPT
Lev Walkinf59d0752004-08-18 04:59:12 +0000195%left '^' TOK_INTERSECTION
196%left '|' TOK_UNION
Lev Walkinf15320b2004-06-03 03:38:44 +0000197
198/* Misc tags */
199%token TOK_TwoDots /* .. */
200%token TOK_ThreeDots /* ... */
Lev Walkinf15320b2004-06-03 03:38:44 +0000201
202
203/*
204 * Types defined herein.
205 */
206%type <a_grammar> ModuleList
207%type <a_module> ModuleSpecification
208%type <a_module> ModuleSpecificationBody
209%type <a_module> ModuleSpecificationElement
210%type <a_module> optModuleSpecificationBody /* Optional */
211%type <a_module_flags> optModuleSpecificationFlags
212%type <a_module_flags> ModuleSpecificationFlags /* Set of FL */
213%type <a_module_flags> ModuleSpecificationFlag /* Single FL */
214%type <a_module> ImportsDefinition
215%type <a_module> ImportsBundleSet
216%type <a_xports> ImportsBundle
217%type <a_xports> ImportsList
218%type <a_xports> ExportsDefinition
219%type <a_xports> ExportsBody
220%type <a_expr> ImportsElement
221%type <a_expr> ExportsElement
Lev Walkinf15320b2004-06-03 03:38:44 +0000222%type <a_expr> ExtensionAndException
Lev Walkin070a52d2004-08-22 03:19:54 +0000223%type <a_expr> TypeDeclaration
Lev Walkinf15320b2004-06-03 03:38:44 +0000224%type <a_ref> ComplexTypeReference
225%type <a_ref> ComplexTypeReferenceAmpList
226%type <a_refcomp> ComplexTypeReferenceElement
227%type <a_refcomp> ClassFieldIdentifier
228%type <a_refcomp> ClassFieldName
229%type <a_expr> ClassFieldList
230%type <a_expr> ClassField
231%type <a_expr> ClassDeclaration
Lev Walkin070a52d2004-08-22 03:19:54 +0000232%type <a_expr> Type
Lev Walkinf15320b2004-06-03 03:38:44 +0000233%type <a_expr> DataTypeReference /* Type1 ::= Type2 */
234%type <a_expr> DefinedTypeRef
235%type <a_expr> ValueSetDefinition /* Val INTEGER ::= {1|2} */
236%type <a_expr> ValueDefinition /* val INTEGER ::= 1*/
Lev Walkin9c974182004-09-15 11:59:51 +0000237%type <a_value> Value
Lev Walkinf15320b2004-06-03 03:38:44 +0000238%type <a_value> DefinedValue
239%type <a_value> SignedNumber
Lev Walkin144db9b2004-10-12 23:26:53 +0000240%type <a_expr> optComponentTypeLists
Lev Walkin070a52d2004-08-22 03:19:54 +0000241%type <a_expr> ComponentTypeLists
242%type <a_expr> ComponentType
243%type <a_expr> AlternativeTypeLists
244%type <a_expr> AlternativeType
Lev Walkinf15320b2004-06-03 03:38:44 +0000245//%type <a_expr> optUniverationDefinition
246%type <a_expr> UniverationDefinition
247%type <a_expr> UniverationList
248%type <a_expr> UniverationElement
249%type <tv_str> TypeRefName
250%type <tv_str> ObjectClassReference
Lev Walkinf15320b2004-06-03 03:38:44 +0000251%type <tv_str> Identifier
Lev Walkin83cac2f2004-09-22 16:03:36 +0000252%type <tv_str> optIdentifier
Lev Walkinf15320b2004-06-03 03:38:44 +0000253%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
Lev Walkinc603f102005-01-23 09:51:44 +0000267%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
268%type <a_tag> TagClass TagTypeValue TagPlicit
Lev Walkinf15320b2004-06-03 03:38:44 +0000269%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
270%type <a_constr> optConstraints
Lev Walkind2ea1de2004-08-20 13:25:29 +0000271%type <a_constr> Constraints
Lev Walkinf59d0752004-08-18 04:59:12 +0000272%type <a_constr> SetOfConstraints
273%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
274%type <a_constr> ElementSetSpec /* 1..2,...,3 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000275%type <a_constr> ConstraintSubtypeElement /* 1..2 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000276%type <a_constr> SimpleTableConstraint
277%type <a_constr> TableConstraint
Lev Walkine596bf02005-03-28 15:01:27 +0000278%type <a_constr> InnerTypeConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +0000279%type <a_constr> WithComponentsList
280%type <a_constr> WithComponentsElement
281%type <a_constr> ComponentRelationConstraint
282%type <a_constr> AtNotationList
283%type <a_ref> AtNotationElement
Lev Walkinff7dd142005-03-20 12:58:00 +0000284%type <a_value> SingleValue
285%type <a_value> ContainedSubtype
Lev Walkinf15320b2004-06-03 03:38:44 +0000286%type <a_ctype> ConstraintSpec
287%type <a_ctype> ConstraintRangeSpec
Lev Walkin1e448d32005-03-24 14:26:38 +0000288%type <a_value> RestrictedCharacterStringValue
Lev Walkinf15320b2004-06-03 03:38:44 +0000289%type <a_wsynt> optWithSyntax
290%type <a_wsynt> WithSyntax
291%type <a_wsynt> WithSyntaxFormat
292%type <a_wchunk> WithSyntaxFormatToken
293%type <a_marker> optMarker Marker
294%type <a_int> optUnique
295%type <a_pres> optPresenceConstraint PresenceConstraint
296%type <tv_str> ComponentIdList
297
298
299%%
300
301
302ParsedGrammar:
303 ModuleList {
304 *(void **)param = $1;
305 }
306 ;
307
308ModuleList:
309 ModuleSpecification {
310 $$ = asn1p_new();
311 checkmem($$);
312 TQ_ADD(&($$->modules), $1, mod_next);
313 }
314 | ModuleList ModuleSpecification {
315 $$ = $1;
316 TQ_ADD(&($$->modules), $2, mod_next);
317 }
318 ;
319
320/*
321 * ASN module definition.
322 * === EXAMPLE ===
323 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
324 * BEGIN
325 * ...
326 * END
327 * === EOF ===
328 */
329
330ModuleSpecification:
331 TypeRefName optObjectIdentifier TOK_DEFINITIONS
332 optModuleSpecificationFlags
333 TOK_PPEQ TOK_BEGIN
334 optModuleSpecificationBody
335 TOK_END {
336
337 if($7) {
338 $$ = $7;
339 } else {
340 /* There's a chance that a module is just plain empty */
341 $$ = asn1p_module_new();
342 }
343 checkmem($$);
344
345 $$->Identifier = $1;
346 $$->module_oid = $2;
347 $$->module_flags = $4;
348 }
349 ;
350
351/*
352 * Object Identifier Definition
353 * { iso member-body(2) 3 }
354 */
355optObjectIdentifier:
356 { $$ = 0; }
357 | ObjectIdentifier { $$ = $1; }
358 ;
359
360ObjectIdentifier:
361 '{' ObjectIdentifierBody '}' {
362 $$ = $2;
363 }
364 | '{' '}' {
365 $$ = 0;
366 }
367 ;
368
369ObjectIdentifierBody:
370 ObjectIdentifierElement {
371 $$ = asn1p_oid_new();
372 asn1p_oid_add_arc($$, &$1);
373 if($1.name)
374 free($1.name);
375 }
376 | ObjectIdentifierBody ObjectIdentifierElement {
377 $$ = $1;
378 asn1p_oid_add_arc($$, &$2);
379 if($2.name)
380 free($2.name);
381 }
382 ;
383
384ObjectIdentifierElement:
385 Identifier { /* iso */
386 $$.name = $1;
387 $$.number = -1;
388 }
389 | Identifier '(' TOK_number ')' { /* iso(1) */
390 $$.name = $1;
391 $$.number = $3;
392 }
393 | TOK_number { /* 1 */
394 $$.name = 0;
395 $$.number = $1;
396 }
397 ;
398
399/*
400 * Optional module flags.
401 */
402optModuleSpecificationFlags:
403 { $$ = MSF_NOFLAGS; }
404 | ModuleSpecificationFlags {
405 $$ = $1;
406 }
407 ;
408
409/*
410 * Module flags.
411 */
412ModuleSpecificationFlags:
413 ModuleSpecificationFlag {
414 $$ = $1;
415 }
416 | ModuleSpecificationFlags ModuleSpecificationFlag {
417 $$ = $1 | $2;
418 }
419 ;
420
421/*
422 * Single module flag.
423 */
424ModuleSpecificationFlag:
425 TOK_EXPLICIT TOK_TAGS {
426 $$ = MSF_EXPLICIT_TAGS;
427 }
428 | TOK_IMPLICIT TOK_TAGS {
429 $$ = MSF_IMPLICIT_TAGS;
430 }
431 | TOK_AUTOMATIC TOK_TAGS {
432 $$ = MSF_AUTOMATIC_TAGS;
433 }
434 | TOK_EXTENSIBILITY TOK_IMPLIED {
435 $$ = MSF_EXTENSIBILITY_IMPLIED;
436 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000437 /* EncodingReferenceDefault */
438 | TOK_capitalreference TOK_INSTRUCTIONS {
439 /* X.680Amd1 specifies TAG and XER */
440 if(strcmp($1, "TAG") == 0) {
441 $$ = MSF_TAG_INSTRUCTIONS;
442 } else if(strcmp($1, "XER") == 0) {
443 $$ = MSF_XER_INSTRUCTIONS;
444 } else {
445 fprintf(stderr,
446 "WARNING: %s INSTRUCTIONS at line %d: "
447 "Unrecognized encoding reference\n",
448 $1, yylineno);
449 $$ = MSF_unk_INSTRUCTIONS;
450 }
451 free($1);
452 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000453 ;
454
455/*
456 * Optional module body.
457 */
458optModuleSpecificationBody:
459 { $$ = 0; }
460 | ModuleSpecificationBody {
Lev Walkinf15320b2004-06-03 03:38:44 +0000461 $$ = $1;
462 }
463 ;
464
465/*
466 * ASN.1 Module body.
467 */
468ModuleSpecificationBody:
469 ModuleSpecificationElement {
470 $$ = $1;
471 }
472 | ModuleSpecificationBody ModuleSpecificationElement {
473 $$ = $1;
474
Lev Walkinf59d0752004-08-18 04:59:12 +0000475 /* Behave well when one of them is skipped. */
476 if(!($1)) {
477 if($2) $$ = $2;
478 break;
479 }
480
Lev Walkinf15320b2004-06-03 03:38:44 +0000481#ifdef MY_IMPORT
482#error MY_IMPORT DEFINED ELSEWHERE!
483#endif
484#define MY_IMPORT(foo,field) do { \
Lev Walkinbc55d232004-08-13 12:31:09 +0000485 while(TQ_FIRST(&($2->foo))) { \
Lev Walkinf15320b2004-06-03 03:38:44 +0000486 TQ_ADD(&($$->foo), \
487 TQ_REMOVE(&($2->foo), field), \
488 field); \
Lev Walkinbc55d232004-08-13 12:31:09 +0000489 } \
490 assert(TQ_FIRST(&($2->foo)) == 0); \
491 } while(0)
Lev Walkinf15320b2004-06-03 03:38:44 +0000492
493 MY_IMPORT(imports, xp_next);
494 MY_IMPORT(exports, xp_next);
495 MY_IMPORT(members, next);
496#undef MY_IMPORT
497
498 }
499 ;
500
501/*
502 * One of the elements of ASN.1 module specification.
503 */
504ModuleSpecificationElement:
505 ImportsDefinition {
506 $$ = $1;
507 }
508 | ExportsDefinition {
509 $$ = asn1p_module_new();
510 checkmem($$);
511 if($1) {
512 TQ_ADD(&($$->exports), $1, xp_next);
513 } else {
514 /* "EXPORTS ALL;" ? */
515 }
516 }
517 | DataTypeReference {
518 $$ = asn1p_module_new();
519 checkmem($$);
520 assert($1->expr_type != A1TC_INVALID);
521 assert($1->meta_type != AMT_INVALID);
522 TQ_ADD(&($$->members), $1, next);
523 }
524 | ValueDefinition {
525 $$ = asn1p_module_new();
526 checkmem($$);
527 assert($1->expr_type != A1TC_INVALID);
528 assert($1->meta_type != AMT_INVALID);
529 TQ_ADD(&($$->members), $1, next);
530 }
531 /*
532 * Value set definition
533 * === EXAMPLE ===
534 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
535 * === EOF ===
536 */
537 | ValueSetDefinition {
538 $$ = asn1p_module_new();
539 checkmem($$);
540 assert($1->expr_type != A1TC_INVALID);
541 assert($1->meta_type != AMT_INVALID);
542 TQ_ADD(&($$->members), $1, next);
543 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000544 | TOK_ENCODING_CONTROL TOK_capitalreference
545 { asn1p_lexer_hack_push_encoding_control(); }
546 {
547 fprintf(stderr,
548 "WARNING: ENCODING-CONTROL %s "
549 "specification at line %d ignored\n",
550 $2, yylineno);
551 free($2);
552 $$ = 0;
553 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000554
555 /*
556 * Erroneous attemps
557 */
558 | BasicString {
559 return yyerror(
560 "Attempt to redefine a standard basic type, "
561 "use -ftypesXY to switch back "
562 "to older version of ASN.1 standard");
563 }
564 ;
565
566/*
567 * === EXAMPLE ===
568 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
569 * === EOF ===
570 */
571ImportsDefinition:
572 TOK_IMPORTS ImportsBundleSet ';' {
573 $$ = $2;
574 }
575 /*
576 * Some error cases.
577 */
578 | TOK_IMPORTS TOK_FROM /* ... */ {
579 return yyerror("Empty IMPORTS list");
580 }
581 ;
582
583ImportsBundleSet:
584 ImportsBundle {
585 $$ = asn1p_module_new();
586 checkmem($$);
587 TQ_ADD(&($$->imports), $1, xp_next);
588 }
589 | ImportsBundleSet ImportsBundle {
590 $$ = $1;
591 TQ_ADD(&($$->imports), $2, xp_next);
592 }
593 ;
594
595ImportsBundle:
596 ImportsList TOK_FROM TypeRefName optObjectIdentifier {
597 $$ = $1;
598 $$->from = $3;
599 $$->from_oid = $4;
600 checkmem($$);
601 }
602 ;
603
604ImportsList:
605 ImportsElement {
606 $$ = asn1p_xports_new();
607 checkmem($$);
608 TQ_ADD(&($$->members), $1, next);
609 }
610 | ImportsList ',' ImportsElement {
611 $$ = $1;
612 TQ_ADD(&($$->members), $3, next);
613 }
614 ;
615
616ImportsElement:
617 TypeRefName {
618 $$ = asn1p_expr_new(yylineno);
619 checkmem($$);
620 $$->Identifier = $1;
621 $$->expr_type = A1TC_REFERENCE;
622 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000623 | TypeRefName '{' '}' { /* Completely equivalent to above */
624 $$ = asn1p_expr_new(yylineno);
625 checkmem($$);
626 $$->Identifier = $1;
627 $$->expr_type = A1TC_REFERENCE;
628 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000629 | Identifier {
630 $$ = asn1p_expr_new(yylineno);
631 checkmem($$);
632 $$->Identifier = $1;
633 $$->expr_type = A1TC_REFERENCE;
634 }
635 ;
636
637ExportsDefinition:
638 TOK_EXPORTS ExportsBody ';' {
639 $$ = $2;
640 }
641 | TOK_EXPORTS TOK_ALL ';' {
642 $$ = 0;
643 }
644 | TOK_EXPORTS ';' {
645 /* Empty EXPORTS clause effectively prohibits export. */
646 $$ = asn1p_xports_new();
647 checkmem($$);
648 }
649 ;
650
651ExportsBody:
652 ExportsElement {
653 $$ = asn1p_xports_new();
654 assert($$);
655 TQ_ADD(&($$->members), $1, next);
656 }
657 | ExportsBody ',' ExportsElement {
658 $$ = $1;
659 TQ_ADD(&($$->members), $3, next);
660 }
661 ;
662
663ExportsElement:
664 TypeRefName {
665 $$ = asn1p_expr_new(yylineno);
666 checkmem($$);
667 $$->Identifier = $1;
668 $$->expr_type = A1TC_EXPORTVAR;
669 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000670 | TypeRefName '{' '}' {
671 $$ = asn1p_expr_new(yylineno);
672 checkmem($$);
673 $$->Identifier = $1;
674 $$->expr_type = A1TC_EXPORTVAR;
675 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000676 | Identifier {
677 $$ = asn1p_expr_new(yylineno);
678 checkmem($$);
679 $$->Identifier = $1;
680 $$->expr_type = A1TC_EXPORTVAR;
681 }
682 ;
683
684
685ValueSetDefinition:
Lev Walkin8ea99482005-03-31 21:48:13 +0000686 TypeRefName DefinedTypeRef TOK_PPEQ
687 '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Lev Walkinf15320b2004-06-03 03:38:44 +0000688 $$ = $2;
689 assert($$->Identifier == 0);
690 $$->Identifier = $1;
691 $$->meta_type = AMT_VALUESET;
Lev Walkin8ea99482005-03-31 21:48:13 +0000692 // take care of ValueSet body
Lev Walkinf15320b2004-06-03 03:38:44 +0000693 }
694 ;
695
696DefinedTypeRef:
697 ComplexTypeReference {
698 $$ = asn1p_expr_new(yylineno);
699 checkmem($$);
700 $$->reference = $1;
701 $$->expr_type = A1TC_REFERENCE;
702 $$->meta_type = AMT_TYPEREF;
703 }
704 | BasicTypeId {
705 $$ = asn1p_expr_new(yylineno);
706 checkmem($$);
707 $$->expr_type = $1;
708 $$->meta_type = AMT_TYPE;
709 }
710 ;
711
Lev Walkinf15320b2004-06-03 03:38:44 +0000712/*
713 * Data Type Reference.
714 * === EXAMPLE ===
715 * Type3 ::= CHOICE { a Type1, b Type 2 }
716 * === EOF ===
717 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000718DataTypeReference:
719 /*
720 * Optionally tagged type definition.
721 */
722 TypeRefName TOK_PPEQ optTag TOK_TYPE_IDENTIFIER {
723 $$ = asn1p_expr_new(yylineno);
724 checkmem($$);
725 $$->Identifier = $1;
726 $$->tag = $3;
727 $$->expr_type = A1TC_TYPEID;
728 $$->meta_type = AMT_TYPE;
729 }
Lev Walkinaf120f72004-09-14 02:36:39 +0000730 | TypeRefName TOK_PPEQ Type {
731 $$ = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000732 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000733 assert($$->expr_type);
734 assert($$->meta_type);
735 }
736 | TypeRefName TOK_PPEQ ClassDeclaration {
737 $$ = $3;
738 $$->Identifier = $1;
739 assert($$->expr_type == A1TC_CLASSDEF);
740 assert($$->meta_type == AMT_OBJECT);
741 }
742 /*
743 * Parametrized <Type> declaration:
744 * === EXAMPLE ===
745 * SIGNED { ToBeSigned } ::= SEQUENCE {
746 * toBeSigned ToBeSigned,
747 * algorithm AlgorithmIdentifier,
748 * signature BIT STRING
749 * }
750 * === EOF ===
751 */
Lev Walkin070a52d2004-08-22 03:19:54 +0000752 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000753 $$ = $6;
754 assert($$->Identifier == 0);
755 $$->Identifier = $1;
756 $$->params = $3;
757 $$->meta_type = AMT_PARAMTYPE;
758 }
759 ;
760
761ParameterArgumentList:
762 ParameterArgumentName {
763 int ret;
764 $$ = asn1p_paramlist_new(yylineno);
765 checkmem($$);
766 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
767 checkmem(ret == 0);
768 if($1.governor) asn1p_ref_free($1.governor);
769 if($1.argument) free($1.argument);
770 }
771 | ParameterArgumentList ',' ParameterArgumentName {
772 int ret;
773 $$ = $1;
774 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
775 checkmem(ret == 0);
776 if($3.governor) asn1p_ref_free($3.governor);
777 if($3.argument) free($3.argument);
778 }
779 ;
780
781ParameterArgumentName:
782 TypeRefName {
783 $$.governor = NULL;
784 $$.argument = $1;
785 }
786 | TypeRefName ':' Identifier {
787 int ret;
788 $$.governor = asn1p_ref_new(yylineno);
789 ret = asn1p_ref_add_component($$.governor, $1, 0);
790 checkmem(ret == 0);
791 $$.argument = $3;
792 }
Lev Walkinc8092cb2005-02-18 16:34:21 +0000793 | TypeRefName ':' TypeRefName {
794 int ret;
795 $$.governor = asn1p_ref_new(yylineno);
796 ret = asn1p_ref_add_component($$.governor, $1, 0);
797 checkmem(ret == 0);
798 $$.argument = $3;
799 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000800 | BasicTypeId ':' Identifier {
801 int ret;
802 $$.governor = asn1p_ref_new(yylineno);
803 ret = asn1p_ref_add_component($$.governor,
804 ASN_EXPR_TYPE2STR($1), 1);
805 checkmem(ret == 0);
806 $$.argument = $3;
807 }
808 ;
809
810ActualParameterList:
811 ActualParameter {
812 $$ = asn1p_expr_new(yylineno);
813 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000814 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000815 }
816 | ActualParameterList ',' ActualParameter {
817 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000818 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000819 }
820 ;
821
822ActualParameter:
Lev Walkin070a52d2004-08-22 03:19:54 +0000823 Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000824 $$ = $1;
825 }
826 | Identifier {
827 $$ = asn1p_expr_new(yylineno);
828 checkmem($$);
829 $$->Identifier = $1;
830 $$->expr_type = A1TC_REFERENCE;
831 $$->meta_type = AMT_VALUE;
832 }
833 ;
834
835/*
Lev Walkinc8092cb2005-02-18 16:34:21 +0000836 | '{' ActualParameter '}' {
837 $$ = asn1p_expr_new(yylineno);
838 checkmem($$);
839 asn1p_expr_add($$, $2);
840 $$->expr_type = A1TC_PARAMETRIZED;
841 $$->meta_type = AMT_TYPE;
842 }
843 ;
844*/
845
846/*
Lev Walkinf15320b2004-06-03 03:38:44 +0000847 * A collection of constructed data type members.
848 */
Lev Walkin144db9b2004-10-12 23:26:53 +0000849optComponentTypeLists:
850 { $$ = asn1p_expr_new(yylineno); }
851 | ComponentTypeLists { $$ = $1; };
852
Lev Walkin070a52d2004-08-22 03:19:54 +0000853ComponentTypeLists:
854 ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +0000855 $$ = asn1p_expr_new(yylineno);
856 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000857 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000858 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000859 | ComponentTypeLists ',' ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +0000860 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000861 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000862 }
863 ;
864
Lev Walkin070a52d2004-08-22 03:19:54 +0000865ComponentType:
Lev Walkinaf120f72004-09-14 02:36:39 +0000866 Identifier Type optMarker {
Lev Walkin070a52d2004-08-22 03:19:54 +0000867 $$ = $2;
868 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +0000869 $$->Identifier = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +0000870 $$->marker = $3;
871 }
872 | TOK_COMPONENTS TOK_OF Type {
873 $$ = asn1p_expr_new(yylineno);
874 checkmem($$);
875 $$->meta_type = $3->meta_type;
876 $$->expr_type = A1TC_COMPONENTS_OF;
Lev Walkin1004aa92004-09-08 00:28:11 +0000877 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +0000878 }
879 | ExtensionAndException {
880 $$ = $1;
881 }
882 ;
883
884AlternativeTypeLists:
885 AlternativeType {
886 $$ = asn1p_expr_new(yylineno);
887 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000888 asn1p_expr_add($$, $1);
Lev Walkin070a52d2004-08-22 03:19:54 +0000889 }
890 | AlternativeTypeLists ',' AlternativeType {
891 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000892 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +0000893 }
894 ;
895
896AlternativeType:
Lev Walkinaf120f72004-09-14 02:36:39 +0000897 Identifier Type {
Lev Walkin070a52d2004-08-22 03:19:54 +0000898 $$ = $2;
899 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +0000900 $$->Identifier = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +0000901 }
902 | ExtensionAndException {
903 $$ = $1;
904 }
905 ;
906
Lev Walkinf15320b2004-06-03 03:38:44 +0000907ClassDeclaration:
908 TOK_CLASS '{' ClassFieldList '}' optWithSyntax {
909 $$ = $3;
910 checkmem($$);
911 $$->with_syntax = $5;
912 assert($$->expr_type == A1TC_CLASSDEF);
913 assert($$->meta_type == AMT_OBJECT);
914 }
915 ;
916
917optUnique:
918 { $$ = 0; }
919 | TOK_UNIQUE { $$ = 1; }
920 ;
921
922ClassFieldList:
923 ClassField {
924 $$ = asn1p_expr_new(yylineno);
925 checkmem($$);
926 $$->expr_type = A1TC_CLASSDEF;
927 $$->meta_type = AMT_OBJECT;
Lev Walkin1004aa92004-09-08 00:28:11 +0000928 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000929 }
930 | ClassFieldList ',' ClassField {
931 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000932 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000933 }
934 ;
935
936ClassField:
937 ClassFieldIdentifier optMarker {
938 $$ = asn1p_expr_new(yylineno);
939 checkmem($$);
940 $$->Identifier = $1.name;
941 $$->expr_type = A1TC_CLASSFIELD;
942 $$->meta_type = AMT_OBJECTFIELD;
943 $$->marker = $2;
944 }
Lev Walkinb7c45ca2004-11-24 17:43:29 +0000945 | ClassFieldIdentifier Type optUnique optMarker {
Lev Walkinf15320b2004-06-03 03:38:44 +0000946 $$ = $2;
947 $$->Identifier = $1.name;
Lev Walkinb7c45ca2004-11-24 17:43:29 +0000948 $$->marker = $4;
949 $$->unique = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000950 }
Lev Walkinb7c45ca2004-11-24 17:43:29 +0000951 | ClassFieldIdentifier ClassFieldIdentifier optUnique optMarker {
Lev Walkinf15320b2004-06-03 03:38:44 +0000952 int ret;
953 $$ = asn1p_expr_new(yylineno);
954 checkmem($$);
955 $$->Identifier = $1.name;
956 $$->reference = asn1p_ref_new(yylineno);
957 checkmem($$->reference);
958 ret = asn1p_ref_add_component($$->reference,
959 $2.name, $2.lex_type);
960 checkmem(ret == 0);
961 $$->expr_type = A1TC_CLASSFIELD;
962 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkinb7c45ca2004-11-24 17:43:29 +0000963 $$->marker = $4;
964 $$->unique = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000965 }
966 ;
967
968optWithSyntax:
969 { $$ = 0; }
970 | WithSyntax {
971 $$ = $1;
972 }
973 ;
974
975WithSyntax:
976 TOK_WITH TOK_SYNTAX '{'
977 { asn1p_lexer_hack_enable_with_syntax(); }
978 WithSyntaxFormat
979 '}' {
980 $$ = $5;
981 }
982 ;
983
984WithSyntaxFormat:
985 WithSyntaxFormatToken {
986 $$ = asn1p_wsyntx_new();
987 TQ_ADD(&($$->chunks), $1, next);
988 }
989 | WithSyntaxFormat WithSyntaxFormatToken {
990 $$ = $1;
991 TQ_ADD(&($$->chunks), $2, next);
992 }
993 ;
994
995WithSyntaxFormatToken:
996 TOK_opaque {
997 $$ = asn1p_wsyntx_chunk_frombuf($1.buf, $1.len, 0);
998 }
999 | ClassFieldIdentifier {
1000 asn1p_ref_t *ref;
1001 int ret;
1002 ref = asn1p_ref_new(yylineno);
1003 checkmem(ref);
1004 ret = asn1p_ref_add_component(ref, $1.name, $1.lex_type);
1005 checkmem(ret == 0);
1006 $$ = asn1p_wsyntx_chunk_fromref(ref, 0);
1007 }
1008 ;
1009
Lev Walkinf15320b2004-06-03 03:38:44 +00001010ExtensionAndException:
1011 TOK_ThreeDots {
Lev Walkinceb20e72004-09-05 10:40:41 +00001012 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001013 checkmem($$);
1014 $$->Identifier = strdup("...");
1015 checkmem($$->Identifier);
1016 $$->expr_type = A1TC_EXTENSIBLE;
1017 $$->meta_type = AMT_TYPE;
1018 }
1019 | TOK_ThreeDots '!' DefinedValue {
Lev Walkinceb20e72004-09-05 10:40:41 +00001020 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001021 checkmem($$);
1022 $$->Identifier = strdup("...");
1023 checkmem($$->Identifier);
1024 $$->value = $3;
1025 $$->expr_type = A1TC_EXTENSIBLE;
1026 $$->meta_type = AMT_TYPE;
1027 }
1028 | TOK_ThreeDots '!' SignedNumber {
Lev Walkinceb20e72004-09-05 10:40:41 +00001029 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001030 checkmem($$);
1031 $$->Identifier = strdup("...");
1032 $$->value = $3;
1033 checkmem($$->Identifier);
1034 $$->expr_type = A1TC_EXTENSIBLE;
1035 $$->meta_type = AMT_TYPE;
1036 }
1037 ;
1038
Lev Walkin070a52d2004-08-22 03:19:54 +00001039Type:
Lev Walkinaf120f72004-09-14 02:36:39 +00001040 optTag TypeDeclaration optConstraints {
1041 $$ = $2;
1042 $$->tag = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001043 /*
1044 * Outer constraint for SEQUENCE OF and SET OF applies
1045 * to the inner type.
1046 */
1047 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1048 || $$->expr_type == ASN_CONSTR_SET_OF) {
1049 assert(!TQ_FIRST(&($$->members))->constraints);
Lev Walkinaf120f72004-09-14 02:36:39 +00001050 TQ_FIRST(&($$->members))->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001051 } else {
1052 if($$->constraints) {
1053 assert(!$2);
1054 } else {
Lev Walkinaf120f72004-09-14 02:36:39 +00001055 $$->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001056 }
1057 }
1058 }
1059 ;
1060
1061TypeDeclaration:
Lev Walkinf15320b2004-06-03 03:38:44 +00001062 BasicType {
1063 $$ = $1;
1064 }
Lev Walkin070a52d2004-08-22 03:19:54 +00001065 | TOK_CHOICE '{' AlternativeTypeLists '}' {
1066 $$ = $3;
1067 assert($$->expr_type == A1TC_INVALID);
1068 $$->expr_type = ASN_CONSTR_CHOICE;
1069 $$->meta_type = AMT_TYPE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001070 }
Lev Walkin144db9b2004-10-12 23:26:53 +00001071 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001072 $$ = $3;
1073 assert($$->expr_type == A1TC_INVALID);
1074 $$->expr_type = ASN_CONSTR_SEQUENCE;
1075 $$->meta_type = AMT_TYPE;
1076 }
Lev Walkin144db9b2004-10-12 23:26:53 +00001077 | TOK_SET '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001078 $$ = $3;
1079 assert($$->expr_type == A1TC_INVALID);
1080 $$->expr_type = ASN_CONSTR_SET;
1081 $$->meta_type = AMT_TYPE;
1082 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001083 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkinceb20e72004-09-05 10:40:41 +00001084 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001085 checkmem($$);
1086 $$->constraints = $2;
1087 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1088 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001089 $6->Identifier = $4;
1090 $6->tag = $5;
1091 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001092 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001093 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkinceb20e72004-09-05 10:40:41 +00001094 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001095 checkmem($$);
1096 $$->constraints = $2;
1097 $$->expr_type = ASN_CONSTR_SET_OF;
1098 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001099 $6->Identifier = $4;
1100 $6->tag = $5;
1101 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001102 }
1103 | TOK_ANY {
Lev Walkinceb20e72004-09-05 10:40:41 +00001104 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001105 checkmem($$);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001106 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001107 $$->meta_type = AMT_TYPE;
1108 }
1109 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1110 int ret;
Lev Walkinceb20e72004-09-05 10:40:41 +00001111 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001112 checkmem($$);
1113 $$->reference = asn1p_ref_new(yylineno);
1114 ret = asn1p_ref_add_component($$->reference,
1115 $4, RLT_lowercase);
1116 checkmem(ret == 0);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001117 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001118 $$->meta_type = AMT_TYPE;
1119 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001120 /*
1121 * A parametrized assignment.
1122 */
1123 | TypeRefName '{' ActualParameterList '}' {
1124 int ret;
1125 $$ = $3;
1126 assert($$->expr_type == 0);
1127 assert($$->meta_type == 0);
1128 assert($$->reference == 0);
1129 $$->reference = asn1p_ref_new(yylineno);
1130 checkmem($$->reference);
1131 ret = asn1p_ref_add_component($$->reference, $1, RLT_UNKNOWN);
1132 checkmem(ret == 0);
1133 free($1);
1134 $$->expr_type = A1TC_PARAMETRIZED;
1135 $$->meta_type = AMT_TYPE;
1136 }
1137 /*
1138 * A DefinedType reference.
1139 * "CLASS1.&id.&id2"
1140 * or
1141 * "Module.Type"
1142 * or
1143 * "Module.identifier"
1144 * or
1145 * "Type"
1146 */
1147 | ComplexTypeReference {
1148 $$ = asn1p_expr_new(yylineno);
1149 checkmem($$);
1150 $$->reference = $1;
1151 $$->expr_type = A1TC_REFERENCE;
1152 $$->meta_type = AMT_TYPEREF;
1153 }
1154 | TOK_INSTANCE TOK_OF ComplexTypeReference {
1155 $$ = asn1p_expr_new(yylineno);
1156 checkmem($$);
1157 $$->reference = $3;
1158 $$->expr_type = A1TC_INSTANCE;
1159 $$->meta_type = AMT_TYPE;
1160 }
1161 ;
1162
1163/*
1164 * A type name consisting of several components.
1165 * === EXAMPLE ===
1166 * === EOF ===
1167 */
1168ComplexTypeReference:
1169 TOK_typereference {
1170 int ret;
1171 $$ = asn1p_ref_new(yylineno);
1172 checkmem($$);
1173 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1174 checkmem(ret == 0);
1175 free($1);
1176 }
1177 | TOK_typereference '.' TypeRefName {
1178 int ret;
1179 $$ = asn1p_ref_new(yylineno);
1180 checkmem($$);
1181 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1182 checkmem(ret == 0);
1183 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1184 checkmem(ret == 0);
1185 free($1);
1186 }
Lev Walkin9c974182004-09-15 11:59:51 +00001187 | ObjectClassReference '.' TypeRefName {
1188 int ret;
1189 $$ = asn1p_ref_new(yylineno);
1190 checkmem($$);
1191 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1192 checkmem(ret == 0);
1193 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1194 checkmem(ret == 0);
1195 free($1);
1196 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001197 | TOK_typereference '.' Identifier {
1198 int ret;
1199 $$ = asn1p_ref_new(yylineno);
1200 checkmem($$);
1201 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1202 checkmem(ret == 0);
1203 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1204 checkmem(ret == 0);
1205 free($1);
1206 }
1207 | ObjectClassReference {
1208 int ret;
1209 $$ = asn1p_ref_new(yylineno);
1210 checkmem($$);
1211 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1212 free($1);
1213 checkmem(ret == 0);
1214 }
1215 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1216 int ret;
1217 $$ = $3;
1218 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1219 free($1);
1220 checkmem(ret == 0);
1221 /*
1222 * Move the last element infront.
1223 */
1224 {
1225 struct asn1p_ref_component_s tmp_comp;
1226 tmp_comp = $$->components[$$->comp_count-1];
1227 memmove(&$$->components[1],
1228 &$$->components[0],
1229 sizeof($$->components[0])
1230 * ($$->comp_count - 1));
1231 $$->components[0] = tmp_comp;
1232 }
1233 }
1234 ;
1235
1236ComplexTypeReferenceAmpList:
1237 ComplexTypeReferenceElement {
1238 int ret;
1239 $$ = asn1p_ref_new(yylineno);
1240 checkmem($$);
1241 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1242 free($1.name);
1243 checkmem(ret == 0);
1244 }
1245 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1246 int ret;
1247 $$ = $1;
1248 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1249 free($3.name);
1250 checkmem(ret == 0);
1251 }
1252 ;
1253
1254ComplexTypeReferenceElement: ClassFieldName;
1255ClassFieldIdentifier: ClassFieldName;
1256
1257ClassFieldName:
1258 /* "&Type1" */
1259 TOK_typefieldreference {
1260 $$.lex_type = RLT_AmpUppercase;
1261 $$.name = $1;
1262 }
1263 /* "&id" */
1264 | TOK_valuefieldreference {
1265 $$.lex_type = RLT_Amplowercase;
1266 $$.name = $1;
1267 }
1268 ;
1269
1270
1271/*
1272 * === EXAMPLE ===
1273 * value INTEGER ::= 1
1274 * === EOF ===
1275 */
1276ValueDefinition:
Lev Walkin9c974182004-09-15 11:59:51 +00001277 Identifier DefinedTypeRef TOK_PPEQ Value {
Lev Walkinf15320b2004-06-03 03:38:44 +00001278 $$ = $2;
1279 assert($$->Identifier == NULL);
1280 $$->Identifier = $1;
1281 $$->meta_type = AMT_VALUE;
1282 $$->value = $4;
1283 }
1284 ;
1285
Lev Walkin9c974182004-09-15 11:59:51 +00001286Value:
1287 Identifier ':' Value {
1288 $$ = asn1p_value_fromint(0);
1289 checkmem($$);
1290 $$->type = ATV_CHOICE_IDENTIFIER;
1291 $$->value.choice_identifier.identifier = $1;
1292 $$->value.choice_identifier.value = $3;
1293 }
Lev Walkincbad2512005-03-24 16:27:02 +00001294 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Lev Walkinf15320b2004-06-03 03:38:44 +00001295 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1296 checkmem($$);
1297 $$->type = ATV_UNPARSED;
1298 }
Lev Walkin9c974182004-09-15 11:59:51 +00001299 | TOK_NULL {
1300 $$ = asn1p_value_fromint(0);
1301 checkmem($$);
1302 $$->type = ATV_NULL;
1303 }
1304 | TOK_FALSE {
1305 $$ = asn1p_value_fromint(0);
1306 checkmem($$);
1307 $$->type = ATV_FALSE;
1308 }
1309 | TOK_TRUE {
1310 $$ = asn1p_value_fromint(0);
1311 checkmem($$);
1312 $$->type = ATV_TRUE;
1313 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001314 | TOK_bstring {
1315 $$ = _convert_bitstring2binary($1, 'B');
1316 checkmem($$);
1317 }
1318 | TOK_hstring {
1319 $$ = _convert_bitstring2binary($1, 'H');
1320 checkmem($$);
1321 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001322 | RestrictedCharacterStringValue {
1323 $$ = $$;
Lev Walkinf15320b2004-06-03 03:38:44 +00001324 }
1325 | SignedNumber {
1326 $$ = $1;
1327 }
1328 | DefinedValue {
1329 $$ = $1;
1330 }
1331 ;
1332
1333DefinedValue:
1334 Identifier {
1335 asn1p_ref_t *ref;
1336 int ret;
1337 ref = asn1p_ref_new(yylineno);
1338 checkmem(ref);
1339 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1340 checkmem(ret == 0);
1341 $$ = asn1p_value_fromref(ref, 0);
1342 checkmem($$);
1343 free($1);
1344 }
1345 | TypeRefName '.' Identifier {
1346 asn1p_ref_t *ref;
1347 int ret;
1348 ref = asn1p_ref_new(yylineno);
1349 checkmem(ref);
1350 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1351 checkmem(ret == 0);
1352 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1353 checkmem(ret == 0);
1354 $$ = asn1p_value_fromref(ref, 0);
1355 checkmem($$);
1356 free($1);
1357 free($3);
1358 }
1359 ;
1360
Lev Walkin1e448d32005-03-24 14:26:38 +00001361
1362RestrictedCharacterStringValue:
1363 TOK_cstring {
1364 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1365 checkmem($$);
1366 }
Lev Walkind9574ae2005-03-24 16:22:35 +00001367 | TOK_tuple {
1368 $$ = asn1p_value_fromint($1);
1369 checkmem($$);
1370 $$->type = ATV_TUPLE;
1371 }
1372 | TOK_quadruple {
1373 $$ = asn1p_value_fromint($1);
1374 checkmem($$);
1375 $$->type = ATV_QUADRUPLE;
1376 }
1377 /*
Lev Walkin1e448d32005-03-24 14:26:38 +00001378 | '{' TOK_number ',' TOK_number '}' {
1379 asn1c_integer_t v = ($2 << 4) + $4;
1380 if($2 > 7) return yyerror("X.680:2003, #37.14 "
1381 "mandates 0..7 range for Tuple's TableColumn");
1382 if($4 > 15) return yyerror("X.680:2003, #37.14 "
1383 "mandates 0..15 range for Tuple's TableRow");
1384 $$ = asn1p_value_fromint(v);
1385 checkmem($$);
1386 $$->type = ATV_TUPLE;
1387 }
1388 | '{' TOK_number ',' TOK_number ',' TOK_number ',' TOK_number '}' {
1389 asn1c_integer_t v = ($2 << 24) | ($4 << 16) | ($6 << 8) | $8;
1390 if($2 > 127) return yyerror("X.680:2003, #37.12 "
1391 "mandates 0..127 range for Quadruple's Group");
1392 if($4 > 255) return yyerror("X.680:2003, #37.12 "
1393 "mandates 0..255 range for Quadruple's Plane");
1394 if($6 > 255) return yyerror("X.680:2003, #37.12 "
1395 "mandates 0..255 range for Quadruple's Row");
1396 if($8 > 255) return yyerror("X.680:2003, #37.12 "
1397 "mandates 0..255 range for Quadruple's Cell");
1398 $$ = asn1p_value_fromint(v);
1399 checkmem($$);
1400 $$->type = ATV_QUADRUPLE;
1401 }
Lev Walkind9574ae2005-03-24 16:22:35 +00001402 */
Lev Walkin1e448d32005-03-24 14:26:38 +00001403 ;
1404
Lev Walkinf15320b2004-06-03 03:38:44 +00001405Opaque:
1406 TOK_opaque {
Lev Walkin1893ddf2005-03-20 14:28:32 +00001407 $$.len = $1.len + 1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001408 $$.buf = malloc($$.len + 1);
1409 checkmem($$.buf);
1410 $$.buf[0] = '{';
Lev Walkin1893ddf2005-03-20 14:28:32 +00001411 memcpy($$.buf + 1, $1.buf, $1.len);
Lev Walkinf15320b2004-06-03 03:38:44 +00001412 $$.buf[$$.len] = '\0';
1413 free($1.buf);
1414 }
1415 | Opaque TOK_opaque {
1416 int newsize = $1.len + $2.len;
1417 char *p = malloc(newsize + 1);
1418 checkmem(p);
1419 memcpy(p , $1.buf, $1.len);
1420 memcpy(p + $1.len, $2.buf, $2.len);
1421 p[newsize] = '\0';
1422 free($1.buf);
1423 free($2.buf);
1424 $$.buf = p;
1425 $$.len = newsize;
1426 }
1427 ;
1428
1429BasicTypeId:
1430 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1431 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1432 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1433 | BasicTypeId_UniverationCompatible { $$ = $1; }
1434 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1435 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1436 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1437 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1438 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1439 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1440 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1441 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
Lev Walkinc7d939d2005-03-20 11:12:40 +00001442 | BasicString { $$ = $1; }
Lev Walkinf15320b2004-06-03 03:38:44 +00001443 ;
1444
1445/*
1446 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1447 */
1448BasicTypeId_UniverationCompatible:
1449 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1450 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1451 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1452 ;
1453
1454BasicType:
1455 BasicTypeId {
Lev Walkinceb20e72004-09-05 10:40:41 +00001456 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001457 checkmem($$);
1458 $$->expr_type = $1;
1459 $$->meta_type = AMT_TYPE;
1460 }
1461 | BasicTypeId_UniverationCompatible UniverationDefinition {
1462 if($2) {
1463 $$ = $2;
1464 } else {
Lev Walkinceb20e72004-09-05 10:40:41 +00001465 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001466 checkmem($$);
1467 }
1468 $$->expr_type = $1;
1469 $$->meta_type = AMT_TYPE;
1470 }
1471 ;
1472
1473BasicString:
1474 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1475 | TOK_GeneralString {
1476 $$ = ASN_STRING_GeneralString;
Lev Walkin9c974182004-09-15 11:59:51 +00001477 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001478 }
1479 | TOK_GraphicString {
1480 $$ = ASN_STRING_GraphicString;
Lev Walkin9c974182004-09-15 11:59:51 +00001481 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001482 }
1483 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1484 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1485 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1486 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1487 | TOK_T61String {
1488 $$ = ASN_STRING_T61String;
Lev Walkin9c974182004-09-15 11:59:51 +00001489 fprintf(stderr, "WARNING: T61String is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001490 }
1491 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1492 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1493 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1494 | TOK_VideotexString {
1495 $$ = ASN_STRING_VideotexString;
Lev Walkin9c974182004-09-15 11:59:51 +00001496 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001497 }
1498 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1499 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1500 ;
1501
Lev Walkind2ea1de2004-08-20 13:25:29 +00001502
Lev Walkinf15320b2004-06-03 03:38:44 +00001503/*
1504 * Data type constraints.
1505 */
Lev Walkinf15320b2004-06-03 03:38:44 +00001506Union: '|' | TOK_UNION;
1507Intersection: '^' | TOK_INTERSECTION;
1508Except: TOK_EXCEPT;
1509
Lev Walkinf59d0752004-08-18 04:59:12 +00001510optConstraints:
1511 { $$ = 0; }
Lev Walkind2ea1de2004-08-20 13:25:29 +00001512 | Constraints {
1513 $$ = $1;
1514 }
1515 ;
1516
1517Constraints:
1518 SetOfConstraints {
Lev Walkinf59d0752004-08-18 04:59:12 +00001519 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
1520 }
1521 | TOK_SIZE '(' ElementSetSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001522 /*
1523 * This is a special case, for compatibility purposes.
Lev Walkinf59d0752004-08-18 04:59:12 +00001524 * It goes without parentheses.
Lev Walkinf15320b2004-06-03 03:38:44 +00001525 */
Lev Walkind2ea1de2004-08-20 13:25:29 +00001526 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001527 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001528 ;
1529
Lev Walkinf59d0752004-08-18 04:59:12 +00001530SetOfConstraints:
1531 '(' ElementSetSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001532 $$ = $2;
1533 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001534 | SetOfConstraints '(' ElementSetSpecs ')' {
1535 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
1536 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001537 ;
1538
Lev Walkinf59d0752004-08-18 04:59:12 +00001539ElementSetSpecs:
1540 ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001541 $$ = $1;
1542 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001543 | ElementSetSpec ',' TOK_ThreeDots {
Lev Walkinf15320b2004-06-03 03:38:44 +00001544 asn1p_constraint_t *ct;
1545 ct = asn1p_constraint_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001546 ct->type = ACT_EL_EXT;
1547 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
1548 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001549 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001550 asn1p_constraint_t *ct;
1551 ct = asn1p_constraint_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001552 ct->type = ACT_EL_EXT;
1553 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinb4fcdd22004-08-13 12:35:09 +00001554 ct = $$;
1555 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
Lev Walkinf15320b2004-06-03 03:38:44 +00001556 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001557 ;
1558
Lev Walkinf59d0752004-08-18 04:59:12 +00001559ElementSetSpec:
1560 ConstraintSubtypeElement {
1561 $$ = $1;
1562 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001563 | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {
1564 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
1565 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001566 | ElementSetSpec Union ConstraintSubtypeElement {
Lev Walkinf15320b2004-06-03 03:38:44 +00001567 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
1568 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001569 | ElementSetSpec Intersection ConstraintSubtypeElement {
Lev Walkinf15320b2004-06-03 03:38:44 +00001570 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
1571 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001572 | ConstraintSubtypeElement Except ConstraintSubtypeElement {
Lev Walkinf15320b2004-06-03 03:38:44 +00001573 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
1574 }
1575 ;
1576
1577ConstraintSubtypeElement:
Lev Walkinf59d0752004-08-18 04:59:12 +00001578 ConstraintSpec '(' ElementSetSpecs ')' {
1579 int ret;
1580 $$ = asn1p_constraint_new(yylineno);
1581 checkmem($$);
1582 $$->type = $1;
1583 ret = asn1p_constraint_insert($$, $3);
1584 checkmem(ret == 0);
1585 }
1586 | '(' ElementSetSpecs ')' {
1587 int ret;
1588 $$ = asn1p_constraint_new(yylineno);
1589 checkmem($$);
1590 $$->type = ACT_CA_SET;
1591 ret = asn1p_constraint_insert($$, $2);
1592 checkmem(ret == 0);
1593 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001594 | SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001595 $$ = asn1p_constraint_new(yylineno);
1596 checkmem($$);
1597 $$->type = ACT_EL_VALUE;
1598 $$->value = $1;
1599 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001600 | ContainedSubtype {
1601 $$ = asn1p_constraint_new(yylineno);
1602 checkmem($$);
1603 $$->type = ACT_EL_TYPE;
1604 $$->containedSubtype = $1;
1605 }
1606 | SingleValue ConstraintRangeSpec SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001607 $$ = asn1p_constraint_new(yylineno);
1608 checkmem($$);
1609 $$->type = $2;
1610 $$->range_start = $1;
1611 $$->range_stop = $3;
1612 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001613 | TOK_MIN ConstraintRangeSpec SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001614 $$ = asn1p_constraint_new(yylineno);
1615 checkmem($$);
Lev Walkinf59d0752004-08-18 04:59:12 +00001616 $$->type = $2;
1617 $$->range_start = asn1p_value_fromint(-123);
1618 $$->range_stop = $3;
1619 $$->range_start->type = ATV_MIN;
1620 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001621 | SingleValue ConstraintRangeSpec TOK_MAX {
Lev Walkinf59d0752004-08-18 04:59:12 +00001622 $$ = asn1p_constraint_new(yylineno);
1623 checkmem($$);
1624 $$->type = $2;
1625 $$->range_start = $1;
1626 $$->range_stop = asn1p_value_fromint(321);
1627 $$->range_stop->type = ATV_MAX;
1628 }
1629 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1630 $$ = asn1p_constraint_new(yylineno);
1631 checkmem($$);
1632 $$->type = $2;
1633 $$->range_start = asn1p_value_fromint(-123);
1634 $$->range_stop = asn1p_value_fromint(321);
1635 $$->range_start->type = ATV_MIN;
1636 $$->range_stop->type = ATV_MAX;
Lev Walkinf15320b2004-06-03 03:38:44 +00001637 }
1638 | TableConstraint {
1639 $$ = $1;
1640 }
Lev Walkine596bf02005-03-28 15:01:27 +00001641 | InnerTypeConstraint {
Lev Walkinf15320b2004-06-03 03:38:44 +00001642 $$ = $1;
1643 }
Lev Walkin1893ddf2005-03-20 14:28:32 +00001644 | TOK_CONSTRAINED TOK_BY '{'
1645 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1646 $$ = asn1p_constraint_new(yylineno);
1647 checkmem($$);
1648 $$->type = ACT_CT_CTDBY;
1649 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
1650 checkmem($$->value);
1651 $$->value->type = ATV_UNPARSED;
1652 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001653 ;
1654
1655ConstraintRangeSpec:
1656 TOK_TwoDots { $$ = ACT_EL_RANGE; }
1657 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
1658 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
1659 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
1660 ;
1661
1662ConstraintSpec:
1663 TOK_SIZE {
1664 $$ = ACT_CT_SIZE;
1665 }
1666 | TOK_FROM {
1667 $$ = ACT_CT_FROM;
1668 }
1669 ;
1670
Lev Walkinff7dd142005-03-20 12:58:00 +00001671SingleValue:
Lev Walkinc8092cb2005-02-18 16:34:21 +00001672 TOK_FALSE {
1673 $$ = asn1p_value_fromint(0);
1674 checkmem($$);
1675 $$->type = ATV_FALSE;
1676 }
1677 | TOK_TRUE {
1678 $$ = asn1p_value_fromint(1);
1679 checkmem($$);
1680 $$->type = ATV_TRUE;
1681 }
1682 | SignedNumber {
Lev Walkinf15320b2004-06-03 03:38:44 +00001683 $$ = $1;
1684 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001685 | RestrictedCharacterStringValue {
1686 $$ = $1;
Lev Walkinc8092cb2005-02-18 16:34:21 +00001687 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001688 | Identifier {
1689 asn1p_ref_t *ref;
1690 int ret;
1691 ref = asn1p_ref_new(yylineno);
1692 checkmem(ref);
1693 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1694 checkmem(ret == 0);
1695 $$ = asn1p_value_fromref(ref, 0);
1696 checkmem($$);
1697 free($1);
1698 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001699 ;
1700
1701ContainedSubtype:
1702 TypeRefName {
Lev Walkinc8092cb2005-02-18 16:34:21 +00001703 asn1p_ref_t *ref;
1704 int ret;
1705 ref = asn1p_ref_new(yylineno);
1706 checkmem(ref);
1707 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1708 checkmem(ret == 0);
1709 $$ = asn1p_value_fromref(ref, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001710 checkmem($$);
Lev Walkinc8092cb2005-02-18 16:34:21 +00001711 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001712 }
1713 ;
1714
Lev Walkine596bf02005-03-28 15:01:27 +00001715InnerTypeConstraint:
1716 TOK_WITH TOK_COMPONENT SetOfConstraints {
1717 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
1718 }
1719 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001720 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
1721 }
1722 ;
1723
1724WithComponentsList:
1725 WithComponentsElement {
1726 $$ = $1;
1727 }
1728 | WithComponentsList ',' WithComponentsElement {
1729 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
1730 }
1731 ;
1732
1733WithComponentsElement:
1734 TOK_ThreeDots {
1735 $$ = asn1p_constraint_new(yylineno);
1736 checkmem($$);
1737 $$->type = ACT_EL_EXT;
Lev Walkine596bf02005-03-28 15:01:27 +00001738 $$->value = asn1p_value_frombuf("...", 3, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001739 }
1740 | Identifier optConstraints optPresenceConstraint {
1741 $$ = asn1p_constraint_new(yylineno);
1742 checkmem($$);
1743 $$->type = ACT_EL_VALUE;
1744 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1745 $$->presence = $3;
Lev Walkine596bf02005-03-28 15:01:27 +00001746 if($2) asn1p_constraint_insert($$, $2);
Lev Walkinf15320b2004-06-03 03:38:44 +00001747 }
1748 ;
1749
1750/*
1751 * presence constraint for WithComponents
1752 */
1753optPresenceConstraint:
1754 { $$ = ACPRES_DEFAULT; }
1755 | PresenceConstraint { $$ = $1; }
1756 ;
1757
1758PresenceConstraint:
1759 TOK_PRESENT {
1760 $$ = ACPRES_PRESENT;
1761 }
1762 | TOK_ABSENT {
1763 $$ = ACPRES_ABSENT;
1764 }
1765 | TOK_OPTIONAL {
1766 $$ = ACPRES_OPTIONAL;
1767 }
1768 ;
1769
1770TableConstraint:
1771 SimpleTableConstraint {
1772 $$ = $1;
1773 }
1774 | ComponentRelationConstraint {
1775 $$ = $1;
1776 }
1777 ;
1778
1779/*
1780 * "{ExtensionSet}"
1781 */
1782SimpleTableConstraint:
1783 '{' TypeRefName '}' {
1784 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
1785 asn1p_constraint_t *ct;
1786 int ret;
1787 ret = asn1p_ref_add_component(ref, $2, 0);
1788 checkmem(ret == 0);
1789 ct = asn1p_constraint_new(yylineno);
1790 checkmem($$);
1791 ct->type = ACT_EL_VALUE;
1792 ct->value = asn1p_value_fromref(ref, 0);
1793 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
1794 }
1795 ;
1796
1797ComponentRelationConstraint:
1798 SimpleTableConstraint '{' AtNotationList '}' {
1799 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
1800 }
1801 ;
1802
1803AtNotationList:
1804 AtNotationElement {
1805 $$ = asn1p_constraint_new(yylineno);
1806 checkmem($$);
1807 $$->type = ACT_EL_VALUE;
1808 $$->value = asn1p_value_fromref($1, 0);
1809 }
1810 | AtNotationList ',' AtNotationElement {
1811 asn1p_constraint_t *ct;
1812 ct = asn1p_constraint_new(yylineno);
1813 checkmem(ct);
1814 ct->type = ACT_EL_VALUE;
1815 ct->value = asn1p_value_fromref($3, 0);
1816 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
1817 }
1818 ;
1819
1820/*
1821 * @blah
1822 */
1823AtNotationElement:
1824 '@' ComponentIdList {
1825 char *p = malloc(strlen($2) + 2);
1826 int ret;
1827 *p = '@';
1828 strcpy(p + 1, $2);
1829 $$ = asn1p_ref_new(yylineno);
1830 ret = asn1p_ref_add_component($$, p, 0);
1831 checkmem(ret == 0);
1832 free(p);
1833 free($2);
1834 }
1835 | '@' '.' ComponentIdList {
1836 char *p = malloc(strlen($3) + 3);
1837 int ret;
1838 p[0] = '@';
1839 p[1] = '.';
1840 strcpy(p + 2, $3);
1841 $$ = asn1p_ref_new(yylineno);
1842 ret = asn1p_ref_add_component($$, p, 0);
1843 checkmem(ret == 0);
1844 free(p);
1845 free($3);
1846 }
1847 ;
1848
1849/* identifier "." ... */
1850ComponentIdList:
1851 Identifier {
1852 $$ = $1;
1853 }
1854 | ComponentIdList '.' Identifier {
1855 int l1 = strlen($1);
1856 int l3 = strlen($3);
1857 $$ = malloc(l1 + 1 + l3 + 1);
1858 memcpy($$, $1, l1);
1859 $$[l1] = '.';
1860 memcpy($$ + l1 + 1, $3, l3);
1861 $$[l1 + 1 + l3] = '\0';
1862 }
1863 ;
1864
1865
1866
1867/*
1868 * MARKERS
1869 */
1870
1871optMarker:
Lev Walkin9c974182004-09-15 11:59:51 +00001872 {
1873 $$.flags = EM_NOMARK;
1874 $$.default_value = 0;
1875 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001876 | Marker { $$ = $1; }
1877 ;
1878
1879Marker:
1880 TOK_OPTIONAL {
Lev Walkin9c974182004-09-15 11:59:51 +00001881 $$.flags = EM_OPTIONAL;
1882 $$.default_value = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +00001883 }
Lev Walkin9c974182004-09-15 11:59:51 +00001884 | TOK_DEFAULT Value {
1885 $$.flags = EM_DEFAULT;
1886 $$.default_value = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00001887 }
1888 ;
1889
1890/*
1891 * Universal enumeration definition to use in INTEGER and ENUMERATED.
1892 * === EXAMPLE ===
1893 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
1894 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
1895 * === EOF ===
1896 */
1897/*
1898optUniverationDefinition:
1899 { $$ = 0; }
1900 | UniverationDefinition {
1901 $$ = $1;
1902 }
1903 ;
1904*/
1905
1906UniverationDefinition:
1907 '{' '}' {
Lev Walkinceb20e72004-09-05 10:40:41 +00001908 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001909 checkmem($$);
1910 }
1911 | '{' UniverationList '}' {
1912 $$ = $2;
1913 }
1914 ;
1915
1916UniverationList:
1917 UniverationElement {
Lev Walkinceb20e72004-09-05 10:40:41 +00001918 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001919 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00001920 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001921 }
1922 | UniverationList ',' UniverationElement {
1923 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001924 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001925 }
1926 ;
1927
1928UniverationElement:
1929 Identifier {
Lev Walkinceb20e72004-09-05 10:40:41 +00001930 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001931 checkmem($$);
1932 $$->expr_type = A1TC_UNIVERVAL;
1933 $$->meta_type = AMT_VALUE;
1934 $$->Identifier = $1;
1935 }
1936 | Identifier '(' SignedNumber ')' {
Lev Walkinceb20e72004-09-05 10:40:41 +00001937 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001938 checkmem($$);
1939 $$->expr_type = A1TC_UNIVERVAL;
1940 $$->meta_type = AMT_VALUE;
1941 $$->Identifier = $1;
1942 $$->value = $3;
1943 }
1944 | Identifier '(' DefinedValue ')' {
Lev Walkinceb20e72004-09-05 10:40:41 +00001945 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001946 checkmem($$);
1947 $$->expr_type = A1TC_UNIVERVAL;
1948 $$->meta_type = AMT_VALUE;
1949 $$->Identifier = $1;
1950 $$->value = $3;
1951 }
1952 | SignedNumber {
Lev Walkinceb20e72004-09-05 10:40:41 +00001953 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001954 checkmem($$);
1955 $$->expr_type = A1TC_UNIVERVAL;
1956 $$->meta_type = AMT_VALUE;
1957 $$->value = $1;
1958 }
1959 | TOK_ThreeDots {
Lev Walkinceb20e72004-09-05 10:40:41 +00001960 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001961 checkmem($$);
1962 $$->Identifier = strdup("...");
1963 checkmem($$->Identifier);
1964 $$->expr_type = A1TC_EXTENSIBLE;
1965 $$->meta_type = AMT_VALUE;
1966 }
1967 ;
1968
1969SignedNumber:
1970 TOK_number {
1971 $$ = asn1p_value_fromint($1);
1972 checkmem($$);
1973 }
1974 | TOK_number_negative {
1975 $$ = asn1p_value_fromint($1);
1976 checkmem($$);
1977 }
1978 ;
1979
1980/*
1981 * SEQUENCE definition.
1982 * === EXAMPLE ===
1983 * Struct1 ::= SEQUENCE {
1984 * memb1 Struct2,
1985 * memb2 SEQUENCE OF {
1986 * memb2-1 Struct 3
1987 * }
1988 * }
1989 * === EOF ===
1990 */
1991
1992
1993
1994/*
1995 * SET definition.
1996 * === EXAMPLE ===
1997 * Person ::= SET {
1998 * name [0] PrintableString (SIZE(1..20)),
1999 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2000 * }
2001 * === EOF ===
2002 */
2003
2004optTag:
2005 { memset(&$$, 0, sizeof($$)); }
2006 | Tag { $$ = $1; }
2007 ;
2008
2009Tag:
Lev Walkinc603f102005-01-23 09:51:44 +00002010 TagTypeValue TagPlicit {
Lev Walkinf15320b2004-06-03 03:38:44 +00002011 $$ = $1;
Lev Walkinc603f102005-01-23 09:51:44 +00002012 $$.tag_mode = $2.tag_mode;
Lev Walkinf15320b2004-06-03 03:38:44 +00002013 }
Lev Walkinc603f102005-01-23 09:51:44 +00002014 ;
2015
2016TagTypeValue:
2017 '[' TagClass TOK_number ']' {
2018 $$ = $2;
2019 $$.tag_value = $3;
2020 };
2021
2022TagClass:
2023 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2024 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2025 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2026 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2027 ;
2028
2029TagPlicit:
2030 { $$.tag_mode = TM_DEFAULT; }
2031 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2032 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
Lev Walkinf15320b2004-06-03 03:38:44 +00002033 ;
2034
2035TypeRefName:
2036 TOK_typereference {
2037 checkmem($1);
2038 $$ = $1;
2039 }
Lev Walkinf59d0752004-08-18 04:59:12 +00002040 | TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002041 checkmem($1);
2042 $$ = $1;
2043 }
2044 ;
2045
Lev Walkinf59d0752004-08-18 04:59:12 +00002046
Lev Walkinf15320b2004-06-03 03:38:44 +00002047ObjectClassReference:
Lev Walkinf59d0752004-08-18 04:59:12 +00002048 TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002049 checkmem($1);
2050 $$ = $1;
2051 }
2052 ;
2053
Lev Walkin83cac2f2004-09-22 16:03:36 +00002054optIdentifier:
2055 { $$ = 0; }
2056 | Identifier {
2057 $$ = $1;
2058 }
2059
Lev Walkinf15320b2004-06-03 03:38:44 +00002060Identifier:
2061 TOK_identifier {
2062 checkmem($1);
2063 $$ = $1;
2064 }
2065 ;
2066
Lev Walkinf15320b2004-06-03 03:38:44 +00002067%%
2068
2069
2070/*
2071 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2072 */
2073static asn1p_value_t *
2074_convert_bitstring2binary(char *str, int base) {
2075 asn1p_value_t *val;
2076 int slen;
2077 int memlen;
2078 int baselen;
2079 int bits;
2080 uint8_t *binary_vector;
2081 uint8_t *bv_ptr;
2082 uint8_t cur_val;
2083
2084 assert(str);
2085 assert(str[0] == '\'');
2086
2087 switch(base) {
2088 case 'B':
2089 baselen = 1;
2090 break;
2091 case 'H':
2092 baselen = 4;
2093 break;
2094 default:
2095 assert(base == 'B' || base == 'H');
2096 errno = EINVAL;
2097 return NULL;
2098 }
2099
2100 slen = strlen(str);
2101 assert(str[slen - 1] == base);
2102 assert(str[slen - 2] == '\'');
2103
2104 memlen = slen / (8 / baselen); /* Conservative estimate */
2105
2106 bv_ptr = binary_vector = malloc(memlen + 1);
2107 if(bv_ptr == NULL)
2108 /* ENOMEM */
2109 return NULL;
2110
2111 cur_val = 0;
2112 bits = 0;
2113 while(*(++str) != '\'') {
2114 switch(baselen) {
2115 case 1:
2116 switch(*str) {
2117 case '1':
2118 cur_val |= 1 << (7 - (bits % 8));
2119 case '0':
2120 break;
2121 default:
2122 assert(!"_y UNREACH1");
2123 case ' ': case '\r': case '\n':
2124 continue;
2125 }
2126 break;
2127 case 4:
2128 switch(*str) {
2129 case '0': case '1': case '2': case '3': case '4':
2130 case '5': case '6': case '7': case '8': case '9':
2131 cur_val |= (*str - '0') << (4 - (bits % 8));
2132 break;
2133 case 'A': case 'B': case 'C':
2134 case 'D': case 'E': case 'F':
2135 cur_val |= ((*str - 'A') + 10)
2136 << (4 - (bits % 8));
2137 break;
2138 default:
2139 assert(!"_y UNREACH2");
2140 case ' ': case '\r': case '\n':
2141 continue;
2142 }
2143 break;
2144 }
2145
2146 bits += baselen;
2147 if((bits % 8) == 0) {
2148 *bv_ptr++ = cur_val;
2149 cur_val = 0;
2150 }
2151 }
2152
2153 *bv_ptr = cur_val;
2154 assert((bv_ptr - binary_vector) <= memlen);
2155
2156 val = asn1p_value_frombits(binary_vector, bits, 0);
2157 if(val == NULL) {
2158 free(binary_vector);
2159 }
2160
2161 return val;
2162}
2163
2164extern char *asn1p_text;
2165
2166int
2167yyerror(const char *msg) {
2168 fprintf(stderr,
2169 "ASN.1 grammar parse error "
2170 "near line %d (token \"%s\"): %s\n",
Lev Walkinceb20e72004-09-05 10:40:41 +00002171 yylineno, asn1p_text, msg);
Lev Walkinf15320b2004-06-03 03:38:44 +00002172 return -1;
2173}
2174
2175