blob: f3131df6e70df4ec1be3b6439557d8945e87b1f9 [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 Walkin5045dfa2006-03-21 09:41:28 +0000275%type <a_expr> ActualParameter
276%type <a_expr> ActualParameterList
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 /*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000750 * A parameterized assignment.
Lev Walkin0c0bca62006-03-21 04:48:15 +0000751 */
Lev Walkin5045dfa2006-03-21 09:41:28 +0000752 | ComplexTypeReference '{' ActualParameterList '}' {
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 /*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000785 * Parameterized <Type> declaration:
Lev Walkinf15320b2004-06-03 03:38:44 +0000786 * === 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;
Lev Walkin5045dfa2006-03-21 09:41:28 +0000796 $$->Identifier = $1;
797 $$->lhs_params = $3;
798 }
799 /* Parameterized CLASS declaration */
800 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ ObjectClass {
801 $$ = $6;
Lev Walkinf15320b2004-06-03 03:38:44 +0000802 $$->Identifier = $1;
Lev Walkina00d6b32006-03-21 03:40:38 +0000803 $$->lhs_params = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000804 }
805 ;
806
807ParameterArgumentList:
808 ParameterArgumentName {
809 int ret;
810 $$ = asn1p_paramlist_new(yylineno);
811 checkmem($$);
812 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
813 checkmem(ret == 0);
814 if($1.governor) asn1p_ref_free($1.governor);
815 if($1.argument) free($1.argument);
816 }
817 | ParameterArgumentList ',' ParameterArgumentName {
818 int ret;
819 $$ = $1;
820 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
821 checkmem(ret == 0);
822 if($3.governor) asn1p_ref_free($3.governor);
823 if($3.argument) free($3.argument);
824 }
825 ;
826
827ParameterArgumentName:
828 TypeRefName {
829 $$.governor = NULL;
830 $$.argument = $1;
831 }
832 | TypeRefName ':' Identifier {
833 int ret;
834 $$.governor = asn1p_ref_new(yylineno);
835 ret = asn1p_ref_add_component($$.governor, $1, 0);
836 checkmem(ret == 0);
837 $$.argument = $3;
838 }
Lev Walkinc8092cb2005-02-18 16:34:21 +0000839 | TypeRefName ':' TypeRefName {
840 int ret;
841 $$.governor = asn1p_ref_new(yylineno);
842 ret = asn1p_ref_add_component($$.governor, $1, 0);
843 checkmem(ret == 0);
844 $$.argument = $3;
845 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000846 | BasicTypeId ':' Identifier {
847 int ret;
848 $$.governor = asn1p_ref_new(yylineno);
849 ret = asn1p_ref_add_component($$.governor,
850 ASN_EXPR_TYPE2STR($1), 1);
851 checkmem(ret == 0);
852 $$.argument = $3;
853 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000854 | BasicTypeId ':' TypeRefName {
855 int ret;
856 $$.governor = asn1p_ref_new(yylineno);
857 ret = asn1p_ref_add_component($$.governor,
858 ASN_EXPR_TYPE2STR($1), 1);
859 checkmem(ret == 0);
860 $$.argument = $3;
861 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000862 ;
863
Lev Walkin5045dfa2006-03-21 09:41:28 +0000864ActualParameterList:
865 ActualParameter {
Lev Walkinf15320b2004-06-03 03:38:44 +0000866 $$ = asn1p_expr_new(yylineno);
867 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000868 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000869 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000870 | ActualParameterList ',' ActualParameter {
Lev Walkinf15320b2004-06-03 03:38:44 +0000871 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000872 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000873 }
874 ;
875
Lev Walkin5045dfa2006-03-21 09:41:28 +0000876ActualParameter:
Lev Walkin070a52d2004-08-22 03:19:54 +0000877 Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000878 $$ = $1;
879 }
Lev Walkin0c0bca62006-03-21 04:48:15 +0000880 | SimpleValue {
881 $$ = asn1p_expr_new(yylineno);
882 checkmem($$);
883 $$->Identifier = "?";
884 $$->expr_type = A1TC_REFERENCE;
885 $$->meta_type = AMT_VALUE;
886 $$->value = $1;
887 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000888 | Identifier {
Lev Walkina00d6b32006-03-21 03:40:38 +0000889 asn1p_ref_t *ref;
Lev Walkinf15320b2004-06-03 03:38:44 +0000890 $$ = asn1p_expr_new(yylineno);
891 checkmem($$);
892 $$->Identifier = $1;
893 $$->expr_type = A1TC_REFERENCE;
894 $$->meta_type = AMT_VALUE;
Lev Walkina00d6b32006-03-21 03:40:38 +0000895 ref = asn1p_ref_new(yylineno);
896 asn1p_ref_add_component(ref, $1, RLT_lowercase);
897 $$->value = asn1p_value_fromref(ref, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +0000898 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000899 | ValueSet {
900 $$ = asn1p_expr_new(yylineno);
901 $$->expr_type = A1TC_VALUESET;
902 $$->meta_type = AMT_VALUESET;
903 $$->constraints = $1;
904 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000905 ;
906
907/*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000908 | '{' ActualParameter '}' {
Lev Walkinc8092cb2005-02-18 16:34:21 +0000909 $$ = asn1p_expr_new(yylineno);
910 checkmem($$);
911 asn1p_expr_add($$, $2);
912 $$->expr_type = A1TC_PARAMETRIZED;
913 $$->meta_type = AMT_TYPE;
914 }
915 ;
916*/
917
918/*
Lev Walkinf15320b2004-06-03 03:38:44 +0000919 * A collection of constructed data type members.
920 */
Lev Walkin144db9b2004-10-12 23:26:53 +0000921optComponentTypeLists:
922 { $$ = asn1p_expr_new(yylineno); }
923 | ComponentTypeLists { $$ = $1; };
924
Lev Walkin070a52d2004-08-22 03:19:54 +0000925ComponentTypeLists:
926 ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +0000927 $$ = asn1p_expr_new(yylineno);
928 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000929 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000930 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000931 | ComponentTypeLists ',' ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +0000932 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000933 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000934 }
935 ;
936
Lev Walkin070a52d2004-08-22 03:19:54 +0000937ComponentType:
Lev Walkinaf120f72004-09-14 02:36:39 +0000938 Identifier Type optMarker {
Lev Walkin070a52d2004-08-22 03:19:54 +0000939 $$ = $2;
940 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +0000941 $$->Identifier = $1;
Lev Walkinef625402005-09-05 05:17:57 +0000942 $3.flags |= $$->marker.flags;
Lev Walkin070a52d2004-08-22 03:19:54 +0000943 $$->marker = $3;
944 }
Lev Walkinef625402005-09-05 05:17:57 +0000945 | Type optMarker {
946 $$ = $1;
947 $2.flags |= $$->marker.flags;
948 $$->marker = $2;
949 _fixup_anonymous_identifier($$);
950 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000951 | TOK_COMPONENTS TOK_OF Type {
952 $$ = asn1p_expr_new(yylineno);
953 checkmem($$);
954 $$->meta_type = $3->meta_type;
955 $$->expr_type = A1TC_COMPONENTS_OF;
Lev Walkin1004aa92004-09-08 00:28:11 +0000956 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +0000957 }
958 | ExtensionAndException {
959 $$ = $1;
960 }
961 ;
962
963AlternativeTypeLists:
964 AlternativeType {
965 $$ = asn1p_expr_new(yylineno);
966 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000967 asn1p_expr_add($$, $1);
Lev Walkin070a52d2004-08-22 03:19:54 +0000968 }
969 | AlternativeTypeLists ',' AlternativeType {
970 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000971 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +0000972 }
973 ;
974
975AlternativeType:
Lev Walkinaf120f72004-09-14 02:36:39 +0000976 Identifier Type {
Lev Walkin070a52d2004-08-22 03:19:54 +0000977 $$ = $2;
978 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +0000979 $$->Identifier = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +0000980 }
981 | ExtensionAndException {
982 $$ = $1;
983 }
Lev Walkin2e9bd5c2005-08-13 09:07:11 +0000984 | Type {
985 $$ = $1;
986 _fixup_anonymous_identifier($$);
987 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000988 ;
989
Lev Walkin9c2285a2006-03-09 08:49:26 +0000990ObjectClass:
991 TOK_CLASS '{' FieldSpec '}' optWithSyntax {
Lev Walkinf15320b2004-06-03 03:38:44 +0000992 $$ = $3;
993 checkmem($$);
994 $$->with_syntax = $5;
995 assert($$->expr_type == A1TC_CLASSDEF);
Lev Walkin9c2285a2006-03-09 08:49:26 +0000996 assert($$->meta_type == AMT_OBJECTCLASS);
Lev Walkinf15320b2004-06-03 03:38:44 +0000997 }
998 ;
999
1000optUnique:
1001 { $$ = 0; }
1002 | TOK_UNIQUE { $$ = 1; }
1003 ;
1004
Lev Walkin9c2285a2006-03-09 08:49:26 +00001005FieldSpec:
Lev Walkinf15320b2004-06-03 03:38:44 +00001006 ClassField {
1007 $$ = asn1p_expr_new(yylineno);
1008 checkmem($$);
1009 $$->expr_type = A1TC_CLASSDEF;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001010 $$->meta_type = AMT_OBJECTCLASS;
Lev Walkin1004aa92004-09-08 00:28:11 +00001011 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001012 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001013 | FieldSpec ',' ClassField {
Lev Walkinf15320b2004-06-03 03:38:44 +00001014 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001015 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001016 }
1017 ;
1018
Lev Walkin9c2285a2006-03-09 08:49:26 +00001019 /* X.681 */
Lev Walkinf15320b2004-06-03 03:38:44 +00001020ClassField:
Lev Walkin9c2285a2006-03-09 08:49:26 +00001021
1022 /* TypeFieldSpec ::= typefieldreference TypeOptionalitySpec? */
1023 TOK_typefieldreference optMarker {
Lev Walkinf15320b2004-06-03 03:38:44 +00001024 $$ = asn1p_expr_new(yylineno);
1025 checkmem($$);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001026 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001027 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001028 $$->expr_type = A1TC_CLASSFIELD_TFS; /* TypeFieldSpec */
Lev Walkinf15320b2004-06-03 03:38:44 +00001029 $$->marker = $2;
1030 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001031
1032 /* FixedTypeValueFieldSpec ::= valuefieldreference Type UNIQUE ? ValueOptionalitySpec ? */
1033 | TOK_valuefieldreference Type optUnique optMarker {
1034 $$ = asn1p_expr_new(yylineno);
1035 $$->Identifier = $1;
1036 $$->meta_type = AMT_OBJECTFIELD;
1037 $$->expr_type = A1TC_CLASSFIELD_FTVFS; /* FixedTypeValueFieldSpec */
Lev Walkinb7c45ca2004-11-24 17:43:29 +00001038 $$->unique = $3;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001039 $$->marker = $4;
1040 asn1p_expr_add($$, $2);
Lev Walkinf15320b2004-06-03 03:38:44 +00001041 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001042
1043 /* VariableTypeValueFieldSpec ::= valuefieldreference FieldName ValueOptionalitySpec ? */
1044 | TOK_valuefieldreference FieldName optMarker {
1045 $$ = asn1p_expr_new(yylineno);
1046 $$->Identifier = $1;
1047 $$->meta_type = AMT_OBJECTFIELD;
1048 $$->expr_type = A1TC_CLASSFIELD_VTVFS;
1049 $$->reference = $2;
1050 $$->marker = $3;
1051 }
1052
Lev Walkin9c2285a2006-03-09 08:49:26 +00001053 /* ObjectFieldSpec ::= objectfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1054 | TOK_valuefieldreference DefinedObjectClass optMarker {
Lev Walkinf15320b2004-06-03 03:38:44 +00001055 $$ = asn1p_expr_new(yylineno);
1056 checkmem($$);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001057 $$->Identifier = $1;
1058 $$->reference = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00001059 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001060 $$->expr_type = A1TC_CLASSFIELD_OFS;
1061 $$->marker = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +00001062 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001063
Lev Walkin54868752006-03-09 09:08:49 +00001064 /* VariableTypeValueSetFieldSpec ::= valuesetfieldreference FieldName ValueOptionalitySpec ? */
1065 | TOK_typefieldreference FieldName optMarker {
Lev Walkin9c2285a2006-03-09 08:49:26 +00001066 $$ = asn1p_expr_new(yylineno);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001067 $$->Identifier = $1;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001068 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin54868752006-03-09 09:08:49 +00001069 $$->expr_type = A1TC_CLASSFIELD_VTVSFS;
1070 $$->reference = $2;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001071 $$->marker = $3;
1072 }
1073
1074 /* FixedTypeValueSetFieldSpec ::= valuesetfieldreference Type ValueSetOptionalitySpec ? */
1075 | TOK_typefieldreference Type optMarker {
1076 $$ = asn1p_expr_new(yylineno);
1077 checkmem($$);
1078 $$->Identifier = $1;
1079 $$->meta_type = AMT_OBJECTFIELD;
1080 $$->expr_type = A1TC_CLASSFIELD_FTVSFS;
1081 asn1p_expr_add($$, $2);
1082 $$->marker = $3;
1083 }
1084
Lev Walkin54868752006-03-09 09:08:49 +00001085 /* ObjectSetFieldSpec ::= objectsetfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1086 | TOK_typefieldreference DefinedObjectClass optMarker {
1087 $$ = asn1p_expr_new(yylineno);
1088 checkmem($$);
1089 $$->Identifier = $1;
1090 $$->reference = $2;
1091 $$->meta_type = AMT_OBJECTFIELD;
1092 $$->expr_type = A1TC_CLASSFIELD_OSFS;
1093 $$->marker = $3;
1094 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001095 ;
1096
1097optWithSyntax:
1098 { $$ = 0; }
1099 | WithSyntax {
1100 $$ = $1;
1101 }
1102 ;
1103
1104WithSyntax:
1105 TOK_WITH TOK_SYNTAX '{'
1106 { asn1p_lexer_hack_enable_with_syntax(); }
Lev Walkin9d542d22006-03-14 16:31:37 +00001107 WithSyntaxList
Lev Walkinf15320b2004-06-03 03:38:44 +00001108 '}' {
1109 $$ = $5;
1110 }
1111 ;
1112
Lev Walkin9d542d22006-03-14 16:31:37 +00001113WithSyntaxList:
1114 WithSyntaxToken {
Lev Walkinf15320b2004-06-03 03:38:44 +00001115 $$ = asn1p_wsyntx_new();
1116 TQ_ADD(&($$->chunks), $1, next);
1117 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001118 | WithSyntaxList WithSyntaxToken {
Lev Walkinf15320b2004-06-03 03:38:44 +00001119 $$ = $1;
1120 TQ_ADD(&($$->chunks), $2, next);
1121 }
1122 ;
1123
Lev Walkin9d542d22006-03-14 16:31:37 +00001124WithSyntaxToken:
Lev Walkin57074f12006-03-16 05:11:14 +00001125 TOK_whitespace {
Lev Walkinf15320b2004-06-03 03:38:44 +00001126 $$ = asn1p_wsyntx_chunk_frombuf($1.buf, $1.len, 0);
Lev Walkin57074f12006-03-16 05:11:14 +00001127 $$->type = WC_WHITESPACE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001128 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001129 | TOK_Literal {
1130 $$ = asn1p_wsyntx_chunk_frombuf($1, strlen($1), 0);
1131 }
Lev Walkind370e9f2006-03-16 10:03:35 +00001132 | PrimitiveFieldReference {
1133 $$ = asn1p_wsyntx_chunk_frombuf($1.name, strlen($1.name), 0);
1134 $$->type = WC_FIELD;
Lev Walkinf15320b2004-06-03 03:38:44 +00001135 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001136 | '[' WithSyntaxList ']' {
1137 $$ = asn1p_wsyntx_chunk_fromsyntax($2);
1138 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001139 ;
1140
Lev Walkinf15320b2004-06-03 03:38:44 +00001141ExtensionAndException:
1142 TOK_ThreeDots {
Lev Walkinceb20e72004-09-05 10:40:41 +00001143 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001144 checkmem($$);
1145 $$->Identifier = strdup("...");
1146 checkmem($$->Identifier);
1147 $$->expr_type = A1TC_EXTENSIBLE;
1148 $$->meta_type = AMT_TYPE;
1149 }
1150 | TOK_ThreeDots '!' DefinedValue {
Lev Walkinceb20e72004-09-05 10:40:41 +00001151 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001152 checkmem($$);
1153 $$->Identifier = strdup("...");
1154 checkmem($$->Identifier);
1155 $$->value = $3;
1156 $$->expr_type = A1TC_EXTENSIBLE;
1157 $$->meta_type = AMT_TYPE;
1158 }
1159 | TOK_ThreeDots '!' SignedNumber {
Lev Walkinceb20e72004-09-05 10:40:41 +00001160 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001161 checkmem($$);
1162 $$->Identifier = strdup("...");
1163 $$->value = $3;
1164 checkmem($$->Identifier);
1165 $$->expr_type = A1TC_EXTENSIBLE;
1166 $$->meta_type = AMT_TYPE;
1167 }
1168 ;
1169
Lev Walkin070a52d2004-08-22 03:19:54 +00001170Type:
Lev Walkinaf120f72004-09-14 02:36:39 +00001171 optTag TypeDeclaration optConstraints {
1172 $$ = $2;
1173 $$->tag = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001174 /*
1175 * Outer constraint for SEQUENCE OF and SET OF applies
1176 * to the inner type.
1177 */
1178 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1179 || $$->expr_type == ASN_CONSTR_SET_OF) {
1180 assert(!TQ_FIRST(&($$->members))->constraints);
Lev Walkinaf120f72004-09-14 02:36:39 +00001181 TQ_FIRST(&($$->members))->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001182 } else {
1183 if($$->constraints) {
1184 assert(!$2);
1185 } else {
Lev Walkinaf120f72004-09-14 02:36:39 +00001186 $$->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001187 }
1188 }
Lev Walkinef625402005-09-05 05:17:57 +00001189 }
1190 ;
1191
1192NSTD_IndirectMarker:
1193 {
1194 $$ = asn1p_as_pointer ? EM_INDIRECT : 0;
1195 asn1p_as_pointer = 0;
Lev Walkin070a52d2004-08-22 03:19:54 +00001196 }
1197 ;
1198
1199TypeDeclaration:
Lev Walkinef625402005-09-05 05:17:57 +00001200 NSTD_IndirectMarker TypeDeclarationSet {
Lev Walkin4696c742005-08-22 12:23:54 +00001201 $$ = $2;
Lev Walkinef625402005-09-05 05:17:57 +00001202 $$->marker.flags |= $1;
1203
1204 if(($$->marker.flags & EM_INDIRECT)
1205 && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
1206 fprintf(stderr,
1207 "INFO: Directive <ASN1C:RepresentAsPointer> "
1208 "applied to %s at line %d\n",
1209 ASN_EXPR_TYPE2STR($$->expr_type)
1210 ? ASN_EXPR_TYPE2STR($$->expr_type)
1211 : "member",
1212 $$->_lineno
1213 );
1214 }
Lev Walkin4696c742005-08-22 12:23:54 +00001215 }
Lev Walkinef625402005-09-05 05:17:57 +00001216 ;
Lev Walkin4696c742005-08-22 12:23:54 +00001217
1218TypeDeclarationSet:
Lev Walkin0c0bca62006-03-21 04:48:15 +00001219 DefinedType {
Lev Walkinf15320b2004-06-03 03:38:44 +00001220 $$ = $1;
1221 }
Lev Walkinef625402005-09-05 05:17:57 +00001222 | TOK_CHOICE '{' AlternativeTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001223 $$ = $3;
1224 assert($$->expr_type == A1TC_INVALID);
1225 $$->expr_type = ASN_CONSTR_CHOICE;
1226 $$->meta_type = AMT_TYPE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001227 }
Lev Walkinef625402005-09-05 05:17:57 +00001228 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001229 $$ = $3;
1230 assert($$->expr_type == A1TC_INVALID);
1231 $$->expr_type = ASN_CONSTR_SEQUENCE;
1232 $$->meta_type = AMT_TYPE;
1233 }
Lev Walkinef625402005-09-05 05:17:57 +00001234 | TOK_SET '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001235 $$ = $3;
1236 assert($$->expr_type == A1TC_INVALID);
1237 $$->expr_type = ASN_CONSTR_SET;
1238 $$->meta_type = AMT_TYPE;
1239 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001240 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkinceb20e72004-09-05 10:40:41 +00001241 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001242 checkmem($$);
1243 $$->constraints = $2;
1244 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1245 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001246 $6->Identifier = $4;
1247 $6->tag = $5;
1248 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001249 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001250 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkinceb20e72004-09-05 10:40:41 +00001251 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001252 checkmem($$);
1253 $$->constraints = $2;
1254 $$->expr_type = ASN_CONSTR_SET_OF;
1255 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001256 $6->Identifier = $4;
1257 $6->tag = $5;
1258 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001259 }
1260 | TOK_ANY {
Lev Walkinceb20e72004-09-05 10:40:41 +00001261 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001262 checkmem($$);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001263 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001264 $$->meta_type = AMT_TYPE;
1265 }
1266 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1267 int ret;
Lev Walkinceb20e72004-09-05 10:40:41 +00001268 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001269 checkmem($$);
1270 $$->reference = asn1p_ref_new(yylineno);
1271 ret = asn1p_ref_add_component($$->reference,
1272 $4, RLT_lowercase);
1273 checkmem(ret == 0);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001274 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001275 $$->meta_type = AMT_TYPE;
1276 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001277 | TOK_INSTANCE TOK_OF ComplexTypeReference {
1278 $$ = asn1p_expr_new(yylineno);
1279 checkmem($$);
1280 $$->reference = $3;
1281 $$->expr_type = A1TC_INSTANCE;
1282 $$->meta_type = AMT_TYPE;
1283 }
1284 ;
1285
1286/*
1287 * A type name consisting of several components.
1288 * === EXAMPLE ===
1289 * === EOF ===
1290 */
1291ComplexTypeReference:
1292 TOK_typereference {
1293 int ret;
1294 $$ = asn1p_ref_new(yylineno);
1295 checkmem($$);
1296 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1297 checkmem(ret == 0);
1298 free($1);
1299 }
1300 | TOK_typereference '.' TypeRefName {
1301 int ret;
1302 $$ = asn1p_ref_new(yylineno);
1303 checkmem($$);
1304 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1305 checkmem(ret == 0);
1306 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1307 checkmem(ret == 0);
1308 free($1);
1309 }
Lev Walkin9c974182004-09-15 11:59:51 +00001310 | ObjectClassReference '.' TypeRefName {
1311 int ret;
1312 $$ = asn1p_ref_new(yylineno);
1313 checkmem($$);
1314 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1315 checkmem(ret == 0);
1316 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1317 checkmem(ret == 0);
1318 free($1);
1319 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001320 | TOK_typereference '.' Identifier {
1321 int ret;
1322 $$ = asn1p_ref_new(yylineno);
1323 checkmem($$);
1324 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1325 checkmem(ret == 0);
1326 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1327 checkmem(ret == 0);
1328 free($1);
1329 }
1330 | ObjectClassReference {
1331 int ret;
1332 $$ = asn1p_ref_new(yylineno);
1333 checkmem($$);
1334 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1335 free($1);
1336 checkmem(ret == 0);
1337 }
1338 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1339 int ret;
1340 $$ = $3;
1341 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1342 free($1);
1343 checkmem(ret == 0);
1344 /*
1345 * Move the last element infront.
1346 */
1347 {
1348 struct asn1p_ref_component_s tmp_comp;
1349 tmp_comp = $$->components[$$->comp_count-1];
1350 memmove(&$$->components[1],
1351 &$$->components[0],
1352 sizeof($$->components[0])
1353 * ($$->comp_count - 1));
1354 $$->components[0] = tmp_comp;
1355 }
1356 }
1357 ;
1358
1359ComplexTypeReferenceAmpList:
1360 ComplexTypeReferenceElement {
1361 int ret;
1362 $$ = asn1p_ref_new(yylineno);
1363 checkmem($$);
1364 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1365 free($1.name);
1366 checkmem(ret == 0);
1367 }
1368 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1369 int ret;
1370 $$ = $1;
1371 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1372 free($3.name);
1373 checkmem(ret == 0);
1374 }
1375 ;
1376
Lev Walkind370e9f2006-03-16 10:03:35 +00001377ComplexTypeReferenceElement: PrimitiveFieldReference;
Lev Walkinf15320b2004-06-03 03:38:44 +00001378
Lev Walkind370e9f2006-03-16 10:03:35 +00001379PrimitiveFieldReference:
Lev Walkinf15320b2004-06-03 03:38:44 +00001380 /* "&Type1" */
1381 TOK_typefieldreference {
1382 $$.lex_type = RLT_AmpUppercase;
1383 $$.name = $1;
1384 }
1385 /* "&id" */
1386 | TOK_valuefieldreference {
1387 $$.lex_type = RLT_Amplowercase;
1388 $$.name = $1;
1389 }
1390 ;
1391
1392
Lev Walkin9c2285a2006-03-09 08:49:26 +00001393FieldName:
1394 /* "&Type1" */
1395 TOK_typefieldreference {
1396 $$ = asn1p_ref_new(yylineno);
1397 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1398 }
1399 | FieldName '.' TOK_typefieldreference {
1400 $$ = $$;
1401 asn1p_ref_add_component($$, $3, RLT_AmpUppercase);
1402 }
1403 | FieldName '.' TOK_valuefieldreference {
1404 $$ = $$;
1405 asn1p_ref_add_component($$, $3, RLT_Amplowercase);
1406 }
1407 ;
1408
1409DefinedObjectClass:
1410 TOK_capitalreference {
1411 $$ = asn1p_ref_new(yylineno);
1412 asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1413 }
Lev Walkin54868752006-03-09 09:08:49 +00001414/*
Lev Walkin9c2285a2006-03-09 08:49:26 +00001415 | TypeRefName '.' TOK_capitalreference {
1416 $$ = asn1p_ref_new(yylineno);
1417 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1418 asn1p_ref_add_component($$, $3, RLT_CAPITALS);
1419 }
Lev Walkin54868752006-03-09 09:08:49 +00001420*/
Lev Walkin9c2285a2006-03-09 08:49:26 +00001421 ;
1422
1423
Lev Walkinf15320b2004-06-03 03:38:44 +00001424/*
1425 * === EXAMPLE ===
1426 * value INTEGER ::= 1
1427 * === EOF ===
1428 */
1429ValueDefinition:
Lev Walkin0c0bca62006-03-21 04:48:15 +00001430 Identifier DefinedType TOK_PPEQ Value {
Lev Walkinf15320b2004-06-03 03:38:44 +00001431 $$ = $2;
1432 assert($$->Identifier == NULL);
1433 $$->Identifier = $1;
1434 $$->meta_type = AMT_VALUE;
1435 $$->value = $4;
1436 }
1437 ;
1438
Lev Walkin9c974182004-09-15 11:59:51 +00001439Value:
Lev Walkin0c0bca62006-03-21 04:48:15 +00001440 SimpleValue
1441 | DefinedValue
1442 | Identifier ':' Value {
Lev Walkin9c974182004-09-15 11:59:51 +00001443 $$ = asn1p_value_fromint(0);
1444 checkmem($$);
1445 $$->type = ATV_CHOICE_IDENTIFIER;
1446 $$->value.choice_identifier.identifier = $1;
1447 $$->value.choice_identifier.value = $3;
1448 }
Lev Walkincbad2512005-03-24 16:27:02 +00001449 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Lev Walkinf15320b2004-06-03 03:38:44 +00001450 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1451 checkmem($$);
1452 $$->type = ATV_UNPARSED;
1453 }
Lev Walkin9c974182004-09-15 11:59:51 +00001454 | TOK_NULL {
1455 $$ = asn1p_value_fromint(0);
1456 checkmem($$);
1457 $$->type = ATV_NULL;
1458 }
Lev Walkin0c0bca62006-03-21 04:48:15 +00001459 ;
1460
1461SimpleValue:
1462 TOK_FALSE {
Lev Walkin9c974182004-09-15 11:59:51 +00001463 $$ = asn1p_value_fromint(0);
1464 checkmem($$);
1465 $$->type = ATV_FALSE;
1466 }
1467 | TOK_TRUE {
1468 $$ = asn1p_value_fromint(0);
1469 checkmem($$);
1470 $$->type = ATV_TRUE;
1471 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001472 | TOK_bstring {
1473 $$ = _convert_bitstring2binary($1, 'B');
1474 checkmem($$);
1475 }
1476 | TOK_hstring {
1477 $$ = _convert_bitstring2binary($1, 'H');
1478 checkmem($$);
1479 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001480 | RestrictedCharacterStringValue {
1481 $$ = $$;
Lev Walkinf15320b2004-06-03 03:38:44 +00001482 }
1483 | SignedNumber {
1484 $$ = $1;
1485 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001486 ;
1487
1488DefinedValue:
1489 Identifier {
1490 asn1p_ref_t *ref;
1491 int ret;
1492 ref = asn1p_ref_new(yylineno);
1493 checkmem(ref);
1494 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1495 checkmem(ret == 0);
1496 $$ = asn1p_value_fromref(ref, 0);
1497 checkmem($$);
1498 free($1);
1499 }
1500 | TypeRefName '.' Identifier {
1501 asn1p_ref_t *ref;
1502 int ret;
1503 ref = asn1p_ref_new(yylineno);
1504 checkmem(ref);
1505 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1506 checkmem(ret == 0);
1507 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1508 checkmem(ret == 0);
1509 $$ = asn1p_value_fromref(ref, 0);
1510 checkmem($$);
1511 free($1);
1512 free($3);
1513 }
1514 ;
1515
Lev Walkin1e448d32005-03-24 14:26:38 +00001516
1517RestrictedCharacterStringValue:
1518 TOK_cstring {
1519 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1520 checkmem($$);
1521 }
Lev Walkind9574ae2005-03-24 16:22:35 +00001522 | TOK_tuple {
1523 $$ = asn1p_value_fromint($1);
1524 checkmem($$);
1525 $$->type = ATV_TUPLE;
1526 }
1527 | TOK_quadruple {
1528 $$ = asn1p_value_fromint($1);
1529 checkmem($$);
1530 $$->type = ATV_QUADRUPLE;
1531 }
1532 /*
Lev Walkin1e448d32005-03-24 14:26:38 +00001533 | '{' TOK_number ',' TOK_number '}' {
1534 asn1c_integer_t v = ($2 << 4) + $4;
1535 if($2 > 7) return yyerror("X.680:2003, #37.14 "
1536 "mandates 0..7 range for Tuple's TableColumn");
1537 if($4 > 15) return yyerror("X.680:2003, #37.14 "
1538 "mandates 0..15 range for Tuple's TableRow");
1539 $$ = asn1p_value_fromint(v);
1540 checkmem($$);
1541 $$->type = ATV_TUPLE;
1542 }
1543 | '{' TOK_number ',' TOK_number ',' TOK_number ',' TOK_number '}' {
1544 asn1c_integer_t v = ($2 << 24) | ($4 << 16) | ($6 << 8) | $8;
1545 if($2 > 127) return yyerror("X.680:2003, #37.12 "
1546 "mandates 0..127 range for Quadruple's Group");
1547 if($4 > 255) return yyerror("X.680:2003, #37.12 "
1548 "mandates 0..255 range for Quadruple's Plane");
1549 if($6 > 255) return yyerror("X.680:2003, #37.12 "
1550 "mandates 0..255 range for Quadruple's Row");
1551 if($8 > 255) return yyerror("X.680:2003, #37.12 "
1552 "mandates 0..255 range for Quadruple's Cell");
1553 $$ = asn1p_value_fromint(v);
1554 checkmem($$);
1555 $$->type = ATV_QUADRUPLE;
1556 }
Lev Walkind9574ae2005-03-24 16:22:35 +00001557 */
Lev Walkin1e448d32005-03-24 14:26:38 +00001558 ;
1559
Lev Walkinf15320b2004-06-03 03:38:44 +00001560Opaque:
1561 TOK_opaque {
Lev Walkin1893ddf2005-03-20 14:28:32 +00001562 $$.len = $1.len + 1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001563 $$.buf = malloc($$.len + 1);
1564 checkmem($$.buf);
1565 $$.buf[0] = '{';
Lev Walkin1893ddf2005-03-20 14:28:32 +00001566 memcpy($$.buf + 1, $1.buf, $1.len);
Lev Walkinf15320b2004-06-03 03:38:44 +00001567 $$.buf[$$.len] = '\0';
1568 free($1.buf);
1569 }
1570 | Opaque TOK_opaque {
1571 int newsize = $1.len + $2.len;
1572 char *p = malloc(newsize + 1);
1573 checkmem(p);
1574 memcpy(p , $1.buf, $1.len);
1575 memcpy(p + $1.len, $2.buf, $2.len);
1576 p[newsize] = '\0';
1577 free($1.buf);
1578 free($2.buf);
1579 $$.buf = p;
1580 $$.len = newsize;
1581 }
1582 ;
1583
1584BasicTypeId:
1585 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1586 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1587 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1588 | BasicTypeId_UniverationCompatible { $$ = $1; }
1589 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1590 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1591 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1592 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1593 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1594 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1595 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1596 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
Lev Walkinc7d939d2005-03-20 11:12:40 +00001597 | BasicString { $$ = $1; }
Lev Walkinf15320b2004-06-03 03:38:44 +00001598 ;
1599
1600/*
1601 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1602 */
1603BasicTypeId_UniverationCompatible:
1604 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1605 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1606 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1607 ;
1608
1609BasicType:
1610 BasicTypeId {
Lev Walkinceb20e72004-09-05 10:40:41 +00001611 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001612 checkmem($$);
1613 $$->expr_type = $1;
1614 $$->meta_type = AMT_TYPE;
1615 }
1616 | BasicTypeId_UniverationCompatible UniverationDefinition {
1617 if($2) {
1618 $$ = $2;
1619 } else {
Lev Walkinceb20e72004-09-05 10:40:41 +00001620 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001621 checkmem($$);
1622 }
1623 $$->expr_type = $1;
1624 $$->meta_type = AMT_TYPE;
1625 }
1626 ;
1627
1628BasicString:
1629 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1630 | TOK_GeneralString {
1631 $$ = ASN_STRING_GeneralString;
Lev Walkin9c974182004-09-15 11:59:51 +00001632 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001633 }
1634 | TOK_GraphicString {
1635 $$ = ASN_STRING_GraphicString;
Lev Walkin9c974182004-09-15 11:59:51 +00001636 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001637 }
1638 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1639 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1640 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1641 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1642 | TOK_T61String {
1643 $$ = ASN_STRING_T61String;
Lev Walkin9c974182004-09-15 11:59:51 +00001644 fprintf(stderr, "WARNING: T61String is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001645 }
1646 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1647 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1648 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1649 | TOK_VideotexString {
1650 $$ = ASN_STRING_VideotexString;
Lev Walkin9c974182004-09-15 11:59:51 +00001651 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001652 }
1653 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1654 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1655 ;
1656
Lev Walkind2ea1de2004-08-20 13:25:29 +00001657
Lev Walkinf15320b2004-06-03 03:38:44 +00001658/*
1659 * Data type constraints.
1660 */
Lev Walkinf15320b2004-06-03 03:38:44 +00001661Union: '|' | TOK_UNION;
1662Intersection: '^' | TOK_INTERSECTION;
1663Except: TOK_EXCEPT;
1664
Lev Walkinf59d0752004-08-18 04:59:12 +00001665optConstraints:
1666 { $$ = 0; }
Lev Walkind2ea1de2004-08-20 13:25:29 +00001667 | Constraints {
1668 $$ = $1;
1669 }
1670 ;
1671
1672Constraints:
1673 SetOfConstraints {
Lev Walkin2c14a692005-08-12 10:08:45 +00001674 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
Lev Walkinf59d0752004-08-18 04:59:12 +00001675 }
1676 | TOK_SIZE '(' ElementSetSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001677 /*
1678 * This is a special case, for compatibility purposes.
Lev Walkinf59d0752004-08-18 04:59:12 +00001679 * It goes without parentheses.
Lev Walkinf15320b2004-06-03 03:38:44 +00001680 */
Lev Walkin2c14a692005-08-12 10:08:45 +00001681 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001682 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001683 ;
1684
Lev Walkinf59d0752004-08-18 04:59:12 +00001685SetOfConstraints:
1686 '(' ElementSetSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001687 $$ = $2;
1688 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001689 | SetOfConstraints '(' ElementSetSpecs ')' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001690 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
Lev Walkinf59d0752004-08-18 04:59:12 +00001691 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001692 ;
1693
Lev Walkinf59d0752004-08-18 04:59:12 +00001694ElementSetSpecs:
Lev Walkin5045dfa2006-03-21 09:41:28 +00001695 TOK_ThreeDots {
1696 $$ = asn1p_constraint_new(yylineno);
1697 $$->type = ACT_EL_EXT;
1698 }
1699 | ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001700 $$ = $1;
1701 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001702 | ElementSetSpec ',' TOK_ThreeDots {
Lev Walkinf15320b2004-06-03 03:38:44 +00001703 asn1p_constraint_t *ct;
1704 ct = asn1p_constraint_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001705 ct->type = ACT_EL_EXT;
Lev Walkin2c14a692005-08-12 10:08:45 +00001706 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00001707 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001708 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001709 asn1p_constraint_t *ct;
1710 ct = asn1p_constraint_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001711 ct->type = ACT_EL_EXT;
Lev Walkin2c14a692005-08-12 10:08:45 +00001712 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinb4fcdd22004-08-13 12:35:09 +00001713 ct = $$;
Lev Walkin2c14a692005-08-12 10:08:45 +00001714 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
Lev Walkinf15320b2004-06-03 03:38:44 +00001715 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001716 ;
1717
Lev Walkinf59d0752004-08-18 04:59:12 +00001718ElementSetSpec:
1719 ConstraintSubtypeElement {
1720 $$ = $1;
1721 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001722 | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001723 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
Lev Walkin1e448d32005-03-24 14:26:38 +00001724 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001725 | ElementSetSpec Union ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001726 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001727 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001728 | ElementSetSpec Intersection ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001729 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001730 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001731 | ConstraintSubtypeElement Except ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001732 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001733 }
1734 ;
1735
1736ConstraintSubtypeElement:
Lev Walkinf59d0752004-08-18 04:59:12 +00001737 ConstraintSpec '(' ElementSetSpecs ')' {
1738 int ret;
1739 $$ = asn1p_constraint_new(yylineno);
1740 checkmem($$);
1741 $$->type = $1;
1742 ret = asn1p_constraint_insert($$, $3);
1743 checkmem(ret == 0);
1744 }
1745 | '(' ElementSetSpecs ')' {
1746 int ret;
1747 $$ = asn1p_constraint_new(yylineno);
1748 checkmem($$);
1749 $$->type = ACT_CA_SET;
1750 ret = asn1p_constraint_insert($$, $2);
1751 checkmem(ret == 0);
1752 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001753 | SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001754 $$ = asn1p_constraint_new(yylineno);
1755 checkmem($$);
1756 $$->type = ACT_EL_VALUE;
1757 $$->value = $1;
1758 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001759 | ContainedSubtype {
1760 $$ = asn1p_constraint_new(yylineno);
1761 checkmem($$);
1762 $$->type = ACT_EL_TYPE;
1763 $$->containedSubtype = $1;
1764 }
1765 | SingleValue ConstraintRangeSpec SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001766 $$ = asn1p_constraint_new(yylineno);
1767 checkmem($$);
1768 $$->type = $2;
1769 $$->range_start = $1;
1770 $$->range_stop = $3;
1771 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001772 | TOK_MIN ConstraintRangeSpec SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001773 $$ = asn1p_constraint_new(yylineno);
1774 checkmem($$);
Lev Walkinf59d0752004-08-18 04:59:12 +00001775 $$->type = $2;
1776 $$->range_start = asn1p_value_fromint(-123);
1777 $$->range_stop = $3;
1778 $$->range_start->type = ATV_MIN;
1779 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001780 | SingleValue ConstraintRangeSpec TOK_MAX {
Lev Walkinf59d0752004-08-18 04:59:12 +00001781 $$ = asn1p_constraint_new(yylineno);
1782 checkmem($$);
1783 $$->type = $2;
1784 $$->range_start = $1;
1785 $$->range_stop = asn1p_value_fromint(321);
1786 $$->range_stop->type = ATV_MAX;
1787 }
1788 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1789 $$ = asn1p_constraint_new(yylineno);
1790 checkmem($$);
1791 $$->type = $2;
1792 $$->range_start = asn1p_value_fromint(-123);
1793 $$->range_stop = asn1p_value_fromint(321);
1794 $$->range_start->type = ATV_MIN;
1795 $$->range_stop->type = ATV_MAX;
Lev Walkinf15320b2004-06-03 03:38:44 +00001796 }
1797 | TableConstraint {
1798 $$ = $1;
1799 }
Lev Walkine596bf02005-03-28 15:01:27 +00001800 | InnerTypeConstraint {
Lev Walkinf15320b2004-06-03 03:38:44 +00001801 $$ = $1;
1802 }
Lev Walkin1893ddf2005-03-20 14:28:32 +00001803 | TOK_CONSTRAINED TOK_BY '{'
1804 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1805 $$ = asn1p_constraint_new(yylineno);
1806 checkmem($$);
1807 $$->type = ACT_CT_CTDBY;
1808 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
1809 checkmem($$->value);
1810 $$->value->type = ATV_UNPARSED;
1811 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001812 ;
1813
1814ConstraintRangeSpec:
1815 TOK_TwoDots { $$ = ACT_EL_RANGE; }
1816 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
1817 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
1818 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
1819 ;
1820
1821ConstraintSpec:
1822 TOK_SIZE {
1823 $$ = ACT_CT_SIZE;
1824 }
1825 | TOK_FROM {
1826 $$ = ACT_CT_FROM;
1827 }
1828 ;
1829
Lev Walkinff7dd142005-03-20 12:58:00 +00001830SingleValue:
Lev Walkinc8092cb2005-02-18 16:34:21 +00001831 TOK_FALSE {
1832 $$ = asn1p_value_fromint(0);
1833 checkmem($$);
1834 $$->type = ATV_FALSE;
1835 }
1836 | TOK_TRUE {
1837 $$ = asn1p_value_fromint(1);
1838 checkmem($$);
1839 $$->type = ATV_TRUE;
1840 }
1841 | SignedNumber {
Lev Walkinf15320b2004-06-03 03:38:44 +00001842 $$ = $1;
1843 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001844 | RestrictedCharacterStringValue {
1845 $$ = $1;
Lev Walkinc8092cb2005-02-18 16:34:21 +00001846 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001847 | Identifier {
1848 asn1p_ref_t *ref;
1849 int ret;
1850 ref = asn1p_ref_new(yylineno);
1851 checkmem(ref);
1852 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1853 checkmem(ret == 0);
1854 $$ = asn1p_value_fromref(ref, 0);
1855 checkmem($$);
1856 free($1);
1857 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001858 ;
1859
1860ContainedSubtype:
1861 TypeRefName {
Lev Walkinc8092cb2005-02-18 16:34:21 +00001862 asn1p_ref_t *ref;
1863 int ret;
1864 ref = asn1p_ref_new(yylineno);
1865 checkmem(ref);
1866 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1867 checkmem(ret == 0);
1868 $$ = asn1p_value_fromref(ref, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001869 checkmem($$);
Lev Walkinc8092cb2005-02-18 16:34:21 +00001870 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001871 }
1872 ;
1873
Lev Walkine596bf02005-03-28 15:01:27 +00001874InnerTypeConstraint:
1875 TOK_WITH TOK_COMPONENT SetOfConstraints {
Lev Walkin2c14a692005-08-12 10:08:45 +00001876 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
Lev Walkine596bf02005-03-28 15:01:27 +00001877 }
1878 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001879 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001880 }
1881 ;
1882
1883WithComponentsList:
1884 WithComponentsElement {
1885 $$ = $1;
1886 }
1887 | WithComponentsList ',' WithComponentsElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001888 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001889 }
1890 ;
1891
1892WithComponentsElement:
1893 TOK_ThreeDots {
1894 $$ = asn1p_constraint_new(yylineno);
1895 checkmem($$);
1896 $$->type = ACT_EL_EXT;
Lev Walkine596bf02005-03-28 15:01:27 +00001897 $$->value = asn1p_value_frombuf("...", 3, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001898 }
1899 | Identifier optConstraints optPresenceConstraint {
1900 $$ = asn1p_constraint_new(yylineno);
1901 checkmem($$);
1902 $$->type = ACT_EL_VALUE;
1903 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1904 $$->presence = $3;
Lev Walkine596bf02005-03-28 15:01:27 +00001905 if($2) asn1p_constraint_insert($$, $2);
Lev Walkinf15320b2004-06-03 03:38:44 +00001906 }
1907 ;
1908
1909/*
1910 * presence constraint for WithComponents
1911 */
1912optPresenceConstraint:
1913 { $$ = ACPRES_DEFAULT; }
1914 | PresenceConstraint { $$ = $1; }
1915 ;
1916
1917PresenceConstraint:
1918 TOK_PRESENT {
1919 $$ = ACPRES_PRESENT;
1920 }
1921 | TOK_ABSENT {
1922 $$ = ACPRES_ABSENT;
1923 }
1924 | TOK_OPTIONAL {
1925 $$ = ACPRES_OPTIONAL;
1926 }
1927 ;
1928
1929TableConstraint:
1930 SimpleTableConstraint {
1931 $$ = $1;
1932 }
1933 | ComponentRelationConstraint {
1934 $$ = $1;
1935 }
1936 ;
1937
1938/*
1939 * "{ExtensionSet}"
1940 */
1941SimpleTableConstraint:
1942 '{' TypeRefName '}' {
1943 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
1944 asn1p_constraint_t *ct;
1945 int ret;
1946 ret = asn1p_ref_add_component(ref, $2, 0);
1947 checkmem(ret == 0);
1948 ct = asn1p_constraint_new(yylineno);
1949 checkmem($$);
1950 ct->type = ACT_EL_VALUE;
1951 ct->value = asn1p_value_fromref(ref, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00001952 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001953 }
1954 ;
1955
1956ComponentRelationConstraint:
1957 SimpleTableConstraint '{' AtNotationList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001958 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001959 }
1960 ;
1961
1962AtNotationList:
1963 AtNotationElement {
1964 $$ = asn1p_constraint_new(yylineno);
1965 checkmem($$);
1966 $$->type = ACT_EL_VALUE;
1967 $$->value = asn1p_value_fromref($1, 0);
1968 }
1969 | AtNotationList ',' AtNotationElement {
1970 asn1p_constraint_t *ct;
1971 ct = asn1p_constraint_new(yylineno);
1972 checkmem(ct);
1973 ct->type = ACT_EL_VALUE;
1974 ct->value = asn1p_value_fromref($3, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00001975 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00001976 }
1977 ;
1978
1979/*
1980 * @blah
1981 */
1982AtNotationElement:
1983 '@' ComponentIdList {
1984 char *p = malloc(strlen($2) + 2);
1985 int ret;
1986 *p = '@';
1987 strcpy(p + 1, $2);
1988 $$ = asn1p_ref_new(yylineno);
1989 ret = asn1p_ref_add_component($$, p, 0);
1990 checkmem(ret == 0);
1991 free(p);
1992 free($2);
1993 }
1994 | '@' '.' ComponentIdList {
1995 char *p = malloc(strlen($3) + 3);
1996 int ret;
1997 p[0] = '@';
1998 p[1] = '.';
1999 strcpy(p + 2, $3);
2000 $$ = asn1p_ref_new(yylineno);
2001 ret = asn1p_ref_add_component($$, p, 0);
2002 checkmem(ret == 0);
2003 free(p);
2004 free($3);
2005 }
2006 ;
2007
2008/* identifier "." ... */
2009ComponentIdList:
2010 Identifier {
2011 $$ = $1;
2012 }
2013 | ComponentIdList '.' Identifier {
2014 int l1 = strlen($1);
2015 int l3 = strlen($3);
2016 $$ = malloc(l1 + 1 + l3 + 1);
2017 memcpy($$, $1, l1);
2018 $$[l1] = '.';
2019 memcpy($$ + l1 + 1, $3, l3);
2020 $$[l1 + 1 + l3] = '\0';
2021 }
2022 ;
2023
2024
2025
2026/*
2027 * MARKERS
2028 */
2029
2030optMarker:
Lev Walkin9c974182004-09-15 11:59:51 +00002031 {
2032 $$.flags = EM_NOMARK;
2033 $$.default_value = 0;
2034 }
Lev Walkinf15320b2004-06-03 03:38:44 +00002035 | Marker { $$ = $1; }
2036 ;
2037
2038Marker:
2039 TOK_OPTIONAL {
Lev Walkin70853052005-11-26 11:21:55 +00002040 $$.flags = EM_OPTIONAL | EM_INDIRECT;
Lev Walkin9c974182004-09-15 11:59:51 +00002041 $$.default_value = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +00002042 }
Lev Walkin9c974182004-09-15 11:59:51 +00002043 | TOK_DEFAULT Value {
2044 $$.flags = EM_DEFAULT;
2045 $$.default_value = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00002046 }
2047 ;
2048
2049/*
2050 * Universal enumeration definition to use in INTEGER and ENUMERATED.
2051 * === EXAMPLE ===
2052 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
2053 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
2054 * === EOF ===
2055 */
2056/*
2057optUniverationDefinition:
2058 { $$ = 0; }
2059 | UniverationDefinition {
2060 $$ = $1;
2061 }
2062 ;
2063*/
2064
2065UniverationDefinition:
2066 '{' '}' {
Lev Walkinceb20e72004-09-05 10:40:41 +00002067 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00002068 checkmem($$);
2069 }
2070 | '{' UniverationList '}' {
2071 $$ = $2;
2072 }
2073 ;
2074
2075UniverationList:
2076 UniverationElement {
Lev Walkinceb20e72004-09-05 10:40:41 +00002077 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00002078 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00002079 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00002080 }
2081 | UniverationList ',' UniverationElement {
2082 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00002083 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002084 }
2085 ;
2086
2087UniverationElement:
2088 Identifier {
Lev Walkinceb20e72004-09-05 10:40:41 +00002089 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00002090 checkmem($$);
2091 $$->expr_type = A1TC_UNIVERVAL;
2092 $$->meta_type = AMT_VALUE;
2093 $$->Identifier = $1;
2094 }
2095 | Identifier '(' SignedNumber ')' {
Lev Walkinceb20e72004-09-05 10:40:41 +00002096 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00002097 checkmem($$);
2098 $$->expr_type = A1TC_UNIVERVAL;
2099 $$->meta_type = AMT_VALUE;
2100 $$->Identifier = $1;
2101 $$->value = $3;
2102 }
2103 | Identifier '(' DefinedValue ')' {
Lev Walkinceb20e72004-09-05 10:40:41 +00002104 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00002105 checkmem($$);
2106 $$->expr_type = A1TC_UNIVERVAL;
2107 $$->meta_type = AMT_VALUE;
2108 $$->Identifier = $1;
2109 $$->value = $3;
2110 }
2111 | SignedNumber {
Lev Walkinceb20e72004-09-05 10:40:41 +00002112 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00002113 checkmem($$);
2114 $$->expr_type = A1TC_UNIVERVAL;
2115 $$->meta_type = AMT_VALUE;
2116 $$->value = $1;
2117 }
2118 | TOK_ThreeDots {
Lev Walkinceb20e72004-09-05 10:40:41 +00002119 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00002120 checkmem($$);
2121 $$->Identifier = strdup("...");
2122 checkmem($$->Identifier);
2123 $$->expr_type = A1TC_EXTENSIBLE;
2124 $$->meta_type = AMT_VALUE;
2125 }
2126 ;
2127
2128SignedNumber:
2129 TOK_number {
2130 $$ = asn1p_value_fromint($1);
2131 checkmem($$);
2132 }
2133 | TOK_number_negative {
2134 $$ = asn1p_value_fromint($1);
2135 checkmem($$);
2136 }
2137 ;
2138
2139/*
2140 * SEQUENCE definition.
2141 * === EXAMPLE ===
2142 * Struct1 ::= SEQUENCE {
2143 * memb1 Struct2,
2144 * memb2 SEQUENCE OF {
2145 * memb2-1 Struct 3
2146 * }
2147 * }
2148 * === EOF ===
2149 */
2150
2151
2152
2153/*
2154 * SET definition.
2155 * === EXAMPLE ===
2156 * Person ::= SET {
2157 * name [0] PrintableString (SIZE(1..20)),
2158 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2159 * }
2160 * === EOF ===
2161 */
2162
2163optTag:
2164 { memset(&$$, 0, sizeof($$)); }
2165 | Tag { $$ = $1; }
2166 ;
2167
2168Tag:
Lev Walkinc603f102005-01-23 09:51:44 +00002169 TagTypeValue TagPlicit {
Lev Walkinf15320b2004-06-03 03:38:44 +00002170 $$ = $1;
Lev Walkinc603f102005-01-23 09:51:44 +00002171 $$.tag_mode = $2.tag_mode;
Lev Walkinf15320b2004-06-03 03:38:44 +00002172 }
Lev Walkinc603f102005-01-23 09:51:44 +00002173 ;
2174
2175TagTypeValue:
2176 '[' TagClass TOK_number ']' {
2177 $$ = $2;
2178 $$.tag_value = $3;
2179 };
2180
2181TagClass:
2182 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2183 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2184 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2185 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2186 ;
2187
2188TagPlicit:
2189 { $$.tag_mode = TM_DEFAULT; }
2190 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2191 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
Lev Walkinf15320b2004-06-03 03:38:44 +00002192 ;
2193
2194TypeRefName:
2195 TOK_typereference {
2196 checkmem($1);
2197 $$ = $1;
2198 }
Lev Walkinf59d0752004-08-18 04:59:12 +00002199 | TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002200 checkmem($1);
2201 $$ = $1;
2202 }
2203 ;
2204
Lev Walkinf59d0752004-08-18 04:59:12 +00002205
Lev Walkinf15320b2004-06-03 03:38:44 +00002206ObjectClassReference:
Lev Walkinf59d0752004-08-18 04:59:12 +00002207 TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002208 checkmem($1);
2209 $$ = $1;
2210 }
2211 ;
2212
Lev Walkin83cac2f2004-09-22 16:03:36 +00002213optIdentifier:
2214 { $$ = 0; }
2215 | Identifier {
2216 $$ = $1;
2217 }
Lev Walkin8f294e02005-06-06 08:28:58 +00002218 ;
Lev Walkin83cac2f2004-09-22 16:03:36 +00002219
Lev Walkinf15320b2004-06-03 03:38:44 +00002220Identifier:
2221 TOK_identifier {
2222 checkmem($1);
2223 $$ = $1;
2224 }
2225 ;
2226
Lev Walkinf15320b2004-06-03 03:38:44 +00002227%%
2228
2229
2230/*
2231 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2232 */
2233static asn1p_value_t *
2234_convert_bitstring2binary(char *str, int base) {
2235 asn1p_value_t *val;
2236 int slen;
2237 int memlen;
2238 int baselen;
2239 int bits;
2240 uint8_t *binary_vector;
2241 uint8_t *bv_ptr;
2242 uint8_t cur_val;
2243
2244 assert(str);
2245 assert(str[0] == '\'');
2246
2247 switch(base) {
2248 case 'B':
2249 baselen = 1;
2250 break;
2251 case 'H':
2252 baselen = 4;
2253 break;
2254 default:
2255 assert(base == 'B' || base == 'H');
2256 errno = EINVAL;
2257 return NULL;
2258 }
2259
2260 slen = strlen(str);
2261 assert(str[slen - 1] == base);
2262 assert(str[slen - 2] == '\'');
2263
2264 memlen = slen / (8 / baselen); /* Conservative estimate */
2265
2266 bv_ptr = binary_vector = malloc(memlen + 1);
2267 if(bv_ptr == NULL)
2268 /* ENOMEM */
2269 return NULL;
2270
2271 cur_val = 0;
2272 bits = 0;
2273 while(*(++str) != '\'') {
2274 switch(baselen) {
2275 case 1:
2276 switch(*str) {
2277 case '1':
2278 cur_val |= 1 << (7 - (bits % 8));
2279 case '0':
2280 break;
2281 default:
2282 assert(!"_y UNREACH1");
2283 case ' ': case '\r': case '\n':
2284 continue;
2285 }
2286 break;
2287 case 4:
2288 switch(*str) {
2289 case '0': case '1': case '2': case '3': case '4':
2290 case '5': case '6': case '7': case '8': case '9':
2291 cur_val |= (*str - '0') << (4 - (bits % 8));
2292 break;
2293 case 'A': case 'B': case 'C':
2294 case 'D': case 'E': case 'F':
2295 cur_val |= ((*str - 'A') + 10)
2296 << (4 - (bits % 8));
2297 break;
2298 default:
2299 assert(!"_y UNREACH2");
2300 case ' ': case '\r': case '\n':
2301 continue;
2302 }
2303 break;
2304 }
2305
2306 bits += baselen;
2307 if((bits % 8) == 0) {
2308 *bv_ptr++ = cur_val;
2309 cur_val = 0;
2310 }
2311 }
2312
2313 *bv_ptr = cur_val;
2314 assert((bv_ptr - binary_vector) <= memlen);
2315
2316 val = asn1p_value_frombits(binary_vector, bits, 0);
2317 if(val == NULL) {
2318 free(binary_vector);
2319 }
2320
2321 return val;
2322}
2323
Lev Walkin2e9bd5c2005-08-13 09:07:11 +00002324/*
2325 * For unnamed types (used in old X.208 compliant modules)
2326 * generate some sort of interim names, to not to force human being to fix
2327 * the specification's compliance to modern ASN.1 standards.
2328 */
2329static void
2330_fixup_anonymous_identifier(asn1p_expr_t *expr) {
2331 char *p;
2332 assert(expr->Identifier == 0);
2333
2334 /*
2335 * Try to figure out the type name
2336 * without going too much into details
2337 */
2338 expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type);
2339 if(expr->reference && expr->reference->comp_count > 0)
2340 expr->Identifier = expr->reference->components[0].name;
2341
2342 fprintf(stderr,
2343 "WARNING: Line %d: expected lower-case member identifier, "
2344 "found an unnamed %s.\n"
2345 "WARNING: Obsolete X.208 syntax detected, "
2346 "please give the member a name.\n",
2347 yylineno, expr->Identifier ? expr->Identifier : "type");
2348
2349 if(!expr->Identifier)
2350 expr->Identifier = "unnamed";
2351 expr->Identifier = strdup(expr->Identifier);
2352 assert(expr->Identifier);
2353 /* Make a lowercase identifier from the type name */
2354 for(p = expr->Identifier; *p; p++) {
2355 switch(*p) {
2356 case 'A' ... 'Z': *p += 32; break;
2357 case ' ': *p = '_'; break;
2358 case '-': *p = '_'; break;
2359 }
2360 }
2361 fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". "
2362 "Name clash may occur later.\n",
2363 expr->Identifier);
2364}
2365
Lev Walkinf15320b2004-06-03 03:38:44 +00002366int
2367yyerror(const char *msg) {
Lev Walkin9d542d22006-03-14 16:31:37 +00002368 extern char *asn1p_text;
Lev Walkinf15320b2004-06-03 03:38:44 +00002369 fprintf(stderr,
2370 "ASN.1 grammar parse error "
2371 "near line %d (token \"%s\"): %s\n",
Lev Walkinceb20e72004-09-05 10:40:41 +00002372 yylineno, asn1p_text, msg);
Lev Walkinf15320b2004-06-03 03:38:44 +00002373 return -1;
2374}
2375