blob: cb24e8ffa7b616604c1e024b510c844a3dd8922d [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
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
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;
777 $$->params = $3;
778 $$->meta_type = AMT_PARAMTYPE;
779 }
780 ;
781
782ParameterArgumentList:
783 ParameterArgumentName {
784 int ret;
785 $$ = asn1p_paramlist_new(yylineno);
786 checkmem($$);
787 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
788 checkmem(ret == 0);
789 if($1.governor) asn1p_ref_free($1.governor);
790 if($1.argument) free($1.argument);
791 }
792 | ParameterArgumentList ',' ParameterArgumentName {
793 int ret;
794 $$ = $1;
795 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
796 checkmem(ret == 0);
797 if($3.governor) asn1p_ref_free($3.governor);
798 if($3.argument) free($3.argument);
799 }
800 ;
801
802ParameterArgumentName:
803 TypeRefName {
804 $$.governor = NULL;
805 $$.argument = $1;
806 }
807 | TypeRefName ':' Identifier {
808 int ret;
809 $$.governor = asn1p_ref_new(yylineno);
810 ret = asn1p_ref_add_component($$.governor, $1, 0);
811 checkmem(ret == 0);
812 $$.argument = $3;
813 }
vlm4053ca52005-02-18 16:34:21 +0000814 | TypeRefName ':' TypeRefName {
815 int ret;
816 $$.governor = asn1p_ref_new(yylineno);
817 ret = asn1p_ref_add_component($$.governor, $1, 0);
818 checkmem(ret == 0);
819 $$.argument = $3;
820 }
vlmfa67ddc2004-06-03 03:38:44 +0000821 | BasicTypeId ':' Identifier {
822 int ret;
823 $$.governor = asn1p_ref_new(yylineno);
824 ret = asn1p_ref_add_component($$.governor,
825 ASN_EXPR_TYPE2STR($1), 1);
826 checkmem(ret == 0);
827 $$.argument = $3;
828 }
829 ;
830
831ActualParameterList:
832 ActualParameter {
833 $$ = asn1p_expr_new(yylineno);
834 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000835 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000836 }
837 | ActualParameterList ',' ActualParameter {
838 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000839 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000840 }
841 ;
842
843ActualParameter:
vlmec8f6812004-08-22 03:19:54 +0000844 Type {
vlmfa67ddc2004-06-03 03:38:44 +0000845 $$ = $1;
846 }
847 | Identifier {
848 $$ = asn1p_expr_new(yylineno);
849 checkmem($$);
850 $$->Identifier = $1;
851 $$->expr_type = A1TC_REFERENCE;
852 $$->meta_type = AMT_VALUE;
853 }
854 ;
855
856/*
vlm4053ca52005-02-18 16:34:21 +0000857 | '{' ActualParameter '}' {
858 $$ = asn1p_expr_new(yylineno);
859 checkmem($$);
860 asn1p_expr_add($$, $2);
861 $$->expr_type = A1TC_PARAMETRIZED;
862 $$->meta_type = AMT_TYPE;
863 }
864 ;
865*/
866
867/*
vlmfa67ddc2004-06-03 03:38:44 +0000868 * A collection of constructed data type members.
869 */
vlm0aa86902004-10-12 23:26:53 +0000870optComponentTypeLists:
871 { $$ = asn1p_expr_new(yylineno); }
872 | ComponentTypeLists { $$ = $1; };
873
vlmec8f6812004-08-22 03:19:54 +0000874ComponentTypeLists:
875 ComponentType {
vlmfa67ddc2004-06-03 03:38:44 +0000876 $$ = asn1p_expr_new(yylineno);
877 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000878 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000879 }
vlmec8f6812004-08-22 03:19:54 +0000880 | ComponentTypeLists ',' ComponentType {
vlmfa67ddc2004-06-03 03:38:44 +0000881 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000882 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000883 }
884 ;
885
vlmec8f6812004-08-22 03:19:54 +0000886ComponentType:
vlmfce48a42004-09-14 02:36:39 +0000887 Identifier Type optMarker {
vlmec8f6812004-08-22 03:19:54 +0000888 $$ = $2;
889 assert($$->Identifier == 0);
vlmfce48a42004-09-14 02:36:39 +0000890 $$->Identifier = $1;
vlm177a5b62005-09-05 05:17:57 +0000891 $3.flags |= $$->marker.flags;
vlmec8f6812004-08-22 03:19:54 +0000892 $$->marker = $3;
893 }
vlm177a5b62005-09-05 05:17:57 +0000894 | Type optMarker {
895 $$ = $1;
896 $2.flags |= $$->marker.flags;
897 $$->marker = $2;
898 _fixup_anonymous_identifier($$);
899 }
vlmec8f6812004-08-22 03:19:54 +0000900 | TOK_COMPONENTS TOK_OF Type {
901 $$ = asn1p_expr_new(yylineno);
902 checkmem($$);
903 $$->meta_type = $3->meta_type;
904 $$->expr_type = A1TC_COMPONENTS_OF;
vlm6a02a8a2004-09-08 00:28:11 +0000905 asn1p_expr_add($$, $3);
vlmec8f6812004-08-22 03:19:54 +0000906 }
907 | ExtensionAndException {
908 $$ = $1;
909 }
910 ;
911
912AlternativeTypeLists:
913 AlternativeType {
914 $$ = asn1p_expr_new(yylineno);
915 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000916 asn1p_expr_add($$, $1);
vlmec8f6812004-08-22 03:19:54 +0000917 }
918 | AlternativeTypeLists ',' AlternativeType {
919 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000920 asn1p_expr_add($$, $3);
vlmec8f6812004-08-22 03:19:54 +0000921 }
922 ;
923
924AlternativeType:
vlmfce48a42004-09-14 02:36:39 +0000925 Identifier Type {
vlmec8f6812004-08-22 03:19:54 +0000926 $$ = $2;
927 assert($$->Identifier == 0);
vlmfce48a42004-09-14 02:36:39 +0000928 $$->Identifier = $1;
vlmec8f6812004-08-22 03:19:54 +0000929 }
930 | ExtensionAndException {
931 $$ = $1;
932 }
vlm5d89c3d2005-08-13 09:07:11 +0000933 | Type {
934 $$ = $1;
935 _fixup_anonymous_identifier($$);
936 }
vlmec8f6812004-08-22 03:19:54 +0000937 ;
938
vlmdc7cf042006-03-09 08:49:26 +0000939ObjectClass:
940 TOK_CLASS '{' FieldSpec '}' optWithSyntax {
vlmfa67ddc2004-06-03 03:38:44 +0000941 $$ = $3;
942 checkmem($$);
943 $$->with_syntax = $5;
944 assert($$->expr_type == A1TC_CLASSDEF);
vlmdc7cf042006-03-09 08:49:26 +0000945 assert($$->meta_type == AMT_OBJECTCLASS);
vlmfa67ddc2004-06-03 03:38:44 +0000946 }
947 ;
948
949optUnique:
950 { $$ = 0; }
951 | TOK_UNIQUE { $$ = 1; }
952 ;
953
vlmdc7cf042006-03-09 08:49:26 +0000954FieldSpec:
vlmfa67ddc2004-06-03 03:38:44 +0000955 ClassField {
956 $$ = asn1p_expr_new(yylineno);
957 checkmem($$);
958 $$->expr_type = A1TC_CLASSDEF;
vlmdc7cf042006-03-09 08:49:26 +0000959 $$->meta_type = AMT_OBJECTCLASS;
vlm6a02a8a2004-09-08 00:28:11 +0000960 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000961 }
vlmdc7cf042006-03-09 08:49:26 +0000962 | FieldSpec ',' ClassField {
vlmfa67ddc2004-06-03 03:38:44 +0000963 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000964 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000965 }
966 ;
967
vlmdc7cf042006-03-09 08:49:26 +0000968 /* X.681 */
vlmfa67ddc2004-06-03 03:38:44 +0000969ClassField:
vlmdc7cf042006-03-09 08:49:26 +0000970
971 /* TypeFieldSpec ::= typefieldreference TypeOptionalitySpec? */
972 TOK_typefieldreference optMarker {
vlmfa67ddc2004-06-03 03:38:44 +0000973 $$ = asn1p_expr_new(yylineno);
974 checkmem($$);
vlmdc7cf042006-03-09 08:49:26 +0000975 $$->Identifier = $1;
vlmfa67ddc2004-06-03 03:38:44 +0000976 $$->meta_type = AMT_OBJECTFIELD;
vlmdc7cf042006-03-09 08:49:26 +0000977 $$->expr_type = A1TC_CLASSFIELD_TFS; /* TypeFieldSpec */
vlmfa67ddc2004-06-03 03:38:44 +0000978 $$->marker = $2;
979 }
vlmdc7cf042006-03-09 08:49:26 +0000980
981 /* FixedTypeValueFieldSpec ::= valuefieldreference Type UNIQUE ? ValueOptionalitySpec ? */
982 | TOK_valuefieldreference Type optUnique optMarker {
983 $$ = asn1p_expr_new(yylineno);
984 $$->Identifier = $1;
985 $$->meta_type = AMT_OBJECTFIELD;
986 $$->expr_type = A1TC_CLASSFIELD_FTVFS; /* FixedTypeValueFieldSpec */
vlmbde35d42004-11-24 17:43:29 +0000987 $$->unique = $3;
vlmdc7cf042006-03-09 08:49:26 +0000988 $$->marker = $4;
989 asn1p_expr_add($$, $2);
vlmfa67ddc2004-06-03 03:38:44 +0000990 }
vlmdc7cf042006-03-09 08:49:26 +0000991
992 /* VariableTypeValueFieldSpec ::= valuefieldreference FieldName ValueOptionalitySpec ? */
993 | TOK_valuefieldreference FieldName optMarker {
994 $$ = asn1p_expr_new(yylineno);
995 $$->Identifier = $1;
996 $$->meta_type = AMT_OBJECTFIELD;
997 $$->expr_type = A1TC_CLASSFIELD_VTVFS;
998 $$->reference = $2;
999 $$->marker = $3;
1000 }
1001
vlmdc7cf042006-03-09 08:49:26 +00001002 /* ObjectFieldSpec ::= objectfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1003 | TOK_valuefieldreference DefinedObjectClass optMarker {
vlmfa67ddc2004-06-03 03:38:44 +00001004 $$ = asn1p_expr_new(yylineno);
1005 checkmem($$);
vlmdc7cf042006-03-09 08:49:26 +00001006 $$->Identifier = $1;
1007 $$->reference = $2;
vlmfa67ddc2004-06-03 03:38:44 +00001008 $$->meta_type = AMT_OBJECTFIELD;
vlmdc7cf042006-03-09 08:49:26 +00001009 $$->expr_type = A1TC_CLASSFIELD_OFS;
1010 $$->marker = $3;
vlmfa67ddc2004-06-03 03:38:44 +00001011 }
vlmdc7cf042006-03-09 08:49:26 +00001012
vlmee7196e2006-03-09 09:08:49 +00001013 /* VariableTypeValueSetFieldSpec ::= valuesetfieldreference FieldName ValueOptionalitySpec ? */
1014 | TOK_typefieldreference FieldName optMarker {
vlmdc7cf042006-03-09 08:49:26 +00001015 $$ = asn1p_expr_new(yylineno);
vlmdc7cf042006-03-09 08:49:26 +00001016 $$->Identifier = $1;
vlmdc7cf042006-03-09 08:49:26 +00001017 $$->meta_type = AMT_OBJECTFIELD;
vlmee7196e2006-03-09 09:08:49 +00001018 $$->expr_type = A1TC_CLASSFIELD_VTVSFS;
1019 $$->reference = $2;
vlmdc7cf042006-03-09 08:49:26 +00001020 $$->marker = $3;
1021 }
1022
1023 /* FixedTypeValueSetFieldSpec ::= valuesetfieldreference Type ValueSetOptionalitySpec ? */
1024 | TOK_typefieldreference Type optMarker {
1025 $$ = asn1p_expr_new(yylineno);
1026 checkmem($$);
1027 $$->Identifier = $1;
1028 $$->meta_type = AMT_OBJECTFIELD;
1029 $$->expr_type = A1TC_CLASSFIELD_FTVSFS;
1030 asn1p_expr_add($$, $2);
1031 $$->marker = $3;
1032 }
1033
vlmee7196e2006-03-09 09:08:49 +00001034 /* ObjectSetFieldSpec ::= objectsetfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1035 | TOK_typefieldreference DefinedObjectClass optMarker {
1036 $$ = asn1p_expr_new(yylineno);
1037 checkmem($$);
1038 $$->Identifier = $1;
1039 $$->reference = $2;
1040 $$->meta_type = AMT_OBJECTFIELD;
1041 $$->expr_type = A1TC_CLASSFIELD_OSFS;
1042 $$->marker = $3;
1043 }
vlmfa67ddc2004-06-03 03:38:44 +00001044 ;
1045
1046optWithSyntax:
1047 { $$ = 0; }
1048 | WithSyntax {
1049 $$ = $1;
1050 }
1051 ;
1052
1053WithSyntax:
1054 TOK_WITH TOK_SYNTAX '{'
1055 { asn1p_lexer_hack_enable_with_syntax(); }
vlm808411d2006-03-14 16:31:37 +00001056 WithSyntaxList
vlmfa67ddc2004-06-03 03:38:44 +00001057 '}' {
1058 $$ = $5;
1059 }
1060 ;
1061
vlm808411d2006-03-14 16:31:37 +00001062WithSyntaxList:
1063 WithSyntaxToken {
vlmfa67ddc2004-06-03 03:38:44 +00001064 $$ = asn1p_wsyntx_new();
1065 TQ_ADD(&($$->chunks), $1, next);
1066 }
vlm808411d2006-03-14 16:31:37 +00001067 | WithSyntaxList WithSyntaxToken {
vlmfa67ddc2004-06-03 03:38:44 +00001068 $$ = $1;
1069 TQ_ADD(&($$->chunks), $2, next);
1070 }
1071 ;
1072
vlm808411d2006-03-14 16:31:37 +00001073WithSyntaxToken:
vlmeeb3c512006-03-16 05:11:14 +00001074 TOK_whitespace {
vlmfa67ddc2004-06-03 03:38:44 +00001075 $$ = asn1p_wsyntx_chunk_frombuf($1.buf, $1.len, 0);
vlmeeb3c512006-03-16 05:11:14 +00001076 $$->type = WC_WHITESPACE;
vlmfa67ddc2004-06-03 03:38:44 +00001077 }
vlm808411d2006-03-14 16:31:37 +00001078 | TOK_Literal {
1079 $$ = asn1p_wsyntx_chunk_frombuf($1, strlen($1), 0);
1080 }
vlma6a84d72006-03-16 10:03:35 +00001081 | PrimitiveFieldReference {
1082 $$ = asn1p_wsyntx_chunk_frombuf($1.name, strlen($1.name), 0);
1083 $$->type = WC_FIELD;
vlmfa67ddc2004-06-03 03:38:44 +00001084 }
vlm808411d2006-03-14 16:31:37 +00001085 | '[' WithSyntaxList ']' {
1086 $$ = asn1p_wsyntx_chunk_fromsyntax($2);
1087 }
vlmfa67ddc2004-06-03 03:38:44 +00001088 ;
1089
vlmfa67ddc2004-06-03 03:38:44 +00001090ExtensionAndException:
1091 TOK_ThreeDots {
vlm39e5ed72004-09-05 10:40:41 +00001092 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001093 checkmem($$);
1094 $$->Identifier = strdup("...");
1095 checkmem($$->Identifier);
1096 $$->expr_type = A1TC_EXTENSIBLE;
1097 $$->meta_type = AMT_TYPE;
1098 }
1099 | TOK_ThreeDots '!' DefinedValue {
vlm39e5ed72004-09-05 10:40:41 +00001100 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001101 checkmem($$);
1102 $$->Identifier = strdup("...");
1103 checkmem($$->Identifier);
1104 $$->value = $3;
1105 $$->expr_type = A1TC_EXTENSIBLE;
1106 $$->meta_type = AMT_TYPE;
1107 }
1108 | TOK_ThreeDots '!' SignedNumber {
vlm39e5ed72004-09-05 10:40:41 +00001109 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001110 checkmem($$);
1111 $$->Identifier = strdup("...");
1112 $$->value = $3;
1113 checkmem($$->Identifier);
1114 $$->expr_type = A1TC_EXTENSIBLE;
1115 $$->meta_type = AMT_TYPE;
1116 }
1117 ;
1118
vlmec8f6812004-08-22 03:19:54 +00001119Type:
vlmfce48a42004-09-14 02:36:39 +00001120 optTag TypeDeclaration optConstraints {
1121 $$ = $2;
1122 $$->tag = $1;
vlmec8f6812004-08-22 03:19:54 +00001123 /*
1124 * Outer constraint for SEQUENCE OF and SET OF applies
1125 * to the inner type.
1126 */
1127 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1128 || $$->expr_type == ASN_CONSTR_SET_OF) {
1129 assert(!TQ_FIRST(&($$->members))->constraints);
vlmfce48a42004-09-14 02:36:39 +00001130 TQ_FIRST(&($$->members))->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001131 } else {
1132 if($$->constraints) {
1133 assert(!$2);
1134 } else {
vlmfce48a42004-09-14 02:36:39 +00001135 $$->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001136 }
1137 }
vlm177a5b62005-09-05 05:17:57 +00001138 }
1139 ;
1140
1141NSTD_IndirectMarker:
1142 {
1143 $$ = asn1p_as_pointer ? EM_INDIRECT : 0;
1144 asn1p_as_pointer = 0;
vlmec8f6812004-08-22 03:19:54 +00001145 }
1146 ;
1147
1148TypeDeclaration:
vlm177a5b62005-09-05 05:17:57 +00001149 NSTD_IndirectMarker TypeDeclarationSet {
vlm066dc102005-08-22 12:23:54 +00001150 $$ = $2;
vlm177a5b62005-09-05 05:17:57 +00001151 $$->marker.flags |= $1;
1152
1153 if(($$->marker.flags & EM_INDIRECT)
1154 && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
1155 fprintf(stderr,
1156 "INFO: Directive <ASN1C:RepresentAsPointer> "
1157 "applied to %s at line %d\n",
1158 ASN_EXPR_TYPE2STR($$->expr_type)
1159 ? ASN_EXPR_TYPE2STR($$->expr_type)
1160 : "member",
1161 $$->_lineno
1162 );
1163 }
vlm066dc102005-08-22 12:23:54 +00001164 }
vlm177a5b62005-09-05 05:17:57 +00001165 ;
vlm066dc102005-08-22 12:23:54 +00001166
1167TypeDeclarationSet:
vlmfa67ddc2004-06-03 03:38:44 +00001168 BasicType {
1169 $$ = $1;
1170 }
vlm177a5b62005-09-05 05:17:57 +00001171 | TOK_CHOICE '{' AlternativeTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001172 $$ = $3;
1173 assert($$->expr_type == A1TC_INVALID);
1174 $$->expr_type = ASN_CONSTR_CHOICE;
1175 $$->meta_type = AMT_TYPE;
vlmfa67ddc2004-06-03 03:38:44 +00001176 }
vlm177a5b62005-09-05 05:17:57 +00001177 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001178 $$ = $3;
1179 assert($$->expr_type == A1TC_INVALID);
1180 $$->expr_type = ASN_CONSTR_SEQUENCE;
1181 $$->meta_type = AMT_TYPE;
1182 }
vlm177a5b62005-09-05 05:17:57 +00001183 | TOK_SET '{' optComponentTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001184 $$ = $3;
1185 assert($$->expr_type == A1TC_INVALID);
1186 $$->expr_type = ASN_CONSTR_SET;
1187 $$->meta_type = AMT_TYPE;
1188 }
vlm151c0b22004-09-22 16:03:36 +00001189 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
vlm39e5ed72004-09-05 10:40:41 +00001190 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001191 checkmem($$);
1192 $$->constraints = $2;
1193 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1194 $$->meta_type = AMT_TYPE;
vlm151c0b22004-09-22 16:03:36 +00001195 $6->Identifier = $4;
1196 $6->tag = $5;
1197 asn1p_expr_add($$, $6);
vlmec8f6812004-08-22 03:19:54 +00001198 }
vlm151c0b22004-09-22 16:03:36 +00001199 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
vlm39e5ed72004-09-05 10:40:41 +00001200 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001201 checkmem($$);
1202 $$->constraints = $2;
1203 $$->expr_type = ASN_CONSTR_SET_OF;
1204 $$->meta_type = AMT_TYPE;
vlm151c0b22004-09-22 16:03:36 +00001205 $6->Identifier = $4;
1206 $6->tag = $5;
1207 asn1p_expr_add($$, $6);
vlmec8f6812004-08-22 03:19:54 +00001208 }
1209 | TOK_ANY {
vlm39e5ed72004-09-05 10:40:41 +00001210 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001211 checkmem($$);
vlm044f7442004-09-04 04:49:21 +00001212 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001213 $$->meta_type = AMT_TYPE;
1214 }
1215 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1216 int ret;
vlm39e5ed72004-09-05 10:40:41 +00001217 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001218 checkmem($$);
1219 $$->reference = asn1p_ref_new(yylineno);
1220 ret = asn1p_ref_add_component($$->reference,
1221 $4, RLT_lowercase);
1222 checkmem(ret == 0);
vlm044f7442004-09-04 04:49:21 +00001223 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001224 $$->meta_type = AMT_TYPE;
1225 }
vlmfa67ddc2004-06-03 03:38:44 +00001226 /*
1227 * A parametrized assignment.
1228 */
1229 | TypeRefName '{' ActualParameterList '}' {
1230 int ret;
1231 $$ = $3;
1232 assert($$->expr_type == 0);
1233 assert($$->meta_type == 0);
1234 assert($$->reference == 0);
1235 $$->reference = asn1p_ref_new(yylineno);
1236 checkmem($$->reference);
1237 ret = asn1p_ref_add_component($$->reference, $1, RLT_UNKNOWN);
1238 checkmem(ret == 0);
1239 free($1);
1240 $$->expr_type = A1TC_PARAMETRIZED;
1241 $$->meta_type = AMT_TYPE;
1242 }
1243 /*
1244 * A DefinedType reference.
1245 * "CLASS1.&id.&id2"
1246 * or
1247 * "Module.Type"
1248 * or
1249 * "Module.identifier"
1250 * or
1251 * "Type"
1252 */
1253 | ComplexTypeReference {
1254 $$ = asn1p_expr_new(yylineno);
1255 checkmem($$);
1256 $$->reference = $1;
1257 $$->expr_type = A1TC_REFERENCE;
1258 $$->meta_type = AMT_TYPEREF;
1259 }
1260 | TOK_INSTANCE TOK_OF ComplexTypeReference {
1261 $$ = asn1p_expr_new(yylineno);
1262 checkmem($$);
1263 $$->reference = $3;
1264 $$->expr_type = A1TC_INSTANCE;
1265 $$->meta_type = AMT_TYPE;
1266 }
1267 ;
1268
1269/*
1270 * A type name consisting of several components.
1271 * === EXAMPLE ===
1272 * === EOF ===
1273 */
1274ComplexTypeReference:
1275 TOK_typereference {
1276 int ret;
1277 $$ = asn1p_ref_new(yylineno);
1278 checkmem($$);
1279 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1280 checkmem(ret == 0);
1281 free($1);
1282 }
1283 | TOK_typereference '.' TypeRefName {
1284 int ret;
1285 $$ = asn1p_ref_new(yylineno);
1286 checkmem($$);
1287 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1288 checkmem(ret == 0);
1289 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1290 checkmem(ret == 0);
1291 free($1);
1292 }
vlmc94e28f2004-09-15 11:59:51 +00001293 | ObjectClassReference '.' TypeRefName {
1294 int ret;
1295 $$ = asn1p_ref_new(yylineno);
1296 checkmem($$);
1297 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1298 checkmem(ret == 0);
1299 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1300 checkmem(ret == 0);
1301 free($1);
1302 }
vlmfa67ddc2004-06-03 03:38:44 +00001303 | TOK_typereference '.' Identifier {
1304 int ret;
1305 $$ = asn1p_ref_new(yylineno);
1306 checkmem($$);
1307 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1308 checkmem(ret == 0);
1309 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1310 checkmem(ret == 0);
1311 free($1);
1312 }
1313 | ObjectClassReference {
1314 int ret;
1315 $$ = asn1p_ref_new(yylineno);
1316 checkmem($$);
1317 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1318 free($1);
1319 checkmem(ret == 0);
1320 }
1321 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1322 int ret;
1323 $$ = $3;
1324 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1325 free($1);
1326 checkmem(ret == 0);
1327 /*
1328 * Move the last element infront.
1329 */
1330 {
1331 struct asn1p_ref_component_s tmp_comp;
1332 tmp_comp = $$->components[$$->comp_count-1];
1333 memmove(&$$->components[1],
1334 &$$->components[0],
1335 sizeof($$->components[0])
1336 * ($$->comp_count - 1));
1337 $$->components[0] = tmp_comp;
1338 }
1339 }
1340 ;
1341
1342ComplexTypeReferenceAmpList:
1343 ComplexTypeReferenceElement {
1344 int ret;
1345 $$ = asn1p_ref_new(yylineno);
1346 checkmem($$);
1347 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1348 free($1.name);
1349 checkmem(ret == 0);
1350 }
1351 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1352 int ret;
1353 $$ = $1;
1354 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1355 free($3.name);
1356 checkmem(ret == 0);
1357 }
1358 ;
1359
vlma6a84d72006-03-16 10:03:35 +00001360ComplexTypeReferenceElement: PrimitiveFieldReference;
vlmfa67ddc2004-06-03 03:38:44 +00001361
vlma6a84d72006-03-16 10:03:35 +00001362PrimitiveFieldReference:
vlmfa67ddc2004-06-03 03:38:44 +00001363 /* "&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 +00002343int
2344yyerror(const char *msg) {
vlm808411d2006-03-14 16:31:37 +00002345 extern char *asn1p_text;
vlmfa67ddc2004-06-03 03:38:44 +00002346 fprintf(stderr,
2347 "ASN.1 grammar parse error "
2348 "near line %d (token \"%s\"): %s\n",
vlm39e5ed72004-09-05 10:40:41 +00002349 yylineno, asn1p_text, msg);
vlmfa67ddc2004-06-03 03:38:44 +00002350 return -1;
2351}
2352