blob: 597f77c5205027e880434b702906c6066c8a0a27 [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 */
Lev Walkin57074f12006-03-16 05:11:14 +0000110%token <tv_opaque> TOK_whitespace /* A span of whitespace */
Lev Walkinf15320b2004-06-03 03:38:44 +0000111%token <tv_opaque> TOK_opaque /* opaque data (driven from .y) */
112%token <tv_str> TOK_bstring
113%token <tv_opaque> TOK_cstring
114%token <tv_str> TOK_hstring
115%token <tv_str> TOK_identifier
116%token <a_int> TOK_number
Lev Walkind9574ae2005-03-24 16:22:35 +0000117%token <a_int> TOK_tuple
118%token <a_int> TOK_quadruple
Lev Walkinf15320b2004-06-03 03:38:44 +0000119%token <a_int> TOK_number_negative
120%token <tv_str> TOK_typereference
Lev Walkinf59d0752004-08-18 04:59:12 +0000121%token <tv_str> TOK_capitalreference /* "CLASS1" */
Lev Walkinf15320b2004-06-03 03:38:44 +0000122%token <tv_str> TOK_typefieldreference /* "&Pork" */
123%token <tv_str> TOK_valuefieldreference /* "&id" */
Lev Walkin9d542d22006-03-14 16:31:37 +0000124%token <tv_str> TOK_Literal /* "BY" */
Lev Walkinf15320b2004-06-03 03:38:44 +0000125
126/*
127 * Token types representing ASN.1 standard keywords.
128 */
129%token TOK_ABSENT
130%token TOK_ABSTRACT_SYNTAX
131%token TOK_ALL
132%token TOK_ANY
133%token TOK_APPLICATION
134%token TOK_AUTOMATIC
135%token TOK_BEGIN
136%token TOK_BIT
137%token TOK_BMPString
138%token TOK_BOOLEAN
139%token TOK_BY
140%token TOK_CHARACTER
141%token TOK_CHOICE
142%token TOK_CLASS
143%token TOK_COMPONENT
144%token TOK_COMPONENTS
145%token TOK_CONSTRAINED
146%token TOK_CONTAINING
147%token TOK_DEFAULT
148%token TOK_DEFINITIONS
149%token TOK_DEFINED
150%token TOK_EMBEDDED
151%token TOK_ENCODED
Lev Walkinf59d0752004-08-18 04:59:12 +0000152%token TOK_ENCODING_CONTROL
Lev Walkinf15320b2004-06-03 03:38:44 +0000153%token TOK_END
154%token TOK_ENUMERATED
155%token TOK_EXPLICIT
156%token TOK_EXPORTS
157%token TOK_EXTENSIBILITY
158%token TOK_EXTERNAL
159%token TOK_FALSE
160%token TOK_FROM
161%token TOK_GeneralizedTime
162%token TOK_GeneralString
163%token TOK_GraphicString
164%token TOK_IA5String
165%token TOK_IDENTIFIER
166%token TOK_IMPLICIT
167%token TOK_IMPLIED
168%token TOK_IMPORTS
169%token TOK_INCLUDES
170%token TOK_INSTANCE
Lev Walkinf59d0752004-08-18 04:59:12 +0000171%token TOK_INSTRUCTIONS
Lev Walkinf15320b2004-06-03 03:38:44 +0000172%token TOK_INTEGER
173%token TOK_ISO646String
174%token TOK_MAX
175%token TOK_MIN
176%token TOK_MINUS_INFINITY
177%token TOK_NULL
178%token TOK_NumericString
179%token TOK_OBJECT
180%token TOK_ObjectDescriptor
181%token TOK_OCTET
182%token TOK_OF
183%token TOK_OPTIONAL
184%token TOK_PATTERN
185%token TOK_PDV
186%token TOK_PLUS_INFINITY
187%token TOK_PRESENT
188%token TOK_PrintableString
189%token TOK_PRIVATE
190%token TOK_REAL
191%token TOK_RELATIVE_OID
192%token TOK_SEQUENCE
193%token TOK_SET
194%token TOK_SIZE
195%token TOK_STRING
196%token TOK_SYNTAX
197%token TOK_T61String
198%token TOK_TAGS
199%token TOK_TeletexString
200%token TOK_TRUE
201%token TOK_TYPE_IDENTIFIER
202%token TOK_UNIQUE
203%token TOK_UNIVERSAL
204%token TOK_UniversalString
205%token TOK_UTCTime
206%token TOK_UTF8String
207%token TOK_VideotexString
208%token TOK_VisibleString
209%token TOK_WITH
210
Lev Walkinf15320b2004-06-03 03:38:44 +0000211%left TOK_EXCEPT
Lev Walkinf59d0752004-08-18 04:59:12 +0000212%left '^' TOK_INTERSECTION
213%left '|' TOK_UNION
Lev Walkinf15320b2004-06-03 03:38:44 +0000214
215/* Misc tags */
216%token TOK_TwoDots /* .. */
217%token TOK_ThreeDots /* ... */
Lev Walkinf15320b2004-06-03 03:38:44 +0000218
219
220/*
221 * Types defined herein.
222 */
223%type <a_grammar> ModuleList
224%type <a_module> ModuleSpecification
225%type <a_module> ModuleSpecificationBody
226%type <a_module> ModuleSpecificationElement
227%type <a_module> optModuleSpecificationBody /* Optional */
228%type <a_module_flags> optModuleSpecificationFlags
229%type <a_module_flags> ModuleSpecificationFlags /* Set of FL */
230%type <a_module_flags> ModuleSpecificationFlag /* Single FL */
231%type <a_module> ImportsDefinition
232%type <a_module> ImportsBundleSet
233%type <a_xports> ImportsBundle
234%type <a_xports> ImportsList
235%type <a_xports> ExportsDefinition
236%type <a_xports> ExportsBody
237%type <a_expr> ImportsElement
238%type <a_expr> ExportsElement
Lev Walkinf15320b2004-06-03 03:38:44 +0000239%type <a_expr> ExtensionAndException
Lev Walkin070a52d2004-08-22 03:19:54 +0000240%type <a_expr> TypeDeclaration
Lev Walkin4696c742005-08-22 12:23:54 +0000241%type <a_expr> TypeDeclarationSet
Lev Walkinf15320b2004-06-03 03:38:44 +0000242%type <a_ref> ComplexTypeReference
243%type <a_ref> ComplexTypeReferenceAmpList
244%type <a_refcomp> ComplexTypeReferenceElement
Lev Walkind370e9f2006-03-16 10:03:35 +0000245%type <a_refcomp> PrimitiveFieldReference
Lev Walkin9c2285a2006-03-09 08:49:26 +0000246%type <a_expr> FieldSpec
247%type <a_ref> FieldName
248%type <a_ref> DefinedObjectClass
Lev Walkinf15320b2004-06-03 03:38:44 +0000249%type <a_expr> ClassField
Lev Walkin9c2285a2006-03-09 08:49:26 +0000250%type <a_expr> ObjectClass
Lev Walkin070a52d2004-08-22 03:19:54 +0000251%type <a_expr> Type
Lev Walkinf15320b2004-06-03 03:38:44 +0000252%type <a_expr> DataTypeReference /* Type1 ::= Type2 */
Lev Walkin0c0bca62006-03-21 04:48:15 +0000253%type <a_expr> DefinedType
Lev Walkin557f27d2006-03-21 07:46:48 +0000254%type <a_constr> ValueSet /* {a|b|c}*/
255%type <a_expr> ValueSetTypeAssignment /* Val INTEGER ::= {1|2} */
Lev Walkinf15320b2004-06-03 03:38:44 +0000256%type <a_expr> ValueDefinition /* val INTEGER ::= 1*/
Lev Walkin9c974182004-09-15 11:59:51 +0000257%type <a_value> Value
Lev Walkin0c0bca62006-03-21 04:48:15 +0000258%type <a_value> SimpleValue
Lev Walkinf15320b2004-06-03 03:38:44 +0000259%type <a_value> DefinedValue
260%type <a_value> SignedNumber
Lev Walkin144db9b2004-10-12 23:26:53 +0000261%type <a_expr> optComponentTypeLists
Lev Walkin070a52d2004-08-22 03:19:54 +0000262%type <a_expr> ComponentTypeLists
263%type <a_expr> ComponentType
264%type <a_expr> AlternativeTypeLists
265%type <a_expr> AlternativeType
Lev Walkinf15320b2004-06-03 03:38:44 +0000266%type <a_expr> UniverationDefinition
267%type <a_expr> UniverationList
268%type <a_expr> UniverationElement
269%type <tv_str> TypeRefName
270%type <tv_str> ObjectClassReference
Lev Walkinf15320b2004-06-03 03:38:44 +0000271%type <tv_str> Identifier
Lev Walkin83cac2f2004-09-22 16:03:36 +0000272%type <tv_str> optIdentifier
Lev Walkinf15320b2004-06-03 03:38:44 +0000273%type <a_parg> ParameterArgumentName
274%type <a_plist> ParameterArgumentList
Lev Walkina00d6b32006-03-21 03:40:38 +0000275%type <a_expr> Specialization
276%type <a_expr> Specializations
Lev Walkin1ed22092005-08-12 10:06:17 +0000277%type <a_aid> AssignedIdentifier /* OID/DefinedValue */
Lev Walkinf15320b2004-06-03 03:38:44 +0000278%type <a_oid> ObjectIdentifier /* OID */
279%type <a_oid> optObjectIdentifier /* Optional OID */
280%type <a_oid> ObjectIdentifierBody
281%type <a_oid_arc> ObjectIdentifierElement
282%type <a_expr> BasicType
283%type <a_type> BasicTypeId
284%type <a_type> BasicTypeId_UniverationCompatible
285%type <a_type> BasicString
286%type <tv_opaque> Opaque
Lev Walkinc603f102005-01-23 09:51:44 +0000287%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
288%type <a_tag> TagClass TagTypeValue TagPlicit
Lev Walkinf15320b2004-06-03 03:38:44 +0000289%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
290%type <a_constr> optConstraints
Lev Walkind2ea1de2004-08-20 13:25:29 +0000291%type <a_constr> Constraints
Lev Walkinf59d0752004-08-18 04:59:12 +0000292%type <a_constr> SetOfConstraints
293%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
294%type <a_constr> ElementSetSpec /* 1..2,...,3 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000295%type <a_constr> ConstraintSubtypeElement /* 1..2 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000296%type <a_constr> SimpleTableConstraint
297%type <a_constr> TableConstraint
Lev Walkine596bf02005-03-28 15:01:27 +0000298%type <a_constr> InnerTypeConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +0000299%type <a_constr> WithComponentsList
300%type <a_constr> WithComponentsElement
301%type <a_constr> ComponentRelationConstraint
302%type <a_constr> AtNotationList
303%type <a_ref> AtNotationElement
Lev Walkinff7dd142005-03-20 12:58:00 +0000304%type <a_value> SingleValue
305%type <a_value> ContainedSubtype
Lev Walkinf15320b2004-06-03 03:38:44 +0000306%type <a_ctype> ConstraintSpec
307%type <a_ctype> ConstraintRangeSpec
Lev Walkin1e448d32005-03-24 14:26:38 +0000308%type <a_value> RestrictedCharacterStringValue
Lev Walkinf15320b2004-06-03 03:38:44 +0000309%type <a_wsynt> optWithSyntax
310%type <a_wsynt> WithSyntax
Lev Walkin9d542d22006-03-14 16:31:37 +0000311%type <a_wsynt> WithSyntaxList
312%type <a_wchunk> WithSyntaxToken
Lev Walkinf15320b2004-06-03 03:38:44 +0000313%type <a_marker> optMarker Marker
314%type <a_int> optUnique
315%type <a_pres> optPresenceConstraint PresenceConstraint
316%type <tv_str> ComponentIdList
Lev Walkinef625402005-09-05 05:17:57 +0000317%type <a_int> NSTD_IndirectMarker
Lev Walkinf15320b2004-06-03 03:38:44 +0000318
319
320%%
321
322
323ParsedGrammar:
324 ModuleList {
325 *(void **)param = $1;
326 }
327 ;
328
329ModuleList:
330 ModuleSpecification {
331 $$ = asn1p_new();
332 checkmem($$);
333 TQ_ADD(&($$->modules), $1, mod_next);
334 }
335 | ModuleList ModuleSpecification {
336 $$ = $1;
337 TQ_ADD(&($$->modules), $2, mod_next);
338 }
339 ;
340
341/*
342 * ASN module definition.
343 * === EXAMPLE ===
344 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
345 * BEGIN
346 * ...
347 * END
348 * === EOF ===
349 */
350
351ModuleSpecification:
352 TypeRefName optObjectIdentifier TOK_DEFINITIONS
353 optModuleSpecificationFlags
354 TOK_PPEQ TOK_BEGIN
355 optModuleSpecificationBody
356 TOK_END {
357
358 if($7) {
359 $$ = $7;
360 } else {
361 /* There's a chance that a module is just plain empty */
362 $$ = asn1p_module_new();
363 }
364 checkmem($$);
365
Lev Walkin1ed22092005-08-12 10:06:17 +0000366 $$->ModuleName = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000367 $$->module_oid = $2;
368 $$->module_flags = $4;
369 }
370 ;
371
372/*
373 * Object Identifier Definition
374 * { iso member-body(2) 3 }
375 */
376optObjectIdentifier:
377 { $$ = 0; }
378 | ObjectIdentifier { $$ = $1; }
379 ;
380
381ObjectIdentifier:
382 '{' ObjectIdentifierBody '}' {
383 $$ = $2;
384 }
385 | '{' '}' {
386 $$ = 0;
387 }
388 ;
389
390ObjectIdentifierBody:
391 ObjectIdentifierElement {
392 $$ = asn1p_oid_new();
393 asn1p_oid_add_arc($$, &$1);
394 if($1.name)
395 free($1.name);
396 }
397 | ObjectIdentifierBody ObjectIdentifierElement {
398 $$ = $1;
399 asn1p_oid_add_arc($$, &$2);
400 if($2.name)
401 free($2.name);
402 }
403 ;
404
405ObjectIdentifierElement:
406 Identifier { /* iso */
407 $$.name = $1;
408 $$.number = -1;
409 }
410 | Identifier '(' TOK_number ')' { /* iso(1) */
411 $$.name = $1;
412 $$.number = $3;
413 }
414 | TOK_number { /* 1 */
415 $$.name = 0;
416 $$.number = $1;
417 }
418 ;
419
420/*
421 * Optional module flags.
422 */
423optModuleSpecificationFlags:
424 { $$ = MSF_NOFLAGS; }
425 | ModuleSpecificationFlags {
426 $$ = $1;
427 }
428 ;
429
430/*
431 * Module flags.
432 */
433ModuleSpecificationFlags:
434 ModuleSpecificationFlag {
435 $$ = $1;
436 }
437 | ModuleSpecificationFlags ModuleSpecificationFlag {
438 $$ = $1 | $2;
439 }
440 ;
441
442/*
443 * Single module flag.
444 */
445ModuleSpecificationFlag:
446 TOK_EXPLICIT TOK_TAGS {
447 $$ = MSF_EXPLICIT_TAGS;
448 }
449 | TOK_IMPLICIT TOK_TAGS {
450 $$ = MSF_IMPLICIT_TAGS;
451 }
452 | TOK_AUTOMATIC TOK_TAGS {
453 $$ = MSF_AUTOMATIC_TAGS;
454 }
455 | TOK_EXTENSIBILITY TOK_IMPLIED {
456 $$ = MSF_EXTENSIBILITY_IMPLIED;
457 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000458 /* EncodingReferenceDefault */
459 | TOK_capitalreference TOK_INSTRUCTIONS {
460 /* X.680Amd1 specifies TAG and XER */
461 if(strcmp($1, "TAG") == 0) {
462 $$ = MSF_TAG_INSTRUCTIONS;
463 } else if(strcmp($1, "XER") == 0) {
464 $$ = MSF_XER_INSTRUCTIONS;
465 } else {
466 fprintf(stderr,
467 "WARNING: %s INSTRUCTIONS at line %d: "
468 "Unrecognized encoding reference\n",
469 $1, yylineno);
470 $$ = MSF_unk_INSTRUCTIONS;
471 }
472 free($1);
473 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000474 ;
475
476/*
477 * Optional module body.
478 */
479optModuleSpecificationBody:
480 { $$ = 0; }
481 | ModuleSpecificationBody {
Lev Walkinf15320b2004-06-03 03:38:44 +0000482 $$ = $1;
483 }
484 ;
485
486/*
487 * ASN.1 Module body.
488 */
489ModuleSpecificationBody:
490 ModuleSpecificationElement {
491 $$ = $1;
492 }
493 | ModuleSpecificationBody ModuleSpecificationElement {
494 $$ = $1;
495
Lev Walkinf59d0752004-08-18 04:59:12 +0000496 /* Behave well when one of them is skipped. */
497 if(!($1)) {
498 if($2) $$ = $2;
499 break;
500 }
501
Lev Walkinf15320b2004-06-03 03:38:44 +0000502#ifdef MY_IMPORT
503#error MY_IMPORT DEFINED ELSEWHERE!
504#endif
505#define MY_IMPORT(foo,field) do { \
Lev Walkinbc55d232004-08-13 12:31:09 +0000506 while(TQ_FIRST(&($2->foo))) { \
Lev Walkinf15320b2004-06-03 03:38:44 +0000507 TQ_ADD(&($$->foo), \
508 TQ_REMOVE(&($2->foo), field), \
509 field); \
Lev Walkinbc55d232004-08-13 12:31:09 +0000510 } \
511 assert(TQ_FIRST(&($2->foo)) == 0); \
512 } while(0)
Lev Walkinf15320b2004-06-03 03:38:44 +0000513
514 MY_IMPORT(imports, xp_next);
515 MY_IMPORT(exports, xp_next);
516 MY_IMPORT(members, next);
517#undef MY_IMPORT
518
519 }
520 ;
521
522/*
523 * One of the elements of ASN.1 module specification.
524 */
525ModuleSpecificationElement:
526 ImportsDefinition {
527 $$ = $1;
528 }
529 | ExportsDefinition {
530 $$ = asn1p_module_new();
531 checkmem($$);
532 if($1) {
533 TQ_ADD(&($$->exports), $1, xp_next);
534 } else {
535 /* "EXPORTS ALL;" ? */
536 }
537 }
538 | DataTypeReference {
539 $$ = asn1p_module_new();
540 checkmem($$);
541 assert($1->expr_type != A1TC_INVALID);
542 assert($1->meta_type != AMT_INVALID);
543 TQ_ADD(&($$->members), $1, next);
544 }
545 | ValueDefinition {
546 $$ = asn1p_module_new();
547 checkmem($$);
548 assert($1->expr_type != A1TC_INVALID);
549 assert($1->meta_type != AMT_INVALID);
550 TQ_ADD(&($$->members), $1, next);
551 }
552 /*
553 * Value set definition
554 * === EXAMPLE ===
555 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
556 * === EOF ===
557 */
Lev Walkin557f27d2006-03-21 07:46:48 +0000558 | ValueSetTypeAssignment {
Lev Walkinf15320b2004-06-03 03:38:44 +0000559 $$ = asn1p_module_new();
560 checkmem($$);
561 assert($1->expr_type != A1TC_INVALID);
562 assert($1->meta_type != AMT_INVALID);
563 TQ_ADD(&($$->members), $1, next);
564 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000565 | TOK_ENCODING_CONTROL TOK_capitalreference
566 { asn1p_lexer_hack_push_encoding_control(); }
567 {
568 fprintf(stderr,
569 "WARNING: ENCODING-CONTROL %s "
570 "specification at line %d ignored\n",
571 $2, yylineno);
572 free($2);
573 $$ = 0;
574 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000575
576 /*
577 * Erroneous attemps
578 */
579 | BasicString {
580 return yyerror(
Lev Walkin70853052005-11-26 11:21:55 +0000581 "Attempt to redefine a standard basic string type, "
582 "please comment out or remove this type redefinition.");
Lev Walkinf15320b2004-06-03 03:38:44 +0000583 }
584 ;
585
586/*
587 * === EXAMPLE ===
588 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
589 * === EOF ===
590 */
591ImportsDefinition:
592 TOK_IMPORTS ImportsBundleSet ';' {
Lev Walkin1ed22092005-08-12 10:06:17 +0000593 if(!saved_aid && 0)
594 return yyerror("Unterminated IMPORTS FROM, "
595 "expected semicolon ';'");
596 saved_aid = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +0000597 $$ = $2;
598 }
599 /*
600 * Some error cases.
601 */
602 | TOK_IMPORTS TOK_FROM /* ... */ {
603 return yyerror("Empty IMPORTS list");
604 }
605 ;
606
607ImportsBundleSet:
608 ImportsBundle {
609 $$ = asn1p_module_new();
610 checkmem($$);
611 TQ_ADD(&($$->imports), $1, xp_next);
612 }
613 | ImportsBundleSet ImportsBundle {
614 $$ = $1;
615 TQ_ADD(&($$->imports), $2, xp_next);
616 }
617 ;
618
Lev Walkin1ed22092005-08-12 10:06:17 +0000619AssignedIdentifier:
620 { memset(&$$, 0, sizeof($$)); }
621 | ObjectIdentifier { $$.oid = $1; };
622 /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
623
Lev Walkinf15320b2004-06-03 03:38:44 +0000624ImportsBundle:
Lev Walkin1ed22092005-08-12 10:06:17 +0000625 ImportsList TOK_FROM TypeRefName AssignedIdentifier {
Lev Walkinf15320b2004-06-03 03:38:44 +0000626 $$ = $1;
Lev Walkin1ed22092005-08-12 10:06:17 +0000627 $$->fromModuleName = $3;
628 $$->identifier = $4;
629 /* This stupid thing is used for look-back hack. */
630 saved_aid = $$->identifier.oid ? 0 : &($$->identifier);
Lev Walkinf15320b2004-06-03 03:38:44 +0000631 checkmem($$);
632 }
633 ;
634
635ImportsList:
636 ImportsElement {
637 $$ = asn1p_xports_new();
638 checkmem($$);
639 TQ_ADD(&($$->members), $1, next);
640 }
641 | ImportsList ',' ImportsElement {
642 $$ = $1;
643 TQ_ADD(&($$->members), $3, next);
644 }
645 ;
646
647ImportsElement:
648 TypeRefName {
649 $$ = asn1p_expr_new(yylineno);
650 checkmem($$);
651 $$->Identifier = $1;
652 $$->expr_type = A1TC_REFERENCE;
653 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000654 | TypeRefName '{' '}' { /* Completely equivalent to above */
655 $$ = asn1p_expr_new(yylineno);
656 checkmem($$);
657 $$->Identifier = $1;
658 $$->expr_type = A1TC_REFERENCE;
659 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000660 | Identifier {
661 $$ = asn1p_expr_new(yylineno);
662 checkmem($$);
663 $$->Identifier = $1;
664 $$->expr_type = A1TC_REFERENCE;
665 }
666 ;
667
668ExportsDefinition:
669 TOK_EXPORTS ExportsBody ';' {
670 $$ = $2;
671 }
672 | TOK_EXPORTS TOK_ALL ';' {
673 $$ = 0;
674 }
675 | TOK_EXPORTS ';' {
676 /* Empty EXPORTS clause effectively prohibits export. */
677 $$ = asn1p_xports_new();
678 checkmem($$);
679 }
680 ;
681
682ExportsBody:
683 ExportsElement {
684 $$ = asn1p_xports_new();
685 assert($$);
686 TQ_ADD(&($$->members), $1, next);
687 }
688 | ExportsBody ',' ExportsElement {
689 $$ = $1;
690 TQ_ADD(&($$->members), $3, next);
691 }
692 ;
693
694ExportsElement:
695 TypeRefName {
696 $$ = asn1p_expr_new(yylineno);
697 checkmem($$);
698 $$->Identifier = $1;
699 $$->expr_type = A1TC_EXPORTVAR;
700 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000701 | TypeRefName '{' '}' {
702 $$ = asn1p_expr_new(yylineno);
703 checkmem($$);
704 $$->Identifier = $1;
705 $$->expr_type = A1TC_EXPORTVAR;
706 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000707 | Identifier {
708 $$ = asn1p_expr_new(yylineno);
709 checkmem($$);
710 $$->Identifier = $1;
711 $$->expr_type = A1TC_EXPORTVAR;
712 }
713 ;
714
715
Lev Walkin557f27d2006-03-21 07:46:48 +0000716ValueSet: '{' ElementSetSpecs '}' { $$ = $2; }
717
718ValueSetTypeAssignment:
719 TypeRefName DefinedType TOK_PPEQ ValueSet {
Lev Walkinf15320b2004-06-03 03:38:44 +0000720 $$ = $2;
721 assert($$->Identifier == 0);
722 $$->Identifier = $1;
723 $$->meta_type = AMT_VALUESET;
Lev Walkin557f27d2006-03-21 07:46:48 +0000724 $$->constraints = $4;
Lev Walkinf15320b2004-06-03 03:38:44 +0000725 }
726 ;
727
Lev Walkin0c0bca62006-03-21 04:48:15 +0000728DefinedType:
729 BasicType {
730 $$ = $1;
731 }
732 /*
733 * A DefinedType reference.
734 * "CLASS1.&id.&id2"
735 * or
736 * "Module.Type"
737 * or
738 * "Module.identifier"
739 * or
740 * "Type"
741 */
742 | ComplexTypeReference {
Lev Walkinf15320b2004-06-03 03:38:44 +0000743 $$ = asn1p_expr_new(yylineno);
744 checkmem($$);
745 $$->reference = $1;
746 $$->expr_type = A1TC_REFERENCE;
747 $$->meta_type = AMT_TYPEREF;
748 }
Lev Walkin0c0bca62006-03-21 04:48:15 +0000749 /*
750 * A parametrized assignment.
751 */
752 | ComplexTypeReference '{' Specializations '}' {
Lev Walkinf15320b2004-06-03 03:38:44 +0000753 $$ = asn1p_expr_new(yylineno);
754 checkmem($$);
Lev Walkin0c0bca62006-03-21 04:48:15 +0000755 $$->reference = $1;
756 $$->rhs_pspecs = $3;
757 $$->expr_type = A1TC_REFERENCE;
758 $$->meta_type = AMT_TYPEREF;
Lev Walkinf15320b2004-06-03 03:38:44 +0000759 }
760 ;
761
Lev Walkinf15320b2004-06-03 03:38:44 +0000762/*
763 * Data Type Reference.
764 * === EXAMPLE ===
765 * Type3 ::= CHOICE { a Type1, b Type 2 }
766 * === EOF ===
767 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000768DataTypeReference:
769 /*
770 * Optionally tagged type definition.
771 */
Lev Walkin9c2285a2006-03-09 08:49:26 +0000772 TypeRefName TOK_PPEQ Type {
Lev Walkinaf120f72004-09-14 02:36:39 +0000773 $$ = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000774 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000775 assert($$->expr_type);
776 assert($$->meta_type);
777 }
Lev Walkin9c2285a2006-03-09 08:49:26 +0000778 | TypeRefName TOK_PPEQ ObjectClass {
Lev Walkinf15320b2004-06-03 03:38:44 +0000779 $$ = $3;
780 $$->Identifier = $1;
781 assert($$->expr_type == A1TC_CLASSDEF);
Lev Walkin9c2285a2006-03-09 08:49:26 +0000782 assert($$->meta_type == AMT_OBJECTCLASS);
Lev Walkinf15320b2004-06-03 03:38:44 +0000783 }
784 /*
785 * Parametrized <Type> declaration:
786 * === EXAMPLE ===
787 * SIGNED { ToBeSigned } ::= SEQUENCE {
788 * toBeSigned ToBeSigned,
789 * algorithm AlgorithmIdentifier,
790 * signature BIT STRING
791 * }
792 * === EOF ===
793 */
Lev Walkin070a52d2004-08-22 03:19:54 +0000794 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000795 $$ = $6;
796 assert($$->Identifier == 0);
797 $$->Identifier = $1;
Lev Walkina00d6b32006-03-21 03:40:38 +0000798 $$->lhs_params = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000799 }
800 ;
801
802ParameterArgumentList:
803 ParameterArgumentName {
804 int ret;
805 $$ = asn1p_paramlist_new(yylineno);
806 checkmem($$);
807 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
808 checkmem(ret == 0);
809 if($1.governor) asn1p_ref_free($1.governor);
810 if($1.argument) free($1.argument);
811 }
812 | ParameterArgumentList ',' ParameterArgumentName {
813 int ret;
814 $$ = $1;
815 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
816 checkmem(ret == 0);
817 if($3.governor) asn1p_ref_free($3.governor);
818 if($3.argument) free($3.argument);
819 }
820 ;
821
822ParameterArgumentName:
823 TypeRefName {
824 $$.governor = NULL;
825 $$.argument = $1;
826 }
827 | TypeRefName ':' Identifier {
828 int ret;
829 $$.governor = asn1p_ref_new(yylineno);
830 ret = asn1p_ref_add_component($$.governor, $1, 0);
831 checkmem(ret == 0);
832 $$.argument = $3;
833 }
Lev Walkinc8092cb2005-02-18 16:34:21 +0000834 | TypeRefName ':' TypeRefName {
835 int ret;
836 $$.governor = asn1p_ref_new(yylineno);
837 ret = asn1p_ref_add_component($$.governor, $1, 0);
838 checkmem(ret == 0);
839 $$.argument = $3;
840 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000841 | BasicTypeId ':' Identifier {
842 int ret;
843 $$.governor = asn1p_ref_new(yylineno);
844 ret = asn1p_ref_add_component($$.governor,
845 ASN_EXPR_TYPE2STR($1), 1);
846 checkmem(ret == 0);
847 $$.argument = $3;
848 }
849 ;
850
Lev Walkina00d6b32006-03-21 03:40:38 +0000851Specializations:
852 Specialization {
Lev Walkinf15320b2004-06-03 03:38:44 +0000853 $$ = asn1p_expr_new(yylineno);
854 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000855 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000856 }
Lev Walkina00d6b32006-03-21 03:40:38 +0000857 | Specializations ',' Specialization {
Lev Walkinf15320b2004-06-03 03:38:44 +0000858 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000859 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000860 }
861 ;
862
Lev Walkina00d6b32006-03-21 03:40:38 +0000863Specialization:
Lev Walkin070a52d2004-08-22 03:19:54 +0000864 Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000865 $$ = $1;
866 }
Lev Walkin0c0bca62006-03-21 04:48:15 +0000867 | SimpleValue {
868 $$ = asn1p_expr_new(yylineno);
869 checkmem($$);
870 $$->Identifier = "?";
871 $$->expr_type = A1TC_REFERENCE;
872 $$->meta_type = AMT_VALUE;
873 $$->value = $1;
874 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000875 | Identifier {
Lev Walkina00d6b32006-03-21 03:40:38 +0000876 asn1p_ref_t *ref;
Lev Walkinf15320b2004-06-03 03:38:44 +0000877 $$ = asn1p_expr_new(yylineno);
878 checkmem($$);
879 $$->Identifier = $1;
880 $$->expr_type = A1TC_REFERENCE;
881 $$->meta_type = AMT_VALUE;
Lev Walkina00d6b32006-03-21 03:40:38 +0000882 ref = asn1p_ref_new(yylineno);
883 asn1p_ref_add_component(ref, $1, RLT_lowercase);
884 $$->value = asn1p_value_fromref(ref, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +0000885 }
886 ;
887
888/*
Lev Walkina00d6b32006-03-21 03:40:38 +0000889 | '{' Specialization '}' {
Lev Walkinc8092cb2005-02-18 16:34:21 +0000890 $$ = asn1p_expr_new(yylineno);
891 checkmem($$);
892 asn1p_expr_add($$, $2);
893 $$->expr_type = A1TC_PARAMETRIZED;
894 $$->meta_type = AMT_TYPE;
895 }
896 ;
897*/
898
899/*
Lev Walkinf15320b2004-06-03 03:38:44 +0000900 * A collection of constructed data type members.
901 */
Lev Walkin144db9b2004-10-12 23:26:53 +0000902optComponentTypeLists:
903 { $$ = asn1p_expr_new(yylineno); }
904 | ComponentTypeLists { $$ = $1; };
905
Lev Walkin070a52d2004-08-22 03:19:54 +0000906ComponentTypeLists:
907 ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +0000908 $$ = asn1p_expr_new(yylineno);
909 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000910 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000911 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000912 | ComponentTypeLists ',' ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +0000913 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000914 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000915 }
916 ;
917
Lev Walkin070a52d2004-08-22 03:19:54 +0000918ComponentType:
Lev Walkinaf120f72004-09-14 02:36:39 +0000919 Identifier Type optMarker {
Lev Walkin070a52d2004-08-22 03:19:54 +0000920 $$ = $2;
921 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +0000922 $$->Identifier = $1;
Lev Walkinef625402005-09-05 05:17:57 +0000923 $3.flags |= $$->marker.flags;
Lev Walkin070a52d2004-08-22 03:19:54 +0000924 $$->marker = $3;
925 }
Lev Walkinef625402005-09-05 05:17:57 +0000926 | Type optMarker {
927 $$ = $1;
928 $2.flags |= $$->marker.flags;
929 $$->marker = $2;
930 _fixup_anonymous_identifier($$);
931 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000932 | TOK_COMPONENTS TOK_OF Type {
933 $$ = asn1p_expr_new(yylineno);
934 checkmem($$);
935 $$->meta_type = $3->meta_type;
936 $$->expr_type = A1TC_COMPONENTS_OF;
Lev Walkin1004aa92004-09-08 00:28:11 +0000937 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +0000938 }
939 | ExtensionAndException {
940 $$ = $1;
941 }
942 ;
943
944AlternativeTypeLists:
945 AlternativeType {
946 $$ = asn1p_expr_new(yylineno);
947 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000948 asn1p_expr_add($$, $1);
Lev Walkin070a52d2004-08-22 03:19:54 +0000949 }
950 | AlternativeTypeLists ',' AlternativeType {
951 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000952 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +0000953 }
954 ;
955
956AlternativeType:
Lev Walkinaf120f72004-09-14 02:36:39 +0000957 Identifier Type {
Lev Walkin070a52d2004-08-22 03:19:54 +0000958 $$ = $2;
959 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +0000960 $$->Identifier = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +0000961 }
962 | ExtensionAndException {
963 $$ = $1;
964 }
Lev Walkin2e9bd5c2005-08-13 09:07:11 +0000965 | Type {
966 $$ = $1;
967 _fixup_anonymous_identifier($$);
968 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000969 ;
970
Lev Walkin9c2285a2006-03-09 08:49:26 +0000971ObjectClass:
972 TOK_CLASS '{' FieldSpec '}' optWithSyntax {
Lev Walkinf15320b2004-06-03 03:38:44 +0000973 $$ = $3;
974 checkmem($$);
975 $$->with_syntax = $5;
976 assert($$->expr_type == A1TC_CLASSDEF);
Lev Walkin9c2285a2006-03-09 08:49:26 +0000977 assert($$->meta_type == AMT_OBJECTCLASS);
Lev Walkinf15320b2004-06-03 03:38:44 +0000978 }
979 ;
980
981optUnique:
982 { $$ = 0; }
983 | TOK_UNIQUE { $$ = 1; }
984 ;
985
Lev Walkin9c2285a2006-03-09 08:49:26 +0000986FieldSpec:
Lev Walkinf15320b2004-06-03 03:38:44 +0000987 ClassField {
988 $$ = asn1p_expr_new(yylineno);
989 checkmem($$);
990 $$->expr_type = A1TC_CLASSDEF;
Lev Walkin9c2285a2006-03-09 08:49:26 +0000991 $$->meta_type = AMT_OBJECTCLASS;
Lev Walkin1004aa92004-09-08 00:28:11 +0000992 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000993 }
Lev Walkin9c2285a2006-03-09 08:49:26 +0000994 | FieldSpec ',' ClassField {
Lev Walkinf15320b2004-06-03 03:38:44 +0000995 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000996 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000997 }
998 ;
999
Lev Walkin9c2285a2006-03-09 08:49:26 +00001000 /* X.681 */
Lev Walkinf15320b2004-06-03 03:38:44 +00001001ClassField:
Lev Walkin9c2285a2006-03-09 08:49:26 +00001002
1003 /* TypeFieldSpec ::= typefieldreference TypeOptionalitySpec? */
1004 TOK_typefieldreference optMarker {
Lev Walkinf15320b2004-06-03 03:38:44 +00001005 $$ = asn1p_expr_new(yylineno);
1006 checkmem($$);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001007 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001008 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001009 $$->expr_type = A1TC_CLASSFIELD_TFS; /* TypeFieldSpec */
Lev Walkinf15320b2004-06-03 03:38:44 +00001010 $$->marker = $2;
1011 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001012
1013 /* FixedTypeValueFieldSpec ::= valuefieldreference Type UNIQUE ? ValueOptionalitySpec ? */
1014 | TOK_valuefieldreference Type optUnique optMarker {
1015 $$ = asn1p_expr_new(yylineno);
1016 $$->Identifier = $1;
1017 $$->meta_type = AMT_OBJECTFIELD;
1018 $$->expr_type = A1TC_CLASSFIELD_FTVFS; /* FixedTypeValueFieldSpec */
Lev Walkinb7c45ca2004-11-24 17:43:29 +00001019 $$->unique = $3;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001020 $$->marker = $4;
1021 asn1p_expr_add($$, $2);
Lev Walkinf15320b2004-06-03 03:38:44 +00001022 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001023
1024 /* VariableTypeValueFieldSpec ::= valuefieldreference FieldName ValueOptionalitySpec ? */
1025 | TOK_valuefieldreference FieldName optMarker {
1026 $$ = asn1p_expr_new(yylineno);
1027 $$->Identifier = $1;
1028 $$->meta_type = AMT_OBJECTFIELD;
1029 $$->expr_type = A1TC_CLASSFIELD_VTVFS;
1030 $$->reference = $2;
1031 $$->marker = $3;
1032 }
1033
Lev Walkin9c2285a2006-03-09 08:49:26 +00001034 /* ObjectFieldSpec ::= objectfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1035 | TOK_valuefieldreference DefinedObjectClass optMarker {
Lev Walkinf15320b2004-06-03 03:38:44 +00001036 $$ = asn1p_expr_new(yylineno);
1037 checkmem($$);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001038 $$->Identifier = $1;
1039 $$->reference = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00001040 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001041 $$->expr_type = A1TC_CLASSFIELD_OFS;
1042 $$->marker = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +00001043 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001044
Lev Walkin54868752006-03-09 09:08:49 +00001045 /* VariableTypeValueSetFieldSpec ::= valuesetfieldreference FieldName ValueOptionalitySpec ? */
1046 | TOK_typefieldreference FieldName optMarker {
Lev Walkin9c2285a2006-03-09 08:49:26 +00001047 $$ = asn1p_expr_new(yylineno);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001048 $$->Identifier = $1;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001049 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin54868752006-03-09 09:08:49 +00001050 $$->expr_type = A1TC_CLASSFIELD_VTVSFS;
1051 $$->reference = $2;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001052 $$->marker = $3;
1053 }
1054
1055 /* FixedTypeValueSetFieldSpec ::= valuesetfieldreference Type ValueSetOptionalitySpec ? */
1056 | TOK_typefieldreference Type optMarker {
1057 $$ = asn1p_expr_new(yylineno);
1058 checkmem($$);
1059 $$->Identifier = $1;
1060 $$->meta_type = AMT_OBJECTFIELD;
1061 $$->expr_type = A1TC_CLASSFIELD_FTVSFS;
1062 asn1p_expr_add($$, $2);
1063 $$->marker = $3;
1064 }
1065
Lev Walkin54868752006-03-09 09:08:49 +00001066 /* ObjectSetFieldSpec ::= objectsetfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1067 | TOK_typefieldreference DefinedObjectClass optMarker {
1068 $$ = asn1p_expr_new(yylineno);
1069 checkmem($$);
1070 $$->Identifier = $1;
1071 $$->reference = $2;
1072 $$->meta_type = AMT_OBJECTFIELD;
1073 $$->expr_type = A1TC_CLASSFIELD_OSFS;
1074 $$->marker = $3;
1075 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001076 ;
1077
1078optWithSyntax:
1079 { $$ = 0; }
1080 | WithSyntax {
1081 $$ = $1;
1082 }
1083 ;
1084
1085WithSyntax:
1086 TOK_WITH TOK_SYNTAX '{'
1087 { asn1p_lexer_hack_enable_with_syntax(); }
Lev Walkin9d542d22006-03-14 16:31:37 +00001088 WithSyntaxList
Lev Walkinf15320b2004-06-03 03:38:44 +00001089 '}' {
1090 $$ = $5;
1091 }
1092 ;
1093
Lev Walkin9d542d22006-03-14 16:31:37 +00001094WithSyntaxList:
1095 WithSyntaxToken {
Lev Walkinf15320b2004-06-03 03:38:44 +00001096 $$ = asn1p_wsyntx_new();
1097 TQ_ADD(&($$->chunks), $1, next);
1098 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001099 | WithSyntaxList WithSyntaxToken {
Lev Walkinf15320b2004-06-03 03:38:44 +00001100 $$ = $1;
1101 TQ_ADD(&($$->chunks), $2, next);
1102 }
1103 ;
1104
Lev Walkin9d542d22006-03-14 16:31:37 +00001105WithSyntaxToken:
Lev Walkin57074f12006-03-16 05:11:14 +00001106 TOK_whitespace {
Lev Walkinf15320b2004-06-03 03:38:44 +00001107 $$ = asn1p_wsyntx_chunk_frombuf($1.buf, $1.len, 0);
Lev Walkin57074f12006-03-16 05:11:14 +00001108 $$->type = WC_WHITESPACE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001109 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001110 | TOK_Literal {
1111 $$ = asn1p_wsyntx_chunk_frombuf($1, strlen($1), 0);
1112 }
Lev Walkind370e9f2006-03-16 10:03:35 +00001113 | PrimitiveFieldReference {
1114 $$ = asn1p_wsyntx_chunk_frombuf($1.name, strlen($1.name), 0);
1115 $$->type = WC_FIELD;
Lev Walkinf15320b2004-06-03 03:38:44 +00001116 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001117 | '[' WithSyntaxList ']' {
1118 $$ = asn1p_wsyntx_chunk_fromsyntax($2);
1119 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001120 ;
1121
Lev Walkinf15320b2004-06-03 03:38:44 +00001122ExtensionAndException:
1123 TOK_ThreeDots {
Lev Walkinceb20e72004-09-05 10:40:41 +00001124 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001125 checkmem($$);
1126 $$->Identifier = strdup("...");
1127 checkmem($$->Identifier);
1128 $$->expr_type = A1TC_EXTENSIBLE;
1129 $$->meta_type = AMT_TYPE;
1130 }
1131 | TOK_ThreeDots '!' DefinedValue {
Lev Walkinceb20e72004-09-05 10:40:41 +00001132 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001133 checkmem($$);
1134 $$->Identifier = strdup("...");
1135 checkmem($$->Identifier);
1136 $$->value = $3;
1137 $$->expr_type = A1TC_EXTENSIBLE;
1138 $$->meta_type = AMT_TYPE;
1139 }
1140 | TOK_ThreeDots '!' SignedNumber {
Lev Walkinceb20e72004-09-05 10:40:41 +00001141 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001142 checkmem($$);
1143 $$->Identifier = strdup("...");
1144 $$->value = $3;
1145 checkmem($$->Identifier);
1146 $$->expr_type = A1TC_EXTENSIBLE;
1147 $$->meta_type = AMT_TYPE;
1148 }
1149 ;
1150
Lev Walkin070a52d2004-08-22 03:19:54 +00001151Type:
Lev Walkinaf120f72004-09-14 02:36:39 +00001152 optTag TypeDeclaration optConstraints {
1153 $$ = $2;
1154 $$->tag = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001155 /*
1156 * Outer constraint for SEQUENCE OF and SET OF applies
1157 * to the inner type.
1158 */
1159 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1160 || $$->expr_type == ASN_CONSTR_SET_OF) {
1161 assert(!TQ_FIRST(&($$->members))->constraints);
Lev Walkinaf120f72004-09-14 02:36:39 +00001162 TQ_FIRST(&($$->members))->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001163 } else {
1164 if($$->constraints) {
1165 assert(!$2);
1166 } else {
Lev Walkinaf120f72004-09-14 02:36:39 +00001167 $$->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001168 }
1169 }
Lev Walkinef625402005-09-05 05:17:57 +00001170 }
1171 ;
1172
1173NSTD_IndirectMarker:
1174 {
1175 $$ = asn1p_as_pointer ? EM_INDIRECT : 0;
1176 asn1p_as_pointer = 0;
Lev Walkin070a52d2004-08-22 03:19:54 +00001177 }
1178 ;
1179
1180TypeDeclaration:
Lev Walkinef625402005-09-05 05:17:57 +00001181 NSTD_IndirectMarker TypeDeclarationSet {
Lev Walkin4696c742005-08-22 12:23:54 +00001182 $$ = $2;
Lev Walkinef625402005-09-05 05:17:57 +00001183 $$->marker.flags |= $1;
1184
1185 if(($$->marker.flags & EM_INDIRECT)
1186 && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
1187 fprintf(stderr,
1188 "INFO: Directive <ASN1C:RepresentAsPointer> "
1189 "applied to %s at line %d\n",
1190 ASN_EXPR_TYPE2STR($$->expr_type)
1191 ? ASN_EXPR_TYPE2STR($$->expr_type)
1192 : "member",
1193 $$->_lineno
1194 );
1195 }
Lev Walkin4696c742005-08-22 12:23:54 +00001196 }
Lev Walkinef625402005-09-05 05:17:57 +00001197 ;
Lev Walkin4696c742005-08-22 12:23:54 +00001198
1199TypeDeclarationSet:
Lev Walkin0c0bca62006-03-21 04:48:15 +00001200 DefinedType {
Lev Walkinf15320b2004-06-03 03:38:44 +00001201 $$ = $1;
1202 }
Lev Walkinef625402005-09-05 05:17:57 +00001203 | TOK_CHOICE '{' AlternativeTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001204 $$ = $3;
1205 assert($$->expr_type == A1TC_INVALID);
1206 $$->expr_type = ASN_CONSTR_CHOICE;
1207 $$->meta_type = AMT_TYPE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001208 }
Lev Walkinef625402005-09-05 05:17:57 +00001209 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001210 $$ = $3;
1211 assert($$->expr_type == A1TC_INVALID);
1212 $$->expr_type = ASN_CONSTR_SEQUENCE;
1213 $$->meta_type = AMT_TYPE;
1214 }
Lev Walkinef625402005-09-05 05:17:57 +00001215 | TOK_SET '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001216 $$ = $3;
1217 assert($$->expr_type == A1TC_INVALID);
1218 $$->expr_type = ASN_CONSTR_SET;
1219 $$->meta_type = AMT_TYPE;
1220 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001221 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkinceb20e72004-09-05 10:40:41 +00001222 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001223 checkmem($$);
1224 $$->constraints = $2;
1225 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1226 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001227 $6->Identifier = $4;
1228 $6->tag = $5;
1229 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001230 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001231 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkinceb20e72004-09-05 10:40:41 +00001232 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001233 checkmem($$);
1234 $$->constraints = $2;
1235 $$->expr_type = ASN_CONSTR_SET_OF;
1236 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001237 $6->Identifier = $4;
1238 $6->tag = $5;
1239 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001240 }
1241 | TOK_ANY {
Lev Walkinceb20e72004-09-05 10:40:41 +00001242 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001243 checkmem($$);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001244 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001245 $$->meta_type = AMT_TYPE;
1246 }
1247 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1248 int ret;
Lev Walkinceb20e72004-09-05 10:40:41 +00001249 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001250 checkmem($$);
1251 $$->reference = asn1p_ref_new(yylineno);
1252 ret = asn1p_ref_add_component($$->reference,
1253 $4, RLT_lowercase);
1254 checkmem(ret == 0);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001255 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001256 $$->meta_type = AMT_TYPE;
1257 }
Lev Walkin0c0bca62006-03-21 04:48:15 +00001258
Lev Walkinf15320b2004-06-03 03:38:44 +00001259 | TOK_INSTANCE TOK_OF ComplexTypeReference {
1260 $$ = asn1p_expr_new(yylineno);
1261 checkmem($$);
1262 $$->reference = $3;
1263 $$->expr_type = A1TC_INSTANCE;
1264 $$->meta_type = AMT_TYPE;
1265 }
1266 ;
1267
1268/*
1269 * A type name consisting of several components.
1270 * === EXAMPLE ===
1271 * === EOF ===
1272 */
1273ComplexTypeReference:
1274 TOK_typereference {
1275 int ret;
1276 $$ = asn1p_ref_new(yylineno);
1277 checkmem($$);
1278 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1279 checkmem(ret == 0);
1280 free($1);
1281 }
1282 | TOK_typereference '.' TypeRefName {
1283 int ret;
1284 $$ = asn1p_ref_new(yylineno);
1285 checkmem($$);
1286 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1287 checkmem(ret == 0);
1288 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1289 checkmem(ret == 0);
1290 free($1);
1291 }
Lev Walkin9c974182004-09-15 11:59:51 +00001292 | ObjectClassReference '.' TypeRefName {
1293 int ret;
1294 $$ = asn1p_ref_new(yylineno);
1295 checkmem($$);
1296 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1297 checkmem(ret == 0);
1298 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1299 checkmem(ret == 0);
1300 free($1);
1301 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001302 | TOK_typereference '.' Identifier {
1303 int ret;
1304 $$ = asn1p_ref_new(yylineno);
1305 checkmem($$);
1306 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1307 checkmem(ret == 0);
1308 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1309 checkmem(ret == 0);
1310 free($1);
1311 }
1312 | ObjectClassReference {
1313 int ret;
1314 $$ = asn1p_ref_new(yylineno);
1315 checkmem($$);
1316 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1317 free($1);
1318 checkmem(ret == 0);
1319 }
1320 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1321 int ret;
1322 $$ = $3;
1323 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1324 free($1);
1325 checkmem(ret == 0);
1326 /*
1327 * Move the last element infront.
1328 */
1329 {
1330 struct asn1p_ref_component_s tmp_comp;
1331 tmp_comp = $$->components[$$->comp_count-1];
1332 memmove(&$$->components[1],
1333 &$$->components[0],
1334 sizeof($$->components[0])
1335 * ($$->comp_count - 1));
1336 $$->components[0] = tmp_comp;
1337 }
1338 }
1339 ;
1340
1341ComplexTypeReferenceAmpList:
1342 ComplexTypeReferenceElement {
1343 int ret;
1344 $$ = asn1p_ref_new(yylineno);
1345 checkmem($$);
1346 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1347 free($1.name);
1348 checkmem(ret == 0);
1349 }
1350 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1351 int ret;
1352 $$ = $1;
1353 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1354 free($3.name);
1355 checkmem(ret == 0);
1356 }
1357 ;
1358
Lev Walkind370e9f2006-03-16 10:03:35 +00001359ComplexTypeReferenceElement: PrimitiveFieldReference;
Lev Walkinf15320b2004-06-03 03:38:44 +00001360
Lev Walkind370e9f2006-03-16 10:03:35 +00001361PrimitiveFieldReference:
Lev Walkinf15320b2004-06-03 03:38:44 +00001362 /* "&Type1" */
1363 TOK_typefieldreference {
1364 $$.lex_type = RLT_AmpUppercase;
1365 $$.name = $1;
1366 }
1367 /* "&id" */
1368 | TOK_valuefieldreference {
1369 $$.lex_type = RLT_Amplowercase;
1370 $$.name = $1;
1371 }
1372 ;
1373
1374
Lev Walkin9c2285a2006-03-09 08:49:26 +00001375FieldName:
1376 /* "&Type1" */
1377 TOK_typefieldreference {
1378 $$ = asn1p_ref_new(yylineno);
1379 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1380 }
1381 | FieldName '.' TOK_typefieldreference {
1382 $$ = $$;
1383 asn1p_ref_add_component($$, $3, RLT_AmpUppercase);
1384 }
1385 | FieldName '.' TOK_valuefieldreference {
1386 $$ = $$;
1387 asn1p_ref_add_component($$, $3, RLT_Amplowercase);
1388 }
1389 ;
1390
1391DefinedObjectClass:
1392 TOK_capitalreference {
1393 $$ = asn1p_ref_new(yylineno);
1394 asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1395 }
Lev Walkin54868752006-03-09 09:08:49 +00001396/*
Lev Walkin9c2285a2006-03-09 08:49:26 +00001397 | TypeRefName '.' TOK_capitalreference {
1398 $$ = asn1p_ref_new(yylineno);
1399 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1400 asn1p_ref_add_component($$, $3, RLT_CAPITALS);
1401 }
Lev Walkin54868752006-03-09 09:08:49 +00001402*/
Lev Walkin9c2285a2006-03-09 08:49:26 +00001403 ;
1404
1405
Lev Walkinf15320b2004-06-03 03:38:44 +00001406/*
1407 * === EXAMPLE ===
1408 * value INTEGER ::= 1
1409 * === EOF ===
1410 */
1411ValueDefinition:
Lev Walkin0c0bca62006-03-21 04:48:15 +00001412 Identifier DefinedType TOK_PPEQ Value {
Lev Walkinf15320b2004-06-03 03:38:44 +00001413 $$ = $2;
1414 assert($$->Identifier == NULL);
1415 $$->Identifier = $1;
1416 $$->meta_type = AMT_VALUE;
1417 $$->value = $4;
1418 }
1419 ;
1420
Lev Walkin9c974182004-09-15 11:59:51 +00001421Value:
Lev Walkin0c0bca62006-03-21 04:48:15 +00001422 SimpleValue
1423 | DefinedValue
1424 | Identifier ':' Value {
Lev Walkin9c974182004-09-15 11:59:51 +00001425 $$ = asn1p_value_fromint(0);
1426 checkmem($$);
1427 $$->type = ATV_CHOICE_IDENTIFIER;
1428 $$->value.choice_identifier.identifier = $1;
1429 $$->value.choice_identifier.value = $3;
1430 }
Lev Walkincbad2512005-03-24 16:27:02 +00001431 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Lev Walkinf15320b2004-06-03 03:38:44 +00001432 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1433 checkmem($$);
1434 $$->type = ATV_UNPARSED;
1435 }
Lev Walkin9c974182004-09-15 11:59:51 +00001436 | TOK_NULL {
1437 $$ = asn1p_value_fromint(0);
1438 checkmem($$);
1439 $$->type = ATV_NULL;
1440 }
Lev Walkin0c0bca62006-03-21 04:48:15 +00001441 ;
1442
1443SimpleValue:
1444 TOK_FALSE {
Lev Walkin9c974182004-09-15 11:59:51 +00001445 $$ = asn1p_value_fromint(0);
1446 checkmem($$);
1447 $$->type = ATV_FALSE;
1448 }
1449 | TOK_TRUE {
1450 $$ = asn1p_value_fromint(0);
1451 checkmem($$);
1452 $$->type = ATV_TRUE;
1453 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001454 | TOK_bstring {
1455 $$ = _convert_bitstring2binary($1, 'B');
1456 checkmem($$);
1457 }
1458 | TOK_hstring {
1459 $$ = _convert_bitstring2binary($1, 'H');
1460 checkmem($$);
1461 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001462 | RestrictedCharacterStringValue {
1463 $$ = $$;
Lev Walkinf15320b2004-06-03 03:38:44 +00001464 }
1465 | SignedNumber {
1466 $$ = $1;
1467 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001468 ;
1469
1470DefinedValue:
1471 Identifier {
1472 asn1p_ref_t *ref;
1473 int ret;
1474 ref = asn1p_ref_new(yylineno);
1475 checkmem(ref);
1476 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1477 checkmem(ret == 0);
1478 $$ = asn1p_value_fromref(ref, 0);
1479 checkmem($$);
1480 free($1);
1481 }
1482 | TypeRefName '.' Identifier {
1483 asn1p_ref_t *ref;
1484 int ret;
1485 ref = asn1p_ref_new(yylineno);
1486 checkmem(ref);
1487 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1488 checkmem(ret == 0);
1489 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1490 checkmem(ret == 0);
1491 $$ = asn1p_value_fromref(ref, 0);
1492 checkmem($$);
1493 free($1);
1494 free($3);
1495 }
1496 ;
1497
Lev Walkin1e448d32005-03-24 14:26:38 +00001498
1499RestrictedCharacterStringValue:
1500 TOK_cstring {
1501 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1502 checkmem($$);
1503 }
Lev Walkind9574ae2005-03-24 16:22:35 +00001504 | TOK_tuple {
1505 $$ = asn1p_value_fromint($1);
1506 checkmem($$);
1507 $$->type = ATV_TUPLE;
1508 }
1509 | TOK_quadruple {
1510 $$ = asn1p_value_fromint($1);
1511 checkmem($$);
1512 $$->type = ATV_QUADRUPLE;
1513 }
1514 /*
Lev Walkin1e448d32005-03-24 14:26:38 +00001515 | '{' TOK_number ',' TOK_number '}' {
1516 asn1c_integer_t v = ($2 << 4) + $4;
1517 if($2 > 7) return yyerror("X.680:2003, #37.14 "
1518 "mandates 0..7 range for Tuple's TableColumn");
1519 if($4 > 15) return yyerror("X.680:2003, #37.14 "
1520 "mandates 0..15 range for Tuple's TableRow");
1521 $$ = asn1p_value_fromint(v);
1522 checkmem($$);
1523 $$->type = ATV_TUPLE;
1524 }
1525 | '{' TOK_number ',' TOK_number ',' TOK_number ',' TOK_number '}' {
1526 asn1c_integer_t v = ($2 << 24) | ($4 << 16) | ($6 << 8) | $8;
1527 if($2 > 127) return yyerror("X.680:2003, #37.12 "
1528 "mandates 0..127 range for Quadruple's Group");
1529 if($4 > 255) return yyerror("X.680:2003, #37.12 "
1530 "mandates 0..255 range for Quadruple's Plane");
1531 if($6 > 255) return yyerror("X.680:2003, #37.12 "
1532 "mandates 0..255 range for Quadruple's Row");
1533 if($8 > 255) return yyerror("X.680:2003, #37.12 "
1534 "mandates 0..255 range for Quadruple's Cell");
1535 $$ = asn1p_value_fromint(v);
1536 checkmem($$);
1537 $$->type = ATV_QUADRUPLE;
1538 }
Lev Walkind9574ae2005-03-24 16:22:35 +00001539 */
Lev Walkin1e448d32005-03-24 14:26:38 +00001540 ;
1541
Lev Walkinf15320b2004-06-03 03:38:44 +00001542Opaque:
1543 TOK_opaque {
Lev Walkin1893ddf2005-03-20 14:28:32 +00001544 $$.len = $1.len + 1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001545 $$.buf = malloc($$.len + 1);
1546 checkmem($$.buf);
1547 $$.buf[0] = '{';
Lev Walkin1893ddf2005-03-20 14:28:32 +00001548 memcpy($$.buf + 1, $1.buf, $1.len);
Lev Walkinf15320b2004-06-03 03:38:44 +00001549 $$.buf[$$.len] = '\0';
1550 free($1.buf);
1551 }
1552 | Opaque TOK_opaque {
1553 int newsize = $1.len + $2.len;
1554 char *p = malloc(newsize + 1);
1555 checkmem(p);
1556 memcpy(p , $1.buf, $1.len);
1557 memcpy(p + $1.len, $2.buf, $2.len);
1558 p[newsize] = '\0';
1559 free($1.buf);
1560 free($2.buf);
1561 $$.buf = p;
1562 $$.len = newsize;
1563 }
1564 ;
1565
1566BasicTypeId:
1567 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1568 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1569 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1570 | BasicTypeId_UniverationCompatible { $$ = $1; }
1571 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1572 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1573 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1574 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1575 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1576 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1577 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1578 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
Lev Walkinc7d939d2005-03-20 11:12:40 +00001579 | BasicString { $$ = $1; }
Lev Walkinf15320b2004-06-03 03:38:44 +00001580 ;
1581
1582/*
1583 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1584 */
1585BasicTypeId_UniverationCompatible:
1586 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1587 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1588 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1589 ;
1590
1591BasicType:
1592 BasicTypeId {
Lev Walkinceb20e72004-09-05 10:40:41 +00001593 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001594 checkmem($$);
1595 $$->expr_type = $1;
1596 $$->meta_type = AMT_TYPE;
1597 }
1598 | BasicTypeId_UniverationCompatible UniverationDefinition {
1599 if($2) {
1600 $$ = $2;
1601 } else {
Lev Walkinceb20e72004-09-05 10:40:41 +00001602 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001603 checkmem($$);
1604 }
1605 $$->expr_type = $1;
1606 $$->meta_type = AMT_TYPE;
1607 }
1608 ;
1609
1610BasicString:
1611 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1612 | TOK_GeneralString {
1613 $$ = ASN_STRING_GeneralString;
Lev Walkin9c974182004-09-15 11:59:51 +00001614 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001615 }
1616 | TOK_GraphicString {
1617 $$ = ASN_STRING_GraphicString;
Lev Walkin9c974182004-09-15 11:59:51 +00001618 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001619 }
1620 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1621 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1622 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1623 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1624 | TOK_T61String {
1625 $$ = ASN_STRING_T61String;
Lev Walkin9c974182004-09-15 11:59:51 +00001626 fprintf(stderr, "WARNING: T61String is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001627 }
1628 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1629 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1630 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1631 | TOK_VideotexString {
1632 $$ = ASN_STRING_VideotexString;
Lev Walkin9c974182004-09-15 11:59:51 +00001633 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001634 }
1635 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1636 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1637 ;
1638
Lev Walkind2ea1de2004-08-20 13:25:29 +00001639
Lev Walkinf15320b2004-06-03 03:38:44 +00001640/*
1641 * Data type constraints.
1642 */
Lev Walkinf15320b2004-06-03 03:38:44 +00001643Union: '|' | TOK_UNION;
1644Intersection: '^' | TOK_INTERSECTION;
1645Except: TOK_EXCEPT;
1646
Lev Walkinf59d0752004-08-18 04:59:12 +00001647optConstraints:
1648 { $$ = 0; }
Lev Walkind2ea1de2004-08-20 13:25:29 +00001649 | Constraints {
1650 $$ = $1;
1651 }
1652 ;
1653
1654Constraints:
1655 SetOfConstraints {
Lev Walkin2c14a692005-08-12 10:08:45 +00001656 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
Lev Walkinf59d0752004-08-18 04:59:12 +00001657 }
1658 | TOK_SIZE '(' ElementSetSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001659 /*
1660 * This is a special case, for compatibility purposes.
Lev Walkinf59d0752004-08-18 04:59:12 +00001661 * It goes without parentheses.
Lev Walkinf15320b2004-06-03 03:38:44 +00001662 */
Lev Walkin2c14a692005-08-12 10:08:45 +00001663 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001664 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001665 ;
1666
Lev Walkinf59d0752004-08-18 04:59:12 +00001667SetOfConstraints:
1668 '(' ElementSetSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001669 $$ = $2;
1670 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001671 | SetOfConstraints '(' ElementSetSpecs ')' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001672 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
Lev Walkinf59d0752004-08-18 04:59:12 +00001673 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001674 ;
1675
Lev Walkinf59d0752004-08-18 04:59:12 +00001676ElementSetSpecs:
1677 ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001678 $$ = $1;
1679 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001680 | ElementSetSpec ',' TOK_ThreeDots {
Lev Walkinf15320b2004-06-03 03:38:44 +00001681 asn1p_constraint_t *ct;
1682 ct = asn1p_constraint_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001683 ct->type = ACT_EL_EXT;
Lev Walkin2c14a692005-08-12 10:08:45 +00001684 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00001685 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001686 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001687 asn1p_constraint_t *ct;
1688 ct = asn1p_constraint_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001689 ct->type = ACT_EL_EXT;
Lev Walkin2c14a692005-08-12 10:08:45 +00001690 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinb4fcdd22004-08-13 12:35:09 +00001691 ct = $$;
Lev Walkin2c14a692005-08-12 10:08:45 +00001692 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
Lev Walkinf15320b2004-06-03 03:38:44 +00001693 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001694 ;
1695
Lev Walkinf59d0752004-08-18 04:59:12 +00001696ElementSetSpec:
1697 ConstraintSubtypeElement {
1698 $$ = $1;
1699 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001700 | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001701 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
Lev Walkin1e448d32005-03-24 14:26:38 +00001702 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001703 | ElementSetSpec Union ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001704 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001705 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001706 | ElementSetSpec Intersection ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001707 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001708 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001709 | ConstraintSubtypeElement Except ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001710 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001711 }
1712 ;
1713
1714ConstraintSubtypeElement:
Lev Walkinf59d0752004-08-18 04:59:12 +00001715 ConstraintSpec '(' ElementSetSpecs ')' {
1716 int ret;
1717 $$ = asn1p_constraint_new(yylineno);
1718 checkmem($$);
1719 $$->type = $1;
1720 ret = asn1p_constraint_insert($$, $3);
1721 checkmem(ret == 0);
1722 }
1723 | '(' ElementSetSpecs ')' {
1724 int ret;
1725 $$ = asn1p_constraint_new(yylineno);
1726 checkmem($$);
1727 $$->type = ACT_CA_SET;
1728 ret = asn1p_constraint_insert($$, $2);
1729 checkmem(ret == 0);
1730 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001731 | SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001732 $$ = asn1p_constraint_new(yylineno);
1733 checkmem($$);
1734 $$->type = ACT_EL_VALUE;
1735 $$->value = $1;
1736 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001737 | ContainedSubtype {
1738 $$ = asn1p_constraint_new(yylineno);
1739 checkmem($$);
1740 $$->type = ACT_EL_TYPE;
1741 $$->containedSubtype = $1;
1742 }
1743 | SingleValue ConstraintRangeSpec SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001744 $$ = asn1p_constraint_new(yylineno);
1745 checkmem($$);
1746 $$->type = $2;
1747 $$->range_start = $1;
1748 $$->range_stop = $3;
1749 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001750 | TOK_MIN ConstraintRangeSpec SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001751 $$ = asn1p_constraint_new(yylineno);
1752 checkmem($$);
Lev Walkinf59d0752004-08-18 04:59:12 +00001753 $$->type = $2;
1754 $$->range_start = asn1p_value_fromint(-123);
1755 $$->range_stop = $3;
1756 $$->range_start->type = ATV_MIN;
1757 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001758 | SingleValue ConstraintRangeSpec TOK_MAX {
Lev Walkinf59d0752004-08-18 04:59:12 +00001759 $$ = asn1p_constraint_new(yylineno);
1760 checkmem($$);
1761 $$->type = $2;
1762 $$->range_start = $1;
1763 $$->range_stop = asn1p_value_fromint(321);
1764 $$->range_stop->type = ATV_MAX;
1765 }
1766 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1767 $$ = asn1p_constraint_new(yylineno);
1768 checkmem($$);
1769 $$->type = $2;
1770 $$->range_start = asn1p_value_fromint(-123);
1771 $$->range_stop = asn1p_value_fromint(321);
1772 $$->range_start->type = ATV_MIN;
1773 $$->range_stop->type = ATV_MAX;
Lev Walkinf15320b2004-06-03 03:38:44 +00001774 }
1775 | TableConstraint {
1776 $$ = $1;
1777 }
Lev Walkine596bf02005-03-28 15:01:27 +00001778 | InnerTypeConstraint {
Lev Walkinf15320b2004-06-03 03:38:44 +00001779 $$ = $1;
1780 }
Lev Walkin1893ddf2005-03-20 14:28:32 +00001781 | TOK_CONSTRAINED TOK_BY '{'
1782 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1783 $$ = asn1p_constraint_new(yylineno);
1784 checkmem($$);
1785 $$->type = ACT_CT_CTDBY;
1786 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
1787 checkmem($$->value);
1788 $$->value->type = ATV_UNPARSED;
1789 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001790 ;
1791
1792ConstraintRangeSpec:
1793 TOK_TwoDots { $$ = ACT_EL_RANGE; }
1794 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
1795 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
1796 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
1797 ;
1798
1799ConstraintSpec:
1800 TOK_SIZE {
1801 $$ = ACT_CT_SIZE;
1802 }
1803 | TOK_FROM {
1804 $$ = ACT_CT_FROM;
1805 }
1806 ;
1807
Lev Walkinff7dd142005-03-20 12:58:00 +00001808SingleValue:
Lev Walkinc8092cb2005-02-18 16:34:21 +00001809 TOK_FALSE {
1810 $$ = asn1p_value_fromint(0);
1811 checkmem($$);
1812 $$->type = ATV_FALSE;
1813 }
1814 | TOK_TRUE {
1815 $$ = asn1p_value_fromint(1);
1816 checkmem($$);
1817 $$->type = ATV_TRUE;
1818 }
1819 | SignedNumber {
Lev Walkinf15320b2004-06-03 03:38:44 +00001820 $$ = $1;
1821 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001822 | RestrictedCharacterStringValue {
1823 $$ = $1;
Lev Walkinc8092cb2005-02-18 16:34:21 +00001824 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001825 | Identifier {
1826 asn1p_ref_t *ref;
1827 int ret;
1828 ref = asn1p_ref_new(yylineno);
1829 checkmem(ref);
1830 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1831 checkmem(ret == 0);
1832 $$ = asn1p_value_fromref(ref, 0);
1833 checkmem($$);
1834 free($1);
1835 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001836 ;
1837
1838ContainedSubtype:
1839 TypeRefName {
Lev Walkinc8092cb2005-02-18 16:34:21 +00001840 asn1p_ref_t *ref;
1841 int ret;
1842 ref = asn1p_ref_new(yylineno);
1843 checkmem(ref);
1844 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1845 checkmem(ret == 0);
1846 $$ = asn1p_value_fromref(ref, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001847 checkmem($$);
Lev Walkinc8092cb2005-02-18 16:34:21 +00001848 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001849 }
1850 ;
1851
Lev Walkine596bf02005-03-28 15:01:27 +00001852InnerTypeConstraint:
1853 TOK_WITH TOK_COMPONENT SetOfConstraints {
Lev Walkin2c14a692005-08-12 10:08:45 +00001854 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
Lev Walkine596bf02005-03-28 15:01:27 +00001855 }
1856 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001857 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001858 }
1859 ;
1860
1861WithComponentsList:
1862 WithComponentsElement {
1863 $$ = $1;
1864 }
1865 | WithComponentsList ',' WithComponentsElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001866 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001867 }
1868 ;
1869
1870WithComponentsElement:
1871 TOK_ThreeDots {
1872 $$ = asn1p_constraint_new(yylineno);
1873 checkmem($$);
1874 $$->type = ACT_EL_EXT;
Lev Walkine596bf02005-03-28 15:01:27 +00001875 $$->value = asn1p_value_frombuf("...", 3, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001876 }
1877 | Identifier optConstraints optPresenceConstraint {
1878 $$ = asn1p_constraint_new(yylineno);
1879 checkmem($$);
1880 $$->type = ACT_EL_VALUE;
1881 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1882 $$->presence = $3;
Lev Walkine596bf02005-03-28 15:01:27 +00001883 if($2) asn1p_constraint_insert($$, $2);
Lev Walkinf15320b2004-06-03 03:38:44 +00001884 }
1885 ;
1886
1887/*
1888 * presence constraint for WithComponents
1889 */
1890optPresenceConstraint:
1891 { $$ = ACPRES_DEFAULT; }
1892 | PresenceConstraint { $$ = $1; }
1893 ;
1894
1895PresenceConstraint:
1896 TOK_PRESENT {
1897 $$ = ACPRES_PRESENT;
1898 }
1899 | TOK_ABSENT {
1900 $$ = ACPRES_ABSENT;
1901 }
1902 | TOK_OPTIONAL {
1903 $$ = ACPRES_OPTIONAL;
1904 }
1905 ;
1906
1907TableConstraint:
1908 SimpleTableConstraint {
1909 $$ = $1;
1910 }
1911 | ComponentRelationConstraint {
1912 $$ = $1;
1913 }
1914 ;
1915
1916/*
1917 * "{ExtensionSet}"
1918 */
1919SimpleTableConstraint:
1920 '{' TypeRefName '}' {
1921 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
1922 asn1p_constraint_t *ct;
1923 int ret;
1924 ret = asn1p_ref_add_component(ref, $2, 0);
1925 checkmem(ret == 0);
1926 ct = asn1p_constraint_new(yylineno);
1927 checkmem($$);
1928 ct->type = ACT_EL_VALUE;
1929 ct->value = asn1p_value_fromref(ref, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00001930 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001931 }
1932 ;
1933
1934ComponentRelationConstraint:
1935 SimpleTableConstraint '{' AtNotationList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001936 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001937 }
1938 ;
1939
1940AtNotationList:
1941 AtNotationElement {
1942 $$ = asn1p_constraint_new(yylineno);
1943 checkmem($$);
1944 $$->type = ACT_EL_VALUE;
1945 $$->value = asn1p_value_fromref($1, 0);
1946 }
1947 | AtNotationList ',' AtNotationElement {
1948 asn1p_constraint_t *ct;
1949 ct = asn1p_constraint_new(yylineno);
1950 checkmem(ct);
1951 ct->type = ACT_EL_VALUE;
1952 ct->value = asn1p_value_fromref($3, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00001953 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00001954 }
1955 ;
1956
1957/*
1958 * @blah
1959 */
1960AtNotationElement:
1961 '@' ComponentIdList {
1962 char *p = malloc(strlen($2) + 2);
1963 int ret;
1964 *p = '@';
1965 strcpy(p + 1, $2);
1966 $$ = asn1p_ref_new(yylineno);
1967 ret = asn1p_ref_add_component($$, p, 0);
1968 checkmem(ret == 0);
1969 free(p);
1970 free($2);
1971 }
1972 | '@' '.' ComponentIdList {
1973 char *p = malloc(strlen($3) + 3);
1974 int ret;
1975 p[0] = '@';
1976 p[1] = '.';
1977 strcpy(p + 2, $3);
1978 $$ = asn1p_ref_new(yylineno);
1979 ret = asn1p_ref_add_component($$, p, 0);
1980 checkmem(ret == 0);
1981 free(p);
1982 free($3);
1983 }
1984 ;
1985
1986/* identifier "." ... */
1987ComponentIdList:
1988 Identifier {
1989 $$ = $1;
1990 }
1991 | ComponentIdList '.' Identifier {
1992 int l1 = strlen($1);
1993 int l3 = strlen($3);
1994 $$ = malloc(l1 + 1 + l3 + 1);
1995 memcpy($$, $1, l1);
1996 $$[l1] = '.';
1997 memcpy($$ + l1 + 1, $3, l3);
1998 $$[l1 + 1 + l3] = '\0';
1999 }
2000 ;
2001
2002
2003
2004/*
2005 * MARKERS
2006 */
2007
2008optMarker:
Lev Walkin9c974182004-09-15 11:59:51 +00002009 {
2010 $$.flags = EM_NOMARK;
2011 $$.default_value = 0;
2012 }
Lev Walkinf15320b2004-06-03 03:38:44 +00002013 | Marker { $$ = $1; }
2014 ;
2015
2016Marker:
2017 TOK_OPTIONAL {
Lev Walkin70853052005-11-26 11:21:55 +00002018 $$.flags = EM_OPTIONAL | EM_INDIRECT;
Lev Walkin9c974182004-09-15 11:59:51 +00002019 $$.default_value = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +00002020 }
Lev Walkin9c974182004-09-15 11:59:51 +00002021 | TOK_DEFAULT Value {
2022 $$.flags = EM_DEFAULT;
2023 $$.default_value = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00002024 }
2025 ;
2026
2027/*
2028 * Universal enumeration definition to use in INTEGER and ENUMERATED.
2029 * === EXAMPLE ===
2030 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
2031 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
2032 * === EOF ===
2033 */
2034/*
2035optUniverationDefinition:
2036 { $$ = 0; }
2037 | UniverationDefinition {
2038 $$ = $1;
2039 }
2040 ;
2041*/
2042
2043UniverationDefinition:
2044 '{' '}' {
Lev Walkinceb20e72004-09-05 10:40:41 +00002045 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00002046 checkmem($$);
2047 }
2048 | '{' UniverationList '}' {
2049 $$ = $2;
2050 }
2051 ;
2052
2053UniverationList:
2054 UniverationElement {
Lev Walkinceb20e72004-09-05 10:40:41 +00002055 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00002056 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00002057 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00002058 }
2059 | UniverationList ',' UniverationElement {
2060 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00002061 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002062 }
2063 ;
2064
2065UniverationElement:
2066 Identifier {
Lev Walkinceb20e72004-09-05 10:40:41 +00002067 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00002068 checkmem($$);
2069 $$->expr_type = A1TC_UNIVERVAL;
2070 $$->meta_type = AMT_VALUE;
2071 $$->Identifier = $1;
2072 }
2073 | Identifier '(' SignedNumber ')' {
Lev Walkinceb20e72004-09-05 10:40:41 +00002074 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00002075 checkmem($$);
2076 $$->expr_type = A1TC_UNIVERVAL;
2077 $$->meta_type = AMT_VALUE;
2078 $$->Identifier = $1;
2079 $$->value = $3;
2080 }
2081 | Identifier '(' DefinedValue ')' {
Lev Walkinceb20e72004-09-05 10:40:41 +00002082 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00002083 checkmem($$);
2084 $$->expr_type = A1TC_UNIVERVAL;
2085 $$->meta_type = AMT_VALUE;
2086 $$->Identifier = $1;
2087 $$->value = $3;
2088 }
2089 | SignedNumber {
Lev Walkinceb20e72004-09-05 10:40:41 +00002090 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00002091 checkmem($$);
2092 $$->expr_type = A1TC_UNIVERVAL;
2093 $$->meta_type = AMT_VALUE;
2094 $$->value = $1;
2095 }
2096 | TOK_ThreeDots {
Lev Walkinceb20e72004-09-05 10:40:41 +00002097 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00002098 checkmem($$);
2099 $$->Identifier = strdup("...");
2100 checkmem($$->Identifier);
2101 $$->expr_type = A1TC_EXTENSIBLE;
2102 $$->meta_type = AMT_VALUE;
2103 }
2104 ;
2105
2106SignedNumber:
2107 TOK_number {
2108 $$ = asn1p_value_fromint($1);
2109 checkmem($$);
2110 }
2111 | TOK_number_negative {
2112 $$ = asn1p_value_fromint($1);
2113 checkmem($$);
2114 }
2115 ;
2116
2117/*
2118 * SEQUENCE definition.
2119 * === EXAMPLE ===
2120 * Struct1 ::= SEQUENCE {
2121 * memb1 Struct2,
2122 * memb2 SEQUENCE OF {
2123 * memb2-1 Struct 3
2124 * }
2125 * }
2126 * === EOF ===
2127 */
2128
2129
2130
2131/*
2132 * SET definition.
2133 * === EXAMPLE ===
2134 * Person ::= SET {
2135 * name [0] PrintableString (SIZE(1..20)),
2136 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2137 * }
2138 * === EOF ===
2139 */
2140
2141optTag:
2142 { memset(&$$, 0, sizeof($$)); }
2143 | Tag { $$ = $1; }
2144 ;
2145
2146Tag:
Lev Walkinc603f102005-01-23 09:51:44 +00002147 TagTypeValue TagPlicit {
Lev Walkinf15320b2004-06-03 03:38:44 +00002148 $$ = $1;
Lev Walkinc603f102005-01-23 09:51:44 +00002149 $$.tag_mode = $2.tag_mode;
Lev Walkinf15320b2004-06-03 03:38:44 +00002150 }
Lev Walkinc603f102005-01-23 09:51:44 +00002151 ;
2152
2153TagTypeValue:
2154 '[' TagClass TOK_number ']' {
2155 $$ = $2;
2156 $$.tag_value = $3;
2157 };
2158
2159TagClass:
2160 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2161 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2162 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2163 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2164 ;
2165
2166TagPlicit:
2167 { $$.tag_mode = TM_DEFAULT; }
2168 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2169 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
Lev Walkinf15320b2004-06-03 03:38:44 +00002170 ;
2171
2172TypeRefName:
2173 TOK_typereference {
2174 checkmem($1);
2175 $$ = $1;
2176 }
Lev Walkinf59d0752004-08-18 04:59:12 +00002177 | TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002178 checkmem($1);
2179 $$ = $1;
2180 }
2181 ;
2182
Lev Walkinf59d0752004-08-18 04:59:12 +00002183
Lev Walkinf15320b2004-06-03 03:38:44 +00002184ObjectClassReference:
Lev Walkinf59d0752004-08-18 04:59:12 +00002185 TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002186 checkmem($1);
2187 $$ = $1;
2188 }
2189 ;
2190
Lev Walkin83cac2f2004-09-22 16:03:36 +00002191optIdentifier:
2192 { $$ = 0; }
2193 | Identifier {
2194 $$ = $1;
2195 }
Lev Walkin8f294e02005-06-06 08:28:58 +00002196 ;
Lev Walkin83cac2f2004-09-22 16:03:36 +00002197
Lev Walkinf15320b2004-06-03 03:38:44 +00002198Identifier:
2199 TOK_identifier {
2200 checkmem($1);
2201 $$ = $1;
2202 }
2203 ;
2204
Lev Walkinf15320b2004-06-03 03:38:44 +00002205%%
2206
2207
2208/*
2209 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2210 */
2211static asn1p_value_t *
2212_convert_bitstring2binary(char *str, int base) {
2213 asn1p_value_t *val;
2214 int slen;
2215 int memlen;
2216 int baselen;
2217 int bits;
2218 uint8_t *binary_vector;
2219 uint8_t *bv_ptr;
2220 uint8_t cur_val;
2221
2222 assert(str);
2223 assert(str[0] == '\'');
2224
2225 switch(base) {
2226 case 'B':
2227 baselen = 1;
2228 break;
2229 case 'H':
2230 baselen = 4;
2231 break;
2232 default:
2233 assert(base == 'B' || base == 'H');
2234 errno = EINVAL;
2235 return NULL;
2236 }
2237
2238 slen = strlen(str);
2239 assert(str[slen - 1] == base);
2240 assert(str[slen - 2] == '\'');
2241
2242 memlen = slen / (8 / baselen); /* Conservative estimate */
2243
2244 bv_ptr = binary_vector = malloc(memlen + 1);
2245 if(bv_ptr == NULL)
2246 /* ENOMEM */
2247 return NULL;
2248
2249 cur_val = 0;
2250 bits = 0;
2251 while(*(++str) != '\'') {
2252 switch(baselen) {
2253 case 1:
2254 switch(*str) {
2255 case '1':
2256 cur_val |= 1 << (7 - (bits % 8));
2257 case '0':
2258 break;
2259 default:
2260 assert(!"_y UNREACH1");
2261 case ' ': case '\r': case '\n':
2262 continue;
2263 }
2264 break;
2265 case 4:
2266 switch(*str) {
2267 case '0': case '1': case '2': case '3': case '4':
2268 case '5': case '6': case '7': case '8': case '9':
2269 cur_val |= (*str - '0') << (4 - (bits % 8));
2270 break;
2271 case 'A': case 'B': case 'C':
2272 case 'D': case 'E': case 'F':
2273 cur_val |= ((*str - 'A') + 10)
2274 << (4 - (bits % 8));
2275 break;
2276 default:
2277 assert(!"_y UNREACH2");
2278 case ' ': case '\r': case '\n':
2279 continue;
2280 }
2281 break;
2282 }
2283
2284 bits += baselen;
2285 if((bits % 8) == 0) {
2286 *bv_ptr++ = cur_val;
2287 cur_val = 0;
2288 }
2289 }
2290
2291 *bv_ptr = cur_val;
2292 assert((bv_ptr - binary_vector) <= memlen);
2293
2294 val = asn1p_value_frombits(binary_vector, bits, 0);
2295 if(val == NULL) {
2296 free(binary_vector);
2297 }
2298
2299 return val;
2300}
2301
Lev Walkin2e9bd5c2005-08-13 09:07:11 +00002302/*
2303 * For unnamed types (used in old X.208 compliant modules)
2304 * generate some sort of interim names, to not to force human being to fix
2305 * the specification's compliance to modern ASN.1 standards.
2306 */
2307static void
2308_fixup_anonymous_identifier(asn1p_expr_t *expr) {
2309 char *p;
2310 assert(expr->Identifier == 0);
2311
2312 /*
2313 * Try to figure out the type name
2314 * without going too much into details
2315 */
2316 expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type);
2317 if(expr->reference && expr->reference->comp_count > 0)
2318 expr->Identifier = expr->reference->components[0].name;
2319
2320 fprintf(stderr,
2321 "WARNING: Line %d: expected lower-case member identifier, "
2322 "found an unnamed %s.\n"
2323 "WARNING: Obsolete X.208 syntax detected, "
2324 "please give the member a name.\n",
2325 yylineno, expr->Identifier ? expr->Identifier : "type");
2326
2327 if(!expr->Identifier)
2328 expr->Identifier = "unnamed";
2329 expr->Identifier = strdup(expr->Identifier);
2330 assert(expr->Identifier);
2331 /* Make a lowercase identifier from the type name */
2332 for(p = expr->Identifier; *p; p++) {
2333 switch(*p) {
2334 case 'A' ... 'Z': *p += 32; break;
2335 case ' ': *p = '_'; break;
2336 case '-': *p = '_'; break;
2337 }
2338 }
2339 fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". "
2340 "Name clash may occur later.\n",
2341 expr->Identifier);
2342}
2343
Lev Walkinf15320b2004-06-03 03:38:44 +00002344int
2345yyerror(const char *msg) {
Lev Walkin9d542d22006-03-14 16:31:37 +00002346 extern char *asn1p_text;
Lev Walkinf15320b2004-06-03 03:38:44 +00002347 fprintf(stderr,
2348 "ASN.1 grammar parse error "
2349 "near line %d (token \"%s\"): %s\n",
Lev Walkinceb20e72004-09-05 10:40:41 +00002350 yylineno, asn1p_text, msg);
Lev Walkinf15320b2004-06-03 03:38:44 +00002351 return -1;
2352}
2353