blob: 323ebe7992e6d287fda6c92503ab232d0b26263b [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
245%type <a_refcomp> ClassFieldIdentifier
246%type <a_refcomp> ClassFieldName
vlmdc7cf042006-03-09 08:49:26 +0000247%type <a_expr> FieldSpec
248%type <a_ref> FieldName
249%type <a_ref> DefinedObjectClass
vlmfa67ddc2004-06-03 03:38:44 +0000250%type <a_expr> ClassField
vlmdc7cf042006-03-09 08:49:26 +0000251%type <a_expr> ObjectClass
vlmec8f6812004-08-22 03:19:54 +0000252%type <a_expr> Type
vlmfa67ddc2004-06-03 03:38:44 +0000253%type <a_expr> DataTypeReference /* Type1 ::= Type2 */
254%type <a_expr> DefinedTypeRef
255%type <a_expr> ValueSetDefinition /* Val INTEGER ::= {1|2} */
256%type <a_expr> ValueDefinition /* val INTEGER ::= 1*/
vlmc94e28f2004-09-15 11:59:51 +0000257%type <a_value> Value
vlmfa67ddc2004-06-03 03:38:44 +0000258%type <a_value> DefinedValue
259%type <a_value> SignedNumber
vlm0aa86902004-10-12 23:26:53 +0000260%type <a_expr> optComponentTypeLists
vlmec8f6812004-08-22 03:19:54 +0000261%type <a_expr> ComponentTypeLists
262%type <a_expr> ComponentType
263%type <a_expr> AlternativeTypeLists
264%type <a_expr> AlternativeType
vlmfa67ddc2004-06-03 03:38:44 +0000265//%type <a_expr> optUniverationDefinition
266%type <a_expr> UniverationDefinition
267%type <a_expr> UniverationList
268%type <a_expr> UniverationElement
269%type <tv_str> TypeRefName
270%type <tv_str> ObjectClassReference
vlmfa67ddc2004-06-03 03:38:44 +0000271%type <tv_str> Identifier
vlm151c0b22004-09-22 16:03:36 +0000272%type <tv_str> optIdentifier
vlmfa67ddc2004-06-03 03:38:44 +0000273%type <a_parg> ParameterArgumentName
274%type <a_plist> ParameterArgumentList
275%type <a_expr> ActualParameter
276%type <a_expr> ActualParameterList
vlm04a08da2005-08-12 10:06:17 +0000277%type <a_aid> AssignedIdentifier /* OID/DefinedValue */
vlmfa67ddc2004-06-03 03:38:44 +0000278%type <a_oid> ObjectIdentifier /* OID */
279%type <a_oid> optObjectIdentifier /* Optional OID */
280%type <a_oid> ObjectIdentifierBody
281%type <a_oid_arc> ObjectIdentifierElement
282%type <a_expr> BasicType
283%type <a_type> BasicTypeId
284%type <a_type> BasicTypeId_UniverationCompatible
285%type <a_type> BasicString
286%type <tv_opaque> Opaque
287//%type <tv_opaque> StringValue
vlm2728a8d2005-01-23 09:51:44 +0000288%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
289%type <a_tag> TagClass TagTypeValue TagPlicit
vlmfa67ddc2004-06-03 03:38:44 +0000290%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
291%type <a_constr> optConstraints
vlm5f0128b2004-08-20 13:25:29 +0000292%type <a_constr> Constraints
vlm9283dbe2004-08-18 04:59:12 +0000293%type <a_constr> SetOfConstraints
294%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
295%type <a_constr> ElementSetSpec /* 1..2,...,3 */
vlmfa67ddc2004-06-03 03:38:44 +0000296%type <a_constr> ConstraintSubtypeElement /* 1..2 */
vlmfa67ddc2004-06-03 03:38:44 +0000297%type <a_constr> SimpleTableConstraint
298%type <a_constr> TableConstraint
vlm7bbdc9f2005-03-28 15:01:27 +0000299%type <a_constr> InnerTypeConstraint
vlmfa67ddc2004-06-03 03:38:44 +0000300%type <a_constr> WithComponentsList
301%type <a_constr> WithComponentsElement
302%type <a_constr> ComponentRelationConstraint
303%type <a_constr> AtNotationList
304%type <a_ref> AtNotationElement
vlma6a12e32005-03-20 12:58:00 +0000305%type <a_value> SingleValue
306%type <a_value> ContainedSubtype
vlmfa67ddc2004-06-03 03:38:44 +0000307%type <a_ctype> ConstraintSpec
308%type <a_ctype> ConstraintRangeSpec
vlme1e6ed82005-03-24 14:26:38 +0000309%type <a_value> RestrictedCharacterStringValue
vlmfa67ddc2004-06-03 03:38:44 +0000310%type <a_wsynt> optWithSyntax
311%type <a_wsynt> WithSyntax
vlm808411d2006-03-14 16:31:37 +0000312%type <a_wsynt> WithSyntaxList
313%type <a_wchunk> WithSyntaxToken
vlmfa67ddc2004-06-03 03:38:44 +0000314%type <a_marker> optMarker Marker
315%type <a_int> optUnique
316%type <a_pres> optPresenceConstraint PresenceConstraint
317%type <tv_str> ComponentIdList
vlm177a5b62005-09-05 05:17:57 +0000318%type <a_int> NSTD_IndirectMarker
vlmfa67ddc2004-06-03 03:38:44 +0000319
320
321%%
322
323
324ParsedGrammar:
325 ModuleList {
326 *(void **)param = $1;
327 }
328 ;
329
330ModuleList:
331 ModuleSpecification {
332 $$ = asn1p_new();
333 checkmem($$);
334 TQ_ADD(&($$->modules), $1, mod_next);
335 }
336 | ModuleList ModuleSpecification {
337 $$ = $1;
338 TQ_ADD(&($$->modules), $2, mod_next);
339 }
340 ;
341
342/*
343 * ASN module definition.
344 * === EXAMPLE ===
345 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
346 * BEGIN
347 * ...
348 * END
349 * === EOF ===
350 */
351
352ModuleSpecification:
353 TypeRefName optObjectIdentifier TOK_DEFINITIONS
354 optModuleSpecificationFlags
355 TOK_PPEQ TOK_BEGIN
356 optModuleSpecificationBody
357 TOK_END {
358
359 if($7) {
360 $$ = $7;
361 } else {
362 /* There's a chance that a module is just plain empty */
363 $$ = asn1p_module_new();
364 }
365 checkmem($$);
366
vlm04a08da2005-08-12 10:06:17 +0000367 $$->ModuleName = $1;
vlmfa67ddc2004-06-03 03:38:44 +0000368 $$->module_oid = $2;
369 $$->module_flags = $4;
370 }
371 ;
372
373/*
374 * Object Identifier Definition
375 * { iso member-body(2) 3 }
376 */
377optObjectIdentifier:
378 { $$ = 0; }
379 | ObjectIdentifier { $$ = $1; }
380 ;
381
382ObjectIdentifier:
383 '{' ObjectIdentifierBody '}' {
384 $$ = $2;
385 }
386 | '{' '}' {
387 $$ = 0;
388 }
389 ;
390
391ObjectIdentifierBody:
392 ObjectIdentifierElement {
393 $$ = asn1p_oid_new();
394 asn1p_oid_add_arc($$, &$1);
395 if($1.name)
396 free($1.name);
397 }
398 | ObjectIdentifierBody ObjectIdentifierElement {
399 $$ = $1;
400 asn1p_oid_add_arc($$, &$2);
401 if($2.name)
402 free($2.name);
403 }
404 ;
405
406ObjectIdentifierElement:
407 Identifier { /* iso */
408 $$.name = $1;
409 $$.number = -1;
410 }
411 | Identifier '(' TOK_number ')' { /* iso(1) */
412 $$.name = $1;
413 $$.number = $3;
414 }
415 | TOK_number { /* 1 */
416 $$.name = 0;
417 $$.number = $1;
418 }
419 ;
420
421/*
422 * Optional module flags.
423 */
424optModuleSpecificationFlags:
425 { $$ = MSF_NOFLAGS; }
426 | ModuleSpecificationFlags {
427 $$ = $1;
428 }
429 ;
430
431/*
432 * Module flags.
433 */
434ModuleSpecificationFlags:
435 ModuleSpecificationFlag {
436 $$ = $1;
437 }
438 | ModuleSpecificationFlags ModuleSpecificationFlag {
439 $$ = $1 | $2;
440 }
441 ;
442
443/*
444 * Single module flag.
445 */
446ModuleSpecificationFlag:
447 TOK_EXPLICIT TOK_TAGS {
448 $$ = MSF_EXPLICIT_TAGS;
449 }
450 | TOK_IMPLICIT TOK_TAGS {
451 $$ = MSF_IMPLICIT_TAGS;
452 }
453 | TOK_AUTOMATIC TOK_TAGS {
454 $$ = MSF_AUTOMATIC_TAGS;
455 }
456 | TOK_EXTENSIBILITY TOK_IMPLIED {
457 $$ = MSF_EXTENSIBILITY_IMPLIED;
458 }
vlm9283dbe2004-08-18 04:59:12 +0000459 /* EncodingReferenceDefault */
460 | TOK_capitalreference TOK_INSTRUCTIONS {
461 /* X.680Amd1 specifies TAG and XER */
462 if(strcmp($1, "TAG") == 0) {
463 $$ = MSF_TAG_INSTRUCTIONS;
464 } else if(strcmp($1, "XER") == 0) {
465 $$ = MSF_XER_INSTRUCTIONS;
466 } else {
467 fprintf(stderr,
468 "WARNING: %s INSTRUCTIONS at line %d: "
469 "Unrecognized encoding reference\n",
470 $1, yylineno);
471 $$ = MSF_unk_INSTRUCTIONS;
472 }
473 free($1);
474 }
vlmfa67ddc2004-06-03 03:38:44 +0000475 ;
476
477/*
478 * Optional module body.
479 */
480optModuleSpecificationBody:
481 { $$ = 0; }
482 | ModuleSpecificationBody {
vlmfa67ddc2004-06-03 03:38:44 +0000483 $$ = $1;
484 }
485 ;
486
487/*
488 * ASN.1 Module body.
489 */
490ModuleSpecificationBody:
491 ModuleSpecificationElement {
492 $$ = $1;
493 }
494 | ModuleSpecificationBody ModuleSpecificationElement {
495 $$ = $1;
496
vlm9283dbe2004-08-18 04:59:12 +0000497 /* Behave well when one of them is skipped. */
498 if(!($1)) {
499 if($2) $$ = $2;
500 break;
501 }
502
vlmfa67ddc2004-06-03 03:38:44 +0000503#ifdef MY_IMPORT
504#error MY_IMPORT DEFINED ELSEWHERE!
505#endif
506#define MY_IMPORT(foo,field) do { \
vlm97ed7152004-08-13 12:31:09 +0000507 while(TQ_FIRST(&($2->foo))) { \
vlmfa67ddc2004-06-03 03:38:44 +0000508 TQ_ADD(&($$->foo), \
509 TQ_REMOVE(&($2->foo), field), \
510 field); \
vlm97ed7152004-08-13 12:31:09 +0000511 } \
512 assert(TQ_FIRST(&($2->foo)) == 0); \
513 } while(0)
vlmfa67ddc2004-06-03 03:38:44 +0000514
515 MY_IMPORT(imports, xp_next);
516 MY_IMPORT(exports, xp_next);
517 MY_IMPORT(members, next);
518#undef MY_IMPORT
519
520 }
521 ;
522
523/*
524 * One of the elements of ASN.1 module specification.
525 */
526ModuleSpecificationElement:
527 ImportsDefinition {
528 $$ = $1;
529 }
530 | ExportsDefinition {
531 $$ = asn1p_module_new();
532 checkmem($$);
533 if($1) {
534 TQ_ADD(&($$->exports), $1, xp_next);
535 } else {
536 /* "EXPORTS ALL;" ? */
537 }
538 }
539 | DataTypeReference {
540 $$ = asn1p_module_new();
541 checkmem($$);
542 assert($1->expr_type != A1TC_INVALID);
543 assert($1->meta_type != AMT_INVALID);
544 TQ_ADD(&($$->members), $1, next);
545 }
546 | ValueDefinition {
547 $$ = asn1p_module_new();
548 checkmem($$);
549 assert($1->expr_type != A1TC_INVALID);
550 assert($1->meta_type != AMT_INVALID);
551 TQ_ADD(&($$->members), $1, next);
552 }
553 /*
554 * Value set definition
555 * === EXAMPLE ===
556 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
557 * === EOF ===
558 */
559 | ValueSetDefinition {
560 $$ = asn1p_module_new();
561 checkmem($$);
562 assert($1->expr_type != A1TC_INVALID);
563 assert($1->meta_type != AMT_INVALID);
564 TQ_ADD(&($$->members), $1, next);
565 }
vlm9283dbe2004-08-18 04:59:12 +0000566 | TOK_ENCODING_CONTROL TOK_capitalreference
567 { asn1p_lexer_hack_push_encoding_control(); }
568 {
569 fprintf(stderr,
570 "WARNING: ENCODING-CONTROL %s "
571 "specification at line %d ignored\n",
572 $2, yylineno);
573 free($2);
574 $$ = 0;
575 }
vlmfa67ddc2004-06-03 03:38:44 +0000576
577 /*
578 * Erroneous attemps
579 */
580 | BasicString {
581 return yyerror(
vlm1ac75e72005-11-26 11:21:55 +0000582 "Attempt to redefine a standard basic string type, "
583 "please comment out or remove this type redefinition.");
vlmfa67ddc2004-06-03 03:38:44 +0000584 }
585 ;
586
587/*
588 * === EXAMPLE ===
589 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
590 * === EOF ===
591 */
592ImportsDefinition:
593 TOK_IMPORTS ImportsBundleSet ';' {
vlm04a08da2005-08-12 10:06:17 +0000594 if(!saved_aid && 0)
595 return yyerror("Unterminated IMPORTS FROM, "
596 "expected semicolon ';'");
597 saved_aid = 0;
vlmfa67ddc2004-06-03 03:38:44 +0000598 $$ = $2;
599 }
600 /*
601 * Some error cases.
602 */
603 | TOK_IMPORTS TOK_FROM /* ... */ {
604 return yyerror("Empty IMPORTS list");
605 }
606 ;
607
608ImportsBundleSet:
609 ImportsBundle {
610 $$ = asn1p_module_new();
611 checkmem($$);
612 TQ_ADD(&($$->imports), $1, xp_next);
613 }
614 | ImportsBundleSet ImportsBundle {
615 $$ = $1;
616 TQ_ADD(&($$->imports), $2, xp_next);
617 }
618 ;
619
vlm04a08da2005-08-12 10:06:17 +0000620AssignedIdentifier:
621 { memset(&$$, 0, sizeof($$)); }
622 | ObjectIdentifier { $$.oid = $1; };
623 /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
624
vlmfa67ddc2004-06-03 03:38:44 +0000625ImportsBundle:
vlm04a08da2005-08-12 10:06:17 +0000626 ImportsList TOK_FROM TypeRefName AssignedIdentifier {
vlmfa67ddc2004-06-03 03:38:44 +0000627 $$ = $1;
vlm04a08da2005-08-12 10:06:17 +0000628 $$->fromModuleName = $3;
629 $$->identifier = $4;
630 /* This stupid thing is used for look-back hack. */
631 saved_aid = $$->identifier.oid ? 0 : &($$->identifier);
vlmfa67ddc2004-06-03 03:38:44 +0000632 checkmem($$);
633 }
634 ;
635
636ImportsList:
637 ImportsElement {
638 $$ = asn1p_xports_new();
639 checkmem($$);
640 TQ_ADD(&($$->members), $1, next);
641 }
642 | ImportsList ',' ImportsElement {
643 $$ = $1;
644 TQ_ADD(&($$->members), $3, next);
645 }
646 ;
647
648ImportsElement:
649 TypeRefName {
650 $$ = asn1p_expr_new(yylineno);
651 checkmem($$);
652 $$->Identifier = $1;
653 $$->expr_type = A1TC_REFERENCE;
654 }
vlm0aa86902004-10-12 23:26:53 +0000655 | TypeRefName '{' '}' { /* Completely equivalent to above */
656 $$ = asn1p_expr_new(yylineno);
657 checkmem($$);
658 $$->Identifier = $1;
659 $$->expr_type = A1TC_REFERENCE;
660 }
vlmfa67ddc2004-06-03 03:38:44 +0000661 | Identifier {
662 $$ = asn1p_expr_new(yylineno);
663 checkmem($$);
664 $$->Identifier = $1;
665 $$->expr_type = A1TC_REFERENCE;
666 }
667 ;
668
669ExportsDefinition:
670 TOK_EXPORTS ExportsBody ';' {
671 $$ = $2;
672 }
673 | TOK_EXPORTS TOK_ALL ';' {
674 $$ = 0;
675 }
676 | TOK_EXPORTS ';' {
677 /* Empty EXPORTS clause effectively prohibits export. */
678 $$ = asn1p_xports_new();
679 checkmem($$);
680 }
681 ;
682
683ExportsBody:
684 ExportsElement {
685 $$ = asn1p_xports_new();
686 assert($$);
687 TQ_ADD(&($$->members), $1, next);
688 }
689 | ExportsBody ',' ExportsElement {
690 $$ = $1;
691 TQ_ADD(&($$->members), $3, next);
692 }
693 ;
694
695ExportsElement:
696 TypeRefName {
697 $$ = asn1p_expr_new(yylineno);
698 checkmem($$);
699 $$->Identifier = $1;
700 $$->expr_type = A1TC_EXPORTVAR;
701 }
vlm0aa86902004-10-12 23:26:53 +0000702 | TypeRefName '{' '}' {
703 $$ = asn1p_expr_new(yylineno);
704 checkmem($$);
705 $$->Identifier = $1;
706 $$->expr_type = A1TC_EXPORTVAR;
707 }
vlmfa67ddc2004-06-03 03:38:44 +0000708 | Identifier {
709 $$ = asn1p_expr_new(yylineno);
710 checkmem($$);
711 $$->Identifier = $1;
712 $$->expr_type = A1TC_EXPORTVAR;
713 }
714 ;
715
716
717ValueSetDefinition:
vlm7388db02005-03-31 21:48:13 +0000718 TypeRefName DefinedTypeRef TOK_PPEQ
719 '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
vlmfa67ddc2004-06-03 03:38:44 +0000720 $$ = $2;
721 assert($$->Identifier == 0);
722 $$->Identifier = $1;
723 $$->meta_type = AMT_VALUESET;
vlm7388db02005-03-31 21:48:13 +0000724 // take care of ValueSet body
vlmfa67ddc2004-06-03 03:38:44 +0000725 }
726 ;
727
728DefinedTypeRef:
729 ComplexTypeReference {
730 $$ = asn1p_expr_new(yylineno);
731 checkmem($$);
732 $$->reference = $1;
733 $$->expr_type = A1TC_REFERENCE;
734 $$->meta_type = AMT_TYPEREF;
735 }
736 | BasicTypeId {
737 $$ = asn1p_expr_new(yylineno);
738 checkmem($$);
739 $$->expr_type = $1;
740 $$->meta_type = AMT_TYPE;
741 }
742 ;
743
vlmfa67ddc2004-06-03 03:38:44 +0000744/*
745 * Data Type Reference.
746 * === EXAMPLE ===
747 * Type3 ::= CHOICE { a Type1, b Type 2 }
748 * === EOF ===
749 */
vlmfa67ddc2004-06-03 03:38:44 +0000750DataTypeReference:
751 /*
752 * Optionally tagged type definition.
753 */
vlmdc7cf042006-03-09 08:49:26 +0000754 TypeRefName TOK_PPEQ Type {
vlmfce48a42004-09-14 02:36:39 +0000755 $$ = $3;
vlmfa67ddc2004-06-03 03:38:44 +0000756 $$->Identifier = $1;
vlmfa67ddc2004-06-03 03:38:44 +0000757 assert($$->expr_type);
758 assert($$->meta_type);
759 }
vlmdc7cf042006-03-09 08:49:26 +0000760 | TypeRefName TOK_PPEQ ObjectClass {
vlmfa67ddc2004-06-03 03:38:44 +0000761 $$ = $3;
762 $$->Identifier = $1;
763 assert($$->expr_type == A1TC_CLASSDEF);
vlmdc7cf042006-03-09 08:49:26 +0000764 assert($$->meta_type == AMT_OBJECTCLASS);
vlmfa67ddc2004-06-03 03:38:44 +0000765 }
766 /*
767 * Parametrized <Type> declaration:
768 * === EXAMPLE ===
769 * SIGNED { ToBeSigned } ::= SEQUENCE {
770 * toBeSigned ToBeSigned,
771 * algorithm AlgorithmIdentifier,
772 * signature BIT STRING
773 * }
774 * === EOF ===
775 */
vlmec8f6812004-08-22 03:19:54 +0000776 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
vlmfa67ddc2004-06-03 03:38:44 +0000777 $$ = $6;
778 assert($$->Identifier == 0);
779 $$->Identifier = $1;
780 $$->params = $3;
781 $$->meta_type = AMT_PARAMTYPE;
782 }
783 ;
784
785ParameterArgumentList:
786 ParameterArgumentName {
787 int ret;
788 $$ = asn1p_paramlist_new(yylineno);
789 checkmem($$);
790 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
791 checkmem(ret == 0);
792 if($1.governor) asn1p_ref_free($1.governor);
793 if($1.argument) free($1.argument);
794 }
795 | ParameterArgumentList ',' ParameterArgumentName {
796 int ret;
797 $$ = $1;
798 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
799 checkmem(ret == 0);
800 if($3.governor) asn1p_ref_free($3.governor);
801 if($3.argument) free($3.argument);
802 }
803 ;
804
805ParameterArgumentName:
806 TypeRefName {
807 $$.governor = NULL;
808 $$.argument = $1;
809 }
810 | TypeRefName ':' Identifier {
811 int ret;
812 $$.governor = asn1p_ref_new(yylineno);
813 ret = asn1p_ref_add_component($$.governor, $1, 0);
814 checkmem(ret == 0);
815 $$.argument = $3;
816 }
vlm4053ca52005-02-18 16:34:21 +0000817 | TypeRefName ':' TypeRefName {
818 int ret;
819 $$.governor = asn1p_ref_new(yylineno);
820 ret = asn1p_ref_add_component($$.governor, $1, 0);
821 checkmem(ret == 0);
822 $$.argument = $3;
823 }
vlmfa67ddc2004-06-03 03:38:44 +0000824 | BasicTypeId ':' Identifier {
825 int ret;
826 $$.governor = asn1p_ref_new(yylineno);
827 ret = asn1p_ref_add_component($$.governor,
828 ASN_EXPR_TYPE2STR($1), 1);
829 checkmem(ret == 0);
830 $$.argument = $3;
831 }
832 ;
833
834ActualParameterList:
835 ActualParameter {
836 $$ = asn1p_expr_new(yylineno);
837 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000838 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000839 }
840 | ActualParameterList ',' ActualParameter {
841 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000842 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000843 }
844 ;
845
846ActualParameter:
vlmec8f6812004-08-22 03:19:54 +0000847 Type {
vlmfa67ddc2004-06-03 03:38:44 +0000848 $$ = $1;
849 }
850 | Identifier {
851 $$ = asn1p_expr_new(yylineno);
852 checkmem($$);
853 $$->Identifier = $1;
854 $$->expr_type = A1TC_REFERENCE;
855 $$->meta_type = AMT_VALUE;
856 }
857 ;
858
859/*
vlm4053ca52005-02-18 16:34:21 +0000860 | '{' ActualParameter '}' {
861 $$ = 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 }
vlmfa67ddc2004-06-03 03:38:44 +00001084 | ClassFieldIdentifier {
1085 asn1p_ref_t *ref;
1086 int ret;
1087 ref = asn1p_ref_new(yylineno);
1088 checkmem(ref);
1089 ret = asn1p_ref_add_component(ref, $1.name, $1.lex_type);
1090 checkmem(ret == 0);
1091 $$ = asn1p_wsyntx_chunk_fromref(ref, 0);
1092 }
vlm808411d2006-03-14 16:31:37 +00001093 | '[' WithSyntaxList ']' {
1094 $$ = asn1p_wsyntx_chunk_fromsyntax($2);
1095 }
vlmfa67ddc2004-06-03 03:38:44 +00001096 ;
1097
vlmfa67ddc2004-06-03 03:38:44 +00001098ExtensionAndException:
1099 TOK_ThreeDots {
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 $$->expr_type = A1TC_EXTENSIBLE;
1105 $$->meta_type = AMT_TYPE;
1106 }
1107 | TOK_ThreeDots '!' DefinedValue {
vlm39e5ed72004-09-05 10:40:41 +00001108 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001109 checkmem($$);
1110 $$->Identifier = strdup("...");
1111 checkmem($$->Identifier);
1112 $$->value = $3;
1113 $$->expr_type = A1TC_EXTENSIBLE;
1114 $$->meta_type = AMT_TYPE;
1115 }
1116 | TOK_ThreeDots '!' SignedNumber {
vlm39e5ed72004-09-05 10:40:41 +00001117 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001118 checkmem($$);
1119 $$->Identifier = strdup("...");
1120 $$->value = $3;
1121 checkmem($$->Identifier);
1122 $$->expr_type = A1TC_EXTENSIBLE;
1123 $$->meta_type = AMT_TYPE;
1124 }
1125 ;
1126
vlmec8f6812004-08-22 03:19:54 +00001127Type:
vlmfce48a42004-09-14 02:36:39 +00001128 optTag TypeDeclaration optConstraints {
1129 $$ = $2;
1130 $$->tag = $1;
vlmec8f6812004-08-22 03:19:54 +00001131 /*
1132 * Outer constraint for SEQUENCE OF and SET OF applies
1133 * to the inner type.
1134 */
1135 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1136 || $$->expr_type == ASN_CONSTR_SET_OF) {
1137 assert(!TQ_FIRST(&($$->members))->constraints);
vlmfce48a42004-09-14 02:36:39 +00001138 TQ_FIRST(&($$->members))->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001139 } else {
1140 if($$->constraints) {
1141 assert(!$2);
1142 } else {
vlmfce48a42004-09-14 02:36:39 +00001143 $$->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001144 }
1145 }
vlm177a5b62005-09-05 05:17:57 +00001146 }
1147 ;
1148
1149NSTD_IndirectMarker:
1150 {
1151 $$ = asn1p_as_pointer ? EM_INDIRECT : 0;
1152 asn1p_as_pointer = 0;
vlmec8f6812004-08-22 03:19:54 +00001153 }
1154 ;
1155
1156TypeDeclaration:
vlm177a5b62005-09-05 05:17:57 +00001157 NSTD_IndirectMarker TypeDeclarationSet {
vlm066dc102005-08-22 12:23:54 +00001158 $$ = $2;
vlm177a5b62005-09-05 05:17:57 +00001159 $$->marker.flags |= $1;
1160
1161 if(($$->marker.flags & EM_INDIRECT)
1162 && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
1163 fprintf(stderr,
1164 "INFO: Directive <ASN1C:RepresentAsPointer> "
1165 "applied to %s at line %d\n",
1166 ASN_EXPR_TYPE2STR($$->expr_type)
1167 ? ASN_EXPR_TYPE2STR($$->expr_type)
1168 : "member",
1169 $$->_lineno
1170 );
1171 }
vlm066dc102005-08-22 12:23:54 +00001172 }
vlm177a5b62005-09-05 05:17:57 +00001173 ;
vlm066dc102005-08-22 12:23:54 +00001174
1175TypeDeclarationSet:
vlmfa67ddc2004-06-03 03:38:44 +00001176 BasicType {
1177 $$ = $1;
1178 }
vlm177a5b62005-09-05 05:17:57 +00001179 | TOK_CHOICE '{' AlternativeTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001180 $$ = $3;
1181 assert($$->expr_type == A1TC_INVALID);
1182 $$->expr_type = ASN_CONSTR_CHOICE;
1183 $$->meta_type = AMT_TYPE;
vlmfa67ddc2004-06-03 03:38:44 +00001184 }
vlm177a5b62005-09-05 05:17:57 +00001185 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001186 $$ = $3;
1187 assert($$->expr_type == A1TC_INVALID);
1188 $$->expr_type = ASN_CONSTR_SEQUENCE;
1189 $$->meta_type = AMT_TYPE;
1190 }
vlm177a5b62005-09-05 05:17:57 +00001191 | TOK_SET '{' optComponentTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001192 $$ = $3;
1193 assert($$->expr_type == A1TC_INVALID);
1194 $$->expr_type = ASN_CONSTR_SET;
1195 $$->meta_type = AMT_TYPE;
1196 }
vlm151c0b22004-09-22 16:03:36 +00001197 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
vlm39e5ed72004-09-05 10:40:41 +00001198 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001199 checkmem($$);
1200 $$->constraints = $2;
1201 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1202 $$->meta_type = AMT_TYPE;
vlm151c0b22004-09-22 16:03:36 +00001203 $6->Identifier = $4;
1204 $6->tag = $5;
1205 asn1p_expr_add($$, $6);
vlmec8f6812004-08-22 03:19:54 +00001206 }
vlm151c0b22004-09-22 16:03:36 +00001207 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
vlm39e5ed72004-09-05 10:40:41 +00001208 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001209 checkmem($$);
1210 $$->constraints = $2;
1211 $$->expr_type = ASN_CONSTR_SET_OF;
1212 $$->meta_type = AMT_TYPE;
vlm151c0b22004-09-22 16:03:36 +00001213 $6->Identifier = $4;
1214 $6->tag = $5;
1215 asn1p_expr_add($$, $6);
vlmec8f6812004-08-22 03:19:54 +00001216 }
1217 | TOK_ANY {
vlm39e5ed72004-09-05 10:40:41 +00001218 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001219 checkmem($$);
vlm044f7442004-09-04 04:49:21 +00001220 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001221 $$->meta_type = AMT_TYPE;
1222 }
1223 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1224 int ret;
vlm39e5ed72004-09-05 10:40:41 +00001225 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001226 checkmem($$);
1227 $$->reference = asn1p_ref_new(yylineno);
1228 ret = asn1p_ref_add_component($$->reference,
1229 $4, RLT_lowercase);
1230 checkmem(ret == 0);
vlm044f7442004-09-04 04:49:21 +00001231 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001232 $$->meta_type = AMT_TYPE;
1233 }
vlmfa67ddc2004-06-03 03:38:44 +00001234 /*
1235 * A parametrized assignment.
1236 */
1237 | TypeRefName '{' ActualParameterList '}' {
1238 int ret;
1239 $$ = $3;
1240 assert($$->expr_type == 0);
1241 assert($$->meta_type == 0);
1242 assert($$->reference == 0);
1243 $$->reference = asn1p_ref_new(yylineno);
1244 checkmem($$->reference);
1245 ret = asn1p_ref_add_component($$->reference, $1, RLT_UNKNOWN);
1246 checkmem(ret == 0);
1247 free($1);
1248 $$->expr_type = A1TC_PARAMETRIZED;
1249 $$->meta_type = AMT_TYPE;
1250 }
1251 /*
1252 * A DefinedType reference.
1253 * "CLASS1.&id.&id2"
1254 * or
1255 * "Module.Type"
1256 * or
1257 * "Module.identifier"
1258 * or
1259 * "Type"
1260 */
1261 | ComplexTypeReference {
1262 $$ = asn1p_expr_new(yylineno);
1263 checkmem($$);
1264 $$->reference = $1;
1265 $$->expr_type = A1TC_REFERENCE;
1266 $$->meta_type = AMT_TYPEREF;
1267 }
1268 | TOK_INSTANCE TOK_OF ComplexTypeReference {
1269 $$ = asn1p_expr_new(yylineno);
1270 checkmem($$);
1271 $$->reference = $3;
1272 $$->expr_type = A1TC_INSTANCE;
1273 $$->meta_type = AMT_TYPE;
1274 }
1275 ;
1276
1277/*
1278 * A type name consisting of several components.
1279 * === EXAMPLE ===
1280 * === EOF ===
1281 */
1282ComplexTypeReference:
1283 TOK_typereference {
1284 int ret;
1285 $$ = asn1p_ref_new(yylineno);
1286 checkmem($$);
1287 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1288 checkmem(ret == 0);
1289 free($1);
1290 }
1291 | TOK_typereference '.' TypeRefName {
1292 int ret;
1293 $$ = asn1p_ref_new(yylineno);
1294 checkmem($$);
1295 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1296 checkmem(ret == 0);
1297 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1298 checkmem(ret == 0);
1299 free($1);
1300 }
vlmc94e28f2004-09-15 11:59:51 +00001301 | ObjectClassReference '.' TypeRefName {
1302 int ret;
1303 $$ = asn1p_ref_new(yylineno);
1304 checkmem($$);
1305 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1306 checkmem(ret == 0);
1307 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1308 checkmem(ret == 0);
1309 free($1);
1310 }
vlmfa67ddc2004-06-03 03:38:44 +00001311 | TOK_typereference '.' Identifier {
1312 int ret;
1313 $$ = asn1p_ref_new(yylineno);
1314 checkmem($$);
1315 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1316 checkmem(ret == 0);
1317 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1318 checkmem(ret == 0);
1319 free($1);
1320 }
1321 | ObjectClassReference {
1322 int ret;
1323 $$ = asn1p_ref_new(yylineno);
1324 checkmem($$);
1325 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1326 free($1);
1327 checkmem(ret == 0);
1328 }
1329 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1330 int ret;
1331 $$ = $3;
1332 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1333 free($1);
1334 checkmem(ret == 0);
1335 /*
1336 * Move the last element infront.
1337 */
1338 {
1339 struct asn1p_ref_component_s tmp_comp;
1340 tmp_comp = $$->components[$$->comp_count-1];
1341 memmove(&$$->components[1],
1342 &$$->components[0],
1343 sizeof($$->components[0])
1344 * ($$->comp_count - 1));
1345 $$->components[0] = tmp_comp;
1346 }
1347 }
1348 ;
1349
1350ComplexTypeReferenceAmpList:
1351 ComplexTypeReferenceElement {
1352 int ret;
1353 $$ = asn1p_ref_new(yylineno);
1354 checkmem($$);
1355 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1356 free($1.name);
1357 checkmem(ret == 0);
1358 }
1359 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1360 int ret;
1361 $$ = $1;
1362 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1363 free($3.name);
1364 checkmem(ret == 0);
1365 }
1366 ;
1367
1368ComplexTypeReferenceElement: ClassFieldName;
1369ClassFieldIdentifier: ClassFieldName;
1370
1371ClassFieldName:
1372 /* "&Type1" */
1373 TOK_typefieldreference {
1374 $$.lex_type = RLT_AmpUppercase;
1375 $$.name = $1;
1376 }
1377 /* "&id" */
1378 | TOK_valuefieldreference {
1379 $$.lex_type = RLT_Amplowercase;
1380 $$.name = $1;
1381 }
1382 ;
1383
1384
vlmdc7cf042006-03-09 08:49:26 +00001385FieldName:
1386 /* "&Type1" */
1387 TOK_typefieldreference {
1388 $$ = asn1p_ref_new(yylineno);
1389 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1390 }
1391 | FieldName '.' TOK_typefieldreference {
1392 $$ = $$;
1393 asn1p_ref_add_component($$, $3, RLT_AmpUppercase);
1394 }
1395 | FieldName '.' TOK_valuefieldreference {
1396 $$ = $$;
1397 asn1p_ref_add_component($$, $3, RLT_Amplowercase);
1398 }
1399 ;
1400
1401DefinedObjectClass:
1402 TOK_capitalreference {
1403 $$ = asn1p_ref_new(yylineno);
1404 asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1405 }
vlmee7196e2006-03-09 09:08:49 +00001406/*
vlmdc7cf042006-03-09 08:49:26 +00001407 | TypeRefName '.' TOK_capitalreference {
1408 $$ = asn1p_ref_new(yylineno);
1409 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1410 asn1p_ref_add_component($$, $3, RLT_CAPITALS);
1411 }
vlmee7196e2006-03-09 09:08:49 +00001412*/
vlmdc7cf042006-03-09 08:49:26 +00001413 ;
1414
1415
vlmfa67ddc2004-06-03 03:38:44 +00001416/*
1417 * === EXAMPLE ===
1418 * value INTEGER ::= 1
1419 * === EOF ===
1420 */
1421ValueDefinition:
vlmc94e28f2004-09-15 11:59:51 +00001422 Identifier DefinedTypeRef TOK_PPEQ Value {
vlmfa67ddc2004-06-03 03:38:44 +00001423 $$ = $2;
1424 assert($$->Identifier == NULL);
1425 $$->Identifier = $1;
1426 $$->meta_type = AMT_VALUE;
1427 $$->value = $4;
1428 }
1429 ;
1430
vlmc94e28f2004-09-15 11:59:51 +00001431Value:
1432 Identifier ':' Value {
1433 $$ = asn1p_value_fromint(0);
1434 checkmem($$);
1435 $$->type = ATV_CHOICE_IDENTIFIER;
1436 $$->value.choice_identifier.identifier = $1;
1437 $$->value.choice_identifier.value = $3;
1438 }
vlmd30bc6c2005-03-24 16:27:02 +00001439 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
vlmfa67ddc2004-06-03 03:38:44 +00001440 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1441 checkmem($$);
1442 $$->type = ATV_UNPARSED;
1443 }
vlmc94e28f2004-09-15 11:59:51 +00001444 | TOK_NULL {
1445 $$ = asn1p_value_fromint(0);
1446 checkmem($$);
1447 $$->type = ATV_NULL;
1448 }
1449 | TOK_FALSE {
1450 $$ = asn1p_value_fromint(0);
1451 checkmem($$);
1452 $$->type = ATV_FALSE;
1453 }
1454 | TOK_TRUE {
1455 $$ = asn1p_value_fromint(0);
1456 checkmem($$);
1457 $$->type = ATV_TRUE;
1458 }
vlmfa67ddc2004-06-03 03:38:44 +00001459 | TOK_bstring {
1460 $$ = _convert_bitstring2binary($1, 'B');
1461 checkmem($$);
1462 }
1463 | TOK_hstring {
1464 $$ = _convert_bitstring2binary($1, 'H');
1465 checkmem($$);
1466 }
vlme1e6ed82005-03-24 14:26:38 +00001467 | RestrictedCharacterStringValue {
1468 $$ = $$;
vlmfa67ddc2004-06-03 03:38:44 +00001469 }
1470 | SignedNumber {
1471 $$ = $1;
1472 }
1473 | DefinedValue {
1474 $$ = $1;
1475 }
1476 ;
1477
1478DefinedValue:
1479 Identifier {
1480 asn1p_ref_t *ref;
1481 int ret;
1482 ref = asn1p_ref_new(yylineno);
1483 checkmem(ref);
1484 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1485 checkmem(ret == 0);
1486 $$ = asn1p_value_fromref(ref, 0);
1487 checkmem($$);
1488 free($1);
1489 }
1490 | TypeRefName '.' Identifier {
1491 asn1p_ref_t *ref;
1492 int ret;
1493 ref = asn1p_ref_new(yylineno);
1494 checkmem(ref);
1495 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1496 checkmem(ret == 0);
1497 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1498 checkmem(ret == 0);
1499 $$ = asn1p_value_fromref(ref, 0);
1500 checkmem($$);
1501 free($1);
1502 free($3);
1503 }
1504 ;
1505
vlme1e6ed82005-03-24 14:26:38 +00001506
1507RestrictedCharacterStringValue:
1508 TOK_cstring {
1509 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1510 checkmem($$);
1511 }
vlm2c8c44d2005-03-24 16:22:35 +00001512 | TOK_tuple {
1513 $$ = asn1p_value_fromint($1);
1514 checkmem($$);
1515 $$->type = ATV_TUPLE;
1516 }
1517 | TOK_quadruple {
1518 $$ = asn1p_value_fromint($1);
1519 checkmem($$);
1520 $$->type = ATV_QUADRUPLE;
1521 }
1522 /*
vlme1e6ed82005-03-24 14:26:38 +00001523 | '{' TOK_number ',' TOK_number '}' {
1524 asn1c_integer_t v = ($2 << 4) + $4;
1525 if($2 > 7) return yyerror("X.680:2003, #37.14 "
1526 "mandates 0..7 range for Tuple's TableColumn");
1527 if($4 > 15) return yyerror("X.680:2003, #37.14 "
1528 "mandates 0..15 range for Tuple's TableRow");
1529 $$ = asn1p_value_fromint(v);
1530 checkmem($$);
1531 $$->type = ATV_TUPLE;
1532 }
1533 | '{' TOK_number ',' TOK_number ',' TOK_number ',' TOK_number '}' {
1534 asn1c_integer_t v = ($2 << 24) | ($4 << 16) | ($6 << 8) | $8;
1535 if($2 > 127) return yyerror("X.680:2003, #37.12 "
1536 "mandates 0..127 range for Quadruple's Group");
1537 if($4 > 255) return yyerror("X.680:2003, #37.12 "
1538 "mandates 0..255 range for Quadruple's Plane");
1539 if($6 > 255) return yyerror("X.680:2003, #37.12 "
1540 "mandates 0..255 range for Quadruple's Row");
1541 if($8 > 255) return yyerror("X.680:2003, #37.12 "
1542 "mandates 0..255 range for Quadruple's Cell");
1543 $$ = asn1p_value_fromint(v);
1544 checkmem($$);
1545 $$->type = ATV_QUADRUPLE;
1546 }
vlm2c8c44d2005-03-24 16:22:35 +00001547 */
vlme1e6ed82005-03-24 14:26:38 +00001548 ;
1549
vlmfa67ddc2004-06-03 03:38:44 +00001550Opaque:
1551 TOK_opaque {
vlm6611add2005-03-20 14:28:32 +00001552 $$.len = $1.len + 1;
vlmfa67ddc2004-06-03 03:38:44 +00001553 $$.buf = malloc($$.len + 1);
1554 checkmem($$.buf);
1555 $$.buf[0] = '{';
vlm6611add2005-03-20 14:28:32 +00001556 memcpy($$.buf + 1, $1.buf, $1.len);
vlmfa67ddc2004-06-03 03:38:44 +00001557 $$.buf[$$.len] = '\0';
1558 free($1.buf);
1559 }
1560 | Opaque TOK_opaque {
1561 int newsize = $1.len + $2.len;
1562 char *p = malloc(newsize + 1);
1563 checkmem(p);
1564 memcpy(p , $1.buf, $1.len);
1565 memcpy(p + $1.len, $2.buf, $2.len);
1566 p[newsize] = '\0';
1567 free($1.buf);
1568 free($2.buf);
1569 $$.buf = p;
1570 $$.len = newsize;
1571 }
1572 ;
1573
1574BasicTypeId:
1575 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1576 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1577 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1578 | BasicTypeId_UniverationCompatible { $$ = $1; }
1579 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1580 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1581 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1582 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1583 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1584 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1585 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1586 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
vlm5e2c4b92005-03-20 11:12:40 +00001587 | BasicString { $$ = $1; }
vlmfa67ddc2004-06-03 03:38:44 +00001588 ;
1589
1590/*
1591 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1592 */
1593BasicTypeId_UniverationCompatible:
1594 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1595 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1596 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1597 ;
1598
1599BasicType:
1600 BasicTypeId {
vlm39e5ed72004-09-05 10:40:41 +00001601 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001602 checkmem($$);
1603 $$->expr_type = $1;
1604 $$->meta_type = AMT_TYPE;
1605 }
1606 | BasicTypeId_UniverationCompatible UniverationDefinition {
1607 if($2) {
1608 $$ = $2;
1609 } else {
vlm39e5ed72004-09-05 10:40:41 +00001610 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001611 checkmem($$);
1612 }
1613 $$->expr_type = $1;
1614 $$->meta_type = AMT_TYPE;
1615 }
1616 ;
1617
1618BasicString:
1619 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1620 | TOK_GeneralString {
1621 $$ = ASN_STRING_GeneralString;
vlmc94e28f2004-09-15 11:59:51 +00001622 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001623 }
1624 | TOK_GraphicString {
1625 $$ = ASN_STRING_GraphicString;
vlmc94e28f2004-09-15 11:59:51 +00001626 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001627 }
1628 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1629 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1630 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1631 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1632 | TOK_T61String {
1633 $$ = ASN_STRING_T61String;
vlmc94e28f2004-09-15 11:59:51 +00001634 fprintf(stderr, "WARNING: T61String is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001635 }
1636 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1637 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1638 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1639 | TOK_VideotexString {
1640 $$ = ASN_STRING_VideotexString;
vlmc94e28f2004-09-15 11:59:51 +00001641 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001642 }
1643 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1644 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1645 ;
1646
vlm5f0128b2004-08-20 13:25:29 +00001647
vlmfa67ddc2004-06-03 03:38:44 +00001648/*
1649 * Data type constraints.
1650 */
vlmfa67ddc2004-06-03 03:38:44 +00001651Union: '|' | TOK_UNION;
1652Intersection: '^' | TOK_INTERSECTION;
1653Except: TOK_EXCEPT;
1654
vlm9283dbe2004-08-18 04:59:12 +00001655optConstraints:
1656 { $$ = 0; }
vlm5f0128b2004-08-20 13:25:29 +00001657 | Constraints {
1658 $$ = $1;
1659 }
1660 ;
1661
1662Constraints:
1663 SetOfConstraints {
vlm9fe7c922005-08-12 10:08:45 +00001664 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
vlm9283dbe2004-08-18 04:59:12 +00001665 }
1666 | TOK_SIZE '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001667 /*
1668 * This is a special case, for compatibility purposes.
vlm9283dbe2004-08-18 04:59:12 +00001669 * It goes without parentheses.
vlmfa67ddc2004-06-03 03:38:44 +00001670 */
vlm9fe7c922005-08-12 10:08:45 +00001671 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001672 }
vlmfa67ddc2004-06-03 03:38:44 +00001673 ;
1674
vlm9283dbe2004-08-18 04:59:12 +00001675SetOfConstraints:
1676 '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001677 $$ = $2;
1678 }
vlm9283dbe2004-08-18 04:59:12 +00001679 | SetOfConstraints '(' ElementSetSpecs ')' {
vlm9fe7c922005-08-12 10:08:45 +00001680 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
vlm9283dbe2004-08-18 04:59:12 +00001681 }
vlmfa67ddc2004-06-03 03:38:44 +00001682 ;
1683
vlm9283dbe2004-08-18 04:59:12 +00001684ElementSetSpecs:
1685 ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001686 $$ = $1;
1687 }
vlm9283dbe2004-08-18 04:59:12 +00001688 | ElementSetSpec ',' TOK_ThreeDots {
vlmfa67ddc2004-06-03 03:38:44 +00001689 asn1p_constraint_t *ct;
1690 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001691 ct->type = ACT_EL_EXT;
vlm9fe7c922005-08-12 10:08:45 +00001692 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlmfa67ddc2004-06-03 03:38:44 +00001693 }
vlm9283dbe2004-08-18 04:59:12 +00001694 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001695 asn1p_constraint_t *ct;
1696 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001697 ct->type = ACT_EL_EXT;
vlm9fe7c922005-08-12 10:08:45 +00001698 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlm6f5eb0b2004-08-13 12:35:09 +00001699 ct = $$;
vlm9fe7c922005-08-12 10:08:45 +00001700 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
vlmfa67ddc2004-06-03 03:38:44 +00001701 }
vlmfa67ddc2004-06-03 03:38:44 +00001702 ;
1703
vlm9283dbe2004-08-18 04:59:12 +00001704ElementSetSpec:
1705 ConstraintSubtypeElement {
1706 $$ = $1;
1707 }
vlme1e6ed82005-03-24 14:26:38 +00001708 | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001709 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
vlme1e6ed82005-03-24 14:26:38 +00001710 }
vlm9283dbe2004-08-18 04:59:12 +00001711 | ElementSetSpec Union ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001712 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001713 }
vlm9283dbe2004-08-18 04:59:12 +00001714 | ElementSetSpec Intersection ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001715 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001716 }
vlm9283dbe2004-08-18 04:59:12 +00001717 | ConstraintSubtypeElement Except ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001718 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001719 }
1720 ;
1721
1722ConstraintSubtypeElement:
vlm9283dbe2004-08-18 04:59:12 +00001723 ConstraintSpec '(' ElementSetSpecs ')' {
1724 int ret;
1725 $$ = asn1p_constraint_new(yylineno);
1726 checkmem($$);
1727 $$->type = $1;
1728 ret = asn1p_constraint_insert($$, $3);
1729 checkmem(ret == 0);
1730 }
1731 | '(' ElementSetSpecs ')' {
1732 int ret;
1733 $$ = asn1p_constraint_new(yylineno);
1734 checkmem($$);
1735 $$->type = ACT_CA_SET;
1736 ret = asn1p_constraint_insert($$, $2);
1737 checkmem(ret == 0);
1738 }
vlma6a12e32005-03-20 12:58:00 +00001739 | SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001740 $$ = asn1p_constraint_new(yylineno);
1741 checkmem($$);
1742 $$->type = ACT_EL_VALUE;
1743 $$->value = $1;
1744 }
vlma6a12e32005-03-20 12:58:00 +00001745 | ContainedSubtype {
1746 $$ = asn1p_constraint_new(yylineno);
1747 checkmem($$);
1748 $$->type = ACT_EL_TYPE;
1749 $$->containedSubtype = $1;
1750 }
1751 | SingleValue ConstraintRangeSpec SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001752 $$ = asn1p_constraint_new(yylineno);
1753 checkmem($$);
1754 $$->type = $2;
1755 $$->range_start = $1;
1756 $$->range_stop = $3;
1757 }
vlma6a12e32005-03-20 12:58:00 +00001758 | TOK_MIN ConstraintRangeSpec SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001759 $$ = asn1p_constraint_new(yylineno);
1760 checkmem($$);
vlm9283dbe2004-08-18 04:59:12 +00001761 $$->type = $2;
1762 $$->range_start = asn1p_value_fromint(-123);
1763 $$->range_stop = $3;
1764 $$->range_start->type = ATV_MIN;
1765 }
vlma6a12e32005-03-20 12:58:00 +00001766 | SingleValue ConstraintRangeSpec TOK_MAX {
vlm9283dbe2004-08-18 04:59:12 +00001767 $$ = asn1p_constraint_new(yylineno);
1768 checkmem($$);
1769 $$->type = $2;
1770 $$->range_start = $1;
1771 $$->range_stop = asn1p_value_fromint(321);
1772 $$->range_stop->type = ATV_MAX;
1773 }
1774 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1775 $$ = asn1p_constraint_new(yylineno);
1776 checkmem($$);
1777 $$->type = $2;
1778 $$->range_start = asn1p_value_fromint(-123);
1779 $$->range_stop = asn1p_value_fromint(321);
1780 $$->range_start->type = ATV_MIN;
1781 $$->range_stop->type = ATV_MAX;
vlmfa67ddc2004-06-03 03:38:44 +00001782 }
1783 | TableConstraint {
1784 $$ = $1;
1785 }
vlm7bbdc9f2005-03-28 15:01:27 +00001786 | InnerTypeConstraint {
vlmfa67ddc2004-06-03 03:38:44 +00001787 $$ = $1;
1788 }
vlm6611add2005-03-20 14:28:32 +00001789 | TOK_CONSTRAINED TOK_BY '{'
1790 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1791 $$ = asn1p_constraint_new(yylineno);
1792 checkmem($$);
1793 $$->type = ACT_CT_CTDBY;
1794 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
1795 checkmem($$->value);
1796 $$->value->type = ATV_UNPARSED;
1797 }
vlmfa67ddc2004-06-03 03:38:44 +00001798 ;
1799
1800ConstraintRangeSpec:
1801 TOK_TwoDots { $$ = ACT_EL_RANGE; }
1802 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
1803 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
1804 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
1805 ;
1806
1807ConstraintSpec:
1808 TOK_SIZE {
1809 $$ = ACT_CT_SIZE;
1810 }
1811 | TOK_FROM {
1812 $$ = ACT_CT_FROM;
1813 }
1814 ;
1815
vlma6a12e32005-03-20 12:58:00 +00001816SingleValue:
vlm4053ca52005-02-18 16:34:21 +00001817 TOK_FALSE {
1818 $$ = asn1p_value_fromint(0);
1819 checkmem($$);
1820 $$->type = ATV_FALSE;
1821 }
1822 | TOK_TRUE {
1823 $$ = asn1p_value_fromint(1);
1824 checkmem($$);
1825 $$->type = ATV_TRUE;
1826 }
1827 | SignedNumber {
vlmfa67ddc2004-06-03 03:38:44 +00001828 $$ = $1;
1829 }
vlme1e6ed82005-03-24 14:26:38 +00001830 | RestrictedCharacterStringValue {
1831 $$ = $1;
vlm4053ca52005-02-18 16:34:21 +00001832 }
vlmfa67ddc2004-06-03 03:38:44 +00001833 | Identifier {
1834 asn1p_ref_t *ref;
1835 int ret;
1836 ref = asn1p_ref_new(yylineno);
1837 checkmem(ref);
1838 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1839 checkmem(ret == 0);
1840 $$ = asn1p_value_fromref(ref, 0);
1841 checkmem($$);
1842 free($1);
1843 }
vlma6a12e32005-03-20 12:58:00 +00001844 ;
1845
1846ContainedSubtype:
1847 TypeRefName {
vlm4053ca52005-02-18 16:34:21 +00001848 asn1p_ref_t *ref;
1849 int ret;
1850 ref = asn1p_ref_new(yylineno);
1851 checkmem(ref);
1852 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1853 checkmem(ret == 0);
1854 $$ = asn1p_value_fromref(ref, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001855 checkmem($$);
vlm4053ca52005-02-18 16:34:21 +00001856 free($1);
vlmfa67ddc2004-06-03 03:38:44 +00001857 }
1858 ;
1859
vlm7bbdc9f2005-03-28 15:01:27 +00001860InnerTypeConstraint:
1861 TOK_WITH TOK_COMPONENT SetOfConstraints {
vlm9fe7c922005-08-12 10:08:45 +00001862 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
vlm7bbdc9f2005-03-28 15:01:27 +00001863 }
1864 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
vlm9fe7c922005-08-12 10:08:45 +00001865 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001866 }
1867 ;
1868
1869WithComponentsList:
1870 WithComponentsElement {
1871 $$ = $1;
1872 }
1873 | WithComponentsList ',' WithComponentsElement {
vlm9fe7c922005-08-12 10:08:45 +00001874 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001875 }
1876 ;
1877
1878WithComponentsElement:
1879 TOK_ThreeDots {
1880 $$ = asn1p_constraint_new(yylineno);
1881 checkmem($$);
1882 $$->type = ACT_EL_EXT;
vlm7bbdc9f2005-03-28 15:01:27 +00001883 $$->value = asn1p_value_frombuf("...", 3, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001884 }
1885 | Identifier optConstraints optPresenceConstraint {
1886 $$ = asn1p_constraint_new(yylineno);
1887 checkmem($$);
1888 $$->type = ACT_EL_VALUE;
1889 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1890 $$->presence = $3;
vlm7bbdc9f2005-03-28 15:01:27 +00001891 if($2) asn1p_constraint_insert($$, $2);
vlmfa67ddc2004-06-03 03:38:44 +00001892 }
1893 ;
1894
1895/*
1896 * presence constraint for WithComponents
1897 */
1898optPresenceConstraint:
1899 { $$ = ACPRES_DEFAULT; }
1900 | PresenceConstraint { $$ = $1; }
1901 ;
1902
1903PresenceConstraint:
1904 TOK_PRESENT {
1905 $$ = ACPRES_PRESENT;
1906 }
1907 | TOK_ABSENT {
1908 $$ = ACPRES_ABSENT;
1909 }
1910 | TOK_OPTIONAL {
1911 $$ = ACPRES_OPTIONAL;
1912 }
1913 ;
1914
1915TableConstraint:
1916 SimpleTableConstraint {
1917 $$ = $1;
1918 }
1919 | ComponentRelationConstraint {
1920 $$ = $1;
1921 }
1922 ;
1923
1924/*
1925 * "{ExtensionSet}"
1926 */
1927SimpleTableConstraint:
1928 '{' TypeRefName '}' {
1929 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
1930 asn1p_constraint_t *ct;
1931 int ret;
1932 ret = asn1p_ref_add_component(ref, $2, 0);
1933 checkmem(ret == 0);
1934 ct = asn1p_constraint_new(yylineno);
1935 checkmem($$);
1936 ct->type = ACT_EL_VALUE;
1937 ct->value = asn1p_value_fromref(ref, 0);
vlm9fe7c922005-08-12 10:08:45 +00001938 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001939 }
1940 ;
1941
1942ComponentRelationConstraint:
1943 SimpleTableConstraint '{' AtNotationList '}' {
vlm9fe7c922005-08-12 10:08:45 +00001944 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001945 }
1946 ;
1947
1948AtNotationList:
1949 AtNotationElement {
1950 $$ = asn1p_constraint_new(yylineno);
1951 checkmem($$);
1952 $$->type = ACT_EL_VALUE;
1953 $$->value = asn1p_value_fromref($1, 0);
1954 }
1955 | AtNotationList ',' AtNotationElement {
1956 asn1p_constraint_t *ct;
1957 ct = asn1p_constraint_new(yylineno);
1958 checkmem(ct);
1959 ct->type = ACT_EL_VALUE;
1960 ct->value = asn1p_value_fromref($3, 0);
vlm9fe7c922005-08-12 10:08:45 +00001961 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlmfa67ddc2004-06-03 03:38:44 +00001962 }
1963 ;
1964
1965/*
1966 * @blah
1967 */
1968AtNotationElement:
1969 '@' ComponentIdList {
1970 char *p = malloc(strlen($2) + 2);
1971 int ret;
1972 *p = '@';
1973 strcpy(p + 1, $2);
1974 $$ = asn1p_ref_new(yylineno);
1975 ret = asn1p_ref_add_component($$, p, 0);
1976 checkmem(ret == 0);
1977 free(p);
1978 free($2);
1979 }
1980 | '@' '.' ComponentIdList {
1981 char *p = malloc(strlen($3) + 3);
1982 int ret;
1983 p[0] = '@';
1984 p[1] = '.';
1985 strcpy(p + 2, $3);
1986 $$ = asn1p_ref_new(yylineno);
1987 ret = asn1p_ref_add_component($$, p, 0);
1988 checkmem(ret == 0);
1989 free(p);
1990 free($3);
1991 }
1992 ;
1993
1994/* identifier "." ... */
1995ComponentIdList:
1996 Identifier {
1997 $$ = $1;
1998 }
1999 | ComponentIdList '.' Identifier {
2000 int l1 = strlen($1);
2001 int l3 = strlen($3);
2002 $$ = malloc(l1 + 1 + l3 + 1);
2003 memcpy($$, $1, l1);
2004 $$[l1] = '.';
2005 memcpy($$ + l1 + 1, $3, l3);
2006 $$[l1 + 1 + l3] = '\0';
2007 }
2008 ;
2009
2010
2011
2012/*
2013 * MARKERS
2014 */
2015
2016optMarker:
vlmc94e28f2004-09-15 11:59:51 +00002017 {
2018 $$.flags = EM_NOMARK;
2019 $$.default_value = 0;
2020 }
vlmfa67ddc2004-06-03 03:38:44 +00002021 | Marker { $$ = $1; }
2022 ;
2023
2024Marker:
2025 TOK_OPTIONAL {
vlm1ac75e72005-11-26 11:21:55 +00002026 $$.flags = EM_OPTIONAL | EM_INDIRECT;
vlmc94e28f2004-09-15 11:59:51 +00002027 $$.default_value = 0;
vlmfa67ddc2004-06-03 03:38:44 +00002028 }
vlmc94e28f2004-09-15 11:59:51 +00002029 | TOK_DEFAULT Value {
2030 $$.flags = EM_DEFAULT;
2031 $$.default_value = $2;
vlmfa67ddc2004-06-03 03:38:44 +00002032 }
2033 ;
2034
2035/*
2036 * Universal enumeration definition to use in INTEGER and ENUMERATED.
2037 * === EXAMPLE ===
2038 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
2039 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
2040 * === EOF ===
2041 */
2042/*
2043optUniverationDefinition:
2044 { $$ = 0; }
2045 | UniverationDefinition {
2046 $$ = $1;
2047 }
2048 ;
2049*/
2050
2051UniverationDefinition:
2052 '{' '}' {
vlm39e5ed72004-09-05 10:40:41 +00002053 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002054 checkmem($$);
2055 }
2056 | '{' UniverationList '}' {
2057 $$ = $2;
2058 }
2059 ;
2060
2061UniverationList:
2062 UniverationElement {
vlm39e5ed72004-09-05 10:40:41 +00002063 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002064 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +00002065 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +00002066 }
2067 | UniverationList ',' UniverationElement {
2068 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +00002069 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +00002070 }
2071 ;
2072
2073UniverationElement:
2074 Identifier {
vlm39e5ed72004-09-05 10:40:41 +00002075 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002076 checkmem($$);
2077 $$->expr_type = A1TC_UNIVERVAL;
2078 $$->meta_type = AMT_VALUE;
2079 $$->Identifier = $1;
2080 }
2081 | Identifier '(' SignedNumber ')' {
vlm39e5ed72004-09-05 10:40:41 +00002082 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002083 checkmem($$);
2084 $$->expr_type = A1TC_UNIVERVAL;
2085 $$->meta_type = AMT_VALUE;
2086 $$->Identifier = $1;
2087 $$->value = $3;
2088 }
2089 | Identifier '(' DefinedValue ')' {
vlm39e5ed72004-09-05 10:40:41 +00002090 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002091 checkmem($$);
2092 $$->expr_type = A1TC_UNIVERVAL;
2093 $$->meta_type = AMT_VALUE;
2094 $$->Identifier = $1;
2095 $$->value = $3;
2096 }
2097 | SignedNumber {
vlm39e5ed72004-09-05 10:40:41 +00002098 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002099 checkmem($$);
2100 $$->expr_type = A1TC_UNIVERVAL;
2101 $$->meta_type = AMT_VALUE;
2102 $$->value = $1;
2103 }
2104 | TOK_ThreeDots {
vlm39e5ed72004-09-05 10:40:41 +00002105 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002106 checkmem($$);
2107 $$->Identifier = strdup("...");
2108 checkmem($$->Identifier);
2109 $$->expr_type = A1TC_EXTENSIBLE;
2110 $$->meta_type = AMT_VALUE;
2111 }
2112 ;
2113
2114SignedNumber:
2115 TOK_number {
2116 $$ = asn1p_value_fromint($1);
2117 checkmem($$);
2118 }
2119 | TOK_number_negative {
2120 $$ = asn1p_value_fromint($1);
2121 checkmem($$);
2122 }
2123 ;
2124
2125/*
2126 * SEQUENCE definition.
2127 * === EXAMPLE ===
2128 * Struct1 ::= SEQUENCE {
2129 * memb1 Struct2,
2130 * memb2 SEQUENCE OF {
2131 * memb2-1 Struct 3
2132 * }
2133 * }
2134 * === EOF ===
2135 */
2136
2137
2138
2139/*
2140 * SET definition.
2141 * === EXAMPLE ===
2142 * Person ::= SET {
2143 * name [0] PrintableString (SIZE(1..20)),
2144 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2145 * }
2146 * === EOF ===
2147 */
2148
2149optTag:
2150 { memset(&$$, 0, sizeof($$)); }
2151 | Tag { $$ = $1; }
2152 ;
2153
2154Tag:
vlm2728a8d2005-01-23 09:51:44 +00002155 TagTypeValue TagPlicit {
vlmfa67ddc2004-06-03 03:38:44 +00002156 $$ = $1;
vlm2728a8d2005-01-23 09:51:44 +00002157 $$.tag_mode = $2.tag_mode;
vlmfa67ddc2004-06-03 03:38:44 +00002158 }
vlm2728a8d2005-01-23 09:51:44 +00002159 ;
2160
2161TagTypeValue:
2162 '[' TagClass TOK_number ']' {
2163 $$ = $2;
2164 $$.tag_value = $3;
2165 };
2166
2167TagClass:
2168 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2169 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2170 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2171 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2172 ;
2173
2174TagPlicit:
2175 { $$.tag_mode = TM_DEFAULT; }
2176 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2177 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
vlmfa67ddc2004-06-03 03:38:44 +00002178 ;
2179
2180TypeRefName:
2181 TOK_typereference {
2182 checkmem($1);
2183 $$ = $1;
2184 }
vlm9283dbe2004-08-18 04:59:12 +00002185 | TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00002186 checkmem($1);
2187 $$ = $1;
2188 }
2189 ;
2190
vlm9283dbe2004-08-18 04:59:12 +00002191
vlmfa67ddc2004-06-03 03:38:44 +00002192ObjectClassReference:
vlm9283dbe2004-08-18 04:59:12 +00002193 TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00002194 checkmem($1);
2195 $$ = $1;
2196 }
2197 ;
2198
vlm151c0b22004-09-22 16:03:36 +00002199optIdentifier:
2200 { $$ = 0; }
2201 | Identifier {
2202 $$ = $1;
2203 }
vlma5b977d2005-06-06 08:28:58 +00002204 ;
vlm151c0b22004-09-22 16:03:36 +00002205
vlmfa67ddc2004-06-03 03:38:44 +00002206Identifier:
2207 TOK_identifier {
2208 checkmem($1);
2209 $$ = $1;
2210 }
2211 ;
2212
vlmfa67ddc2004-06-03 03:38:44 +00002213%%
2214
2215
2216/*
2217 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2218 */
2219static asn1p_value_t *
2220_convert_bitstring2binary(char *str, int base) {
2221 asn1p_value_t *val;
2222 int slen;
2223 int memlen;
2224 int baselen;
2225 int bits;
2226 uint8_t *binary_vector;
2227 uint8_t *bv_ptr;
2228 uint8_t cur_val;
2229
2230 assert(str);
2231 assert(str[0] == '\'');
2232
2233 switch(base) {
2234 case 'B':
2235 baselen = 1;
2236 break;
2237 case 'H':
2238 baselen = 4;
2239 break;
2240 default:
2241 assert(base == 'B' || base == 'H');
2242 errno = EINVAL;
2243 return NULL;
2244 }
2245
2246 slen = strlen(str);
2247 assert(str[slen - 1] == base);
2248 assert(str[slen - 2] == '\'');
2249
2250 memlen = slen / (8 / baselen); /* Conservative estimate */
2251
2252 bv_ptr = binary_vector = malloc(memlen + 1);
2253 if(bv_ptr == NULL)
2254 /* ENOMEM */
2255 return NULL;
2256
2257 cur_val = 0;
2258 bits = 0;
2259 while(*(++str) != '\'') {
2260 switch(baselen) {
2261 case 1:
2262 switch(*str) {
2263 case '1':
2264 cur_val |= 1 << (7 - (bits % 8));
2265 case '0':
2266 break;
2267 default:
2268 assert(!"_y UNREACH1");
2269 case ' ': case '\r': case '\n':
2270 continue;
2271 }
2272 break;
2273 case 4:
2274 switch(*str) {
2275 case '0': case '1': case '2': case '3': case '4':
2276 case '5': case '6': case '7': case '8': case '9':
2277 cur_val |= (*str - '0') << (4 - (bits % 8));
2278 break;
2279 case 'A': case 'B': case 'C':
2280 case 'D': case 'E': case 'F':
2281 cur_val |= ((*str - 'A') + 10)
2282 << (4 - (bits % 8));
2283 break;
2284 default:
2285 assert(!"_y UNREACH2");
2286 case ' ': case '\r': case '\n':
2287 continue;
2288 }
2289 break;
2290 }
2291
2292 bits += baselen;
2293 if((bits % 8) == 0) {
2294 *bv_ptr++ = cur_val;
2295 cur_val = 0;
2296 }
2297 }
2298
2299 *bv_ptr = cur_val;
2300 assert((bv_ptr - binary_vector) <= memlen);
2301
2302 val = asn1p_value_frombits(binary_vector, bits, 0);
2303 if(val == NULL) {
2304 free(binary_vector);
2305 }
2306
2307 return val;
2308}
2309
vlm5d89c3d2005-08-13 09:07:11 +00002310/*
2311 * For unnamed types (used in old X.208 compliant modules)
2312 * generate some sort of interim names, to not to force human being to fix
2313 * the specification's compliance to modern ASN.1 standards.
2314 */
2315static void
2316_fixup_anonymous_identifier(asn1p_expr_t *expr) {
2317 char *p;
2318 assert(expr->Identifier == 0);
2319
2320 /*
2321 * Try to figure out the type name
2322 * without going too much into details
2323 */
2324 expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type);
2325 if(expr->reference && expr->reference->comp_count > 0)
2326 expr->Identifier = expr->reference->components[0].name;
2327
2328 fprintf(stderr,
2329 "WARNING: Line %d: expected lower-case member identifier, "
2330 "found an unnamed %s.\n"
2331 "WARNING: Obsolete X.208 syntax detected, "
2332 "please give the member a name.\n",
2333 yylineno, expr->Identifier ? expr->Identifier : "type");
2334
2335 if(!expr->Identifier)
2336 expr->Identifier = "unnamed";
2337 expr->Identifier = strdup(expr->Identifier);
2338 assert(expr->Identifier);
2339 /* Make a lowercase identifier from the type name */
2340 for(p = expr->Identifier; *p; p++) {
2341 switch(*p) {
2342 case 'A' ... 'Z': *p += 32; break;
2343 case ' ': *p = '_'; break;
2344 case '-': *p = '_'; break;
2345 }
2346 }
2347 fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". "
2348 "Name clash may occur later.\n",
2349 expr->Identifier);
2350}
2351
vlmfa67ddc2004-06-03 03:38:44 +00002352int
2353yyerror(const char *msg) {
vlm808411d2006-03-14 16:31:37 +00002354 extern char *asn1p_text;
vlmfa67ddc2004-06-03 03:38:44 +00002355 fprintf(stderr,
2356 "ASN.1 grammar parse error "
2357 "near line %d (token \"%s\"): %s\n",
vlm39e5ed72004-09-05 10:40:41 +00002358 yylineno, asn1p_text, msg);
vlmfa67ddc2004-06-03 03:38:44 +00002359 return -1;
2360}
2361