blob: e119f1720269d069887a127bc5f0d8d12aa48bc2 [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 */
vlmeeb3c512006-03-16 05:11:14 +0000110%token <tv_opaque> TOK_whitespace /* A span of whitespace */
vlmfa67ddc2004-06-03 03:38:44 +0000111%token <tv_opaque> TOK_opaque /* opaque data (driven from .y) */
112%token <tv_str> TOK_bstring
113%token <tv_opaque> TOK_cstring
114%token <tv_str> TOK_hstring
115%token <tv_str> TOK_identifier
116%token <a_int> TOK_number
vlm2c8c44d2005-03-24 16:22:35 +0000117%token <a_int> TOK_tuple
118%token <a_int> TOK_quadruple
vlmfa67ddc2004-06-03 03:38:44 +0000119%token <a_int> TOK_number_negative
120%token <tv_str> TOK_typereference
vlm9283dbe2004-08-18 04:59:12 +0000121%token <tv_str> TOK_capitalreference /* "CLASS1" */
vlmfa67ddc2004-06-03 03:38:44 +0000122%token <tv_str> TOK_typefieldreference /* "&Pork" */
123%token <tv_str> TOK_valuefieldreference /* "&id" */
vlm808411d2006-03-14 16:31:37 +0000124%token <tv_str> TOK_Literal /* "BY" */
vlmfa67ddc2004-06-03 03:38:44 +0000125
126/*
127 * Token types representing ASN.1 standard keywords.
128 */
129%token TOK_ABSENT
130%token TOK_ABSTRACT_SYNTAX
131%token TOK_ALL
132%token TOK_ANY
133%token TOK_APPLICATION
134%token TOK_AUTOMATIC
135%token TOK_BEGIN
136%token TOK_BIT
137%token TOK_BMPString
138%token TOK_BOOLEAN
139%token TOK_BY
140%token TOK_CHARACTER
141%token TOK_CHOICE
142%token TOK_CLASS
143%token TOK_COMPONENT
144%token TOK_COMPONENTS
145%token TOK_CONSTRAINED
146%token TOK_CONTAINING
147%token TOK_DEFAULT
148%token TOK_DEFINITIONS
149%token TOK_DEFINED
150%token TOK_EMBEDDED
151%token TOK_ENCODED
vlm9283dbe2004-08-18 04:59:12 +0000152%token TOK_ENCODING_CONTROL
vlmfa67ddc2004-06-03 03:38:44 +0000153%token TOK_END
154%token TOK_ENUMERATED
155%token TOK_EXPLICIT
156%token TOK_EXPORTS
157%token TOK_EXTENSIBILITY
158%token TOK_EXTERNAL
159%token TOK_FALSE
160%token TOK_FROM
161%token TOK_GeneralizedTime
162%token TOK_GeneralString
163%token TOK_GraphicString
164%token TOK_IA5String
165%token TOK_IDENTIFIER
166%token TOK_IMPLICIT
167%token TOK_IMPLIED
168%token TOK_IMPORTS
169%token TOK_INCLUDES
170%token TOK_INSTANCE
vlm9283dbe2004-08-18 04:59:12 +0000171%token TOK_INSTRUCTIONS
vlmfa67ddc2004-06-03 03:38:44 +0000172%token TOK_INTEGER
173%token TOK_ISO646String
174%token TOK_MAX
175%token TOK_MIN
176%token TOK_MINUS_INFINITY
177%token TOK_NULL
178%token TOK_NumericString
179%token TOK_OBJECT
180%token TOK_ObjectDescriptor
181%token TOK_OCTET
182%token TOK_OF
183%token TOK_OPTIONAL
184%token TOK_PATTERN
185%token TOK_PDV
186%token TOK_PLUS_INFINITY
187%token TOK_PRESENT
188%token TOK_PrintableString
189%token TOK_PRIVATE
190%token TOK_REAL
191%token TOK_RELATIVE_OID
192%token TOK_SEQUENCE
193%token TOK_SET
194%token TOK_SIZE
195%token TOK_STRING
196%token TOK_SYNTAX
197%token TOK_T61String
198%token TOK_TAGS
199%token TOK_TeletexString
200%token TOK_TRUE
201%token TOK_TYPE_IDENTIFIER
202%token TOK_UNIQUE
203%token TOK_UNIVERSAL
204%token TOK_UniversalString
205%token TOK_UTCTime
206%token TOK_UTF8String
207%token TOK_VideotexString
208%token TOK_VisibleString
209%token TOK_WITH
210
vlmfa67ddc2004-06-03 03:38:44 +0000211%left TOK_EXCEPT
vlm9283dbe2004-08-18 04:59:12 +0000212%left '^' TOK_INTERSECTION
213%left '|' TOK_UNION
vlmfa67ddc2004-06-03 03:38:44 +0000214
215/* Misc tags */
216%token TOK_TwoDots /* .. */
217%token TOK_ThreeDots /* ... */
vlmfa67ddc2004-06-03 03:38:44 +0000218
219
220/*
221 * Types defined herein.
222 */
223%type <a_grammar> ModuleList
224%type <a_module> ModuleSpecification
225%type <a_module> ModuleSpecificationBody
226%type <a_module> ModuleSpecificationElement
227%type <a_module> optModuleSpecificationBody /* Optional */
228%type <a_module_flags> optModuleSpecificationFlags
229%type <a_module_flags> ModuleSpecificationFlags /* Set of FL */
230%type <a_module_flags> ModuleSpecificationFlag /* Single FL */
231%type <a_module> ImportsDefinition
232%type <a_module> ImportsBundleSet
233%type <a_xports> ImportsBundle
234%type <a_xports> ImportsList
235%type <a_xports> ExportsDefinition
236%type <a_xports> ExportsBody
237%type <a_expr> ImportsElement
238%type <a_expr> ExportsElement
vlmfa67ddc2004-06-03 03:38:44 +0000239%type <a_expr> ExtensionAndException
vlmec8f6812004-08-22 03:19:54 +0000240%type <a_expr> TypeDeclaration
vlm066dc102005-08-22 12:23:54 +0000241%type <a_expr> TypeDeclarationSet
vlmfa67ddc2004-06-03 03:38:44 +0000242%type <a_ref> ComplexTypeReference
243%type <a_ref> ComplexTypeReferenceAmpList
244%type <a_refcomp> ComplexTypeReferenceElement
vlma6a84d72006-03-16 10:03:35 +0000245%type <a_refcomp> PrimitiveFieldReference
vlmdc7cf042006-03-09 08:49:26 +0000246%type <a_expr> FieldSpec
247%type <a_ref> FieldName
248%type <a_ref> DefinedObjectClass
vlmfa67ddc2004-06-03 03:38:44 +0000249%type <a_expr> ClassField
vlmdc7cf042006-03-09 08:49:26 +0000250%type <a_expr> ObjectClass
vlmec8f6812004-08-22 03:19:54 +0000251%type <a_expr> Type
vlmfa67ddc2004-06-03 03:38:44 +0000252%type <a_expr> DataTypeReference /* Type1 ::= Type2 */
253%type <a_expr> DefinedTypeRef
254%type <a_expr> ValueSetDefinition /* Val INTEGER ::= {1|2} */
255%type <a_expr> ValueDefinition /* val INTEGER ::= 1*/
vlmc94e28f2004-09-15 11:59:51 +0000256%type <a_value> Value
vlmfa67ddc2004-06-03 03:38:44 +0000257%type <a_value> DefinedValue
258%type <a_value> SignedNumber
vlm0aa86902004-10-12 23:26:53 +0000259%type <a_expr> optComponentTypeLists
vlmec8f6812004-08-22 03:19:54 +0000260%type <a_expr> ComponentTypeLists
261%type <a_expr> ComponentType
262%type <a_expr> AlternativeTypeLists
263%type <a_expr> AlternativeType
vlmfa67ddc2004-06-03 03:38:44 +0000264%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
vlm0c6d3812006-03-21 03:40:38 +0000273%type <a_expr> Specialization
274%type <a_expr> Specializations
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
vlm2728a8d2005-01-23 09:51:44 +0000285%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
286%type <a_tag> TagClass TagTypeValue TagPlicit
vlmfa67ddc2004-06-03 03:38:44 +0000287%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
288%type <a_constr> optConstraints
vlm5f0128b2004-08-20 13:25:29 +0000289%type <a_constr> Constraints
vlm9283dbe2004-08-18 04:59:12 +0000290%type <a_constr> SetOfConstraints
291%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
292%type <a_constr> ElementSetSpec /* 1..2,...,3 */
vlmfa67ddc2004-06-03 03:38:44 +0000293%type <a_constr> ConstraintSubtypeElement /* 1..2 */
vlmfa67ddc2004-06-03 03:38:44 +0000294%type <a_constr> SimpleTableConstraint
295%type <a_constr> TableConstraint
vlm7bbdc9f2005-03-28 15:01:27 +0000296%type <a_constr> InnerTypeConstraint
vlmfa67ddc2004-06-03 03:38:44 +0000297%type <a_constr> WithComponentsList
298%type <a_constr> WithComponentsElement
299%type <a_constr> ComponentRelationConstraint
300%type <a_constr> AtNotationList
301%type <a_ref> AtNotationElement
vlma6a12e32005-03-20 12:58:00 +0000302%type <a_value> SingleValue
303%type <a_value> ContainedSubtype
vlmfa67ddc2004-06-03 03:38:44 +0000304%type <a_ctype> ConstraintSpec
305%type <a_ctype> ConstraintRangeSpec
vlme1e6ed82005-03-24 14:26:38 +0000306%type <a_value> RestrictedCharacterStringValue
vlmfa67ddc2004-06-03 03:38:44 +0000307%type <a_wsynt> optWithSyntax
308%type <a_wsynt> WithSyntax
vlm808411d2006-03-14 16:31:37 +0000309%type <a_wsynt> WithSyntaxList
310%type <a_wchunk> WithSyntaxToken
vlmfa67ddc2004-06-03 03:38:44 +0000311%type <a_marker> optMarker Marker
312%type <a_int> optUnique
313%type <a_pres> optPresenceConstraint PresenceConstraint
314%type <tv_str> ComponentIdList
vlm177a5b62005-09-05 05:17:57 +0000315%type <a_int> NSTD_IndirectMarker
vlmfa67ddc2004-06-03 03:38:44 +0000316
317
318%%
319
320
321ParsedGrammar:
322 ModuleList {
323 *(void **)param = $1;
324 }
325 ;
326
327ModuleList:
328 ModuleSpecification {
329 $$ = asn1p_new();
330 checkmem($$);
331 TQ_ADD(&($$->modules), $1, mod_next);
332 }
333 | ModuleList ModuleSpecification {
334 $$ = $1;
335 TQ_ADD(&($$->modules), $2, mod_next);
336 }
337 ;
338
339/*
340 * ASN module definition.
341 * === EXAMPLE ===
342 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
343 * BEGIN
344 * ...
345 * END
346 * === EOF ===
347 */
348
349ModuleSpecification:
350 TypeRefName optObjectIdentifier TOK_DEFINITIONS
351 optModuleSpecificationFlags
352 TOK_PPEQ TOK_BEGIN
353 optModuleSpecificationBody
354 TOK_END {
355
356 if($7) {
357 $$ = $7;
358 } else {
359 /* There's a chance that a module is just plain empty */
360 $$ = asn1p_module_new();
361 }
362 checkmem($$);
363
vlm04a08da2005-08-12 10:06:17 +0000364 $$->ModuleName = $1;
vlmfa67ddc2004-06-03 03:38:44 +0000365 $$->module_oid = $2;
366 $$->module_flags = $4;
367 }
368 ;
369
370/*
371 * Object Identifier Definition
372 * { iso member-body(2) 3 }
373 */
374optObjectIdentifier:
375 { $$ = 0; }
376 | ObjectIdentifier { $$ = $1; }
377 ;
378
379ObjectIdentifier:
380 '{' ObjectIdentifierBody '}' {
381 $$ = $2;
382 }
383 | '{' '}' {
384 $$ = 0;
385 }
386 ;
387
388ObjectIdentifierBody:
389 ObjectIdentifierElement {
390 $$ = asn1p_oid_new();
391 asn1p_oid_add_arc($$, &$1);
392 if($1.name)
393 free($1.name);
394 }
395 | ObjectIdentifierBody ObjectIdentifierElement {
396 $$ = $1;
397 asn1p_oid_add_arc($$, &$2);
398 if($2.name)
399 free($2.name);
400 }
401 ;
402
403ObjectIdentifierElement:
404 Identifier { /* iso */
405 $$.name = $1;
406 $$.number = -1;
407 }
408 | Identifier '(' TOK_number ')' { /* iso(1) */
409 $$.name = $1;
410 $$.number = $3;
411 }
412 | TOK_number { /* 1 */
413 $$.name = 0;
414 $$.number = $1;
415 }
416 ;
417
418/*
419 * Optional module flags.
420 */
421optModuleSpecificationFlags:
422 { $$ = MSF_NOFLAGS; }
423 | ModuleSpecificationFlags {
424 $$ = $1;
425 }
426 ;
427
428/*
429 * Module flags.
430 */
431ModuleSpecificationFlags:
432 ModuleSpecificationFlag {
433 $$ = $1;
434 }
435 | ModuleSpecificationFlags ModuleSpecificationFlag {
436 $$ = $1 | $2;
437 }
438 ;
439
440/*
441 * Single module flag.
442 */
443ModuleSpecificationFlag:
444 TOK_EXPLICIT TOK_TAGS {
445 $$ = MSF_EXPLICIT_TAGS;
446 }
447 | TOK_IMPLICIT TOK_TAGS {
448 $$ = MSF_IMPLICIT_TAGS;
449 }
450 | TOK_AUTOMATIC TOK_TAGS {
451 $$ = MSF_AUTOMATIC_TAGS;
452 }
453 | TOK_EXTENSIBILITY TOK_IMPLIED {
454 $$ = MSF_EXTENSIBILITY_IMPLIED;
455 }
vlm9283dbe2004-08-18 04:59:12 +0000456 /* EncodingReferenceDefault */
457 | TOK_capitalreference TOK_INSTRUCTIONS {
458 /* X.680Amd1 specifies TAG and XER */
459 if(strcmp($1, "TAG") == 0) {
460 $$ = MSF_TAG_INSTRUCTIONS;
461 } else if(strcmp($1, "XER") == 0) {
462 $$ = MSF_XER_INSTRUCTIONS;
463 } else {
464 fprintf(stderr,
465 "WARNING: %s INSTRUCTIONS at line %d: "
466 "Unrecognized encoding reference\n",
467 $1, yylineno);
468 $$ = MSF_unk_INSTRUCTIONS;
469 }
470 free($1);
471 }
vlmfa67ddc2004-06-03 03:38:44 +0000472 ;
473
474/*
475 * Optional module body.
476 */
477optModuleSpecificationBody:
478 { $$ = 0; }
479 | ModuleSpecificationBody {
vlmfa67ddc2004-06-03 03:38:44 +0000480 $$ = $1;
481 }
482 ;
483
484/*
485 * ASN.1 Module body.
486 */
487ModuleSpecificationBody:
488 ModuleSpecificationElement {
489 $$ = $1;
490 }
491 | ModuleSpecificationBody ModuleSpecificationElement {
492 $$ = $1;
493
vlm9283dbe2004-08-18 04:59:12 +0000494 /* Behave well when one of them is skipped. */
495 if(!($1)) {
496 if($2) $$ = $2;
497 break;
498 }
499
vlmfa67ddc2004-06-03 03:38:44 +0000500#ifdef MY_IMPORT
501#error MY_IMPORT DEFINED ELSEWHERE!
502#endif
503#define MY_IMPORT(foo,field) do { \
vlm97ed7152004-08-13 12:31:09 +0000504 while(TQ_FIRST(&($2->foo))) { \
vlmfa67ddc2004-06-03 03:38:44 +0000505 TQ_ADD(&($$->foo), \
506 TQ_REMOVE(&($2->foo), field), \
507 field); \
vlm97ed7152004-08-13 12:31:09 +0000508 } \
509 assert(TQ_FIRST(&($2->foo)) == 0); \
510 } while(0)
vlmfa67ddc2004-06-03 03:38:44 +0000511
512 MY_IMPORT(imports, xp_next);
513 MY_IMPORT(exports, xp_next);
514 MY_IMPORT(members, next);
515#undef MY_IMPORT
516
517 }
518 ;
519
520/*
521 * One of the elements of ASN.1 module specification.
522 */
523ModuleSpecificationElement:
524 ImportsDefinition {
525 $$ = $1;
526 }
527 | ExportsDefinition {
528 $$ = asn1p_module_new();
529 checkmem($$);
530 if($1) {
531 TQ_ADD(&($$->exports), $1, xp_next);
532 } else {
533 /* "EXPORTS ALL;" ? */
534 }
535 }
536 | DataTypeReference {
537 $$ = asn1p_module_new();
538 checkmem($$);
539 assert($1->expr_type != A1TC_INVALID);
540 assert($1->meta_type != AMT_INVALID);
541 TQ_ADD(&($$->members), $1, next);
542 }
543 | ValueDefinition {
544 $$ = asn1p_module_new();
545 checkmem($$);
546 assert($1->expr_type != A1TC_INVALID);
547 assert($1->meta_type != AMT_INVALID);
548 TQ_ADD(&($$->members), $1, next);
549 }
550 /*
551 * Value set definition
552 * === EXAMPLE ===
553 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
554 * === EOF ===
555 */
556 | ValueSetDefinition {
557 $$ = asn1p_module_new();
558 checkmem($$);
559 assert($1->expr_type != A1TC_INVALID);
560 assert($1->meta_type != AMT_INVALID);
561 TQ_ADD(&($$->members), $1, next);
562 }
vlm9283dbe2004-08-18 04:59:12 +0000563 | TOK_ENCODING_CONTROL TOK_capitalreference
564 { asn1p_lexer_hack_push_encoding_control(); }
565 {
566 fprintf(stderr,
567 "WARNING: ENCODING-CONTROL %s "
568 "specification at line %d ignored\n",
569 $2, yylineno);
570 free($2);
571 $$ = 0;
572 }
vlmfa67ddc2004-06-03 03:38:44 +0000573
574 /*
575 * Erroneous attemps
576 */
577 | BasicString {
578 return yyerror(
vlm1ac75e72005-11-26 11:21:55 +0000579 "Attempt to redefine a standard basic string type, "
580 "please comment out or remove this type redefinition.");
vlmfa67ddc2004-06-03 03:38:44 +0000581 }
582 ;
583
584/*
585 * === EXAMPLE ===
586 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
587 * === EOF ===
588 */
589ImportsDefinition:
590 TOK_IMPORTS ImportsBundleSet ';' {
vlm04a08da2005-08-12 10:06:17 +0000591 if(!saved_aid && 0)
592 return yyerror("Unterminated IMPORTS FROM, "
593 "expected semicolon ';'");
594 saved_aid = 0;
vlmfa67ddc2004-06-03 03:38:44 +0000595 $$ = $2;
596 }
597 /*
598 * Some error cases.
599 */
600 | TOK_IMPORTS TOK_FROM /* ... */ {
601 return yyerror("Empty IMPORTS list");
602 }
603 ;
604
605ImportsBundleSet:
606 ImportsBundle {
607 $$ = asn1p_module_new();
608 checkmem($$);
609 TQ_ADD(&($$->imports), $1, xp_next);
610 }
611 | ImportsBundleSet ImportsBundle {
612 $$ = $1;
613 TQ_ADD(&($$->imports), $2, xp_next);
614 }
615 ;
616
vlm04a08da2005-08-12 10:06:17 +0000617AssignedIdentifier:
618 { memset(&$$, 0, sizeof($$)); }
619 | ObjectIdentifier { $$.oid = $1; };
620 /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
621
vlmfa67ddc2004-06-03 03:38:44 +0000622ImportsBundle:
vlm04a08da2005-08-12 10:06:17 +0000623 ImportsList TOK_FROM TypeRefName AssignedIdentifier {
vlmfa67ddc2004-06-03 03:38:44 +0000624 $$ = $1;
vlm04a08da2005-08-12 10:06:17 +0000625 $$->fromModuleName = $3;
626 $$->identifier = $4;
627 /* This stupid thing is used for look-back hack. */
628 saved_aid = $$->identifier.oid ? 0 : &($$->identifier);
vlmfa67ddc2004-06-03 03:38:44 +0000629 checkmem($$);
630 }
631 ;
632
633ImportsList:
634 ImportsElement {
635 $$ = asn1p_xports_new();
636 checkmem($$);
637 TQ_ADD(&($$->members), $1, next);
638 }
639 | ImportsList ',' ImportsElement {
640 $$ = $1;
641 TQ_ADD(&($$->members), $3, next);
642 }
643 ;
644
645ImportsElement:
646 TypeRefName {
647 $$ = asn1p_expr_new(yylineno);
648 checkmem($$);
649 $$->Identifier = $1;
650 $$->expr_type = A1TC_REFERENCE;
651 }
vlm0aa86902004-10-12 23:26:53 +0000652 | TypeRefName '{' '}' { /* Completely equivalent to above */
653 $$ = asn1p_expr_new(yylineno);
654 checkmem($$);
655 $$->Identifier = $1;
656 $$->expr_type = A1TC_REFERENCE;
657 }
vlmfa67ddc2004-06-03 03:38:44 +0000658 | Identifier {
659 $$ = asn1p_expr_new(yylineno);
660 checkmem($$);
661 $$->Identifier = $1;
662 $$->expr_type = A1TC_REFERENCE;
663 }
664 ;
665
666ExportsDefinition:
667 TOK_EXPORTS ExportsBody ';' {
668 $$ = $2;
669 }
670 | TOK_EXPORTS TOK_ALL ';' {
671 $$ = 0;
672 }
673 | TOK_EXPORTS ';' {
674 /* Empty EXPORTS clause effectively prohibits export. */
675 $$ = asn1p_xports_new();
676 checkmem($$);
677 }
678 ;
679
680ExportsBody:
681 ExportsElement {
682 $$ = asn1p_xports_new();
683 assert($$);
684 TQ_ADD(&($$->members), $1, next);
685 }
686 | ExportsBody ',' ExportsElement {
687 $$ = $1;
688 TQ_ADD(&($$->members), $3, next);
689 }
690 ;
691
692ExportsElement:
693 TypeRefName {
694 $$ = asn1p_expr_new(yylineno);
695 checkmem($$);
696 $$->Identifier = $1;
697 $$->expr_type = A1TC_EXPORTVAR;
698 }
vlm0aa86902004-10-12 23:26:53 +0000699 | TypeRefName '{' '}' {
700 $$ = asn1p_expr_new(yylineno);
701 checkmem($$);
702 $$->Identifier = $1;
703 $$->expr_type = A1TC_EXPORTVAR;
704 }
vlmfa67ddc2004-06-03 03:38:44 +0000705 | Identifier {
706 $$ = asn1p_expr_new(yylineno);
707 checkmem($$);
708 $$->Identifier = $1;
709 $$->expr_type = A1TC_EXPORTVAR;
710 }
711 ;
712
713
714ValueSetDefinition:
vlm7388db02005-03-31 21:48:13 +0000715 TypeRefName DefinedTypeRef TOK_PPEQ
716 '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
vlmfa67ddc2004-06-03 03:38:44 +0000717 $$ = $2;
718 assert($$->Identifier == 0);
719 $$->Identifier = $1;
720 $$->meta_type = AMT_VALUESET;
vlm7259fdc2006-03-16 22:39:56 +0000721 /* take care of ValueSet body */
vlmfa67ddc2004-06-03 03:38:44 +0000722 }
723 ;
724
725DefinedTypeRef:
726 ComplexTypeReference {
727 $$ = asn1p_expr_new(yylineno);
728 checkmem($$);
729 $$->reference = $1;
730 $$->expr_type = A1TC_REFERENCE;
731 $$->meta_type = AMT_TYPEREF;
732 }
733 | BasicTypeId {
734 $$ = asn1p_expr_new(yylineno);
735 checkmem($$);
736 $$->expr_type = $1;
737 $$->meta_type = AMT_TYPE;
738 }
739 ;
740
vlmfa67ddc2004-06-03 03:38:44 +0000741/*
742 * Data Type Reference.
743 * === EXAMPLE ===
744 * Type3 ::= CHOICE { a Type1, b Type 2 }
745 * === EOF ===
746 */
vlmfa67ddc2004-06-03 03:38:44 +0000747DataTypeReference:
748 /*
749 * Optionally tagged type definition.
750 */
vlmdc7cf042006-03-09 08:49:26 +0000751 TypeRefName TOK_PPEQ Type {
vlmfce48a42004-09-14 02:36:39 +0000752 $$ = $3;
vlmfa67ddc2004-06-03 03:38:44 +0000753 $$->Identifier = $1;
vlmfa67ddc2004-06-03 03:38:44 +0000754 assert($$->expr_type);
755 assert($$->meta_type);
756 }
vlmdc7cf042006-03-09 08:49:26 +0000757 | TypeRefName TOK_PPEQ ObjectClass {
vlmfa67ddc2004-06-03 03:38:44 +0000758 $$ = $3;
759 $$->Identifier = $1;
760 assert($$->expr_type == A1TC_CLASSDEF);
vlmdc7cf042006-03-09 08:49:26 +0000761 assert($$->meta_type == AMT_OBJECTCLASS);
vlmfa67ddc2004-06-03 03:38:44 +0000762 }
763 /*
764 * Parametrized <Type> declaration:
765 * === EXAMPLE ===
766 * SIGNED { ToBeSigned } ::= SEQUENCE {
767 * toBeSigned ToBeSigned,
768 * algorithm AlgorithmIdentifier,
769 * signature BIT STRING
770 * }
771 * === EOF ===
772 */
vlmec8f6812004-08-22 03:19:54 +0000773 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
vlmfa67ddc2004-06-03 03:38:44 +0000774 $$ = $6;
775 assert($$->Identifier == 0);
776 $$->Identifier = $1;
vlm0c6d3812006-03-21 03:40:38 +0000777 $$->lhs_params = $3;
vlmfa67ddc2004-06-03 03:38:44 +0000778 }
779 ;
780
781ParameterArgumentList:
782 ParameterArgumentName {
783 int ret;
784 $$ = asn1p_paramlist_new(yylineno);
785 checkmem($$);
786 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
787 checkmem(ret == 0);
788 if($1.governor) asn1p_ref_free($1.governor);
789 if($1.argument) free($1.argument);
790 }
791 | ParameterArgumentList ',' ParameterArgumentName {
792 int ret;
793 $$ = $1;
794 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
795 checkmem(ret == 0);
796 if($3.governor) asn1p_ref_free($3.governor);
797 if($3.argument) free($3.argument);
798 }
799 ;
800
801ParameterArgumentName:
802 TypeRefName {
803 $$.governor = NULL;
804 $$.argument = $1;
805 }
806 | TypeRefName ':' Identifier {
807 int ret;
808 $$.governor = asn1p_ref_new(yylineno);
809 ret = asn1p_ref_add_component($$.governor, $1, 0);
810 checkmem(ret == 0);
811 $$.argument = $3;
812 }
vlm4053ca52005-02-18 16:34:21 +0000813 | TypeRefName ':' TypeRefName {
814 int ret;
815 $$.governor = asn1p_ref_new(yylineno);
816 ret = asn1p_ref_add_component($$.governor, $1, 0);
817 checkmem(ret == 0);
818 $$.argument = $3;
819 }
vlmfa67ddc2004-06-03 03:38:44 +0000820 | BasicTypeId ':' Identifier {
821 int ret;
822 $$.governor = asn1p_ref_new(yylineno);
823 ret = asn1p_ref_add_component($$.governor,
824 ASN_EXPR_TYPE2STR($1), 1);
825 checkmem(ret == 0);
826 $$.argument = $3;
827 }
828 ;
829
vlm0c6d3812006-03-21 03:40:38 +0000830Specializations:
831 Specialization {
vlmfa67ddc2004-06-03 03:38:44 +0000832 $$ = asn1p_expr_new(yylineno);
833 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000834 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000835 }
vlm0c6d3812006-03-21 03:40:38 +0000836 | Specializations ',' Specialization {
vlmfa67ddc2004-06-03 03:38:44 +0000837 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000838 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000839 }
840 ;
841
vlm0c6d3812006-03-21 03:40:38 +0000842Specialization:
vlmec8f6812004-08-22 03:19:54 +0000843 Type {
vlmfa67ddc2004-06-03 03:38:44 +0000844 $$ = $1;
845 }
846 | Identifier {
vlm0c6d3812006-03-21 03:40:38 +0000847 asn1p_ref_t *ref;
vlmfa67ddc2004-06-03 03:38:44 +0000848 $$ = asn1p_expr_new(yylineno);
849 checkmem($$);
850 $$->Identifier = $1;
851 $$->expr_type = A1TC_REFERENCE;
852 $$->meta_type = AMT_VALUE;
vlm0c6d3812006-03-21 03:40:38 +0000853 ref = asn1p_ref_new(yylineno);
854 asn1p_ref_add_component(ref, $1, RLT_lowercase);
855 $$->value = asn1p_value_fromref(ref, 0);
vlmfa67ddc2004-06-03 03:38:44 +0000856 }
857 ;
858
859/*
vlm0c6d3812006-03-21 03:40:38 +0000860 | '{' Specialization '}' {
vlm4053ca52005-02-18 16:34:21 +0000861 $$ = asn1p_expr_new(yylineno);
862 checkmem($$);
863 asn1p_expr_add($$, $2);
864 $$->expr_type = A1TC_PARAMETRIZED;
865 $$->meta_type = AMT_TYPE;
866 }
867 ;
868*/
869
870/*
vlmfa67ddc2004-06-03 03:38:44 +0000871 * A collection of constructed data type members.
872 */
vlm0aa86902004-10-12 23:26:53 +0000873optComponentTypeLists:
874 { $$ = asn1p_expr_new(yylineno); }
875 | ComponentTypeLists { $$ = $1; };
876
vlmec8f6812004-08-22 03:19:54 +0000877ComponentTypeLists:
878 ComponentType {
vlmfa67ddc2004-06-03 03:38:44 +0000879 $$ = asn1p_expr_new(yylineno);
880 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000881 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000882 }
vlmec8f6812004-08-22 03:19:54 +0000883 | ComponentTypeLists ',' ComponentType {
vlmfa67ddc2004-06-03 03:38:44 +0000884 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000885 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000886 }
887 ;
888
vlmec8f6812004-08-22 03:19:54 +0000889ComponentType:
vlmfce48a42004-09-14 02:36:39 +0000890 Identifier Type optMarker {
vlmec8f6812004-08-22 03:19:54 +0000891 $$ = $2;
892 assert($$->Identifier == 0);
vlmfce48a42004-09-14 02:36:39 +0000893 $$->Identifier = $1;
vlm177a5b62005-09-05 05:17:57 +0000894 $3.flags |= $$->marker.flags;
vlmec8f6812004-08-22 03:19:54 +0000895 $$->marker = $3;
896 }
vlm177a5b62005-09-05 05:17:57 +0000897 | Type optMarker {
898 $$ = $1;
899 $2.flags |= $$->marker.flags;
900 $$->marker = $2;
901 _fixup_anonymous_identifier($$);
902 }
vlmec8f6812004-08-22 03:19:54 +0000903 | TOK_COMPONENTS TOK_OF Type {
904 $$ = asn1p_expr_new(yylineno);
905 checkmem($$);
906 $$->meta_type = $3->meta_type;
907 $$->expr_type = A1TC_COMPONENTS_OF;
vlm6a02a8a2004-09-08 00:28:11 +0000908 asn1p_expr_add($$, $3);
vlmec8f6812004-08-22 03:19:54 +0000909 }
910 | ExtensionAndException {
911 $$ = $1;
912 }
913 ;
914
915AlternativeTypeLists:
916 AlternativeType {
917 $$ = asn1p_expr_new(yylineno);
918 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000919 asn1p_expr_add($$, $1);
vlmec8f6812004-08-22 03:19:54 +0000920 }
921 | AlternativeTypeLists ',' AlternativeType {
922 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000923 asn1p_expr_add($$, $3);
vlmec8f6812004-08-22 03:19:54 +0000924 }
925 ;
926
927AlternativeType:
vlmfce48a42004-09-14 02:36:39 +0000928 Identifier Type {
vlmec8f6812004-08-22 03:19:54 +0000929 $$ = $2;
930 assert($$->Identifier == 0);
vlmfce48a42004-09-14 02:36:39 +0000931 $$->Identifier = $1;
vlmec8f6812004-08-22 03:19:54 +0000932 }
933 | ExtensionAndException {
934 $$ = $1;
935 }
vlm5d89c3d2005-08-13 09:07:11 +0000936 | Type {
937 $$ = $1;
938 _fixup_anonymous_identifier($$);
939 }
vlmec8f6812004-08-22 03:19:54 +0000940 ;
941
vlmdc7cf042006-03-09 08:49:26 +0000942ObjectClass:
943 TOK_CLASS '{' FieldSpec '}' optWithSyntax {
vlmfa67ddc2004-06-03 03:38:44 +0000944 $$ = $3;
945 checkmem($$);
946 $$->with_syntax = $5;
947 assert($$->expr_type == A1TC_CLASSDEF);
vlmdc7cf042006-03-09 08:49:26 +0000948 assert($$->meta_type == AMT_OBJECTCLASS);
vlmfa67ddc2004-06-03 03:38:44 +0000949 }
950 ;
951
952optUnique:
953 { $$ = 0; }
954 | TOK_UNIQUE { $$ = 1; }
955 ;
956
vlmdc7cf042006-03-09 08:49:26 +0000957FieldSpec:
vlmfa67ddc2004-06-03 03:38:44 +0000958 ClassField {
959 $$ = asn1p_expr_new(yylineno);
960 checkmem($$);
961 $$->expr_type = A1TC_CLASSDEF;
vlmdc7cf042006-03-09 08:49:26 +0000962 $$->meta_type = AMT_OBJECTCLASS;
vlm6a02a8a2004-09-08 00:28:11 +0000963 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000964 }
vlmdc7cf042006-03-09 08:49:26 +0000965 | FieldSpec ',' ClassField {
vlmfa67ddc2004-06-03 03:38:44 +0000966 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000967 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000968 }
969 ;
970
vlmdc7cf042006-03-09 08:49:26 +0000971 /* X.681 */
vlmfa67ddc2004-06-03 03:38:44 +0000972ClassField:
vlmdc7cf042006-03-09 08:49:26 +0000973
974 /* TypeFieldSpec ::= typefieldreference TypeOptionalitySpec? */
975 TOK_typefieldreference optMarker {
vlmfa67ddc2004-06-03 03:38:44 +0000976 $$ = asn1p_expr_new(yylineno);
977 checkmem($$);
vlmdc7cf042006-03-09 08:49:26 +0000978 $$->Identifier = $1;
vlmfa67ddc2004-06-03 03:38:44 +0000979 $$->meta_type = AMT_OBJECTFIELD;
vlmdc7cf042006-03-09 08:49:26 +0000980 $$->expr_type = A1TC_CLASSFIELD_TFS; /* TypeFieldSpec */
vlmfa67ddc2004-06-03 03:38:44 +0000981 $$->marker = $2;
982 }
vlmdc7cf042006-03-09 08:49:26 +0000983
984 /* FixedTypeValueFieldSpec ::= valuefieldreference Type UNIQUE ? ValueOptionalitySpec ? */
985 | TOK_valuefieldreference Type optUnique optMarker {
986 $$ = asn1p_expr_new(yylineno);
987 $$->Identifier = $1;
988 $$->meta_type = AMT_OBJECTFIELD;
989 $$->expr_type = A1TC_CLASSFIELD_FTVFS; /* FixedTypeValueFieldSpec */
vlmbde35d42004-11-24 17:43:29 +0000990 $$->unique = $3;
vlmdc7cf042006-03-09 08:49:26 +0000991 $$->marker = $4;
992 asn1p_expr_add($$, $2);
vlmfa67ddc2004-06-03 03:38:44 +0000993 }
vlmdc7cf042006-03-09 08:49:26 +0000994
995 /* VariableTypeValueFieldSpec ::= valuefieldreference FieldName ValueOptionalitySpec ? */
996 | TOK_valuefieldreference FieldName optMarker {
997 $$ = asn1p_expr_new(yylineno);
998 $$->Identifier = $1;
999 $$->meta_type = AMT_OBJECTFIELD;
1000 $$->expr_type = A1TC_CLASSFIELD_VTVFS;
1001 $$->reference = $2;
1002 $$->marker = $3;
1003 }
1004
vlmdc7cf042006-03-09 08:49:26 +00001005 /* ObjectFieldSpec ::= objectfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1006 | TOK_valuefieldreference DefinedObjectClass optMarker {
vlmfa67ddc2004-06-03 03:38:44 +00001007 $$ = asn1p_expr_new(yylineno);
1008 checkmem($$);
vlmdc7cf042006-03-09 08:49:26 +00001009 $$->Identifier = $1;
1010 $$->reference = $2;
vlmfa67ddc2004-06-03 03:38:44 +00001011 $$->meta_type = AMT_OBJECTFIELD;
vlmdc7cf042006-03-09 08:49:26 +00001012 $$->expr_type = A1TC_CLASSFIELD_OFS;
1013 $$->marker = $3;
vlmfa67ddc2004-06-03 03:38:44 +00001014 }
vlmdc7cf042006-03-09 08:49:26 +00001015
vlmee7196e2006-03-09 09:08:49 +00001016 /* VariableTypeValueSetFieldSpec ::= valuesetfieldreference FieldName ValueOptionalitySpec ? */
1017 | TOK_typefieldreference FieldName optMarker {
vlmdc7cf042006-03-09 08:49:26 +00001018 $$ = asn1p_expr_new(yylineno);
vlmdc7cf042006-03-09 08:49:26 +00001019 $$->Identifier = $1;
vlmdc7cf042006-03-09 08:49:26 +00001020 $$->meta_type = AMT_OBJECTFIELD;
vlmee7196e2006-03-09 09:08:49 +00001021 $$->expr_type = A1TC_CLASSFIELD_VTVSFS;
1022 $$->reference = $2;
vlmdc7cf042006-03-09 08:49:26 +00001023 $$->marker = $3;
1024 }
1025
1026 /* FixedTypeValueSetFieldSpec ::= valuesetfieldreference Type ValueSetOptionalitySpec ? */
1027 | TOK_typefieldreference Type optMarker {
1028 $$ = asn1p_expr_new(yylineno);
1029 checkmem($$);
1030 $$->Identifier = $1;
1031 $$->meta_type = AMT_OBJECTFIELD;
1032 $$->expr_type = A1TC_CLASSFIELD_FTVSFS;
1033 asn1p_expr_add($$, $2);
1034 $$->marker = $3;
1035 }
1036
vlmee7196e2006-03-09 09:08:49 +00001037 /* ObjectSetFieldSpec ::= objectsetfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1038 | TOK_typefieldreference DefinedObjectClass optMarker {
1039 $$ = asn1p_expr_new(yylineno);
1040 checkmem($$);
1041 $$->Identifier = $1;
1042 $$->reference = $2;
1043 $$->meta_type = AMT_OBJECTFIELD;
1044 $$->expr_type = A1TC_CLASSFIELD_OSFS;
1045 $$->marker = $3;
1046 }
vlmfa67ddc2004-06-03 03:38:44 +00001047 ;
1048
1049optWithSyntax:
1050 { $$ = 0; }
1051 | WithSyntax {
1052 $$ = $1;
1053 }
1054 ;
1055
1056WithSyntax:
1057 TOK_WITH TOK_SYNTAX '{'
1058 { asn1p_lexer_hack_enable_with_syntax(); }
vlm808411d2006-03-14 16:31:37 +00001059 WithSyntaxList
vlmfa67ddc2004-06-03 03:38:44 +00001060 '}' {
1061 $$ = $5;
1062 }
1063 ;
1064
vlm808411d2006-03-14 16:31:37 +00001065WithSyntaxList:
1066 WithSyntaxToken {
vlmfa67ddc2004-06-03 03:38:44 +00001067 $$ = asn1p_wsyntx_new();
1068 TQ_ADD(&($$->chunks), $1, next);
1069 }
vlm808411d2006-03-14 16:31:37 +00001070 | WithSyntaxList WithSyntaxToken {
vlmfa67ddc2004-06-03 03:38:44 +00001071 $$ = $1;
1072 TQ_ADD(&($$->chunks), $2, next);
1073 }
1074 ;
1075
vlm808411d2006-03-14 16:31:37 +00001076WithSyntaxToken:
vlmeeb3c512006-03-16 05:11:14 +00001077 TOK_whitespace {
vlmfa67ddc2004-06-03 03:38:44 +00001078 $$ = asn1p_wsyntx_chunk_frombuf($1.buf, $1.len, 0);
vlmeeb3c512006-03-16 05:11:14 +00001079 $$->type = WC_WHITESPACE;
vlmfa67ddc2004-06-03 03:38:44 +00001080 }
vlm808411d2006-03-14 16:31:37 +00001081 | TOK_Literal {
1082 $$ = asn1p_wsyntx_chunk_frombuf($1, strlen($1), 0);
1083 }
vlma6a84d72006-03-16 10:03:35 +00001084 | PrimitiveFieldReference {
1085 $$ = asn1p_wsyntx_chunk_frombuf($1.name, strlen($1.name), 0);
1086 $$->type = WC_FIELD;
vlmfa67ddc2004-06-03 03:38:44 +00001087 }
vlm808411d2006-03-14 16:31:37 +00001088 | '[' WithSyntaxList ']' {
1089 $$ = asn1p_wsyntx_chunk_fromsyntax($2);
1090 }
vlmfa67ddc2004-06-03 03:38:44 +00001091 ;
1092
vlmfa67ddc2004-06-03 03:38:44 +00001093ExtensionAndException:
1094 TOK_ThreeDots {
vlm39e5ed72004-09-05 10:40:41 +00001095 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001096 checkmem($$);
1097 $$->Identifier = strdup("...");
1098 checkmem($$->Identifier);
1099 $$->expr_type = A1TC_EXTENSIBLE;
1100 $$->meta_type = AMT_TYPE;
1101 }
1102 | TOK_ThreeDots '!' DefinedValue {
vlm39e5ed72004-09-05 10:40:41 +00001103 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001104 checkmem($$);
1105 $$->Identifier = strdup("...");
1106 checkmem($$->Identifier);
1107 $$->value = $3;
1108 $$->expr_type = A1TC_EXTENSIBLE;
1109 $$->meta_type = AMT_TYPE;
1110 }
1111 | TOK_ThreeDots '!' SignedNumber {
vlm39e5ed72004-09-05 10:40:41 +00001112 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001113 checkmem($$);
1114 $$->Identifier = strdup("...");
1115 $$->value = $3;
1116 checkmem($$->Identifier);
1117 $$->expr_type = A1TC_EXTENSIBLE;
1118 $$->meta_type = AMT_TYPE;
1119 }
1120 ;
1121
vlmec8f6812004-08-22 03:19:54 +00001122Type:
vlmfce48a42004-09-14 02:36:39 +00001123 optTag TypeDeclaration optConstraints {
1124 $$ = $2;
1125 $$->tag = $1;
vlmec8f6812004-08-22 03:19:54 +00001126 /*
1127 * Outer constraint for SEQUENCE OF and SET OF applies
1128 * to the inner type.
1129 */
1130 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1131 || $$->expr_type == ASN_CONSTR_SET_OF) {
1132 assert(!TQ_FIRST(&($$->members))->constraints);
vlmfce48a42004-09-14 02:36:39 +00001133 TQ_FIRST(&($$->members))->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001134 } else {
1135 if($$->constraints) {
1136 assert(!$2);
1137 } else {
vlmfce48a42004-09-14 02:36:39 +00001138 $$->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001139 }
1140 }
vlm177a5b62005-09-05 05:17:57 +00001141 }
1142 ;
1143
1144NSTD_IndirectMarker:
1145 {
1146 $$ = asn1p_as_pointer ? EM_INDIRECT : 0;
1147 asn1p_as_pointer = 0;
vlmec8f6812004-08-22 03:19:54 +00001148 }
1149 ;
1150
1151TypeDeclaration:
vlm177a5b62005-09-05 05:17:57 +00001152 NSTD_IndirectMarker TypeDeclarationSet {
vlm066dc102005-08-22 12:23:54 +00001153 $$ = $2;
vlm177a5b62005-09-05 05:17:57 +00001154 $$->marker.flags |= $1;
1155
1156 if(($$->marker.flags & EM_INDIRECT)
1157 && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
1158 fprintf(stderr,
1159 "INFO: Directive <ASN1C:RepresentAsPointer> "
1160 "applied to %s at line %d\n",
1161 ASN_EXPR_TYPE2STR($$->expr_type)
1162 ? ASN_EXPR_TYPE2STR($$->expr_type)
1163 : "member",
1164 $$->_lineno
1165 );
1166 }
vlm066dc102005-08-22 12:23:54 +00001167 }
vlm177a5b62005-09-05 05:17:57 +00001168 ;
vlm066dc102005-08-22 12:23:54 +00001169
1170TypeDeclarationSet:
vlmfa67ddc2004-06-03 03:38:44 +00001171 BasicType {
1172 $$ = $1;
1173 }
vlm177a5b62005-09-05 05:17:57 +00001174 | TOK_CHOICE '{' AlternativeTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001175 $$ = $3;
1176 assert($$->expr_type == A1TC_INVALID);
1177 $$->expr_type = ASN_CONSTR_CHOICE;
1178 $$->meta_type = AMT_TYPE;
vlmfa67ddc2004-06-03 03:38:44 +00001179 }
vlm177a5b62005-09-05 05:17:57 +00001180 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001181 $$ = $3;
1182 assert($$->expr_type == A1TC_INVALID);
1183 $$->expr_type = ASN_CONSTR_SEQUENCE;
1184 $$->meta_type = AMT_TYPE;
1185 }
vlm177a5b62005-09-05 05:17:57 +00001186 | TOK_SET '{' optComponentTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001187 $$ = $3;
1188 assert($$->expr_type == A1TC_INVALID);
1189 $$->expr_type = ASN_CONSTR_SET;
1190 $$->meta_type = AMT_TYPE;
1191 }
vlm151c0b22004-09-22 16:03:36 +00001192 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
vlm39e5ed72004-09-05 10:40:41 +00001193 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001194 checkmem($$);
1195 $$->constraints = $2;
1196 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1197 $$->meta_type = AMT_TYPE;
vlm151c0b22004-09-22 16:03:36 +00001198 $6->Identifier = $4;
1199 $6->tag = $5;
1200 asn1p_expr_add($$, $6);
vlmec8f6812004-08-22 03:19:54 +00001201 }
vlm151c0b22004-09-22 16:03:36 +00001202 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
vlm39e5ed72004-09-05 10:40:41 +00001203 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001204 checkmem($$);
1205 $$->constraints = $2;
1206 $$->expr_type = ASN_CONSTR_SET_OF;
1207 $$->meta_type = AMT_TYPE;
vlm151c0b22004-09-22 16:03:36 +00001208 $6->Identifier = $4;
1209 $6->tag = $5;
1210 asn1p_expr_add($$, $6);
vlmec8f6812004-08-22 03:19:54 +00001211 }
1212 | TOK_ANY {
vlm39e5ed72004-09-05 10:40:41 +00001213 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001214 checkmem($$);
vlm044f7442004-09-04 04:49:21 +00001215 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001216 $$->meta_type = AMT_TYPE;
1217 }
1218 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1219 int ret;
vlm39e5ed72004-09-05 10:40:41 +00001220 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001221 checkmem($$);
1222 $$->reference = asn1p_ref_new(yylineno);
1223 ret = asn1p_ref_add_component($$->reference,
1224 $4, RLT_lowercase);
1225 checkmem(ret == 0);
vlm044f7442004-09-04 04:49:21 +00001226 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001227 $$->meta_type = AMT_TYPE;
1228 }
vlmfa67ddc2004-06-03 03:38:44 +00001229 /*
vlmfa67ddc2004-06-03 03:38:44 +00001230 * A DefinedType reference.
1231 * "CLASS1.&id.&id2"
1232 * or
1233 * "Module.Type"
1234 * or
1235 * "Module.identifier"
1236 * or
1237 * "Type"
1238 */
1239 | ComplexTypeReference {
1240 $$ = asn1p_expr_new(yylineno);
1241 checkmem($$);
1242 $$->reference = $1;
1243 $$->expr_type = A1TC_REFERENCE;
1244 $$->meta_type = AMT_TYPEREF;
1245 }
vlm0c6d3812006-03-21 03:40:38 +00001246 /*
1247 * A parametrized assignment.
1248 */
1249 | ComplexTypeReference '{' Specializations '}' {
1250 $$ = asn1p_expr_new(yylineno);
1251 checkmem($$);
1252 $$->reference = $1;
1253 $$->rhs_pspecs = $3;
1254 $$->expr_type = A1TC_REFERENCE;
1255 $$->meta_type = AMT_TYPEREF;
1256 }
vlmfa67ddc2004-06-03 03:38:44 +00001257 | TOK_INSTANCE TOK_OF ComplexTypeReference {
1258 $$ = asn1p_expr_new(yylineno);
1259 checkmem($$);
1260 $$->reference = $3;
1261 $$->expr_type = A1TC_INSTANCE;
1262 $$->meta_type = AMT_TYPE;
1263 }
1264 ;
1265
1266/*
1267 * A type name consisting of several components.
1268 * === EXAMPLE ===
1269 * === EOF ===
1270 */
1271ComplexTypeReference:
1272 TOK_typereference {
1273 int ret;
1274 $$ = asn1p_ref_new(yylineno);
1275 checkmem($$);
1276 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1277 checkmem(ret == 0);
1278 free($1);
1279 }
1280 | TOK_typereference '.' TypeRefName {
1281 int ret;
1282 $$ = asn1p_ref_new(yylineno);
1283 checkmem($$);
1284 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1285 checkmem(ret == 0);
1286 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1287 checkmem(ret == 0);
1288 free($1);
1289 }
vlmc94e28f2004-09-15 11:59:51 +00001290 | ObjectClassReference '.' TypeRefName {
1291 int ret;
1292 $$ = asn1p_ref_new(yylineno);
1293 checkmem($$);
1294 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1295 checkmem(ret == 0);
1296 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1297 checkmem(ret == 0);
1298 free($1);
1299 }
vlmfa67ddc2004-06-03 03:38:44 +00001300 | TOK_typereference '.' Identifier {
1301 int ret;
1302 $$ = asn1p_ref_new(yylineno);
1303 checkmem($$);
1304 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1305 checkmem(ret == 0);
1306 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1307 checkmem(ret == 0);
1308 free($1);
1309 }
1310 | ObjectClassReference {
1311 int ret;
1312 $$ = asn1p_ref_new(yylineno);
1313 checkmem($$);
1314 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1315 free($1);
1316 checkmem(ret == 0);
1317 }
1318 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1319 int ret;
1320 $$ = $3;
1321 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1322 free($1);
1323 checkmem(ret == 0);
1324 /*
1325 * Move the last element infront.
1326 */
1327 {
1328 struct asn1p_ref_component_s tmp_comp;
1329 tmp_comp = $$->components[$$->comp_count-1];
1330 memmove(&$$->components[1],
1331 &$$->components[0],
1332 sizeof($$->components[0])
1333 * ($$->comp_count - 1));
1334 $$->components[0] = tmp_comp;
1335 }
1336 }
1337 ;
1338
1339ComplexTypeReferenceAmpList:
1340 ComplexTypeReferenceElement {
1341 int ret;
1342 $$ = asn1p_ref_new(yylineno);
1343 checkmem($$);
1344 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1345 free($1.name);
1346 checkmem(ret == 0);
1347 }
1348 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1349 int ret;
1350 $$ = $1;
1351 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1352 free($3.name);
1353 checkmem(ret == 0);
1354 }
1355 ;
1356
vlma6a84d72006-03-16 10:03:35 +00001357ComplexTypeReferenceElement: PrimitiveFieldReference;
vlmfa67ddc2004-06-03 03:38:44 +00001358
vlma6a84d72006-03-16 10:03:35 +00001359PrimitiveFieldReference:
vlmfa67ddc2004-06-03 03:38:44 +00001360 /* "&Type1" */
1361 TOK_typefieldreference {
1362 $$.lex_type = RLT_AmpUppercase;
1363 $$.name = $1;
1364 }
1365 /* "&id" */
1366 | TOK_valuefieldreference {
1367 $$.lex_type = RLT_Amplowercase;
1368 $$.name = $1;
1369 }
1370 ;
1371
1372
vlmdc7cf042006-03-09 08:49:26 +00001373FieldName:
1374 /* "&Type1" */
1375 TOK_typefieldreference {
1376 $$ = asn1p_ref_new(yylineno);
1377 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1378 }
1379 | FieldName '.' TOK_typefieldreference {
1380 $$ = $$;
1381 asn1p_ref_add_component($$, $3, RLT_AmpUppercase);
1382 }
1383 | FieldName '.' TOK_valuefieldreference {
1384 $$ = $$;
1385 asn1p_ref_add_component($$, $3, RLT_Amplowercase);
1386 }
1387 ;
1388
1389DefinedObjectClass:
1390 TOK_capitalreference {
1391 $$ = asn1p_ref_new(yylineno);
1392 asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1393 }
vlmee7196e2006-03-09 09:08:49 +00001394/*
vlmdc7cf042006-03-09 08:49:26 +00001395 | TypeRefName '.' TOK_capitalreference {
1396 $$ = asn1p_ref_new(yylineno);
1397 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1398 asn1p_ref_add_component($$, $3, RLT_CAPITALS);
1399 }
vlmee7196e2006-03-09 09:08:49 +00001400*/
vlmdc7cf042006-03-09 08:49:26 +00001401 ;
1402
1403
vlmfa67ddc2004-06-03 03:38:44 +00001404/*
1405 * === EXAMPLE ===
1406 * value INTEGER ::= 1
1407 * === EOF ===
1408 */
1409ValueDefinition:
vlmc94e28f2004-09-15 11:59:51 +00001410 Identifier DefinedTypeRef TOK_PPEQ Value {
vlmfa67ddc2004-06-03 03:38:44 +00001411 $$ = $2;
1412 assert($$->Identifier == NULL);
1413 $$->Identifier = $1;
1414 $$->meta_type = AMT_VALUE;
1415 $$->value = $4;
1416 }
1417 ;
1418
vlmc94e28f2004-09-15 11:59:51 +00001419Value:
1420 Identifier ':' Value {
1421 $$ = asn1p_value_fromint(0);
1422 checkmem($$);
1423 $$->type = ATV_CHOICE_IDENTIFIER;
1424 $$->value.choice_identifier.identifier = $1;
1425 $$->value.choice_identifier.value = $3;
1426 }
vlmd30bc6c2005-03-24 16:27:02 +00001427 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
vlmfa67ddc2004-06-03 03:38:44 +00001428 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1429 checkmem($$);
1430 $$->type = ATV_UNPARSED;
1431 }
vlmc94e28f2004-09-15 11:59:51 +00001432 | TOK_NULL {
1433 $$ = asn1p_value_fromint(0);
1434 checkmem($$);
1435 $$->type = ATV_NULL;
1436 }
1437 | TOK_FALSE {
1438 $$ = asn1p_value_fromint(0);
1439 checkmem($$);
1440 $$->type = ATV_FALSE;
1441 }
1442 | TOK_TRUE {
1443 $$ = asn1p_value_fromint(0);
1444 checkmem($$);
1445 $$->type = ATV_TRUE;
1446 }
vlmfa67ddc2004-06-03 03:38:44 +00001447 | TOK_bstring {
1448 $$ = _convert_bitstring2binary($1, 'B');
1449 checkmem($$);
1450 }
1451 | TOK_hstring {
1452 $$ = _convert_bitstring2binary($1, 'H');
1453 checkmem($$);
1454 }
vlme1e6ed82005-03-24 14:26:38 +00001455 | RestrictedCharacterStringValue {
1456 $$ = $$;
vlmfa67ddc2004-06-03 03:38:44 +00001457 }
1458 | SignedNumber {
1459 $$ = $1;
1460 }
1461 | DefinedValue {
1462 $$ = $1;
1463 }
1464 ;
1465
1466DefinedValue:
1467 Identifier {
1468 asn1p_ref_t *ref;
1469 int ret;
1470 ref = asn1p_ref_new(yylineno);
1471 checkmem(ref);
1472 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1473 checkmem(ret == 0);
1474 $$ = asn1p_value_fromref(ref, 0);
1475 checkmem($$);
1476 free($1);
1477 }
1478 | TypeRefName '.' Identifier {
1479 asn1p_ref_t *ref;
1480 int ret;
1481 ref = asn1p_ref_new(yylineno);
1482 checkmem(ref);
1483 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1484 checkmem(ret == 0);
1485 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1486 checkmem(ret == 0);
1487 $$ = asn1p_value_fromref(ref, 0);
1488 checkmem($$);
1489 free($1);
1490 free($3);
1491 }
1492 ;
1493
vlme1e6ed82005-03-24 14:26:38 +00001494
1495RestrictedCharacterStringValue:
1496 TOK_cstring {
1497 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1498 checkmem($$);
1499 }
vlm2c8c44d2005-03-24 16:22:35 +00001500 | TOK_tuple {
1501 $$ = asn1p_value_fromint($1);
1502 checkmem($$);
1503 $$->type = ATV_TUPLE;
1504 }
1505 | TOK_quadruple {
1506 $$ = asn1p_value_fromint($1);
1507 checkmem($$);
1508 $$->type = ATV_QUADRUPLE;
1509 }
1510 /*
vlme1e6ed82005-03-24 14:26:38 +00001511 | '{' TOK_number ',' TOK_number '}' {
1512 asn1c_integer_t v = ($2 << 4) + $4;
1513 if($2 > 7) return yyerror("X.680:2003, #37.14 "
1514 "mandates 0..7 range for Tuple's TableColumn");
1515 if($4 > 15) return yyerror("X.680:2003, #37.14 "
1516 "mandates 0..15 range for Tuple's TableRow");
1517 $$ = asn1p_value_fromint(v);
1518 checkmem($$);
1519 $$->type = ATV_TUPLE;
1520 }
1521 | '{' TOK_number ',' TOK_number ',' TOK_number ',' TOK_number '}' {
1522 asn1c_integer_t v = ($2 << 24) | ($4 << 16) | ($6 << 8) | $8;
1523 if($2 > 127) return yyerror("X.680:2003, #37.12 "
1524 "mandates 0..127 range for Quadruple's Group");
1525 if($4 > 255) return yyerror("X.680:2003, #37.12 "
1526 "mandates 0..255 range for Quadruple's Plane");
1527 if($6 > 255) return yyerror("X.680:2003, #37.12 "
1528 "mandates 0..255 range for Quadruple's Row");
1529 if($8 > 255) return yyerror("X.680:2003, #37.12 "
1530 "mandates 0..255 range for Quadruple's Cell");
1531 $$ = asn1p_value_fromint(v);
1532 checkmem($$);
1533 $$->type = ATV_QUADRUPLE;
1534 }
vlm2c8c44d2005-03-24 16:22:35 +00001535 */
vlme1e6ed82005-03-24 14:26:38 +00001536 ;
1537
vlmfa67ddc2004-06-03 03:38:44 +00001538Opaque:
1539 TOK_opaque {
vlm6611add2005-03-20 14:28:32 +00001540 $$.len = $1.len + 1;
vlmfa67ddc2004-06-03 03:38:44 +00001541 $$.buf = malloc($$.len + 1);
1542 checkmem($$.buf);
1543 $$.buf[0] = '{';
vlm6611add2005-03-20 14:28:32 +00001544 memcpy($$.buf + 1, $1.buf, $1.len);
vlmfa67ddc2004-06-03 03:38:44 +00001545 $$.buf[$$.len] = '\0';
1546 free($1.buf);
1547 }
1548 | Opaque TOK_opaque {
1549 int newsize = $1.len + $2.len;
1550 char *p = malloc(newsize + 1);
1551 checkmem(p);
1552 memcpy(p , $1.buf, $1.len);
1553 memcpy(p + $1.len, $2.buf, $2.len);
1554 p[newsize] = '\0';
1555 free($1.buf);
1556 free($2.buf);
1557 $$.buf = p;
1558 $$.len = newsize;
1559 }
1560 ;
1561
1562BasicTypeId:
1563 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1564 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1565 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1566 | BasicTypeId_UniverationCompatible { $$ = $1; }
1567 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1568 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1569 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1570 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1571 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1572 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1573 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1574 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
vlm5e2c4b92005-03-20 11:12:40 +00001575 | BasicString { $$ = $1; }
vlmfa67ddc2004-06-03 03:38:44 +00001576 ;
1577
1578/*
1579 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1580 */
1581BasicTypeId_UniverationCompatible:
1582 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1583 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1584 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1585 ;
1586
1587BasicType:
1588 BasicTypeId {
vlm39e5ed72004-09-05 10:40:41 +00001589 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001590 checkmem($$);
1591 $$->expr_type = $1;
1592 $$->meta_type = AMT_TYPE;
1593 }
1594 | BasicTypeId_UniverationCompatible UniverationDefinition {
1595 if($2) {
1596 $$ = $2;
1597 } else {
vlm39e5ed72004-09-05 10:40:41 +00001598 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001599 checkmem($$);
1600 }
1601 $$->expr_type = $1;
1602 $$->meta_type = AMT_TYPE;
1603 }
1604 ;
1605
1606BasicString:
1607 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1608 | TOK_GeneralString {
1609 $$ = ASN_STRING_GeneralString;
vlmc94e28f2004-09-15 11:59:51 +00001610 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001611 }
1612 | TOK_GraphicString {
1613 $$ = ASN_STRING_GraphicString;
vlmc94e28f2004-09-15 11:59:51 +00001614 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001615 }
1616 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1617 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1618 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1619 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1620 | TOK_T61String {
1621 $$ = ASN_STRING_T61String;
vlmc94e28f2004-09-15 11:59:51 +00001622 fprintf(stderr, "WARNING: T61String is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001623 }
1624 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1625 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1626 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1627 | TOK_VideotexString {
1628 $$ = ASN_STRING_VideotexString;
vlmc94e28f2004-09-15 11:59:51 +00001629 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001630 }
1631 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1632 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1633 ;
1634
vlm5f0128b2004-08-20 13:25:29 +00001635
vlmfa67ddc2004-06-03 03:38:44 +00001636/*
1637 * Data type constraints.
1638 */
vlmfa67ddc2004-06-03 03:38:44 +00001639Union: '|' | TOK_UNION;
1640Intersection: '^' | TOK_INTERSECTION;
1641Except: TOK_EXCEPT;
1642
vlm9283dbe2004-08-18 04:59:12 +00001643optConstraints:
1644 { $$ = 0; }
vlm5f0128b2004-08-20 13:25:29 +00001645 | Constraints {
1646 $$ = $1;
1647 }
1648 ;
1649
1650Constraints:
1651 SetOfConstraints {
vlm9fe7c922005-08-12 10:08:45 +00001652 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
vlm9283dbe2004-08-18 04:59:12 +00001653 }
1654 | TOK_SIZE '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001655 /*
1656 * This is a special case, for compatibility purposes.
vlm9283dbe2004-08-18 04:59:12 +00001657 * It goes without parentheses.
vlmfa67ddc2004-06-03 03:38:44 +00001658 */
vlm9fe7c922005-08-12 10:08:45 +00001659 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001660 }
vlmfa67ddc2004-06-03 03:38:44 +00001661 ;
1662
vlm9283dbe2004-08-18 04:59:12 +00001663SetOfConstraints:
1664 '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001665 $$ = $2;
1666 }
vlm9283dbe2004-08-18 04:59:12 +00001667 | SetOfConstraints '(' ElementSetSpecs ')' {
vlm9fe7c922005-08-12 10:08:45 +00001668 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
vlm9283dbe2004-08-18 04:59:12 +00001669 }
vlmfa67ddc2004-06-03 03:38:44 +00001670 ;
1671
vlm9283dbe2004-08-18 04:59:12 +00001672ElementSetSpecs:
1673 ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001674 $$ = $1;
1675 }
vlm9283dbe2004-08-18 04:59:12 +00001676 | ElementSetSpec ',' TOK_ThreeDots {
vlmfa67ddc2004-06-03 03:38:44 +00001677 asn1p_constraint_t *ct;
1678 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001679 ct->type = ACT_EL_EXT;
vlm9fe7c922005-08-12 10:08:45 +00001680 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlmfa67ddc2004-06-03 03:38:44 +00001681 }
vlm9283dbe2004-08-18 04:59:12 +00001682 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001683 asn1p_constraint_t *ct;
1684 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001685 ct->type = ACT_EL_EXT;
vlm9fe7c922005-08-12 10:08:45 +00001686 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlm6f5eb0b2004-08-13 12:35:09 +00001687 ct = $$;
vlm9fe7c922005-08-12 10:08:45 +00001688 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
vlmfa67ddc2004-06-03 03:38:44 +00001689 }
vlmfa67ddc2004-06-03 03:38:44 +00001690 ;
1691
vlm9283dbe2004-08-18 04:59:12 +00001692ElementSetSpec:
1693 ConstraintSubtypeElement {
1694 $$ = $1;
1695 }
vlme1e6ed82005-03-24 14:26:38 +00001696 | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001697 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
vlme1e6ed82005-03-24 14:26:38 +00001698 }
vlm9283dbe2004-08-18 04:59:12 +00001699 | ElementSetSpec Union ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001700 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001701 }
vlm9283dbe2004-08-18 04:59:12 +00001702 | ElementSetSpec Intersection ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001703 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001704 }
vlm9283dbe2004-08-18 04:59:12 +00001705 | ConstraintSubtypeElement Except ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001706 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001707 }
1708 ;
1709
1710ConstraintSubtypeElement:
vlm9283dbe2004-08-18 04:59:12 +00001711 ConstraintSpec '(' ElementSetSpecs ')' {
1712 int ret;
1713 $$ = asn1p_constraint_new(yylineno);
1714 checkmem($$);
1715 $$->type = $1;
1716 ret = asn1p_constraint_insert($$, $3);
1717 checkmem(ret == 0);
1718 }
1719 | '(' ElementSetSpecs ')' {
1720 int ret;
1721 $$ = asn1p_constraint_new(yylineno);
1722 checkmem($$);
1723 $$->type = ACT_CA_SET;
1724 ret = asn1p_constraint_insert($$, $2);
1725 checkmem(ret == 0);
1726 }
vlma6a12e32005-03-20 12:58:00 +00001727 | SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001728 $$ = asn1p_constraint_new(yylineno);
1729 checkmem($$);
1730 $$->type = ACT_EL_VALUE;
1731 $$->value = $1;
1732 }
vlma6a12e32005-03-20 12:58:00 +00001733 | ContainedSubtype {
1734 $$ = asn1p_constraint_new(yylineno);
1735 checkmem($$);
1736 $$->type = ACT_EL_TYPE;
1737 $$->containedSubtype = $1;
1738 }
1739 | SingleValue ConstraintRangeSpec SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001740 $$ = asn1p_constraint_new(yylineno);
1741 checkmem($$);
1742 $$->type = $2;
1743 $$->range_start = $1;
1744 $$->range_stop = $3;
1745 }
vlma6a12e32005-03-20 12:58:00 +00001746 | TOK_MIN ConstraintRangeSpec SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001747 $$ = asn1p_constraint_new(yylineno);
1748 checkmem($$);
vlm9283dbe2004-08-18 04:59:12 +00001749 $$->type = $2;
1750 $$->range_start = asn1p_value_fromint(-123);
1751 $$->range_stop = $3;
1752 $$->range_start->type = ATV_MIN;
1753 }
vlma6a12e32005-03-20 12:58:00 +00001754 | SingleValue ConstraintRangeSpec TOK_MAX {
vlm9283dbe2004-08-18 04:59:12 +00001755 $$ = asn1p_constraint_new(yylineno);
1756 checkmem($$);
1757 $$->type = $2;
1758 $$->range_start = $1;
1759 $$->range_stop = asn1p_value_fromint(321);
1760 $$->range_stop->type = ATV_MAX;
1761 }
1762 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1763 $$ = asn1p_constraint_new(yylineno);
1764 checkmem($$);
1765 $$->type = $2;
1766 $$->range_start = asn1p_value_fromint(-123);
1767 $$->range_stop = asn1p_value_fromint(321);
1768 $$->range_start->type = ATV_MIN;
1769 $$->range_stop->type = ATV_MAX;
vlmfa67ddc2004-06-03 03:38:44 +00001770 }
1771 | TableConstraint {
1772 $$ = $1;
1773 }
vlm7bbdc9f2005-03-28 15:01:27 +00001774 | InnerTypeConstraint {
vlmfa67ddc2004-06-03 03:38:44 +00001775 $$ = $1;
1776 }
vlm6611add2005-03-20 14:28:32 +00001777 | TOK_CONSTRAINED TOK_BY '{'
1778 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1779 $$ = asn1p_constraint_new(yylineno);
1780 checkmem($$);
1781 $$->type = ACT_CT_CTDBY;
1782 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
1783 checkmem($$->value);
1784 $$->value->type = ATV_UNPARSED;
1785 }
vlmfa67ddc2004-06-03 03:38:44 +00001786 ;
1787
1788ConstraintRangeSpec:
1789 TOK_TwoDots { $$ = ACT_EL_RANGE; }
1790 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
1791 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
1792 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
1793 ;
1794
1795ConstraintSpec:
1796 TOK_SIZE {
1797 $$ = ACT_CT_SIZE;
1798 }
1799 | TOK_FROM {
1800 $$ = ACT_CT_FROM;
1801 }
1802 ;
1803
vlma6a12e32005-03-20 12:58:00 +00001804SingleValue:
vlm4053ca52005-02-18 16:34:21 +00001805 TOK_FALSE {
1806 $$ = asn1p_value_fromint(0);
1807 checkmem($$);
1808 $$->type = ATV_FALSE;
1809 }
1810 | TOK_TRUE {
1811 $$ = asn1p_value_fromint(1);
1812 checkmem($$);
1813 $$->type = ATV_TRUE;
1814 }
1815 | SignedNumber {
vlmfa67ddc2004-06-03 03:38:44 +00001816 $$ = $1;
1817 }
vlme1e6ed82005-03-24 14:26:38 +00001818 | RestrictedCharacterStringValue {
1819 $$ = $1;
vlm4053ca52005-02-18 16:34:21 +00001820 }
vlmfa67ddc2004-06-03 03:38:44 +00001821 | Identifier {
1822 asn1p_ref_t *ref;
1823 int ret;
1824 ref = asn1p_ref_new(yylineno);
1825 checkmem(ref);
1826 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1827 checkmem(ret == 0);
1828 $$ = asn1p_value_fromref(ref, 0);
1829 checkmem($$);
1830 free($1);
1831 }
vlma6a12e32005-03-20 12:58:00 +00001832 ;
1833
1834ContainedSubtype:
1835 TypeRefName {
vlm4053ca52005-02-18 16:34:21 +00001836 asn1p_ref_t *ref;
1837 int ret;
1838 ref = asn1p_ref_new(yylineno);
1839 checkmem(ref);
1840 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1841 checkmem(ret == 0);
1842 $$ = asn1p_value_fromref(ref, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001843 checkmem($$);
vlm4053ca52005-02-18 16:34:21 +00001844 free($1);
vlmfa67ddc2004-06-03 03:38:44 +00001845 }
1846 ;
1847
vlm7bbdc9f2005-03-28 15:01:27 +00001848InnerTypeConstraint:
1849 TOK_WITH TOK_COMPONENT SetOfConstraints {
vlm9fe7c922005-08-12 10:08:45 +00001850 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
vlm7bbdc9f2005-03-28 15:01:27 +00001851 }
1852 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
vlm9fe7c922005-08-12 10:08:45 +00001853 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001854 }
1855 ;
1856
1857WithComponentsList:
1858 WithComponentsElement {
1859 $$ = $1;
1860 }
1861 | WithComponentsList ',' WithComponentsElement {
vlm9fe7c922005-08-12 10:08:45 +00001862 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001863 }
1864 ;
1865
1866WithComponentsElement:
1867 TOK_ThreeDots {
1868 $$ = asn1p_constraint_new(yylineno);
1869 checkmem($$);
1870 $$->type = ACT_EL_EXT;
vlm7bbdc9f2005-03-28 15:01:27 +00001871 $$->value = asn1p_value_frombuf("...", 3, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001872 }
1873 | Identifier optConstraints optPresenceConstraint {
1874 $$ = asn1p_constraint_new(yylineno);
1875 checkmem($$);
1876 $$->type = ACT_EL_VALUE;
1877 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1878 $$->presence = $3;
vlm7bbdc9f2005-03-28 15:01:27 +00001879 if($2) asn1p_constraint_insert($$, $2);
vlmfa67ddc2004-06-03 03:38:44 +00001880 }
1881 ;
1882
1883/*
1884 * presence constraint for WithComponents
1885 */
1886optPresenceConstraint:
1887 { $$ = ACPRES_DEFAULT; }
1888 | PresenceConstraint { $$ = $1; }
1889 ;
1890
1891PresenceConstraint:
1892 TOK_PRESENT {
1893 $$ = ACPRES_PRESENT;
1894 }
1895 | TOK_ABSENT {
1896 $$ = ACPRES_ABSENT;
1897 }
1898 | TOK_OPTIONAL {
1899 $$ = ACPRES_OPTIONAL;
1900 }
1901 ;
1902
1903TableConstraint:
1904 SimpleTableConstraint {
1905 $$ = $1;
1906 }
1907 | ComponentRelationConstraint {
1908 $$ = $1;
1909 }
1910 ;
1911
1912/*
1913 * "{ExtensionSet}"
1914 */
1915SimpleTableConstraint:
1916 '{' TypeRefName '}' {
1917 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
1918 asn1p_constraint_t *ct;
1919 int ret;
1920 ret = asn1p_ref_add_component(ref, $2, 0);
1921 checkmem(ret == 0);
1922 ct = asn1p_constraint_new(yylineno);
1923 checkmem($$);
1924 ct->type = ACT_EL_VALUE;
1925 ct->value = asn1p_value_fromref(ref, 0);
vlm9fe7c922005-08-12 10:08:45 +00001926 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001927 }
1928 ;
1929
1930ComponentRelationConstraint:
1931 SimpleTableConstraint '{' AtNotationList '}' {
vlm9fe7c922005-08-12 10:08:45 +00001932 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001933 }
1934 ;
1935
1936AtNotationList:
1937 AtNotationElement {
1938 $$ = asn1p_constraint_new(yylineno);
1939 checkmem($$);
1940 $$->type = ACT_EL_VALUE;
1941 $$->value = asn1p_value_fromref($1, 0);
1942 }
1943 | AtNotationList ',' AtNotationElement {
1944 asn1p_constraint_t *ct;
1945 ct = asn1p_constraint_new(yylineno);
1946 checkmem(ct);
1947 ct->type = ACT_EL_VALUE;
1948 ct->value = asn1p_value_fromref($3, 0);
vlm9fe7c922005-08-12 10:08:45 +00001949 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlmfa67ddc2004-06-03 03:38:44 +00001950 }
1951 ;
1952
1953/*
1954 * @blah
1955 */
1956AtNotationElement:
1957 '@' ComponentIdList {
1958 char *p = malloc(strlen($2) + 2);
1959 int ret;
1960 *p = '@';
1961 strcpy(p + 1, $2);
1962 $$ = asn1p_ref_new(yylineno);
1963 ret = asn1p_ref_add_component($$, p, 0);
1964 checkmem(ret == 0);
1965 free(p);
1966 free($2);
1967 }
1968 | '@' '.' ComponentIdList {
1969 char *p = malloc(strlen($3) + 3);
1970 int ret;
1971 p[0] = '@';
1972 p[1] = '.';
1973 strcpy(p + 2, $3);
1974 $$ = asn1p_ref_new(yylineno);
1975 ret = asn1p_ref_add_component($$, p, 0);
1976 checkmem(ret == 0);
1977 free(p);
1978 free($3);
1979 }
1980 ;
1981
1982/* identifier "." ... */
1983ComponentIdList:
1984 Identifier {
1985 $$ = $1;
1986 }
1987 | ComponentIdList '.' Identifier {
1988 int l1 = strlen($1);
1989 int l3 = strlen($3);
1990 $$ = malloc(l1 + 1 + l3 + 1);
1991 memcpy($$, $1, l1);
1992 $$[l1] = '.';
1993 memcpy($$ + l1 + 1, $3, l3);
1994 $$[l1 + 1 + l3] = '\0';
1995 }
1996 ;
1997
1998
1999
2000/*
2001 * MARKERS
2002 */
2003
2004optMarker:
vlmc94e28f2004-09-15 11:59:51 +00002005 {
2006 $$.flags = EM_NOMARK;
2007 $$.default_value = 0;
2008 }
vlmfa67ddc2004-06-03 03:38:44 +00002009 | Marker { $$ = $1; }
2010 ;
2011
2012Marker:
2013 TOK_OPTIONAL {
vlm1ac75e72005-11-26 11:21:55 +00002014 $$.flags = EM_OPTIONAL | EM_INDIRECT;
vlmc94e28f2004-09-15 11:59:51 +00002015 $$.default_value = 0;
vlmfa67ddc2004-06-03 03:38:44 +00002016 }
vlmc94e28f2004-09-15 11:59:51 +00002017 | TOK_DEFAULT Value {
2018 $$.flags = EM_DEFAULT;
2019 $$.default_value = $2;
vlmfa67ddc2004-06-03 03:38:44 +00002020 }
2021 ;
2022
2023/*
2024 * Universal enumeration definition to use in INTEGER and ENUMERATED.
2025 * === EXAMPLE ===
2026 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
2027 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
2028 * === EOF ===
2029 */
2030/*
2031optUniverationDefinition:
2032 { $$ = 0; }
2033 | UniverationDefinition {
2034 $$ = $1;
2035 }
2036 ;
2037*/
2038
2039UniverationDefinition:
2040 '{' '}' {
vlm39e5ed72004-09-05 10:40:41 +00002041 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002042 checkmem($$);
2043 }
2044 | '{' UniverationList '}' {
2045 $$ = $2;
2046 }
2047 ;
2048
2049UniverationList:
2050 UniverationElement {
vlm39e5ed72004-09-05 10:40:41 +00002051 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002052 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +00002053 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +00002054 }
2055 | UniverationList ',' UniverationElement {
2056 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +00002057 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +00002058 }
2059 ;
2060
2061UniverationElement:
2062 Identifier {
vlm39e5ed72004-09-05 10:40:41 +00002063 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002064 checkmem($$);
2065 $$->expr_type = A1TC_UNIVERVAL;
2066 $$->meta_type = AMT_VALUE;
2067 $$->Identifier = $1;
2068 }
2069 | Identifier '(' SignedNumber ')' {
vlm39e5ed72004-09-05 10:40:41 +00002070 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002071 checkmem($$);
2072 $$->expr_type = A1TC_UNIVERVAL;
2073 $$->meta_type = AMT_VALUE;
2074 $$->Identifier = $1;
2075 $$->value = $3;
2076 }
2077 | Identifier '(' DefinedValue ')' {
vlm39e5ed72004-09-05 10:40:41 +00002078 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002079 checkmem($$);
2080 $$->expr_type = A1TC_UNIVERVAL;
2081 $$->meta_type = AMT_VALUE;
2082 $$->Identifier = $1;
2083 $$->value = $3;
2084 }
2085 | SignedNumber {
vlm39e5ed72004-09-05 10:40:41 +00002086 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002087 checkmem($$);
2088 $$->expr_type = A1TC_UNIVERVAL;
2089 $$->meta_type = AMT_VALUE;
2090 $$->value = $1;
2091 }
2092 | TOK_ThreeDots {
vlm39e5ed72004-09-05 10:40:41 +00002093 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002094 checkmem($$);
2095 $$->Identifier = strdup("...");
2096 checkmem($$->Identifier);
2097 $$->expr_type = A1TC_EXTENSIBLE;
2098 $$->meta_type = AMT_VALUE;
2099 }
2100 ;
2101
2102SignedNumber:
2103 TOK_number {
2104 $$ = asn1p_value_fromint($1);
2105 checkmem($$);
2106 }
2107 | TOK_number_negative {
2108 $$ = asn1p_value_fromint($1);
2109 checkmem($$);
2110 }
2111 ;
2112
2113/*
2114 * SEQUENCE definition.
2115 * === EXAMPLE ===
2116 * Struct1 ::= SEQUENCE {
2117 * memb1 Struct2,
2118 * memb2 SEQUENCE OF {
2119 * memb2-1 Struct 3
2120 * }
2121 * }
2122 * === EOF ===
2123 */
2124
2125
2126
2127/*
2128 * SET definition.
2129 * === EXAMPLE ===
2130 * Person ::= SET {
2131 * name [0] PrintableString (SIZE(1..20)),
2132 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2133 * }
2134 * === EOF ===
2135 */
2136
2137optTag:
2138 { memset(&$$, 0, sizeof($$)); }
2139 | Tag { $$ = $1; }
2140 ;
2141
2142Tag:
vlm2728a8d2005-01-23 09:51:44 +00002143 TagTypeValue TagPlicit {
vlmfa67ddc2004-06-03 03:38:44 +00002144 $$ = $1;
vlm2728a8d2005-01-23 09:51:44 +00002145 $$.tag_mode = $2.tag_mode;
vlmfa67ddc2004-06-03 03:38:44 +00002146 }
vlm2728a8d2005-01-23 09:51:44 +00002147 ;
2148
2149TagTypeValue:
2150 '[' TagClass TOK_number ']' {
2151 $$ = $2;
2152 $$.tag_value = $3;
2153 };
2154
2155TagClass:
2156 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2157 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2158 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2159 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2160 ;
2161
2162TagPlicit:
2163 { $$.tag_mode = TM_DEFAULT; }
2164 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2165 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
vlmfa67ddc2004-06-03 03:38:44 +00002166 ;
2167
2168TypeRefName:
2169 TOK_typereference {
2170 checkmem($1);
2171 $$ = $1;
2172 }
vlm9283dbe2004-08-18 04:59:12 +00002173 | TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00002174 checkmem($1);
2175 $$ = $1;
2176 }
2177 ;
2178
vlm9283dbe2004-08-18 04:59:12 +00002179
vlmfa67ddc2004-06-03 03:38:44 +00002180ObjectClassReference:
vlm9283dbe2004-08-18 04:59:12 +00002181 TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00002182 checkmem($1);
2183 $$ = $1;
2184 }
2185 ;
2186
vlm151c0b22004-09-22 16:03:36 +00002187optIdentifier:
2188 { $$ = 0; }
2189 | Identifier {
2190 $$ = $1;
2191 }
vlma5b977d2005-06-06 08:28:58 +00002192 ;
vlm151c0b22004-09-22 16:03:36 +00002193
vlmfa67ddc2004-06-03 03:38:44 +00002194Identifier:
2195 TOK_identifier {
2196 checkmem($1);
2197 $$ = $1;
2198 }
2199 ;
2200
vlmfa67ddc2004-06-03 03:38:44 +00002201%%
2202
2203
2204/*
2205 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2206 */
2207static asn1p_value_t *
2208_convert_bitstring2binary(char *str, int base) {
2209 asn1p_value_t *val;
2210 int slen;
2211 int memlen;
2212 int baselen;
2213 int bits;
2214 uint8_t *binary_vector;
2215 uint8_t *bv_ptr;
2216 uint8_t cur_val;
2217
2218 assert(str);
2219 assert(str[0] == '\'');
2220
2221 switch(base) {
2222 case 'B':
2223 baselen = 1;
2224 break;
2225 case 'H':
2226 baselen = 4;
2227 break;
2228 default:
2229 assert(base == 'B' || base == 'H');
2230 errno = EINVAL;
2231 return NULL;
2232 }
2233
2234 slen = strlen(str);
2235 assert(str[slen - 1] == base);
2236 assert(str[slen - 2] == '\'');
2237
2238 memlen = slen / (8 / baselen); /* Conservative estimate */
2239
2240 bv_ptr = binary_vector = malloc(memlen + 1);
2241 if(bv_ptr == NULL)
2242 /* ENOMEM */
2243 return NULL;
2244
2245 cur_val = 0;
2246 bits = 0;
2247 while(*(++str) != '\'') {
2248 switch(baselen) {
2249 case 1:
2250 switch(*str) {
2251 case '1':
2252 cur_val |= 1 << (7 - (bits % 8));
2253 case '0':
2254 break;
2255 default:
2256 assert(!"_y UNREACH1");
2257 case ' ': case '\r': case '\n':
2258 continue;
2259 }
2260 break;
2261 case 4:
2262 switch(*str) {
2263 case '0': case '1': case '2': case '3': case '4':
2264 case '5': case '6': case '7': case '8': case '9':
2265 cur_val |= (*str - '0') << (4 - (bits % 8));
2266 break;
2267 case 'A': case 'B': case 'C':
2268 case 'D': case 'E': case 'F':
2269 cur_val |= ((*str - 'A') + 10)
2270 << (4 - (bits % 8));
2271 break;
2272 default:
2273 assert(!"_y UNREACH2");
2274 case ' ': case '\r': case '\n':
2275 continue;
2276 }
2277 break;
2278 }
2279
2280 bits += baselen;
2281 if((bits % 8) == 0) {
2282 *bv_ptr++ = cur_val;
2283 cur_val = 0;
2284 }
2285 }
2286
2287 *bv_ptr = cur_val;
2288 assert((bv_ptr - binary_vector) <= memlen);
2289
2290 val = asn1p_value_frombits(binary_vector, bits, 0);
2291 if(val == NULL) {
2292 free(binary_vector);
2293 }
2294
2295 return val;
2296}
2297
vlm5d89c3d2005-08-13 09:07:11 +00002298/*
2299 * For unnamed types (used in old X.208 compliant modules)
2300 * generate some sort of interim names, to not to force human being to fix
2301 * the specification's compliance to modern ASN.1 standards.
2302 */
2303static void
2304_fixup_anonymous_identifier(asn1p_expr_t *expr) {
2305 char *p;
2306 assert(expr->Identifier == 0);
2307
2308 /*
2309 * Try to figure out the type name
2310 * without going too much into details
2311 */
2312 expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type);
2313 if(expr->reference && expr->reference->comp_count > 0)
2314 expr->Identifier = expr->reference->components[0].name;
2315
2316 fprintf(stderr,
2317 "WARNING: Line %d: expected lower-case member identifier, "
2318 "found an unnamed %s.\n"
2319 "WARNING: Obsolete X.208 syntax detected, "
2320 "please give the member a name.\n",
2321 yylineno, expr->Identifier ? expr->Identifier : "type");
2322
2323 if(!expr->Identifier)
2324 expr->Identifier = "unnamed";
2325 expr->Identifier = strdup(expr->Identifier);
2326 assert(expr->Identifier);
2327 /* Make a lowercase identifier from the type name */
2328 for(p = expr->Identifier; *p; p++) {
2329 switch(*p) {
2330 case 'A' ... 'Z': *p += 32; break;
2331 case ' ': *p = '_'; break;
2332 case '-': *p = '_'; break;
2333 }
2334 }
2335 fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". "
2336 "Name clash may occur later.\n",
2337 expr->Identifier);
2338}
2339
vlmfa67ddc2004-06-03 03:38:44 +00002340int
2341yyerror(const char *msg) {
vlm808411d2006-03-14 16:31:37 +00002342 extern char *asn1p_text;
vlmfa67ddc2004-06-03 03:38:44 +00002343 fprintf(stderr,
2344 "ASN.1 grammar parse error "
2345 "near line %d (token \"%s\"): %s\n",
vlm39e5ed72004-09-05 10:40:41 +00002346 yylineno, asn1p_text, msg);
vlmfa67ddc2004-06-03 03:38:44 +00002347 return -1;
2348}
2349