blob: 36d9bafd80c2b6e5851278e3cd0c79458fe8b959 [file] [log] [blame]
vlmfa67ddc2004-06-03 03:38:44 +00001%{
2
3#include <stdlib.h>
4#include <stdio.h>
5#include <string.h>
6#include <errno.h>
7#include <assert.h>
8
9#include "asn1parser.h"
10
11#define YYPARSE_PARAM param
vlmfbf6bf62005-06-07 21:25:42 +000012#define YYPARSE_PARAM_TYPE void **
vlmfa67ddc2004-06-03 03:38:44 +000013#define YYERROR_VERBOSE
14
15int yylex(void);
16int yyerror(const char *msg);
vlmd2f87602005-06-07 21:32:16 +000017#ifdef YYBYACC
18int yyparse(void **param); /* byacc does not produce a prototype */
19#endif
vlmfa67ddc2004-06-03 03:38:44 +000020void asn1p_lexer_hack_push_opaque_state(void);
21void asn1p_lexer_hack_enable_with_syntax(void);
vlm9283dbe2004-08-18 04:59:12 +000022void asn1p_lexer_hack_push_encoding_control(void);
vlmfa67ddc2004-06-03 03:38:44 +000023#define yylineno asn1p_lineno
24extern int asn1p_lineno;
25
vlm04a08da2005-08-12 10:06:17 +000026/*
vlm177a5b62005-09-05 05:17:57 +000027 * Process directives as <ASN1C:RepresentAsPointer>
vlm066dc102005-08-22 12:23:54 +000028 */
29extern int asn1p_as_pointer;
vlm066dc102005-08-22 12:23:54 +000030
31/*
vlm04a08da2005-08-12 10:06:17 +000032 * This temporary variable is used to solve the shortcomings of 1-lookahead
33 * parser.
34 */
35static struct AssignedIdentifier *saved_aid;
vlmfa67ddc2004-06-03 03:38:44 +000036
vlm5d89c3d2005-08-13 09:07:11 +000037static asn1p_value_t *_convert_bitstring2binary(char *str, int base);
38static void _fixup_anonymous_identifier(asn1p_expr_t *expr);
vlmfa67ddc2004-06-03 03:38:44 +000039
vlm04a08da2005-08-12 10:06:17 +000040#define checkmem(ptr) do { \
41 if(!(ptr)) \
42 return yyerror("Memory failure"); \
vlmfa67ddc2004-06-03 03:38:44 +000043 } while(0)
44
vlm9fe7c922005-08-12 10:08:45 +000045#define CONSTRAINT_INSERT(root, constr_type, arg1, arg2) do { \
vlm04a08da2005-08-12 10:06:17 +000046 if(arg1->type != constr_type) { \
47 int __ret; \
48 root = asn1p_constraint_new(yylineno); \
49 checkmem(root); \
50 root->type = constr_type; \
51 __ret = asn1p_constraint_insert(root, \
52 arg1); \
53 checkmem(__ret == 0); \
54 } else { \
55 root = arg1; \
56 } \
57 if(arg2) { \
58 int __ret \
59 = asn1p_constraint_insert(root, arg2); \
60 checkmem(__ret == 0); \
61 } \
vlmfa67ddc2004-06-03 03:38:44 +000062 } while(0)
63
64%}
65
66
67/*
68 * Token value definition.
69 * a_*: ASN-specific types.
70 * tv_*: Locally meaningful types.
71 */
72%union {
73 asn1p_t *a_grammar;
74 asn1p_module_flags_e a_module_flags;
75 asn1p_module_t *a_module;
76 asn1p_expr_type_e a_type; /* ASN.1 Type */
77 asn1p_expr_t *a_expr; /* Constructed collection */
78 asn1p_constraint_t *a_constr; /* Constraint */
79 enum asn1p_constraint_type_e a_ctype;/* Constraint type */
80 asn1p_xports_t *a_xports; /* IMports/EXports */
vlm04a08da2005-08-12 10:06:17 +000081 struct AssignedIdentifier a_aid; /* Assigned Identifier */
vlmfa67ddc2004-06-03 03:38:44 +000082 asn1p_oid_t *a_oid; /* Object Identifier */
83 asn1p_oid_arc_t a_oid_arc; /* Single OID's arc */
84 struct asn1p_type_tag_s a_tag; /* A tag */
85 asn1p_ref_t *a_ref; /* Reference to custom type */
86 asn1p_wsyntx_t *a_wsynt; /* WITH SYNTAX contents */
87 asn1p_wsyntx_chunk_t *a_wchunk; /* WITH SYNTAX chunk */
88 struct asn1p_ref_component_s a_refcomp; /* Component of a reference */
89 asn1p_value_t *a_value; /* Number, DefinedValue, etc */
90 struct asn1p_param_s a_parg; /* A parameter argument */
91 asn1p_paramlist_t *a_plist; /* A pargs list */
vlmc94e28f2004-09-15 11:59:51 +000092 struct asn1p_expr_marker_s a_marker; /* OPTIONAL/DEFAULT */
vlmfa67ddc2004-06-03 03:38:44 +000093 enum asn1p_constr_pres_e a_pres; /* PRESENT/ABSENT/OPTIONAL */
vlm0aa86902004-10-12 23:26:53 +000094 asn1c_integer_t a_int;
vlmfa67ddc2004-06-03 03:38:44 +000095 char *tv_str;
96 struct {
97 char *buf;
98 int len;
99 } tv_opaque;
100 struct {
101 char *name;
102 struct asn1p_type_tag_s tag;
103 } tv_nametag;
104};
105
106/*
107 * Token types returned by scanner.
108 */
109%token TOK_PPEQ /* "::=", Pseudo Pascal EQuality */
110%token <tv_opaque> TOK_opaque /* opaque data (driven from .y) */
111%token <tv_str> TOK_bstring
112%token <tv_opaque> TOK_cstring
113%token <tv_str> TOK_hstring
114%token <tv_str> TOK_identifier
115%token <a_int> TOK_number
vlm2c8c44d2005-03-24 16:22:35 +0000116%token <a_int> TOK_tuple
117%token <a_int> TOK_quadruple
vlmfa67ddc2004-06-03 03:38:44 +0000118%token <a_int> TOK_number_negative
119%token <tv_str> TOK_typereference
vlm9283dbe2004-08-18 04:59:12 +0000120%token <tv_str> TOK_capitalreference /* "CLASS1" */
vlmfa67ddc2004-06-03 03:38:44 +0000121%token <tv_str> TOK_typefieldreference /* "&Pork" */
122%token <tv_str> TOK_valuefieldreference /* "&id" */
123
124/*
125 * Token types representing ASN.1 standard keywords.
126 */
127%token TOK_ABSENT
128%token TOK_ABSTRACT_SYNTAX
129%token TOK_ALL
130%token TOK_ANY
131%token TOK_APPLICATION
132%token TOK_AUTOMATIC
133%token TOK_BEGIN
134%token TOK_BIT
135%token TOK_BMPString
136%token TOK_BOOLEAN
137%token TOK_BY
138%token TOK_CHARACTER
139%token TOK_CHOICE
140%token TOK_CLASS
141%token TOK_COMPONENT
142%token TOK_COMPONENTS
143%token TOK_CONSTRAINED
144%token TOK_CONTAINING
145%token TOK_DEFAULT
146%token TOK_DEFINITIONS
147%token TOK_DEFINED
148%token TOK_EMBEDDED
149%token TOK_ENCODED
vlm9283dbe2004-08-18 04:59:12 +0000150%token TOK_ENCODING_CONTROL
vlmfa67ddc2004-06-03 03:38:44 +0000151%token TOK_END
152%token TOK_ENUMERATED
153%token TOK_EXPLICIT
154%token TOK_EXPORTS
155%token TOK_EXTENSIBILITY
156%token TOK_EXTERNAL
157%token TOK_FALSE
158%token TOK_FROM
159%token TOK_GeneralizedTime
160%token TOK_GeneralString
161%token TOK_GraphicString
162%token TOK_IA5String
163%token TOK_IDENTIFIER
164%token TOK_IMPLICIT
165%token TOK_IMPLIED
166%token TOK_IMPORTS
167%token TOK_INCLUDES
168%token TOK_INSTANCE
vlm9283dbe2004-08-18 04:59:12 +0000169%token TOK_INSTRUCTIONS
vlmfa67ddc2004-06-03 03:38:44 +0000170%token TOK_INTEGER
171%token TOK_ISO646String
172%token TOK_MAX
173%token TOK_MIN
174%token TOK_MINUS_INFINITY
175%token TOK_NULL
176%token TOK_NumericString
177%token TOK_OBJECT
178%token TOK_ObjectDescriptor
179%token TOK_OCTET
180%token TOK_OF
181%token TOK_OPTIONAL
182%token TOK_PATTERN
183%token TOK_PDV
184%token TOK_PLUS_INFINITY
185%token TOK_PRESENT
186%token TOK_PrintableString
187%token TOK_PRIVATE
188%token TOK_REAL
189%token TOK_RELATIVE_OID
190%token TOK_SEQUENCE
191%token TOK_SET
192%token TOK_SIZE
193%token TOK_STRING
194%token TOK_SYNTAX
195%token TOK_T61String
196%token TOK_TAGS
197%token TOK_TeletexString
198%token TOK_TRUE
199%token TOK_TYPE_IDENTIFIER
200%token TOK_UNIQUE
201%token TOK_UNIVERSAL
202%token TOK_UniversalString
203%token TOK_UTCTime
204%token TOK_UTF8String
205%token TOK_VideotexString
206%token TOK_VisibleString
207%token TOK_WITH
208
vlmfa67ddc2004-06-03 03:38:44 +0000209%left TOK_EXCEPT
vlm9283dbe2004-08-18 04:59:12 +0000210%left '^' TOK_INTERSECTION
211%left '|' TOK_UNION
vlmfa67ddc2004-06-03 03:38:44 +0000212
213/* Misc tags */
214%token TOK_TwoDots /* .. */
215%token TOK_ThreeDots /* ... */
vlmfa67ddc2004-06-03 03:38:44 +0000216
217
218/*
219 * Types defined herein.
220 */
221%type <a_grammar> ModuleList
222%type <a_module> ModuleSpecification
223%type <a_module> ModuleSpecificationBody
224%type <a_module> ModuleSpecificationElement
225%type <a_module> optModuleSpecificationBody /* Optional */
226%type <a_module_flags> optModuleSpecificationFlags
227%type <a_module_flags> ModuleSpecificationFlags /* Set of FL */
228%type <a_module_flags> ModuleSpecificationFlag /* Single FL */
229%type <a_module> ImportsDefinition
230%type <a_module> ImportsBundleSet
231%type <a_xports> ImportsBundle
232%type <a_xports> ImportsList
233%type <a_xports> ExportsDefinition
234%type <a_xports> ExportsBody
235%type <a_expr> ImportsElement
236%type <a_expr> ExportsElement
vlmfa67ddc2004-06-03 03:38:44 +0000237%type <a_expr> ExtensionAndException
vlmec8f6812004-08-22 03:19:54 +0000238%type <a_expr> TypeDeclaration
vlm066dc102005-08-22 12:23:54 +0000239%type <a_expr> TypeDeclarationSet
vlmfa67ddc2004-06-03 03:38:44 +0000240%type <a_ref> ComplexTypeReference
241%type <a_ref> ComplexTypeReferenceAmpList
242%type <a_refcomp> ComplexTypeReferenceElement
243%type <a_refcomp> ClassFieldIdentifier
244%type <a_refcomp> ClassFieldName
vlmdc7cf042006-03-09 08:49:26 +0000245%type <a_expr> FieldSpec
246%type <a_ref> FieldName
247%type <a_ref> DefinedObjectClass
vlmfa67ddc2004-06-03 03:38:44 +0000248%type <a_expr> ClassField
vlmdc7cf042006-03-09 08:49:26 +0000249%type <a_expr> ObjectClass
vlmec8f6812004-08-22 03:19:54 +0000250%type <a_expr> Type
vlmfa67ddc2004-06-03 03:38:44 +0000251%type <a_expr> DataTypeReference /* Type1 ::= Type2 */
252%type <a_expr> DefinedTypeRef
253%type <a_expr> ValueSetDefinition /* Val INTEGER ::= {1|2} */
254%type <a_expr> ValueDefinition /* val INTEGER ::= 1*/
vlmc94e28f2004-09-15 11:59:51 +0000255%type <a_value> Value
vlmfa67ddc2004-06-03 03:38:44 +0000256%type <a_value> DefinedValue
257%type <a_value> SignedNumber
vlm0aa86902004-10-12 23:26:53 +0000258%type <a_expr> optComponentTypeLists
vlmec8f6812004-08-22 03:19:54 +0000259%type <a_expr> ComponentTypeLists
260%type <a_expr> ComponentType
261%type <a_expr> AlternativeTypeLists
262%type <a_expr> AlternativeType
vlmfa67ddc2004-06-03 03:38:44 +0000263//%type <a_expr> optUniverationDefinition
264%type <a_expr> UniverationDefinition
265%type <a_expr> UniverationList
266%type <a_expr> UniverationElement
267%type <tv_str> TypeRefName
268%type <tv_str> ObjectClassReference
vlmfa67ddc2004-06-03 03:38:44 +0000269%type <tv_str> Identifier
vlm151c0b22004-09-22 16:03:36 +0000270%type <tv_str> optIdentifier
vlmfa67ddc2004-06-03 03:38:44 +0000271%type <a_parg> ParameterArgumentName
272%type <a_plist> ParameterArgumentList
273%type <a_expr> ActualParameter
274%type <a_expr> ActualParameterList
vlm04a08da2005-08-12 10:06:17 +0000275%type <a_aid> AssignedIdentifier /* OID/DefinedValue */
vlmfa67ddc2004-06-03 03:38:44 +0000276%type <a_oid> ObjectIdentifier /* OID */
277%type <a_oid> optObjectIdentifier /* Optional OID */
278%type <a_oid> ObjectIdentifierBody
279%type <a_oid_arc> ObjectIdentifierElement
280%type <a_expr> BasicType
281%type <a_type> BasicTypeId
282%type <a_type> BasicTypeId_UniverationCompatible
283%type <a_type> BasicString
284%type <tv_opaque> Opaque
285//%type <tv_opaque> StringValue
vlm2728a8d2005-01-23 09:51:44 +0000286%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
287%type <a_tag> TagClass TagTypeValue TagPlicit
vlmfa67ddc2004-06-03 03:38:44 +0000288%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
289%type <a_constr> optConstraints
vlm5f0128b2004-08-20 13:25:29 +0000290%type <a_constr> Constraints
vlm9283dbe2004-08-18 04:59:12 +0000291%type <a_constr> SetOfConstraints
292%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
293%type <a_constr> ElementSetSpec /* 1..2,...,3 */
vlmfa67ddc2004-06-03 03:38:44 +0000294%type <a_constr> ConstraintSubtypeElement /* 1..2 */
vlmfa67ddc2004-06-03 03:38:44 +0000295%type <a_constr> SimpleTableConstraint
296%type <a_constr> TableConstraint
vlm7bbdc9f2005-03-28 15:01:27 +0000297%type <a_constr> InnerTypeConstraint
vlmfa67ddc2004-06-03 03:38:44 +0000298%type <a_constr> WithComponentsList
299%type <a_constr> WithComponentsElement
300%type <a_constr> ComponentRelationConstraint
301%type <a_constr> AtNotationList
302%type <a_ref> AtNotationElement
vlma6a12e32005-03-20 12:58:00 +0000303%type <a_value> SingleValue
304%type <a_value> ContainedSubtype
vlmfa67ddc2004-06-03 03:38:44 +0000305%type <a_ctype> ConstraintSpec
306%type <a_ctype> ConstraintRangeSpec
vlme1e6ed82005-03-24 14:26:38 +0000307%type <a_value> RestrictedCharacterStringValue
vlmfa67ddc2004-06-03 03:38:44 +0000308%type <a_wsynt> optWithSyntax
309%type <a_wsynt> WithSyntax
310%type <a_wsynt> WithSyntaxFormat
311%type <a_wchunk> WithSyntaxFormatToken
312%type <a_marker> optMarker Marker
313%type <a_int> optUnique
314%type <a_pres> optPresenceConstraint PresenceConstraint
315%type <tv_str> ComponentIdList
vlm177a5b62005-09-05 05:17:57 +0000316%type <a_int> NSTD_IndirectMarker
vlmfa67ddc2004-06-03 03:38:44 +0000317
318
319%%
320
321
322ParsedGrammar:
323 ModuleList {
324 *(void **)param = $1;
325 }
326 ;
327
328ModuleList:
329 ModuleSpecification {
330 $$ = asn1p_new();
331 checkmem($$);
332 TQ_ADD(&($$->modules), $1, mod_next);
333 }
334 | ModuleList ModuleSpecification {
335 $$ = $1;
336 TQ_ADD(&($$->modules), $2, mod_next);
337 }
338 ;
339
340/*
341 * ASN module definition.
342 * === EXAMPLE ===
343 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
344 * BEGIN
345 * ...
346 * END
347 * === EOF ===
348 */
349
350ModuleSpecification:
351 TypeRefName optObjectIdentifier TOK_DEFINITIONS
352 optModuleSpecificationFlags
353 TOK_PPEQ TOK_BEGIN
354 optModuleSpecificationBody
355 TOK_END {
356
357 if($7) {
358 $$ = $7;
359 } else {
360 /* There's a chance that a module is just plain empty */
361 $$ = asn1p_module_new();
362 }
363 checkmem($$);
364
vlm04a08da2005-08-12 10:06:17 +0000365 $$->ModuleName = $1;
vlmfa67ddc2004-06-03 03:38:44 +0000366 $$->module_oid = $2;
367 $$->module_flags = $4;
368 }
369 ;
370
371/*
372 * Object Identifier Definition
373 * { iso member-body(2) 3 }
374 */
375optObjectIdentifier:
376 { $$ = 0; }
377 | ObjectIdentifier { $$ = $1; }
378 ;
379
380ObjectIdentifier:
381 '{' ObjectIdentifierBody '}' {
382 $$ = $2;
383 }
384 | '{' '}' {
385 $$ = 0;
386 }
387 ;
388
389ObjectIdentifierBody:
390 ObjectIdentifierElement {
391 $$ = asn1p_oid_new();
392 asn1p_oid_add_arc($$, &$1);
393 if($1.name)
394 free($1.name);
395 }
396 | ObjectIdentifierBody ObjectIdentifierElement {
397 $$ = $1;
398 asn1p_oid_add_arc($$, &$2);
399 if($2.name)
400 free($2.name);
401 }
402 ;
403
404ObjectIdentifierElement:
405 Identifier { /* iso */
406 $$.name = $1;
407 $$.number = -1;
408 }
409 | Identifier '(' TOK_number ')' { /* iso(1) */
410 $$.name = $1;
411 $$.number = $3;
412 }
413 | TOK_number { /* 1 */
414 $$.name = 0;
415 $$.number = $1;
416 }
417 ;
418
419/*
420 * Optional module flags.
421 */
422optModuleSpecificationFlags:
423 { $$ = MSF_NOFLAGS; }
424 | ModuleSpecificationFlags {
425 $$ = $1;
426 }
427 ;
428
429/*
430 * Module flags.
431 */
432ModuleSpecificationFlags:
433 ModuleSpecificationFlag {
434 $$ = $1;
435 }
436 | ModuleSpecificationFlags ModuleSpecificationFlag {
437 $$ = $1 | $2;
438 }
439 ;
440
441/*
442 * Single module flag.
443 */
444ModuleSpecificationFlag:
445 TOK_EXPLICIT TOK_TAGS {
446 $$ = MSF_EXPLICIT_TAGS;
447 }
448 | TOK_IMPLICIT TOK_TAGS {
449 $$ = MSF_IMPLICIT_TAGS;
450 }
451 | TOK_AUTOMATIC TOK_TAGS {
452 $$ = MSF_AUTOMATIC_TAGS;
453 }
454 | TOK_EXTENSIBILITY TOK_IMPLIED {
455 $$ = MSF_EXTENSIBILITY_IMPLIED;
456 }
vlm9283dbe2004-08-18 04:59:12 +0000457 /* EncodingReferenceDefault */
458 | TOK_capitalreference TOK_INSTRUCTIONS {
459 /* X.680Amd1 specifies TAG and XER */
460 if(strcmp($1, "TAG") == 0) {
461 $$ = MSF_TAG_INSTRUCTIONS;
462 } else if(strcmp($1, "XER") == 0) {
463 $$ = MSF_XER_INSTRUCTIONS;
464 } else {
465 fprintf(stderr,
466 "WARNING: %s INSTRUCTIONS at line %d: "
467 "Unrecognized encoding reference\n",
468 $1, yylineno);
469 $$ = MSF_unk_INSTRUCTIONS;
470 }
471 free($1);
472 }
vlmfa67ddc2004-06-03 03:38:44 +0000473 ;
474
475/*
476 * Optional module body.
477 */
478optModuleSpecificationBody:
479 { $$ = 0; }
480 | ModuleSpecificationBody {
vlmfa67ddc2004-06-03 03:38:44 +0000481 $$ = $1;
482 }
483 ;
484
485/*
486 * ASN.1 Module body.
487 */
488ModuleSpecificationBody:
489 ModuleSpecificationElement {
490 $$ = $1;
491 }
492 | ModuleSpecificationBody ModuleSpecificationElement {
493 $$ = $1;
494
vlm9283dbe2004-08-18 04:59:12 +0000495 /* Behave well when one of them is skipped. */
496 if(!($1)) {
497 if($2) $$ = $2;
498 break;
499 }
500
vlmfa67ddc2004-06-03 03:38:44 +0000501#ifdef MY_IMPORT
502#error MY_IMPORT DEFINED ELSEWHERE!
503#endif
504#define MY_IMPORT(foo,field) do { \
vlm97ed7152004-08-13 12:31:09 +0000505 while(TQ_FIRST(&($2->foo))) { \
vlmfa67ddc2004-06-03 03:38:44 +0000506 TQ_ADD(&($$->foo), \
507 TQ_REMOVE(&($2->foo), field), \
508 field); \
vlm97ed7152004-08-13 12:31:09 +0000509 } \
510 assert(TQ_FIRST(&($2->foo)) == 0); \
511 } while(0)
vlmfa67ddc2004-06-03 03:38:44 +0000512
513 MY_IMPORT(imports, xp_next);
514 MY_IMPORT(exports, xp_next);
515 MY_IMPORT(members, next);
516#undef MY_IMPORT
517
518 }
519 ;
520
521/*
522 * One of the elements of ASN.1 module specification.
523 */
524ModuleSpecificationElement:
525 ImportsDefinition {
526 $$ = $1;
527 }
528 | ExportsDefinition {
529 $$ = asn1p_module_new();
530 checkmem($$);
531 if($1) {
532 TQ_ADD(&($$->exports), $1, xp_next);
533 } else {
534 /* "EXPORTS ALL;" ? */
535 }
536 }
537 | DataTypeReference {
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 }
544 | ValueDefinition {
545 $$ = asn1p_module_new();
546 checkmem($$);
547 assert($1->expr_type != A1TC_INVALID);
548 assert($1->meta_type != AMT_INVALID);
549 TQ_ADD(&($$->members), $1, next);
550 }
551 /*
552 * Value set definition
553 * === EXAMPLE ===
554 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
555 * === EOF ===
556 */
557 | ValueSetDefinition {
558 $$ = asn1p_module_new();
559 checkmem($$);
560 assert($1->expr_type != A1TC_INVALID);
561 assert($1->meta_type != AMT_INVALID);
562 TQ_ADD(&($$->members), $1, next);
563 }
vlm9283dbe2004-08-18 04:59:12 +0000564 | TOK_ENCODING_CONTROL TOK_capitalreference
565 { asn1p_lexer_hack_push_encoding_control(); }
566 {
567 fprintf(stderr,
568 "WARNING: ENCODING-CONTROL %s "
569 "specification at line %d ignored\n",
570 $2, yylineno);
571 free($2);
572 $$ = 0;
573 }
vlmfa67ddc2004-06-03 03:38:44 +0000574
575 /*
576 * Erroneous attemps
577 */
578 | BasicString {
579 return yyerror(
vlm1ac75e72005-11-26 11:21:55 +0000580 "Attempt to redefine a standard basic string type, "
581 "please comment out or remove this type redefinition.");
vlmfa67ddc2004-06-03 03:38:44 +0000582 }
583 ;
584
585/*
586 * === EXAMPLE ===
587 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
588 * === EOF ===
589 */
590ImportsDefinition:
591 TOK_IMPORTS ImportsBundleSet ';' {
vlm04a08da2005-08-12 10:06:17 +0000592 if(!saved_aid && 0)
593 return yyerror("Unterminated IMPORTS FROM, "
594 "expected semicolon ';'");
595 saved_aid = 0;
vlmfa67ddc2004-06-03 03:38:44 +0000596 $$ = $2;
597 }
598 /*
599 * Some error cases.
600 */
601 | TOK_IMPORTS TOK_FROM /* ... */ {
602 return yyerror("Empty IMPORTS list");
603 }
604 ;
605
606ImportsBundleSet:
607 ImportsBundle {
608 $$ = asn1p_module_new();
609 checkmem($$);
610 TQ_ADD(&($$->imports), $1, xp_next);
611 }
612 | ImportsBundleSet ImportsBundle {
613 $$ = $1;
614 TQ_ADD(&($$->imports), $2, xp_next);
615 }
616 ;
617
vlm04a08da2005-08-12 10:06:17 +0000618AssignedIdentifier:
619 { memset(&$$, 0, sizeof($$)); }
620 | ObjectIdentifier { $$.oid = $1; };
621 /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
622
vlmfa67ddc2004-06-03 03:38:44 +0000623ImportsBundle:
vlm04a08da2005-08-12 10:06:17 +0000624 ImportsList TOK_FROM TypeRefName AssignedIdentifier {
vlmfa67ddc2004-06-03 03:38:44 +0000625 $$ = $1;
vlm04a08da2005-08-12 10:06:17 +0000626 $$->fromModuleName = $3;
627 $$->identifier = $4;
628 /* This stupid thing is used for look-back hack. */
629 saved_aid = $$->identifier.oid ? 0 : &($$->identifier);
vlmfa67ddc2004-06-03 03:38:44 +0000630 checkmem($$);
631 }
632 ;
633
634ImportsList:
635 ImportsElement {
636 $$ = asn1p_xports_new();
637 checkmem($$);
638 TQ_ADD(&($$->members), $1, next);
639 }
640 | ImportsList ',' ImportsElement {
641 $$ = $1;
642 TQ_ADD(&($$->members), $3, next);
643 }
644 ;
645
646ImportsElement:
647 TypeRefName {
648 $$ = asn1p_expr_new(yylineno);
649 checkmem($$);
650 $$->Identifier = $1;
651 $$->expr_type = A1TC_REFERENCE;
652 }
vlm0aa86902004-10-12 23:26:53 +0000653 | TypeRefName '{' '}' { /* Completely equivalent to above */
654 $$ = asn1p_expr_new(yylineno);
655 checkmem($$);
656 $$->Identifier = $1;
657 $$->expr_type = A1TC_REFERENCE;
658 }
vlmfa67ddc2004-06-03 03:38:44 +0000659 | Identifier {
660 $$ = asn1p_expr_new(yylineno);
661 checkmem($$);
662 $$->Identifier = $1;
663 $$->expr_type = A1TC_REFERENCE;
664 }
665 ;
666
667ExportsDefinition:
668 TOK_EXPORTS ExportsBody ';' {
669 $$ = $2;
670 }
671 | TOK_EXPORTS TOK_ALL ';' {
672 $$ = 0;
673 }
674 | TOK_EXPORTS ';' {
675 /* Empty EXPORTS clause effectively prohibits export. */
676 $$ = asn1p_xports_new();
677 checkmem($$);
678 }
679 ;
680
681ExportsBody:
682 ExportsElement {
683 $$ = asn1p_xports_new();
684 assert($$);
685 TQ_ADD(&($$->members), $1, next);
686 }
687 | ExportsBody ',' ExportsElement {
688 $$ = $1;
689 TQ_ADD(&($$->members), $3, next);
690 }
691 ;
692
693ExportsElement:
694 TypeRefName {
695 $$ = asn1p_expr_new(yylineno);
696 checkmem($$);
697 $$->Identifier = $1;
698 $$->expr_type = A1TC_EXPORTVAR;
699 }
vlm0aa86902004-10-12 23:26:53 +0000700 | TypeRefName '{' '}' {
701 $$ = asn1p_expr_new(yylineno);
702 checkmem($$);
703 $$->Identifier = $1;
704 $$->expr_type = A1TC_EXPORTVAR;
705 }
vlmfa67ddc2004-06-03 03:38:44 +0000706 | Identifier {
707 $$ = asn1p_expr_new(yylineno);
708 checkmem($$);
709 $$->Identifier = $1;
710 $$->expr_type = A1TC_EXPORTVAR;
711 }
712 ;
713
714
715ValueSetDefinition:
vlm7388db02005-03-31 21:48:13 +0000716 TypeRefName DefinedTypeRef TOK_PPEQ
717 '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
vlmfa67ddc2004-06-03 03:38:44 +0000718 $$ = $2;
719 assert($$->Identifier == 0);
720 $$->Identifier = $1;
721 $$->meta_type = AMT_VALUESET;
vlm7388db02005-03-31 21:48:13 +0000722 // take care of ValueSet body
vlmfa67ddc2004-06-03 03:38:44 +0000723 }
724 ;
725
726DefinedTypeRef:
727 ComplexTypeReference {
728 $$ = asn1p_expr_new(yylineno);
729 checkmem($$);
730 $$->reference = $1;
731 $$->expr_type = A1TC_REFERENCE;
732 $$->meta_type = AMT_TYPEREF;
733 }
734 | BasicTypeId {
735 $$ = asn1p_expr_new(yylineno);
736 checkmem($$);
737 $$->expr_type = $1;
738 $$->meta_type = AMT_TYPE;
739 }
740 ;
741
vlmfa67ddc2004-06-03 03:38:44 +0000742/*
743 * Data Type Reference.
744 * === EXAMPLE ===
745 * Type3 ::= CHOICE { a Type1, b Type 2 }
746 * === EOF ===
747 */
vlmfa67ddc2004-06-03 03:38:44 +0000748DataTypeReference:
749 /*
750 * Optionally tagged type definition.
751 */
vlmdc7cf042006-03-09 08:49:26 +0000752 TypeRefName TOK_PPEQ Type {
vlmfce48a42004-09-14 02:36:39 +0000753 $$ = $3;
vlmfa67ddc2004-06-03 03:38:44 +0000754 $$->Identifier = $1;
vlmfa67ddc2004-06-03 03:38:44 +0000755 assert($$->expr_type);
756 assert($$->meta_type);
757 }
vlmdc7cf042006-03-09 08:49:26 +0000758 | TypeRefName TOK_PPEQ ObjectClass {
vlmfa67ddc2004-06-03 03:38:44 +0000759 $$ = $3;
760 $$->Identifier = $1;
761 assert($$->expr_type == A1TC_CLASSDEF);
vlmdc7cf042006-03-09 08:49:26 +0000762 assert($$->meta_type == AMT_OBJECTCLASS);
vlmfa67ddc2004-06-03 03:38:44 +0000763 }
764 /*
765 * Parametrized <Type> declaration:
766 * === EXAMPLE ===
767 * SIGNED { ToBeSigned } ::= SEQUENCE {
768 * toBeSigned ToBeSigned,
769 * algorithm AlgorithmIdentifier,
770 * signature BIT STRING
771 * }
772 * === EOF ===
773 */
vlmec8f6812004-08-22 03:19:54 +0000774 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
vlmfa67ddc2004-06-03 03:38:44 +0000775 $$ = $6;
776 assert($$->Identifier == 0);
777 $$->Identifier = $1;
778 $$->params = $3;
779 $$->meta_type = AMT_PARAMTYPE;
780 }
781 ;
782
783ParameterArgumentList:
784 ParameterArgumentName {
785 int ret;
786 $$ = asn1p_paramlist_new(yylineno);
787 checkmem($$);
788 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
789 checkmem(ret == 0);
790 if($1.governor) asn1p_ref_free($1.governor);
791 if($1.argument) free($1.argument);
792 }
793 | ParameterArgumentList ',' ParameterArgumentName {
794 int ret;
795 $$ = $1;
796 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
797 checkmem(ret == 0);
798 if($3.governor) asn1p_ref_free($3.governor);
799 if($3.argument) free($3.argument);
800 }
801 ;
802
803ParameterArgumentName:
804 TypeRefName {
805 $$.governor = NULL;
806 $$.argument = $1;
807 }
808 | TypeRefName ':' Identifier {
809 int ret;
810 $$.governor = asn1p_ref_new(yylineno);
811 ret = asn1p_ref_add_component($$.governor, $1, 0);
812 checkmem(ret == 0);
813 $$.argument = $3;
814 }
vlm4053ca52005-02-18 16:34:21 +0000815 | TypeRefName ':' TypeRefName {
816 int ret;
817 $$.governor = asn1p_ref_new(yylineno);
818 ret = asn1p_ref_add_component($$.governor, $1, 0);
819 checkmem(ret == 0);
820 $$.argument = $3;
821 }
vlmfa67ddc2004-06-03 03:38:44 +0000822 | BasicTypeId ':' Identifier {
823 int ret;
824 $$.governor = asn1p_ref_new(yylineno);
825 ret = asn1p_ref_add_component($$.governor,
826 ASN_EXPR_TYPE2STR($1), 1);
827 checkmem(ret == 0);
828 $$.argument = $3;
829 }
830 ;
831
832ActualParameterList:
833 ActualParameter {
834 $$ = asn1p_expr_new(yylineno);
835 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000836 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000837 }
838 | ActualParameterList ',' ActualParameter {
839 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000840 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000841 }
842 ;
843
844ActualParameter:
vlmec8f6812004-08-22 03:19:54 +0000845 Type {
vlmfa67ddc2004-06-03 03:38:44 +0000846 $$ = $1;
847 }
848 | Identifier {
849 $$ = asn1p_expr_new(yylineno);
850 checkmem($$);
851 $$->Identifier = $1;
852 $$->expr_type = A1TC_REFERENCE;
853 $$->meta_type = AMT_VALUE;
854 }
855 ;
856
857/*
vlm4053ca52005-02-18 16:34:21 +0000858 | '{' ActualParameter '}' {
859 $$ = asn1p_expr_new(yylineno);
860 checkmem($$);
861 asn1p_expr_add($$, $2);
862 $$->expr_type = A1TC_PARAMETRIZED;
863 $$->meta_type = AMT_TYPE;
864 }
865 ;
866*/
867
868/*
vlmfa67ddc2004-06-03 03:38:44 +0000869 * A collection of constructed data type members.
870 */
vlm0aa86902004-10-12 23:26:53 +0000871optComponentTypeLists:
872 { $$ = asn1p_expr_new(yylineno); }
873 | ComponentTypeLists { $$ = $1; };
874
vlmec8f6812004-08-22 03:19:54 +0000875ComponentTypeLists:
876 ComponentType {
vlmfa67ddc2004-06-03 03:38:44 +0000877 $$ = asn1p_expr_new(yylineno);
878 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000879 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000880 }
vlmec8f6812004-08-22 03:19:54 +0000881 | ComponentTypeLists ',' ComponentType {
vlmfa67ddc2004-06-03 03:38:44 +0000882 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000883 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000884 }
885 ;
886
vlmec8f6812004-08-22 03:19:54 +0000887ComponentType:
vlmfce48a42004-09-14 02:36:39 +0000888 Identifier Type optMarker {
vlmec8f6812004-08-22 03:19:54 +0000889 $$ = $2;
890 assert($$->Identifier == 0);
vlmfce48a42004-09-14 02:36:39 +0000891 $$->Identifier = $1;
vlm177a5b62005-09-05 05:17:57 +0000892 $3.flags |= $$->marker.flags;
vlmec8f6812004-08-22 03:19:54 +0000893 $$->marker = $3;
894 }
vlm177a5b62005-09-05 05:17:57 +0000895 | Type optMarker {
896 $$ = $1;
897 $2.flags |= $$->marker.flags;
898 $$->marker = $2;
899 _fixup_anonymous_identifier($$);
900 }
vlmec8f6812004-08-22 03:19:54 +0000901 | TOK_COMPONENTS TOK_OF Type {
902 $$ = asn1p_expr_new(yylineno);
903 checkmem($$);
904 $$->meta_type = $3->meta_type;
905 $$->expr_type = A1TC_COMPONENTS_OF;
vlm6a02a8a2004-09-08 00:28:11 +0000906 asn1p_expr_add($$, $3);
vlmec8f6812004-08-22 03:19:54 +0000907 }
908 | ExtensionAndException {
909 $$ = $1;
910 }
911 ;
912
913AlternativeTypeLists:
914 AlternativeType {
915 $$ = asn1p_expr_new(yylineno);
916 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000917 asn1p_expr_add($$, $1);
vlmec8f6812004-08-22 03:19:54 +0000918 }
919 | AlternativeTypeLists ',' AlternativeType {
920 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000921 asn1p_expr_add($$, $3);
vlmec8f6812004-08-22 03:19:54 +0000922 }
923 ;
924
925AlternativeType:
vlmfce48a42004-09-14 02:36:39 +0000926 Identifier Type {
vlmec8f6812004-08-22 03:19:54 +0000927 $$ = $2;
928 assert($$->Identifier == 0);
vlmfce48a42004-09-14 02:36:39 +0000929 $$->Identifier = $1;
vlmec8f6812004-08-22 03:19:54 +0000930 }
931 | ExtensionAndException {
932 $$ = $1;
933 }
vlm5d89c3d2005-08-13 09:07:11 +0000934 | Type {
935 $$ = $1;
936 _fixup_anonymous_identifier($$);
937 }
vlmec8f6812004-08-22 03:19:54 +0000938 ;
939
vlmdc7cf042006-03-09 08:49:26 +0000940ObjectClass:
941 TOK_CLASS '{' FieldSpec '}' optWithSyntax {
vlmfa67ddc2004-06-03 03:38:44 +0000942 $$ = $3;
943 checkmem($$);
944 $$->with_syntax = $5;
945 assert($$->expr_type == A1TC_CLASSDEF);
vlmdc7cf042006-03-09 08:49:26 +0000946 assert($$->meta_type == AMT_OBJECTCLASS);
vlmfa67ddc2004-06-03 03:38:44 +0000947 }
948 ;
949
950optUnique:
951 { $$ = 0; }
952 | TOK_UNIQUE { $$ = 1; }
953 ;
954
vlmdc7cf042006-03-09 08:49:26 +0000955FieldSpec:
vlmfa67ddc2004-06-03 03:38:44 +0000956 ClassField {
957 $$ = asn1p_expr_new(yylineno);
958 checkmem($$);
959 $$->expr_type = A1TC_CLASSDEF;
vlmdc7cf042006-03-09 08:49:26 +0000960 $$->meta_type = AMT_OBJECTCLASS;
vlm6a02a8a2004-09-08 00:28:11 +0000961 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000962 }
vlmdc7cf042006-03-09 08:49:26 +0000963 | FieldSpec ',' ClassField {
vlmfa67ddc2004-06-03 03:38:44 +0000964 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000965 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000966 }
967 ;
968
vlmdc7cf042006-03-09 08:49:26 +0000969 /* X.681 */
vlmfa67ddc2004-06-03 03:38:44 +0000970ClassField:
vlmdc7cf042006-03-09 08:49:26 +0000971
972 /* TypeFieldSpec ::= typefieldreference TypeOptionalitySpec? */
973 TOK_typefieldreference optMarker {
vlmfa67ddc2004-06-03 03:38:44 +0000974 $$ = asn1p_expr_new(yylineno);
975 checkmem($$);
vlmdc7cf042006-03-09 08:49:26 +0000976 $$->Identifier = $1;
vlmfa67ddc2004-06-03 03:38:44 +0000977 $$->meta_type = AMT_OBJECTFIELD;
vlmdc7cf042006-03-09 08:49:26 +0000978 $$->expr_type = A1TC_CLASSFIELD_TFS; /* TypeFieldSpec */
vlmfa67ddc2004-06-03 03:38:44 +0000979 $$->marker = $2;
980 }
vlmdc7cf042006-03-09 08:49:26 +0000981
982 /* FixedTypeValueFieldSpec ::= valuefieldreference Type UNIQUE ? ValueOptionalitySpec ? */
983 | TOK_valuefieldreference Type optUnique optMarker {
984 $$ = asn1p_expr_new(yylineno);
985 $$->Identifier = $1;
986 $$->meta_type = AMT_OBJECTFIELD;
987 $$->expr_type = A1TC_CLASSFIELD_FTVFS; /* FixedTypeValueFieldSpec */
vlmbde35d42004-11-24 17:43:29 +0000988 $$->unique = $3;
vlmdc7cf042006-03-09 08:49:26 +0000989 $$->marker = $4;
990 asn1p_expr_add($$, $2);
vlmfa67ddc2004-06-03 03:38:44 +0000991 }
vlmdc7cf042006-03-09 08:49:26 +0000992
993 /* VariableTypeValueFieldSpec ::= valuefieldreference FieldName ValueOptionalitySpec ? */
994 | TOK_valuefieldreference FieldName optMarker {
995 $$ = asn1p_expr_new(yylineno);
996 $$->Identifier = $1;
997 $$->meta_type = AMT_OBJECTFIELD;
998 $$->expr_type = A1TC_CLASSFIELD_VTVFS;
999 $$->reference = $2;
1000 $$->marker = $3;
1001 }
1002
vlmdc7cf042006-03-09 08:49:26 +00001003 /* ObjectFieldSpec ::= objectfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1004 | TOK_valuefieldreference DefinedObjectClass optMarker {
vlmfa67ddc2004-06-03 03:38:44 +00001005 $$ = asn1p_expr_new(yylineno);
1006 checkmem($$);
vlmdc7cf042006-03-09 08:49:26 +00001007 $$->Identifier = $1;
1008 $$->reference = $2;
vlmfa67ddc2004-06-03 03:38:44 +00001009 $$->meta_type = AMT_OBJECTFIELD;
vlmdc7cf042006-03-09 08:49:26 +00001010 $$->expr_type = A1TC_CLASSFIELD_OFS;
1011 $$->marker = $3;
vlmfa67ddc2004-06-03 03:38:44 +00001012 }
vlmdc7cf042006-03-09 08:49:26 +00001013
vlmee7196e2006-03-09 09:08:49 +00001014 /* VariableTypeValueSetFieldSpec ::= valuesetfieldreference FieldName ValueOptionalitySpec ? */
1015 | TOK_typefieldreference FieldName optMarker {
vlmdc7cf042006-03-09 08:49:26 +00001016 $$ = asn1p_expr_new(yylineno);
vlmdc7cf042006-03-09 08:49:26 +00001017 $$->Identifier = $1;
vlmdc7cf042006-03-09 08:49:26 +00001018 $$->meta_type = AMT_OBJECTFIELD;
vlmee7196e2006-03-09 09:08:49 +00001019 $$->expr_type = A1TC_CLASSFIELD_VTVSFS;
1020 $$->reference = $2;
vlmdc7cf042006-03-09 08:49:26 +00001021 $$->marker = $3;
1022 }
1023
1024 /* FixedTypeValueSetFieldSpec ::= valuesetfieldreference Type ValueSetOptionalitySpec ? */
1025 | TOK_typefieldreference Type optMarker {
1026 $$ = asn1p_expr_new(yylineno);
1027 checkmem($$);
1028 $$->Identifier = $1;
1029 $$->meta_type = AMT_OBJECTFIELD;
1030 $$->expr_type = A1TC_CLASSFIELD_FTVSFS;
1031 asn1p_expr_add($$, $2);
1032 $$->marker = $3;
1033 }
1034
vlmee7196e2006-03-09 09:08:49 +00001035 /* ObjectSetFieldSpec ::= objectsetfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1036 | TOK_typefieldreference DefinedObjectClass optMarker {
1037 $$ = asn1p_expr_new(yylineno);
1038 checkmem($$);
1039 $$->Identifier = $1;
1040 $$->reference = $2;
1041 $$->meta_type = AMT_OBJECTFIELD;
1042 $$->expr_type = A1TC_CLASSFIELD_OSFS;
1043 $$->marker = $3;
1044 }
vlmfa67ddc2004-06-03 03:38:44 +00001045 ;
1046
1047optWithSyntax:
1048 { $$ = 0; }
1049 | WithSyntax {
1050 $$ = $1;
1051 }
1052 ;
1053
1054WithSyntax:
1055 TOK_WITH TOK_SYNTAX '{'
1056 { asn1p_lexer_hack_enable_with_syntax(); }
1057 WithSyntaxFormat
1058 '}' {
1059 $$ = $5;
1060 }
1061 ;
1062
1063WithSyntaxFormat:
1064 WithSyntaxFormatToken {
1065 $$ = asn1p_wsyntx_new();
1066 TQ_ADD(&($$->chunks), $1, next);
1067 }
1068 | WithSyntaxFormat WithSyntaxFormatToken {
1069 $$ = $1;
1070 TQ_ADD(&($$->chunks), $2, next);
1071 }
1072 ;
1073
1074WithSyntaxFormatToken:
1075 TOK_opaque {
1076 $$ = asn1p_wsyntx_chunk_frombuf($1.buf, $1.len, 0);
1077 }
1078 | ClassFieldIdentifier {
1079 asn1p_ref_t *ref;
1080 int ret;
1081 ref = asn1p_ref_new(yylineno);
1082 checkmem(ref);
1083 ret = asn1p_ref_add_component(ref, $1.name, $1.lex_type);
1084 checkmem(ret == 0);
1085 $$ = asn1p_wsyntx_chunk_fromref(ref, 0);
1086 }
1087 ;
1088
vlmfa67ddc2004-06-03 03:38:44 +00001089ExtensionAndException:
1090 TOK_ThreeDots {
vlm39e5ed72004-09-05 10:40:41 +00001091 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001092 checkmem($$);
1093 $$->Identifier = strdup("...");
1094 checkmem($$->Identifier);
1095 $$->expr_type = A1TC_EXTENSIBLE;
1096 $$->meta_type = AMT_TYPE;
1097 }
1098 | TOK_ThreeDots '!' DefinedValue {
vlm39e5ed72004-09-05 10:40:41 +00001099 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001100 checkmem($$);
1101 $$->Identifier = strdup("...");
1102 checkmem($$->Identifier);
1103 $$->value = $3;
1104 $$->expr_type = A1TC_EXTENSIBLE;
1105 $$->meta_type = AMT_TYPE;
1106 }
1107 | TOK_ThreeDots '!' SignedNumber {
vlm39e5ed72004-09-05 10:40:41 +00001108 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001109 checkmem($$);
1110 $$->Identifier = strdup("...");
1111 $$->value = $3;
1112 checkmem($$->Identifier);
1113 $$->expr_type = A1TC_EXTENSIBLE;
1114 $$->meta_type = AMT_TYPE;
1115 }
1116 ;
1117
vlmec8f6812004-08-22 03:19:54 +00001118Type:
vlmfce48a42004-09-14 02:36:39 +00001119 optTag TypeDeclaration optConstraints {
1120 $$ = $2;
1121 $$->tag = $1;
vlmec8f6812004-08-22 03:19:54 +00001122 /*
1123 * Outer constraint for SEQUENCE OF and SET OF applies
1124 * to the inner type.
1125 */
1126 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1127 || $$->expr_type == ASN_CONSTR_SET_OF) {
1128 assert(!TQ_FIRST(&($$->members))->constraints);
vlmfce48a42004-09-14 02:36:39 +00001129 TQ_FIRST(&($$->members))->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001130 } else {
1131 if($$->constraints) {
1132 assert(!$2);
1133 } else {
vlmfce48a42004-09-14 02:36:39 +00001134 $$->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001135 }
1136 }
vlm177a5b62005-09-05 05:17:57 +00001137 }
1138 ;
1139
1140NSTD_IndirectMarker:
1141 {
1142 $$ = asn1p_as_pointer ? EM_INDIRECT : 0;
1143 asn1p_as_pointer = 0;
vlmec8f6812004-08-22 03:19:54 +00001144 }
1145 ;
1146
1147TypeDeclaration:
vlm177a5b62005-09-05 05:17:57 +00001148 NSTD_IndirectMarker TypeDeclarationSet {
vlm066dc102005-08-22 12:23:54 +00001149 $$ = $2;
vlm177a5b62005-09-05 05:17:57 +00001150 $$->marker.flags |= $1;
1151
1152 if(($$->marker.flags & EM_INDIRECT)
1153 && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
1154 fprintf(stderr,
1155 "INFO: Directive <ASN1C:RepresentAsPointer> "
1156 "applied to %s at line %d\n",
1157 ASN_EXPR_TYPE2STR($$->expr_type)
1158 ? ASN_EXPR_TYPE2STR($$->expr_type)
1159 : "member",
1160 $$->_lineno
1161 );
1162 }
vlm066dc102005-08-22 12:23:54 +00001163 }
vlm177a5b62005-09-05 05:17:57 +00001164 ;
vlm066dc102005-08-22 12:23:54 +00001165
1166TypeDeclarationSet:
vlmfa67ddc2004-06-03 03:38:44 +00001167 BasicType {
1168 $$ = $1;
1169 }
vlm177a5b62005-09-05 05:17:57 +00001170 | TOK_CHOICE '{' AlternativeTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001171 $$ = $3;
1172 assert($$->expr_type == A1TC_INVALID);
1173 $$->expr_type = ASN_CONSTR_CHOICE;
1174 $$->meta_type = AMT_TYPE;
vlmfa67ddc2004-06-03 03:38:44 +00001175 }
vlm177a5b62005-09-05 05:17:57 +00001176 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001177 $$ = $3;
1178 assert($$->expr_type == A1TC_INVALID);
1179 $$->expr_type = ASN_CONSTR_SEQUENCE;
1180 $$->meta_type = AMT_TYPE;
1181 }
vlm177a5b62005-09-05 05:17:57 +00001182 | TOK_SET '{' optComponentTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001183 $$ = $3;
1184 assert($$->expr_type == A1TC_INVALID);
1185 $$->expr_type = ASN_CONSTR_SET;
1186 $$->meta_type = AMT_TYPE;
1187 }
vlm151c0b22004-09-22 16:03:36 +00001188 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
vlm39e5ed72004-09-05 10:40:41 +00001189 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001190 checkmem($$);
1191 $$->constraints = $2;
1192 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1193 $$->meta_type = AMT_TYPE;
vlm151c0b22004-09-22 16:03:36 +00001194 $6->Identifier = $4;
1195 $6->tag = $5;
1196 asn1p_expr_add($$, $6);
vlmec8f6812004-08-22 03:19:54 +00001197 }
vlm151c0b22004-09-22 16:03:36 +00001198 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
vlm39e5ed72004-09-05 10:40:41 +00001199 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001200 checkmem($$);
1201 $$->constraints = $2;
1202 $$->expr_type = ASN_CONSTR_SET_OF;
1203 $$->meta_type = AMT_TYPE;
vlm151c0b22004-09-22 16:03:36 +00001204 $6->Identifier = $4;
1205 $6->tag = $5;
1206 asn1p_expr_add($$, $6);
vlmec8f6812004-08-22 03:19:54 +00001207 }
1208 | TOK_ANY {
vlm39e5ed72004-09-05 10:40:41 +00001209 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001210 checkmem($$);
vlm044f7442004-09-04 04:49:21 +00001211 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001212 $$->meta_type = AMT_TYPE;
1213 }
1214 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1215 int ret;
vlm39e5ed72004-09-05 10:40:41 +00001216 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001217 checkmem($$);
1218 $$->reference = asn1p_ref_new(yylineno);
1219 ret = asn1p_ref_add_component($$->reference,
1220 $4, RLT_lowercase);
1221 checkmem(ret == 0);
vlm044f7442004-09-04 04:49:21 +00001222 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001223 $$->meta_type = AMT_TYPE;
1224 }
vlmfa67ddc2004-06-03 03:38:44 +00001225 /*
1226 * A parametrized assignment.
1227 */
1228 | TypeRefName '{' ActualParameterList '}' {
1229 int ret;
1230 $$ = $3;
1231 assert($$->expr_type == 0);
1232 assert($$->meta_type == 0);
1233 assert($$->reference == 0);
1234 $$->reference = asn1p_ref_new(yylineno);
1235 checkmem($$->reference);
1236 ret = asn1p_ref_add_component($$->reference, $1, RLT_UNKNOWN);
1237 checkmem(ret == 0);
1238 free($1);
1239 $$->expr_type = A1TC_PARAMETRIZED;
1240 $$->meta_type = AMT_TYPE;
1241 }
1242 /*
1243 * A DefinedType reference.
1244 * "CLASS1.&id.&id2"
1245 * or
1246 * "Module.Type"
1247 * or
1248 * "Module.identifier"
1249 * or
1250 * "Type"
1251 */
1252 | ComplexTypeReference {
1253 $$ = asn1p_expr_new(yylineno);
1254 checkmem($$);
1255 $$->reference = $1;
1256 $$->expr_type = A1TC_REFERENCE;
1257 $$->meta_type = AMT_TYPEREF;
1258 }
1259 | TOK_INSTANCE TOK_OF ComplexTypeReference {
1260 $$ = asn1p_expr_new(yylineno);
1261 checkmem($$);
1262 $$->reference = $3;
1263 $$->expr_type = A1TC_INSTANCE;
1264 $$->meta_type = AMT_TYPE;
1265 }
1266 ;
1267
1268/*
1269 * A type name consisting of several components.
1270 * === EXAMPLE ===
1271 * === EOF ===
1272 */
1273ComplexTypeReference:
1274 TOK_typereference {
1275 int ret;
1276 $$ = asn1p_ref_new(yylineno);
1277 checkmem($$);
1278 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1279 checkmem(ret == 0);
1280 free($1);
1281 }
1282 | TOK_typereference '.' TypeRefName {
1283 int ret;
1284 $$ = asn1p_ref_new(yylineno);
1285 checkmem($$);
1286 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1287 checkmem(ret == 0);
1288 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1289 checkmem(ret == 0);
1290 free($1);
1291 }
vlmc94e28f2004-09-15 11:59:51 +00001292 | ObjectClassReference '.' TypeRefName {
1293 int ret;
1294 $$ = asn1p_ref_new(yylineno);
1295 checkmem($$);
1296 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1297 checkmem(ret == 0);
1298 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1299 checkmem(ret == 0);
1300 free($1);
1301 }
vlmfa67ddc2004-06-03 03:38:44 +00001302 | TOK_typereference '.' Identifier {
1303 int ret;
1304 $$ = asn1p_ref_new(yylineno);
1305 checkmem($$);
1306 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1307 checkmem(ret == 0);
1308 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1309 checkmem(ret == 0);
1310 free($1);
1311 }
1312 | ObjectClassReference {
1313 int ret;
1314 $$ = asn1p_ref_new(yylineno);
1315 checkmem($$);
1316 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1317 free($1);
1318 checkmem(ret == 0);
1319 }
1320 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1321 int ret;
1322 $$ = $3;
1323 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1324 free($1);
1325 checkmem(ret == 0);
1326 /*
1327 * Move the last element infront.
1328 */
1329 {
1330 struct asn1p_ref_component_s tmp_comp;
1331 tmp_comp = $$->components[$$->comp_count-1];
1332 memmove(&$$->components[1],
1333 &$$->components[0],
1334 sizeof($$->components[0])
1335 * ($$->comp_count - 1));
1336 $$->components[0] = tmp_comp;
1337 }
1338 }
1339 ;
1340
1341ComplexTypeReferenceAmpList:
1342 ComplexTypeReferenceElement {
1343 int ret;
1344 $$ = asn1p_ref_new(yylineno);
1345 checkmem($$);
1346 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1347 free($1.name);
1348 checkmem(ret == 0);
1349 }
1350 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1351 int ret;
1352 $$ = $1;
1353 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1354 free($3.name);
1355 checkmem(ret == 0);
1356 }
1357 ;
1358
1359ComplexTypeReferenceElement: ClassFieldName;
1360ClassFieldIdentifier: ClassFieldName;
1361
1362ClassFieldName:
1363 /* "&Type1" */
1364 TOK_typefieldreference {
1365 $$.lex_type = RLT_AmpUppercase;
1366 $$.name = $1;
1367 }
1368 /* "&id" */
1369 | TOK_valuefieldreference {
1370 $$.lex_type = RLT_Amplowercase;
1371 $$.name = $1;
1372 }
1373 ;
1374
1375
vlmdc7cf042006-03-09 08:49:26 +00001376FieldName:
1377 /* "&Type1" */
1378 TOK_typefieldreference {
1379 $$ = asn1p_ref_new(yylineno);
1380 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1381 }
1382 | FieldName '.' TOK_typefieldreference {
1383 $$ = $$;
1384 asn1p_ref_add_component($$, $3, RLT_AmpUppercase);
1385 }
1386 | FieldName '.' TOK_valuefieldreference {
1387 $$ = $$;
1388 asn1p_ref_add_component($$, $3, RLT_Amplowercase);
1389 }
1390 ;
1391
1392DefinedObjectClass:
1393 TOK_capitalreference {
1394 $$ = asn1p_ref_new(yylineno);
1395 asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1396 }
vlmee7196e2006-03-09 09:08:49 +00001397/*
vlmdc7cf042006-03-09 08:49:26 +00001398 | TypeRefName '.' TOK_capitalreference {
1399 $$ = asn1p_ref_new(yylineno);
1400 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1401 asn1p_ref_add_component($$, $3, RLT_CAPITALS);
1402 }
vlmee7196e2006-03-09 09:08:49 +00001403*/
vlmdc7cf042006-03-09 08:49:26 +00001404 ;
1405
1406
vlmfa67ddc2004-06-03 03:38:44 +00001407/*
1408 * === EXAMPLE ===
1409 * value INTEGER ::= 1
1410 * === EOF ===
1411 */
1412ValueDefinition:
vlmc94e28f2004-09-15 11:59:51 +00001413 Identifier DefinedTypeRef TOK_PPEQ Value {
vlmfa67ddc2004-06-03 03:38:44 +00001414 $$ = $2;
1415 assert($$->Identifier == NULL);
1416 $$->Identifier = $1;
1417 $$->meta_type = AMT_VALUE;
1418 $$->value = $4;
1419 }
1420 ;
1421
vlmc94e28f2004-09-15 11:59:51 +00001422Value:
1423 Identifier ':' Value {
1424 $$ = asn1p_value_fromint(0);
1425 checkmem($$);
1426 $$->type = ATV_CHOICE_IDENTIFIER;
1427 $$->value.choice_identifier.identifier = $1;
1428 $$->value.choice_identifier.value = $3;
1429 }
vlmd30bc6c2005-03-24 16:27:02 +00001430 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
vlmfa67ddc2004-06-03 03:38:44 +00001431 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1432 checkmem($$);
1433 $$->type = ATV_UNPARSED;
1434 }
vlmc94e28f2004-09-15 11:59:51 +00001435 | TOK_NULL {
1436 $$ = asn1p_value_fromint(0);
1437 checkmem($$);
1438 $$->type = ATV_NULL;
1439 }
1440 | TOK_FALSE {
1441 $$ = asn1p_value_fromint(0);
1442 checkmem($$);
1443 $$->type = ATV_FALSE;
1444 }
1445 | TOK_TRUE {
1446 $$ = asn1p_value_fromint(0);
1447 checkmem($$);
1448 $$->type = ATV_TRUE;
1449 }
vlmfa67ddc2004-06-03 03:38:44 +00001450 | TOK_bstring {
1451 $$ = _convert_bitstring2binary($1, 'B');
1452 checkmem($$);
1453 }
1454 | TOK_hstring {
1455 $$ = _convert_bitstring2binary($1, 'H');
1456 checkmem($$);
1457 }
vlme1e6ed82005-03-24 14:26:38 +00001458 | RestrictedCharacterStringValue {
1459 $$ = $$;
vlmfa67ddc2004-06-03 03:38:44 +00001460 }
1461 | SignedNumber {
1462 $$ = $1;
1463 }
1464 | DefinedValue {
1465 $$ = $1;
1466 }
1467 ;
1468
1469DefinedValue:
1470 Identifier {
1471 asn1p_ref_t *ref;
1472 int ret;
1473 ref = asn1p_ref_new(yylineno);
1474 checkmem(ref);
1475 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1476 checkmem(ret == 0);
1477 $$ = asn1p_value_fromref(ref, 0);
1478 checkmem($$);
1479 free($1);
1480 }
1481 | TypeRefName '.' Identifier {
1482 asn1p_ref_t *ref;
1483 int ret;
1484 ref = asn1p_ref_new(yylineno);
1485 checkmem(ref);
1486 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1487 checkmem(ret == 0);
1488 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1489 checkmem(ret == 0);
1490 $$ = asn1p_value_fromref(ref, 0);
1491 checkmem($$);
1492 free($1);
1493 free($3);
1494 }
1495 ;
1496
vlme1e6ed82005-03-24 14:26:38 +00001497
1498RestrictedCharacterStringValue:
1499 TOK_cstring {
1500 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1501 checkmem($$);
1502 }
vlm2c8c44d2005-03-24 16:22:35 +00001503 | TOK_tuple {
1504 $$ = asn1p_value_fromint($1);
1505 checkmem($$);
1506 $$->type = ATV_TUPLE;
1507 }
1508 | TOK_quadruple {
1509 $$ = asn1p_value_fromint($1);
1510 checkmem($$);
1511 $$->type = ATV_QUADRUPLE;
1512 }
1513 /*
vlme1e6ed82005-03-24 14:26:38 +00001514 | '{' TOK_number ',' TOK_number '}' {
1515 asn1c_integer_t v = ($2 << 4) + $4;
1516 if($2 > 7) return yyerror("X.680:2003, #37.14 "
1517 "mandates 0..7 range for Tuple's TableColumn");
1518 if($4 > 15) return yyerror("X.680:2003, #37.14 "
1519 "mandates 0..15 range for Tuple's TableRow");
1520 $$ = asn1p_value_fromint(v);
1521 checkmem($$);
1522 $$->type = ATV_TUPLE;
1523 }
1524 | '{' TOK_number ',' TOK_number ',' TOK_number ',' TOK_number '}' {
1525 asn1c_integer_t v = ($2 << 24) | ($4 << 16) | ($6 << 8) | $8;
1526 if($2 > 127) return yyerror("X.680:2003, #37.12 "
1527 "mandates 0..127 range for Quadruple's Group");
1528 if($4 > 255) return yyerror("X.680:2003, #37.12 "
1529 "mandates 0..255 range for Quadruple's Plane");
1530 if($6 > 255) return yyerror("X.680:2003, #37.12 "
1531 "mandates 0..255 range for Quadruple's Row");
1532 if($8 > 255) return yyerror("X.680:2003, #37.12 "
1533 "mandates 0..255 range for Quadruple's Cell");
1534 $$ = asn1p_value_fromint(v);
1535 checkmem($$);
1536 $$->type = ATV_QUADRUPLE;
1537 }
vlm2c8c44d2005-03-24 16:22:35 +00001538 */
vlme1e6ed82005-03-24 14:26:38 +00001539 ;
1540
vlmfa67ddc2004-06-03 03:38:44 +00001541Opaque:
1542 TOK_opaque {
vlm6611add2005-03-20 14:28:32 +00001543 $$.len = $1.len + 1;
vlmfa67ddc2004-06-03 03:38:44 +00001544 $$.buf = malloc($$.len + 1);
1545 checkmem($$.buf);
1546 $$.buf[0] = '{';
vlm6611add2005-03-20 14:28:32 +00001547 memcpy($$.buf + 1, $1.buf, $1.len);
vlmfa67ddc2004-06-03 03:38:44 +00001548 $$.buf[$$.len] = '\0';
1549 free($1.buf);
1550 }
1551 | Opaque TOK_opaque {
1552 int newsize = $1.len + $2.len;
1553 char *p = malloc(newsize + 1);
1554 checkmem(p);
1555 memcpy(p , $1.buf, $1.len);
1556 memcpy(p + $1.len, $2.buf, $2.len);
1557 p[newsize] = '\0';
1558 free($1.buf);
1559 free($2.buf);
1560 $$.buf = p;
1561 $$.len = newsize;
1562 }
1563 ;
1564
1565BasicTypeId:
1566 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1567 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1568 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1569 | BasicTypeId_UniverationCompatible { $$ = $1; }
1570 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1571 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1572 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1573 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1574 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1575 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1576 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1577 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
vlm5e2c4b92005-03-20 11:12:40 +00001578 | BasicString { $$ = $1; }
vlmfa67ddc2004-06-03 03:38:44 +00001579 ;
1580
1581/*
1582 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1583 */
1584BasicTypeId_UniverationCompatible:
1585 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1586 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1587 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1588 ;
1589
1590BasicType:
1591 BasicTypeId {
vlm39e5ed72004-09-05 10:40:41 +00001592 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001593 checkmem($$);
1594 $$->expr_type = $1;
1595 $$->meta_type = AMT_TYPE;
1596 }
1597 | BasicTypeId_UniverationCompatible UniverationDefinition {
1598 if($2) {
1599 $$ = $2;
1600 } else {
vlm39e5ed72004-09-05 10:40:41 +00001601 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001602 checkmem($$);
1603 }
1604 $$->expr_type = $1;
1605 $$->meta_type = AMT_TYPE;
1606 }
1607 ;
1608
1609BasicString:
1610 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1611 | TOK_GeneralString {
1612 $$ = ASN_STRING_GeneralString;
vlmc94e28f2004-09-15 11:59:51 +00001613 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001614 }
1615 | TOK_GraphicString {
1616 $$ = ASN_STRING_GraphicString;
vlmc94e28f2004-09-15 11:59:51 +00001617 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001618 }
1619 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1620 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1621 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1622 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1623 | TOK_T61String {
1624 $$ = ASN_STRING_T61String;
vlmc94e28f2004-09-15 11:59:51 +00001625 fprintf(stderr, "WARNING: T61String is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001626 }
1627 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1628 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1629 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1630 | TOK_VideotexString {
1631 $$ = ASN_STRING_VideotexString;
vlmc94e28f2004-09-15 11:59:51 +00001632 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001633 }
1634 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1635 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1636 ;
1637
vlm5f0128b2004-08-20 13:25:29 +00001638
vlmfa67ddc2004-06-03 03:38:44 +00001639/*
1640 * Data type constraints.
1641 */
vlmfa67ddc2004-06-03 03:38:44 +00001642Union: '|' | TOK_UNION;
1643Intersection: '^' | TOK_INTERSECTION;
1644Except: TOK_EXCEPT;
1645
vlm9283dbe2004-08-18 04:59:12 +00001646optConstraints:
1647 { $$ = 0; }
vlm5f0128b2004-08-20 13:25:29 +00001648 | Constraints {
1649 $$ = $1;
1650 }
1651 ;
1652
1653Constraints:
1654 SetOfConstraints {
vlm9fe7c922005-08-12 10:08:45 +00001655 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
vlm9283dbe2004-08-18 04:59:12 +00001656 }
1657 | TOK_SIZE '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001658 /*
1659 * This is a special case, for compatibility purposes.
vlm9283dbe2004-08-18 04:59:12 +00001660 * It goes without parentheses.
vlmfa67ddc2004-06-03 03:38:44 +00001661 */
vlm9fe7c922005-08-12 10:08:45 +00001662 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001663 }
vlmfa67ddc2004-06-03 03:38:44 +00001664 ;
1665
vlm9283dbe2004-08-18 04:59:12 +00001666SetOfConstraints:
1667 '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001668 $$ = $2;
1669 }
vlm9283dbe2004-08-18 04:59:12 +00001670 | SetOfConstraints '(' ElementSetSpecs ')' {
vlm9fe7c922005-08-12 10:08:45 +00001671 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
vlm9283dbe2004-08-18 04:59:12 +00001672 }
vlmfa67ddc2004-06-03 03:38:44 +00001673 ;
1674
vlm9283dbe2004-08-18 04:59:12 +00001675ElementSetSpecs:
1676 ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001677 $$ = $1;
1678 }
vlm9283dbe2004-08-18 04:59:12 +00001679 | ElementSetSpec ',' TOK_ThreeDots {
vlmfa67ddc2004-06-03 03:38:44 +00001680 asn1p_constraint_t *ct;
1681 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001682 ct->type = ACT_EL_EXT;
vlm9fe7c922005-08-12 10:08:45 +00001683 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlmfa67ddc2004-06-03 03:38:44 +00001684 }
vlm9283dbe2004-08-18 04:59:12 +00001685 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001686 asn1p_constraint_t *ct;
1687 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001688 ct->type = ACT_EL_EXT;
vlm9fe7c922005-08-12 10:08:45 +00001689 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlm6f5eb0b2004-08-13 12:35:09 +00001690 ct = $$;
vlm9fe7c922005-08-12 10:08:45 +00001691 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
vlmfa67ddc2004-06-03 03:38:44 +00001692 }
vlmfa67ddc2004-06-03 03:38:44 +00001693 ;
1694
vlm9283dbe2004-08-18 04:59:12 +00001695ElementSetSpec:
1696 ConstraintSubtypeElement {
1697 $$ = $1;
1698 }
vlme1e6ed82005-03-24 14:26:38 +00001699 | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001700 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
vlme1e6ed82005-03-24 14:26:38 +00001701 }
vlm9283dbe2004-08-18 04:59:12 +00001702 | ElementSetSpec Union ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001703 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001704 }
vlm9283dbe2004-08-18 04:59:12 +00001705 | ElementSetSpec Intersection ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001706 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001707 }
vlm9283dbe2004-08-18 04:59:12 +00001708 | ConstraintSubtypeElement Except ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001709 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001710 }
1711 ;
1712
1713ConstraintSubtypeElement:
vlm9283dbe2004-08-18 04:59:12 +00001714 ConstraintSpec '(' ElementSetSpecs ')' {
1715 int ret;
1716 $$ = asn1p_constraint_new(yylineno);
1717 checkmem($$);
1718 $$->type = $1;
1719 ret = asn1p_constraint_insert($$, $3);
1720 checkmem(ret == 0);
1721 }
1722 | '(' ElementSetSpecs ')' {
1723 int ret;
1724 $$ = asn1p_constraint_new(yylineno);
1725 checkmem($$);
1726 $$->type = ACT_CA_SET;
1727 ret = asn1p_constraint_insert($$, $2);
1728 checkmem(ret == 0);
1729 }
vlma6a12e32005-03-20 12:58:00 +00001730 | SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001731 $$ = asn1p_constraint_new(yylineno);
1732 checkmem($$);
1733 $$->type = ACT_EL_VALUE;
1734 $$->value = $1;
1735 }
vlma6a12e32005-03-20 12:58:00 +00001736 | ContainedSubtype {
1737 $$ = asn1p_constraint_new(yylineno);
1738 checkmem($$);
1739 $$->type = ACT_EL_TYPE;
1740 $$->containedSubtype = $1;
1741 }
1742 | SingleValue ConstraintRangeSpec SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001743 $$ = asn1p_constraint_new(yylineno);
1744 checkmem($$);
1745 $$->type = $2;
1746 $$->range_start = $1;
1747 $$->range_stop = $3;
1748 }
vlma6a12e32005-03-20 12:58:00 +00001749 | TOK_MIN ConstraintRangeSpec SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001750 $$ = asn1p_constraint_new(yylineno);
1751 checkmem($$);
vlm9283dbe2004-08-18 04:59:12 +00001752 $$->type = $2;
1753 $$->range_start = asn1p_value_fromint(-123);
1754 $$->range_stop = $3;
1755 $$->range_start->type = ATV_MIN;
1756 }
vlma6a12e32005-03-20 12:58:00 +00001757 | SingleValue ConstraintRangeSpec TOK_MAX {
vlm9283dbe2004-08-18 04:59:12 +00001758 $$ = asn1p_constraint_new(yylineno);
1759 checkmem($$);
1760 $$->type = $2;
1761 $$->range_start = $1;
1762 $$->range_stop = asn1p_value_fromint(321);
1763 $$->range_stop->type = ATV_MAX;
1764 }
1765 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1766 $$ = asn1p_constraint_new(yylineno);
1767 checkmem($$);
1768 $$->type = $2;
1769 $$->range_start = asn1p_value_fromint(-123);
1770 $$->range_stop = asn1p_value_fromint(321);
1771 $$->range_start->type = ATV_MIN;
1772 $$->range_stop->type = ATV_MAX;
vlmfa67ddc2004-06-03 03:38:44 +00001773 }
1774 | TableConstraint {
1775 $$ = $1;
1776 }
vlm7bbdc9f2005-03-28 15:01:27 +00001777 | InnerTypeConstraint {
vlmfa67ddc2004-06-03 03:38:44 +00001778 $$ = $1;
1779 }
vlm6611add2005-03-20 14:28:32 +00001780 | TOK_CONSTRAINED TOK_BY '{'
1781 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1782 $$ = asn1p_constraint_new(yylineno);
1783 checkmem($$);
1784 $$->type = ACT_CT_CTDBY;
1785 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
1786 checkmem($$->value);
1787 $$->value->type = ATV_UNPARSED;
1788 }
vlmfa67ddc2004-06-03 03:38:44 +00001789 ;
1790
1791ConstraintRangeSpec:
1792 TOK_TwoDots { $$ = ACT_EL_RANGE; }
1793 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
1794 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
1795 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
1796 ;
1797
1798ConstraintSpec:
1799 TOK_SIZE {
1800 $$ = ACT_CT_SIZE;
1801 }
1802 | TOK_FROM {
1803 $$ = ACT_CT_FROM;
1804 }
1805 ;
1806
vlma6a12e32005-03-20 12:58:00 +00001807SingleValue:
vlm4053ca52005-02-18 16:34:21 +00001808 TOK_FALSE {
1809 $$ = asn1p_value_fromint(0);
1810 checkmem($$);
1811 $$->type = ATV_FALSE;
1812 }
1813 | TOK_TRUE {
1814 $$ = asn1p_value_fromint(1);
1815 checkmem($$);
1816 $$->type = ATV_TRUE;
1817 }
1818 | SignedNumber {
vlmfa67ddc2004-06-03 03:38:44 +00001819 $$ = $1;
1820 }
vlme1e6ed82005-03-24 14:26:38 +00001821 | RestrictedCharacterStringValue {
1822 $$ = $1;
vlm4053ca52005-02-18 16:34:21 +00001823 }
vlmfa67ddc2004-06-03 03:38:44 +00001824 | Identifier {
1825 asn1p_ref_t *ref;
1826 int ret;
1827 ref = asn1p_ref_new(yylineno);
1828 checkmem(ref);
1829 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1830 checkmem(ret == 0);
1831 $$ = asn1p_value_fromref(ref, 0);
1832 checkmem($$);
1833 free($1);
1834 }
vlma6a12e32005-03-20 12:58:00 +00001835 ;
1836
1837ContainedSubtype:
1838 TypeRefName {
vlm4053ca52005-02-18 16:34:21 +00001839 asn1p_ref_t *ref;
1840 int ret;
1841 ref = asn1p_ref_new(yylineno);
1842 checkmem(ref);
1843 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1844 checkmem(ret == 0);
1845 $$ = asn1p_value_fromref(ref, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001846 checkmem($$);
vlm4053ca52005-02-18 16:34:21 +00001847 free($1);
vlmfa67ddc2004-06-03 03:38:44 +00001848 }
1849 ;
1850
vlm7bbdc9f2005-03-28 15:01:27 +00001851InnerTypeConstraint:
1852 TOK_WITH TOK_COMPONENT SetOfConstraints {
vlm9fe7c922005-08-12 10:08:45 +00001853 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
vlm7bbdc9f2005-03-28 15:01:27 +00001854 }
1855 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
vlm9fe7c922005-08-12 10:08:45 +00001856 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001857 }
1858 ;
1859
1860WithComponentsList:
1861 WithComponentsElement {
1862 $$ = $1;
1863 }
1864 | WithComponentsList ',' WithComponentsElement {
vlm9fe7c922005-08-12 10:08:45 +00001865 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001866 }
1867 ;
1868
1869WithComponentsElement:
1870 TOK_ThreeDots {
1871 $$ = asn1p_constraint_new(yylineno);
1872 checkmem($$);
1873 $$->type = ACT_EL_EXT;
vlm7bbdc9f2005-03-28 15:01:27 +00001874 $$->value = asn1p_value_frombuf("...", 3, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001875 }
1876 | Identifier optConstraints optPresenceConstraint {
1877 $$ = asn1p_constraint_new(yylineno);
1878 checkmem($$);
1879 $$->type = ACT_EL_VALUE;
1880 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1881 $$->presence = $3;
vlm7bbdc9f2005-03-28 15:01:27 +00001882 if($2) asn1p_constraint_insert($$, $2);
vlmfa67ddc2004-06-03 03:38:44 +00001883 }
1884 ;
1885
1886/*
1887 * presence constraint for WithComponents
1888 */
1889optPresenceConstraint:
1890 { $$ = ACPRES_DEFAULT; }
1891 | PresenceConstraint { $$ = $1; }
1892 ;
1893
1894PresenceConstraint:
1895 TOK_PRESENT {
1896 $$ = ACPRES_PRESENT;
1897 }
1898 | TOK_ABSENT {
1899 $$ = ACPRES_ABSENT;
1900 }
1901 | TOK_OPTIONAL {
1902 $$ = ACPRES_OPTIONAL;
1903 }
1904 ;
1905
1906TableConstraint:
1907 SimpleTableConstraint {
1908 $$ = $1;
1909 }
1910 | ComponentRelationConstraint {
1911 $$ = $1;
1912 }
1913 ;
1914
1915/*
1916 * "{ExtensionSet}"
1917 */
1918SimpleTableConstraint:
1919 '{' TypeRefName '}' {
1920 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
1921 asn1p_constraint_t *ct;
1922 int ret;
1923 ret = asn1p_ref_add_component(ref, $2, 0);
1924 checkmem(ret == 0);
1925 ct = asn1p_constraint_new(yylineno);
1926 checkmem($$);
1927 ct->type = ACT_EL_VALUE;
1928 ct->value = asn1p_value_fromref(ref, 0);
vlm9fe7c922005-08-12 10:08:45 +00001929 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001930 }
1931 ;
1932
1933ComponentRelationConstraint:
1934 SimpleTableConstraint '{' AtNotationList '}' {
vlm9fe7c922005-08-12 10:08:45 +00001935 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001936 }
1937 ;
1938
1939AtNotationList:
1940 AtNotationElement {
1941 $$ = asn1p_constraint_new(yylineno);
1942 checkmem($$);
1943 $$->type = ACT_EL_VALUE;
1944 $$->value = asn1p_value_fromref($1, 0);
1945 }
1946 | AtNotationList ',' AtNotationElement {
1947 asn1p_constraint_t *ct;
1948 ct = asn1p_constraint_new(yylineno);
1949 checkmem(ct);
1950 ct->type = ACT_EL_VALUE;
1951 ct->value = asn1p_value_fromref($3, 0);
vlm9fe7c922005-08-12 10:08:45 +00001952 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlmfa67ddc2004-06-03 03:38:44 +00001953 }
1954 ;
1955
1956/*
1957 * @blah
1958 */
1959AtNotationElement:
1960 '@' ComponentIdList {
1961 char *p = malloc(strlen($2) + 2);
1962 int ret;
1963 *p = '@';
1964 strcpy(p + 1, $2);
1965 $$ = asn1p_ref_new(yylineno);
1966 ret = asn1p_ref_add_component($$, p, 0);
1967 checkmem(ret == 0);
1968 free(p);
1969 free($2);
1970 }
1971 | '@' '.' ComponentIdList {
1972 char *p = malloc(strlen($3) + 3);
1973 int ret;
1974 p[0] = '@';
1975 p[1] = '.';
1976 strcpy(p + 2, $3);
1977 $$ = asn1p_ref_new(yylineno);
1978 ret = asn1p_ref_add_component($$, p, 0);
1979 checkmem(ret == 0);
1980 free(p);
1981 free($3);
1982 }
1983 ;
1984
1985/* identifier "." ... */
1986ComponentIdList:
1987 Identifier {
1988 $$ = $1;
1989 }
1990 | ComponentIdList '.' Identifier {
1991 int l1 = strlen($1);
1992 int l3 = strlen($3);
1993 $$ = malloc(l1 + 1 + l3 + 1);
1994 memcpy($$, $1, l1);
1995 $$[l1] = '.';
1996 memcpy($$ + l1 + 1, $3, l3);
1997 $$[l1 + 1 + l3] = '\0';
1998 }
1999 ;
2000
2001
2002
2003/*
2004 * MARKERS
2005 */
2006
2007optMarker:
vlmc94e28f2004-09-15 11:59:51 +00002008 {
2009 $$.flags = EM_NOMARK;
2010 $$.default_value = 0;
2011 }
vlmfa67ddc2004-06-03 03:38:44 +00002012 | Marker { $$ = $1; }
2013 ;
2014
2015Marker:
2016 TOK_OPTIONAL {
vlm1ac75e72005-11-26 11:21:55 +00002017 $$.flags = EM_OPTIONAL | EM_INDIRECT;
vlmc94e28f2004-09-15 11:59:51 +00002018 $$.default_value = 0;
vlmfa67ddc2004-06-03 03:38:44 +00002019 }
vlmc94e28f2004-09-15 11:59:51 +00002020 | TOK_DEFAULT Value {
2021 $$.flags = EM_DEFAULT;
2022 $$.default_value = $2;
vlmfa67ddc2004-06-03 03:38:44 +00002023 }
2024 ;
2025
2026/*
2027 * Universal enumeration definition to use in INTEGER and ENUMERATED.
2028 * === EXAMPLE ===
2029 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
2030 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
2031 * === EOF ===
2032 */
2033/*
2034optUniverationDefinition:
2035 { $$ = 0; }
2036 | UniverationDefinition {
2037 $$ = $1;
2038 }
2039 ;
2040*/
2041
2042UniverationDefinition:
2043 '{' '}' {
vlm39e5ed72004-09-05 10:40:41 +00002044 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002045 checkmem($$);
2046 }
2047 | '{' UniverationList '}' {
2048 $$ = $2;
2049 }
2050 ;
2051
2052UniverationList:
2053 UniverationElement {
vlm39e5ed72004-09-05 10:40:41 +00002054 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002055 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +00002056 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +00002057 }
2058 | UniverationList ',' UniverationElement {
2059 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +00002060 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +00002061 }
2062 ;
2063
2064UniverationElement:
2065 Identifier {
vlm39e5ed72004-09-05 10:40:41 +00002066 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002067 checkmem($$);
2068 $$->expr_type = A1TC_UNIVERVAL;
2069 $$->meta_type = AMT_VALUE;
2070 $$->Identifier = $1;
2071 }
2072 | Identifier '(' SignedNumber ')' {
vlm39e5ed72004-09-05 10:40:41 +00002073 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002074 checkmem($$);
2075 $$->expr_type = A1TC_UNIVERVAL;
2076 $$->meta_type = AMT_VALUE;
2077 $$->Identifier = $1;
2078 $$->value = $3;
2079 }
2080 | Identifier '(' DefinedValue ')' {
vlm39e5ed72004-09-05 10:40:41 +00002081 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002082 checkmem($$);
2083 $$->expr_type = A1TC_UNIVERVAL;
2084 $$->meta_type = AMT_VALUE;
2085 $$->Identifier = $1;
2086 $$->value = $3;
2087 }
2088 | SignedNumber {
vlm39e5ed72004-09-05 10:40:41 +00002089 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002090 checkmem($$);
2091 $$->expr_type = A1TC_UNIVERVAL;
2092 $$->meta_type = AMT_VALUE;
2093 $$->value = $1;
2094 }
2095 | TOK_ThreeDots {
vlm39e5ed72004-09-05 10:40:41 +00002096 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002097 checkmem($$);
2098 $$->Identifier = strdup("...");
2099 checkmem($$->Identifier);
2100 $$->expr_type = A1TC_EXTENSIBLE;
2101 $$->meta_type = AMT_VALUE;
2102 }
2103 ;
2104
2105SignedNumber:
2106 TOK_number {
2107 $$ = asn1p_value_fromint($1);
2108 checkmem($$);
2109 }
2110 | TOK_number_negative {
2111 $$ = asn1p_value_fromint($1);
2112 checkmem($$);
2113 }
2114 ;
2115
2116/*
2117 * SEQUENCE definition.
2118 * === EXAMPLE ===
2119 * Struct1 ::= SEQUENCE {
2120 * memb1 Struct2,
2121 * memb2 SEQUENCE OF {
2122 * memb2-1 Struct 3
2123 * }
2124 * }
2125 * === EOF ===
2126 */
2127
2128
2129
2130/*
2131 * SET definition.
2132 * === EXAMPLE ===
2133 * Person ::= SET {
2134 * name [0] PrintableString (SIZE(1..20)),
2135 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2136 * }
2137 * === EOF ===
2138 */
2139
2140optTag:
2141 { memset(&$$, 0, sizeof($$)); }
2142 | Tag { $$ = $1; }
2143 ;
2144
2145Tag:
vlm2728a8d2005-01-23 09:51:44 +00002146 TagTypeValue TagPlicit {
vlmfa67ddc2004-06-03 03:38:44 +00002147 $$ = $1;
vlm2728a8d2005-01-23 09:51:44 +00002148 $$.tag_mode = $2.tag_mode;
vlmfa67ddc2004-06-03 03:38:44 +00002149 }
vlm2728a8d2005-01-23 09:51:44 +00002150 ;
2151
2152TagTypeValue:
2153 '[' TagClass TOK_number ']' {
2154 $$ = $2;
2155 $$.tag_value = $3;
2156 };
2157
2158TagClass:
2159 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2160 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2161 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2162 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2163 ;
2164
2165TagPlicit:
2166 { $$.tag_mode = TM_DEFAULT; }
2167 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2168 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
vlmfa67ddc2004-06-03 03:38:44 +00002169 ;
2170
2171TypeRefName:
2172 TOK_typereference {
2173 checkmem($1);
2174 $$ = $1;
2175 }
vlm9283dbe2004-08-18 04:59:12 +00002176 | TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00002177 checkmem($1);
2178 $$ = $1;
2179 }
2180 ;
2181
vlm9283dbe2004-08-18 04:59:12 +00002182
vlmfa67ddc2004-06-03 03:38:44 +00002183ObjectClassReference:
vlm9283dbe2004-08-18 04:59:12 +00002184 TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00002185 checkmem($1);
2186 $$ = $1;
2187 }
2188 ;
2189
vlm151c0b22004-09-22 16:03:36 +00002190optIdentifier:
2191 { $$ = 0; }
2192 | Identifier {
2193 $$ = $1;
2194 }
vlma5b977d2005-06-06 08:28:58 +00002195 ;
vlm151c0b22004-09-22 16:03:36 +00002196
vlmfa67ddc2004-06-03 03:38:44 +00002197Identifier:
2198 TOK_identifier {
2199 checkmem($1);
2200 $$ = $1;
2201 }
2202 ;
2203
vlmfa67ddc2004-06-03 03:38:44 +00002204%%
2205
2206
2207/*
2208 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2209 */
2210static asn1p_value_t *
2211_convert_bitstring2binary(char *str, int base) {
2212 asn1p_value_t *val;
2213 int slen;
2214 int memlen;
2215 int baselen;
2216 int bits;
2217 uint8_t *binary_vector;
2218 uint8_t *bv_ptr;
2219 uint8_t cur_val;
2220
2221 assert(str);
2222 assert(str[0] == '\'');
2223
2224 switch(base) {
2225 case 'B':
2226 baselen = 1;
2227 break;
2228 case 'H':
2229 baselen = 4;
2230 break;
2231 default:
2232 assert(base == 'B' || base == 'H');
2233 errno = EINVAL;
2234 return NULL;
2235 }
2236
2237 slen = strlen(str);
2238 assert(str[slen - 1] == base);
2239 assert(str[slen - 2] == '\'');
2240
2241 memlen = slen / (8 / baselen); /* Conservative estimate */
2242
2243 bv_ptr = binary_vector = malloc(memlen + 1);
2244 if(bv_ptr == NULL)
2245 /* ENOMEM */
2246 return NULL;
2247
2248 cur_val = 0;
2249 bits = 0;
2250 while(*(++str) != '\'') {
2251 switch(baselen) {
2252 case 1:
2253 switch(*str) {
2254 case '1':
2255 cur_val |= 1 << (7 - (bits % 8));
2256 case '0':
2257 break;
2258 default:
2259 assert(!"_y UNREACH1");
2260 case ' ': case '\r': case '\n':
2261 continue;
2262 }
2263 break;
2264 case 4:
2265 switch(*str) {
2266 case '0': case '1': case '2': case '3': case '4':
2267 case '5': case '6': case '7': case '8': case '9':
2268 cur_val |= (*str - '0') << (4 - (bits % 8));
2269 break;
2270 case 'A': case 'B': case 'C':
2271 case 'D': case 'E': case 'F':
2272 cur_val |= ((*str - 'A') + 10)
2273 << (4 - (bits % 8));
2274 break;
2275 default:
2276 assert(!"_y UNREACH2");
2277 case ' ': case '\r': case '\n':
2278 continue;
2279 }
2280 break;
2281 }
2282
2283 bits += baselen;
2284 if((bits % 8) == 0) {
2285 *bv_ptr++ = cur_val;
2286 cur_val = 0;
2287 }
2288 }
2289
2290 *bv_ptr = cur_val;
2291 assert((bv_ptr - binary_vector) <= memlen);
2292
2293 val = asn1p_value_frombits(binary_vector, bits, 0);
2294 if(val == NULL) {
2295 free(binary_vector);
2296 }
2297
2298 return val;
2299}
2300
vlm5d89c3d2005-08-13 09:07:11 +00002301/*
2302 * For unnamed types (used in old X.208 compliant modules)
2303 * generate some sort of interim names, to not to force human being to fix
2304 * the specification's compliance to modern ASN.1 standards.
2305 */
2306static void
2307_fixup_anonymous_identifier(asn1p_expr_t *expr) {
2308 char *p;
2309 assert(expr->Identifier == 0);
2310
2311 /*
2312 * Try to figure out the type name
2313 * without going too much into details
2314 */
2315 expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type);
2316 if(expr->reference && expr->reference->comp_count > 0)
2317 expr->Identifier = expr->reference->components[0].name;
2318
2319 fprintf(stderr,
2320 "WARNING: Line %d: expected lower-case member identifier, "
2321 "found an unnamed %s.\n"
2322 "WARNING: Obsolete X.208 syntax detected, "
2323 "please give the member a name.\n",
2324 yylineno, expr->Identifier ? expr->Identifier : "type");
2325
2326 if(!expr->Identifier)
2327 expr->Identifier = "unnamed";
2328 expr->Identifier = strdup(expr->Identifier);
2329 assert(expr->Identifier);
2330 /* Make a lowercase identifier from the type name */
2331 for(p = expr->Identifier; *p; p++) {
2332 switch(*p) {
2333 case 'A' ... 'Z': *p += 32; break;
2334 case ' ': *p = '_'; break;
2335 case '-': *p = '_'; break;
2336 }
2337 }
2338 fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". "
2339 "Name clash may occur later.\n",
2340 expr->Identifier);
2341}
2342
vlmfa67ddc2004-06-03 03:38:44 +00002343extern char *asn1p_text;
2344
2345int
2346yyerror(const char *msg) {
2347 fprintf(stderr,
2348 "ASN.1 grammar parse error "
2349 "near line %d (token \"%s\"): %s\n",
vlm39e5ed72004-09-05 10:40:41 +00002350 yylineno, asn1p_text, msg);
vlmfa67ddc2004-06-03 03:38:44 +00002351 return -1;
2352}
2353
2354