blob: b070f2afded4117cc42a240bd8ff14dfc0fd4395 [file] [log] [blame]
vlmfa67ddc2004-06-03 03:38:44 +00001%{
2
3#include <stdlib.h>
4#include <stdio.h>
5#include <string.h>
6#include <errno.h>
7#include <assert.h>
8
9#include "asn1parser.h"
10
11#define YYPARSE_PARAM param
vlmfbf6bf62005-06-07 21:25:42 +000012#define YYPARSE_PARAM_TYPE void **
vlmfa67ddc2004-06-03 03:38:44 +000013#define YYERROR_VERBOSE
14
15int yylex(void);
16int yyerror(const char *msg);
vlmd2f87602005-06-07 21:32:16 +000017#ifdef YYBYACC
18int yyparse(void **param); /* byacc does not produce a prototype */
19#endif
vlmfa67ddc2004-06-03 03:38:44 +000020void asn1p_lexer_hack_push_opaque_state(void);
21void asn1p_lexer_hack_enable_with_syntax(void);
vlm9283dbe2004-08-18 04:59:12 +000022void asn1p_lexer_hack_push_encoding_control(void);
vlmfa67ddc2004-06-03 03:38:44 +000023#define yylineno asn1p_lineno
24extern int asn1p_lineno;
25
vlm04a08da2005-08-12 10:06:17 +000026/*
vlm177a5b62005-09-05 05:17:57 +000027 * Process directives as <ASN1C:RepresentAsPointer>
vlm066dc102005-08-22 12:23:54 +000028 */
29extern int asn1p_as_pointer;
vlm066dc102005-08-22 12:23:54 +000030
31/*
vlm04a08da2005-08-12 10:06:17 +000032 * This temporary variable is used to solve the shortcomings of 1-lookahead
33 * parser.
34 */
35static struct AssignedIdentifier *saved_aid;
vlmfa67ddc2004-06-03 03:38:44 +000036
vlm5d89c3d2005-08-13 09:07:11 +000037static asn1p_value_t *_convert_bitstring2binary(char *str, int base);
38static void _fixup_anonymous_identifier(asn1p_expr_t *expr);
vlmfa67ddc2004-06-03 03:38:44 +000039
vlm04a08da2005-08-12 10:06:17 +000040#define checkmem(ptr) do { \
41 if(!(ptr)) \
42 return yyerror("Memory failure"); \
vlmfa67ddc2004-06-03 03:38:44 +000043 } while(0)
44
vlm9fe7c922005-08-12 10:08:45 +000045#define CONSTRAINT_INSERT(root, constr_type, arg1, arg2) do { \
vlm04a08da2005-08-12 10:06:17 +000046 if(arg1->type != constr_type) { \
47 int __ret; \
48 root = asn1p_constraint_new(yylineno); \
49 checkmem(root); \
50 root->type = constr_type; \
51 __ret = asn1p_constraint_insert(root, \
52 arg1); \
53 checkmem(__ret == 0); \
54 } else { \
55 root = arg1; \
56 } \
57 if(arg2) { \
58 int __ret \
59 = asn1p_constraint_insert(root, arg2); \
60 checkmem(__ret == 0); \
61 } \
vlmfa67ddc2004-06-03 03:38:44 +000062 } while(0)
63
64%}
65
66
67/*
68 * Token value definition.
69 * a_*: ASN-specific types.
70 * tv_*: Locally meaningful types.
71 */
72%union {
73 asn1p_t *a_grammar;
74 asn1p_module_flags_e a_module_flags;
75 asn1p_module_t *a_module;
76 asn1p_expr_type_e a_type; /* ASN.1 Type */
77 asn1p_expr_t *a_expr; /* Constructed collection */
78 asn1p_constraint_t *a_constr; /* Constraint */
79 enum asn1p_constraint_type_e a_ctype;/* Constraint type */
80 asn1p_xports_t *a_xports; /* IMports/EXports */
vlm04a08da2005-08-12 10:06:17 +000081 struct AssignedIdentifier a_aid; /* Assigned Identifier */
vlmfa67ddc2004-06-03 03:38:44 +000082 asn1p_oid_t *a_oid; /* Object Identifier */
83 asn1p_oid_arc_t a_oid_arc; /* Single OID's arc */
84 struct asn1p_type_tag_s a_tag; /* A tag */
85 asn1p_ref_t *a_ref; /* Reference to custom type */
86 asn1p_wsyntx_t *a_wsynt; /* WITH SYNTAX contents */
87 asn1p_wsyntx_chunk_t *a_wchunk; /* WITH SYNTAX chunk */
88 struct asn1p_ref_component_s a_refcomp; /* Component of a reference */
89 asn1p_value_t *a_value; /* Number, DefinedValue, etc */
90 struct asn1p_param_s a_parg; /* A parameter argument */
91 asn1p_paramlist_t *a_plist; /* A pargs list */
vlmc94e28f2004-09-15 11:59:51 +000092 struct asn1p_expr_marker_s a_marker; /* OPTIONAL/DEFAULT */
vlmfa67ddc2004-06-03 03:38:44 +000093 enum asn1p_constr_pres_e a_pres; /* PRESENT/ABSENT/OPTIONAL */
vlm0aa86902004-10-12 23:26:53 +000094 asn1c_integer_t a_int;
vlmfa67ddc2004-06-03 03:38:44 +000095 char *tv_str;
96 struct {
97 char *buf;
98 int len;
99 } tv_opaque;
100 struct {
101 char *name;
102 struct asn1p_type_tag_s tag;
103 } tv_nametag;
104};
105
106/*
107 * Token types returned by scanner.
108 */
109%token TOK_PPEQ /* "::=", Pseudo Pascal EQuality */
110%token <tv_opaque> TOK_opaque /* opaque data (driven from .y) */
111%token <tv_str> TOK_bstring
112%token <tv_opaque> TOK_cstring
113%token <tv_str> TOK_hstring
114%token <tv_str> TOK_identifier
115%token <a_int> TOK_number
vlm2c8c44d2005-03-24 16:22:35 +0000116%token <a_int> TOK_tuple
117%token <a_int> TOK_quadruple
vlmfa67ddc2004-06-03 03:38:44 +0000118%token <a_int> TOK_number_negative
119%token <tv_str> TOK_typereference
vlm9283dbe2004-08-18 04:59:12 +0000120%token <tv_str> TOK_capitalreference /* "CLASS1" */
vlmfa67ddc2004-06-03 03:38:44 +0000121%token <tv_str> TOK_typefieldreference /* "&Pork" */
122%token <tv_str> TOK_valuefieldreference /* "&id" */
123
124/*
125 * Token types representing ASN.1 standard keywords.
126 */
127%token TOK_ABSENT
128%token TOK_ABSTRACT_SYNTAX
129%token TOK_ALL
130%token TOK_ANY
131%token TOK_APPLICATION
132%token TOK_AUTOMATIC
133%token TOK_BEGIN
134%token TOK_BIT
135%token TOK_BMPString
136%token TOK_BOOLEAN
137%token TOK_BY
138%token TOK_CHARACTER
139%token TOK_CHOICE
140%token TOK_CLASS
141%token TOK_COMPONENT
142%token TOK_COMPONENTS
143%token TOK_CONSTRAINED
144%token TOK_CONTAINING
145%token TOK_DEFAULT
146%token TOK_DEFINITIONS
147%token TOK_DEFINED
148%token TOK_EMBEDDED
149%token TOK_ENCODED
vlm9283dbe2004-08-18 04:59:12 +0000150%token TOK_ENCODING_CONTROL
vlmfa67ddc2004-06-03 03:38:44 +0000151%token TOK_END
152%token TOK_ENUMERATED
153%token TOK_EXPLICIT
154%token TOK_EXPORTS
155%token TOK_EXTENSIBILITY
156%token TOK_EXTERNAL
157%token TOK_FALSE
158%token TOK_FROM
159%token TOK_GeneralizedTime
160%token TOK_GeneralString
161%token TOK_GraphicString
162%token TOK_IA5String
163%token TOK_IDENTIFIER
164%token TOK_IMPLICIT
165%token TOK_IMPLIED
166%token TOK_IMPORTS
167%token TOK_INCLUDES
168%token TOK_INSTANCE
vlm9283dbe2004-08-18 04:59:12 +0000169%token TOK_INSTRUCTIONS
vlmfa67ddc2004-06-03 03:38:44 +0000170%token TOK_INTEGER
171%token TOK_ISO646String
172%token TOK_MAX
173%token TOK_MIN
174%token TOK_MINUS_INFINITY
175%token TOK_NULL
176%token TOK_NumericString
177%token TOK_OBJECT
178%token TOK_ObjectDescriptor
179%token TOK_OCTET
180%token TOK_OF
181%token TOK_OPTIONAL
182%token TOK_PATTERN
183%token TOK_PDV
184%token TOK_PLUS_INFINITY
185%token TOK_PRESENT
186%token TOK_PrintableString
187%token TOK_PRIVATE
188%token TOK_REAL
189%token TOK_RELATIVE_OID
190%token TOK_SEQUENCE
191%token TOK_SET
192%token TOK_SIZE
193%token TOK_STRING
194%token TOK_SYNTAX
195%token TOK_T61String
196%token TOK_TAGS
197%token TOK_TeletexString
198%token TOK_TRUE
199%token TOK_TYPE_IDENTIFIER
200%token TOK_UNIQUE
201%token TOK_UNIVERSAL
202%token TOK_UniversalString
203%token TOK_UTCTime
204%token TOK_UTF8String
205%token TOK_VideotexString
206%token TOK_VisibleString
207%token TOK_WITH
208
vlmfa67ddc2004-06-03 03:38:44 +0000209%left TOK_EXCEPT
vlm9283dbe2004-08-18 04:59:12 +0000210%left '^' TOK_INTERSECTION
211%left '|' TOK_UNION
vlmfa67ddc2004-06-03 03:38:44 +0000212
213/* Misc tags */
214%token TOK_TwoDots /* .. */
215%token TOK_ThreeDots /* ... */
vlmfa67ddc2004-06-03 03:38:44 +0000216
217
218/*
219 * Types defined herein.
220 */
221%type <a_grammar> ModuleList
222%type <a_module> ModuleSpecification
223%type <a_module> ModuleSpecificationBody
224%type <a_module> ModuleSpecificationElement
225%type <a_module> optModuleSpecificationBody /* Optional */
226%type <a_module_flags> optModuleSpecificationFlags
227%type <a_module_flags> ModuleSpecificationFlags /* Set of FL */
228%type <a_module_flags> ModuleSpecificationFlag /* Single FL */
229%type <a_module> ImportsDefinition
230%type <a_module> ImportsBundleSet
231%type <a_xports> ImportsBundle
232%type <a_xports> ImportsList
233%type <a_xports> ExportsDefinition
234%type <a_xports> ExportsBody
235%type <a_expr> ImportsElement
236%type <a_expr> ExportsElement
vlmfa67ddc2004-06-03 03:38:44 +0000237%type <a_expr> ExtensionAndException
vlmec8f6812004-08-22 03:19:54 +0000238%type <a_expr> TypeDeclaration
vlm066dc102005-08-22 12:23:54 +0000239%type <a_expr> TypeDeclarationSet
vlmfa67ddc2004-06-03 03:38:44 +0000240%type <a_ref> ComplexTypeReference
241%type <a_ref> ComplexTypeReferenceAmpList
242%type <a_refcomp> ComplexTypeReferenceElement
243%type <a_refcomp> ClassFieldIdentifier
244%type <a_refcomp> ClassFieldName
245%type <a_expr> ClassFieldList
246%type <a_expr> ClassField
247%type <a_expr> ClassDeclaration
vlmec8f6812004-08-22 03:19:54 +0000248%type <a_expr> Type
vlmfa67ddc2004-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*/
vlmc94e28f2004-09-15 11:59:51 +0000253%type <a_value> Value
vlmfa67ddc2004-06-03 03:38:44 +0000254%type <a_value> DefinedValue
255%type <a_value> SignedNumber
vlm0aa86902004-10-12 23:26:53 +0000256%type <a_expr> optComponentTypeLists
vlmec8f6812004-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
vlmfa67ddc2004-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
vlmfa67ddc2004-06-03 03:38:44 +0000267%type <tv_str> Identifier
vlm151c0b22004-09-22 16:03:36 +0000268%type <tv_str> optIdentifier
vlmfa67ddc2004-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
vlm04a08da2005-08-12 10:06:17 +0000273%type <a_aid> AssignedIdentifier /* OID/DefinedValue */
vlmfa67ddc2004-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
vlm2728a8d2005-01-23 09:51:44 +0000284%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
285%type <a_tag> TagClass TagTypeValue TagPlicit
vlmfa67ddc2004-06-03 03:38:44 +0000286%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
287%type <a_constr> optConstraints
vlm5f0128b2004-08-20 13:25:29 +0000288%type <a_constr> Constraints
vlm9283dbe2004-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 */
vlmfa67ddc2004-06-03 03:38:44 +0000292%type <a_constr> ConstraintSubtypeElement /* 1..2 */
vlmfa67ddc2004-06-03 03:38:44 +0000293%type <a_constr> SimpleTableConstraint
294%type <a_constr> TableConstraint
vlm7bbdc9f2005-03-28 15:01:27 +0000295%type <a_constr> InnerTypeConstraint
vlmfa67ddc2004-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
vlma6a12e32005-03-20 12:58:00 +0000301%type <a_value> SingleValue
302%type <a_value> ContainedSubtype
vlmfa67ddc2004-06-03 03:38:44 +0000303%type <a_ctype> ConstraintSpec
304%type <a_ctype> ConstraintRangeSpec
vlme1e6ed82005-03-24 14:26:38 +0000305%type <a_value> RestrictedCharacterStringValue
vlmfa67ddc2004-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
vlm177a5b62005-09-05 05:17:57 +0000314%type <a_int> NSTD_IndirectMarker
vlmfa67ddc2004-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
vlm04a08da2005-08-12 10:06:17 +0000363 $$->ModuleName = $1;
vlmfa67ddc2004-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 }
vlm9283dbe2004-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 }
vlmfa67ddc2004-06-03 03:38:44 +0000471 ;
472
473/*
474 * Optional module body.
475 */
476optModuleSpecificationBody:
477 { $$ = 0; }
478 | ModuleSpecificationBody {
vlmfa67ddc2004-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
vlm9283dbe2004-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
vlmfa67ddc2004-06-03 03:38:44 +0000499#ifdef MY_IMPORT
500#error MY_IMPORT DEFINED ELSEWHERE!
501#endif
502#define MY_IMPORT(foo,field) do { \
vlm97ed7152004-08-13 12:31:09 +0000503 while(TQ_FIRST(&($2->foo))) { \
vlmfa67ddc2004-06-03 03:38:44 +0000504 TQ_ADD(&($$->foo), \
505 TQ_REMOVE(&($2->foo), field), \
506 field); \
vlm97ed7152004-08-13 12:31:09 +0000507 } \
508 assert(TQ_FIRST(&($2->foo)) == 0); \
509 } while(0)
vlmfa67ddc2004-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 }
vlm9283dbe2004-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 }
vlmfa67ddc2004-06-03 03:38:44 +0000572
573 /*
574 * Erroneous attemps
575 */
576 | BasicString {
577 return yyerror(
vlm1ac75e72005-11-26 11:21:55 +0000578 "Attempt to redefine a standard basic string type, "
579 "please comment out or remove this type redefinition.");
vlmfa67ddc2004-06-03 03:38:44 +0000580 }
581 ;
582
583/*
584 * === EXAMPLE ===
585 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
586 * === EOF ===
587 */
588ImportsDefinition:
589 TOK_IMPORTS ImportsBundleSet ';' {
vlm04a08da2005-08-12 10:06:17 +0000590 if(!saved_aid && 0)
591 return yyerror("Unterminated IMPORTS FROM, "
592 "expected semicolon ';'");
593 saved_aid = 0;
vlmfa67ddc2004-06-03 03:38:44 +0000594 $$ = $2;
595 }
596 /*
597 * Some error cases.
598 */
599 | TOK_IMPORTS TOK_FROM /* ... */ {
600 return yyerror("Empty IMPORTS list");
601 }
602 ;
603
604ImportsBundleSet:
605 ImportsBundle {
606 $$ = asn1p_module_new();
607 checkmem($$);
608 TQ_ADD(&($$->imports), $1, xp_next);
609 }
610 | ImportsBundleSet ImportsBundle {
611 $$ = $1;
612 TQ_ADD(&($$->imports), $2, xp_next);
613 }
614 ;
615
vlm04a08da2005-08-12 10:06:17 +0000616AssignedIdentifier:
617 { memset(&$$, 0, sizeof($$)); }
618 | ObjectIdentifier { $$.oid = $1; };
619 /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
620
vlmfa67ddc2004-06-03 03:38:44 +0000621ImportsBundle:
vlm04a08da2005-08-12 10:06:17 +0000622 ImportsList TOK_FROM TypeRefName AssignedIdentifier {
vlmfa67ddc2004-06-03 03:38:44 +0000623 $$ = $1;
vlm04a08da2005-08-12 10:06:17 +0000624 $$->fromModuleName = $3;
625 $$->identifier = $4;
626 /* This stupid thing is used for look-back hack. */
627 saved_aid = $$->identifier.oid ? 0 : &($$->identifier);
vlmfa67ddc2004-06-03 03:38:44 +0000628 checkmem($$);
629 }
630 ;
631
632ImportsList:
633 ImportsElement {
634 $$ = asn1p_xports_new();
635 checkmem($$);
636 TQ_ADD(&($$->members), $1, next);
637 }
638 | ImportsList ',' ImportsElement {
639 $$ = $1;
640 TQ_ADD(&($$->members), $3, next);
641 }
642 ;
643
644ImportsElement:
645 TypeRefName {
646 $$ = asn1p_expr_new(yylineno);
647 checkmem($$);
648 $$->Identifier = $1;
649 $$->expr_type = A1TC_REFERENCE;
650 }
vlm0aa86902004-10-12 23:26:53 +0000651 | TypeRefName '{' '}' { /* Completely equivalent to above */
652 $$ = asn1p_expr_new(yylineno);
653 checkmem($$);
654 $$->Identifier = $1;
655 $$->expr_type = A1TC_REFERENCE;
656 }
vlmfa67ddc2004-06-03 03:38:44 +0000657 | Identifier {
658 $$ = asn1p_expr_new(yylineno);
659 checkmem($$);
660 $$->Identifier = $1;
661 $$->expr_type = A1TC_REFERENCE;
662 }
663 ;
664
665ExportsDefinition:
666 TOK_EXPORTS ExportsBody ';' {
667 $$ = $2;
668 }
669 | TOK_EXPORTS TOK_ALL ';' {
670 $$ = 0;
671 }
672 | TOK_EXPORTS ';' {
673 /* Empty EXPORTS clause effectively prohibits export. */
674 $$ = asn1p_xports_new();
675 checkmem($$);
676 }
677 ;
678
679ExportsBody:
680 ExportsElement {
681 $$ = asn1p_xports_new();
682 assert($$);
683 TQ_ADD(&($$->members), $1, next);
684 }
685 | ExportsBody ',' ExportsElement {
686 $$ = $1;
687 TQ_ADD(&($$->members), $3, next);
688 }
689 ;
690
691ExportsElement:
692 TypeRefName {
693 $$ = asn1p_expr_new(yylineno);
694 checkmem($$);
695 $$->Identifier = $1;
696 $$->expr_type = A1TC_EXPORTVAR;
697 }
vlm0aa86902004-10-12 23:26:53 +0000698 | TypeRefName '{' '}' {
699 $$ = asn1p_expr_new(yylineno);
700 checkmem($$);
701 $$->Identifier = $1;
702 $$->expr_type = A1TC_EXPORTVAR;
703 }
vlmfa67ddc2004-06-03 03:38:44 +0000704 | Identifier {
705 $$ = asn1p_expr_new(yylineno);
706 checkmem($$);
707 $$->Identifier = $1;
708 $$->expr_type = A1TC_EXPORTVAR;
709 }
710 ;
711
712
713ValueSetDefinition:
vlm7388db02005-03-31 21:48:13 +0000714 TypeRefName DefinedTypeRef TOK_PPEQ
715 '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
vlmfa67ddc2004-06-03 03:38:44 +0000716 $$ = $2;
717 assert($$->Identifier == 0);
718 $$->Identifier = $1;
719 $$->meta_type = AMT_VALUESET;
vlm7388db02005-03-31 21:48:13 +0000720 // take care of ValueSet body
vlmfa67ddc2004-06-03 03:38:44 +0000721 }
722 ;
723
724DefinedTypeRef:
725 ComplexTypeReference {
726 $$ = asn1p_expr_new(yylineno);
727 checkmem($$);
728 $$->reference = $1;
729 $$->expr_type = A1TC_REFERENCE;
730 $$->meta_type = AMT_TYPEREF;
731 }
732 | BasicTypeId {
733 $$ = asn1p_expr_new(yylineno);
734 checkmem($$);
735 $$->expr_type = $1;
736 $$->meta_type = AMT_TYPE;
737 }
738 ;
739
vlmfa67ddc2004-06-03 03:38:44 +0000740/*
741 * Data Type Reference.
742 * === EXAMPLE ===
743 * Type3 ::= CHOICE { a Type1, b Type 2 }
744 * === EOF ===
745 */
vlmfa67ddc2004-06-03 03:38:44 +0000746DataTypeReference:
747 /*
748 * Optionally tagged type definition.
749 */
750 TypeRefName TOK_PPEQ optTag TOK_TYPE_IDENTIFIER {
751 $$ = asn1p_expr_new(yylineno);
752 checkmem($$);
753 $$->Identifier = $1;
754 $$->tag = $3;
755 $$->expr_type = A1TC_TYPEID;
756 $$->meta_type = AMT_TYPE;
757 }
vlmfce48a42004-09-14 02:36:39 +0000758 | TypeRefName TOK_PPEQ Type {
759 $$ = $3;
vlmfa67ddc2004-06-03 03:38:44 +0000760 $$->Identifier = $1;
vlmfa67ddc2004-06-03 03:38:44 +0000761 assert($$->expr_type);
762 assert($$->meta_type);
763 }
764 | TypeRefName TOK_PPEQ ClassDeclaration {
765 $$ = $3;
766 $$->Identifier = $1;
767 assert($$->expr_type == A1TC_CLASSDEF);
768 assert($$->meta_type == AMT_OBJECT);
769 }
770 /*
771 * Parametrized <Type> declaration:
772 * === EXAMPLE ===
773 * SIGNED { ToBeSigned } ::= SEQUENCE {
774 * toBeSigned ToBeSigned,
775 * algorithm AlgorithmIdentifier,
776 * signature BIT STRING
777 * }
778 * === EOF ===
779 */
vlmec8f6812004-08-22 03:19:54 +0000780 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
vlmfa67ddc2004-06-03 03:38:44 +0000781 $$ = $6;
782 assert($$->Identifier == 0);
783 $$->Identifier = $1;
784 $$->params = $3;
785 $$->meta_type = AMT_PARAMTYPE;
786 }
787 ;
788
789ParameterArgumentList:
790 ParameterArgumentName {
791 int ret;
792 $$ = asn1p_paramlist_new(yylineno);
793 checkmem($$);
794 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
795 checkmem(ret == 0);
796 if($1.governor) asn1p_ref_free($1.governor);
797 if($1.argument) free($1.argument);
798 }
799 | ParameterArgumentList ',' ParameterArgumentName {
800 int ret;
801 $$ = $1;
802 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
803 checkmem(ret == 0);
804 if($3.governor) asn1p_ref_free($3.governor);
805 if($3.argument) free($3.argument);
806 }
807 ;
808
809ParameterArgumentName:
810 TypeRefName {
811 $$.governor = NULL;
812 $$.argument = $1;
813 }
814 | TypeRefName ':' Identifier {
815 int ret;
816 $$.governor = asn1p_ref_new(yylineno);
817 ret = asn1p_ref_add_component($$.governor, $1, 0);
818 checkmem(ret == 0);
819 $$.argument = $3;
820 }
vlm4053ca52005-02-18 16:34:21 +0000821 | TypeRefName ':' TypeRefName {
822 int ret;
823 $$.governor = asn1p_ref_new(yylineno);
824 ret = asn1p_ref_add_component($$.governor, $1, 0);
825 checkmem(ret == 0);
826 $$.argument = $3;
827 }
vlmfa67ddc2004-06-03 03:38:44 +0000828 | BasicTypeId ':' Identifier {
829 int ret;
830 $$.governor = asn1p_ref_new(yylineno);
831 ret = asn1p_ref_add_component($$.governor,
832 ASN_EXPR_TYPE2STR($1), 1);
833 checkmem(ret == 0);
834 $$.argument = $3;
835 }
836 ;
837
838ActualParameterList:
839 ActualParameter {
840 $$ = asn1p_expr_new(yylineno);
841 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000842 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000843 }
844 | ActualParameterList ',' ActualParameter {
845 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000846 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000847 }
848 ;
849
850ActualParameter:
vlmec8f6812004-08-22 03:19:54 +0000851 Type {
vlmfa67ddc2004-06-03 03:38:44 +0000852 $$ = $1;
853 }
854 | Identifier {
855 $$ = asn1p_expr_new(yylineno);
856 checkmem($$);
857 $$->Identifier = $1;
858 $$->expr_type = A1TC_REFERENCE;
859 $$->meta_type = AMT_VALUE;
860 }
861 ;
862
863/*
vlm4053ca52005-02-18 16:34:21 +0000864 | '{' ActualParameter '}' {
865 $$ = asn1p_expr_new(yylineno);
866 checkmem($$);
867 asn1p_expr_add($$, $2);
868 $$->expr_type = A1TC_PARAMETRIZED;
869 $$->meta_type = AMT_TYPE;
870 }
871 ;
872*/
873
874/*
vlmfa67ddc2004-06-03 03:38:44 +0000875 * A collection of constructed data type members.
876 */
vlm0aa86902004-10-12 23:26:53 +0000877optComponentTypeLists:
878 { $$ = asn1p_expr_new(yylineno); }
879 | ComponentTypeLists { $$ = $1; };
880
vlmec8f6812004-08-22 03:19:54 +0000881ComponentTypeLists:
882 ComponentType {
vlmfa67ddc2004-06-03 03:38:44 +0000883 $$ = asn1p_expr_new(yylineno);
884 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000885 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000886 }
vlmec8f6812004-08-22 03:19:54 +0000887 | ComponentTypeLists ',' ComponentType {
vlmfa67ddc2004-06-03 03:38:44 +0000888 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000889 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000890 }
891 ;
892
vlmec8f6812004-08-22 03:19:54 +0000893ComponentType:
vlmfce48a42004-09-14 02:36:39 +0000894 Identifier Type optMarker {
vlmec8f6812004-08-22 03:19:54 +0000895 $$ = $2;
896 assert($$->Identifier == 0);
vlmfce48a42004-09-14 02:36:39 +0000897 $$->Identifier = $1;
vlm177a5b62005-09-05 05:17:57 +0000898 $3.flags |= $$->marker.flags;
vlmec8f6812004-08-22 03:19:54 +0000899 $$->marker = $3;
900 }
vlm177a5b62005-09-05 05:17:57 +0000901 | Type optMarker {
902 $$ = $1;
903 $2.flags |= $$->marker.flags;
904 $$->marker = $2;
905 _fixup_anonymous_identifier($$);
906 }
vlmec8f6812004-08-22 03:19:54 +0000907 | TOK_COMPONENTS TOK_OF Type {
908 $$ = asn1p_expr_new(yylineno);
909 checkmem($$);
910 $$->meta_type = $3->meta_type;
911 $$->expr_type = A1TC_COMPONENTS_OF;
vlm6a02a8a2004-09-08 00:28:11 +0000912 asn1p_expr_add($$, $3);
vlmec8f6812004-08-22 03:19:54 +0000913 }
914 | ExtensionAndException {
915 $$ = $1;
916 }
917 ;
918
919AlternativeTypeLists:
920 AlternativeType {
921 $$ = asn1p_expr_new(yylineno);
922 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000923 asn1p_expr_add($$, $1);
vlmec8f6812004-08-22 03:19:54 +0000924 }
925 | AlternativeTypeLists ',' AlternativeType {
926 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000927 asn1p_expr_add($$, $3);
vlmec8f6812004-08-22 03:19:54 +0000928 }
929 ;
930
931AlternativeType:
vlmfce48a42004-09-14 02:36:39 +0000932 Identifier Type {
vlmec8f6812004-08-22 03:19:54 +0000933 $$ = $2;
934 assert($$->Identifier == 0);
vlmfce48a42004-09-14 02:36:39 +0000935 $$->Identifier = $1;
vlmec8f6812004-08-22 03:19:54 +0000936 }
937 | ExtensionAndException {
938 $$ = $1;
939 }
vlm5d89c3d2005-08-13 09:07:11 +0000940 | Type {
941 $$ = $1;
942 _fixup_anonymous_identifier($$);
943 }
vlmec8f6812004-08-22 03:19:54 +0000944 ;
945
vlmfa67ddc2004-06-03 03:38:44 +0000946ClassDeclaration:
947 TOK_CLASS '{' ClassFieldList '}' optWithSyntax {
948 $$ = $3;
949 checkmem($$);
950 $$->with_syntax = $5;
951 assert($$->expr_type == A1TC_CLASSDEF);
952 assert($$->meta_type == AMT_OBJECT);
953 }
954 ;
955
956optUnique:
957 { $$ = 0; }
958 | TOK_UNIQUE { $$ = 1; }
959 ;
960
961ClassFieldList:
962 ClassField {
963 $$ = asn1p_expr_new(yylineno);
964 checkmem($$);
965 $$->expr_type = A1TC_CLASSDEF;
966 $$->meta_type = AMT_OBJECT;
vlm6a02a8a2004-09-08 00:28:11 +0000967 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000968 }
969 | ClassFieldList ',' ClassField {
970 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000971 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000972 }
973 ;
974
975ClassField:
976 ClassFieldIdentifier optMarker {
977 $$ = asn1p_expr_new(yylineno);
978 checkmem($$);
979 $$->Identifier = $1.name;
980 $$->expr_type = A1TC_CLASSFIELD;
981 $$->meta_type = AMT_OBJECTFIELD;
982 $$->marker = $2;
983 }
vlmbde35d42004-11-24 17:43:29 +0000984 | ClassFieldIdentifier Type optUnique optMarker {
vlmfa67ddc2004-06-03 03:38:44 +0000985 $$ = $2;
986 $$->Identifier = $1.name;
vlmbde35d42004-11-24 17:43:29 +0000987 $$->marker = $4;
988 $$->unique = $3;
vlmfa67ddc2004-06-03 03:38:44 +0000989 }
vlmbde35d42004-11-24 17:43:29 +0000990 | ClassFieldIdentifier ClassFieldIdentifier optUnique optMarker {
vlmfa67ddc2004-06-03 03:38:44 +0000991 int ret;
992 $$ = asn1p_expr_new(yylineno);
993 checkmem($$);
994 $$->Identifier = $1.name;
995 $$->reference = asn1p_ref_new(yylineno);
996 checkmem($$->reference);
997 ret = asn1p_ref_add_component($$->reference,
998 $2.name, $2.lex_type);
999 checkmem(ret == 0);
1000 $$->expr_type = A1TC_CLASSFIELD;
1001 $$->meta_type = AMT_OBJECTFIELD;
vlmbde35d42004-11-24 17:43:29 +00001002 $$->marker = $4;
1003 $$->unique = $3;
vlmfa67ddc2004-06-03 03:38:44 +00001004 }
1005 ;
1006
1007optWithSyntax:
1008 { $$ = 0; }
1009 | WithSyntax {
1010 $$ = $1;
1011 }
1012 ;
1013
1014WithSyntax:
1015 TOK_WITH TOK_SYNTAX '{'
1016 { asn1p_lexer_hack_enable_with_syntax(); }
1017 WithSyntaxFormat
1018 '}' {
1019 $$ = $5;
1020 }
1021 ;
1022
1023WithSyntaxFormat:
1024 WithSyntaxFormatToken {
1025 $$ = asn1p_wsyntx_new();
1026 TQ_ADD(&($$->chunks), $1, next);
1027 }
1028 | WithSyntaxFormat WithSyntaxFormatToken {
1029 $$ = $1;
1030 TQ_ADD(&($$->chunks), $2, next);
1031 }
1032 ;
1033
1034WithSyntaxFormatToken:
1035 TOK_opaque {
1036 $$ = asn1p_wsyntx_chunk_frombuf($1.buf, $1.len, 0);
1037 }
1038 | ClassFieldIdentifier {
1039 asn1p_ref_t *ref;
1040 int ret;
1041 ref = asn1p_ref_new(yylineno);
1042 checkmem(ref);
1043 ret = asn1p_ref_add_component(ref, $1.name, $1.lex_type);
1044 checkmem(ret == 0);
1045 $$ = asn1p_wsyntx_chunk_fromref(ref, 0);
1046 }
1047 ;
1048
vlmfa67ddc2004-06-03 03:38:44 +00001049ExtensionAndException:
1050 TOK_ThreeDots {
vlm39e5ed72004-09-05 10:40:41 +00001051 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001052 checkmem($$);
1053 $$->Identifier = strdup("...");
1054 checkmem($$->Identifier);
1055 $$->expr_type = A1TC_EXTENSIBLE;
1056 $$->meta_type = AMT_TYPE;
1057 }
1058 | TOK_ThreeDots '!' DefinedValue {
vlm39e5ed72004-09-05 10:40:41 +00001059 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001060 checkmem($$);
1061 $$->Identifier = strdup("...");
1062 checkmem($$->Identifier);
1063 $$->value = $3;
1064 $$->expr_type = A1TC_EXTENSIBLE;
1065 $$->meta_type = AMT_TYPE;
1066 }
1067 | TOK_ThreeDots '!' SignedNumber {
vlm39e5ed72004-09-05 10:40:41 +00001068 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001069 checkmem($$);
1070 $$->Identifier = strdup("...");
1071 $$->value = $3;
1072 checkmem($$->Identifier);
1073 $$->expr_type = A1TC_EXTENSIBLE;
1074 $$->meta_type = AMT_TYPE;
1075 }
1076 ;
1077
vlmec8f6812004-08-22 03:19:54 +00001078Type:
vlmfce48a42004-09-14 02:36:39 +00001079 optTag TypeDeclaration optConstraints {
1080 $$ = $2;
1081 $$->tag = $1;
vlmec8f6812004-08-22 03:19:54 +00001082 /*
1083 * Outer constraint for SEQUENCE OF and SET OF applies
1084 * to the inner type.
1085 */
1086 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1087 || $$->expr_type == ASN_CONSTR_SET_OF) {
1088 assert(!TQ_FIRST(&($$->members))->constraints);
vlmfce48a42004-09-14 02:36:39 +00001089 TQ_FIRST(&($$->members))->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001090 } else {
1091 if($$->constraints) {
1092 assert(!$2);
1093 } else {
vlmfce48a42004-09-14 02:36:39 +00001094 $$->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001095 }
1096 }
vlm177a5b62005-09-05 05:17:57 +00001097 }
1098 ;
1099
1100NSTD_IndirectMarker:
1101 {
1102 $$ = asn1p_as_pointer ? EM_INDIRECT : 0;
1103 asn1p_as_pointer = 0;
vlmec8f6812004-08-22 03:19:54 +00001104 }
1105 ;
1106
1107TypeDeclaration:
vlm177a5b62005-09-05 05:17:57 +00001108 NSTD_IndirectMarker TypeDeclarationSet {
vlm066dc102005-08-22 12:23:54 +00001109 $$ = $2;
vlm177a5b62005-09-05 05:17:57 +00001110 $$->marker.flags |= $1;
1111
1112 if(($$->marker.flags & EM_INDIRECT)
1113 && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
1114 fprintf(stderr,
1115 "INFO: Directive <ASN1C:RepresentAsPointer> "
1116 "applied to %s at line %d\n",
1117 ASN_EXPR_TYPE2STR($$->expr_type)
1118 ? ASN_EXPR_TYPE2STR($$->expr_type)
1119 : "member",
1120 $$->_lineno
1121 );
1122 }
vlm066dc102005-08-22 12:23:54 +00001123 }
vlm177a5b62005-09-05 05:17:57 +00001124 ;
vlm066dc102005-08-22 12:23:54 +00001125
1126TypeDeclarationSet:
vlmfa67ddc2004-06-03 03:38:44 +00001127 BasicType {
1128 $$ = $1;
1129 }
vlm177a5b62005-09-05 05:17:57 +00001130 | TOK_CHOICE '{' AlternativeTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001131 $$ = $3;
1132 assert($$->expr_type == A1TC_INVALID);
1133 $$->expr_type = ASN_CONSTR_CHOICE;
1134 $$->meta_type = AMT_TYPE;
vlmfa67ddc2004-06-03 03:38:44 +00001135 }
vlm177a5b62005-09-05 05:17:57 +00001136 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001137 $$ = $3;
1138 assert($$->expr_type == A1TC_INVALID);
1139 $$->expr_type = ASN_CONSTR_SEQUENCE;
1140 $$->meta_type = AMT_TYPE;
1141 }
vlm177a5b62005-09-05 05:17:57 +00001142 | TOK_SET '{' optComponentTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001143 $$ = $3;
1144 assert($$->expr_type == A1TC_INVALID);
1145 $$->expr_type = ASN_CONSTR_SET;
1146 $$->meta_type = AMT_TYPE;
1147 }
vlm151c0b22004-09-22 16:03:36 +00001148 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
vlm39e5ed72004-09-05 10:40:41 +00001149 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001150 checkmem($$);
1151 $$->constraints = $2;
1152 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1153 $$->meta_type = AMT_TYPE;
vlm151c0b22004-09-22 16:03:36 +00001154 $6->Identifier = $4;
1155 $6->tag = $5;
1156 asn1p_expr_add($$, $6);
vlmec8f6812004-08-22 03:19:54 +00001157 }
vlm151c0b22004-09-22 16:03:36 +00001158 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
vlm39e5ed72004-09-05 10:40:41 +00001159 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001160 checkmem($$);
1161 $$->constraints = $2;
1162 $$->expr_type = ASN_CONSTR_SET_OF;
1163 $$->meta_type = AMT_TYPE;
vlm151c0b22004-09-22 16:03:36 +00001164 $6->Identifier = $4;
1165 $6->tag = $5;
1166 asn1p_expr_add($$, $6);
vlmec8f6812004-08-22 03:19:54 +00001167 }
1168 | TOK_ANY {
vlm39e5ed72004-09-05 10:40:41 +00001169 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001170 checkmem($$);
vlm044f7442004-09-04 04:49:21 +00001171 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001172 $$->meta_type = AMT_TYPE;
1173 }
1174 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1175 int ret;
vlm39e5ed72004-09-05 10:40:41 +00001176 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001177 checkmem($$);
1178 $$->reference = asn1p_ref_new(yylineno);
1179 ret = asn1p_ref_add_component($$->reference,
1180 $4, RLT_lowercase);
1181 checkmem(ret == 0);
vlm044f7442004-09-04 04:49:21 +00001182 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001183 $$->meta_type = AMT_TYPE;
1184 }
vlmfa67ddc2004-06-03 03:38:44 +00001185 /*
1186 * A parametrized assignment.
1187 */
1188 | TypeRefName '{' ActualParameterList '}' {
1189 int ret;
1190 $$ = $3;
1191 assert($$->expr_type == 0);
1192 assert($$->meta_type == 0);
1193 assert($$->reference == 0);
1194 $$->reference = asn1p_ref_new(yylineno);
1195 checkmem($$->reference);
1196 ret = asn1p_ref_add_component($$->reference, $1, RLT_UNKNOWN);
1197 checkmem(ret == 0);
1198 free($1);
1199 $$->expr_type = A1TC_PARAMETRIZED;
1200 $$->meta_type = AMT_TYPE;
1201 }
1202 /*
1203 * A DefinedType reference.
1204 * "CLASS1.&id.&id2"
1205 * or
1206 * "Module.Type"
1207 * or
1208 * "Module.identifier"
1209 * or
1210 * "Type"
1211 */
1212 | ComplexTypeReference {
1213 $$ = asn1p_expr_new(yylineno);
1214 checkmem($$);
1215 $$->reference = $1;
1216 $$->expr_type = A1TC_REFERENCE;
1217 $$->meta_type = AMT_TYPEREF;
1218 }
1219 | TOK_INSTANCE TOK_OF ComplexTypeReference {
1220 $$ = asn1p_expr_new(yylineno);
1221 checkmem($$);
1222 $$->reference = $3;
1223 $$->expr_type = A1TC_INSTANCE;
1224 $$->meta_type = AMT_TYPE;
1225 }
1226 ;
1227
1228/*
1229 * A type name consisting of several components.
1230 * === EXAMPLE ===
1231 * === EOF ===
1232 */
1233ComplexTypeReference:
1234 TOK_typereference {
1235 int ret;
1236 $$ = asn1p_ref_new(yylineno);
1237 checkmem($$);
1238 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1239 checkmem(ret == 0);
1240 free($1);
1241 }
1242 | TOK_typereference '.' TypeRefName {
1243 int ret;
1244 $$ = asn1p_ref_new(yylineno);
1245 checkmem($$);
1246 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1247 checkmem(ret == 0);
1248 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1249 checkmem(ret == 0);
1250 free($1);
1251 }
vlmc94e28f2004-09-15 11:59:51 +00001252 | ObjectClassReference '.' TypeRefName {
1253 int ret;
1254 $$ = asn1p_ref_new(yylineno);
1255 checkmem($$);
1256 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1257 checkmem(ret == 0);
1258 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1259 checkmem(ret == 0);
1260 free($1);
1261 }
vlmfa67ddc2004-06-03 03:38:44 +00001262 | TOK_typereference '.' Identifier {
1263 int ret;
1264 $$ = asn1p_ref_new(yylineno);
1265 checkmem($$);
1266 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1267 checkmem(ret == 0);
1268 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1269 checkmem(ret == 0);
1270 free($1);
1271 }
1272 | ObjectClassReference {
1273 int ret;
1274 $$ = asn1p_ref_new(yylineno);
1275 checkmem($$);
1276 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1277 free($1);
1278 checkmem(ret == 0);
1279 }
1280 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1281 int ret;
1282 $$ = $3;
1283 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1284 free($1);
1285 checkmem(ret == 0);
1286 /*
1287 * Move the last element infront.
1288 */
1289 {
1290 struct asn1p_ref_component_s tmp_comp;
1291 tmp_comp = $$->components[$$->comp_count-1];
1292 memmove(&$$->components[1],
1293 &$$->components[0],
1294 sizeof($$->components[0])
1295 * ($$->comp_count - 1));
1296 $$->components[0] = tmp_comp;
1297 }
1298 }
1299 ;
1300
1301ComplexTypeReferenceAmpList:
1302 ComplexTypeReferenceElement {
1303 int ret;
1304 $$ = asn1p_ref_new(yylineno);
1305 checkmem($$);
1306 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1307 free($1.name);
1308 checkmem(ret == 0);
1309 }
1310 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1311 int ret;
1312 $$ = $1;
1313 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1314 free($3.name);
1315 checkmem(ret == 0);
1316 }
1317 ;
1318
1319ComplexTypeReferenceElement: ClassFieldName;
1320ClassFieldIdentifier: ClassFieldName;
1321
1322ClassFieldName:
1323 /* "&Type1" */
1324 TOK_typefieldreference {
1325 $$.lex_type = RLT_AmpUppercase;
1326 $$.name = $1;
1327 }
1328 /* "&id" */
1329 | TOK_valuefieldreference {
1330 $$.lex_type = RLT_Amplowercase;
1331 $$.name = $1;
1332 }
1333 ;
1334
1335
1336/*
1337 * === EXAMPLE ===
1338 * value INTEGER ::= 1
1339 * === EOF ===
1340 */
1341ValueDefinition:
vlmc94e28f2004-09-15 11:59:51 +00001342 Identifier DefinedTypeRef TOK_PPEQ Value {
vlmfa67ddc2004-06-03 03:38:44 +00001343 $$ = $2;
1344 assert($$->Identifier == NULL);
1345 $$->Identifier = $1;
1346 $$->meta_type = AMT_VALUE;
1347 $$->value = $4;
1348 }
1349 ;
1350
vlmc94e28f2004-09-15 11:59:51 +00001351Value:
1352 Identifier ':' Value {
1353 $$ = asn1p_value_fromint(0);
1354 checkmem($$);
1355 $$->type = ATV_CHOICE_IDENTIFIER;
1356 $$->value.choice_identifier.identifier = $1;
1357 $$->value.choice_identifier.value = $3;
1358 }
vlmd30bc6c2005-03-24 16:27:02 +00001359 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
vlmfa67ddc2004-06-03 03:38:44 +00001360 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1361 checkmem($$);
1362 $$->type = ATV_UNPARSED;
1363 }
vlmc94e28f2004-09-15 11:59:51 +00001364 | TOK_NULL {
1365 $$ = asn1p_value_fromint(0);
1366 checkmem($$);
1367 $$->type = ATV_NULL;
1368 }
1369 | TOK_FALSE {
1370 $$ = asn1p_value_fromint(0);
1371 checkmem($$);
1372 $$->type = ATV_FALSE;
1373 }
1374 | TOK_TRUE {
1375 $$ = asn1p_value_fromint(0);
1376 checkmem($$);
1377 $$->type = ATV_TRUE;
1378 }
vlmfa67ddc2004-06-03 03:38:44 +00001379 | TOK_bstring {
1380 $$ = _convert_bitstring2binary($1, 'B');
1381 checkmem($$);
1382 }
1383 | TOK_hstring {
1384 $$ = _convert_bitstring2binary($1, 'H');
1385 checkmem($$);
1386 }
vlme1e6ed82005-03-24 14:26:38 +00001387 | RestrictedCharacterStringValue {
1388 $$ = $$;
vlmfa67ddc2004-06-03 03:38:44 +00001389 }
1390 | SignedNumber {
1391 $$ = $1;
1392 }
1393 | DefinedValue {
1394 $$ = $1;
1395 }
1396 ;
1397
1398DefinedValue:
1399 Identifier {
1400 asn1p_ref_t *ref;
1401 int ret;
1402 ref = asn1p_ref_new(yylineno);
1403 checkmem(ref);
1404 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1405 checkmem(ret == 0);
1406 $$ = asn1p_value_fromref(ref, 0);
1407 checkmem($$);
1408 free($1);
1409 }
1410 | TypeRefName '.' Identifier {
1411 asn1p_ref_t *ref;
1412 int ret;
1413 ref = asn1p_ref_new(yylineno);
1414 checkmem(ref);
1415 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1416 checkmem(ret == 0);
1417 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1418 checkmem(ret == 0);
1419 $$ = asn1p_value_fromref(ref, 0);
1420 checkmem($$);
1421 free($1);
1422 free($3);
1423 }
1424 ;
1425
vlme1e6ed82005-03-24 14:26:38 +00001426
1427RestrictedCharacterStringValue:
1428 TOK_cstring {
1429 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1430 checkmem($$);
1431 }
vlm2c8c44d2005-03-24 16:22:35 +00001432 | TOK_tuple {
1433 $$ = asn1p_value_fromint($1);
1434 checkmem($$);
1435 $$->type = ATV_TUPLE;
1436 }
1437 | TOK_quadruple {
1438 $$ = asn1p_value_fromint($1);
1439 checkmem($$);
1440 $$->type = ATV_QUADRUPLE;
1441 }
1442 /*
vlme1e6ed82005-03-24 14:26:38 +00001443 | '{' TOK_number ',' TOK_number '}' {
1444 asn1c_integer_t v = ($2 << 4) + $4;
1445 if($2 > 7) return yyerror("X.680:2003, #37.14 "
1446 "mandates 0..7 range for Tuple's TableColumn");
1447 if($4 > 15) return yyerror("X.680:2003, #37.14 "
1448 "mandates 0..15 range for Tuple's TableRow");
1449 $$ = asn1p_value_fromint(v);
1450 checkmem($$);
1451 $$->type = ATV_TUPLE;
1452 }
1453 | '{' TOK_number ',' TOK_number ',' TOK_number ',' TOK_number '}' {
1454 asn1c_integer_t v = ($2 << 24) | ($4 << 16) | ($6 << 8) | $8;
1455 if($2 > 127) return yyerror("X.680:2003, #37.12 "
1456 "mandates 0..127 range for Quadruple's Group");
1457 if($4 > 255) return yyerror("X.680:2003, #37.12 "
1458 "mandates 0..255 range for Quadruple's Plane");
1459 if($6 > 255) return yyerror("X.680:2003, #37.12 "
1460 "mandates 0..255 range for Quadruple's Row");
1461 if($8 > 255) return yyerror("X.680:2003, #37.12 "
1462 "mandates 0..255 range for Quadruple's Cell");
1463 $$ = asn1p_value_fromint(v);
1464 checkmem($$);
1465 $$->type = ATV_QUADRUPLE;
1466 }
vlm2c8c44d2005-03-24 16:22:35 +00001467 */
vlme1e6ed82005-03-24 14:26:38 +00001468 ;
1469
vlmfa67ddc2004-06-03 03:38:44 +00001470Opaque:
1471 TOK_opaque {
vlm6611add2005-03-20 14:28:32 +00001472 $$.len = $1.len + 1;
vlmfa67ddc2004-06-03 03:38:44 +00001473 $$.buf = malloc($$.len + 1);
1474 checkmem($$.buf);
1475 $$.buf[0] = '{';
vlm6611add2005-03-20 14:28:32 +00001476 memcpy($$.buf + 1, $1.buf, $1.len);
vlmfa67ddc2004-06-03 03:38:44 +00001477 $$.buf[$$.len] = '\0';
1478 free($1.buf);
1479 }
1480 | Opaque TOK_opaque {
1481 int newsize = $1.len + $2.len;
1482 char *p = malloc(newsize + 1);
1483 checkmem(p);
1484 memcpy(p , $1.buf, $1.len);
1485 memcpy(p + $1.len, $2.buf, $2.len);
1486 p[newsize] = '\0';
1487 free($1.buf);
1488 free($2.buf);
1489 $$.buf = p;
1490 $$.len = newsize;
1491 }
1492 ;
1493
1494BasicTypeId:
1495 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1496 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1497 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1498 | BasicTypeId_UniverationCompatible { $$ = $1; }
1499 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1500 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1501 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1502 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1503 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1504 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1505 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1506 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
vlm5e2c4b92005-03-20 11:12:40 +00001507 | BasicString { $$ = $1; }
vlmfa67ddc2004-06-03 03:38:44 +00001508 ;
1509
1510/*
1511 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1512 */
1513BasicTypeId_UniverationCompatible:
1514 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1515 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1516 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1517 ;
1518
1519BasicType:
1520 BasicTypeId {
vlm39e5ed72004-09-05 10:40:41 +00001521 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001522 checkmem($$);
1523 $$->expr_type = $1;
1524 $$->meta_type = AMT_TYPE;
1525 }
1526 | BasicTypeId_UniverationCompatible UniverationDefinition {
1527 if($2) {
1528 $$ = $2;
1529 } else {
vlm39e5ed72004-09-05 10:40:41 +00001530 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001531 checkmem($$);
1532 }
1533 $$->expr_type = $1;
1534 $$->meta_type = AMT_TYPE;
1535 }
1536 ;
1537
1538BasicString:
1539 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1540 | TOK_GeneralString {
1541 $$ = ASN_STRING_GeneralString;
vlmc94e28f2004-09-15 11:59:51 +00001542 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001543 }
1544 | TOK_GraphicString {
1545 $$ = ASN_STRING_GraphicString;
vlmc94e28f2004-09-15 11:59:51 +00001546 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001547 }
1548 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1549 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1550 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1551 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1552 | TOK_T61String {
1553 $$ = ASN_STRING_T61String;
vlmc94e28f2004-09-15 11:59:51 +00001554 fprintf(stderr, "WARNING: T61String is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001555 }
1556 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1557 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1558 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1559 | TOK_VideotexString {
1560 $$ = ASN_STRING_VideotexString;
vlmc94e28f2004-09-15 11:59:51 +00001561 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001562 }
1563 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1564 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1565 ;
1566
vlm5f0128b2004-08-20 13:25:29 +00001567
vlmfa67ddc2004-06-03 03:38:44 +00001568/*
1569 * Data type constraints.
1570 */
vlmfa67ddc2004-06-03 03:38:44 +00001571Union: '|' | TOK_UNION;
1572Intersection: '^' | TOK_INTERSECTION;
1573Except: TOK_EXCEPT;
1574
vlm9283dbe2004-08-18 04:59:12 +00001575optConstraints:
1576 { $$ = 0; }
vlm5f0128b2004-08-20 13:25:29 +00001577 | Constraints {
1578 $$ = $1;
1579 }
1580 ;
1581
1582Constraints:
1583 SetOfConstraints {
vlm9fe7c922005-08-12 10:08:45 +00001584 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
vlm9283dbe2004-08-18 04:59:12 +00001585 }
1586 | TOK_SIZE '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001587 /*
1588 * This is a special case, for compatibility purposes.
vlm9283dbe2004-08-18 04:59:12 +00001589 * It goes without parentheses.
vlmfa67ddc2004-06-03 03:38:44 +00001590 */
vlm9fe7c922005-08-12 10:08:45 +00001591 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001592 }
vlmfa67ddc2004-06-03 03:38:44 +00001593 ;
1594
vlm9283dbe2004-08-18 04:59:12 +00001595SetOfConstraints:
1596 '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001597 $$ = $2;
1598 }
vlm9283dbe2004-08-18 04:59:12 +00001599 | SetOfConstraints '(' ElementSetSpecs ')' {
vlm9fe7c922005-08-12 10:08:45 +00001600 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
vlm9283dbe2004-08-18 04:59:12 +00001601 }
vlmfa67ddc2004-06-03 03:38:44 +00001602 ;
1603
vlm9283dbe2004-08-18 04:59:12 +00001604ElementSetSpecs:
1605 ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001606 $$ = $1;
1607 }
vlm9283dbe2004-08-18 04:59:12 +00001608 | ElementSetSpec ',' TOK_ThreeDots {
vlmfa67ddc2004-06-03 03:38:44 +00001609 asn1p_constraint_t *ct;
1610 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001611 ct->type = ACT_EL_EXT;
vlm9fe7c922005-08-12 10:08:45 +00001612 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlmfa67ddc2004-06-03 03:38:44 +00001613 }
vlm9283dbe2004-08-18 04:59:12 +00001614 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001615 asn1p_constraint_t *ct;
1616 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001617 ct->type = ACT_EL_EXT;
vlm9fe7c922005-08-12 10:08:45 +00001618 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlm6f5eb0b2004-08-13 12:35:09 +00001619 ct = $$;
vlm9fe7c922005-08-12 10:08:45 +00001620 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
vlmfa67ddc2004-06-03 03:38:44 +00001621 }
vlmfa67ddc2004-06-03 03:38:44 +00001622 ;
1623
vlm9283dbe2004-08-18 04:59:12 +00001624ElementSetSpec:
1625 ConstraintSubtypeElement {
1626 $$ = $1;
1627 }
vlme1e6ed82005-03-24 14:26:38 +00001628 | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001629 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
vlme1e6ed82005-03-24 14:26:38 +00001630 }
vlm9283dbe2004-08-18 04:59:12 +00001631 | ElementSetSpec Union ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001632 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001633 }
vlm9283dbe2004-08-18 04:59:12 +00001634 | ElementSetSpec Intersection ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001635 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001636 }
vlm9283dbe2004-08-18 04:59:12 +00001637 | ConstraintSubtypeElement Except ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001638 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001639 }
1640 ;
1641
1642ConstraintSubtypeElement:
vlm9283dbe2004-08-18 04:59:12 +00001643 ConstraintSpec '(' ElementSetSpecs ')' {
1644 int ret;
1645 $$ = asn1p_constraint_new(yylineno);
1646 checkmem($$);
1647 $$->type = $1;
1648 ret = asn1p_constraint_insert($$, $3);
1649 checkmem(ret == 0);
1650 }
1651 | '(' ElementSetSpecs ')' {
1652 int ret;
1653 $$ = asn1p_constraint_new(yylineno);
1654 checkmem($$);
1655 $$->type = ACT_CA_SET;
1656 ret = asn1p_constraint_insert($$, $2);
1657 checkmem(ret == 0);
1658 }
vlma6a12e32005-03-20 12:58:00 +00001659 | SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001660 $$ = asn1p_constraint_new(yylineno);
1661 checkmem($$);
1662 $$->type = ACT_EL_VALUE;
1663 $$->value = $1;
1664 }
vlma6a12e32005-03-20 12:58:00 +00001665 | ContainedSubtype {
1666 $$ = asn1p_constraint_new(yylineno);
1667 checkmem($$);
1668 $$->type = ACT_EL_TYPE;
1669 $$->containedSubtype = $1;
1670 }
1671 | SingleValue ConstraintRangeSpec SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001672 $$ = asn1p_constraint_new(yylineno);
1673 checkmem($$);
1674 $$->type = $2;
1675 $$->range_start = $1;
1676 $$->range_stop = $3;
1677 }
vlma6a12e32005-03-20 12:58:00 +00001678 | TOK_MIN ConstraintRangeSpec SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001679 $$ = asn1p_constraint_new(yylineno);
1680 checkmem($$);
vlm9283dbe2004-08-18 04:59:12 +00001681 $$->type = $2;
1682 $$->range_start = asn1p_value_fromint(-123);
1683 $$->range_stop = $3;
1684 $$->range_start->type = ATV_MIN;
1685 }
vlma6a12e32005-03-20 12:58:00 +00001686 | SingleValue ConstraintRangeSpec TOK_MAX {
vlm9283dbe2004-08-18 04:59:12 +00001687 $$ = asn1p_constraint_new(yylineno);
1688 checkmem($$);
1689 $$->type = $2;
1690 $$->range_start = $1;
1691 $$->range_stop = asn1p_value_fromint(321);
1692 $$->range_stop->type = ATV_MAX;
1693 }
1694 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1695 $$ = asn1p_constraint_new(yylineno);
1696 checkmem($$);
1697 $$->type = $2;
1698 $$->range_start = asn1p_value_fromint(-123);
1699 $$->range_stop = asn1p_value_fromint(321);
1700 $$->range_start->type = ATV_MIN;
1701 $$->range_stop->type = ATV_MAX;
vlmfa67ddc2004-06-03 03:38:44 +00001702 }
1703 | TableConstraint {
1704 $$ = $1;
1705 }
vlm7bbdc9f2005-03-28 15:01:27 +00001706 | InnerTypeConstraint {
vlmfa67ddc2004-06-03 03:38:44 +00001707 $$ = $1;
1708 }
vlm6611add2005-03-20 14:28:32 +00001709 | TOK_CONSTRAINED TOK_BY '{'
1710 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1711 $$ = asn1p_constraint_new(yylineno);
1712 checkmem($$);
1713 $$->type = ACT_CT_CTDBY;
1714 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
1715 checkmem($$->value);
1716 $$->value->type = ATV_UNPARSED;
1717 }
vlmfa67ddc2004-06-03 03:38:44 +00001718 ;
1719
1720ConstraintRangeSpec:
1721 TOK_TwoDots { $$ = ACT_EL_RANGE; }
1722 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
1723 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
1724 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
1725 ;
1726
1727ConstraintSpec:
1728 TOK_SIZE {
1729 $$ = ACT_CT_SIZE;
1730 }
1731 | TOK_FROM {
1732 $$ = ACT_CT_FROM;
1733 }
1734 ;
1735
vlma6a12e32005-03-20 12:58:00 +00001736SingleValue:
vlm4053ca52005-02-18 16:34:21 +00001737 TOK_FALSE {
1738 $$ = asn1p_value_fromint(0);
1739 checkmem($$);
1740 $$->type = ATV_FALSE;
1741 }
1742 | TOK_TRUE {
1743 $$ = asn1p_value_fromint(1);
1744 checkmem($$);
1745 $$->type = ATV_TRUE;
1746 }
1747 | SignedNumber {
vlmfa67ddc2004-06-03 03:38:44 +00001748 $$ = $1;
1749 }
vlme1e6ed82005-03-24 14:26:38 +00001750 | RestrictedCharacterStringValue {
1751 $$ = $1;
vlm4053ca52005-02-18 16:34:21 +00001752 }
vlmfa67ddc2004-06-03 03:38:44 +00001753 | Identifier {
1754 asn1p_ref_t *ref;
1755 int ret;
1756 ref = asn1p_ref_new(yylineno);
1757 checkmem(ref);
1758 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1759 checkmem(ret == 0);
1760 $$ = asn1p_value_fromref(ref, 0);
1761 checkmem($$);
1762 free($1);
1763 }
vlma6a12e32005-03-20 12:58:00 +00001764 ;
1765
1766ContainedSubtype:
1767 TypeRefName {
vlm4053ca52005-02-18 16:34:21 +00001768 asn1p_ref_t *ref;
1769 int ret;
1770 ref = asn1p_ref_new(yylineno);
1771 checkmem(ref);
1772 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1773 checkmem(ret == 0);
1774 $$ = asn1p_value_fromref(ref, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001775 checkmem($$);
vlm4053ca52005-02-18 16:34:21 +00001776 free($1);
vlmfa67ddc2004-06-03 03:38:44 +00001777 }
1778 ;
1779
vlm7bbdc9f2005-03-28 15:01:27 +00001780InnerTypeConstraint:
1781 TOK_WITH TOK_COMPONENT SetOfConstraints {
vlm9fe7c922005-08-12 10:08:45 +00001782 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
vlm7bbdc9f2005-03-28 15:01:27 +00001783 }
1784 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
vlm9fe7c922005-08-12 10:08:45 +00001785 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001786 }
1787 ;
1788
1789WithComponentsList:
1790 WithComponentsElement {
1791 $$ = $1;
1792 }
1793 | WithComponentsList ',' WithComponentsElement {
vlm9fe7c922005-08-12 10:08:45 +00001794 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001795 }
1796 ;
1797
1798WithComponentsElement:
1799 TOK_ThreeDots {
1800 $$ = asn1p_constraint_new(yylineno);
1801 checkmem($$);
1802 $$->type = ACT_EL_EXT;
vlm7bbdc9f2005-03-28 15:01:27 +00001803 $$->value = asn1p_value_frombuf("...", 3, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001804 }
1805 | Identifier optConstraints optPresenceConstraint {
1806 $$ = asn1p_constraint_new(yylineno);
1807 checkmem($$);
1808 $$->type = ACT_EL_VALUE;
1809 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1810 $$->presence = $3;
vlm7bbdc9f2005-03-28 15:01:27 +00001811 if($2) asn1p_constraint_insert($$, $2);
vlmfa67ddc2004-06-03 03:38:44 +00001812 }
1813 ;
1814
1815/*
1816 * presence constraint for WithComponents
1817 */
1818optPresenceConstraint:
1819 { $$ = ACPRES_DEFAULT; }
1820 | PresenceConstraint { $$ = $1; }
1821 ;
1822
1823PresenceConstraint:
1824 TOK_PRESENT {
1825 $$ = ACPRES_PRESENT;
1826 }
1827 | TOK_ABSENT {
1828 $$ = ACPRES_ABSENT;
1829 }
1830 | TOK_OPTIONAL {
1831 $$ = ACPRES_OPTIONAL;
1832 }
1833 ;
1834
1835TableConstraint:
1836 SimpleTableConstraint {
1837 $$ = $1;
1838 }
1839 | ComponentRelationConstraint {
1840 $$ = $1;
1841 }
1842 ;
1843
1844/*
1845 * "{ExtensionSet}"
1846 */
1847SimpleTableConstraint:
1848 '{' TypeRefName '}' {
1849 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
1850 asn1p_constraint_t *ct;
1851 int ret;
1852 ret = asn1p_ref_add_component(ref, $2, 0);
1853 checkmem(ret == 0);
1854 ct = asn1p_constraint_new(yylineno);
1855 checkmem($$);
1856 ct->type = ACT_EL_VALUE;
1857 ct->value = asn1p_value_fromref(ref, 0);
vlm9fe7c922005-08-12 10:08:45 +00001858 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001859 }
1860 ;
1861
1862ComponentRelationConstraint:
1863 SimpleTableConstraint '{' AtNotationList '}' {
vlm9fe7c922005-08-12 10:08:45 +00001864 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001865 }
1866 ;
1867
1868AtNotationList:
1869 AtNotationElement {
1870 $$ = asn1p_constraint_new(yylineno);
1871 checkmem($$);
1872 $$->type = ACT_EL_VALUE;
1873 $$->value = asn1p_value_fromref($1, 0);
1874 }
1875 | AtNotationList ',' AtNotationElement {
1876 asn1p_constraint_t *ct;
1877 ct = asn1p_constraint_new(yylineno);
1878 checkmem(ct);
1879 ct->type = ACT_EL_VALUE;
1880 ct->value = asn1p_value_fromref($3, 0);
vlm9fe7c922005-08-12 10:08:45 +00001881 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlmfa67ddc2004-06-03 03:38:44 +00001882 }
1883 ;
1884
1885/*
1886 * @blah
1887 */
1888AtNotationElement:
1889 '@' ComponentIdList {
1890 char *p = malloc(strlen($2) + 2);
1891 int ret;
1892 *p = '@';
1893 strcpy(p + 1, $2);
1894 $$ = asn1p_ref_new(yylineno);
1895 ret = asn1p_ref_add_component($$, p, 0);
1896 checkmem(ret == 0);
1897 free(p);
1898 free($2);
1899 }
1900 | '@' '.' ComponentIdList {
1901 char *p = malloc(strlen($3) + 3);
1902 int ret;
1903 p[0] = '@';
1904 p[1] = '.';
1905 strcpy(p + 2, $3);
1906 $$ = asn1p_ref_new(yylineno);
1907 ret = asn1p_ref_add_component($$, p, 0);
1908 checkmem(ret == 0);
1909 free(p);
1910 free($3);
1911 }
1912 ;
1913
1914/* identifier "." ... */
1915ComponentIdList:
1916 Identifier {
1917 $$ = $1;
1918 }
1919 | ComponentIdList '.' Identifier {
1920 int l1 = strlen($1);
1921 int l3 = strlen($3);
1922 $$ = malloc(l1 + 1 + l3 + 1);
1923 memcpy($$, $1, l1);
1924 $$[l1] = '.';
1925 memcpy($$ + l1 + 1, $3, l3);
1926 $$[l1 + 1 + l3] = '\0';
1927 }
1928 ;
1929
1930
1931
1932/*
1933 * MARKERS
1934 */
1935
1936optMarker:
vlmc94e28f2004-09-15 11:59:51 +00001937 {
1938 $$.flags = EM_NOMARK;
1939 $$.default_value = 0;
1940 }
vlmfa67ddc2004-06-03 03:38:44 +00001941 | Marker { $$ = $1; }
1942 ;
1943
1944Marker:
1945 TOK_OPTIONAL {
vlm1ac75e72005-11-26 11:21:55 +00001946 $$.flags = EM_OPTIONAL | EM_INDIRECT;
vlmc94e28f2004-09-15 11:59:51 +00001947 $$.default_value = 0;
vlmfa67ddc2004-06-03 03:38:44 +00001948 }
vlmc94e28f2004-09-15 11:59:51 +00001949 | TOK_DEFAULT Value {
1950 $$.flags = EM_DEFAULT;
1951 $$.default_value = $2;
vlmfa67ddc2004-06-03 03:38:44 +00001952 }
1953 ;
1954
1955/*
1956 * Universal enumeration definition to use in INTEGER and ENUMERATED.
1957 * === EXAMPLE ===
1958 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
1959 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
1960 * === EOF ===
1961 */
1962/*
1963optUniverationDefinition:
1964 { $$ = 0; }
1965 | UniverationDefinition {
1966 $$ = $1;
1967 }
1968 ;
1969*/
1970
1971UniverationDefinition:
1972 '{' '}' {
vlm39e5ed72004-09-05 10:40:41 +00001973 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001974 checkmem($$);
1975 }
1976 | '{' UniverationList '}' {
1977 $$ = $2;
1978 }
1979 ;
1980
1981UniverationList:
1982 UniverationElement {
vlm39e5ed72004-09-05 10:40:41 +00001983 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001984 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +00001985 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +00001986 }
1987 | UniverationList ',' UniverationElement {
1988 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +00001989 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001990 }
1991 ;
1992
1993UniverationElement:
1994 Identifier {
vlm39e5ed72004-09-05 10:40:41 +00001995 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001996 checkmem($$);
1997 $$->expr_type = A1TC_UNIVERVAL;
1998 $$->meta_type = AMT_VALUE;
1999 $$->Identifier = $1;
2000 }
2001 | Identifier '(' SignedNumber ')' {
vlm39e5ed72004-09-05 10:40:41 +00002002 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002003 checkmem($$);
2004 $$->expr_type = A1TC_UNIVERVAL;
2005 $$->meta_type = AMT_VALUE;
2006 $$->Identifier = $1;
2007 $$->value = $3;
2008 }
2009 | Identifier '(' DefinedValue ')' {
vlm39e5ed72004-09-05 10:40:41 +00002010 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002011 checkmem($$);
2012 $$->expr_type = A1TC_UNIVERVAL;
2013 $$->meta_type = AMT_VALUE;
2014 $$->Identifier = $1;
2015 $$->value = $3;
2016 }
2017 | SignedNumber {
vlm39e5ed72004-09-05 10:40:41 +00002018 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002019 checkmem($$);
2020 $$->expr_type = A1TC_UNIVERVAL;
2021 $$->meta_type = AMT_VALUE;
2022 $$->value = $1;
2023 }
2024 | TOK_ThreeDots {
vlm39e5ed72004-09-05 10:40:41 +00002025 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002026 checkmem($$);
2027 $$->Identifier = strdup("...");
2028 checkmem($$->Identifier);
2029 $$->expr_type = A1TC_EXTENSIBLE;
2030 $$->meta_type = AMT_VALUE;
2031 }
2032 ;
2033
2034SignedNumber:
2035 TOK_number {
2036 $$ = asn1p_value_fromint($1);
2037 checkmem($$);
2038 }
2039 | TOK_number_negative {
2040 $$ = asn1p_value_fromint($1);
2041 checkmem($$);
2042 }
2043 ;
2044
2045/*
2046 * SEQUENCE definition.
2047 * === EXAMPLE ===
2048 * Struct1 ::= SEQUENCE {
2049 * memb1 Struct2,
2050 * memb2 SEQUENCE OF {
2051 * memb2-1 Struct 3
2052 * }
2053 * }
2054 * === EOF ===
2055 */
2056
2057
2058
2059/*
2060 * SET definition.
2061 * === EXAMPLE ===
2062 * Person ::= SET {
2063 * name [0] PrintableString (SIZE(1..20)),
2064 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2065 * }
2066 * === EOF ===
2067 */
2068
2069optTag:
2070 { memset(&$$, 0, sizeof($$)); }
2071 | Tag { $$ = $1; }
2072 ;
2073
2074Tag:
vlm2728a8d2005-01-23 09:51:44 +00002075 TagTypeValue TagPlicit {
vlmfa67ddc2004-06-03 03:38:44 +00002076 $$ = $1;
vlm2728a8d2005-01-23 09:51:44 +00002077 $$.tag_mode = $2.tag_mode;
vlmfa67ddc2004-06-03 03:38:44 +00002078 }
vlm2728a8d2005-01-23 09:51:44 +00002079 ;
2080
2081TagTypeValue:
2082 '[' TagClass TOK_number ']' {
2083 $$ = $2;
2084 $$.tag_value = $3;
2085 };
2086
2087TagClass:
2088 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2089 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2090 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2091 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2092 ;
2093
2094TagPlicit:
2095 { $$.tag_mode = TM_DEFAULT; }
2096 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2097 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
vlmfa67ddc2004-06-03 03:38:44 +00002098 ;
2099
2100TypeRefName:
2101 TOK_typereference {
2102 checkmem($1);
2103 $$ = $1;
2104 }
vlm9283dbe2004-08-18 04:59:12 +00002105 | TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00002106 checkmem($1);
2107 $$ = $1;
2108 }
2109 ;
2110
vlm9283dbe2004-08-18 04:59:12 +00002111
vlmfa67ddc2004-06-03 03:38:44 +00002112ObjectClassReference:
vlm9283dbe2004-08-18 04:59:12 +00002113 TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00002114 checkmem($1);
2115 $$ = $1;
2116 }
2117 ;
2118
vlm151c0b22004-09-22 16:03:36 +00002119optIdentifier:
2120 { $$ = 0; }
2121 | Identifier {
2122 $$ = $1;
2123 }
vlma5b977d2005-06-06 08:28:58 +00002124 ;
vlm151c0b22004-09-22 16:03:36 +00002125
vlmfa67ddc2004-06-03 03:38:44 +00002126Identifier:
2127 TOK_identifier {
2128 checkmem($1);
2129 $$ = $1;
2130 }
2131 ;
2132
vlmfa67ddc2004-06-03 03:38:44 +00002133%%
2134
2135
2136/*
2137 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2138 */
2139static asn1p_value_t *
2140_convert_bitstring2binary(char *str, int base) {
2141 asn1p_value_t *val;
2142 int slen;
2143 int memlen;
2144 int baselen;
2145 int bits;
2146 uint8_t *binary_vector;
2147 uint8_t *bv_ptr;
2148 uint8_t cur_val;
2149
2150 assert(str);
2151 assert(str[0] == '\'');
2152
2153 switch(base) {
2154 case 'B':
2155 baselen = 1;
2156 break;
2157 case 'H':
2158 baselen = 4;
2159 break;
2160 default:
2161 assert(base == 'B' || base == 'H');
2162 errno = EINVAL;
2163 return NULL;
2164 }
2165
2166 slen = strlen(str);
2167 assert(str[slen - 1] == base);
2168 assert(str[slen - 2] == '\'');
2169
2170 memlen = slen / (8 / baselen); /* Conservative estimate */
2171
2172 bv_ptr = binary_vector = malloc(memlen + 1);
2173 if(bv_ptr == NULL)
2174 /* ENOMEM */
2175 return NULL;
2176
2177 cur_val = 0;
2178 bits = 0;
2179 while(*(++str) != '\'') {
2180 switch(baselen) {
2181 case 1:
2182 switch(*str) {
2183 case '1':
2184 cur_val |= 1 << (7 - (bits % 8));
2185 case '0':
2186 break;
2187 default:
2188 assert(!"_y UNREACH1");
2189 case ' ': case '\r': case '\n':
2190 continue;
2191 }
2192 break;
2193 case 4:
2194 switch(*str) {
2195 case '0': case '1': case '2': case '3': case '4':
2196 case '5': case '6': case '7': case '8': case '9':
2197 cur_val |= (*str - '0') << (4 - (bits % 8));
2198 break;
2199 case 'A': case 'B': case 'C':
2200 case 'D': case 'E': case 'F':
2201 cur_val |= ((*str - 'A') + 10)
2202 << (4 - (bits % 8));
2203 break;
2204 default:
2205 assert(!"_y UNREACH2");
2206 case ' ': case '\r': case '\n':
2207 continue;
2208 }
2209 break;
2210 }
2211
2212 bits += baselen;
2213 if((bits % 8) == 0) {
2214 *bv_ptr++ = cur_val;
2215 cur_val = 0;
2216 }
2217 }
2218
2219 *bv_ptr = cur_val;
2220 assert((bv_ptr - binary_vector) <= memlen);
2221
2222 val = asn1p_value_frombits(binary_vector, bits, 0);
2223 if(val == NULL) {
2224 free(binary_vector);
2225 }
2226
2227 return val;
2228}
2229
vlm5d89c3d2005-08-13 09:07:11 +00002230/*
2231 * For unnamed types (used in old X.208 compliant modules)
2232 * generate some sort of interim names, to not to force human being to fix
2233 * the specification's compliance to modern ASN.1 standards.
2234 */
2235static void
2236_fixup_anonymous_identifier(asn1p_expr_t *expr) {
2237 char *p;
2238 assert(expr->Identifier == 0);
2239
2240 /*
2241 * Try to figure out the type name
2242 * without going too much into details
2243 */
2244 expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type);
2245 if(expr->reference && expr->reference->comp_count > 0)
2246 expr->Identifier = expr->reference->components[0].name;
2247
2248 fprintf(stderr,
2249 "WARNING: Line %d: expected lower-case member identifier, "
2250 "found an unnamed %s.\n"
2251 "WARNING: Obsolete X.208 syntax detected, "
2252 "please give the member a name.\n",
2253 yylineno, expr->Identifier ? expr->Identifier : "type");
2254
2255 if(!expr->Identifier)
2256 expr->Identifier = "unnamed";
2257 expr->Identifier = strdup(expr->Identifier);
2258 assert(expr->Identifier);
2259 /* Make a lowercase identifier from the type name */
2260 for(p = expr->Identifier; *p; p++) {
2261 switch(*p) {
2262 case 'A' ... 'Z': *p += 32; break;
2263 case ' ': *p = '_'; break;
2264 case '-': *p = '_'; break;
2265 }
2266 }
2267 fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". "
2268 "Name clash may occur later.\n",
2269 expr->Identifier);
2270}
2271
vlmfa67ddc2004-06-03 03:38:44 +00002272extern char *asn1p_text;
2273
2274int
2275yyerror(const char *msg) {
2276 fprintf(stderr,
2277 "ASN.1 grammar parse error "
2278 "near line %d (token \"%s\"): %s\n",
vlm39e5ed72004-09-05 10:40:41 +00002279 yylineno, asn1p_text, msg);
vlmfa67ddc2004-06-03 03:38:44 +00002280 return -1;
2281}
2282
2283