blob: 812b2d839e15131360119ede404b69e8871ad39a [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001%{
2
3#include <stdlib.h>
4#include <stdio.h>
5#include <string.h>
6#include <errno.h>
7#include <assert.h>
8
9#include "asn1parser.h"
10
11#define YYPARSE_PARAM param
Lev Walkin4354b442005-06-07 21:25:42 +000012#define YYPARSE_PARAM_TYPE void **
Lev Walkinf15320b2004-06-03 03:38:44 +000013#define YYERROR_VERBOSE
14
15int yylex(void);
16int yyerror(const char *msg);
Lev Walkin8daab912005-06-07 21:32:16 +000017#ifdef YYBYACC
18int yyparse(void **param); /* byacc does not produce a prototype */
19#endif
Lev Walkinf15320b2004-06-03 03:38:44 +000020void asn1p_lexer_hack_push_opaque_state(void);
21void asn1p_lexer_hack_enable_with_syntax(void);
Lev Walkinf59d0752004-08-18 04:59:12 +000022void asn1p_lexer_hack_push_encoding_control(void);
Lev Walkinf15320b2004-06-03 03:38:44 +000023#define yylineno asn1p_lineno
24extern int asn1p_lineno;
25
Lev Walkin1ed22092005-08-12 10:06:17 +000026/*
Lev Walkinef625402005-09-05 05:17:57 +000027 * Process directives as <ASN1C:RepresentAsPointer>
Lev Walkin4696c742005-08-22 12:23:54 +000028 */
29extern int asn1p_as_pointer;
Lev Walkin4696c742005-08-22 12:23:54 +000030
31/*
Lev Walkin1ed22092005-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;
Lev Walkinf15320b2004-06-03 03:38:44 +000036
Lev Walkin2e9bd5c2005-08-13 09:07:11 +000037static asn1p_value_t *_convert_bitstring2binary(char *str, int base);
38static void _fixup_anonymous_identifier(asn1p_expr_t *expr);
Lev Walkinf15320b2004-06-03 03:38:44 +000039
Lev Walkin1ed22092005-08-12 10:06:17 +000040#define checkmem(ptr) do { \
41 if(!(ptr)) \
42 return yyerror("Memory failure"); \
Lev Walkinf15320b2004-06-03 03:38:44 +000043 } while(0)
44
Lev Walkin2c14a692005-08-12 10:08:45 +000045#define CONSTRAINT_INSERT(root, constr_type, arg1, arg2) do { \
Lev Walkin1ed22092005-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 } \
Lev Walkinf15320b2004-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 */
Lev Walkin1ed22092005-08-12 10:06:17 +000081 struct AssignedIdentifier a_aid; /* Assigned Identifier */
Lev Walkinf15320b2004-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 */
Lev Walkin9c974182004-09-15 11:59:51 +000092 struct asn1p_expr_marker_s a_marker; /* OPTIONAL/DEFAULT */
Lev Walkinf15320b2004-06-03 03:38:44 +000093 enum asn1p_constr_pres_e a_pres; /* PRESENT/ABSENT/OPTIONAL */
Lev Walkin144db9b2004-10-12 23:26:53 +000094 asn1c_integer_t a_int;
Lev Walkinf15320b2004-06-03 03:38:44 +000095 char *tv_str;
96 struct {
97 char *buf;
98 int len;
99 } tv_opaque;
100 struct {
101 char *name;
102 struct asn1p_type_tag_s tag;
103 } tv_nametag;
104};
105
106/*
107 * Token types returned by scanner.
108 */
109%token TOK_PPEQ /* "::=", Pseudo Pascal EQuality */
110%token <tv_opaque> TOK_opaque /* opaque data (driven from .y) */
111%token <tv_str> TOK_bstring
112%token <tv_opaque> TOK_cstring
113%token <tv_str> TOK_hstring
114%token <tv_str> TOK_identifier
115%token <a_int> TOK_number
Lev Walkind9574ae2005-03-24 16:22:35 +0000116%token <a_int> TOK_tuple
117%token <a_int> TOK_quadruple
Lev Walkinf15320b2004-06-03 03:38:44 +0000118%token <a_int> TOK_number_negative
119%token <tv_str> TOK_typereference
Lev Walkinf59d0752004-08-18 04:59:12 +0000120%token <tv_str> TOK_capitalreference /* "CLASS1" */
Lev Walkinf15320b2004-06-03 03:38:44 +0000121%token <tv_str> TOK_typefieldreference /* "&Pork" */
122%token <tv_str> TOK_valuefieldreference /* "&id" */
123
124/*
125 * Token types representing ASN.1 standard keywords.
126 */
127%token TOK_ABSENT
128%token TOK_ABSTRACT_SYNTAX
129%token TOK_ALL
130%token TOK_ANY
131%token TOK_APPLICATION
132%token TOK_AUTOMATIC
133%token TOK_BEGIN
134%token TOK_BIT
135%token TOK_BMPString
136%token TOK_BOOLEAN
137%token TOK_BY
138%token TOK_CHARACTER
139%token TOK_CHOICE
140%token TOK_CLASS
141%token TOK_COMPONENT
142%token TOK_COMPONENTS
143%token TOK_CONSTRAINED
144%token TOK_CONTAINING
145%token TOK_DEFAULT
146%token TOK_DEFINITIONS
147%token TOK_DEFINED
148%token TOK_EMBEDDED
149%token TOK_ENCODED
Lev Walkinf59d0752004-08-18 04:59:12 +0000150%token TOK_ENCODING_CONTROL
Lev Walkinf15320b2004-06-03 03:38:44 +0000151%token TOK_END
152%token TOK_ENUMERATED
153%token TOK_EXPLICIT
154%token TOK_EXPORTS
155%token TOK_EXTENSIBILITY
156%token TOK_EXTERNAL
157%token TOK_FALSE
158%token TOK_FROM
159%token TOK_GeneralizedTime
160%token TOK_GeneralString
161%token TOK_GraphicString
162%token TOK_IA5String
163%token TOK_IDENTIFIER
164%token TOK_IMPLICIT
165%token TOK_IMPLIED
166%token TOK_IMPORTS
167%token TOK_INCLUDES
168%token TOK_INSTANCE
Lev Walkinf59d0752004-08-18 04:59:12 +0000169%token TOK_INSTRUCTIONS
Lev Walkinf15320b2004-06-03 03:38:44 +0000170%token TOK_INTEGER
171%token TOK_ISO646String
172%token TOK_MAX
173%token TOK_MIN
174%token TOK_MINUS_INFINITY
175%token TOK_NULL
176%token TOK_NumericString
177%token TOK_OBJECT
178%token TOK_ObjectDescriptor
179%token TOK_OCTET
180%token TOK_OF
181%token TOK_OPTIONAL
182%token TOK_PATTERN
183%token TOK_PDV
184%token TOK_PLUS_INFINITY
185%token TOK_PRESENT
186%token TOK_PrintableString
187%token TOK_PRIVATE
188%token TOK_REAL
189%token TOK_RELATIVE_OID
190%token TOK_SEQUENCE
191%token TOK_SET
192%token TOK_SIZE
193%token TOK_STRING
194%token TOK_SYNTAX
195%token TOK_T61String
196%token TOK_TAGS
197%token TOK_TeletexString
198%token TOK_TRUE
199%token TOK_TYPE_IDENTIFIER
200%token TOK_UNIQUE
201%token TOK_UNIVERSAL
202%token TOK_UniversalString
203%token TOK_UTCTime
204%token TOK_UTF8String
205%token TOK_VideotexString
206%token TOK_VisibleString
207%token TOK_WITH
208
Lev Walkinf15320b2004-06-03 03:38:44 +0000209%left TOK_EXCEPT
Lev Walkinf59d0752004-08-18 04:59:12 +0000210%left '^' TOK_INTERSECTION
211%left '|' TOK_UNION
Lev Walkinf15320b2004-06-03 03:38:44 +0000212
213/* Misc tags */
214%token TOK_TwoDots /* .. */
215%token TOK_ThreeDots /* ... */
Lev Walkinf15320b2004-06-03 03:38:44 +0000216
217
218/*
219 * Types defined herein.
220 */
221%type <a_grammar> ModuleList
222%type <a_module> ModuleSpecification
223%type <a_module> ModuleSpecificationBody
224%type <a_module> ModuleSpecificationElement
225%type <a_module> optModuleSpecificationBody /* Optional */
226%type <a_module_flags> optModuleSpecificationFlags
227%type <a_module_flags> ModuleSpecificationFlags /* Set of FL */
228%type <a_module_flags> ModuleSpecificationFlag /* Single FL */
229%type <a_module> ImportsDefinition
230%type <a_module> ImportsBundleSet
231%type <a_xports> ImportsBundle
232%type <a_xports> ImportsList
233%type <a_xports> ExportsDefinition
234%type <a_xports> ExportsBody
235%type <a_expr> ImportsElement
236%type <a_expr> ExportsElement
Lev Walkinf15320b2004-06-03 03:38:44 +0000237%type <a_expr> ExtensionAndException
Lev Walkin070a52d2004-08-22 03:19:54 +0000238%type <a_expr> TypeDeclaration
Lev Walkin4696c742005-08-22 12:23:54 +0000239%type <a_expr> TypeDeclarationSet
Lev Walkinf15320b2004-06-03 03:38:44 +0000240%type <a_ref> ComplexTypeReference
241%type <a_ref> ComplexTypeReferenceAmpList
242%type <a_refcomp> ComplexTypeReferenceElement
243%type <a_refcomp> ClassFieldIdentifier
244%type <a_refcomp> ClassFieldName
245%type <a_expr> ClassFieldList
246%type <a_expr> ClassField
247%type <a_expr> ClassDeclaration
Lev Walkin070a52d2004-08-22 03:19:54 +0000248%type <a_expr> Type
Lev Walkinf15320b2004-06-03 03:38:44 +0000249%type <a_expr> DataTypeReference /* Type1 ::= Type2 */
250%type <a_expr> DefinedTypeRef
251%type <a_expr> ValueSetDefinition /* Val INTEGER ::= {1|2} */
252%type <a_expr> ValueDefinition /* val INTEGER ::= 1*/
Lev Walkin9c974182004-09-15 11:59:51 +0000253%type <a_value> Value
Lev Walkinf15320b2004-06-03 03:38:44 +0000254%type <a_value> DefinedValue
255%type <a_value> SignedNumber
Lev Walkin144db9b2004-10-12 23:26:53 +0000256%type <a_expr> optComponentTypeLists
Lev Walkin070a52d2004-08-22 03:19:54 +0000257%type <a_expr> ComponentTypeLists
258%type <a_expr> ComponentType
259%type <a_expr> AlternativeTypeLists
260%type <a_expr> AlternativeType
Lev Walkinf15320b2004-06-03 03:38:44 +0000261//%type <a_expr> optUniverationDefinition
262%type <a_expr> UniverationDefinition
263%type <a_expr> UniverationList
264%type <a_expr> UniverationElement
265%type <tv_str> TypeRefName
266%type <tv_str> ObjectClassReference
Lev Walkinf15320b2004-06-03 03:38:44 +0000267%type <tv_str> Identifier
Lev Walkin83cac2f2004-09-22 16:03:36 +0000268%type <tv_str> optIdentifier
Lev Walkinf15320b2004-06-03 03:38:44 +0000269%type <a_parg> ParameterArgumentName
270%type <a_plist> ParameterArgumentList
271%type <a_expr> ActualParameter
272%type <a_expr> ActualParameterList
Lev Walkin1ed22092005-08-12 10:06:17 +0000273%type <a_aid> AssignedIdentifier /* OID/DefinedValue */
Lev Walkinf15320b2004-06-03 03:38:44 +0000274%type <a_oid> ObjectIdentifier /* OID */
275%type <a_oid> optObjectIdentifier /* Optional OID */
276%type <a_oid> ObjectIdentifierBody
277%type <a_oid_arc> ObjectIdentifierElement
278%type <a_expr> BasicType
279%type <a_type> BasicTypeId
280%type <a_type> BasicTypeId_UniverationCompatible
281%type <a_type> BasicString
282%type <tv_opaque> Opaque
283//%type <tv_opaque> StringValue
Lev Walkinc603f102005-01-23 09:51:44 +0000284%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
285%type <a_tag> TagClass TagTypeValue TagPlicit
Lev Walkinf15320b2004-06-03 03:38:44 +0000286%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
287%type <a_constr> optConstraints
Lev Walkind2ea1de2004-08-20 13:25:29 +0000288%type <a_constr> Constraints
Lev Walkinf59d0752004-08-18 04:59:12 +0000289%type <a_constr> SetOfConstraints
290%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
291%type <a_constr> ElementSetSpec /* 1..2,...,3 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000292%type <a_constr> ConstraintSubtypeElement /* 1..2 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000293%type <a_constr> SimpleTableConstraint
294%type <a_constr> TableConstraint
Lev Walkine596bf02005-03-28 15:01:27 +0000295%type <a_constr> InnerTypeConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +0000296%type <a_constr> WithComponentsList
297%type <a_constr> WithComponentsElement
298%type <a_constr> ComponentRelationConstraint
299%type <a_constr> AtNotationList
300%type <a_ref> AtNotationElement
Lev Walkinff7dd142005-03-20 12:58:00 +0000301%type <a_value> SingleValue
302%type <a_value> ContainedSubtype
Lev Walkinf15320b2004-06-03 03:38:44 +0000303%type <a_ctype> ConstraintSpec
304%type <a_ctype> ConstraintRangeSpec
Lev Walkin1e448d32005-03-24 14:26:38 +0000305%type <a_value> RestrictedCharacterStringValue
Lev Walkinf15320b2004-06-03 03:38:44 +0000306%type <a_wsynt> optWithSyntax
307%type <a_wsynt> WithSyntax
308%type <a_wsynt> WithSyntaxFormat
309%type <a_wchunk> WithSyntaxFormatToken
310%type <a_marker> optMarker Marker
311%type <a_int> optUnique
312%type <a_pres> optPresenceConstraint PresenceConstraint
313%type <tv_str> ComponentIdList
Lev Walkinef625402005-09-05 05:17:57 +0000314%type <a_int> NSTD_IndirectMarker
Lev Walkinf15320b2004-06-03 03:38:44 +0000315
316
317%%
318
319
320ParsedGrammar:
321 ModuleList {
322 *(void **)param = $1;
323 }
324 ;
325
326ModuleList:
327 ModuleSpecification {
328 $$ = asn1p_new();
329 checkmem($$);
330 TQ_ADD(&($$->modules), $1, mod_next);
331 }
332 | ModuleList ModuleSpecification {
333 $$ = $1;
334 TQ_ADD(&($$->modules), $2, mod_next);
335 }
336 ;
337
338/*
339 * ASN module definition.
340 * === EXAMPLE ===
341 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
342 * BEGIN
343 * ...
344 * END
345 * === EOF ===
346 */
347
348ModuleSpecification:
349 TypeRefName optObjectIdentifier TOK_DEFINITIONS
350 optModuleSpecificationFlags
351 TOK_PPEQ TOK_BEGIN
352 optModuleSpecificationBody
353 TOK_END {
354
355 if($7) {
356 $$ = $7;
357 } else {
358 /* There's a chance that a module is just plain empty */
359 $$ = asn1p_module_new();
360 }
361 checkmem($$);
362
Lev Walkin1ed22092005-08-12 10:06:17 +0000363 $$->ModuleName = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000364 $$->module_oid = $2;
365 $$->module_flags = $4;
366 }
367 ;
368
369/*
370 * Object Identifier Definition
371 * { iso member-body(2) 3 }
372 */
373optObjectIdentifier:
374 { $$ = 0; }
375 | ObjectIdentifier { $$ = $1; }
376 ;
377
378ObjectIdentifier:
379 '{' ObjectIdentifierBody '}' {
380 $$ = $2;
381 }
382 | '{' '}' {
383 $$ = 0;
384 }
385 ;
386
387ObjectIdentifierBody:
388 ObjectIdentifierElement {
389 $$ = asn1p_oid_new();
390 asn1p_oid_add_arc($$, &$1);
391 if($1.name)
392 free($1.name);
393 }
394 | ObjectIdentifierBody ObjectIdentifierElement {
395 $$ = $1;
396 asn1p_oid_add_arc($$, &$2);
397 if($2.name)
398 free($2.name);
399 }
400 ;
401
402ObjectIdentifierElement:
403 Identifier { /* iso */
404 $$.name = $1;
405 $$.number = -1;
406 }
407 | Identifier '(' TOK_number ')' { /* iso(1) */
408 $$.name = $1;
409 $$.number = $3;
410 }
411 | TOK_number { /* 1 */
412 $$.name = 0;
413 $$.number = $1;
414 }
415 ;
416
417/*
418 * Optional module flags.
419 */
420optModuleSpecificationFlags:
421 { $$ = MSF_NOFLAGS; }
422 | ModuleSpecificationFlags {
423 $$ = $1;
424 }
425 ;
426
427/*
428 * Module flags.
429 */
430ModuleSpecificationFlags:
431 ModuleSpecificationFlag {
432 $$ = $1;
433 }
434 | ModuleSpecificationFlags ModuleSpecificationFlag {
435 $$ = $1 | $2;
436 }
437 ;
438
439/*
440 * Single module flag.
441 */
442ModuleSpecificationFlag:
443 TOK_EXPLICIT TOK_TAGS {
444 $$ = MSF_EXPLICIT_TAGS;
445 }
446 | TOK_IMPLICIT TOK_TAGS {
447 $$ = MSF_IMPLICIT_TAGS;
448 }
449 | TOK_AUTOMATIC TOK_TAGS {
450 $$ = MSF_AUTOMATIC_TAGS;
451 }
452 | TOK_EXTENSIBILITY TOK_IMPLIED {
453 $$ = MSF_EXTENSIBILITY_IMPLIED;
454 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000455 /* EncodingReferenceDefault */
456 | TOK_capitalreference TOK_INSTRUCTIONS {
457 /* X.680Amd1 specifies TAG and XER */
458 if(strcmp($1, "TAG") == 0) {
459 $$ = MSF_TAG_INSTRUCTIONS;
460 } else if(strcmp($1, "XER") == 0) {
461 $$ = MSF_XER_INSTRUCTIONS;
462 } else {
463 fprintf(stderr,
464 "WARNING: %s INSTRUCTIONS at line %d: "
465 "Unrecognized encoding reference\n",
466 $1, yylineno);
467 $$ = MSF_unk_INSTRUCTIONS;
468 }
469 free($1);
470 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000471 ;
472
473/*
474 * Optional module body.
475 */
476optModuleSpecificationBody:
477 { $$ = 0; }
478 | ModuleSpecificationBody {
Lev Walkinf15320b2004-06-03 03:38:44 +0000479 $$ = $1;
480 }
481 ;
482
483/*
484 * ASN.1 Module body.
485 */
486ModuleSpecificationBody:
487 ModuleSpecificationElement {
488 $$ = $1;
489 }
490 | ModuleSpecificationBody ModuleSpecificationElement {
491 $$ = $1;
492
Lev Walkinf59d0752004-08-18 04:59:12 +0000493 /* Behave well when one of them is skipped. */
494 if(!($1)) {
495 if($2) $$ = $2;
496 break;
497 }
498
Lev Walkinf15320b2004-06-03 03:38:44 +0000499#ifdef MY_IMPORT
500#error MY_IMPORT DEFINED ELSEWHERE!
501#endif
502#define MY_IMPORT(foo,field) do { \
Lev Walkinbc55d232004-08-13 12:31:09 +0000503 while(TQ_FIRST(&($2->foo))) { \
Lev Walkinf15320b2004-06-03 03:38:44 +0000504 TQ_ADD(&($$->foo), \
505 TQ_REMOVE(&($2->foo), field), \
506 field); \
Lev Walkinbc55d232004-08-13 12:31:09 +0000507 } \
508 assert(TQ_FIRST(&($2->foo)) == 0); \
509 } while(0)
Lev Walkinf15320b2004-06-03 03:38:44 +0000510
511 MY_IMPORT(imports, xp_next);
512 MY_IMPORT(exports, xp_next);
513 MY_IMPORT(members, next);
514#undef MY_IMPORT
515
516 }
517 ;
518
519/*
520 * One of the elements of ASN.1 module specification.
521 */
522ModuleSpecificationElement:
523 ImportsDefinition {
524 $$ = $1;
525 }
526 | ExportsDefinition {
527 $$ = asn1p_module_new();
528 checkmem($$);
529 if($1) {
530 TQ_ADD(&($$->exports), $1, xp_next);
531 } else {
532 /* "EXPORTS ALL;" ? */
533 }
534 }
535 | DataTypeReference {
536 $$ = asn1p_module_new();
537 checkmem($$);
538 assert($1->expr_type != A1TC_INVALID);
539 assert($1->meta_type != AMT_INVALID);
540 TQ_ADD(&($$->members), $1, next);
541 }
542 | ValueDefinition {
543 $$ = asn1p_module_new();
544 checkmem($$);
545 assert($1->expr_type != A1TC_INVALID);
546 assert($1->meta_type != AMT_INVALID);
547 TQ_ADD(&($$->members), $1, next);
548 }
549 /*
550 * Value set definition
551 * === EXAMPLE ===
552 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
553 * === EOF ===
554 */
555 | ValueSetDefinition {
556 $$ = asn1p_module_new();
557 checkmem($$);
558 assert($1->expr_type != A1TC_INVALID);
559 assert($1->meta_type != AMT_INVALID);
560 TQ_ADD(&($$->members), $1, next);
561 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000562 | TOK_ENCODING_CONTROL TOK_capitalreference
563 { asn1p_lexer_hack_push_encoding_control(); }
564 {
565 fprintf(stderr,
566 "WARNING: ENCODING-CONTROL %s "
567 "specification at line %d ignored\n",
568 $2, yylineno);
569 free($2);
570 $$ = 0;
571 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000572
573 /*
574 * Erroneous attemps
575 */
576 | BasicString {
577 return yyerror(
578 "Attempt to redefine a standard basic type, "
579 "use -ftypesXY to switch back "
580 "to older version of ASN.1 standard");
581 }
582 ;
583
584/*
585 * === EXAMPLE ===
586 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
587 * === EOF ===
588 */
589ImportsDefinition:
590 TOK_IMPORTS ImportsBundleSet ';' {
Lev Walkin1ed22092005-08-12 10:06:17 +0000591 if(!saved_aid && 0)
592 return yyerror("Unterminated IMPORTS FROM, "
593 "expected semicolon ';'");
594 saved_aid = 0;
Lev Walkinf15320b2004-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
Lev Walkin1ed22092005-08-12 10:06:17 +0000617AssignedIdentifier:
618 { memset(&$$, 0, sizeof($$)); }
619 | ObjectIdentifier { $$.oid = $1; };
620 /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
621
Lev Walkinf15320b2004-06-03 03:38:44 +0000622ImportsBundle:
Lev Walkin1ed22092005-08-12 10:06:17 +0000623 ImportsList TOK_FROM TypeRefName AssignedIdentifier {
Lev Walkinf15320b2004-06-03 03:38:44 +0000624 $$ = $1;
Lev Walkin1ed22092005-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);
Lev Walkinf15320b2004-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 }
Lev Walkin144db9b2004-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 }
Lev Walkinf15320b2004-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 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000699 | TypeRefName '{' '}' {
700 $$ = asn1p_expr_new(yylineno);
701 checkmem($$);
702 $$->Identifier = $1;
703 $$->expr_type = A1TC_EXPORTVAR;
704 }
Lev Walkinf15320b2004-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:
Lev Walkin8ea99482005-03-31 21:48:13 +0000715 TypeRefName DefinedTypeRef TOK_PPEQ
716 '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Lev Walkinf15320b2004-06-03 03:38:44 +0000717 $$ = $2;
718 assert($$->Identifier == 0);
719 $$->Identifier = $1;
720 $$->meta_type = AMT_VALUESET;
Lev Walkin8ea99482005-03-31 21:48:13 +0000721 // take care of ValueSet body
Lev Walkinf15320b2004-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
Lev Walkinf15320b2004-06-03 03:38:44 +0000741/*
742 * Data Type Reference.
743 * === EXAMPLE ===
744 * Type3 ::= CHOICE { a Type1, b Type 2 }
745 * === EOF ===
746 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000747DataTypeReference:
748 /*
749 * Optionally tagged type definition.
750 */
751 TypeRefName TOK_PPEQ optTag TOK_TYPE_IDENTIFIER {
752 $$ = asn1p_expr_new(yylineno);
753 checkmem($$);
754 $$->Identifier = $1;
755 $$->tag = $3;
756 $$->expr_type = A1TC_TYPEID;
757 $$->meta_type = AMT_TYPE;
758 }
Lev Walkinaf120f72004-09-14 02:36:39 +0000759 | TypeRefName TOK_PPEQ Type {
760 $$ = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000761 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000762 assert($$->expr_type);
763 assert($$->meta_type);
764 }
765 | TypeRefName TOK_PPEQ ClassDeclaration {
766 $$ = $3;
767 $$->Identifier = $1;
768 assert($$->expr_type == A1TC_CLASSDEF);
769 assert($$->meta_type == AMT_OBJECT);
770 }
771 /*
772 * Parametrized <Type> declaration:
773 * === EXAMPLE ===
774 * SIGNED { ToBeSigned } ::= SEQUENCE {
775 * toBeSigned ToBeSigned,
776 * algorithm AlgorithmIdentifier,
777 * signature BIT STRING
778 * }
779 * === EOF ===
780 */
Lev Walkin070a52d2004-08-22 03:19:54 +0000781 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000782 $$ = $6;
783 assert($$->Identifier == 0);
784 $$->Identifier = $1;
785 $$->params = $3;
786 $$->meta_type = AMT_PARAMTYPE;
787 }
788 ;
789
790ParameterArgumentList:
791 ParameterArgumentName {
792 int ret;
793 $$ = asn1p_paramlist_new(yylineno);
794 checkmem($$);
795 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
796 checkmem(ret == 0);
797 if($1.governor) asn1p_ref_free($1.governor);
798 if($1.argument) free($1.argument);
799 }
800 | ParameterArgumentList ',' ParameterArgumentName {
801 int ret;
802 $$ = $1;
803 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
804 checkmem(ret == 0);
805 if($3.governor) asn1p_ref_free($3.governor);
806 if($3.argument) free($3.argument);
807 }
808 ;
809
810ParameterArgumentName:
811 TypeRefName {
812 $$.governor = NULL;
813 $$.argument = $1;
814 }
815 | TypeRefName ':' Identifier {
816 int ret;
817 $$.governor = asn1p_ref_new(yylineno);
818 ret = asn1p_ref_add_component($$.governor, $1, 0);
819 checkmem(ret == 0);
820 $$.argument = $3;
821 }
Lev Walkinc8092cb2005-02-18 16:34:21 +0000822 | TypeRefName ':' TypeRefName {
823 int ret;
824 $$.governor = asn1p_ref_new(yylineno);
825 ret = asn1p_ref_add_component($$.governor, $1, 0);
826 checkmem(ret == 0);
827 $$.argument = $3;
828 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000829 | BasicTypeId ':' Identifier {
830 int ret;
831 $$.governor = asn1p_ref_new(yylineno);
832 ret = asn1p_ref_add_component($$.governor,
833 ASN_EXPR_TYPE2STR($1), 1);
834 checkmem(ret == 0);
835 $$.argument = $3;
836 }
837 ;
838
839ActualParameterList:
840 ActualParameter {
841 $$ = asn1p_expr_new(yylineno);
842 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000843 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000844 }
845 | ActualParameterList ',' ActualParameter {
846 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000847 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000848 }
849 ;
850
851ActualParameter:
Lev Walkin070a52d2004-08-22 03:19:54 +0000852 Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000853 $$ = $1;
854 }
855 | Identifier {
856 $$ = asn1p_expr_new(yylineno);
857 checkmem($$);
858 $$->Identifier = $1;
859 $$->expr_type = A1TC_REFERENCE;
860 $$->meta_type = AMT_VALUE;
861 }
862 ;
863
864/*
Lev Walkinc8092cb2005-02-18 16:34:21 +0000865 | '{' ActualParameter '}' {
866 $$ = asn1p_expr_new(yylineno);
867 checkmem($$);
868 asn1p_expr_add($$, $2);
869 $$->expr_type = A1TC_PARAMETRIZED;
870 $$->meta_type = AMT_TYPE;
871 }
872 ;
873*/
874
875/*
Lev Walkinf15320b2004-06-03 03:38:44 +0000876 * A collection of constructed data type members.
877 */
Lev Walkin144db9b2004-10-12 23:26:53 +0000878optComponentTypeLists:
879 { $$ = asn1p_expr_new(yylineno); }
880 | ComponentTypeLists { $$ = $1; };
881
Lev Walkin070a52d2004-08-22 03:19:54 +0000882ComponentTypeLists:
883 ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +0000884 $$ = asn1p_expr_new(yylineno);
885 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000886 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000887 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000888 | ComponentTypeLists ',' ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +0000889 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000890 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000891 }
892 ;
893
Lev Walkin070a52d2004-08-22 03:19:54 +0000894ComponentType:
Lev Walkinaf120f72004-09-14 02:36:39 +0000895 Identifier Type optMarker {
Lev Walkin070a52d2004-08-22 03:19:54 +0000896 $$ = $2;
897 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +0000898 $$->Identifier = $1;
Lev Walkinef625402005-09-05 05:17:57 +0000899 $3.flags |= $$->marker.flags;
Lev Walkin070a52d2004-08-22 03:19:54 +0000900 $$->marker = $3;
901 }
Lev Walkinef625402005-09-05 05:17:57 +0000902 | Type optMarker {
903 $$ = $1;
904 $2.flags |= $$->marker.flags;
905 $$->marker = $2;
906 _fixup_anonymous_identifier($$);
907 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000908 | TOK_COMPONENTS TOK_OF Type {
909 $$ = asn1p_expr_new(yylineno);
910 checkmem($$);
911 $$->meta_type = $3->meta_type;
912 $$->expr_type = A1TC_COMPONENTS_OF;
Lev Walkin1004aa92004-09-08 00:28:11 +0000913 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +0000914 }
915 | ExtensionAndException {
916 $$ = $1;
917 }
918 ;
919
920AlternativeTypeLists:
921 AlternativeType {
922 $$ = asn1p_expr_new(yylineno);
923 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000924 asn1p_expr_add($$, $1);
Lev Walkin070a52d2004-08-22 03:19:54 +0000925 }
926 | AlternativeTypeLists ',' AlternativeType {
927 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000928 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +0000929 }
930 ;
931
932AlternativeType:
Lev Walkinaf120f72004-09-14 02:36:39 +0000933 Identifier Type {
Lev Walkin070a52d2004-08-22 03:19:54 +0000934 $$ = $2;
935 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +0000936 $$->Identifier = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +0000937 }
938 | ExtensionAndException {
939 $$ = $1;
940 }
Lev Walkin2e9bd5c2005-08-13 09:07:11 +0000941 | Type {
942 $$ = $1;
943 _fixup_anonymous_identifier($$);
944 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000945 ;
946
Lev Walkinf15320b2004-06-03 03:38:44 +0000947ClassDeclaration:
948 TOK_CLASS '{' ClassFieldList '}' optWithSyntax {
949 $$ = $3;
950 checkmem($$);
951 $$->with_syntax = $5;
952 assert($$->expr_type == A1TC_CLASSDEF);
953 assert($$->meta_type == AMT_OBJECT);
954 }
955 ;
956
957optUnique:
958 { $$ = 0; }
959 | TOK_UNIQUE { $$ = 1; }
960 ;
961
962ClassFieldList:
963 ClassField {
964 $$ = asn1p_expr_new(yylineno);
965 checkmem($$);
966 $$->expr_type = A1TC_CLASSDEF;
967 $$->meta_type = AMT_OBJECT;
Lev Walkin1004aa92004-09-08 00:28:11 +0000968 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000969 }
970 | ClassFieldList ',' ClassField {
971 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000972 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000973 }
974 ;
975
976ClassField:
977 ClassFieldIdentifier optMarker {
978 $$ = asn1p_expr_new(yylineno);
979 checkmem($$);
980 $$->Identifier = $1.name;
981 $$->expr_type = A1TC_CLASSFIELD;
982 $$->meta_type = AMT_OBJECTFIELD;
983 $$->marker = $2;
984 }
Lev Walkinb7c45ca2004-11-24 17:43:29 +0000985 | ClassFieldIdentifier Type optUnique optMarker {
Lev Walkinf15320b2004-06-03 03:38:44 +0000986 $$ = $2;
987 $$->Identifier = $1.name;
Lev Walkinb7c45ca2004-11-24 17:43:29 +0000988 $$->marker = $4;
989 $$->unique = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000990 }
Lev Walkinb7c45ca2004-11-24 17:43:29 +0000991 | ClassFieldIdentifier ClassFieldIdentifier optUnique optMarker {
Lev Walkinf15320b2004-06-03 03:38:44 +0000992 int ret;
993 $$ = asn1p_expr_new(yylineno);
994 checkmem($$);
995 $$->Identifier = $1.name;
996 $$->reference = asn1p_ref_new(yylineno);
997 checkmem($$->reference);
998 ret = asn1p_ref_add_component($$->reference,
999 $2.name, $2.lex_type);
1000 checkmem(ret == 0);
1001 $$->expr_type = A1TC_CLASSFIELD;
1002 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkinb7c45ca2004-11-24 17:43:29 +00001003 $$->marker = $4;
1004 $$->unique = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +00001005 }
1006 ;
1007
1008optWithSyntax:
1009 { $$ = 0; }
1010 | WithSyntax {
1011 $$ = $1;
1012 }
1013 ;
1014
1015WithSyntax:
1016 TOK_WITH TOK_SYNTAX '{'
1017 { asn1p_lexer_hack_enable_with_syntax(); }
1018 WithSyntaxFormat
1019 '}' {
1020 $$ = $5;
1021 }
1022 ;
1023
1024WithSyntaxFormat:
1025 WithSyntaxFormatToken {
1026 $$ = asn1p_wsyntx_new();
1027 TQ_ADD(&($$->chunks), $1, next);
1028 }
1029 | WithSyntaxFormat WithSyntaxFormatToken {
1030 $$ = $1;
1031 TQ_ADD(&($$->chunks), $2, next);
1032 }
1033 ;
1034
1035WithSyntaxFormatToken:
1036 TOK_opaque {
1037 $$ = asn1p_wsyntx_chunk_frombuf($1.buf, $1.len, 0);
1038 }
1039 | ClassFieldIdentifier {
1040 asn1p_ref_t *ref;
1041 int ret;
1042 ref = asn1p_ref_new(yylineno);
1043 checkmem(ref);
1044 ret = asn1p_ref_add_component(ref, $1.name, $1.lex_type);
1045 checkmem(ret == 0);
1046 $$ = asn1p_wsyntx_chunk_fromref(ref, 0);
1047 }
1048 ;
1049
Lev Walkinf15320b2004-06-03 03:38:44 +00001050ExtensionAndException:
1051 TOK_ThreeDots {
Lev Walkinceb20e72004-09-05 10:40:41 +00001052 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001053 checkmem($$);
1054 $$->Identifier = strdup("...");
1055 checkmem($$->Identifier);
1056 $$->expr_type = A1TC_EXTENSIBLE;
1057 $$->meta_type = AMT_TYPE;
1058 }
1059 | TOK_ThreeDots '!' DefinedValue {
Lev Walkinceb20e72004-09-05 10:40:41 +00001060 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001061 checkmem($$);
1062 $$->Identifier = strdup("...");
1063 checkmem($$->Identifier);
1064 $$->value = $3;
1065 $$->expr_type = A1TC_EXTENSIBLE;
1066 $$->meta_type = AMT_TYPE;
1067 }
1068 | TOK_ThreeDots '!' SignedNumber {
Lev Walkinceb20e72004-09-05 10:40:41 +00001069 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001070 checkmem($$);
1071 $$->Identifier = strdup("...");
1072 $$->value = $3;
1073 checkmem($$->Identifier);
1074 $$->expr_type = A1TC_EXTENSIBLE;
1075 $$->meta_type = AMT_TYPE;
1076 }
1077 ;
1078
Lev Walkin070a52d2004-08-22 03:19:54 +00001079Type:
Lev Walkinaf120f72004-09-14 02:36:39 +00001080 optTag TypeDeclaration optConstraints {
1081 $$ = $2;
1082 $$->tag = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001083 /*
1084 * Outer constraint for SEQUENCE OF and SET OF applies
1085 * to the inner type.
1086 */
1087 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1088 || $$->expr_type == ASN_CONSTR_SET_OF) {
1089 assert(!TQ_FIRST(&($$->members))->constraints);
Lev Walkinaf120f72004-09-14 02:36:39 +00001090 TQ_FIRST(&($$->members))->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001091 } else {
1092 if($$->constraints) {
1093 assert(!$2);
1094 } else {
Lev Walkinaf120f72004-09-14 02:36:39 +00001095 $$->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001096 }
1097 }
Lev Walkinef625402005-09-05 05:17:57 +00001098 }
1099 ;
1100
1101NSTD_IndirectMarker:
1102 {
1103 $$ = asn1p_as_pointer ? EM_INDIRECT : 0;
1104 asn1p_as_pointer = 0;
Lev Walkin070a52d2004-08-22 03:19:54 +00001105 }
1106 ;
1107
1108TypeDeclaration:
Lev Walkinef625402005-09-05 05:17:57 +00001109 NSTD_IndirectMarker TypeDeclarationSet {
Lev Walkin4696c742005-08-22 12:23:54 +00001110 $$ = $2;
Lev Walkinef625402005-09-05 05:17:57 +00001111 $$->marker.flags |= $1;
1112
1113 if(($$->marker.flags & EM_INDIRECT)
1114 && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
1115 fprintf(stderr,
1116 "INFO: Directive <ASN1C:RepresentAsPointer> "
1117 "applied to %s at line %d\n",
1118 ASN_EXPR_TYPE2STR($$->expr_type)
1119 ? ASN_EXPR_TYPE2STR($$->expr_type)
1120 : "member",
1121 $$->_lineno
1122 );
1123 }
Lev Walkin4696c742005-08-22 12:23:54 +00001124 }
Lev Walkinef625402005-09-05 05:17:57 +00001125 ;
Lev Walkin4696c742005-08-22 12:23:54 +00001126
1127TypeDeclarationSet:
Lev Walkinf15320b2004-06-03 03:38:44 +00001128 BasicType {
1129 $$ = $1;
1130 }
Lev Walkinef625402005-09-05 05:17:57 +00001131 | TOK_CHOICE '{' AlternativeTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001132 $$ = $3;
1133 assert($$->expr_type == A1TC_INVALID);
1134 $$->expr_type = ASN_CONSTR_CHOICE;
1135 $$->meta_type = AMT_TYPE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001136 }
Lev Walkinef625402005-09-05 05:17:57 +00001137 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001138 $$ = $3;
1139 assert($$->expr_type == A1TC_INVALID);
1140 $$->expr_type = ASN_CONSTR_SEQUENCE;
1141 $$->meta_type = AMT_TYPE;
1142 }
Lev Walkinef625402005-09-05 05:17:57 +00001143 | TOK_SET '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001144 $$ = $3;
1145 assert($$->expr_type == A1TC_INVALID);
1146 $$->expr_type = ASN_CONSTR_SET;
1147 $$->meta_type = AMT_TYPE;
1148 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001149 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkinceb20e72004-09-05 10:40:41 +00001150 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001151 checkmem($$);
1152 $$->constraints = $2;
1153 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1154 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001155 $6->Identifier = $4;
1156 $6->tag = $5;
1157 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001158 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001159 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkinceb20e72004-09-05 10:40:41 +00001160 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001161 checkmem($$);
1162 $$->constraints = $2;
1163 $$->expr_type = ASN_CONSTR_SET_OF;
1164 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001165 $6->Identifier = $4;
1166 $6->tag = $5;
1167 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001168 }
1169 | TOK_ANY {
Lev Walkinceb20e72004-09-05 10:40:41 +00001170 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001171 checkmem($$);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001172 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001173 $$->meta_type = AMT_TYPE;
1174 }
1175 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1176 int ret;
Lev Walkinceb20e72004-09-05 10:40:41 +00001177 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001178 checkmem($$);
1179 $$->reference = asn1p_ref_new(yylineno);
1180 ret = asn1p_ref_add_component($$->reference,
1181 $4, RLT_lowercase);
1182 checkmem(ret == 0);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001183 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001184 $$->meta_type = AMT_TYPE;
1185 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001186 /*
1187 * A parametrized assignment.
1188 */
1189 | TypeRefName '{' ActualParameterList '}' {
1190 int ret;
1191 $$ = $3;
1192 assert($$->expr_type == 0);
1193 assert($$->meta_type == 0);
1194 assert($$->reference == 0);
1195 $$->reference = asn1p_ref_new(yylineno);
1196 checkmem($$->reference);
1197 ret = asn1p_ref_add_component($$->reference, $1, RLT_UNKNOWN);
1198 checkmem(ret == 0);
1199 free($1);
1200 $$->expr_type = A1TC_PARAMETRIZED;
1201 $$->meta_type = AMT_TYPE;
1202 }
1203 /*
1204 * A DefinedType reference.
1205 * "CLASS1.&id.&id2"
1206 * or
1207 * "Module.Type"
1208 * or
1209 * "Module.identifier"
1210 * or
1211 * "Type"
1212 */
1213 | ComplexTypeReference {
1214 $$ = asn1p_expr_new(yylineno);
1215 checkmem($$);
1216 $$->reference = $1;
1217 $$->expr_type = A1TC_REFERENCE;
1218 $$->meta_type = AMT_TYPEREF;
1219 }
1220 | TOK_INSTANCE TOK_OF ComplexTypeReference {
1221 $$ = asn1p_expr_new(yylineno);
1222 checkmem($$);
1223 $$->reference = $3;
1224 $$->expr_type = A1TC_INSTANCE;
1225 $$->meta_type = AMT_TYPE;
1226 }
1227 ;
1228
1229/*
1230 * A type name consisting of several components.
1231 * === EXAMPLE ===
1232 * === EOF ===
1233 */
1234ComplexTypeReference:
1235 TOK_typereference {
1236 int ret;
1237 $$ = asn1p_ref_new(yylineno);
1238 checkmem($$);
1239 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1240 checkmem(ret == 0);
1241 free($1);
1242 }
1243 | TOK_typereference '.' TypeRefName {
1244 int ret;
1245 $$ = asn1p_ref_new(yylineno);
1246 checkmem($$);
1247 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1248 checkmem(ret == 0);
1249 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1250 checkmem(ret == 0);
1251 free($1);
1252 }
Lev Walkin9c974182004-09-15 11:59:51 +00001253 | ObjectClassReference '.' TypeRefName {
1254 int ret;
1255 $$ = asn1p_ref_new(yylineno);
1256 checkmem($$);
1257 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1258 checkmem(ret == 0);
1259 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1260 checkmem(ret == 0);
1261 free($1);
1262 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001263 | TOK_typereference '.' Identifier {
1264 int ret;
1265 $$ = asn1p_ref_new(yylineno);
1266 checkmem($$);
1267 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1268 checkmem(ret == 0);
1269 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1270 checkmem(ret == 0);
1271 free($1);
1272 }
1273 | ObjectClassReference {
1274 int ret;
1275 $$ = asn1p_ref_new(yylineno);
1276 checkmem($$);
1277 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1278 free($1);
1279 checkmem(ret == 0);
1280 }
1281 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1282 int ret;
1283 $$ = $3;
1284 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1285 free($1);
1286 checkmem(ret == 0);
1287 /*
1288 * Move the last element infront.
1289 */
1290 {
1291 struct asn1p_ref_component_s tmp_comp;
1292 tmp_comp = $$->components[$$->comp_count-1];
1293 memmove(&$$->components[1],
1294 &$$->components[0],
1295 sizeof($$->components[0])
1296 * ($$->comp_count - 1));
1297 $$->components[0] = tmp_comp;
1298 }
1299 }
1300 ;
1301
1302ComplexTypeReferenceAmpList:
1303 ComplexTypeReferenceElement {
1304 int ret;
1305 $$ = asn1p_ref_new(yylineno);
1306 checkmem($$);
1307 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1308 free($1.name);
1309 checkmem(ret == 0);
1310 }
1311 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1312 int ret;
1313 $$ = $1;
1314 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1315 free($3.name);
1316 checkmem(ret == 0);
1317 }
1318 ;
1319
1320ComplexTypeReferenceElement: ClassFieldName;
1321ClassFieldIdentifier: ClassFieldName;
1322
1323ClassFieldName:
1324 /* "&Type1" */
1325 TOK_typefieldreference {
1326 $$.lex_type = RLT_AmpUppercase;
1327 $$.name = $1;
1328 }
1329 /* "&id" */
1330 | TOK_valuefieldreference {
1331 $$.lex_type = RLT_Amplowercase;
1332 $$.name = $1;
1333 }
1334 ;
1335
1336
1337/*
1338 * === EXAMPLE ===
1339 * value INTEGER ::= 1
1340 * === EOF ===
1341 */
1342ValueDefinition:
Lev Walkin9c974182004-09-15 11:59:51 +00001343 Identifier DefinedTypeRef TOK_PPEQ Value {
Lev Walkinf15320b2004-06-03 03:38:44 +00001344 $$ = $2;
1345 assert($$->Identifier == NULL);
1346 $$->Identifier = $1;
1347 $$->meta_type = AMT_VALUE;
1348 $$->value = $4;
1349 }
1350 ;
1351
Lev Walkin9c974182004-09-15 11:59:51 +00001352Value:
1353 Identifier ':' Value {
1354 $$ = asn1p_value_fromint(0);
1355 checkmem($$);
1356 $$->type = ATV_CHOICE_IDENTIFIER;
1357 $$->value.choice_identifier.identifier = $1;
1358 $$->value.choice_identifier.value = $3;
1359 }
Lev Walkincbad2512005-03-24 16:27:02 +00001360 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Lev Walkinf15320b2004-06-03 03:38:44 +00001361 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1362 checkmem($$);
1363 $$->type = ATV_UNPARSED;
1364 }
Lev Walkin9c974182004-09-15 11:59:51 +00001365 | TOK_NULL {
1366 $$ = asn1p_value_fromint(0);
1367 checkmem($$);
1368 $$->type = ATV_NULL;
1369 }
1370 | TOK_FALSE {
1371 $$ = asn1p_value_fromint(0);
1372 checkmem($$);
1373 $$->type = ATV_FALSE;
1374 }
1375 | TOK_TRUE {
1376 $$ = asn1p_value_fromint(0);
1377 checkmem($$);
1378 $$->type = ATV_TRUE;
1379 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001380 | TOK_bstring {
1381 $$ = _convert_bitstring2binary($1, 'B');
1382 checkmem($$);
1383 }
1384 | TOK_hstring {
1385 $$ = _convert_bitstring2binary($1, 'H');
1386 checkmem($$);
1387 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001388 | RestrictedCharacterStringValue {
1389 $$ = $$;
Lev Walkinf15320b2004-06-03 03:38:44 +00001390 }
1391 | SignedNumber {
1392 $$ = $1;
1393 }
1394 | DefinedValue {
1395 $$ = $1;
1396 }
1397 ;
1398
1399DefinedValue:
1400 Identifier {
1401 asn1p_ref_t *ref;
1402 int ret;
1403 ref = asn1p_ref_new(yylineno);
1404 checkmem(ref);
1405 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1406 checkmem(ret == 0);
1407 $$ = asn1p_value_fromref(ref, 0);
1408 checkmem($$);
1409 free($1);
1410 }
1411 | TypeRefName '.' Identifier {
1412 asn1p_ref_t *ref;
1413 int ret;
1414 ref = asn1p_ref_new(yylineno);
1415 checkmem(ref);
1416 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1417 checkmem(ret == 0);
1418 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1419 checkmem(ret == 0);
1420 $$ = asn1p_value_fromref(ref, 0);
1421 checkmem($$);
1422 free($1);
1423 free($3);
1424 }
1425 ;
1426
Lev Walkin1e448d32005-03-24 14:26:38 +00001427
1428RestrictedCharacterStringValue:
1429 TOK_cstring {
1430 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1431 checkmem($$);
1432 }
Lev Walkind9574ae2005-03-24 16:22:35 +00001433 | TOK_tuple {
1434 $$ = asn1p_value_fromint($1);
1435 checkmem($$);
1436 $$->type = ATV_TUPLE;
1437 }
1438 | TOK_quadruple {
1439 $$ = asn1p_value_fromint($1);
1440 checkmem($$);
1441 $$->type = ATV_QUADRUPLE;
1442 }
1443 /*
Lev Walkin1e448d32005-03-24 14:26:38 +00001444 | '{' TOK_number ',' TOK_number '}' {
1445 asn1c_integer_t v = ($2 << 4) + $4;
1446 if($2 > 7) return yyerror("X.680:2003, #37.14 "
1447 "mandates 0..7 range for Tuple's TableColumn");
1448 if($4 > 15) return yyerror("X.680:2003, #37.14 "
1449 "mandates 0..15 range for Tuple's TableRow");
1450 $$ = asn1p_value_fromint(v);
1451 checkmem($$);
1452 $$->type = ATV_TUPLE;
1453 }
1454 | '{' TOK_number ',' TOK_number ',' TOK_number ',' TOK_number '}' {
1455 asn1c_integer_t v = ($2 << 24) | ($4 << 16) | ($6 << 8) | $8;
1456 if($2 > 127) return yyerror("X.680:2003, #37.12 "
1457 "mandates 0..127 range for Quadruple's Group");
1458 if($4 > 255) return yyerror("X.680:2003, #37.12 "
1459 "mandates 0..255 range for Quadruple's Plane");
1460 if($6 > 255) return yyerror("X.680:2003, #37.12 "
1461 "mandates 0..255 range for Quadruple's Row");
1462 if($8 > 255) return yyerror("X.680:2003, #37.12 "
1463 "mandates 0..255 range for Quadruple's Cell");
1464 $$ = asn1p_value_fromint(v);
1465 checkmem($$);
1466 $$->type = ATV_QUADRUPLE;
1467 }
Lev Walkind9574ae2005-03-24 16:22:35 +00001468 */
Lev Walkin1e448d32005-03-24 14:26:38 +00001469 ;
1470
Lev Walkinf15320b2004-06-03 03:38:44 +00001471Opaque:
1472 TOK_opaque {
Lev Walkin1893ddf2005-03-20 14:28:32 +00001473 $$.len = $1.len + 1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001474 $$.buf = malloc($$.len + 1);
1475 checkmem($$.buf);
1476 $$.buf[0] = '{';
Lev Walkin1893ddf2005-03-20 14:28:32 +00001477 memcpy($$.buf + 1, $1.buf, $1.len);
Lev Walkinf15320b2004-06-03 03:38:44 +00001478 $$.buf[$$.len] = '\0';
1479 free($1.buf);
1480 }
1481 | Opaque TOK_opaque {
1482 int newsize = $1.len + $2.len;
1483 char *p = malloc(newsize + 1);
1484 checkmem(p);
1485 memcpy(p , $1.buf, $1.len);
1486 memcpy(p + $1.len, $2.buf, $2.len);
1487 p[newsize] = '\0';
1488 free($1.buf);
1489 free($2.buf);
1490 $$.buf = p;
1491 $$.len = newsize;
1492 }
1493 ;
1494
1495BasicTypeId:
1496 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1497 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1498 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1499 | BasicTypeId_UniverationCompatible { $$ = $1; }
1500 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1501 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1502 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1503 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1504 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1505 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1506 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1507 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
Lev Walkinc7d939d2005-03-20 11:12:40 +00001508 | BasicString { $$ = $1; }
Lev Walkinf15320b2004-06-03 03:38:44 +00001509 ;
1510
1511/*
1512 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1513 */
1514BasicTypeId_UniverationCompatible:
1515 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1516 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1517 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1518 ;
1519
1520BasicType:
1521 BasicTypeId {
Lev Walkinceb20e72004-09-05 10:40:41 +00001522 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001523 checkmem($$);
1524 $$->expr_type = $1;
1525 $$->meta_type = AMT_TYPE;
1526 }
1527 | BasicTypeId_UniverationCompatible UniverationDefinition {
1528 if($2) {
1529 $$ = $2;
1530 } else {
Lev Walkinceb20e72004-09-05 10:40:41 +00001531 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001532 checkmem($$);
1533 }
1534 $$->expr_type = $1;
1535 $$->meta_type = AMT_TYPE;
1536 }
1537 ;
1538
1539BasicString:
1540 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1541 | TOK_GeneralString {
1542 $$ = ASN_STRING_GeneralString;
Lev Walkin9c974182004-09-15 11:59:51 +00001543 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001544 }
1545 | TOK_GraphicString {
1546 $$ = ASN_STRING_GraphicString;
Lev Walkin9c974182004-09-15 11:59:51 +00001547 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001548 }
1549 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1550 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1551 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1552 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1553 | TOK_T61String {
1554 $$ = ASN_STRING_T61String;
Lev Walkin9c974182004-09-15 11:59:51 +00001555 fprintf(stderr, "WARNING: T61String is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001556 }
1557 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1558 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1559 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1560 | TOK_VideotexString {
1561 $$ = ASN_STRING_VideotexString;
Lev Walkin9c974182004-09-15 11:59:51 +00001562 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001563 }
1564 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1565 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1566 ;
1567
Lev Walkind2ea1de2004-08-20 13:25:29 +00001568
Lev Walkinf15320b2004-06-03 03:38:44 +00001569/*
1570 * Data type constraints.
1571 */
Lev Walkinf15320b2004-06-03 03:38:44 +00001572Union: '|' | TOK_UNION;
1573Intersection: '^' | TOK_INTERSECTION;
1574Except: TOK_EXCEPT;
1575
Lev Walkinf59d0752004-08-18 04:59:12 +00001576optConstraints:
1577 { $$ = 0; }
Lev Walkind2ea1de2004-08-20 13:25:29 +00001578 | Constraints {
1579 $$ = $1;
1580 }
1581 ;
1582
1583Constraints:
1584 SetOfConstraints {
Lev Walkin2c14a692005-08-12 10:08:45 +00001585 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
Lev Walkinf59d0752004-08-18 04:59:12 +00001586 }
1587 | TOK_SIZE '(' ElementSetSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001588 /*
1589 * This is a special case, for compatibility purposes.
Lev Walkinf59d0752004-08-18 04:59:12 +00001590 * It goes without parentheses.
Lev Walkinf15320b2004-06-03 03:38:44 +00001591 */
Lev Walkin2c14a692005-08-12 10:08:45 +00001592 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001593 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001594 ;
1595
Lev Walkinf59d0752004-08-18 04:59:12 +00001596SetOfConstraints:
1597 '(' ElementSetSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001598 $$ = $2;
1599 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001600 | SetOfConstraints '(' ElementSetSpecs ')' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001601 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
Lev Walkinf59d0752004-08-18 04:59:12 +00001602 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001603 ;
1604
Lev Walkinf59d0752004-08-18 04:59:12 +00001605ElementSetSpecs:
1606 ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001607 $$ = $1;
1608 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001609 | ElementSetSpec ',' TOK_ThreeDots {
Lev Walkinf15320b2004-06-03 03:38:44 +00001610 asn1p_constraint_t *ct;
1611 ct = asn1p_constraint_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001612 ct->type = ACT_EL_EXT;
Lev Walkin2c14a692005-08-12 10:08:45 +00001613 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00001614 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001615 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001616 asn1p_constraint_t *ct;
1617 ct = asn1p_constraint_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001618 ct->type = ACT_EL_EXT;
Lev Walkin2c14a692005-08-12 10:08:45 +00001619 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinb4fcdd22004-08-13 12:35:09 +00001620 ct = $$;
Lev Walkin2c14a692005-08-12 10:08:45 +00001621 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
Lev Walkinf15320b2004-06-03 03:38:44 +00001622 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001623 ;
1624
Lev Walkinf59d0752004-08-18 04:59:12 +00001625ElementSetSpec:
1626 ConstraintSubtypeElement {
1627 $$ = $1;
1628 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001629 | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001630 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
Lev Walkin1e448d32005-03-24 14:26:38 +00001631 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001632 | ElementSetSpec Union ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001633 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001634 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001635 | ElementSetSpec Intersection ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001636 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001637 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001638 | ConstraintSubtypeElement Except ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001639 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001640 }
1641 ;
1642
1643ConstraintSubtypeElement:
Lev Walkinf59d0752004-08-18 04:59:12 +00001644 ConstraintSpec '(' ElementSetSpecs ')' {
1645 int ret;
1646 $$ = asn1p_constraint_new(yylineno);
1647 checkmem($$);
1648 $$->type = $1;
1649 ret = asn1p_constraint_insert($$, $3);
1650 checkmem(ret == 0);
1651 }
1652 | '(' ElementSetSpecs ')' {
1653 int ret;
1654 $$ = asn1p_constraint_new(yylineno);
1655 checkmem($$);
1656 $$->type = ACT_CA_SET;
1657 ret = asn1p_constraint_insert($$, $2);
1658 checkmem(ret == 0);
1659 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001660 | SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001661 $$ = asn1p_constraint_new(yylineno);
1662 checkmem($$);
1663 $$->type = ACT_EL_VALUE;
1664 $$->value = $1;
1665 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001666 | ContainedSubtype {
1667 $$ = asn1p_constraint_new(yylineno);
1668 checkmem($$);
1669 $$->type = ACT_EL_TYPE;
1670 $$->containedSubtype = $1;
1671 }
1672 | SingleValue ConstraintRangeSpec SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001673 $$ = asn1p_constraint_new(yylineno);
1674 checkmem($$);
1675 $$->type = $2;
1676 $$->range_start = $1;
1677 $$->range_stop = $3;
1678 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001679 | TOK_MIN ConstraintRangeSpec SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001680 $$ = asn1p_constraint_new(yylineno);
1681 checkmem($$);
Lev Walkinf59d0752004-08-18 04:59:12 +00001682 $$->type = $2;
1683 $$->range_start = asn1p_value_fromint(-123);
1684 $$->range_stop = $3;
1685 $$->range_start->type = ATV_MIN;
1686 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001687 | SingleValue ConstraintRangeSpec TOK_MAX {
Lev Walkinf59d0752004-08-18 04:59:12 +00001688 $$ = asn1p_constraint_new(yylineno);
1689 checkmem($$);
1690 $$->type = $2;
1691 $$->range_start = $1;
1692 $$->range_stop = asn1p_value_fromint(321);
1693 $$->range_stop->type = ATV_MAX;
1694 }
1695 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1696 $$ = asn1p_constraint_new(yylineno);
1697 checkmem($$);
1698 $$->type = $2;
1699 $$->range_start = asn1p_value_fromint(-123);
1700 $$->range_stop = asn1p_value_fromint(321);
1701 $$->range_start->type = ATV_MIN;
1702 $$->range_stop->type = ATV_MAX;
Lev Walkinf15320b2004-06-03 03:38:44 +00001703 }
1704 | TableConstraint {
1705 $$ = $1;
1706 }
Lev Walkine596bf02005-03-28 15:01:27 +00001707 | InnerTypeConstraint {
Lev Walkinf15320b2004-06-03 03:38:44 +00001708 $$ = $1;
1709 }
Lev Walkin1893ddf2005-03-20 14:28:32 +00001710 | TOK_CONSTRAINED TOK_BY '{'
1711 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1712 $$ = asn1p_constraint_new(yylineno);
1713 checkmem($$);
1714 $$->type = ACT_CT_CTDBY;
1715 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
1716 checkmem($$->value);
1717 $$->value->type = ATV_UNPARSED;
1718 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001719 ;
1720
1721ConstraintRangeSpec:
1722 TOK_TwoDots { $$ = ACT_EL_RANGE; }
1723 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
1724 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
1725 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
1726 ;
1727
1728ConstraintSpec:
1729 TOK_SIZE {
1730 $$ = ACT_CT_SIZE;
1731 }
1732 | TOK_FROM {
1733 $$ = ACT_CT_FROM;
1734 }
1735 ;
1736
Lev Walkinff7dd142005-03-20 12:58:00 +00001737SingleValue:
Lev Walkinc8092cb2005-02-18 16:34:21 +00001738 TOK_FALSE {
1739 $$ = asn1p_value_fromint(0);
1740 checkmem($$);
1741 $$->type = ATV_FALSE;
1742 }
1743 | TOK_TRUE {
1744 $$ = asn1p_value_fromint(1);
1745 checkmem($$);
1746 $$->type = ATV_TRUE;
1747 }
1748 | SignedNumber {
Lev Walkinf15320b2004-06-03 03:38:44 +00001749 $$ = $1;
1750 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001751 | RestrictedCharacterStringValue {
1752 $$ = $1;
Lev Walkinc8092cb2005-02-18 16:34:21 +00001753 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001754 | Identifier {
1755 asn1p_ref_t *ref;
1756 int ret;
1757 ref = asn1p_ref_new(yylineno);
1758 checkmem(ref);
1759 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1760 checkmem(ret == 0);
1761 $$ = asn1p_value_fromref(ref, 0);
1762 checkmem($$);
1763 free($1);
1764 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001765 ;
1766
1767ContainedSubtype:
1768 TypeRefName {
Lev Walkinc8092cb2005-02-18 16:34:21 +00001769 asn1p_ref_t *ref;
1770 int ret;
1771 ref = asn1p_ref_new(yylineno);
1772 checkmem(ref);
1773 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1774 checkmem(ret == 0);
1775 $$ = asn1p_value_fromref(ref, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001776 checkmem($$);
Lev Walkinc8092cb2005-02-18 16:34:21 +00001777 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001778 }
1779 ;
1780
Lev Walkine596bf02005-03-28 15:01:27 +00001781InnerTypeConstraint:
1782 TOK_WITH TOK_COMPONENT SetOfConstraints {
Lev Walkin2c14a692005-08-12 10:08:45 +00001783 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
Lev Walkine596bf02005-03-28 15:01:27 +00001784 }
1785 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001786 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001787 }
1788 ;
1789
1790WithComponentsList:
1791 WithComponentsElement {
1792 $$ = $1;
1793 }
1794 | WithComponentsList ',' WithComponentsElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001795 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001796 }
1797 ;
1798
1799WithComponentsElement:
1800 TOK_ThreeDots {
1801 $$ = asn1p_constraint_new(yylineno);
1802 checkmem($$);
1803 $$->type = ACT_EL_EXT;
Lev Walkine596bf02005-03-28 15:01:27 +00001804 $$->value = asn1p_value_frombuf("...", 3, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001805 }
1806 | Identifier optConstraints optPresenceConstraint {
1807 $$ = asn1p_constraint_new(yylineno);
1808 checkmem($$);
1809 $$->type = ACT_EL_VALUE;
1810 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1811 $$->presence = $3;
Lev Walkine596bf02005-03-28 15:01:27 +00001812 if($2) asn1p_constraint_insert($$, $2);
Lev Walkinf15320b2004-06-03 03:38:44 +00001813 }
1814 ;
1815
1816/*
1817 * presence constraint for WithComponents
1818 */
1819optPresenceConstraint:
1820 { $$ = ACPRES_DEFAULT; }
1821 | PresenceConstraint { $$ = $1; }
1822 ;
1823
1824PresenceConstraint:
1825 TOK_PRESENT {
1826 $$ = ACPRES_PRESENT;
1827 }
1828 | TOK_ABSENT {
1829 $$ = ACPRES_ABSENT;
1830 }
1831 | TOK_OPTIONAL {
1832 $$ = ACPRES_OPTIONAL;
1833 }
1834 ;
1835
1836TableConstraint:
1837 SimpleTableConstraint {
1838 $$ = $1;
1839 }
1840 | ComponentRelationConstraint {
1841 $$ = $1;
1842 }
1843 ;
1844
1845/*
1846 * "{ExtensionSet}"
1847 */
1848SimpleTableConstraint:
1849 '{' TypeRefName '}' {
1850 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
1851 asn1p_constraint_t *ct;
1852 int ret;
1853 ret = asn1p_ref_add_component(ref, $2, 0);
1854 checkmem(ret == 0);
1855 ct = asn1p_constraint_new(yylineno);
1856 checkmem($$);
1857 ct->type = ACT_EL_VALUE;
1858 ct->value = asn1p_value_fromref(ref, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00001859 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001860 }
1861 ;
1862
1863ComponentRelationConstraint:
1864 SimpleTableConstraint '{' AtNotationList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001865 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001866 }
1867 ;
1868
1869AtNotationList:
1870 AtNotationElement {
1871 $$ = asn1p_constraint_new(yylineno);
1872 checkmem($$);
1873 $$->type = ACT_EL_VALUE;
1874 $$->value = asn1p_value_fromref($1, 0);
1875 }
1876 | AtNotationList ',' AtNotationElement {
1877 asn1p_constraint_t *ct;
1878 ct = asn1p_constraint_new(yylineno);
1879 checkmem(ct);
1880 ct->type = ACT_EL_VALUE;
1881 ct->value = asn1p_value_fromref($3, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00001882 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00001883 }
1884 ;
1885
1886/*
1887 * @blah
1888 */
1889AtNotationElement:
1890 '@' ComponentIdList {
1891 char *p = malloc(strlen($2) + 2);
1892 int ret;
1893 *p = '@';
1894 strcpy(p + 1, $2);
1895 $$ = asn1p_ref_new(yylineno);
1896 ret = asn1p_ref_add_component($$, p, 0);
1897 checkmem(ret == 0);
1898 free(p);
1899 free($2);
1900 }
1901 | '@' '.' ComponentIdList {
1902 char *p = malloc(strlen($3) + 3);
1903 int ret;
1904 p[0] = '@';
1905 p[1] = '.';
1906 strcpy(p + 2, $3);
1907 $$ = asn1p_ref_new(yylineno);
1908 ret = asn1p_ref_add_component($$, p, 0);
1909 checkmem(ret == 0);
1910 free(p);
1911 free($3);
1912 }
1913 ;
1914
1915/* identifier "." ... */
1916ComponentIdList:
1917 Identifier {
1918 $$ = $1;
1919 }
1920 | ComponentIdList '.' Identifier {
1921 int l1 = strlen($1);
1922 int l3 = strlen($3);
1923 $$ = malloc(l1 + 1 + l3 + 1);
1924 memcpy($$, $1, l1);
1925 $$[l1] = '.';
1926 memcpy($$ + l1 + 1, $3, l3);
1927 $$[l1 + 1 + l3] = '\0';
1928 }
1929 ;
1930
1931
1932
1933/*
1934 * MARKERS
1935 */
1936
1937optMarker:
Lev Walkin9c974182004-09-15 11:59:51 +00001938 {
1939 $$.flags = EM_NOMARK;
1940 $$.default_value = 0;
1941 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001942 | Marker { $$ = $1; }
1943 ;
1944
1945Marker:
1946 TOK_OPTIONAL {
Lev Walkin9c974182004-09-15 11:59:51 +00001947 $$.flags = EM_OPTIONAL;
1948 $$.default_value = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +00001949 }
Lev Walkin9c974182004-09-15 11:59:51 +00001950 | TOK_DEFAULT Value {
1951 $$.flags = EM_DEFAULT;
1952 $$.default_value = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00001953 }
1954 ;
1955
1956/*
1957 * Universal enumeration definition to use in INTEGER and ENUMERATED.
1958 * === EXAMPLE ===
1959 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
1960 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
1961 * === EOF ===
1962 */
1963/*
1964optUniverationDefinition:
1965 { $$ = 0; }
1966 | UniverationDefinition {
1967 $$ = $1;
1968 }
1969 ;
1970*/
1971
1972UniverationDefinition:
1973 '{' '}' {
Lev Walkinceb20e72004-09-05 10:40:41 +00001974 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001975 checkmem($$);
1976 }
1977 | '{' UniverationList '}' {
1978 $$ = $2;
1979 }
1980 ;
1981
1982UniverationList:
1983 UniverationElement {
Lev Walkinceb20e72004-09-05 10:40:41 +00001984 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001985 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00001986 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001987 }
1988 | UniverationList ',' UniverationElement {
1989 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001990 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001991 }
1992 ;
1993
1994UniverationElement:
1995 Identifier {
Lev Walkinceb20e72004-09-05 10:40:41 +00001996 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001997 checkmem($$);
1998 $$->expr_type = A1TC_UNIVERVAL;
1999 $$->meta_type = AMT_VALUE;
2000 $$->Identifier = $1;
2001 }
2002 | Identifier '(' SignedNumber ')' {
Lev Walkinceb20e72004-09-05 10:40:41 +00002003 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00002004 checkmem($$);
2005 $$->expr_type = A1TC_UNIVERVAL;
2006 $$->meta_type = AMT_VALUE;
2007 $$->Identifier = $1;
2008 $$->value = $3;
2009 }
2010 | Identifier '(' DefinedValue ')' {
Lev Walkinceb20e72004-09-05 10:40:41 +00002011 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00002012 checkmem($$);
2013 $$->expr_type = A1TC_UNIVERVAL;
2014 $$->meta_type = AMT_VALUE;
2015 $$->Identifier = $1;
2016 $$->value = $3;
2017 }
2018 | SignedNumber {
Lev Walkinceb20e72004-09-05 10:40:41 +00002019 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00002020 checkmem($$);
2021 $$->expr_type = A1TC_UNIVERVAL;
2022 $$->meta_type = AMT_VALUE;
2023 $$->value = $1;
2024 }
2025 | TOK_ThreeDots {
Lev Walkinceb20e72004-09-05 10:40:41 +00002026 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00002027 checkmem($$);
2028 $$->Identifier = strdup("...");
2029 checkmem($$->Identifier);
2030 $$->expr_type = A1TC_EXTENSIBLE;
2031 $$->meta_type = AMT_VALUE;
2032 }
2033 ;
2034
2035SignedNumber:
2036 TOK_number {
2037 $$ = asn1p_value_fromint($1);
2038 checkmem($$);
2039 }
2040 | TOK_number_negative {
2041 $$ = asn1p_value_fromint($1);
2042 checkmem($$);
2043 }
2044 ;
2045
2046/*
2047 * SEQUENCE definition.
2048 * === EXAMPLE ===
2049 * Struct1 ::= SEQUENCE {
2050 * memb1 Struct2,
2051 * memb2 SEQUENCE OF {
2052 * memb2-1 Struct 3
2053 * }
2054 * }
2055 * === EOF ===
2056 */
2057
2058
2059
2060/*
2061 * SET definition.
2062 * === EXAMPLE ===
2063 * Person ::= SET {
2064 * name [0] PrintableString (SIZE(1..20)),
2065 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2066 * }
2067 * === EOF ===
2068 */
2069
2070optTag:
2071 { memset(&$$, 0, sizeof($$)); }
2072 | Tag { $$ = $1; }
2073 ;
2074
2075Tag:
Lev Walkinc603f102005-01-23 09:51:44 +00002076 TagTypeValue TagPlicit {
Lev Walkinf15320b2004-06-03 03:38:44 +00002077 $$ = $1;
Lev Walkinc603f102005-01-23 09:51:44 +00002078 $$.tag_mode = $2.tag_mode;
Lev Walkinf15320b2004-06-03 03:38:44 +00002079 }
Lev Walkinc603f102005-01-23 09:51:44 +00002080 ;
2081
2082TagTypeValue:
2083 '[' TagClass TOK_number ']' {
2084 $$ = $2;
2085 $$.tag_value = $3;
2086 };
2087
2088TagClass:
2089 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2090 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2091 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2092 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2093 ;
2094
2095TagPlicit:
2096 { $$.tag_mode = TM_DEFAULT; }
2097 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2098 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
Lev Walkinf15320b2004-06-03 03:38:44 +00002099 ;
2100
2101TypeRefName:
2102 TOK_typereference {
2103 checkmem($1);
2104 $$ = $1;
2105 }
Lev Walkinf59d0752004-08-18 04:59:12 +00002106 | TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002107 checkmem($1);
2108 $$ = $1;
2109 }
2110 ;
2111
Lev Walkinf59d0752004-08-18 04:59:12 +00002112
Lev Walkinf15320b2004-06-03 03:38:44 +00002113ObjectClassReference:
Lev Walkinf59d0752004-08-18 04:59:12 +00002114 TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002115 checkmem($1);
2116 $$ = $1;
2117 }
2118 ;
2119
Lev Walkin83cac2f2004-09-22 16:03:36 +00002120optIdentifier:
2121 { $$ = 0; }
2122 | Identifier {
2123 $$ = $1;
2124 }
Lev Walkin8f294e02005-06-06 08:28:58 +00002125 ;
Lev Walkin83cac2f2004-09-22 16:03:36 +00002126
Lev Walkinf15320b2004-06-03 03:38:44 +00002127Identifier:
2128 TOK_identifier {
2129 checkmem($1);
2130 $$ = $1;
2131 }
2132 ;
2133
Lev Walkinf15320b2004-06-03 03:38:44 +00002134%%
2135
2136
2137/*
2138 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2139 */
2140static asn1p_value_t *
2141_convert_bitstring2binary(char *str, int base) {
2142 asn1p_value_t *val;
2143 int slen;
2144 int memlen;
2145 int baselen;
2146 int bits;
2147 uint8_t *binary_vector;
2148 uint8_t *bv_ptr;
2149 uint8_t cur_val;
2150
2151 assert(str);
2152 assert(str[0] == '\'');
2153
2154 switch(base) {
2155 case 'B':
2156 baselen = 1;
2157 break;
2158 case 'H':
2159 baselen = 4;
2160 break;
2161 default:
2162 assert(base == 'B' || base == 'H');
2163 errno = EINVAL;
2164 return NULL;
2165 }
2166
2167 slen = strlen(str);
2168 assert(str[slen - 1] == base);
2169 assert(str[slen - 2] == '\'');
2170
2171 memlen = slen / (8 / baselen); /* Conservative estimate */
2172
2173 bv_ptr = binary_vector = malloc(memlen + 1);
2174 if(bv_ptr == NULL)
2175 /* ENOMEM */
2176 return NULL;
2177
2178 cur_val = 0;
2179 bits = 0;
2180 while(*(++str) != '\'') {
2181 switch(baselen) {
2182 case 1:
2183 switch(*str) {
2184 case '1':
2185 cur_val |= 1 << (7 - (bits % 8));
2186 case '0':
2187 break;
2188 default:
2189 assert(!"_y UNREACH1");
2190 case ' ': case '\r': case '\n':
2191 continue;
2192 }
2193 break;
2194 case 4:
2195 switch(*str) {
2196 case '0': case '1': case '2': case '3': case '4':
2197 case '5': case '6': case '7': case '8': case '9':
2198 cur_val |= (*str - '0') << (4 - (bits % 8));
2199 break;
2200 case 'A': case 'B': case 'C':
2201 case 'D': case 'E': case 'F':
2202 cur_val |= ((*str - 'A') + 10)
2203 << (4 - (bits % 8));
2204 break;
2205 default:
2206 assert(!"_y UNREACH2");
2207 case ' ': case '\r': case '\n':
2208 continue;
2209 }
2210 break;
2211 }
2212
2213 bits += baselen;
2214 if((bits % 8) == 0) {
2215 *bv_ptr++ = cur_val;
2216 cur_val = 0;
2217 }
2218 }
2219
2220 *bv_ptr = cur_val;
2221 assert((bv_ptr - binary_vector) <= memlen);
2222
2223 val = asn1p_value_frombits(binary_vector, bits, 0);
2224 if(val == NULL) {
2225 free(binary_vector);
2226 }
2227
2228 return val;
2229}
2230
Lev Walkin2e9bd5c2005-08-13 09:07:11 +00002231/*
2232 * For unnamed types (used in old X.208 compliant modules)
2233 * generate some sort of interim names, to not to force human being to fix
2234 * the specification's compliance to modern ASN.1 standards.
2235 */
2236static void
2237_fixup_anonymous_identifier(asn1p_expr_t *expr) {
2238 char *p;
2239 assert(expr->Identifier == 0);
2240
2241 /*
2242 * Try to figure out the type name
2243 * without going too much into details
2244 */
2245 expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type);
2246 if(expr->reference && expr->reference->comp_count > 0)
2247 expr->Identifier = expr->reference->components[0].name;
2248
2249 fprintf(stderr,
2250 "WARNING: Line %d: expected lower-case member identifier, "
2251 "found an unnamed %s.\n"
2252 "WARNING: Obsolete X.208 syntax detected, "
2253 "please give the member a name.\n",
2254 yylineno, expr->Identifier ? expr->Identifier : "type");
2255
2256 if(!expr->Identifier)
2257 expr->Identifier = "unnamed";
2258 expr->Identifier = strdup(expr->Identifier);
2259 assert(expr->Identifier);
2260 /* Make a lowercase identifier from the type name */
2261 for(p = expr->Identifier; *p; p++) {
2262 switch(*p) {
2263 case 'A' ... 'Z': *p += 32; break;
2264 case ' ': *p = '_'; break;
2265 case '-': *p = '_'; break;
2266 }
2267 }
2268 fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". "
2269 "Name clash may occur later.\n",
2270 expr->Identifier);
2271}
2272
Lev Walkinf15320b2004-06-03 03:38:44 +00002273extern char *asn1p_text;
2274
2275int
2276yyerror(const char *msg) {
2277 fprintf(stderr,
2278 "ASN.1 grammar parse error "
2279 "near line %d (token \"%s\"): %s\n",
Lev Walkinceb20e72004-09-05 10:40:41 +00002280 yylineno, asn1p_text, msg);
Lev Walkinf15320b2004-06-03 03:38:44 +00002281 return -1;
2282}
2283
2284