blob: b252a7316dc26603bd5138ebae7d8196152f43ac [file] [log] [blame]
vlmfa67ddc2004-06-03 03:38:44 +00001%{
2
3#include <stdlib.h>
4#include <stdio.h>
5#include <string.h>
6#include <errno.h>
7#include <assert.h>
8
9#include "asn1parser.h"
10
11#define YYPARSE_PARAM param
vlmfbf6bf62005-06-07 21:25:42 +000012#define YYPARSE_PARAM_TYPE void **
vlmfa67ddc2004-06-03 03:38:44 +000013#define YYERROR_VERBOSE
14
15int yylex(void);
16int yyerror(const char *msg);
vlmd2f87602005-06-07 21:32:16 +000017#ifdef YYBYACC
18int yyparse(void **param); /* byacc does not produce a prototype */
19#endif
vlmfa67ddc2004-06-03 03:38:44 +000020void asn1p_lexer_hack_push_opaque_state(void);
21void asn1p_lexer_hack_enable_with_syntax(void);
vlm9283dbe2004-08-18 04:59:12 +000022void asn1p_lexer_hack_push_encoding_control(void);
vlmfa67ddc2004-06-03 03:38:44 +000023#define yylineno asn1p_lineno
24extern int asn1p_lineno;
25
vlm04a08da2005-08-12 10:06:17 +000026/*
vlm177a5b62005-09-05 05:17:57 +000027 * Process directives as <ASN1C:RepresentAsPointer>
vlm066dc102005-08-22 12:23:54 +000028 */
29extern int asn1p_as_pointer;
vlm066dc102005-08-22 12:23:54 +000030
31/*
vlm04a08da2005-08-12 10:06:17 +000032 * This temporary variable is used to solve the shortcomings of 1-lookahead
33 * parser.
34 */
35static struct AssignedIdentifier *saved_aid;
vlmfa67ddc2004-06-03 03:38:44 +000036
vlm5d89c3d2005-08-13 09:07:11 +000037static asn1p_value_t *_convert_bitstring2binary(char *str, int base);
38static void _fixup_anonymous_identifier(asn1p_expr_t *expr);
vlmfa67ddc2004-06-03 03:38:44 +000039
vlm04a08da2005-08-12 10:06:17 +000040#define checkmem(ptr) do { \
41 if(!(ptr)) \
42 return yyerror("Memory failure"); \
vlmfa67ddc2004-06-03 03:38:44 +000043 } while(0)
44
vlm9fe7c922005-08-12 10:08:45 +000045#define CONSTRAINT_INSERT(root, constr_type, arg1, arg2) do { \
vlm04a08da2005-08-12 10:06:17 +000046 if(arg1->type != constr_type) { \
47 int __ret; \
48 root = asn1p_constraint_new(yylineno); \
49 checkmem(root); \
50 root->type = constr_type; \
51 __ret = asn1p_constraint_insert(root, \
52 arg1); \
53 checkmem(__ret == 0); \
54 } else { \
55 root = arg1; \
56 } \
57 if(arg2) { \
58 int __ret \
59 = asn1p_constraint_insert(root, arg2); \
60 checkmem(__ret == 0); \
61 } \
vlmfa67ddc2004-06-03 03:38:44 +000062 } while(0)
63
vlmd3420d32006-09-14 10:35:20 +000064#ifdef AL_IMPORT
65#error AL_IMPORT DEFINED ELSEWHERE!
66#endif
67#define AL_IMPORT(to,where,from,field) do { \
68 if(!(from)) break; \
69 while(TQ_FIRST(&((from)->where))) { \
70 TQ_ADD(&((to)->where), \
71 TQ_REMOVE(&((from)->where), field), \
72 field); \
73 } \
74 assert(TQ_FIRST(&((from)->where)) == 0); \
75 } while(0)
76
vlmfa67ddc2004-06-03 03:38:44 +000077%}
78
79
80/*
81 * Token value definition.
82 * a_*: ASN-specific types.
83 * tv_*: Locally meaningful types.
84 */
85%union {
86 asn1p_t *a_grammar;
87 asn1p_module_flags_e a_module_flags;
88 asn1p_module_t *a_module;
89 asn1p_expr_type_e a_type; /* ASN.1 Type */
90 asn1p_expr_t *a_expr; /* Constructed collection */
91 asn1p_constraint_t *a_constr; /* Constraint */
92 enum asn1p_constraint_type_e a_ctype;/* Constraint type */
93 asn1p_xports_t *a_xports; /* IMports/EXports */
vlm04a08da2005-08-12 10:06:17 +000094 struct AssignedIdentifier a_aid; /* Assigned Identifier */
vlmfa67ddc2004-06-03 03:38:44 +000095 asn1p_oid_t *a_oid; /* Object Identifier */
96 asn1p_oid_arc_t a_oid_arc; /* Single OID's arc */
97 struct asn1p_type_tag_s a_tag; /* A tag */
98 asn1p_ref_t *a_ref; /* Reference to custom type */
99 asn1p_wsyntx_t *a_wsynt; /* WITH SYNTAX contents */
100 asn1p_wsyntx_chunk_t *a_wchunk; /* WITH SYNTAX chunk */
101 struct asn1p_ref_component_s a_refcomp; /* Component of a reference */
102 asn1p_value_t *a_value; /* Number, DefinedValue, etc */
103 struct asn1p_param_s a_parg; /* A parameter argument */
104 asn1p_paramlist_t *a_plist; /* A pargs list */
vlmc94e28f2004-09-15 11:59:51 +0000105 struct asn1p_expr_marker_s a_marker; /* OPTIONAL/DEFAULT */
vlmfa67ddc2004-06-03 03:38:44 +0000106 enum asn1p_constr_pres_e a_pres; /* PRESENT/ABSENT/OPTIONAL */
vlm0aa86902004-10-12 23:26:53 +0000107 asn1c_integer_t a_int;
vlme745fcd2006-09-05 16:18:34 +0000108 double a_dbl;
vlmfa67ddc2004-06-03 03:38:44 +0000109 char *tv_str;
110 struct {
111 char *buf;
112 int len;
113 } tv_opaque;
114 struct {
115 char *name;
116 struct asn1p_type_tag_s tag;
117 } tv_nametag;
118};
119
120/*
121 * Token types returned by scanner.
122 */
123%token TOK_PPEQ /* "::=", Pseudo Pascal EQuality */
vlmeeb3c512006-03-16 05:11:14 +0000124%token <tv_opaque> TOK_whitespace /* A span of whitespace */
vlmfa67ddc2004-06-03 03:38:44 +0000125%token <tv_opaque> TOK_opaque /* opaque data (driven from .y) */
126%token <tv_str> TOK_bstring
127%token <tv_opaque> TOK_cstring
128%token <tv_str> TOK_hstring
129%token <tv_str> TOK_identifier
130%token <a_int> TOK_number
vlme745fcd2006-09-05 16:18:34 +0000131%token <a_int> TOK_number_negative
132%token <a_dbl> TOK_realnumber
vlm2c8c44d2005-03-24 16:22:35 +0000133%token <a_int> TOK_tuple
134%token <a_int> TOK_quadruple
vlmfa67ddc2004-06-03 03:38:44 +0000135%token <tv_str> TOK_typereference
vlm9283dbe2004-08-18 04:59:12 +0000136%token <tv_str> TOK_capitalreference /* "CLASS1" */
vlmfa67ddc2004-06-03 03:38:44 +0000137%token <tv_str> TOK_typefieldreference /* "&Pork" */
138%token <tv_str> TOK_valuefieldreference /* "&id" */
vlm808411d2006-03-14 16:31:37 +0000139%token <tv_str> TOK_Literal /* "BY" */
vlmfa67ddc2004-06-03 03:38:44 +0000140
141/*
142 * Token types representing ASN.1 standard keywords.
143 */
144%token TOK_ABSENT
145%token TOK_ABSTRACT_SYNTAX
146%token TOK_ALL
147%token TOK_ANY
148%token TOK_APPLICATION
149%token TOK_AUTOMATIC
150%token TOK_BEGIN
151%token TOK_BIT
152%token TOK_BMPString
153%token TOK_BOOLEAN
154%token TOK_BY
155%token TOK_CHARACTER
156%token TOK_CHOICE
157%token TOK_CLASS
158%token TOK_COMPONENT
159%token TOK_COMPONENTS
160%token TOK_CONSTRAINED
161%token TOK_CONTAINING
162%token TOK_DEFAULT
163%token TOK_DEFINITIONS
164%token TOK_DEFINED
165%token TOK_EMBEDDED
166%token TOK_ENCODED
vlm9283dbe2004-08-18 04:59:12 +0000167%token TOK_ENCODING_CONTROL
vlmfa67ddc2004-06-03 03:38:44 +0000168%token TOK_END
169%token TOK_ENUMERATED
170%token TOK_EXPLICIT
171%token TOK_EXPORTS
172%token TOK_EXTENSIBILITY
173%token TOK_EXTERNAL
174%token TOK_FALSE
175%token TOK_FROM
176%token TOK_GeneralizedTime
177%token TOK_GeneralString
178%token TOK_GraphicString
179%token TOK_IA5String
180%token TOK_IDENTIFIER
181%token TOK_IMPLICIT
182%token TOK_IMPLIED
183%token TOK_IMPORTS
184%token TOK_INCLUDES
185%token TOK_INSTANCE
vlm9283dbe2004-08-18 04:59:12 +0000186%token TOK_INSTRUCTIONS
vlmfa67ddc2004-06-03 03:38:44 +0000187%token TOK_INTEGER
188%token TOK_ISO646String
189%token TOK_MAX
190%token TOK_MIN
191%token TOK_MINUS_INFINITY
192%token TOK_NULL
193%token TOK_NumericString
194%token TOK_OBJECT
195%token TOK_ObjectDescriptor
196%token TOK_OCTET
197%token TOK_OF
198%token TOK_OPTIONAL
199%token TOK_PATTERN
200%token TOK_PDV
201%token TOK_PLUS_INFINITY
202%token TOK_PRESENT
203%token TOK_PrintableString
204%token TOK_PRIVATE
205%token TOK_REAL
206%token TOK_RELATIVE_OID
207%token TOK_SEQUENCE
208%token TOK_SET
209%token TOK_SIZE
210%token TOK_STRING
211%token TOK_SYNTAX
212%token TOK_T61String
213%token TOK_TAGS
214%token TOK_TeletexString
215%token TOK_TRUE
216%token TOK_TYPE_IDENTIFIER
217%token TOK_UNIQUE
218%token TOK_UNIVERSAL
219%token TOK_UniversalString
220%token TOK_UTCTime
221%token TOK_UTF8String
222%token TOK_VideotexString
223%token TOK_VisibleString
224%token TOK_WITH
225
vlmfa67ddc2004-06-03 03:38:44 +0000226%left TOK_EXCEPT
vlm9283dbe2004-08-18 04:59:12 +0000227%left '^' TOK_INTERSECTION
228%left '|' TOK_UNION
vlmfa67ddc2004-06-03 03:38:44 +0000229
230/* Misc tags */
231%token TOK_TwoDots /* .. */
232%token TOK_ThreeDots /* ... */
vlmfa67ddc2004-06-03 03:38:44 +0000233
234
235/*
236 * Types defined herein.
237 */
238%type <a_grammar> ModuleList
vlmd3420d32006-09-14 10:35:20 +0000239%type <a_module> ModuleDefinition
240%type <a_module> ModuleBody
241%type <a_module> AssignmentList
242%type <a_module> Assignment
243%type <a_module> optModuleBody /* Optional */
244%type <a_module_flags> optModuleDefinitionFlags
245%type <a_module_flags> ModuleDefinitionFlags /* Set of FL */
246%type <a_module_flags> ModuleDefinitionFlag /* Single FL */
247%type <a_module> optImports
248%type <a_module> optExports
vlmfa67ddc2004-06-03 03:38:44 +0000249%type <a_module> ImportsDefinition
250%type <a_module> ImportsBundleSet
251%type <a_xports> ImportsBundle
252%type <a_xports> ImportsList
253%type <a_xports> ExportsDefinition
254%type <a_xports> ExportsBody
255%type <a_expr> ImportsElement
256%type <a_expr> ExportsElement
vlmfa67ddc2004-06-03 03:38:44 +0000257%type <a_expr> ExtensionAndException
vlmec8f6812004-08-22 03:19:54 +0000258%type <a_expr> TypeDeclaration
vlm066dc102005-08-22 12:23:54 +0000259%type <a_expr> TypeDeclarationSet
vlmfa67ddc2004-06-03 03:38:44 +0000260%type <a_ref> ComplexTypeReference
261%type <a_ref> ComplexTypeReferenceAmpList
262%type <a_refcomp> ComplexTypeReferenceElement
vlma6a84d72006-03-16 10:03:35 +0000263%type <a_refcomp> PrimitiveFieldReference
vlmdc7cf042006-03-09 08:49:26 +0000264%type <a_expr> FieldSpec
265%type <a_ref> FieldName
266%type <a_ref> DefinedObjectClass
vlmfa67ddc2004-06-03 03:38:44 +0000267%type <a_expr> ClassField
vlmdc7cf042006-03-09 08:49:26 +0000268%type <a_expr> ObjectClass
vlmec8f6812004-08-22 03:19:54 +0000269%type <a_expr> Type
vlmfa67ddc2004-06-03 03:38:44 +0000270%type <a_expr> DataTypeReference /* Type1 ::= Type2 */
vlm17e65d02006-03-21 04:48:15 +0000271%type <a_expr> DefinedType
vlm59b620a2006-03-21 07:46:48 +0000272%type <a_constr> ValueSet /* {a|b|c}*/
273%type <a_expr> ValueSetTypeAssignment /* Val INTEGER ::= {1|2} */
vlmfa67ddc2004-06-03 03:38:44 +0000274%type <a_expr> ValueDefinition /* val INTEGER ::= 1*/
vlmc94e28f2004-09-15 11:59:51 +0000275%type <a_value> Value
vlm17e65d02006-03-21 04:48:15 +0000276%type <a_value> SimpleValue
vlmfa67ddc2004-06-03 03:38:44 +0000277%type <a_value> DefinedValue
278%type <a_value> SignedNumber
vlme745fcd2006-09-05 16:18:34 +0000279%type <a_value> RealValue
vlm0aa86902004-10-12 23:26:53 +0000280%type <a_expr> optComponentTypeLists
vlmec8f6812004-08-22 03:19:54 +0000281%type <a_expr> ComponentTypeLists
282%type <a_expr> ComponentType
283%type <a_expr> AlternativeTypeLists
284%type <a_expr> AlternativeType
vlmfa67ddc2004-06-03 03:38:44 +0000285%type <a_expr> UniverationDefinition
286%type <a_expr> UniverationList
287%type <a_expr> UniverationElement
288%type <tv_str> TypeRefName
289%type <tv_str> ObjectClassReference
vlmfa67ddc2004-06-03 03:38:44 +0000290%type <tv_str> Identifier
vlm151c0b22004-09-22 16:03:36 +0000291%type <tv_str> optIdentifier
vlmfa67ddc2004-06-03 03:38:44 +0000292%type <a_parg> ParameterArgumentName
293%type <a_plist> ParameterArgumentList
vlmdfbff8c2006-03-21 09:41:28 +0000294%type <a_expr> ActualParameter
295%type <a_expr> ActualParameterList
vlm04a08da2005-08-12 10:06:17 +0000296%type <a_aid> AssignedIdentifier /* OID/DefinedValue */
vlmfa67ddc2004-06-03 03:38:44 +0000297%type <a_oid> ObjectIdentifier /* OID */
298%type <a_oid> optObjectIdentifier /* Optional OID */
299%type <a_oid> ObjectIdentifierBody
300%type <a_oid_arc> ObjectIdentifierElement
301%type <a_expr> BasicType
302%type <a_type> BasicTypeId
303%type <a_type> BasicTypeId_UniverationCompatible
304%type <a_type> BasicString
305%type <tv_opaque> Opaque
vlm2728a8d2005-01-23 09:51:44 +0000306%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
307%type <a_tag> TagClass TagTypeValue TagPlicit
vlmfa67ddc2004-06-03 03:38:44 +0000308%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
309%type <a_constr> optConstraints
vlm5f0128b2004-08-20 13:25:29 +0000310%type <a_constr> Constraints
vlm9283dbe2004-08-18 04:59:12 +0000311%type <a_constr> SetOfConstraints
312%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
313%type <a_constr> ElementSetSpec /* 1..2,...,3 */
vlmfa67ddc2004-06-03 03:38:44 +0000314%type <a_constr> ConstraintSubtypeElement /* 1..2 */
vlmfa67ddc2004-06-03 03:38:44 +0000315%type <a_constr> SimpleTableConstraint
316%type <a_constr> TableConstraint
vlm7bbdc9f2005-03-28 15:01:27 +0000317%type <a_constr> InnerTypeConstraint
vlmfa67ddc2004-06-03 03:38:44 +0000318%type <a_constr> WithComponentsList
319%type <a_constr> WithComponentsElement
320%type <a_constr> ComponentRelationConstraint
321%type <a_constr> AtNotationList
322%type <a_ref> AtNotationElement
vlma6a12e32005-03-20 12:58:00 +0000323%type <a_value> SingleValue
324%type <a_value> ContainedSubtype
vlmfa67ddc2004-06-03 03:38:44 +0000325%type <a_ctype> ConstraintSpec
326%type <a_ctype> ConstraintRangeSpec
vlme1e6ed82005-03-24 14:26:38 +0000327%type <a_value> RestrictedCharacterStringValue
vlmfa67ddc2004-06-03 03:38:44 +0000328%type <a_wsynt> optWithSyntax
329%type <a_wsynt> WithSyntax
vlm808411d2006-03-14 16:31:37 +0000330%type <a_wsynt> WithSyntaxList
331%type <a_wchunk> WithSyntaxToken
vlmfa67ddc2004-06-03 03:38:44 +0000332%type <a_marker> optMarker Marker
333%type <a_int> optUnique
334%type <a_pres> optPresenceConstraint PresenceConstraint
335%type <tv_str> ComponentIdList
vlm177a5b62005-09-05 05:17:57 +0000336%type <a_int> NSTD_IndirectMarker
vlmfa67ddc2004-06-03 03:38:44 +0000337
338
339%%
340
341
342ParsedGrammar:
343 ModuleList {
344 *(void **)param = $1;
345 }
346 ;
347
348ModuleList:
vlmd3420d32006-09-14 10:35:20 +0000349 ModuleDefinition {
vlmfa67ddc2004-06-03 03:38:44 +0000350 $$ = asn1p_new();
351 checkmem($$);
352 TQ_ADD(&($$->modules), $1, mod_next);
353 }
vlmd3420d32006-09-14 10:35:20 +0000354 | ModuleList ModuleDefinition {
vlmfa67ddc2004-06-03 03:38:44 +0000355 $$ = $1;
356 TQ_ADD(&($$->modules), $2, mod_next);
357 }
358 ;
359
360/*
361 * ASN module definition.
362 * === EXAMPLE ===
363 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
364 * BEGIN
365 * ...
366 * END
367 * === EOF ===
368 */
369
vlmd3420d32006-09-14 10:35:20 +0000370ModuleDefinition:
vlmfa67ddc2004-06-03 03:38:44 +0000371 TypeRefName optObjectIdentifier TOK_DEFINITIONS
vlmd3420d32006-09-14 10:35:20 +0000372 optModuleDefinitionFlags
vlmfa67ddc2004-06-03 03:38:44 +0000373 TOK_PPEQ TOK_BEGIN
vlmd3420d32006-09-14 10:35:20 +0000374 optModuleBody
vlmfa67ddc2004-06-03 03:38:44 +0000375 TOK_END {
376
377 if($7) {
378 $$ = $7;
379 } else {
380 /* There's a chance that a module is just plain empty */
381 $$ = asn1p_module_new();
382 }
383 checkmem($$);
384
vlm04a08da2005-08-12 10:06:17 +0000385 $$->ModuleName = $1;
vlmfa67ddc2004-06-03 03:38:44 +0000386 $$->module_oid = $2;
387 $$->module_flags = $4;
388 }
389 ;
390
391/*
392 * Object Identifier Definition
393 * { iso member-body(2) 3 }
394 */
395optObjectIdentifier:
396 { $$ = 0; }
397 | ObjectIdentifier { $$ = $1; }
398 ;
399
400ObjectIdentifier:
401 '{' ObjectIdentifierBody '}' {
402 $$ = $2;
403 }
404 | '{' '}' {
405 $$ = 0;
406 }
407 ;
408
409ObjectIdentifierBody:
410 ObjectIdentifierElement {
411 $$ = asn1p_oid_new();
412 asn1p_oid_add_arc($$, &$1);
413 if($1.name)
414 free($1.name);
415 }
416 | ObjectIdentifierBody ObjectIdentifierElement {
417 $$ = $1;
418 asn1p_oid_add_arc($$, &$2);
419 if($2.name)
420 free($2.name);
421 }
422 ;
423
424ObjectIdentifierElement:
425 Identifier { /* iso */
426 $$.name = $1;
427 $$.number = -1;
428 }
429 | Identifier '(' TOK_number ')' { /* iso(1) */
430 $$.name = $1;
431 $$.number = $3;
432 }
433 | TOK_number { /* 1 */
434 $$.name = 0;
435 $$.number = $1;
436 }
437 ;
438
439/*
440 * Optional module flags.
441 */
vlmd3420d32006-09-14 10:35:20 +0000442optModuleDefinitionFlags:
vlmfa67ddc2004-06-03 03:38:44 +0000443 { $$ = MSF_NOFLAGS; }
vlmd3420d32006-09-14 10:35:20 +0000444 | ModuleDefinitionFlags {
vlmfa67ddc2004-06-03 03:38:44 +0000445 $$ = $1;
446 }
447 ;
448
449/*
450 * Module flags.
451 */
vlmd3420d32006-09-14 10:35:20 +0000452ModuleDefinitionFlags:
453 ModuleDefinitionFlag {
vlmfa67ddc2004-06-03 03:38:44 +0000454 $$ = $1;
455 }
vlmd3420d32006-09-14 10:35:20 +0000456 | ModuleDefinitionFlags ModuleDefinitionFlag {
vlmfa67ddc2004-06-03 03:38:44 +0000457 $$ = $1 | $2;
458 }
459 ;
460
461/*
462 * Single module flag.
463 */
vlmd3420d32006-09-14 10:35:20 +0000464ModuleDefinitionFlag:
vlmfa67ddc2004-06-03 03:38:44 +0000465 TOK_EXPLICIT TOK_TAGS {
466 $$ = MSF_EXPLICIT_TAGS;
467 }
468 | TOK_IMPLICIT TOK_TAGS {
469 $$ = MSF_IMPLICIT_TAGS;
470 }
471 | TOK_AUTOMATIC TOK_TAGS {
472 $$ = MSF_AUTOMATIC_TAGS;
473 }
474 | TOK_EXTENSIBILITY TOK_IMPLIED {
475 $$ = MSF_EXTENSIBILITY_IMPLIED;
476 }
vlm9283dbe2004-08-18 04:59:12 +0000477 /* EncodingReferenceDefault */
478 | TOK_capitalreference TOK_INSTRUCTIONS {
479 /* X.680Amd1 specifies TAG and XER */
480 if(strcmp($1, "TAG") == 0) {
481 $$ = MSF_TAG_INSTRUCTIONS;
482 } else if(strcmp($1, "XER") == 0) {
483 $$ = MSF_XER_INSTRUCTIONS;
484 } else {
485 fprintf(stderr,
486 "WARNING: %s INSTRUCTIONS at line %d: "
487 "Unrecognized encoding reference\n",
488 $1, yylineno);
489 $$ = MSF_unk_INSTRUCTIONS;
490 }
491 free($1);
492 }
vlmfa67ddc2004-06-03 03:38:44 +0000493 ;
494
495/*
496 * Optional module body.
497 */
vlmd3420d32006-09-14 10:35:20 +0000498optModuleBody:
vlmfa67ddc2004-06-03 03:38:44 +0000499 { $$ = 0; }
vlmd3420d32006-09-14 10:35:20 +0000500 | ModuleBody {
vlmfa67ddc2004-06-03 03:38:44 +0000501 $$ = $1;
502 }
503 ;
504
505/*
506 * ASN.1 Module body.
507 */
vlmd3420d32006-09-14 10:35:20 +0000508ModuleBody:
509 optExports optImports AssignmentList {
510 $$ = asn1p_module_new();
511 AL_IMPORT($$, exports, $1, xp_next);
512 AL_IMPORT($$, imports, $2, xp_next);
513 AL_IMPORT($$, members, $3, next);
vlmfa67ddc2004-06-03 03:38:44 +0000514 }
515 ;
516
vlmd3420d32006-09-14 10:35:20 +0000517AssignmentList:
518 Assignment {
519 $$ = $1;
520 }
521 | AssignmentList Assignment {
522 if($1) {
523 $$ = $1;
524 } else {
525 $$ = $2;
526 break;
527 }
528 AL_IMPORT($$, members, $2, next);
529 }
530 ;
531
532
vlmfa67ddc2004-06-03 03:38:44 +0000533/*
534 * One of the elements of ASN.1 module specification.
535 */
vlmd3420d32006-09-14 10:35:20 +0000536Assignment:
537 DataTypeReference {
vlmfa67ddc2004-06-03 03:38:44 +0000538 $$ = asn1p_module_new();
539 checkmem($$);
540 assert($1->expr_type != A1TC_INVALID);
541 assert($1->meta_type != AMT_INVALID);
542 TQ_ADD(&($$->members), $1, next);
543 }
544 | ValueDefinition {
545 $$ = asn1p_module_new();
546 checkmem($$);
547 assert($1->expr_type != A1TC_INVALID);
548 assert($1->meta_type != AMT_INVALID);
549 TQ_ADD(&($$->members), $1, next);
550 }
551 /*
552 * Value set definition
553 * === EXAMPLE ===
554 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
555 * === EOF ===
556 */
vlm59b620a2006-03-21 07:46:48 +0000557 | ValueSetTypeAssignment {
vlmfa67ddc2004-06-03 03:38:44 +0000558 $$ = asn1p_module_new();
559 checkmem($$);
560 assert($1->expr_type != A1TC_INVALID);
561 assert($1->meta_type != AMT_INVALID);
562 TQ_ADD(&($$->members), $1, next);
563 }
vlm9283dbe2004-08-18 04:59:12 +0000564 | TOK_ENCODING_CONTROL TOK_capitalreference
565 { asn1p_lexer_hack_push_encoding_control(); }
566 {
567 fprintf(stderr,
568 "WARNING: ENCODING-CONTROL %s "
569 "specification at line %d ignored\n",
570 $2, yylineno);
571 free($2);
572 $$ = 0;
573 }
vlmfa67ddc2004-06-03 03:38:44 +0000574
575 /*
576 * Erroneous attemps
577 */
578 | BasicString {
579 return yyerror(
vlm1ac75e72005-11-26 11:21:55 +0000580 "Attempt to redefine a standard basic string type, "
581 "please comment out or remove this type redefinition.");
vlmfa67ddc2004-06-03 03:38:44 +0000582 }
583 ;
584
585/*
586 * === EXAMPLE ===
587 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
588 * === EOF ===
589 */
vlmd3420d32006-09-14 10:35:20 +0000590optImports:
591 { $$ = 0; }
592 | ImportsDefinition;
593
vlmfa67ddc2004-06-03 03:38:44 +0000594ImportsDefinition:
595 TOK_IMPORTS ImportsBundleSet ';' {
vlm04a08da2005-08-12 10:06:17 +0000596 if(!saved_aid && 0)
597 return yyerror("Unterminated IMPORTS FROM, "
598 "expected semicolon ';'");
599 saved_aid = 0;
vlmfa67ddc2004-06-03 03:38:44 +0000600 $$ = $2;
601 }
602 /*
603 * Some error cases.
604 */
605 | TOK_IMPORTS TOK_FROM /* ... */ {
606 return yyerror("Empty IMPORTS list");
607 }
608 ;
609
610ImportsBundleSet:
611 ImportsBundle {
612 $$ = asn1p_module_new();
613 checkmem($$);
614 TQ_ADD(&($$->imports), $1, xp_next);
615 }
616 | ImportsBundleSet ImportsBundle {
617 $$ = $1;
618 TQ_ADD(&($$->imports), $2, xp_next);
619 }
620 ;
621
vlm04a08da2005-08-12 10:06:17 +0000622AssignedIdentifier:
623 { memset(&$$, 0, sizeof($$)); }
624 | ObjectIdentifier { $$.oid = $1; };
625 /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
626
vlmfa67ddc2004-06-03 03:38:44 +0000627ImportsBundle:
vlm04a08da2005-08-12 10:06:17 +0000628 ImportsList TOK_FROM TypeRefName AssignedIdentifier {
vlmfa67ddc2004-06-03 03:38:44 +0000629 $$ = $1;
vlm04a08da2005-08-12 10:06:17 +0000630 $$->fromModuleName = $3;
631 $$->identifier = $4;
632 /* This stupid thing is used for look-back hack. */
633 saved_aid = $$->identifier.oid ? 0 : &($$->identifier);
vlmfa67ddc2004-06-03 03:38:44 +0000634 checkmem($$);
635 }
636 ;
637
638ImportsList:
639 ImportsElement {
640 $$ = asn1p_xports_new();
641 checkmem($$);
642 TQ_ADD(&($$->members), $1, next);
643 }
644 | ImportsList ',' ImportsElement {
645 $$ = $1;
646 TQ_ADD(&($$->members), $3, next);
647 }
648 ;
649
650ImportsElement:
651 TypeRefName {
652 $$ = asn1p_expr_new(yylineno);
653 checkmem($$);
654 $$->Identifier = $1;
655 $$->expr_type = A1TC_REFERENCE;
656 }
vlm0aa86902004-10-12 23:26:53 +0000657 | TypeRefName '{' '}' { /* Completely equivalent to above */
658 $$ = asn1p_expr_new(yylineno);
659 checkmem($$);
660 $$->Identifier = $1;
661 $$->expr_type = A1TC_REFERENCE;
662 }
vlmfa67ddc2004-06-03 03:38:44 +0000663 | Identifier {
664 $$ = asn1p_expr_new(yylineno);
665 checkmem($$);
666 $$->Identifier = $1;
667 $$->expr_type = A1TC_REFERENCE;
668 }
669 ;
670
vlmd3420d32006-09-14 10:35:20 +0000671
672optExports:
673 { $$ = 0; }
674 | ExportsDefinition {
675 $$ = asn1p_module_new();
676 checkmem($$);
677 if($1) {
678 TQ_ADD(&($$->exports), $1, xp_next);
679 } else {
680 /* "EXPORTS ALL;" */
681 }
682 }
683 ;
684
vlmfa67ddc2004-06-03 03:38:44 +0000685ExportsDefinition:
686 TOK_EXPORTS ExportsBody ';' {
687 $$ = $2;
688 }
689 | TOK_EXPORTS TOK_ALL ';' {
690 $$ = 0;
691 }
692 | TOK_EXPORTS ';' {
693 /* Empty EXPORTS clause effectively prohibits export. */
694 $$ = asn1p_xports_new();
695 checkmem($$);
696 }
697 ;
698
699ExportsBody:
700 ExportsElement {
701 $$ = asn1p_xports_new();
702 assert($$);
703 TQ_ADD(&($$->members), $1, next);
704 }
705 | ExportsBody ',' ExportsElement {
706 $$ = $1;
707 TQ_ADD(&($$->members), $3, next);
708 }
709 ;
710
711ExportsElement:
712 TypeRefName {
713 $$ = asn1p_expr_new(yylineno);
714 checkmem($$);
715 $$->Identifier = $1;
716 $$->expr_type = A1TC_EXPORTVAR;
717 }
vlm0aa86902004-10-12 23:26:53 +0000718 | TypeRefName '{' '}' {
719 $$ = asn1p_expr_new(yylineno);
720 checkmem($$);
721 $$->Identifier = $1;
722 $$->expr_type = A1TC_EXPORTVAR;
723 }
vlmfa67ddc2004-06-03 03:38:44 +0000724 | Identifier {
725 $$ = asn1p_expr_new(yylineno);
726 checkmem($$);
727 $$->Identifier = $1;
728 $$->expr_type = A1TC_EXPORTVAR;
729 }
730 ;
731
732
vlm1aeaddd2006-07-13 08:24:20 +0000733ValueSet: '{' ElementSetSpecs '}' { $$ = $2; };
vlm59b620a2006-03-21 07:46:48 +0000734
735ValueSetTypeAssignment:
736 TypeRefName DefinedType TOK_PPEQ ValueSet {
vlmfa67ddc2004-06-03 03:38:44 +0000737 $$ = $2;
738 assert($$->Identifier == 0);
739 $$->Identifier = $1;
740 $$->meta_type = AMT_VALUESET;
vlm59b620a2006-03-21 07:46:48 +0000741 $$->constraints = $4;
vlmfa67ddc2004-06-03 03:38:44 +0000742 }
743 ;
744
vlm17e65d02006-03-21 04:48:15 +0000745DefinedType:
746 BasicType {
747 $$ = $1;
748 }
749 /*
750 * A DefinedType reference.
751 * "CLASS1.&id.&id2"
752 * or
753 * "Module.Type"
754 * or
755 * "Module.identifier"
756 * or
757 * "Type"
758 */
759 | ComplexTypeReference {
vlmfa67ddc2004-06-03 03:38:44 +0000760 $$ = asn1p_expr_new(yylineno);
761 checkmem($$);
762 $$->reference = $1;
763 $$->expr_type = A1TC_REFERENCE;
764 $$->meta_type = AMT_TYPEREF;
765 }
vlm17e65d02006-03-21 04:48:15 +0000766 /*
vlmdfbff8c2006-03-21 09:41:28 +0000767 * A parameterized assignment.
vlm17e65d02006-03-21 04:48:15 +0000768 */
vlmdfbff8c2006-03-21 09:41:28 +0000769 | ComplexTypeReference '{' ActualParameterList '}' {
vlmfa67ddc2004-06-03 03:38:44 +0000770 $$ = asn1p_expr_new(yylineno);
771 checkmem($$);
vlm17e65d02006-03-21 04:48:15 +0000772 $$->reference = $1;
773 $$->rhs_pspecs = $3;
774 $$->expr_type = A1TC_REFERENCE;
775 $$->meta_type = AMT_TYPEREF;
vlmfa67ddc2004-06-03 03:38:44 +0000776 }
777 ;
778
vlmfa67ddc2004-06-03 03:38:44 +0000779/*
780 * Data Type Reference.
781 * === EXAMPLE ===
782 * Type3 ::= CHOICE { a Type1, b Type 2 }
783 * === EOF ===
784 */
vlmfa67ddc2004-06-03 03:38:44 +0000785DataTypeReference:
786 /*
787 * Optionally tagged type definition.
788 */
vlmdc7cf042006-03-09 08:49:26 +0000789 TypeRefName TOK_PPEQ Type {
vlmfce48a42004-09-14 02:36:39 +0000790 $$ = $3;
vlmfa67ddc2004-06-03 03:38:44 +0000791 $$->Identifier = $1;
vlmfa67ddc2004-06-03 03:38:44 +0000792 assert($$->expr_type);
793 assert($$->meta_type);
794 }
vlmdc7cf042006-03-09 08:49:26 +0000795 | TypeRefName TOK_PPEQ ObjectClass {
vlmfa67ddc2004-06-03 03:38:44 +0000796 $$ = $3;
797 $$->Identifier = $1;
798 assert($$->expr_type == A1TC_CLASSDEF);
vlmdc7cf042006-03-09 08:49:26 +0000799 assert($$->meta_type == AMT_OBJECTCLASS);
vlmfa67ddc2004-06-03 03:38:44 +0000800 }
801 /*
vlmdfbff8c2006-03-21 09:41:28 +0000802 * Parameterized <Type> declaration:
vlmfa67ddc2004-06-03 03:38:44 +0000803 * === EXAMPLE ===
804 * SIGNED { ToBeSigned } ::= SEQUENCE {
805 * toBeSigned ToBeSigned,
806 * algorithm AlgorithmIdentifier,
807 * signature BIT STRING
808 * }
809 * === EOF ===
810 */
vlmec8f6812004-08-22 03:19:54 +0000811 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
vlmfa67ddc2004-06-03 03:38:44 +0000812 $$ = $6;
vlmdfbff8c2006-03-21 09:41:28 +0000813 $$->Identifier = $1;
814 $$->lhs_params = $3;
815 }
816 /* Parameterized CLASS declaration */
817 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ ObjectClass {
818 $$ = $6;
vlmfa67ddc2004-06-03 03:38:44 +0000819 $$->Identifier = $1;
vlm0c6d3812006-03-21 03:40:38 +0000820 $$->lhs_params = $3;
vlmfa67ddc2004-06-03 03:38:44 +0000821 }
822 ;
823
824ParameterArgumentList:
825 ParameterArgumentName {
826 int ret;
827 $$ = asn1p_paramlist_new(yylineno);
828 checkmem($$);
829 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
830 checkmem(ret == 0);
831 if($1.governor) asn1p_ref_free($1.governor);
832 if($1.argument) free($1.argument);
833 }
834 | ParameterArgumentList ',' ParameterArgumentName {
835 int ret;
836 $$ = $1;
837 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
838 checkmem(ret == 0);
839 if($3.governor) asn1p_ref_free($3.governor);
840 if($3.argument) free($3.argument);
841 }
842 ;
843
844ParameterArgumentName:
845 TypeRefName {
846 $$.governor = NULL;
847 $$.argument = $1;
848 }
849 | TypeRefName ':' Identifier {
850 int ret;
851 $$.governor = asn1p_ref_new(yylineno);
852 ret = asn1p_ref_add_component($$.governor, $1, 0);
853 checkmem(ret == 0);
854 $$.argument = $3;
855 }
vlm4053ca52005-02-18 16:34:21 +0000856 | TypeRefName ':' TypeRefName {
857 int ret;
858 $$.governor = asn1p_ref_new(yylineno);
859 ret = asn1p_ref_add_component($$.governor, $1, 0);
860 checkmem(ret == 0);
861 $$.argument = $3;
862 }
vlmfa67ddc2004-06-03 03:38:44 +0000863 | BasicTypeId ':' Identifier {
864 int ret;
865 $$.governor = asn1p_ref_new(yylineno);
866 ret = asn1p_ref_add_component($$.governor,
867 ASN_EXPR_TYPE2STR($1), 1);
868 checkmem(ret == 0);
869 $$.argument = $3;
870 }
vlmdfbff8c2006-03-21 09:41:28 +0000871 | BasicTypeId ':' TypeRefName {
872 int ret;
873 $$.governor = asn1p_ref_new(yylineno);
874 ret = asn1p_ref_add_component($$.governor,
875 ASN_EXPR_TYPE2STR($1), 1);
876 checkmem(ret == 0);
877 $$.argument = $3;
878 }
vlmfa67ddc2004-06-03 03:38:44 +0000879 ;
880
vlmdfbff8c2006-03-21 09:41:28 +0000881ActualParameterList:
882 ActualParameter {
vlmfa67ddc2004-06-03 03:38:44 +0000883 $$ = asn1p_expr_new(yylineno);
884 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000885 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000886 }
vlmdfbff8c2006-03-21 09:41:28 +0000887 | ActualParameterList ',' ActualParameter {
vlmfa67ddc2004-06-03 03:38:44 +0000888 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000889 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000890 }
891 ;
892
vlmdfbff8c2006-03-21 09:41:28 +0000893ActualParameter:
vlmec8f6812004-08-22 03:19:54 +0000894 Type {
vlmfa67ddc2004-06-03 03:38:44 +0000895 $$ = $1;
896 }
vlm17e65d02006-03-21 04:48:15 +0000897 | SimpleValue {
898 $$ = asn1p_expr_new(yylineno);
899 checkmem($$);
900 $$->Identifier = "?";
901 $$->expr_type = A1TC_REFERENCE;
902 $$->meta_type = AMT_VALUE;
903 $$->value = $1;
904 }
vlmfa67ddc2004-06-03 03:38:44 +0000905 | Identifier {
vlm0c6d3812006-03-21 03:40:38 +0000906 asn1p_ref_t *ref;
vlmfa67ddc2004-06-03 03:38:44 +0000907 $$ = asn1p_expr_new(yylineno);
908 checkmem($$);
909 $$->Identifier = $1;
910 $$->expr_type = A1TC_REFERENCE;
911 $$->meta_type = AMT_VALUE;
vlm0c6d3812006-03-21 03:40:38 +0000912 ref = asn1p_ref_new(yylineno);
913 asn1p_ref_add_component(ref, $1, RLT_lowercase);
914 $$->value = asn1p_value_fromref(ref, 0);
vlmfa67ddc2004-06-03 03:38:44 +0000915 }
vlmdfbff8c2006-03-21 09:41:28 +0000916 | ValueSet {
917 $$ = asn1p_expr_new(yylineno);
918 $$->expr_type = A1TC_VALUESET;
919 $$->meta_type = AMT_VALUESET;
920 $$->constraints = $1;
921 }
vlmfa67ddc2004-06-03 03:38:44 +0000922 ;
923
924/*
vlmdfbff8c2006-03-21 09:41:28 +0000925 | '{' ActualParameter '}' {
vlm4053ca52005-02-18 16:34:21 +0000926 $$ = asn1p_expr_new(yylineno);
927 checkmem($$);
928 asn1p_expr_add($$, $2);
929 $$->expr_type = A1TC_PARAMETRIZED;
930 $$->meta_type = AMT_TYPE;
931 }
932 ;
933*/
934
935/*
vlmfa67ddc2004-06-03 03:38:44 +0000936 * A collection of constructed data type members.
937 */
vlm0aa86902004-10-12 23:26:53 +0000938optComponentTypeLists:
939 { $$ = asn1p_expr_new(yylineno); }
940 | ComponentTypeLists { $$ = $1; };
941
vlmec8f6812004-08-22 03:19:54 +0000942ComponentTypeLists:
943 ComponentType {
vlmfa67ddc2004-06-03 03:38:44 +0000944 $$ = asn1p_expr_new(yylineno);
945 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000946 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000947 }
vlmec8f6812004-08-22 03:19:54 +0000948 | ComponentTypeLists ',' ComponentType {
vlmfa67ddc2004-06-03 03:38:44 +0000949 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000950 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000951 }
952 ;
953
vlmec8f6812004-08-22 03:19:54 +0000954ComponentType:
vlmfce48a42004-09-14 02:36:39 +0000955 Identifier Type optMarker {
vlmec8f6812004-08-22 03:19:54 +0000956 $$ = $2;
957 assert($$->Identifier == 0);
vlmfce48a42004-09-14 02:36:39 +0000958 $$->Identifier = $1;
vlm177a5b62005-09-05 05:17:57 +0000959 $3.flags |= $$->marker.flags;
vlmec8f6812004-08-22 03:19:54 +0000960 $$->marker = $3;
961 }
vlm177a5b62005-09-05 05:17:57 +0000962 | Type optMarker {
963 $$ = $1;
964 $2.flags |= $$->marker.flags;
965 $$->marker = $2;
966 _fixup_anonymous_identifier($$);
967 }
vlmec8f6812004-08-22 03:19:54 +0000968 | TOK_COMPONENTS TOK_OF Type {
969 $$ = asn1p_expr_new(yylineno);
970 checkmem($$);
971 $$->meta_type = $3->meta_type;
972 $$->expr_type = A1TC_COMPONENTS_OF;
vlm6a02a8a2004-09-08 00:28:11 +0000973 asn1p_expr_add($$, $3);
vlmec8f6812004-08-22 03:19:54 +0000974 }
975 | ExtensionAndException {
976 $$ = $1;
977 }
978 ;
979
980AlternativeTypeLists:
981 AlternativeType {
982 $$ = asn1p_expr_new(yylineno);
983 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000984 asn1p_expr_add($$, $1);
vlmec8f6812004-08-22 03:19:54 +0000985 }
986 | AlternativeTypeLists ',' AlternativeType {
987 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000988 asn1p_expr_add($$, $3);
vlmec8f6812004-08-22 03:19:54 +0000989 }
990 ;
991
992AlternativeType:
vlmfce48a42004-09-14 02:36:39 +0000993 Identifier Type {
vlmec8f6812004-08-22 03:19:54 +0000994 $$ = $2;
995 assert($$->Identifier == 0);
vlmfce48a42004-09-14 02:36:39 +0000996 $$->Identifier = $1;
vlmec8f6812004-08-22 03:19:54 +0000997 }
998 | ExtensionAndException {
999 $$ = $1;
1000 }
vlm5d89c3d2005-08-13 09:07:11 +00001001 | Type {
1002 $$ = $1;
1003 _fixup_anonymous_identifier($$);
1004 }
vlmec8f6812004-08-22 03:19:54 +00001005 ;
1006
vlmdc7cf042006-03-09 08:49:26 +00001007ObjectClass:
1008 TOK_CLASS '{' FieldSpec '}' optWithSyntax {
vlmfa67ddc2004-06-03 03:38:44 +00001009 $$ = $3;
1010 checkmem($$);
1011 $$->with_syntax = $5;
1012 assert($$->expr_type == A1TC_CLASSDEF);
vlmdc7cf042006-03-09 08:49:26 +00001013 assert($$->meta_type == AMT_OBJECTCLASS);
vlmfa67ddc2004-06-03 03:38:44 +00001014 }
1015 ;
1016
1017optUnique:
1018 { $$ = 0; }
1019 | TOK_UNIQUE { $$ = 1; }
1020 ;
1021
vlmdc7cf042006-03-09 08:49:26 +00001022FieldSpec:
vlmfa67ddc2004-06-03 03:38:44 +00001023 ClassField {
1024 $$ = asn1p_expr_new(yylineno);
1025 checkmem($$);
1026 $$->expr_type = A1TC_CLASSDEF;
vlmdc7cf042006-03-09 08:49:26 +00001027 $$->meta_type = AMT_OBJECTCLASS;
vlm6a02a8a2004-09-08 00:28:11 +00001028 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +00001029 }
vlmdc7cf042006-03-09 08:49:26 +00001030 | FieldSpec ',' ClassField {
vlmfa67ddc2004-06-03 03:38:44 +00001031 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +00001032 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001033 }
1034 ;
1035
vlmdc7cf042006-03-09 08:49:26 +00001036 /* X.681 */
vlmfa67ddc2004-06-03 03:38:44 +00001037ClassField:
vlmdc7cf042006-03-09 08:49:26 +00001038
1039 /* TypeFieldSpec ::= typefieldreference TypeOptionalitySpec? */
1040 TOK_typefieldreference optMarker {
vlmfa67ddc2004-06-03 03:38:44 +00001041 $$ = asn1p_expr_new(yylineno);
1042 checkmem($$);
vlmdc7cf042006-03-09 08:49:26 +00001043 $$->Identifier = $1;
vlmfa67ddc2004-06-03 03:38:44 +00001044 $$->meta_type = AMT_OBJECTFIELD;
vlmdc7cf042006-03-09 08:49:26 +00001045 $$->expr_type = A1TC_CLASSFIELD_TFS; /* TypeFieldSpec */
vlmfa67ddc2004-06-03 03:38:44 +00001046 $$->marker = $2;
1047 }
vlmdc7cf042006-03-09 08:49:26 +00001048
1049 /* FixedTypeValueFieldSpec ::= valuefieldreference Type UNIQUE ? ValueOptionalitySpec ? */
1050 | TOK_valuefieldreference Type optUnique optMarker {
1051 $$ = asn1p_expr_new(yylineno);
1052 $$->Identifier = $1;
1053 $$->meta_type = AMT_OBJECTFIELD;
1054 $$->expr_type = A1TC_CLASSFIELD_FTVFS; /* FixedTypeValueFieldSpec */
vlmbde35d42004-11-24 17:43:29 +00001055 $$->unique = $3;
vlmdc7cf042006-03-09 08:49:26 +00001056 $$->marker = $4;
1057 asn1p_expr_add($$, $2);
vlmfa67ddc2004-06-03 03:38:44 +00001058 }
vlmdc7cf042006-03-09 08:49:26 +00001059
1060 /* VariableTypeValueFieldSpec ::= valuefieldreference FieldName ValueOptionalitySpec ? */
1061 | TOK_valuefieldreference FieldName optMarker {
1062 $$ = asn1p_expr_new(yylineno);
1063 $$->Identifier = $1;
1064 $$->meta_type = AMT_OBJECTFIELD;
1065 $$->expr_type = A1TC_CLASSFIELD_VTVFS;
1066 $$->reference = $2;
1067 $$->marker = $3;
1068 }
1069
vlmdc7cf042006-03-09 08:49:26 +00001070 /* ObjectFieldSpec ::= objectfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1071 | TOK_valuefieldreference DefinedObjectClass optMarker {
vlmfa67ddc2004-06-03 03:38:44 +00001072 $$ = asn1p_expr_new(yylineno);
1073 checkmem($$);
vlmdc7cf042006-03-09 08:49:26 +00001074 $$->Identifier = $1;
1075 $$->reference = $2;
vlmfa67ddc2004-06-03 03:38:44 +00001076 $$->meta_type = AMT_OBJECTFIELD;
vlmdc7cf042006-03-09 08:49:26 +00001077 $$->expr_type = A1TC_CLASSFIELD_OFS;
1078 $$->marker = $3;
vlmfa67ddc2004-06-03 03:38:44 +00001079 }
vlmdc7cf042006-03-09 08:49:26 +00001080
vlmee7196e2006-03-09 09:08:49 +00001081 /* VariableTypeValueSetFieldSpec ::= valuesetfieldreference FieldName ValueOptionalitySpec ? */
1082 | TOK_typefieldreference FieldName optMarker {
vlmdc7cf042006-03-09 08:49:26 +00001083 $$ = asn1p_expr_new(yylineno);
vlmdc7cf042006-03-09 08:49:26 +00001084 $$->Identifier = $1;
vlmdc7cf042006-03-09 08:49:26 +00001085 $$->meta_type = AMT_OBJECTFIELD;
vlmee7196e2006-03-09 09:08:49 +00001086 $$->expr_type = A1TC_CLASSFIELD_VTVSFS;
1087 $$->reference = $2;
vlmdc7cf042006-03-09 08:49:26 +00001088 $$->marker = $3;
1089 }
1090
1091 /* FixedTypeValueSetFieldSpec ::= valuesetfieldreference Type ValueSetOptionalitySpec ? */
1092 | TOK_typefieldreference Type optMarker {
1093 $$ = asn1p_expr_new(yylineno);
1094 checkmem($$);
1095 $$->Identifier = $1;
1096 $$->meta_type = AMT_OBJECTFIELD;
1097 $$->expr_type = A1TC_CLASSFIELD_FTVSFS;
1098 asn1p_expr_add($$, $2);
1099 $$->marker = $3;
1100 }
1101
vlmee7196e2006-03-09 09:08:49 +00001102 /* ObjectSetFieldSpec ::= objectsetfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1103 | TOK_typefieldreference DefinedObjectClass optMarker {
1104 $$ = asn1p_expr_new(yylineno);
1105 checkmem($$);
1106 $$->Identifier = $1;
1107 $$->reference = $2;
1108 $$->meta_type = AMT_OBJECTFIELD;
1109 $$->expr_type = A1TC_CLASSFIELD_OSFS;
1110 $$->marker = $3;
1111 }
vlmfa67ddc2004-06-03 03:38:44 +00001112 ;
1113
1114optWithSyntax:
1115 { $$ = 0; }
1116 | WithSyntax {
1117 $$ = $1;
1118 }
1119 ;
1120
1121WithSyntax:
1122 TOK_WITH TOK_SYNTAX '{'
1123 { asn1p_lexer_hack_enable_with_syntax(); }
vlm808411d2006-03-14 16:31:37 +00001124 WithSyntaxList
vlmfa67ddc2004-06-03 03:38:44 +00001125 '}' {
1126 $$ = $5;
1127 }
1128 ;
1129
vlm808411d2006-03-14 16:31:37 +00001130WithSyntaxList:
1131 WithSyntaxToken {
vlmfa67ddc2004-06-03 03:38:44 +00001132 $$ = asn1p_wsyntx_new();
1133 TQ_ADD(&($$->chunks), $1, next);
1134 }
vlm808411d2006-03-14 16:31:37 +00001135 | WithSyntaxList WithSyntaxToken {
vlmfa67ddc2004-06-03 03:38:44 +00001136 $$ = $1;
1137 TQ_ADD(&($$->chunks), $2, next);
1138 }
1139 ;
1140
vlm808411d2006-03-14 16:31:37 +00001141WithSyntaxToken:
vlmeeb3c512006-03-16 05:11:14 +00001142 TOK_whitespace {
vlm1fcf7592006-08-18 02:27:55 +00001143 $$ = asn1p_wsyntx_chunk_fromstring($1.buf, 0);
vlmeeb3c512006-03-16 05:11:14 +00001144 $$->type = WC_WHITESPACE;
vlmfa67ddc2004-06-03 03:38:44 +00001145 }
vlm808411d2006-03-14 16:31:37 +00001146 | TOK_Literal {
vlm1fcf7592006-08-18 02:27:55 +00001147 $$ = asn1p_wsyntx_chunk_fromstring($1, 0);
vlm808411d2006-03-14 16:31:37 +00001148 }
vlma6a84d72006-03-16 10:03:35 +00001149 | PrimitiveFieldReference {
vlm1fcf7592006-08-18 02:27:55 +00001150 $$ = asn1p_wsyntx_chunk_fromstring($1.name, 0);
vlma6a84d72006-03-16 10:03:35 +00001151 $$->type = WC_FIELD;
vlmfa67ddc2004-06-03 03:38:44 +00001152 }
vlm808411d2006-03-14 16:31:37 +00001153 | '[' WithSyntaxList ']' {
1154 $$ = asn1p_wsyntx_chunk_fromsyntax($2);
1155 }
vlmfa67ddc2004-06-03 03:38:44 +00001156 ;
1157
vlmfa67ddc2004-06-03 03:38:44 +00001158ExtensionAndException:
1159 TOK_ThreeDots {
vlm39e5ed72004-09-05 10:40:41 +00001160 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001161 checkmem($$);
1162 $$->Identifier = strdup("...");
1163 checkmem($$->Identifier);
1164 $$->expr_type = A1TC_EXTENSIBLE;
1165 $$->meta_type = AMT_TYPE;
1166 }
1167 | TOK_ThreeDots '!' DefinedValue {
vlm39e5ed72004-09-05 10:40:41 +00001168 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001169 checkmem($$);
1170 $$->Identifier = strdup("...");
1171 checkmem($$->Identifier);
1172 $$->value = $3;
1173 $$->expr_type = A1TC_EXTENSIBLE;
1174 $$->meta_type = AMT_TYPE;
1175 }
1176 | TOK_ThreeDots '!' SignedNumber {
vlm39e5ed72004-09-05 10:40:41 +00001177 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001178 checkmem($$);
1179 $$->Identifier = strdup("...");
1180 $$->value = $3;
1181 checkmem($$->Identifier);
1182 $$->expr_type = A1TC_EXTENSIBLE;
1183 $$->meta_type = AMT_TYPE;
1184 }
1185 ;
1186
vlmec8f6812004-08-22 03:19:54 +00001187Type:
vlmfce48a42004-09-14 02:36:39 +00001188 optTag TypeDeclaration optConstraints {
1189 $$ = $2;
1190 $$->tag = $1;
vlmec8f6812004-08-22 03:19:54 +00001191 /*
1192 * Outer constraint for SEQUENCE OF and SET OF applies
1193 * to the inner type.
1194 */
1195 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1196 || $$->expr_type == ASN_CONSTR_SET_OF) {
1197 assert(!TQ_FIRST(&($$->members))->constraints);
vlmfce48a42004-09-14 02:36:39 +00001198 TQ_FIRST(&($$->members))->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001199 } else {
1200 if($$->constraints) {
1201 assert(!$2);
1202 } else {
vlmfce48a42004-09-14 02:36:39 +00001203 $$->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001204 }
1205 }
vlm177a5b62005-09-05 05:17:57 +00001206 }
1207 ;
1208
1209NSTD_IndirectMarker:
1210 {
1211 $$ = asn1p_as_pointer ? EM_INDIRECT : 0;
1212 asn1p_as_pointer = 0;
vlmec8f6812004-08-22 03:19:54 +00001213 }
1214 ;
1215
1216TypeDeclaration:
vlm177a5b62005-09-05 05:17:57 +00001217 NSTD_IndirectMarker TypeDeclarationSet {
vlm066dc102005-08-22 12:23:54 +00001218 $$ = $2;
vlm177a5b62005-09-05 05:17:57 +00001219 $$->marker.flags |= $1;
1220
1221 if(($$->marker.flags & EM_INDIRECT)
1222 && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
1223 fprintf(stderr,
1224 "INFO: Directive <ASN1C:RepresentAsPointer> "
1225 "applied to %s at line %d\n",
1226 ASN_EXPR_TYPE2STR($$->expr_type)
1227 ? ASN_EXPR_TYPE2STR($$->expr_type)
1228 : "member",
1229 $$->_lineno
1230 );
1231 }
vlm066dc102005-08-22 12:23:54 +00001232 }
vlm177a5b62005-09-05 05:17:57 +00001233 ;
vlm066dc102005-08-22 12:23:54 +00001234
1235TypeDeclarationSet:
vlm17e65d02006-03-21 04:48:15 +00001236 DefinedType {
vlmfa67ddc2004-06-03 03:38:44 +00001237 $$ = $1;
1238 }
vlm177a5b62005-09-05 05:17:57 +00001239 | TOK_CHOICE '{' AlternativeTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001240 $$ = $3;
1241 assert($$->expr_type == A1TC_INVALID);
1242 $$->expr_type = ASN_CONSTR_CHOICE;
1243 $$->meta_type = AMT_TYPE;
vlmfa67ddc2004-06-03 03:38:44 +00001244 }
vlm177a5b62005-09-05 05:17:57 +00001245 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001246 $$ = $3;
1247 assert($$->expr_type == A1TC_INVALID);
1248 $$->expr_type = ASN_CONSTR_SEQUENCE;
1249 $$->meta_type = AMT_TYPE;
1250 }
vlm177a5b62005-09-05 05:17:57 +00001251 | TOK_SET '{' optComponentTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001252 $$ = $3;
1253 assert($$->expr_type == A1TC_INVALID);
1254 $$->expr_type = ASN_CONSTR_SET;
1255 $$->meta_type = AMT_TYPE;
1256 }
vlm151c0b22004-09-22 16:03:36 +00001257 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
vlm39e5ed72004-09-05 10:40:41 +00001258 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001259 checkmem($$);
1260 $$->constraints = $2;
1261 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1262 $$->meta_type = AMT_TYPE;
vlm151c0b22004-09-22 16:03:36 +00001263 $6->Identifier = $4;
1264 $6->tag = $5;
1265 asn1p_expr_add($$, $6);
vlmec8f6812004-08-22 03:19:54 +00001266 }
vlm151c0b22004-09-22 16:03:36 +00001267 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
vlm39e5ed72004-09-05 10:40:41 +00001268 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001269 checkmem($$);
1270 $$->constraints = $2;
1271 $$->expr_type = ASN_CONSTR_SET_OF;
1272 $$->meta_type = AMT_TYPE;
vlm151c0b22004-09-22 16:03:36 +00001273 $6->Identifier = $4;
1274 $6->tag = $5;
1275 asn1p_expr_add($$, $6);
vlmec8f6812004-08-22 03:19:54 +00001276 }
1277 | TOK_ANY {
vlm39e5ed72004-09-05 10:40:41 +00001278 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001279 checkmem($$);
vlm044f7442004-09-04 04:49:21 +00001280 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001281 $$->meta_type = AMT_TYPE;
1282 }
1283 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1284 int ret;
vlm39e5ed72004-09-05 10:40:41 +00001285 $$ = asn1p_expr_new(yylineno);
vlmec8f6812004-08-22 03:19:54 +00001286 checkmem($$);
1287 $$->reference = asn1p_ref_new(yylineno);
1288 ret = asn1p_ref_add_component($$->reference,
1289 $4, RLT_lowercase);
1290 checkmem(ret == 0);
vlm044f7442004-09-04 04:49:21 +00001291 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001292 $$->meta_type = AMT_TYPE;
1293 }
vlmfa67ddc2004-06-03 03:38:44 +00001294 | TOK_INSTANCE TOK_OF ComplexTypeReference {
1295 $$ = asn1p_expr_new(yylineno);
1296 checkmem($$);
1297 $$->reference = $3;
1298 $$->expr_type = A1TC_INSTANCE;
1299 $$->meta_type = AMT_TYPE;
1300 }
1301 ;
1302
1303/*
1304 * A type name consisting of several components.
1305 * === EXAMPLE ===
1306 * === EOF ===
1307 */
1308ComplexTypeReference:
1309 TOK_typereference {
1310 int ret;
1311 $$ = asn1p_ref_new(yylineno);
1312 checkmem($$);
1313 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1314 checkmem(ret == 0);
1315 free($1);
1316 }
1317 | TOK_typereference '.' TypeRefName {
1318 int ret;
1319 $$ = asn1p_ref_new(yylineno);
1320 checkmem($$);
1321 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1322 checkmem(ret == 0);
1323 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1324 checkmem(ret == 0);
1325 free($1);
1326 }
vlmc94e28f2004-09-15 11:59:51 +00001327 | ObjectClassReference '.' TypeRefName {
1328 int ret;
1329 $$ = asn1p_ref_new(yylineno);
1330 checkmem($$);
1331 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1332 checkmem(ret == 0);
1333 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1334 checkmem(ret == 0);
1335 free($1);
1336 }
vlmfa67ddc2004-06-03 03:38:44 +00001337 | TOK_typereference '.' Identifier {
1338 int ret;
1339 $$ = asn1p_ref_new(yylineno);
1340 checkmem($$);
1341 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1342 checkmem(ret == 0);
1343 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1344 checkmem(ret == 0);
1345 free($1);
1346 }
1347 | ObjectClassReference {
1348 int ret;
1349 $$ = asn1p_ref_new(yylineno);
1350 checkmem($$);
1351 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1352 free($1);
1353 checkmem(ret == 0);
1354 }
1355 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1356 int ret;
1357 $$ = $3;
1358 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1359 free($1);
1360 checkmem(ret == 0);
1361 /*
1362 * Move the last element infront.
1363 */
1364 {
1365 struct asn1p_ref_component_s tmp_comp;
1366 tmp_comp = $$->components[$$->comp_count-1];
1367 memmove(&$$->components[1],
1368 &$$->components[0],
1369 sizeof($$->components[0])
1370 * ($$->comp_count - 1));
1371 $$->components[0] = tmp_comp;
1372 }
1373 }
1374 ;
1375
1376ComplexTypeReferenceAmpList:
1377 ComplexTypeReferenceElement {
1378 int ret;
1379 $$ = asn1p_ref_new(yylineno);
1380 checkmem($$);
1381 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1382 free($1.name);
1383 checkmem(ret == 0);
1384 }
1385 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1386 int ret;
1387 $$ = $1;
1388 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1389 free($3.name);
1390 checkmem(ret == 0);
1391 }
1392 ;
1393
vlma6a84d72006-03-16 10:03:35 +00001394ComplexTypeReferenceElement: PrimitiveFieldReference;
vlmfa67ddc2004-06-03 03:38:44 +00001395
vlma6a84d72006-03-16 10:03:35 +00001396PrimitiveFieldReference:
vlmfa67ddc2004-06-03 03:38:44 +00001397 /* "&Type1" */
1398 TOK_typefieldreference {
1399 $$.lex_type = RLT_AmpUppercase;
1400 $$.name = $1;
1401 }
1402 /* "&id" */
1403 | TOK_valuefieldreference {
1404 $$.lex_type = RLT_Amplowercase;
1405 $$.name = $1;
1406 }
1407 ;
1408
1409
vlmdc7cf042006-03-09 08:49:26 +00001410FieldName:
1411 /* "&Type1" */
1412 TOK_typefieldreference {
1413 $$ = asn1p_ref_new(yylineno);
1414 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1415 }
1416 | FieldName '.' TOK_typefieldreference {
1417 $$ = $$;
1418 asn1p_ref_add_component($$, $3, RLT_AmpUppercase);
1419 }
1420 | FieldName '.' TOK_valuefieldreference {
1421 $$ = $$;
1422 asn1p_ref_add_component($$, $3, RLT_Amplowercase);
1423 }
1424 ;
1425
1426DefinedObjectClass:
1427 TOK_capitalreference {
1428 $$ = asn1p_ref_new(yylineno);
1429 asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1430 }
vlmee7196e2006-03-09 09:08:49 +00001431/*
vlmdc7cf042006-03-09 08:49:26 +00001432 | TypeRefName '.' TOK_capitalreference {
1433 $$ = asn1p_ref_new(yylineno);
1434 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1435 asn1p_ref_add_component($$, $3, RLT_CAPITALS);
1436 }
vlmee7196e2006-03-09 09:08:49 +00001437*/
vlmdc7cf042006-03-09 08:49:26 +00001438 ;
1439
1440
vlmfa67ddc2004-06-03 03:38:44 +00001441/*
1442 * === EXAMPLE ===
1443 * value INTEGER ::= 1
1444 * === EOF ===
1445 */
1446ValueDefinition:
vlm17e65d02006-03-21 04:48:15 +00001447 Identifier DefinedType TOK_PPEQ Value {
vlmfa67ddc2004-06-03 03:38:44 +00001448 $$ = $2;
1449 assert($$->Identifier == NULL);
1450 $$->Identifier = $1;
1451 $$->meta_type = AMT_VALUE;
1452 $$->value = $4;
1453 }
1454 ;
1455
vlmc94e28f2004-09-15 11:59:51 +00001456Value:
vlm17e65d02006-03-21 04:48:15 +00001457 SimpleValue
1458 | DefinedValue
1459 | Identifier ':' Value {
vlmc94e28f2004-09-15 11:59:51 +00001460 $$ = asn1p_value_fromint(0);
1461 checkmem($$);
1462 $$->type = ATV_CHOICE_IDENTIFIER;
1463 $$->value.choice_identifier.identifier = $1;
1464 $$->value.choice_identifier.value = $3;
1465 }
vlmd30bc6c2005-03-24 16:27:02 +00001466 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
vlmfa67ddc2004-06-03 03:38:44 +00001467 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1468 checkmem($$);
1469 $$->type = ATV_UNPARSED;
1470 }
vlmc94e28f2004-09-15 11:59:51 +00001471 | TOK_NULL {
1472 $$ = asn1p_value_fromint(0);
1473 checkmem($$);
1474 $$->type = ATV_NULL;
1475 }
vlm17e65d02006-03-21 04:48:15 +00001476 ;
1477
1478SimpleValue:
1479 TOK_FALSE {
vlmc94e28f2004-09-15 11:59:51 +00001480 $$ = asn1p_value_fromint(0);
1481 checkmem($$);
1482 $$->type = ATV_FALSE;
1483 }
1484 | TOK_TRUE {
1485 $$ = asn1p_value_fromint(0);
1486 checkmem($$);
1487 $$->type = ATV_TRUE;
1488 }
vlmfa67ddc2004-06-03 03:38:44 +00001489 | TOK_bstring {
1490 $$ = _convert_bitstring2binary($1, 'B');
1491 checkmem($$);
1492 }
1493 | TOK_hstring {
1494 $$ = _convert_bitstring2binary($1, 'H');
1495 checkmem($$);
1496 }
vlme1e6ed82005-03-24 14:26:38 +00001497 | RestrictedCharacterStringValue {
1498 $$ = $$;
vlmfa67ddc2004-06-03 03:38:44 +00001499 }
1500 | SignedNumber {
1501 $$ = $1;
1502 }
vlmfa67ddc2004-06-03 03:38:44 +00001503 ;
1504
1505DefinedValue:
1506 Identifier {
1507 asn1p_ref_t *ref;
1508 int ret;
1509 ref = asn1p_ref_new(yylineno);
1510 checkmem(ref);
1511 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1512 checkmem(ret == 0);
1513 $$ = asn1p_value_fromref(ref, 0);
1514 checkmem($$);
1515 free($1);
1516 }
1517 | TypeRefName '.' Identifier {
1518 asn1p_ref_t *ref;
1519 int ret;
1520 ref = asn1p_ref_new(yylineno);
1521 checkmem(ref);
1522 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1523 checkmem(ret == 0);
1524 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1525 checkmem(ret == 0);
1526 $$ = asn1p_value_fromref(ref, 0);
1527 checkmem($$);
1528 free($1);
1529 free($3);
1530 }
1531 ;
1532
vlme1e6ed82005-03-24 14:26:38 +00001533
1534RestrictedCharacterStringValue:
1535 TOK_cstring {
1536 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1537 checkmem($$);
1538 }
vlm2c8c44d2005-03-24 16:22:35 +00001539 | TOK_tuple {
1540 $$ = asn1p_value_fromint($1);
1541 checkmem($$);
1542 $$->type = ATV_TUPLE;
1543 }
1544 | TOK_quadruple {
1545 $$ = asn1p_value_fromint($1);
1546 checkmem($$);
1547 $$->type = ATV_QUADRUPLE;
1548 }
1549 /*
vlme1e6ed82005-03-24 14:26:38 +00001550 | '{' TOK_number ',' TOK_number '}' {
1551 asn1c_integer_t v = ($2 << 4) + $4;
1552 if($2 > 7) return yyerror("X.680:2003, #37.14 "
1553 "mandates 0..7 range for Tuple's TableColumn");
1554 if($4 > 15) return yyerror("X.680:2003, #37.14 "
1555 "mandates 0..15 range for Tuple's TableRow");
1556 $$ = asn1p_value_fromint(v);
1557 checkmem($$);
1558 $$->type = ATV_TUPLE;
1559 }
1560 | '{' TOK_number ',' TOK_number ',' TOK_number ',' TOK_number '}' {
1561 asn1c_integer_t v = ($2 << 24) | ($4 << 16) | ($6 << 8) | $8;
1562 if($2 > 127) return yyerror("X.680:2003, #37.12 "
1563 "mandates 0..127 range for Quadruple's Group");
1564 if($4 > 255) return yyerror("X.680:2003, #37.12 "
1565 "mandates 0..255 range for Quadruple's Plane");
1566 if($6 > 255) return yyerror("X.680:2003, #37.12 "
1567 "mandates 0..255 range for Quadruple's Row");
1568 if($8 > 255) return yyerror("X.680:2003, #37.12 "
1569 "mandates 0..255 range for Quadruple's Cell");
1570 $$ = asn1p_value_fromint(v);
1571 checkmem($$);
1572 $$->type = ATV_QUADRUPLE;
1573 }
vlm2c8c44d2005-03-24 16:22:35 +00001574 */
vlme1e6ed82005-03-24 14:26:38 +00001575 ;
1576
vlmfa67ddc2004-06-03 03:38:44 +00001577Opaque:
1578 TOK_opaque {
vlm6611add2005-03-20 14:28:32 +00001579 $$.len = $1.len + 1;
vlmfa67ddc2004-06-03 03:38:44 +00001580 $$.buf = malloc($$.len + 1);
1581 checkmem($$.buf);
1582 $$.buf[0] = '{';
vlm6611add2005-03-20 14:28:32 +00001583 memcpy($$.buf + 1, $1.buf, $1.len);
vlmfa67ddc2004-06-03 03:38:44 +00001584 $$.buf[$$.len] = '\0';
1585 free($1.buf);
1586 }
1587 | Opaque TOK_opaque {
1588 int newsize = $1.len + $2.len;
1589 char *p = malloc(newsize + 1);
1590 checkmem(p);
1591 memcpy(p , $1.buf, $1.len);
1592 memcpy(p + $1.len, $2.buf, $2.len);
1593 p[newsize] = '\0';
1594 free($1.buf);
1595 free($2.buf);
1596 $$.buf = p;
1597 $$.len = newsize;
1598 }
1599 ;
1600
1601BasicTypeId:
1602 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1603 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1604 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1605 | BasicTypeId_UniverationCompatible { $$ = $1; }
1606 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1607 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1608 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1609 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1610 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1611 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1612 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1613 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
vlm5e2c4b92005-03-20 11:12:40 +00001614 | BasicString { $$ = $1; }
vlmfa67ddc2004-06-03 03:38:44 +00001615 ;
1616
1617/*
1618 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1619 */
1620BasicTypeId_UniverationCompatible:
1621 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1622 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1623 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1624 ;
1625
1626BasicType:
1627 BasicTypeId {
vlm39e5ed72004-09-05 10:40:41 +00001628 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001629 checkmem($$);
1630 $$->expr_type = $1;
1631 $$->meta_type = AMT_TYPE;
1632 }
1633 | BasicTypeId_UniverationCompatible UniverationDefinition {
1634 if($2) {
1635 $$ = $2;
1636 } else {
vlm39e5ed72004-09-05 10:40:41 +00001637 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001638 checkmem($$);
1639 }
1640 $$->expr_type = $1;
1641 $$->meta_type = AMT_TYPE;
1642 }
1643 ;
1644
1645BasicString:
1646 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1647 | TOK_GeneralString {
1648 $$ = ASN_STRING_GeneralString;
vlmc94e28f2004-09-15 11:59:51 +00001649 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001650 }
1651 | TOK_GraphicString {
1652 $$ = ASN_STRING_GraphicString;
vlmc94e28f2004-09-15 11:59:51 +00001653 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001654 }
1655 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1656 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1657 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1658 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1659 | TOK_T61String {
1660 $$ = ASN_STRING_T61String;
vlmc94e28f2004-09-15 11:59:51 +00001661 fprintf(stderr, "WARNING: T61String is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001662 }
1663 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1664 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1665 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1666 | TOK_VideotexString {
1667 $$ = ASN_STRING_VideotexString;
vlmc94e28f2004-09-15 11:59:51 +00001668 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001669 }
1670 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1671 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1672 ;
1673
vlm5f0128b2004-08-20 13:25:29 +00001674
vlmfa67ddc2004-06-03 03:38:44 +00001675/*
1676 * Data type constraints.
1677 */
vlmfa67ddc2004-06-03 03:38:44 +00001678Union: '|' | TOK_UNION;
1679Intersection: '^' | TOK_INTERSECTION;
1680Except: TOK_EXCEPT;
1681
vlm9283dbe2004-08-18 04:59:12 +00001682optConstraints:
1683 { $$ = 0; }
vlm5f0128b2004-08-20 13:25:29 +00001684 | Constraints {
1685 $$ = $1;
1686 }
1687 ;
1688
1689Constraints:
1690 SetOfConstraints {
vlm9fe7c922005-08-12 10:08:45 +00001691 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
vlm9283dbe2004-08-18 04:59:12 +00001692 }
1693 | TOK_SIZE '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001694 /*
1695 * This is a special case, for compatibility purposes.
vlm9283dbe2004-08-18 04:59:12 +00001696 * It goes without parentheses.
vlmfa67ddc2004-06-03 03:38:44 +00001697 */
vlm9fe7c922005-08-12 10:08:45 +00001698 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001699 }
vlmfa67ddc2004-06-03 03:38:44 +00001700 ;
1701
vlm9283dbe2004-08-18 04:59:12 +00001702SetOfConstraints:
1703 '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001704 $$ = $2;
1705 }
vlm9283dbe2004-08-18 04:59:12 +00001706 | SetOfConstraints '(' ElementSetSpecs ')' {
vlm9fe7c922005-08-12 10:08:45 +00001707 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
vlm9283dbe2004-08-18 04:59:12 +00001708 }
vlmfa67ddc2004-06-03 03:38:44 +00001709 ;
1710
vlm9283dbe2004-08-18 04:59:12 +00001711ElementSetSpecs:
vlmdfbff8c2006-03-21 09:41:28 +00001712 TOK_ThreeDots {
1713 $$ = asn1p_constraint_new(yylineno);
1714 $$->type = ACT_EL_EXT;
1715 }
1716 | ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001717 $$ = $1;
1718 }
vlm9283dbe2004-08-18 04:59:12 +00001719 | ElementSetSpec ',' TOK_ThreeDots {
vlmfa67ddc2004-06-03 03:38:44 +00001720 asn1p_constraint_t *ct;
1721 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001722 ct->type = ACT_EL_EXT;
vlm9fe7c922005-08-12 10:08:45 +00001723 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlmfa67ddc2004-06-03 03:38:44 +00001724 }
vlm9283dbe2004-08-18 04:59:12 +00001725 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001726 asn1p_constraint_t *ct;
1727 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001728 ct->type = ACT_EL_EXT;
vlm9fe7c922005-08-12 10:08:45 +00001729 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlm6f5eb0b2004-08-13 12:35:09 +00001730 ct = $$;
vlm9fe7c922005-08-12 10:08:45 +00001731 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
vlmfa67ddc2004-06-03 03:38:44 +00001732 }
vlmfa67ddc2004-06-03 03:38:44 +00001733 ;
1734
vlm9283dbe2004-08-18 04:59:12 +00001735ElementSetSpec:
1736 ConstraintSubtypeElement {
1737 $$ = $1;
1738 }
vlme1e6ed82005-03-24 14:26:38 +00001739 | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001740 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
vlme1e6ed82005-03-24 14:26:38 +00001741 }
vlm9283dbe2004-08-18 04:59:12 +00001742 | ElementSetSpec Union ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001743 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001744 }
vlm9283dbe2004-08-18 04:59:12 +00001745 | ElementSetSpec Intersection ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001746 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001747 }
vlm9283dbe2004-08-18 04:59:12 +00001748 | ConstraintSubtypeElement Except ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001749 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001750 }
1751 ;
1752
1753ConstraintSubtypeElement:
vlm9283dbe2004-08-18 04:59:12 +00001754 ConstraintSpec '(' ElementSetSpecs ')' {
1755 int ret;
1756 $$ = asn1p_constraint_new(yylineno);
1757 checkmem($$);
1758 $$->type = $1;
1759 ret = asn1p_constraint_insert($$, $3);
1760 checkmem(ret == 0);
1761 }
1762 | '(' ElementSetSpecs ')' {
1763 int ret;
1764 $$ = asn1p_constraint_new(yylineno);
1765 checkmem($$);
1766 $$->type = ACT_CA_SET;
1767 ret = asn1p_constraint_insert($$, $2);
1768 checkmem(ret == 0);
1769 }
vlma6a12e32005-03-20 12:58:00 +00001770 | SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001771 $$ = asn1p_constraint_new(yylineno);
1772 checkmem($$);
1773 $$->type = ACT_EL_VALUE;
1774 $$->value = $1;
1775 }
vlma6a12e32005-03-20 12:58:00 +00001776 | ContainedSubtype {
1777 $$ = asn1p_constraint_new(yylineno);
1778 checkmem($$);
1779 $$->type = ACT_EL_TYPE;
1780 $$->containedSubtype = $1;
1781 }
1782 | SingleValue ConstraintRangeSpec SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001783 $$ = asn1p_constraint_new(yylineno);
1784 checkmem($$);
1785 $$->type = $2;
1786 $$->range_start = $1;
1787 $$->range_stop = $3;
1788 }
vlma6a12e32005-03-20 12:58:00 +00001789 | TOK_MIN ConstraintRangeSpec SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001790 $$ = asn1p_constraint_new(yylineno);
1791 checkmem($$);
vlm9283dbe2004-08-18 04:59:12 +00001792 $$->type = $2;
1793 $$->range_start = asn1p_value_fromint(-123);
1794 $$->range_stop = $3;
1795 $$->range_start->type = ATV_MIN;
1796 }
vlma6a12e32005-03-20 12:58:00 +00001797 | SingleValue ConstraintRangeSpec TOK_MAX {
vlm9283dbe2004-08-18 04:59:12 +00001798 $$ = asn1p_constraint_new(yylineno);
1799 checkmem($$);
1800 $$->type = $2;
1801 $$->range_start = $1;
1802 $$->range_stop = asn1p_value_fromint(321);
1803 $$->range_stop->type = ATV_MAX;
1804 }
1805 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1806 $$ = asn1p_constraint_new(yylineno);
1807 checkmem($$);
1808 $$->type = $2;
1809 $$->range_start = asn1p_value_fromint(-123);
1810 $$->range_stop = asn1p_value_fromint(321);
1811 $$->range_start->type = ATV_MIN;
1812 $$->range_stop->type = ATV_MAX;
vlmfa67ddc2004-06-03 03:38:44 +00001813 }
1814 | TableConstraint {
1815 $$ = $1;
1816 }
vlm7bbdc9f2005-03-28 15:01:27 +00001817 | InnerTypeConstraint {
vlmfa67ddc2004-06-03 03:38:44 +00001818 $$ = $1;
1819 }
vlm6611add2005-03-20 14:28:32 +00001820 | TOK_CONSTRAINED TOK_BY '{'
1821 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1822 $$ = asn1p_constraint_new(yylineno);
1823 checkmem($$);
1824 $$->type = ACT_CT_CTDBY;
1825 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
1826 checkmem($$->value);
1827 $$->value->type = ATV_UNPARSED;
1828 }
vlmfa67ddc2004-06-03 03:38:44 +00001829 ;
1830
1831ConstraintRangeSpec:
1832 TOK_TwoDots { $$ = ACT_EL_RANGE; }
1833 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
1834 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
1835 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
1836 ;
1837
1838ConstraintSpec:
1839 TOK_SIZE {
1840 $$ = ACT_CT_SIZE;
1841 }
1842 | TOK_FROM {
1843 $$ = ACT_CT_FROM;
1844 }
1845 ;
1846
vlma6a12e32005-03-20 12:58:00 +00001847SingleValue:
vlm4053ca52005-02-18 16:34:21 +00001848 TOK_FALSE {
1849 $$ = asn1p_value_fromint(0);
1850 checkmem($$);
1851 $$->type = ATV_FALSE;
1852 }
1853 | TOK_TRUE {
1854 $$ = asn1p_value_fromint(1);
1855 checkmem($$);
1856 $$->type = ATV_TRUE;
1857 }
vlme745fcd2006-09-05 16:18:34 +00001858 | RealValue
1859 | RestrictedCharacterStringValue
vlmfa67ddc2004-06-03 03:38:44 +00001860 | Identifier {
1861 asn1p_ref_t *ref;
1862 int ret;
1863 ref = asn1p_ref_new(yylineno);
1864 checkmem(ref);
1865 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1866 checkmem(ret == 0);
1867 $$ = asn1p_value_fromref(ref, 0);
1868 checkmem($$);
1869 free($1);
1870 }
vlma6a12e32005-03-20 12:58:00 +00001871 ;
1872
1873ContainedSubtype:
1874 TypeRefName {
vlm4053ca52005-02-18 16:34:21 +00001875 asn1p_ref_t *ref;
1876 int ret;
1877 ref = asn1p_ref_new(yylineno);
1878 checkmem(ref);
1879 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1880 checkmem(ret == 0);
1881 $$ = asn1p_value_fromref(ref, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001882 checkmem($$);
vlm4053ca52005-02-18 16:34:21 +00001883 free($1);
vlmfa67ddc2004-06-03 03:38:44 +00001884 }
1885 ;
1886
vlm7bbdc9f2005-03-28 15:01:27 +00001887InnerTypeConstraint:
1888 TOK_WITH TOK_COMPONENT SetOfConstraints {
vlm9fe7c922005-08-12 10:08:45 +00001889 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
vlm7bbdc9f2005-03-28 15:01:27 +00001890 }
1891 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
vlm9fe7c922005-08-12 10:08:45 +00001892 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001893 }
1894 ;
1895
1896WithComponentsList:
1897 WithComponentsElement {
1898 $$ = $1;
1899 }
1900 | WithComponentsList ',' WithComponentsElement {
vlm9fe7c922005-08-12 10:08:45 +00001901 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001902 }
1903 ;
1904
1905WithComponentsElement:
1906 TOK_ThreeDots {
1907 $$ = asn1p_constraint_new(yylineno);
1908 checkmem($$);
1909 $$->type = ACT_EL_EXT;
vlm1aeaddd2006-07-13 08:24:20 +00001910 $$->value = asn1p_value_frombuf("...", 3, 1);
vlmfa67ddc2004-06-03 03:38:44 +00001911 }
1912 | Identifier optConstraints optPresenceConstraint {
1913 $$ = asn1p_constraint_new(yylineno);
1914 checkmem($$);
1915 $$->type = ACT_EL_VALUE;
1916 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1917 $$->presence = $3;
vlm7bbdc9f2005-03-28 15:01:27 +00001918 if($2) asn1p_constraint_insert($$, $2);
vlmfa67ddc2004-06-03 03:38:44 +00001919 }
1920 ;
1921
1922/*
1923 * presence constraint for WithComponents
1924 */
1925optPresenceConstraint:
1926 { $$ = ACPRES_DEFAULT; }
1927 | PresenceConstraint { $$ = $1; }
1928 ;
1929
1930PresenceConstraint:
1931 TOK_PRESENT {
1932 $$ = ACPRES_PRESENT;
1933 }
1934 | TOK_ABSENT {
1935 $$ = ACPRES_ABSENT;
1936 }
1937 | TOK_OPTIONAL {
1938 $$ = ACPRES_OPTIONAL;
1939 }
1940 ;
1941
1942TableConstraint:
1943 SimpleTableConstraint {
1944 $$ = $1;
1945 }
1946 | ComponentRelationConstraint {
1947 $$ = $1;
1948 }
1949 ;
1950
1951/*
1952 * "{ExtensionSet}"
1953 */
1954SimpleTableConstraint:
1955 '{' TypeRefName '}' {
1956 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
1957 asn1p_constraint_t *ct;
1958 int ret;
1959 ret = asn1p_ref_add_component(ref, $2, 0);
1960 checkmem(ret == 0);
1961 ct = asn1p_constraint_new(yylineno);
1962 checkmem($$);
1963 ct->type = ACT_EL_VALUE;
1964 ct->value = asn1p_value_fromref(ref, 0);
vlm9fe7c922005-08-12 10:08:45 +00001965 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001966 }
1967 ;
1968
1969ComponentRelationConstraint:
1970 SimpleTableConstraint '{' AtNotationList '}' {
vlm9fe7c922005-08-12 10:08:45 +00001971 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001972 }
1973 ;
1974
1975AtNotationList:
1976 AtNotationElement {
1977 $$ = asn1p_constraint_new(yylineno);
1978 checkmem($$);
1979 $$->type = ACT_EL_VALUE;
1980 $$->value = asn1p_value_fromref($1, 0);
1981 }
1982 | AtNotationList ',' AtNotationElement {
1983 asn1p_constraint_t *ct;
1984 ct = asn1p_constraint_new(yylineno);
1985 checkmem(ct);
1986 ct->type = ACT_EL_VALUE;
1987 ct->value = asn1p_value_fromref($3, 0);
vlm9fe7c922005-08-12 10:08:45 +00001988 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlmfa67ddc2004-06-03 03:38:44 +00001989 }
1990 ;
1991
1992/*
1993 * @blah
1994 */
1995AtNotationElement:
1996 '@' ComponentIdList {
1997 char *p = malloc(strlen($2) + 2);
1998 int ret;
1999 *p = '@';
2000 strcpy(p + 1, $2);
2001 $$ = asn1p_ref_new(yylineno);
2002 ret = asn1p_ref_add_component($$, p, 0);
2003 checkmem(ret == 0);
2004 free(p);
2005 free($2);
2006 }
2007 | '@' '.' ComponentIdList {
2008 char *p = malloc(strlen($3) + 3);
2009 int ret;
2010 p[0] = '@';
2011 p[1] = '.';
2012 strcpy(p + 2, $3);
2013 $$ = asn1p_ref_new(yylineno);
2014 ret = asn1p_ref_add_component($$, p, 0);
2015 checkmem(ret == 0);
2016 free(p);
2017 free($3);
2018 }
2019 ;
2020
2021/* identifier "." ... */
2022ComponentIdList:
2023 Identifier {
2024 $$ = $1;
2025 }
2026 | ComponentIdList '.' Identifier {
2027 int l1 = strlen($1);
2028 int l3 = strlen($3);
2029 $$ = malloc(l1 + 1 + l3 + 1);
2030 memcpy($$, $1, l1);
2031 $$[l1] = '.';
2032 memcpy($$ + l1 + 1, $3, l3);
2033 $$[l1 + 1 + l3] = '\0';
2034 }
2035 ;
2036
2037
2038
2039/*
2040 * MARKERS
2041 */
2042
2043optMarker:
vlmc94e28f2004-09-15 11:59:51 +00002044 {
2045 $$.flags = EM_NOMARK;
2046 $$.default_value = 0;
2047 }
vlmfa67ddc2004-06-03 03:38:44 +00002048 | Marker { $$ = $1; }
2049 ;
2050
2051Marker:
2052 TOK_OPTIONAL {
vlm1ac75e72005-11-26 11:21:55 +00002053 $$.flags = EM_OPTIONAL | EM_INDIRECT;
vlmc94e28f2004-09-15 11:59:51 +00002054 $$.default_value = 0;
vlmfa67ddc2004-06-03 03:38:44 +00002055 }
vlmc94e28f2004-09-15 11:59:51 +00002056 | TOK_DEFAULT Value {
2057 $$.flags = EM_DEFAULT;
2058 $$.default_value = $2;
vlmfa67ddc2004-06-03 03:38:44 +00002059 }
2060 ;
2061
2062/*
2063 * Universal enumeration definition to use in INTEGER and ENUMERATED.
2064 * === EXAMPLE ===
2065 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
2066 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
2067 * === EOF ===
2068 */
2069/*
2070optUniverationDefinition:
2071 { $$ = 0; }
2072 | UniverationDefinition {
2073 $$ = $1;
2074 }
2075 ;
2076*/
2077
2078UniverationDefinition:
2079 '{' '}' {
vlm39e5ed72004-09-05 10:40:41 +00002080 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002081 checkmem($$);
2082 }
2083 | '{' UniverationList '}' {
2084 $$ = $2;
2085 }
2086 ;
2087
2088UniverationList:
2089 UniverationElement {
vlm39e5ed72004-09-05 10:40:41 +00002090 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002091 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +00002092 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +00002093 }
2094 | UniverationList ',' UniverationElement {
2095 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +00002096 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +00002097 }
2098 ;
2099
2100UniverationElement:
2101 Identifier {
vlm39e5ed72004-09-05 10:40:41 +00002102 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002103 checkmem($$);
2104 $$->expr_type = A1TC_UNIVERVAL;
2105 $$->meta_type = AMT_VALUE;
2106 $$->Identifier = $1;
2107 }
2108 | Identifier '(' SignedNumber ')' {
vlm39e5ed72004-09-05 10:40:41 +00002109 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002110 checkmem($$);
2111 $$->expr_type = A1TC_UNIVERVAL;
2112 $$->meta_type = AMT_VALUE;
2113 $$->Identifier = $1;
2114 $$->value = $3;
2115 }
2116 | Identifier '(' DefinedValue ')' {
vlm39e5ed72004-09-05 10:40:41 +00002117 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002118 checkmem($$);
2119 $$->expr_type = A1TC_UNIVERVAL;
2120 $$->meta_type = AMT_VALUE;
2121 $$->Identifier = $1;
2122 $$->value = $3;
2123 }
2124 | SignedNumber {
vlm39e5ed72004-09-05 10:40:41 +00002125 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002126 checkmem($$);
2127 $$->expr_type = A1TC_UNIVERVAL;
2128 $$->meta_type = AMT_VALUE;
2129 $$->value = $1;
2130 }
2131 | TOK_ThreeDots {
vlm39e5ed72004-09-05 10:40:41 +00002132 $$ = asn1p_expr_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00002133 checkmem($$);
2134 $$->Identifier = strdup("...");
2135 checkmem($$->Identifier);
2136 $$->expr_type = A1TC_EXTENSIBLE;
2137 $$->meta_type = AMT_VALUE;
2138 }
2139 ;
2140
2141SignedNumber:
2142 TOK_number {
2143 $$ = asn1p_value_fromint($1);
2144 checkmem($$);
2145 }
2146 | TOK_number_negative {
2147 $$ = asn1p_value_fromint($1);
2148 checkmem($$);
2149 }
2150 ;
2151
vlme745fcd2006-09-05 16:18:34 +00002152RealValue:
2153 SignedNumber
2154 | TOK_realnumber {
2155 $$ = asn1p_value_fromdouble($1);
2156 checkmem($$);
2157 }
2158 ;
2159
vlmfa67ddc2004-06-03 03:38:44 +00002160/*
2161 * SEQUENCE definition.
2162 * === EXAMPLE ===
2163 * Struct1 ::= SEQUENCE {
2164 * memb1 Struct2,
2165 * memb2 SEQUENCE OF {
2166 * memb2-1 Struct 3
2167 * }
2168 * }
2169 * === EOF ===
2170 */
2171
2172
2173
2174/*
2175 * SET definition.
2176 * === EXAMPLE ===
2177 * Person ::= SET {
2178 * name [0] PrintableString (SIZE(1..20)),
2179 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2180 * }
2181 * === EOF ===
2182 */
2183
2184optTag:
2185 { memset(&$$, 0, sizeof($$)); }
2186 | Tag { $$ = $1; }
2187 ;
2188
2189Tag:
vlm2728a8d2005-01-23 09:51:44 +00002190 TagTypeValue TagPlicit {
vlmfa67ddc2004-06-03 03:38:44 +00002191 $$ = $1;
vlm2728a8d2005-01-23 09:51:44 +00002192 $$.tag_mode = $2.tag_mode;
vlmfa67ddc2004-06-03 03:38:44 +00002193 }
vlm2728a8d2005-01-23 09:51:44 +00002194 ;
2195
2196TagTypeValue:
2197 '[' TagClass TOK_number ']' {
2198 $$ = $2;
2199 $$.tag_value = $3;
2200 };
2201
2202TagClass:
2203 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2204 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2205 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2206 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2207 ;
2208
2209TagPlicit:
2210 { $$.tag_mode = TM_DEFAULT; }
2211 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2212 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
vlmfa67ddc2004-06-03 03:38:44 +00002213 ;
2214
2215TypeRefName:
2216 TOK_typereference {
2217 checkmem($1);
2218 $$ = $1;
2219 }
vlm9283dbe2004-08-18 04:59:12 +00002220 | TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00002221 checkmem($1);
2222 $$ = $1;
2223 }
2224 ;
2225
vlm9283dbe2004-08-18 04:59:12 +00002226
vlmfa67ddc2004-06-03 03:38:44 +00002227ObjectClassReference:
vlm9283dbe2004-08-18 04:59:12 +00002228 TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00002229 checkmem($1);
2230 $$ = $1;
2231 }
2232 ;
2233
vlm151c0b22004-09-22 16:03:36 +00002234optIdentifier:
2235 { $$ = 0; }
2236 | Identifier {
2237 $$ = $1;
2238 }
vlma5b977d2005-06-06 08:28:58 +00002239 ;
vlm151c0b22004-09-22 16:03:36 +00002240
vlmfa67ddc2004-06-03 03:38:44 +00002241Identifier:
2242 TOK_identifier {
2243 checkmem($1);
2244 $$ = $1;
2245 }
2246 ;
2247
vlmfa67ddc2004-06-03 03:38:44 +00002248%%
2249
2250
2251/*
2252 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2253 */
2254static asn1p_value_t *
2255_convert_bitstring2binary(char *str, int base) {
2256 asn1p_value_t *val;
2257 int slen;
2258 int memlen;
2259 int baselen;
2260 int bits;
2261 uint8_t *binary_vector;
2262 uint8_t *bv_ptr;
2263 uint8_t cur_val;
2264
2265 assert(str);
2266 assert(str[0] == '\'');
2267
2268 switch(base) {
2269 case 'B':
2270 baselen = 1;
2271 break;
2272 case 'H':
2273 baselen = 4;
2274 break;
2275 default:
2276 assert(base == 'B' || base == 'H');
2277 errno = EINVAL;
2278 return NULL;
2279 }
2280
2281 slen = strlen(str);
2282 assert(str[slen - 1] == base);
2283 assert(str[slen - 2] == '\'');
2284
2285 memlen = slen / (8 / baselen); /* Conservative estimate */
2286
2287 bv_ptr = binary_vector = malloc(memlen + 1);
2288 if(bv_ptr == NULL)
2289 /* ENOMEM */
2290 return NULL;
2291
2292 cur_val = 0;
2293 bits = 0;
2294 while(*(++str) != '\'') {
2295 switch(baselen) {
2296 case 1:
2297 switch(*str) {
2298 case '1':
2299 cur_val |= 1 << (7 - (bits % 8));
2300 case '0':
2301 break;
2302 default:
2303 assert(!"_y UNREACH1");
2304 case ' ': case '\r': case '\n':
2305 continue;
2306 }
2307 break;
2308 case 4:
2309 switch(*str) {
2310 case '0': case '1': case '2': case '3': case '4':
2311 case '5': case '6': case '7': case '8': case '9':
2312 cur_val |= (*str - '0') << (4 - (bits % 8));
2313 break;
2314 case 'A': case 'B': case 'C':
2315 case 'D': case 'E': case 'F':
2316 cur_val |= ((*str - 'A') + 10)
2317 << (4 - (bits % 8));
2318 break;
2319 default:
2320 assert(!"_y UNREACH2");
2321 case ' ': case '\r': case '\n':
2322 continue;
2323 }
2324 break;
2325 }
2326
2327 bits += baselen;
2328 if((bits % 8) == 0) {
2329 *bv_ptr++ = cur_val;
2330 cur_val = 0;
2331 }
2332 }
2333
2334 *bv_ptr = cur_val;
2335 assert((bv_ptr - binary_vector) <= memlen);
2336
2337 val = asn1p_value_frombits(binary_vector, bits, 0);
2338 if(val == NULL) {
2339 free(binary_vector);
2340 }
2341
2342 return val;
2343}
2344
vlm5d89c3d2005-08-13 09:07:11 +00002345/*
2346 * For unnamed types (used in old X.208 compliant modules)
2347 * generate some sort of interim names, to not to force human being to fix
2348 * the specification's compliance to modern ASN.1 standards.
2349 */
2350static void
2351_fixup_anonymous_identifier(asn1p_expr_t *expr) {
2352 char *p;
2353 assert(expr->Identifier == 0);
2354
2355 /*
2356 * Try to figure out the type name
2357 * without going too much into details
2358 */
2359 expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type);
2360 if(expr->reference && expr->reference->comp_count > 0)
2361 expr->Identifier = expr->reference->components[0].name;
2362
2363 fprintf(stderr,
2364 "WARNING: Line %d: expected lower-case member identifier, "
2365 "found an unnamed %s.\n"
2366 "WARNING: Obsolete X.208 syntax detected, "
2367 "please give the member a name.\n",
2368 yylineno, expr->Identifier ? expr->Identifier : "type");
2369
2370 if(!expr->Identifier)
2371 expr->Identifier = "unnamed";
2372 expr->Identifier = strdup(expr->Identifier);
2373 assert(expr->Identifier);
2374 /* Make a lowercase identifier from the type name */
2375 for(p = expr->Identifier; *p; p++) {
2376 switch(*p) {
2377 case 'A' ... 'Z': *p += 32; break;
2378 case ' ': *p = '_'; break;
2379 case '-': *p = '_'; break;
2380 }
2381 }
2382 fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". "
2383 "Name clash may occur later.\n",
2384 expr->Identifier);
2385}
2386
vlmfa67ddc2004-06-03 03:38:44 +00002387int
2388yyerror(const char *msg) {
vlm808411d2006-03-14 16:31:37 +00002389 extern char *asn1p_text;
vlmfa67ddc2004-06-03 03:38:44 +00002390 fprintf(stderr,
2391 "ASN.1 grammar parse error "
2392 "near line %d (token \"%s\"): %s\n",
vlm39e5ed72004-09-05 10:40:41 +00002393 yylineno, asn1p_text, msg);
vlmfa67ddc2004-06-03 03:38:44 +00002394 return -1;
2395}
2396