blob: 8c714f1a8bab051f8569fe635c0946f299b2bba6 [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
Lev Walkin4354b442005-06-07 21:25:42 +000012#define YYPARSE_PARAM_TYPE void **
Lev Walkinf15320b2004-06-03 03:38:44 +000013#define YYERROR_VERBOSE
14
15int yylex(void);
16int yyerror(const char *msg);
Lev Walkin8daab912005-06-07 21:32:16 +000017#ifdef YYBYACC
18int yyparse(void **param); /* byacc does not produce a prototype */
19#endif
Lev Walkinf15320b2004-06-03 03:38:44 +000020void asn1p_lexer_hack_push_opaque_state(void);
21void asn1p_lexer_hack_enable_with_syntax(void);
Lev Walkinf59d0752004-08-18 04:59:12 +000022void asn1p_lexer_hack_push_encoding_control(void);
Lev Walkinf15320b2004-06-03 03:38:44 +000023#define yylineno asn1p_lineno
24extern int asn1p_lineno;
25
26
27static asn1p_value_t *
28 _convert_bitstring2binary(char *str, int base);
29
Lev Walkin1004aa92004-09-08 00:28:11 +000030#define checkmem(ptr) do { \
31 if(!(ptr)) \
32 return yyerror("Memory failure"); \
Lev Walkinf15320b2004-06-03 03:38:44 +000033 } while(0)
34
35#define CONSTRAINT_INSERT(root, constr_type, arg1, arg2) do { \
36 if(arg1->type != constr_type) { \
37 int __ret; \
38 root = asn1p_constraint_new(yylineno); \
39 checkmem(root); \
40 root->type = constr_type; \
41 __ret = asn1p_constraint_insert(root, \
42 arg1); \
43 checkmem(__ret == 0); \
44 } else { \
45 root = arg1; \
46 } \
47 if(arg2) { \
48 int __ret \
49 = asn1p_constraint_insert(root, arg2); \
50 checkmem(__ret == 0); \
51 } \
52 } while(0)
53
54%}
55
56
57/*
58 * Token value definition.
59 * a_*: ASN-specific types.
60 * tv_*: Locally meaningful types.
61 */
62%union {
63 asn1p_t *a_grammar;
64 asn1p_module_flags_e a_module_flags;
65 asn1p_module_t *a_module;
66 asn1p_expr_type_e a_type; /* ASN.1 Type */
67 asn1p_expr_t *a_expr; /* Constructed collection */
68 asn1p_constraint_t *a_constr; /* Constraint */
69 enum asn1p_constraint_type_e a_ctype;/* Constraint type */
70 asn1p_xports_t *a_xports; /* IMports/EXports */
71 asn1p_oid_t *a_oid; /* Object Identifier */
72 asn1p_oid_arc_t a_oid_arc; /* Single OID's arc */
73 struct asn1p_type_tag_s a_tag; /* A tag */
74 asn1p_ref_t *a_ref; /* Reference to custom type */
75 asn1p_wsyntx_t *a_wsynt; /* WITH SYNTAX contents */
76 asn1p_wsyntx_chunk_t *a_wchunk; /* WITH SYNTAX chunk */
77 struct asn1p_ref_component_s a_refcomp; /* Component of a reference */
78 asn1p_value_t *a_value; /* Number, DefinedValue, etc */
79 struct asn1p_param_s a_parg; /* A parameter argument */
80 asn1p_paramlist_t *a_plist; /* A pargs list */
Lev Walkin9c974182004-09-15 11:59:51 +000081 struct asn1p_expr_marker_s a_marker; /* OPTIONAL/DEFAULT */
Lev Walkinf15320b2004-06-03 03:38:44 +000082 enum asn1p_constr_pres_e a_pres; /* PRESENT/ABSENT/OPTIONAL */
Lev Walkin144db9b2004-10-12 23:26:53 +000083 asn1c_integer_t a_int;
Lev Walkinf15320b2004-06-03 03:38:44 +000084 char *tv_str;
85 struct {
86 char *buf;
87 int len;
88 } tv_opaque;
89 struct {
90 char *name;
91 struct asn1p_type_tag_s tag;
92 } tv_nametag;
93};
94
95/*
96 * Token types returned by scanner.
97 */
98%token TOK_PPEQ /* "::=", Pseudo Pascal EQuality */
99%token <tv_opaque> TOK_opaque /* opaque data (driven from .y) */
100%token <tv_str> TOK_bstring
101%token <tv_opaque> TOK_cstring
102%token <tv_str> TOK_hstring
103%token <tv_str> TOK_identifier
104%token <a_int> TOK_number
Lev Walkind9574ae2005-03-24 16:22:35 +0000105%token <a_int> TOK_tuple
106%token <a_int> TOK_quadruple
Lev Walkinf15320b2004-06-03 03:38:44 +0000107%token <a_int> TOK_number_negative
108%token <tv_str> TOK_typereference
Lev Walkinf59d0752004-08-18 04:59:12 +0000109%token <tv_str> TOK_capitalreference /* "CLASS1" */
Lev Walkinf15320b2004-06-03 03:38:44 +0000110%token <tv_str> TOK_typefieldreference /* "&Pork" */
111%token <tv_str> TOK_valuefieldreference /* "&id" */
112
113/*
114 * Token types representing ASN.1 standard keywords.
115 */
116%token TOK_ABSENT
117%token TOK_ABSTRACT_SYNTAX
118%token TOK_ALL
119%token TOK_ANY
120%token TOK_APPLICATION
121%token TOK_AUTOMATIC
122%token TOK_BEGIN
123%token TOK_BIT
124%token TOK_BMPString
125%token TOK_BOOLEAN
126%token TOK_BY
127%token TOK_CHARACTER
128%token TOK_CHOICE
129%token TOK_CLASS
130%token TOK_COMPONENT
131%token TOK_COMPONENTS
132%token TOK_CONSTRAINED
133%token TOK_CONTAINING
134%token TOK_DEFAULT
135%token TOK_DEFINITIONS
136%token TOK_DEFINED
137%token TOK_EMBEDDED
138%token TOK_ENCODED
Lev Walkinf59d0752004-08-18 04:59:12 +0000139%token TOK_ENCODING_CONTROL
Lev Walkinf15320b2004-06-03 03:38:44 +0000140%token TOK_END
141%token TOK_ENUMERATED
142%token TOK_EXPLICIT
143%token TOK_EXPORTS
144%token TOK_EXTENSIBILITY
145%token TOK_EXTERNAL
146%token TOK_FALSE
147%token TOK_FROM
148%token TOK_GeneralizedTime
149%token TOK_GeneralString
150%token TOK_GraphicString
151%token TOK_IA5String
152%token TOK_IDENTIFIER
153%token TOK_IMPLICIT
154%token TOK_IMPLIED
155%token TOK_IMPORTS
156%token TOK_INCLUDES
157%token TOK_INSTANCE
Lev Walkinf59d0752004-08-18 04:59:12 +0000158%token TOK_INSTRUCTIONS
Lev Walkinf15320b2004-06-03 03:38:44 +0000159%token TOK_INTEGER
160%token TOK_ISO646String
161%token TOK_MAX
162%token TOK_MIN
163%token TOK_MINUS_INFINITY
164%token TOK_NULL
165%token TOK_NumericString
166%token TOK_OBJECT
167%token TOK_ObjectDescriptor
168%token TOK_OCTET
169%token TOK_OF
170%token TOK_OPTIONAL
171%token TOK_PATTERN
172%token TOK_PDV
173%token TOK_PLUS_INFINITY
174%token TOK_PRESENT
175%token TOK_PrintableString
176%token TOK_PRIVATE
177%token TOK_REAL
178%token TOK_RELATIVE_OID
179%token TOK_SEQUENCE
180%token TOK_SET
181%token TOK_SIZE
182%token TOK_STRING
183%token TOK_SYNTAX
184%token TOK_T61String
185%token TOK_TAGS
186%token TOK_TeletexString
187%token TOK_TRUE
188%token TOK_TYPE_IDENTIFIER
189%token TOK_UNIQUE
190%token TOK_UNIVERSAL
191%token TOK_UniversalString
192%token TOK_UTCTime
193%token TOK_UTF8String
194%token TOK_VideotexString
195%token TOK_VisibleString
196%token TOK_WITH
197
Lev Walkinf15320b2004-06-03 03:38:44 +0000198%left TOK_EXCEPT
Lev Walkinf59d0752004-08-18 04:59:12 +0000199%left '^' TOK_INTERSECTION
200%left '|' TOK_UNION
Lev Walkinf15320b2004-06-03 03:38:44 +0000201
202/* Misc tags */
203%token TOK_TwoDots /* .. */
204%token TOK_ThreeDots /* ... */
Lev Walkinf15320b2004-06-03 03:38:44 +0000205
206
207/*
208 * Types defined herein.
209 */
210%type <a_grammar> ModuleList
211%type <a_module> ModuleSpecification
212%type <a_module> ModuleSpecificationBody
213%type <a_module> ModuleSpecificationElement
214%type <a_module> optModuleSpecificationBody /* Optional */
215%type <a_module_flags> optModuleSpecificationFlags
216%type <a_module_flags> ModuleSpecificationFlags /* Set of FL */
217%type <a_module_flags> ModuleSpecificationFlag /* Single FL */
218%type <a_module> ImportsDefinition
219%type <a_module> ImportsBundleSet
220%type <a_xports> ImportsBundle
221%type <a_xports> ImportsList
222%type <a_xports> ExportsDefinition
223%type <a_xports> ExportsBody
224%type <a_expr> ImportsElement
225%type <a_expr> ExportsElement
Lev Walkinf15320b2004-06-03 03:38:44 +0000226%type <a_expr> ExtensionAndException
Lev Walkin070a52d2004-08-22 03:19:54 +0000227%type <a_expr> TypeDeclaration
Lev Walkinf15320b2004-06-03 03:38:44 +0000228%type <a_ref> ComplexTypeReference
229%type <a_ref> ComplexTypeReferenceAmpList
230%type <a_refcomp> ComplexTypeReferenceElement
231%type <a_refcomp> ClassFieldIdentifier
232%type <a_refcomp> ClassFieldName
233%type <a_expr> ClassFieldList
234%type <a_expr> ClassField
235%type <a_expr> ClassDeclaration
Lev Walkin070a52d2004-08-22 03:19:54 +0000236%type <a_expr> Type
Lev Walkinf15320b2004-06-03 03:38:44 +0000237%type <a_expr> DataTypeReference /* Type1 ::= Type2 */
238%type <a_expr> DefinedTypeRef
239%type <a_expr> ValueSetDefinition /* Val INTEGER ::= {1|2} */
240%type <a_expr> ValueDefinition /* val INTEGER ::= 1*/
Lev Walkin9c974182004-09-15 11:59:51 +0000241%type <a_value> Value
Lev Walkinf15320b2004-06-03 03:38:44 +0000242%type <a_value> DefinedValue
243%type <a_value> SignedNumber
Lev Walkin144db9b2004-10-12 23:26:53 +0000244%type <a_expr> optComponentTypeLists
Lev Walkin070a52d2004-08-22 03:19:54 +0000245%type <a_expr> ComponentTypeLists
246%type <a_expr> ComponentType
247%type <a_expr> AlternativeTypeLists
248%type <a_expr> AlternativeType
Lev Walkinf15320b2004-06-03 03:38:44 +0000249//%type <a_expr> optUniverationDefinition
250%type <a_expr> UniverationDefinition
251%type <a_expr> UniverationList
252%type <a_expr> UniverationElement
253%type <tv_str> TypeRefName
254%type <tv_str> ObjectClassReference
Lev Walkinf15320b2004-06-03 03:38:44 +0000255%type <tv_str> Identifier
Lev Walkin83cac2f2004-09-22 16:03:36 +0000256%type <tv_str> optIdentifier
Lev Walkinf15320b2004-06-03 03:38:44 +0000257%type <a_parg> ParameterArgumentName
258%type <a_plist> ParameterArgumentList
259%type <a_expr> ActualParameter
260%type <a_expr> ActualParameterList
261%type <a_oid> ObjectIdentifier /* OID */
262%type <a_oid> optObjectIdentifier /* Optional OID */
263%type <a_oid> ObjectIdentifierBody
264%type <a_oid_arc> ObjectIdentifierElement
265%type <a_expr> BasicType
266%type <a_type> BasicTypeId
267%type <a_type> BasicTypeId_UniverationCompatible
268%type <a_type> BasicString
269%type <tv_opaque> Opaque
270//%type <tv_opaque> StringValue
Lev Walkinc603f102005-01-23 09:51:44 +0000271%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
272%type <a_tag> TagClass TagTypeValue TagPlicit
Lev Walkinf15320b2004-06-03 03:38:44 +0000273%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
274%type <a_constr> optConstraints
Lev Walkind2ea1de2004-08-20 13:25:29 +0000275%type <a_constr> Constraints
Lev Walkinf59d0752004-08-18 04:59:12 +0000276%type <a_constr> SetOfConstraints
277%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
278%type <a_constr> ElementSetSpec /* 1..2,...,3 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000279%type <a_constr> ConstraintSubtypeElement /* 1..2 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000280%type <a_constr> SimpleTableConstraint
281%type <a_constr> TableConstraint
Lev Walkine596bf02005-03-28 15:01:27 +0000282%type <a_constr> InnerTypeConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +0000283%type <a_constr> WithComponentsList
284%type <a_constr> WithComponentsElement
285%type <a_constr> ComponentRelationConstraint
286%type <a_constr> AtNotationList
287%type <a_ref> AtNotationElement
Lev Walkinff7dd142005-03-20 12:58:00 +0000288%type <a_value> SingleValue
289%type <a_value> ContainedSubtype
Lev Walkinf15320b2004-06-03 03:38:44 +0000290%type <a_ctype> ConstraintSpec
291%type <a_ctype> ConstraintRangeSpec
Lev Walkin1e448d32005-03-24 14:26:38 +0000292%type <a_value> RestrictedCharacterStringValue
Lev Walkinf15320b2004-06-03 03:38:44 +0000293%type <a_wsynt> optWithSyntax
294%type <a_wsynt> WithSyntax
295%type <a_wsynt> WithSyntaxFormat
296%type <a_wchunk> WithSyntaxFormatToken
297%type <a_marker> optMarker Marker
298%type <a_int> optUnique
299%type <a_pres> optPresenceConstraint PresenceConstraint
300%type <tv_str> ComponentIdList
301
302
303%%
304
305
306ParsedGrammar:
307 ModuleList {
308 *(void **)param = $1;
309 }
310 ;
311
312ModuleList:
313 ModuleSpecification {
314 $$ = asn1p_new();
315 checkmem($$);
316 TQ_ADD(&($$->modules), $1, mod_next);
317 }
318 | ModuleList ModuleSpecification {
319 $$ = $1;
320 TQ_ADD(&($$->modules), $2, mod_next);
321 }
322 ;
323
324/*
325 * ASN module definition.
326 * === EXAMPLE ===
327 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
328 * BEGIN
329 * ...
330 * END
331 * === EOF ===
332 */
333
334ModuleSpecification:
335 TypeRefName optObjectIdentifier TOK_DEFINITIONS
336 optModuleSpecificationFlags
337 TOK_PPEQ TOK_BEGIN
338 optModuleSpecificationBody
339 TOK_END {
340
341 if($7) {
342 $$ = $7;
343 } else {
344 /* There's a chance that a module is just plain empty */
345 $$ = asn1p_module_new();
346 }
347 checkmem($$);
348
349 $$->Identifier = $1;
350 $$->module_oid = $2;
351 $$->module_flags = $4;
352 }
353 ;
354
355/*
356 * Object Identifier Definition
357 * { iso member-body(2) 3 }
358 */
359optObjectIdentifier:
360 { $$ = 0; }
361 | ObjectIdentifier { $$ = $1; }
362 ;
363
364ObjectIdentifier:
365 '{' ObjectIdentifierBody '}' {
366 $$ = $2;
367 }
368 | '{' '}' {
369 $$ = 0;
370 }
371 ;
372
373ObjectIdentifierBody:
374 ObjectIdentifierElement {
375 $$ = asn1p_oid_new();
376 asn1p_oid_add_arc($$, &$1);
377 if($1.name)
378 free($1.name);
379 }
380 | ObjectIdentifierBody ObjectIdentifierElement {
381 $$ = $1;
382 asn1p_oid_add_arc($$, &$2);
383 if($2.name)
384 free($2.name);
385 }
386 ;
387
388ObjectIdentifierElement:
389 Identifier { /* iso */
390 $$.name = $1;
391 $$.number = -1;
392 }
393 | Identifier '(' TOK_number ')' { /* iso(1) */
394 $$.name = $1;
395 $$.number = $3;
396 }
397 | TOK_number { /* 1 */
398 $$.name = 0;
399 $$.number = $1;
400 }
401 ;
402
403/*
404 * Optional module flags.
405 */
406optModuleSpecificationFlags:
407 { $$ = MSF_NOFLAGS; }
408 | ModuleSpecificationFlags {
409 $$ = $1;
410 }
411 ;
412
413/*
414 * Module flags.
415 */
416ModuleSpecificationFlags:
417 ModuleSpecificationFlag {
418 $$ = $1;
419 }
420 | ModuleSpecificationFlags ModuleSpecificationFlag {
421 $$ = $1 | $2;
422 }
423 ;
424
425/*
426 * Single module flag.
427 */
428ModuleSpecificationFlag:
429 TOK_EXPLICIT TOK_TAGS {
430 $$ = MSF_EXPLICIT_TAGS;
431 }
432 | TOK_IMPLICIT TOK_TAGS {
433 $$ = MSF_IMPLICIT_TAGS;
434 }
435 | TOK_AUTOMATIC TOK_TAGS {
436 $$ = MSF_AUTOMATIC_TAGS;
437 }
438 | TOK_EXTENSIBILITY TOK_IMPLIED {
439 $$ = MSF_EXTENSIBILITY_IMPLIED;
440 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000441 /* EncodingReferenceDefault */
442 | TOK_capitalreference TOK_INSTRUCTIONS {
443 /* X.680Amd1 specifies TAG and XER */
444 if(strcmp($1, "TAG") == 0) {
445 $$ = MSF_TAG_INSTRUCTIONS;
446 } else if(strcmp($1, "XER") == 0) {
447 $$ = MSF_XER_INSTRUCTIONS;
448 } else {
449 fprintf(stderr,
450 "WARNING: %s INSTRUCTIONS at line %d: "
451 "Unrecognized encoding reference\n",
452 $1, yylineno);
453 $$ = MSF_unk_INSTRUCTIONS;
454 }
455 free($1);
456 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000457 ;
458
459/*
460 * Optional module body.
461 */
462optModuleSpecificationBody:
463 { $$ = 0; }
464 | ModuleSpecificationBody {
Lev Walkinf15320b2004-06-03 03:38:44 +0000465 $$ = $1;
466 }
467 ;
468
469/*
470 * ASN.1 Module body.
471 */
472ModuleSpecificationBody:
473 ModuleSpecificationElement {
474 $$ = $1;
475 }
476 | ModuleSpecificationBody ModuleSpecificationElement {
477 $$ = $1;
478
Lev Walkinf59d0752004-08-18 04:59:12 +0000479 /* Behave well when one of them is skipped. */
480 if(!($1)) {
481 if($2) $$ = $2;
482 break;
483 }
484
Lev Walkinf15320b2004-06-03 03:38:44 +0000485#ifdef MY_IMPORT
486#error MY_IMPORT DEFINED ELSEWHERE!
487#endif
488#define MY_IMPORT(foo,field) do { \
Lev Walkinbc55d232004-08-13 12:31:09 +0000489 while(TQ_FIRST(&($2->foo))) { \
Lev Walkinf15320b2004-06-03 03:38:44 +0000490 TQ_ADD(&($$->foo), \
491 TQ_REMOVE(&($2->foo), field), \
492 field); \
Lev Walkinbc55d232004-08-13 12:31:09 +0000493 } \
494 assert(TQ_FIRST(&($2->foo)) == 0); \
495 } while(0)
Lev Walkinf15320b2004-06-03 03:38:44 +0000496
497 MY_IMPORT(imports, xp_next);
498 MY_IMPORT(exports, xp_next);
499 MY_IMPORT(members, next);
500#undef MY_IMPORT
501
502 }
503 ;
504
505/*
506 * One of the elements of ASN.1 module specification.
507 */
508ModuleSpecificationElement:
509 ImportsDefinition {
510 $$ = $1;
511 }
512 | ExportsDefinition {
513 $$ = asn1p_module_new();
514 checkmem($$);
515 if($1) {
516 TQ_ADD(&($$->exports), $1, xp_next);
517 } else {
518 /* "EXPORTS ALL;" ? */
519 }
520 }
521 | DataTypeReference {
522 $$ = asn1p_module_new();
523 checkmem($$);
524 assert($1->expr_type != A1TC_INVALID);
525 assert($1->meta_type != AMT_INVALID);
526 TQ_ADD(&($$->members), $1, next);
527 }
528 | ValueDefinition {
529 $$ = asn1p_module_new();
530 checkmem($$);
531 assert($1->expr_type != A1TC_INVALID);
532 assert($1->meta_type != AMT_INVALID);
533 TQ_ADD(&($$->members), $1, next);
534 }
535 /*
536 * Value set definition
537 * === EXAMPLE ===
538 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
539 * === EOF ===
540 */
541 | ValueSetDefinition {
542 $$ = asn1p_module_new();
543 checkmem($$);
544 assert($1->expr_type != A1TC_INVALID);
545 assert($1->meta_type != AMT_INVALID);
546 TQ_ADD(&($$->members), $1, next);
547 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000548 | TOK_ENCODING_CONTROL TOK_capitalreference
549 { asn1p_lexer_hack_push_encoding_control(); }
550 {
551 fprintf(stderr,
552 "WARNING: ENCODING-CONTROL %s "
553 "specification at line %d ignored\n",
554 $2, yylineno);
555 free($2);
556 $$ = 0;
557 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000558
559 /*
560 * Erroneous attemps
561 */
562 | BasicString {
563 return yyerror(
564 "Attempt to redefine a standard basic type, "
565 "use -ftypesXY to switch back "
566 "to older version of ASN.1 standard");
567 }
568 ;
569
570/*
571 * === EXAMPLE ===
572 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
573 * === EOF ===
574 */
575ImportsDefinition:
576 TOK_IMPORTS ImportsBundleSet ';' {
577 $$ = $2;
578 }
579 /*
580 * Some error cases.
581 */
582 | TOK_IMPORTS TOK_FROM /* ... */ {
583 return yyerror("Empty IMPORTS list");
584 }
585 ;
586
587ImportsBundleSet:
588 ImportsBundle {
589 $$ = asn1p_module_new();
590 checkmem($$);
591 TQ_ADD(&($$->imports), $1, xp_next);
592 }
593 | ImportsBundleSet ImportsBundle {
594 $$ = $1;
595 TQ_ADD(&($$->imports), $2, xp_next);
596 }
597 ;
598
599ImportsBundle:
600 ImportsList TOK_FROM TypeRefName optObjectIdentifier {
601 $$ = $1;
602 $$->from = $3;
603 $$->from_oid = $4;
604 checkmem($$);
605 }
606 ;
607
608ImportsList:
609 ImportsElement {
610 $$ = asn1p_xports_new();
611 checkmem($$);
612 TQ_ADD(&($$->members), $1, next);
613 }
614 | ImportsList ',' ImportsElement {
615 $$ = $1;
616 TQ_ADD(&($$->members), $3, next);
617 }
618 ;
619
620ImportsElement:
621 TypeRefName {
622 $$ = asn1p_expr_new(yylineno);
623 checkmem($$);
624 $$->Identifier = $1;
625 $$->expr_type = A1TC_REFERENCE;
626 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000627 | TypeRefName '{' '}' { /* Completely equivalent to above */
628 $$ = asn1p_expr_new(yylineno);
629 checkmem($$);
630 $$->Identifier = $1;
631 $$->expr_type = A1TC_REFERENCE;
632 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000633 | Identifier {
634 $$ = asn1p_expr_new(yylineno);
635 checkmem($$);
636 $$->Identifier = $1;
637 $$->expr_type = A1TC_REFERENCE;
638 }
639 ;
640
641ExportsDefinition:
642 TOK_EXPORTS ExportsBody ';' {
643 $$ = $2;
644 }
645 | TOK_EXPORTS TOK_ALL ';' {
646 $$ = 0;
647 }
648 | TOK_EXPORTS ';' {
649 /* Empty EXPORTS clause effectively prohibits export. */
650 $$ = asn1p_xports_new();
651 checkmem($$);
652 }
653 ;
654
655ExportsBody:
656 ExportsElement {
657 $$ = asn1p_xports_new();
658 assert($$);
659 TQ_ADD(&($$->members), $1, next);
660 }
661 | ExportsBody ',' ExportsElement {
662 $$ = $1;
663 TQ_ADD(&($$->members), $3, next);
664 }
665 ;
666
667ExportsElement:
668 TypeRefName {
669 $$ = asn1p_expr_new(yylineno);
670 checkmem($$);
671 $$->Identifier = $1;
672 $$->expr_type = A1TC_EXPORTVAR;
673 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000674 | TypeRefName '{' '}' {
675 $$ = asn1p_expr_new(yylineno);
676 checkmem($$);
677 $$->Identifier = $1;
678 $$->expr_type = A1TC_EXPORTVAR;
679 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000680 | Identifier {
681 $$ = asn1p_expr_new(yylineno);
682 checkmem($$);
683 $$->Identifier = $1;
684 $$->expr_type = A1TC_EXPORTVAR;
685 }
686 ;
687
688
689ValueSetDefinition:
Lev Walkin8ea99482005-03-31 21:48:13 +0000690 TypeRefName DefinedTypeRef TOK_PPEQ
691 '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Lev Walkinf15320b2004-06-03 03:38:44 +0000692 $$ = $2;
693 assert($$->Identifier == 0);
694 $$->Identifier = $1;
695 $$->meta_type = AMT_VALUESET;
Lev Walkin8ea99482005-03-31 21:48:13 +0000696 // take care of ValueSet body
Lev Walkinf15320b2004-06-03 03:38:44 +0000697 }
698 ;
699
700DefinedTypeRef:
701 ComplexTypeReference {
702 $$ = asn1p_expr_new(yylineno);
703 checkmem($$);
704 $$->reference = $1;
705 $$->expr_type = A1TC_REFERENCE;
706 $$->meta_type = AMT_TYPEREF;
707 }
708 | BasicTypeId {
709 $$ = asn1p_expr_new(yylineno);
710 checkmem($$);
711 $$->expr_type = $1;
712 $$->meta_type = AMT_TYPE;
713 }
714 ;
715
Lev Walkinf15320b2004-06-03 03:38:44 +0000716/*
717 * Data Type Reference.
718 * === EXAMPLE ===
719 * Type3 ::= CHOICE { a Type1, b Type 2 }
720 * === EOF ===
721 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000722DataTypeReference:
723 /*
724 * Optionally tagged type definition.
725 */
726 TypeRefName TOK_PPEQ optTag TOK_TYPE_IDENTIFIER {
727 $$ = asn1p_expr_new(yylineno);
728 checkmem($$);
729 $$->Identifier = $1;
730 $$->tag = $3;
731 $$->expr_type = A1TC_TYPEID;
732 $$->meta_type = AMT_TYPE;
733 }
Lev Walkinaf120f72004-09-14 02:36:39 +0000734 | TypeRefName TOK_PPEQ Type {
735 $$ = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000736 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000737 assert($$->expr_type);
738 assert($$->meta_type);
739 }
740 | TypeRefName TOK_PPEQ ClassDeclaration {
741 $$ = $3;
742 $$->Identifier = $1;
743 assert($$->expr_type == A1TC_CLASSDEF);
744 assert($$->meta_type == AMT_OBJECT);
745 }
746 /*
747 * Parametrized <Type> declaration:
748 * === EXAMPLE ===
749 * SIGNED { ToBeSigned } ::= SEQUENCE {
750 * toBeSigned ToBeSigned,
751 * algorithm AlgorithmIdentifier,
752 * signature BIT STRING
753 * }
754 * === EOF ===
755 */
Lev Walkin070a52d2004-08-22 03:19:54 +0000756 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000757 $$ = $6;
758 assert($$->Identifier == 0);
759 $$->Identifier = $1;
760 $$->params = $3;
761 $$->meta_type = AMT_PARAMTYPE;
762 }
763 ;
764
765ParameterArgumentList:
766 ParameterArgumentName {
767 int ret;
768 $$ = asn1p_paramlist_new(yylineno);
769 checkmem($$);
770 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
771 checkmem(ret == 0);
772 if($1.governor) asn1p_ref_free($1.governor);
773 if($1.argument) free($1.argument);
774 }
775 | ParameterArgumentList ',' ParameterArgumentName {
776 int ret;
777 $$ = $1;
778 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
779 checkmem(ret == 0);
780 if($3.governor) asn1p_ref_free($3.governor);
781 if($3.argument) free($3.argument);
782 }
783 ;
784
785ParameterArgumentName:
786 TypeRefName {
787 $$.governor = NULL;
788 $$.argument = $1;
789 }
790 | TypeRefName ':' Identifier {
791 int ret;
792 $$.governor = asn1p_ref_new(yylineno);
793 ret = asn1p_ref_add_component($$.governor, $1, 0);
794 checkmem(ret == 0);
795 $$.argument = $3;
796 }
Lev Walkinc8092cb2005-02-18 16:34:21 +0000797 | TypeRefName ':' TypeRefName {
798 int ret;
799 $$.governor = asn1p_ref_new(yylineno);
800 ret = asn1p_ref_add_component($$.governor, $1, 0);
801 checkmem(ret == 0);
802 $$.argument = $3;
803 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000804 | BasicTypeId ':' Identifier {
805 int ret;
806 $$.governor = asn1p_ref_new(yylineno);
807 ret = asn1p_ref_add_component($$.governor,
808 ASN_EXPR_TYPE2STR($1), 1);
809 checkmem(ret == 0);
810 $$.argument = $3;
811 }
812 ;
813
814ActualParameterList:
815 ActualParameter {
816 $$ = asn1p_expr_new(yylineno);
817 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000818 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000819 }
820 | ActualParameterList ',' ActualParameter {
821 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000822 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000823 }
824 ;
825
826ActualParameter:
Lev Walkin070a52d2004-08-22 03:19:54 +0000827 Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000828 $$ = $1;
829 }
830 | Identifier {
831 $$ = asn1p_expr_new(yylineno);
832 checkmem($$);
833 $$->Identifier = $1;
834 $$->expr_type = A1TC_REFERENCE;
835 $$->meta_type = AMT_VALUE;
836 }
837 ;
838
839/*
Lev Walkinc8092cb2005-02-18 16:34:21 +0000840 | '{' ActualParameter '}' {
841 $$ = asn1p_expr_new(yylineno);
842 checkmem($$);
843 asn1p_expr_add($$, $2);
844 $$->expr_type = A1TC_PARAMETRIZED;
845 $$->meta_type = AMT_TYPE;
846 }
847 ;
848*/
849
850/*
Lev Walkinf15320b2004-06-03 03:38:44 +0000851 * A collection of constructed data type members.
852 */
Lev Walkin144db9b2004-10-12 23:26:53 +0000853optComponentTypeLists:
854 { $$ = asn1p_expr_new(yylineno); }
855 | ComponentTypeLists { $$ = $1; };
856
Lev Walkin070a52d2004-08-22 03:19:54 +0000857ComponentTypeLists:
858 ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +0000859 $$ = asn1p_expr_new(yylineno);
860 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000861 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000862 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000863 | ComponentTypeLists ',' ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +0000864 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000865 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000866 }
867 ;
868
Lev Walkin070a52d2004-08-22 03:19:54 +0000869ComponentType:
Lev Walkinaf120f72004-09-14 02:36:39 +0000870 Identifier Type optMarker {
Lev Walkin070a52d2004-08-22 03:19:54 +0000871 $$ = $2;
872 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +0000873 $$->Identifier = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +0000874 $$->marker = $3;
875 }
876 | TOK_COMPONENTS TOK_OF Type {
877 $$ = asn1p_expr_new(yylineno);
878 checkmem($$);
879 $$->meta_type = $3->meta_type;
880 $$->expr_type = A1TC_COMPONENTS_OF;
Lev Walkin1004aa92004-09-08 00:28:11 +0000881 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +0000882 }
883 | ExtensionAndException {
884 $$ = $1;
885 }
886 ;
887
888AlternativeTypeLists:
889 AlternativeType {
890 $$ = asn1p_expr_new(yylineno);
891 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000892 asn1p_expr_add($$, $1);
Lev Walkin070a52d2004-08-22 03:19:54 +0000893 }
894 | AlternativeTypeLists ',' AlternativeType {
895 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000896 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +0000897 }
898 ;
899
900AlternativeType:
Lev Walkinaf120f72004-09-14 02:36:39 +0000901 Identifier Type {
Lev Walkin070a52d2004-08-22 03:19:54 +0000902 $$ = $2;
903 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +0000904 $$->Identifier = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +0000905 }
906 | ExtensionAndException {
907 $$ = $1;
908 }
909 ;
910
Lev Walkinf15320b2004-06-03 03:38:44 +0000911ClassDeclaration:
912 TOK_CLASS '{' ClassFieldList '}' optWithSyntax {
913 $$ = $3;
914 checkmem($$);
915 $$->with_syntax = $5;
916 assert($$->expr_type == A1TC_CLASSDEF);
917 assert($$->meta_type == AMT_OBJECT);
918 }
919 ;
920
921optUnique:
922 { $$ = 0; }
923 | TOK_UNIQUE { $$ = 1; }
924 ;
925
926ClassFieldList:
927 ClassField {
928 $$ = asn1p_expr_new(yylineno);
929 checkmem($$);
930 $$->expr_type = A1TC_CLASSDEF;
931 $$->meta_type = AMT_OBJECT;
Lev Walkin1004aa92004-09-08 00:28:11 +0000932 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000933 }
934 | ClassFieldList ',' ClassField {
935 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000936 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000937 }
938 ;
939
940ClassField:
941 ClassFieldIdentifier optMarker {
942 $$ = asn1p_expr_new(yylineno);
943 checkmem($$);
944 $$->Identifier = $1.name;
945 $$->expr_type = A1TC_CLASSFIELD;
946 $$->meta_type = AMT_OBJECTFIELD;
947 $$->marker = $2;
948 }
Lev Walkinb7c45ca2004-11-24 17:43:29 +0000949 | ClassFieldIdentifier Type optUnique optMarker {
Lev Walkinf15320b2004-06-03 03:38:44 +0000950 $$ = $2;
951 $$->Identifier = $1.name;
Lev Walkinb7c45ca2004-11-24 17:43:29 +0000952 $$->marker = $4;
953 $$->unique = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000954 }
Lev Walkinb7c45ca2004-11-24 17:43:29 +0000955 | ClassFieldIdentifier ClassFieldIdentifier optUnique optMarker {
Lev Walkinf15320b2004-06-03 03:38:44 +0000956 int ret;
957 $$ = asn1p_expr_new(yylineno);
958 checkmem($$);
959 $$->Identifier = $1.name;
960 $$->reference = asn1p_ref_new(yylineno);
961 checkmem($$->reference);
962 ret = asn1p_ref_add_component($$->reference,
963 $2.name, $2.lex_type);
964 checkmem(ret == 0);
965 $$->expr_type = A1TC_CLASSFIELD;
966 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkinb7c45ca2004-11-24 17:43:29 +0000967 $$->marker = $4;
968 $$->unique = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000969 }
970 ;
971
972optWithSyntax:
973 { $$ = 0; }
974 | WithSyntax {
975 $$ = $1;
976 }
977 ;
978
979WithSyntax:
980 TOK_WITH TOK_SYNTAX '{'
981 { asn1p_lexer_hack_enable_with_syntax(); }
982 WithSyntaxFormat
983 '}' {
984 $$ = $5;
985 }
986 ;
987
988WithSyntaxFormat:
989 WithSyntaxFormatToken {
990 $$ = asn1p_wsyntx_new();
991 TQ_ADD(&($$->chunks), $1, next);
992 }
993 | WithSyntaxFormat WithSyntaxFormatToken {
994 $$ = $1;
995 TQ_ADD(&($$->chunks), $2, next);
996 }
997 ;
998
999WithSyntaxFormatToken:
1000 TOK_opaque {
1001 $$ = asn1p_wsyntx_chunk_frombuf($1.buf, $1.len, 0);
1002 }
1003 | ClassFieldIdentifier {
1004 asn1p_ref_t *ref;
1005 int ret;
1006 ref = asn1p_ref_new(yylineno);
1007 checkmem(ref);
1008 ret = asn1p_ref_add_component(ref, $1.name, $1.lex_type);
1009 checkmem(ret == 0);
1010 $$ = asn1p_wsyntx_chunk_fromref(ref, 0);
1011 }
1012 ;
1013
Lev Walkinf15320b2004-06-03 03:38:44 +00001014ExtensionAndException:
1015 TOK_ThreeDots {
Lev Walkinceb20e72004-09-05 10:40:41 +00001016 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001017 checkmem($$);
1018 $$->Identifier = strdup("...");
1019 checkmem($$->Identifier);
1020 $$->expr_type = A1TC_EXTENSIBLE;
1021 $$->meta_type = AMT_TYPE;
1022 }
1023 | TOK_ThreeDots '!' DefinedValue {
Lev Walkinceb20e72004-09-05 10:40:41 +00001024 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001025 checkmem($$);
1026 $$->Identifier = strdup("...");
1027 checkmem($$->Identifier);
1028 $$->value = $3;
1029 $$->expr_type = A1TC_EXTENSIBLE;
1030 $$->meta_type = AMT_TYPE;
1031 }
1032 | TOK_ThreeDots '!' SignedNumber {
Lev Walkinceb20e72004-09-05 10:40:41 +00001033 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001034 checkmem($$);
1035 $$->Identifier = strdup("...");
1036 $$->value = $3;
1037 checkmem($$->Identifier);
1038 $$->expr_type = A1TC_EXTENSIBLE;
1039 $$->meta_type = AMT_TYPE;
1040 }
1041 ;
1042
Lev Walkin070a52d2004-08-22 03:19:54 +00001043Type:
Lev Walkinaf120f72004-09-14 02:36:39 +00001044 optTag TypeDeclaration optConstraints {
1045 $$ = $2;
1046 $$->tag = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001047 /*
1048 * Outer constraint for SEQUENCE OF and SET OF applies
1049 * to the inner type.
1050 */
1051 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1052 || $$->expr_type == ASN_CONSTR_SET_OF) {
1053 assert(!TQ_FIRST(&($$->members))->constraints);
Lev Walkinaf120f72004-09-14 02:36:39 +00001054 TQ_FIRST(&($$->members))->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001055 } else {
1056 if($$->constraints) {
1057 assert(!$2);
1058 } else {
Lev Walkinaf120f72004-09-14 02:36:39 +00001059 $$->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001060 }
1061 }
1062 }
1063 ;
1064
1065TypeDeclaration:
Lev Walkinf15320b2004-06-03 03:38:44 +00001066 BasicType {
1067 $$ = $1;
1068 }
Lev Walkin070a52d2004-08-22 03:19:54 +00001069 | TOK_CHOICE '{' AlternativeTypeLists '}' {
1070 $$ = $3;
1071 assert($$->expr_type == A1TC_INVALID);
1072 $$->expr_type = ASN_CONSTR_CHOICE;
1073 $$->meta_type = AMT_TYPE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001074 }
Lev Walkin144db9b2004-10-12 23:26:53 +00001075 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001076 $$ = $3;
1077 assert($$->expr_type == A1TC_INVALID);
1078 $$->expr_type = ASN_CONSTR_SEQUENCE;
1079 $$->meta_type = AMT_TYPE;
1080 }
Lev Walkin144db9b2004-10-12 23:26:53 +00001081 | TOK_SET '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001082 $$ = $3;
1083 assert($$->expr_type == A1TC_INVALID);
1084 $$->expr_type = ASN_CONSTR_SET;
1085 $$->meta_type = AMT_TYPE;
1086 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001087 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkinceb20e72004-09-05 10:40:41 +00001088 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001089 checkmem($$);
1090 $$->constraints = $2;
1091 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1092 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001093 $6->Identifier = $4;
1094 $6->tag = $5;
1095 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001096 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001097 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkinceb20e72004-09-05 10:40:41 +00001098 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001099 checkmem($$);
1100 $$->constraints = $2;
1101 $$->expr_type = ASN_CONSTR_SET_OF;
1102 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001103 $6->Identifier = $4;
1104 $6->tag = $5;
1105 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001106 }
1107 | TOK_ANY {
Lev Walkinceb20e72004-09-05 10:40:41 +00001108 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001109 checkmem($$);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001110 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001111 $$->meta_type = AMT_TYPE;
1112 }
1113 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1114 int ret;
Lev Walkinceb20e72004-09-05 10:40:41 +00001115 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001116 checkmem($$);
1117 $$->reference = asn1p_ref_new(yylineno);
1118 ret = asn1p_ref_add_component($$->reference,
1119 $4, RLT_lowercase);
1120 checkmem(ret == 0);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001121 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001122 $$->meta_type = AMT_TYPE;
1123 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001124 /*
1125 * A parametrized assignment.
1126 */
1127 | TypeRefName '{' ActualParameterList '}' {
1128 int ret;
1129 $$ = $3;
1130 assert($$->expr_type == 0);
1131 assert($$->meta_type == 0);
1132 assert($$->reference == 0);
1133 $$->reference = asn1p_ref_new(yylineno);
1134 checkmem($$->reference);
1135 ret = asn1p_ref_add_component($$->reference, $1, RLT_UNKNOWN);
1136 checkmem(ret == 0);
1137 free($1);
1138 $$->expr_type = A1TC_PARAMETRIZED;
1139 $$->meta_type = AMT_TYPE;
1140 }
1141 /*
1142 * A DefinedType reference.
1143 * "CLASS1.&id.&id2"
1144 * or
1145 * "Module.Type"
1146 * or
1147 * "Module.identifier"
1148 * or
1149 * "Type"
1150 */
1151 | ComplexTypeReference {
1152 $$ = asn1p_expr_new(yylineno);
1153 checkmem($$);
1154 $$->reference = $1;
1155 $$->expr_type = A1TC_REFERENCE;
1156 $$->meta_type = AMT_TYPEREF;
1157 }
1158 | TOK_INSTANCE TOK_OF ComplexTypeReference {
1159 $$ = asn1p_expr_new(yylineno);
1160 checkmem($$);
1161 $$->reference = $3;
1162 $$->expr_type = A1TC_INSTANCE;
1163 $$->meta_type = AMT_TYPE;
1164 }
1165 ;
1166
1167/*
1168 * A type name consisting of several components.
1169 * === EXAMPLE ===
1170 * === EOF ===
1171 */
1172ComplexTypeReference:
1173 TOK_typereference {
1174 int ret;
1175 $$ = asn1p_ref_new(yylineno);
1176 checkmem($$);
1177 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1178 checkmem(ret == 0);
1179 free($1);
1180 }
1181 | TOK_typereference '.' TypeRefName {
1182 int ret;
1183 $$ = asn1p_ref_new(yylineno);
1184 checkmem($$);
1185 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1186 checkmem(ret == 0);
1187 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1188 checkmem(ret == 0);
1189 free($1);
1190 }
Lev Walkin9c974182004-09-15 11:59:51 +00001191 | ObjectClassReference '.' TypeRefName {
1192 int ret;
1193 $$ = asn1p_ref_new(yylineno);
1194 checkmem($$);
1195 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1196 checkmem(ret == 0);
1197 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1198 checkmem(ret == 0);
1199 free($1);
1200 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001201 | TOK_typereference '.' Identifier {
1202 int ret;
1203 $$ = asn1p_ref_new(yylineno);
1204 checkmem($$);
1205 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1206 checkmem(ret == 0);
1207 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1208 checkmem(ret == 0);
1209 free($1);
1210 }
1211 | ObjectClassReference {
1212 int ret;
1213 $$ = asn1p_ref_new(yylineno);
1214 checkmem($$);
1215 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1216 free($1);
1217 checkmem(ret == 0);
1218 }
1219 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1220 int ret;
1221 $$ = $3;
1222 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1223 free($1);
1224 checkmem(ret == 0);
1225 /*
1226 * Move the last element infront.
1227 */
1228 {
1229 struct asn1p_ref_component_s tmp_comp;
1230 tmp_comp = $$->components[$$->comp_count-1];
1231 memmove(&$$->components[1],
1232 &$$->components[0],
1233 sizeof($$->components[0])
1234 * ($$->comp_count - 1));
1235 $$->components[0] = tmp_comp;
1236 }
1237 }
1238 ;
1239
1240ComplexTypeReferenceAmpList:
1241 ComplexTypeReferenceElement {
1242 int ret;
1243 $$ = asn1p_ref_new(yylineno);
1244 checkmem($$);
1245 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1246 free($1.name);
1247 checkmem(ret == 0);
1248 }
1249 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1250 int ret;
1251 $$ = $1;
1252 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1253 free($3.name);
1254 checkmem(ret == 0);
1255 }
1256 ;
1257
1258ComplexTypeReferenceElement: ClassFieldName;
1259ClassFieldIdentifier: ClassFieldName;
1260
1261ClassFieldName:
1262 /* "&Type1" */
1263 TOK_typefieldreference {
1264 $$.lex_type = RLT_AmpUppercase;
1265 $$.name = $1;
1266 }
1267 /* "&id" */
1268 | TOK_valuefieldreference {
1269 $$.lex_type = RLT_Amplowercase;
1270 $$.name = $1;
1271 }
1272 ;
1273
1274
1275/*
1276 * === EXAMPLE ===
1277 * value INTEGER ::= 1
1278 * === EOF ===
1279 */
1280ValueDefinition:
Lev Walkin9c974182004-09-15 11:59:51 +00001281 Identifier DefinedTypeRef TOK_PPEQ Value {
Lev Walkinf15320b2004-06-03 03:38:44 +00001282 $$ = $2;
1283 assert($$->Identifier == NULL);
1284 $$->Identifier = $1;
1285 $$->meta_type = AMT_VALUE;
1286 $$->value = $4;
1287 }
1288 ;
1289
Lev Walkin9c974182004-09-15 11:59:51 +00001290Value:
1291 Identifier ':' Value {
1292 $$ = asn1p_value_fromint(0);
1293 checkmem($$);
1294 $$->type = ATV_CHOICE_IDENTIFIER;
1295 $$->value.choice_identifier.identifier = $1;
1296 $$->value.choice_identifier.value = $3;
1297 }
Lev Walkincbad2512005-03-24 16:27:02 +00001298 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Lev Walkinf15320b2004-06-03 03:38:44 +00001299 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1300 checkmem($$);
1301 $$->type = ATV_UNPARSED;
1302 }
Lev Walkin9c974182004-09-15 11:59:51 +00001303 | TOK_NULL {
1304 $$ = asn1p_value_fromint(0);
1305 checkmem($$);
1306 $$->type = ATV_NULL;
1307 }
1308 | TOK_FALSE {
1309 $$ = asn1p_value_fromint(0);
1310 checkmem($$);
1311 $$->type = ATV_FALSE;
1312 }
1313 | TOK_TRUE {
1314 $$ = asn1p_value_fromint(0);
1315 checkmem($$);
1316 $$->type = ATV_TRUE;
1317 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001318 | TOK_bstring {
1319 $$ = _convert_bitstring2binary($1, 'B');
1320 checkmem($$);
1321 }
1322 | TOK_hstring {
1323 $$ = _convert_bitstring2binary($1, 'H');
1324 checkmem($$);
1325 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001326 | RestrictedCharacterStringValue {
1327 $$ = $$;
Lev Walkinf15320b2004-06-03 03:38:44 +00001328 }
1329 | SignedNumber {
1330 $$ = $1;
1331 }
1332 | DefinedValue {
1333 $$ = $1;
1334 }
1335 ;
1336
1337DefinedValue:
1338 Identifier {
1339 asn1p_ref_t *ref;
1340 int ret;
1341 ref = asn1p_ref_new(yylineno);
1342 checkmem(ref);
1343 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1344 checkmem(ret == 0);
1345 $$ = asn1p_value_fromref(ref, 0);
1346 checkmem($$);
1347 free($1);
1348 }
1349 | TypeRefName '.' Identifier {
1350 asn1p_ref_t *ref;
1351 int ret;
1352 ref = asn1p_ref_new(yylineno);
1353 checkmem(ref);
1354 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1355 checkmem(ret == 0);
1356 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1357 checkmem(ret == 0);
1358 $$ = asn1p_value_fromref(ref, 0);
1359 checkmem($$);
1360 free($1);
1361 free($3);
1362 }
1363 ;
1364
Lev Walkin1e448d32005-03-24 14:26:38 +00001365
1366RestrictedCharacterStringValue:
1367 TOK_cstring {
1368 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1369 checkmem($$);
1370 }
Lev Walkind9574ae2005-03-24 16:22:35 +00001371 | TOK_tuple {
1372 $$ = asn1p_value_fromint($1);
1373 checkmem($$);
1374 $$->type = ATV_TUPLE;
1375 }
1376 | TOK_quadruple {
1377 $$ = asn1p_value_fromint($1);
1378 checkmem($$);
1379 $$->type = ATV_QUADRUPLE;
1380 }
1381 /*
Lev Walkin1e448d32005-03-24 14:26:38 +00001382 | '{' TOK_number ',' TOK_number '}' {
1383 asn1c_integer_t v = ($2 << 4) + $4;
1384 if($2 > 7) return yyerror("X.680:2003, #37.14 "
1385 "mandates 0..7 range for Tuple's TableColumn");
1386 if($4 > 15) return yyerror("X.680:2003, #37.14 "
1387 "mandates 0..15 range for Tuple's TableRow");
1388 $$ = asn1p_value_fromint(v);
1389 checkmem($$);
1390 $$->type = ATV_TUPLE;
1391 }
1392 | '{' TOK_number ',' TOK_number ',' TOK_number ',' TOK_number '}' {
1393 asn1c_integer_t v = ($2 << 24) | ($4 << 16) | ($6 << 8) | $8;
1394 if($2 > 127) return yyerror("X.680:2003, #37.12 "
1395 "mandates 0..127 range for Quadruple's Group");
1396 if($4 > 255) return yyerror("X.680:2003, #37.12 "
1397 "mandates 0..255 range for Quadruple's Plane");
1398 if($6 > 255) return yyerror("X.680:2003, #37.12 "
1399 "mandates 0..255 range for Quadruple's Row");
1400 if($8 > 255) return yyerror("X.680:2003, #37.12 "
1401 "mandates 0..255 range for Quadruple's Cell");
1402 $$ = asn1p_value_fromint(v);
1403 checkmem($$);
1404 $$->type = ATV_QUADRUPLE;
1405 }
Lev Walkind9574ae2005-03-24 16:22:35 +00001406 */
Lev Walkin1e448d32005-03-24 14:26:38 +00001407 ;
1408
Lev Walkinf15320b2004-06-03 03:38:44 +00001409Opaque:
1410 TOK_opaque {
Lev Walkin1893ddf2005-03-20 14:28:32 +00001411 $$.len = $1.len + 1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001412 $$.buf = malloc($$.len + 1);
1413 checkmem($$.buf);
1414 $$.buf[0] = '{';
Lev Walkin1893ddf2005-03-20 14:28:32 +00001415 memcpy($$.buf + 1, $1.buf, $1.len);
Lev Walkinf15320b2004-06-03 03:38:44 +00001416 $$.buf[$$.len] = '\0';
1417 free($1.buf);
1418 }
1419 | Opaque TOK_opaque {
1420 int newsize = $1.len + $2.len;
1421 char *p = malloc(newsize + 1);
1422 checkmem(p);
1423 memcpy(p , $1.buf, $1.len);
1424 memcpy(p + $1.len, $2.buf, $2.len);
1425 p[newsize] = '\0';
1426 free($1.buf);
1427 free($2.buf);
1428 $$.buf = p;
1429 $$.len = newsize;
1430 }
1431 ;
1432
1433BasicTypeId:
1434 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1435 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1436 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1437 | BasicTypeId_UniverationCompatible { $$ = $1; }
1438 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1439 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1440 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1441 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1442 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1443 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1444 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1445 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
Lev Walkinc7d939d2005-03-20 11:12:40 +00001446 | BasicString { $$ = $1; }
Lev Walkinf15320b2004-06-03 03:38:44 +00001447 ;
1448
1449/*
1450 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1451 */
1452BasicTypeId_UniverationCompatible:
1453 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1454 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1455 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1456 ;
1457
1458BasicType:
1459 BasicTypeId {
Lev Walkinceb20e72004-09-05 10:40:41 +00001460 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001461 checkmem($$);
1462 $$->expr_type = $1;
1463 $$->meta_type = AMT_TYPE;
1464 }
1465 | BasicTypeId_UniverationCompatible UniverationDefinition {
1466 if($2) {
1467 $$ = $2;
1468 } else {
Lev Walkinceb20e72004-09-05 10:40:41 +00001469 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001470 checkmem($$);
1471 }
1472 $$->expr_type = $1;
1473 $$->meta_type = AMT_TYPE;
1474 }
1475 ;
1476
1477BasicString:
1478 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1479 | TOK_GeneralString {
1480 $$ = ASN_STRING_GeneralString;
Lev Walkin9c974182004-09-15 11:59:51 +00001481 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001482 }
1483 | TOK_GraphicString {
1484 $$ = ASN_STRING_GraphicString;
Lev Walkin9c974182004-09-15 11:59:51 +00001485 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001486 }
1487 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1488 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1489 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1490 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1491 | TOK_T61String {
1492 $$ = ASN_STRING_T61String;
Lev Walkin9c974182004-09-15 11:59:51 +00001493 fprintf(stderr, "WARNING: T61String is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001494 }
1495 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1496 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1497 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1498 | TOK_VideotexString {
1499 $$ = ASN_STRING_VideotexString;
Lev Walkin9c974182004-09-15 11:59:51 +00001500 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001501 }
1502 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1503 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1504 ;
1505
Lev Walkind2ea1de2004-08-20 13:25:29 +00001506
Lev Walkinf15320b2004-06-03 03:38:44 +00001507/*
1508 * Data type constraints.
1509 */
Lev Walkinf15320b2004-06-03 03:38:44 +00001510Union: '|' | TOK_UNION;
1511Intersection: '^' | TOK_INTERSECTION;
1512Except: TOK_EXCEPT;
1513
Lev Walkinf59d0752004-08-18 04:59:12 +00001514optConstraints:
1515 { $$ = 0; }
Lev Walkind2ea1de2004-08-20 13:25:29 +00001516 | Constraints {
1517 $$ = $1;
1518 }
1519 ;
1520
1521Constraints:
1522 SetOfConstraints {
Lev Walkinf59d0752004-08-18 04:59:12 +00001523 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
1524 }
1525 | TOK_SIZE '(' ElementSetSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001526 /*
1527 * This is a special case, for compatibility purposes.
Lev Walkinf59d0752004-08-18 04:59:12 +00001528 * It goes without parentheses.
Lev Walkinf15320b2004-06-03 03:38:44 +00001529 */
Lev Walkind2ea1de2004-08-20 13:25:29 +00001530 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001531 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001532 ;
1533
Lev Walkinf59d0752004-08-18 04:59:12 +00001534SetOfConstraints:
1535 '(' ElementSetSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001536 $$ = $2;
1537 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001538 | SetOfConstraints '(' ElementSetSpecs ')' {
1539 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
1540 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001541 ;
1542
Lev Walkinf59d0752004-08-18 04:59:12 +00001543ElementSetSpecs:
1544 ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001545 $$ = $1;
1546 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001547 | ElementSetSpec ',' TOK_ThreeDots {
Lev Walkinf15320b2004-06-03 03:38:44 +00001548 asn1p_constraint_t *ct;
1549 ct = asn1p_constraint_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001550 ct->type = ACT_EL_EXT;
1551 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
1552 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001553 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001554 asn1p_constraint_t *ct;
1555 ct = asn1p_constraint_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001556 ct->type = ACT_EL_EXT;
1557 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinb4fcdd22004-08-13 12:35:09 +00001558 ct = $$;
1559 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
Lev Walkinf15320b2004-06-03 03:38:44 +00001560 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001561 ;
1562
Lev Walkinf59d0752004-08-18 04:59:12 +00001563ElementSetSpec:
1564 ConstraintSubtypeElement {
1565 $$ = $1;
1566 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001567 | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {
1568 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
1569 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001570 | ElementSetSpec Union ConstraintSubtypeElement {
Lev Walkinf15320b2004-06-03 03:38:44 +00001571 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
1572 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001573 | ElementSetSpec Intersection ConstraintSubtypeElement {
Lev Walkinf15320b2004-06-03 03:38:44 +00001574 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
1575 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001576 | ConstraintSubtypeElement Except ConstraintSubtypeElement {
Lev Walkinf15320b2004-06-03 03:38:44 +00001577 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
1578 }
1579 ;
1580
1581ConstraintSubtypeElement:
Lev Walkinf59d0752004-08-18 04:59:12 +00001582 ConstraintSpec '(' ElementSetSpecs ')' {
1583 int ret;
1584 $$ = asn1p_constraint_new(yylineno);
1585 checkmem($$);
1586 $$->type = $1;
1587 ret = asn1p_constraint_insert($$, $3);
1588 checkmem(ret == 0);
1589 }
1590 | '(' ElementSetSpecs ')' {
1591 int ret;
1592 $$ = asn1p_constraint_new(yylineno);
1593 checkmem($$);
1594 $$->type = ACT_CA_SET;
1595 ret = asn1p_constraint_insert($$, $2);
1596 checkmem(ret == 0);
1597 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001598 | SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001599 $$ = asn1p_constraint_new(yylineno);
1600 checkmem($$);
1601 $$->type = ACT_EL_VALUE;
1602 $$->value = $1;
1603 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001604 | ContainedSubtype {
1605 $$ = asn1p_constraint_new(yylineno);
1606 checkmem($$);
1607 $$->type = ACT_EL_TYPE;
1608 $$->containedSubtype = $1;
1609 }
1610 | SingleValue ConstraintRangeSpec SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001611 $$ = asn1p_constraint_new(yylineno);
1612 checkmem($$);
1613 $$->type = $2;
1614 $$->range_start = $1;
1615 $$->range_stop = $3;
1616 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001617 | TOK_MIN ConstraintRangeSpec SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001618 $$ = asn1p_constraint_new(yylineno);
1619 checkmem($$);
Lev Walkinf59d0752004-08-18 04:59:12 +00001620 $$->type = $2;
1621 $$->range_start = asn1p_value_fromint(-123);
1622 $$->range_stop = $3;
1623 $$->range_start->type = ATV_MIN;
1624 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001625 | SingleValue ConstraintRangeSpec TOK_MAX {
Lev Walkinf59d0752004-08-18 04:59:12 +00001626 $$ = asn1p_constraint_new(yylineno);
1627 checkmem($$);
1628 $$->type = $2;
1629 $$->range_start = $1;
1630 $$->range_stop = asn1p_value_fromint(321);
1631 $$->range_stop->type = ATV_MAX;
1632 }
1633 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1634 $$ = asn1p_constraint_new(yylineno);
1635 checkmem($$);
1636 $$->type = $2;
1637 $$->range_start = asn1p_value_fromint(-123);
1638 $$->range_stop = asn1p_value_fromint(321);
1639 $$->range_start->type = ATV_MIN;
1640 $$->range_stop->type = ATV_MAX;
Lev Walkinf15320b2004-06-03 03:38:44 +00001641 }
1642 | TableConstraint {
1643 $$ = $1;
1644 }
Lev Walkine596bf02005-03-28 15:01:27 +00001645 | InnerTypeConstraint {
Lev Walkinf15320b2004-06-03 03:38:44 +00001646 $$ = $1;
1647 }
Lev Walkin1893ddf2005-03-20 14:28:32 +00001648 | TOK_CONSTRAINED TOK_BY '{'
1649 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1650 $$ = asn1p_constraint_new(yylineno);
1651 checkmem($$);
1652 $$->type = ACT_CT_CTDBY;
1653 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
1654 checkmem($$->value);
1655 $$->value->type = ATV_UNPARSED;
1656 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001657 ;
1658
1659ConstraintRangeSpec:
1660 TOK_TwoDots { $$ = ACT_EL_RANGE; }
1661 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
1662 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
1663 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
1664 ;
1665
1666ConstraintSpec:
1667 TOK_SIZE {
1668 $$ = ACT_CT_SIZE;
1669 }
1670 | TOK_FROM {
1671 $$ = ACT_CT_FROM;
1672 }
1673 ;
1674
Lev Walkinff7dd142005-03-20 12:58:00 +00001675SingleValue:
Lev Walkinc8092cb2005-02-18 16:34:21 +00001676 TOK_FALSE {
1677 $$ = asn1p_value_fromint(0);
1678 checkmem($$);
1679 $$->type = ATV_FALSE;
1680 }
1681 | TOK_TRUE {
1682 $$ = asn1p_value_fromint(1);
1683 checkmem($$);
1684 $$->type = ATV_TRUE;
1685 }
1686 | SignedNumber {
Lev Walkinf15320b2004-06-03 03:38:44 +00001687 $$ = $1;
1688 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001689 | RestrictedCharacterStringValue {
1690 $$ = $1;
Lev Walkinc8092cb2005-02-18 16:34:21 +00001691 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001692 | Identifier {
1693 asn1p_ref_t *ref;
1694 int ret;
1695 ref = asn1p_ref_new(yylineno);
1696 checkmem(ref);
1697 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1698 checkmem(ret == 0);
1699 $$ = asn1p_value_fromref(ref, 0);
1700 checkmem($$);
1701 free($1);
1702 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001703 ;
1704
1705ContainedSubtype:
1706 TypeRefName {
Lev Walkinc8092cb2005-02-18 16:34:21 +00001707 asn1p_ref_t *ref;
1708 int ret;
1709 ref = asn1p_ref_new(yylineno);
1710 checkmem(ref);
1711 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1712 checkmem(ret == 0);
1713 $$ = asn1p_value_fromref(ref, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001714 checkmem($$);
Lev Walkinc8092cb2005-02-18 16:34:21 +00001715 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001716 }
1717 ;
1718
Lev Walkine596bf02005-03-28 15:01:27 +00001719InnerTypeConstraint:
1720 TOK_WITH TOK_COMPONENT SetOfConstraints {
1721 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
1722 }
1723 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001724 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
1725 }
1726 ;
1727
1728WithComponentsList:
1729 WithComponentsElement {
1730 $$ = $1;
1731 }
1732 | WithComponentsList ',' WithComponentsElement {
1733 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
1734 }
1735 ;
1736
1737WithComponentsElement:
1738 TOK_ThreeDots {
1739 $$ = asn1p_constraint_new(yylineno);
1740 checkmem($$);
1741 $$->type = ACT_EL_EXT;
Lev Walkine596bf02005-03-28 15:01:27 +00001742 $$->value = asn1p_value_frombuf("...", 3, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001743 }
1744 | Identifier optConstraints optPresenceConstraint {
1745 $$ = asn1p_constraint_new(yylineno);
1746 checkmem($$);
1747 $$->type = ACT_EL_VALUE;
1748 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1749 $$->presence = $3;
Lev Walkine596bf02005-03-28 15:01:27 +00001750 if($2) asn1p_constraint_insert($$, $2);
Lev Walkinf15320b2004-06-03 03:38:44 +00001751 }
1752 ;
1753
1754/*
1755 * presence constraint for WithComponents
1756 */
1757optPresenceConstraint:
1758 { $$ = ACPRES_DEFAULT; }
1759 | PresenceConstraint { $$ = $1; }
1760 ;
1761
1762PresenceConstraint:
1763 TOK_PRESENT {
1764 $$ = ACPRES_PRESENT;
1765 }
1766 | TOK_ABSENT {
1767 $$ = ACPRES_ABSENT;
1768 }
1769 | TOK_OPTIONAL {
1770 $$ = ACPRES_OPTIONAL;
1771 }
1772 ;
1773
1774TableConstraint:
1775 SimpleTableConstraint {
1776 $$ = $1;
1777 }
1778 | ComponentRelationConstraint {
1779 $$ = $1;
1780 }
1781 ;
1782
1783/*
1784 * "{ExtensionSet}"
1785 */
1786SimpleTableConstraint:
1787 '{' TypeRefName '}' {
1788 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
1789 asn1p_constraint_t *ct;
1790 int ret;
1791 ret = asn1p_ref_add_component(ref, $2, 0);
1792 checkmem(ret == 0);
1793 ct = asn1p_constraint_new(yylineno);
1794 checkmem($$);
1795 ct->type = ACT_EL_VALUE;
1796 ct->value = asn1p_value_fromref(ref, 0);
1797 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
1798 }
1799 ;
1800
1801ComponentRelationConstraint:
1802 SimpleTableConstraint '{' AtNotationList '}' {
1803 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
1804 }
1805 ;
1806
1807AtNotationList:
1808 AtNotationElement {
1809 $$ = asn1p_constraint_new(yylineno);
1810 checkmem($$);
1811 $$->type = ACT_EL_VALUE;
1812 $$->value = asn1p_value_fromref($1, 0);
1813 }
1814 | AtNotationList ',' AtNotationElement {
1815 asn1p_constraint_t *ct;
1816 ct = asn1p_constraint_new(yylineno);
1817 checkmem(ct);
1818 ct->type = ACT_EL_VALUE;
1819 ct->value = asn1p_value_fromref($3, 0);
1820 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
1821 }
1822 ;
1823
1824/*
1825 * @blah
1826 */
1827AtNotationElement:
1828 '@' ComponentIdList {
1829 char *p = malloc(strlen($2) + 2);
1830 int ret;
1831 *p = '@';
1832 strcpy(p + 1, $2);
1833 $$ = asn1p_ref_new(yylineno);
1834 ret = asn1p_ref_add_component($$, p, 0);
1835 checkmem(ret == 0);
1836 free(p);
1837 free($2);
1838 }
1839 | '@' '.' ComponentIdList {
1840 char *p = malloc(strlen($3) + 3);
1841 int ret;
1842 p[0] = '@';
1843 p[1] = '.';
1844 strcpy(p + 2, $3);
1845 $$ = asn1p_ref_new(yylineno);
1846 ret = asn1p_ref_add_component($$, p, 0);
1847 checkmem(ret == 0);
1848 free(p);
1849 free($3);
1850 }
1851 ;
1852
1853/* identifier "." ... */
1854ComponentIdList:
1855 Identifier {
1856 $$ = $1;
1857 }
1858 | ComponentIdList '.' Identifier {
1859 int l1 = strlen($1);
1860 int l3 = strlen($3);
1861 $$ = malloc(l1 + 1 + l3 + 1);
1862 memcpy($$, $1, l1);
1863 $$[l1] = '.';
1864 memcpy($$ + l1 + 1, $3, l3);
1865 $$[l1 + 1 + l3] = '\0';
1866 }
1867 ;
1868
1869
1870
1871/*
1872 * MARKERS
1873 */
1874
1875optMarker:
Lev Walkin9c974182004-09-15 11:59:51 +00001876 {
1877 $$.flags = EM_NOMARK;
1878 $$.default_value = 0;
1879 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001880 | Marker { $$ = $1; }
1881 ;
1882
1883Marker:
1884 TOK_OPTIONAL {
Lev Walkin9c974182004-09-15 11:59:51 +00001885 $$.flags = EM_OPTIONAL;
1886 $$.default_value = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +00001887 }
Lev Walkin9c974182004-09-15 11:59:51 +00001888 | TOK_DEFAULT Value {
1889 $$.flags = EM_DEFAULT;
1890 $$.default_value = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00001891 }
1892 ;
1893
1894/*
1895 * Universal enumeration definition to use in INTEGER and ENUMERATED.
1896 * === EXAMPLE ===
1897 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
1898 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
1899 * === EOF ===
1900 */
1901/*
1902optUniverationDefinition:
1903 { $$ = 0; }
1904 | UniverationDefinition {
1905 $$ = $1;
1906 }
1907 ;
1908*/
1909
1910UniverationDefinition:
1911 '{' '}' {
Lev Walkinceb20e72004-09-05 10:40:41 +00001912 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001913 checkmem($$);
1914 }
1915 | '{' UniverationList '}' {
1916 $$ = $2;
1917 }
1918 ;
1919
1920UniverationList:
1921 UniverationElement {
Lev Walkinceb20e72004-09-05 10:40:41 +00001922 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001923 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00001924 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001925 }
1926 | UniverationList ',' UniverationElement {
1927 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001928 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001929 }
1930 ;
1931
1932UniverationElement:
1933 Identifier {
Lev Walkinceb20e72004-09-05 10:40:41 +00001934 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001935 checkmem($$);
1936 $$->expr_type = A1TC_UNIVERVAL;
1937 $$->meta_type = AMT_VALUE;
1938 $$->Identifier = $1;
1939 }
1940 | Identifier '(' SignedNumber ')' {
Lev Walkinceb20e72004-09-05 10:40:41 +00001941 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001942 checkmem($$);
1943 $$->expr_type = A1TC_UNIVERVAL;
1944 $$->meta_type = AMT_VALUE;
1945 $$->Identifier = $1;
1946 $$->value = $3;
1947 }
1948 | Identifier '(' DefinedValue ')' {
Lev Walkinceb20e72004-09-05 10:40:41 +00001949 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001950 checkmem($$);
1951 $$->expr_type = A1TC_UNIVERVAL;
1952 $$->meta_type = AMT_VALUE;
1953 $$->Identifier = $1;
1954 $$->value = $3;
1955 }
1956 | SignedNumber {
Lev Walkinceb20e72004-09-05 10:40:41 +00001957 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001958 checkmem($$);
1959 $$->expr_type = A1TC_UNIVERVAL;
1960 $$->meta_type = AMT_VALUE;
1961 $$->value = $1;
1962 }
1963 | TOK_ThreeDots {
Lev Walkinceb20e72004-09-05 10:40:41 +00001964 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001965 checkmem($$);
1966 $$->Identifier = strdup("...");
1967 checkmem($$->Identifier);
1968 $$->expr_type = A1TC_EXTENSIBLE;
1969 $$->meta_type = AMT_VALUE;
1970 }
1971 ;
1972
1973SignedNumber:
1974 TOK_number {
1975 $$ = asn1p_value_fromint($1);
1976 checkmem($$);
1977 }
1978 | TOK_number_negative {
1979 $$ = asn1p_value_fromint($1);
1980 checkmem($$);
1981 }
1982 ;
1983
1984/*
1985 * SEQUENCE definition.
1986 * === EXAMPLE ===
1987 * Struct1 ::= SEQUENCE {
1988 * memb1 Struct2,
1989 * memb2 SEQUENCE OF {
1990 * memb2-1 Struct 3
1991 * }
1992 * }
1993 * === EOF ===
1994 */
1995
1996
1997
1998/*
1999 * SET definition.
2000 * === EXAMPLE ===
2001 * Person ::= SET {
2002 * name [0] PrintableString (SIZE(1..20)),
2003 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2004 * }
2005 * === EOF ===
2006 */
2007
2008optTag:
2009 { memset(&$$, 0, sizeof($$)); }
2010 | Tag { $$ = $1; }
2011 ;
2012
2013Tag:
Lev Walkinc603f102005-01-23 09:51:44 +00002014 TagTypeValue TagPlicit {
Lev Walkinf15320b2004-06-03 03:38:44 +00002015 $$ = $1;
Lev Walkinc603f102005-01-23 09:51:44 +00002016 $$.tag_mode = $2.tag_mode;
Lev Walkinf15320b2004-06-03 03:38:44 +00002017 }
Lev Walkinc603f102005-01-23 09:51:44 +00002018 ;
2019
2020TagTypeValue:
2021 '[' TagClass TOK_number ']' {
2022 $$ = $2;
2023 $$.tag_value = $3;
2024 };
2025
2026TagClass:
2027 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2028 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2029 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2030 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2031 ;
2032
2033TagPlicit:
2034 { $$.tag_mode = TM_DEFAULT; }
2035 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2036 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
Lev Walkinf15320b2004-06-03 03:38:44 +00002037 ;
2038
2039TypeRefName:
2040 TOK_typereference {
2041 checkmem($1);
2042 $$ = $1;
2043 }
Lev Walkinf59d0752004-08-18 04:59:12 +00002044 | TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002045 checkmem($1);
2046 $$ = $1;
2047 }
2048 ;
2049
Lev Walkinf59d0752004-08-18 04:59:12 +00002050
Lev Walkinf15320b2004-06-03 03:38:44 +00002051ObjectClassReference:
Lev Walkinf59d0752004-08-18 04:59:12 +00002052 TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002053 checkmem($1);
2054 $$ = $1;
2055 }
2056 ;
2057
Lev Walkin83cac2f2004-09-22 16:03:36 +00002058optIdentifier:
2059 { $$ = 0; }
2060 | Identifier {
2061 $$ = $1;
2062 }
Lev Walkin8f294e02005-06-06 08:28:58 +00002063 ;
Lev Walkin83cac2f2004-09-22 16:03:36 +00002064
Lev Walkinf15320b2004-06-03 03:38:44 +00002065Identifier:
2066 TOK_identifier {
2067 checkmem($1);
2068 $$ = $1;
2069 }
2070 ;
2071
Lev Walkinf15320b2004-06-03 03:38:44 +00002072%%
2073
2074
2075/*
2076 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2077 */
2078static asn1p_value_t *
2079_convert_bitstring2binary(char *str, int base) {
2080 asn1p_value_t *val;
2081 int slen;
2082 int memlen;
2083 int baselen;
2084 int bits;
2085 uint8_t *binary_vector;
2086 uint8_t *bv_ptr;
2087 uint8_t cur_val;
2088
2089 assert(str);
2090 assert(str[0] == '\'');
2091
2092 switch(base) {
2093 case 'B':
2094 baselen = 1;
2095 break;
2096 case 'H':
2097 baselen = 4;
2098 break;
2099 default:
2100 assert(base == 'B' || base == 'H');
2101 errno = EINVAL;
2102 return NULL;
2103 }
2104
2105 slen = strlen(str);
2106 assert(str[slen - 1] == base);
2107 assert(str[slen - 2] == '\'');
2108
2109 memlen = slen / (8 / baselen); /* Conservative estimate */
2110
2111 bv_ptr = binary_vector = malloc(memlen + 1);
2112 if(bv_ptr == NULL)
2113 /* ENOMEM */
2114 return NULL;
2115
2116 cur_val = 0;
2117 bits = 0;
2118 while(*(++str) != '\'') {
2119 switch(baselen) {
2120 case 1:
2121 switch(*str) {
2122 case '1':
2123 cur_val |= 1 << (7 - (bits % 8));
2124 case '0':
2125 break;
2126 default:
2127 assert(!"_y UNREACH1");
2128 case ' ': case '\r': case '\n':
2129 continue;
2130 }
2131 break;
2132 case 4:
2133 switch(*str) {
2134 case '0': case '1': case '2': case '3': case '4':
2135 case '5': case '6': case '7': case '8': case '9':
2136 cur_val |= (*str - '0') << (4 - (bits % 8));
2137 break;
2138 case 'A': case 'B': case 'C':
2139 case 'D': case 'E': case 'F':
2140 cur_val |= ((*str - 'A') + 10)
2141 << (4 - (bits % 8));
2142 break;
2143 default:
2144 assert(!"_y UNREACH2");
2145 case ' ': case '\r': case '\n':
2146 continue;
2147 }
2148 break;
2149 }
2150
2151 bits += baselen;
2152 if((bits % 8) == 0) {
2153 *bv_ptr++ = cur_val;
2154 cur_val = 0;
2155 }
2156 }
2157
2158 *bv_ptr = cur_val;
2159 assert((bv_ptr - binary_vector) <= memlen);
2160
2161 val = asn1p_value_frombits(binary_vector, bits, 0);
2162 if(val == NULL) {
2163 free(binary_vector);
2164 }
2165
2166 return val;
2167}
2168
2169extern char *asn1p_text;
2170
2171int
2172yyerror(const char *msg) {
2173 fprintf(stderr,
2174 "ASN.1 grammar parse error "
2175 "near line %d (token \"%s\"): %s\n",
Lev Walkinceb20e72004-09-05 10:40:41 +00002176 yylineno, asn1p_text, msg);
Lev Walkinf15320b2004-06-03 03:38:44 +00002177 return -1;
2178}
2179
2180