blob: a89ba79803d3419ef83f58a4bbf3c9c0132d9611 [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
vlm43c8ac52006-09-17 04:52:50 +000040static asn1p_module_t *currentModule;
41#define NEW_EXPR() (asn1p_expr_new(yylineno, currentModule))
42
vlm04a08da2005-08-12 10:06:17 +000043#define checkmem(ptr) do { \
44 if(!(ptr)) \
45 return yyerror("Memory failure"); \
vlmfa67ddc2004-06-03 03:38:44 +000046 } while(0)
47
vlm9fe7c922005-08-12 10:08:45 +000048#define CONSTRAINT_INSERT(root, constr_type, arg1, arg2) do { \
vlm04a08da2005-08-12 10:06:17 +000049 if(arg1->type != constr_type) { \
50 int __ret; \
51 root = asn1p_constraint_new(yylineno); \
52 checkmem(root); \
53 root->type = constr_type; \
54 __ret = asn1p_constraint_insert(root, \
55 arg1); \
56 checkmem(__ret == 0); \
57 } else { \
58 root = arg1; \
59 } \
60 if(arg2) { \
61 int __ret \
62 = asn1p_constraint_insert(root, arg2); \
63 checkmem(__ret == 0); \
64 } \
vlmfa67ddc2004-06-03 03:38:44 +000065 } while(0)
66
vlmd3420d32006-09-14 10:35:20 +000067#ifdef AL_IMPORT
68#error AL_IMPORT DEFINED ELSEWHERE!
69#endif
70#define AL_IMPORT(to,where,from,field) do { \
71 if(!(from)) break; \
72 while(TQ_FIRST(&((from)->where))) { \
73 TQ_ADD(&((to)->where), \
74 TQ_REMOVE(&((from)->where), field), \
75 field); \
76 } \
77 assert(TQ_FIRST(&((from)->where)) == 0); \
78 } while(0)
79
vlmfa67ddc2004-06-03 03:38:44 +000080%}
81
82
83/*
84 * Token value definition.
85 * a_*: ASN-specific types.
86 * tv_*: Locally meaningful types.
87 */
88%union {
89 asn1p_t *a_grammar;
90 asn1p_module_flags_e a_module_flags;
91 asn1p_module_t *a_module;
92 asn1p_expr_type_e a_type; /* ASN.1 Type */
93 asn1p_expr_t *a_expr; /* Constructed collection */
94 asn1p_constraint_t *a_constr; /* Constraint */
95 enum asn1p_constraint_type_e a_ctype;/* Constraint type */
96 asn1p_xports_t *a_xports; /* IMports/EXports */
vlm04a08da2005-08-12 10:06:17 +000097 struct AssignedIdentifier a_aid; /* Assigned Identifier */
vlmfa67ddc2004-06-03 03:38:44 +000098 asn1p_oid_t *a_oid; /* Object Identifier */
99 asn1p_oid_arc_t a_oid_arc; /* Single OID's arc */
100 struct asn1p_type_tag_s a_tag; /* A tag */
101 asn1p_ref_t *a_ref; /* Reference to custom type */
102 asn1p_wsyntx_t *a_wsynt; /* WITH SYNTAX contents */
103 asn1p_wsyntx_chunk_t *a_wchunk; /* WITH SYNTAX chunk */
104 struct asn1p_ref_component_s a_refcomp; /* Component of a reference */
105 asn1p_value_t *a_value; /* Number, DefinedValue, etc */
106 struct asn1p_param_s a_parg; /* A parameter argument */
107 asn1p_paramlist_t *a_plist; /* A pargs list */
vlmc94e28f2004-09-15 11:59:51 +0000108 struct asn1p_expr_marker_s a_marker; /* OPTIONAL/DEFAULT */
vlmfa67ddc2004-06-03 03:38:44 +0000109 enum asn1p_constr_pres_e a_pres; /* PRESENT/ABSENT/OPTIONAL */
vlm0aa86902004-10-12 23:26:53 +0000110 asn1c_integer_t a_int;
vlme745fcd2006-09-05 16:18:34 +0000111 double a_dbl;
vlmfa67ddc2004-06-03 03:38:44 +0000112 char *tv_str;
113 struct {
114 char *buf;
115 int len;
116 } tv_opaque;
117 struct {
118 char *name;
119 struct asn1p_type_tag_s tag;
120 } tv_nametag;
121};
122
123/*
124 * Token types returned by scanner.
125 */
126%token TOK_PPEQ /* "::=", Pseudo Pascal EQuality */
vlmeeb3c512006-03-16 05:11:14 +0000127%token <tv_opaque> TOK_whitespace /* A span of whitespace */
vlmfa67ddc2004-06-03 03:38:44 +0000128%token <tv_opaque> TOK_opaque /* opaque data (driven from .y) */
129%token <tv_str> TOK_bstring
130%token <tv_opaque> TOK_cstring
131%token <tv_str> TOK_hstring
132%token <tv_str> TOK_identifier
133%token <a_int> TOK_number
vlme745fcd2006-09-05 16:18:34 +0000134%token <a_int> TOK_number_negative
135%token <a_dbl> TOK_realnumber
vlm2c8c44d2005-03-24 16:22:35 +0000136%token <a_int> TOK_tuple
137%token <a_int> TOK_quadruple
vlmfa67ddc2004-06-03 03:38:44 +0000138%token <tv_str> TOK_typereference
vlm9283dbe2004-08-18 04:59:12 +0000139%token <tv_str> TOK_capitalreference /* "CLASS1" */
vlmfa67ddc2004-06-03 03:38:44 +0000140%token <tv_str> TOK_typefieldreference /* "&Pork" */
141%token <tv_str> TOK_valuefieldreference /* "&id" */
vlm808411d2006-03-14 16:31:37 +0000142%token <tv_str> TOK_Literal /* "BY" */
vlmfa67ddc2004-06-03 03:38:44 +0000143
144/*
145 * Token types representing ASN.1 standard keywords.
146 */
147%token TOK_ABSENT
148%token TOK_ABSTRACT_SYNTAX
149%token TOK_ALL
150%token TOK_ANY
151%token TOK_APPLICATION
152%token TOK_AUTOMATIC
153%token TOK_BEGIN
154%token TOK_BIT
155%token TOK_BMPString
156%token TOK_BOOLEAN
157%token TOK_BY
158%token TOK_CHARACTER
159%token TOK_CHOICE
160%token TOK_CLASS
161%token TOK_COMPONENT
162%token TOK_COMPONENTS
163%token TOK_CONSTRAINED
164%token TOK_CONTAINING
165%token TOK_DEFAULT
166%token TOK_DEFINITIONS
167%token TOK_DEFINED
168%token TOK_EMBEDDED
169%token TOK_ENCODED
vlm9283dbe2004-08-18 04:59:12 +0000170%token TOK_ENCODING_CONTROL
vlmfa67ddc2004-06-03 03:38:44 +0000171%token TOK_END
172%token TOK_ENUMERATED
173%token TOK_EXPLICIT
174%token TOK_EXPORTS
175%token TOK_EXTENSIBILITY
176%token TOK_EXTERNAL
177%token TOK_FALSE
178%token TOK_FROM
179%token TOK_GeneralizedTime
180%token TOK_GeneralString
181%token TOK_GraphicString
182%token TOK_IA5String
183%token TOK_IDENTIFIER
184%token TOK_IMPLICIT
185%token TOK_IMPLIED
186%token TOK_IMPORTS
187%token TOK_INCLUDES
188%token TOK_INSTANCE
vlm9283dbe2004-08-18 04:59:12 +0000189%token TOK_INSTRUCTIONS
vlmfa67ddc2004-06-03 03:38:44 +0000190%token TOK_INTEGER
191%token TOK_ISO646String
192%token TOK_MAX
193%token TOK_MIN
194%token TOK_MINUS_INFINITY
195%token TOK_NULL
196%token TOK_NumericString
197%token TOK_OBJECT
198%token TOK_ObjectDescriptor
199%token TOK_OCTET
200%token TOK_OF
201%token TOK_OPTIONAL
202%token TOK_PATTERN
203%token TOK_PDV
204%token TOK_PLUS_INFINITY
205%token TOK_PRESENT
206%token TOK_PrintableString
207%token TOK_PRIVATE
208%token TOK_REAL
209%token TOK_RELATIVE_OID
210%token TOK_SEQUENCE
211%token TOK_SET
212%token TOK_SIZE
213%token TOK_STRING
214%token TOK_SYNTAX
215%token TOK_T61String
216%token TOK_TAGS
217%token TOK_TeletexString
218%token TOK_TRUE
219%token TOK_TYPE_IDENTIFIER
220%token TOK_UNIQUE
221%token TOK_UNIVERSAL
222%token TOK_UniversalString
223%token TOK_UTCTime
224%token TOK_UTF8String
225%token TOK_VideotexString
226%token TOK_VisibleString
227%token TOK_WITH
228
vlm1bc782f2006-09-21 01:50:37 +0000229%nonassoc TOK_EXCEPT
vlm9283dbe2004-08-18 04:59:12 +0000230%left '^' TOK_INTERSECTION
231%left '|' TOK_UNION
vlmfa67ddc2004-06-03 03:38:44 +0000232
233/* Misc tags */
234%token TOK_TwoDots /* .. */
235%token TOK_ThreeDots /* ... */
vlmfa67ddc2004-06-03 03:38:44 +0000236
237
238/*
239 * Types defined herein.
240 */
241%type <a_grammar> ModuleList
vlmd3420d32006-09-14 10:35:20 +0000242%type <a_module> ModuleDefinition
243%type <a_module> ModuleBody
244%type <a_module> AssignmentList
245%type <a_module> Assignment
246%type <a_module> optModuleBody /* Optional */
247%type <a_module_flags> optModuleDefinitionFlags
248%type <a_module_flags> ModuleDefinitionFlags /* Set of FL */
249%type <a_module_flags> ModuleDefinitionFlag /* Single FL */
250%type <a_module> optImports
251%type <a_module> optExports
vlmfa67ddc2004-06-03 03:38:44 +0000252%type <a_module> ImportsDefinition
253%type <a_module> ImportsBundleSet
254%type <a_xports> ImportsBundle
255%type <a_xports> ImportsList
256%type <a_xports> ExportsDefinition
257%type <a_xports> ExportsBody
258%type <a_expr> ImportsElement
259%type <a_expr> ExportsElement
vlmfa67ddc2004-06-03 03:38:44 +0000260%type <a_expr> ExtensionAndException
vlm43c8ac52006-09-17 04:52:50 +0000261%type <a_expr> Type
vlmec8f6812004-08-22 03:19:54 +0000262%type <a_expr> TypeDeclaration
vlm066dc102005-08-22 12:23:54 +0000263%type <a_expr> TypeDeclarationSet
vlmfa67ddc2004-06-03 03:38:44 +0000264%type <a_ref> ComplexTypeReference
265%type <a_ref> ComplexTypeReferenceAmpList
266%type <a_refcomp> ComplexTypeReferenceElement
vlma6a84d72006-03-16 10:03:35 +0000267%type <a_refcomp> PrimitiveFieldReference
vlmdc7cf042006-03-09 08:49:26 +0000268%type <a_expr> FieldSpec
269%type <a_ref> FieldName
270%type <a_ref> DefinedObjectClass
vlmfa67ddc2004-06-03 03:38:44 +0000271%type <a_expr> ClassField
vlmdc7cf042006-03-09 08:49:26 +0000272%type <a_expr> ObjectClass
vlmfa67ddc2004-06-03 03:38:44 +0000273%type <a_expr> DataTypeReference /* Type1 ::= Type2 */
vlm17e65d02006-03-21 04:48:15 +0000274%type <a_expr> DefinedType
vlm59b620a2006-03-21 07:46:48 +0000275%type <a_constr> ValueSet /* {a|b|c}*/
276%type <a_expr> ValueSetTypeAssignment /* Val INTEGER ::= {1|2} */
vlmfa67ddc2004-06-03 03:38:44 +0000277%type <a_expr> ValueDefinition /* val INTEGER ::= 1*/
vlmc94e28f2004-09-15 11:59:51 +0000278%type <a_value> Value
vlm17e65d02006-03-21 04:48:15 +0000279%type <a_value> SimpleValue
vlmfa67ddc2004-06-03 03:38:44 +0000280%type <a_value> DefinedValue
281%type <a_value> SignedNumber
vlme745fcd2006-09-05 16:18:34 +0000282%type <a_value> RealValue
vlm0aa86902004-10-12 23:26:53 +0000283%type <a_expr> optComponentTypeLists
vlmec8f6812004-08-22 03:19:54 +0000284%type <a_expr> ComponentTypeLists
285%type <a_expr> ComponentType
286%type <a_expr> AlternativeTypeLists
287%type <a_expr> AlternativeType
vlmfa67ddc2004-06-03 03:38:44 +0000288%type <a_expr> UniverationDefinition
289%type <a_expr> UniverationList
290%type <a_expr> UniverationElement
291%type <tv_str> TypeRefName
292%type <tv_str> ObjectClassReference
vlmfa67ddc2004-06-03 03:38:44 +0000293%type <tv_str> Identifier
vlm151c0b22004-09-22 16:03:36 +0000294%type <tv_str> optIdentifier
vlmfa67ddc2004-06-03 03:38:44 +0000295%type <a_parg> ParameterArgumentName
296%type <a_plist> ParameterArgumentList
vlmdfbff8c2006-03-21 09:41:28 +0000297%type <a_expr> ActualParameter
298%type <a_expr> ActualParameterList
vlm04a08da2005-08-12 10:06:17 +0000299%type <a_aid> AssignedIdentifier /* OID/DefinedValue */
vlmfa67ddc2004-06-03 03:38:44 +0000300%type <a_oid> ObjectIdentifier /* OID */
301%type <a_oid> optObjectIdentifier /* Optional OID */
302%type <a_oid> ObjectIdentifierBody
303%type <a_oid_arc> ObjectIdentifierElement
304%type <a_expr> BasicType
305%type <a_type> BasicTypeId
306%type <a_type> BasicTypeId_UniverationCompatible
307%type <a_type> BasicString
308%type <tv_opaque> Opaque
vlm2728a8d2005-01-23 09:51:44 +0000309%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
310%type <a_tag> TagClass TagTypeValue TagPlicit
vlmfa67ddc2004-06-03 03:38:44 +0000311%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
312%type <a_constr> optConstraints
vlm43c8ac52006-09-17 04:52:50 +0000313%type <a_constr> Constraint
314%type <a_constr> SubtypeConstraint
315%type <a_constr> GeneralConstraint
vlm9283dbe2004-08-18 04:59:12 +0000316%type <a_constr> SetOfConstraints
317%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
318%type <a_constr> ElementSetSpec /* 1..2,...,3 */
vlm1bc782f2006-09-21 01:50:37 +0000319%type <a_constr> Unions
320%type <a_constr> Intersections
321%type <a_constr> IntersectionElements
vlmfa67ddc2004-06-03 03:38:44 +0000322%type <a_constr> ConstraintSubtypeElement /* 1..2 */
vlmfa67ddc2004-06-03 03:38:44 +0000323%type <a_constr> SimpleTableConstraint
vlm43c8ac52006-09-17 04:52:50 +0000324%type <a_constr> UserDefinedConstraint
vlmfa67ddc2004-06-03 03:38:44 +0000325%type <a_constr> TableConstraint
vlm43c8ac52006-09-17 04:52:50 +0000326%type <a_constr> ContentsConstraint
vlm7bbdc9f2005-03-28 15:01:27 +0000327%type <a_constr> InnerTypeConstraint
vlmfa67ddc2004-06-03 03:38:44 +0000328%type <a_constr> WithComponentsList
329%type <a_constr> WithComponentsElement
330%type <a_constr> ComponentRelationConstraint
331%type <a_constr> AtNotationList
332%type <a_ref> AtNotationElement
vlma6a12e32005-03-20 12:58:00 +0000333%type <a_value> SingleValue
334%type <a_value> ContainedSubtype
vlmfa67ddc2004-06-03 03:38:44 +0000335%type <a_ctype> ConstraintSpec
336%type <a_ctype> ConstraintRangeSpec
vlme1e6ed82005-03-24 14:26:38 +0000337%type <a_value> RestrictedCharacterStringValue
vlmfa67ddc2004-06-03 03:38:44 +0000338%type <a_wsynt> optWithSyntax
339%type <a_wsynt> WithSyntax
vlm808411d2006-03-14 16:31:37 +0000340%type <a_wsynt> WithSyntaxList
341%type <a_wchunk> WithSyntaxToken
vlmfa67ddc2004-06-03 03:38:44 +0000342%type <a_marker> optMarker Marker
343%type <a_int> optUnique
344%type <a_pres> optPresenceConstraint PresenceConstraint
345%type <tv_str> ComponentIdList
vlm177a5b62005-09-05 05:17:57 +0000346%type <a_int> NSTD_IndirectMarker
vlmfa67ddc2004-06-03 03:38:44 +0000347
348
349%%
350
351
352ParsedGrammar:
353 ModuleList {
354 *(void **)param = $1;
355 }
356 ;
357
358ModuleList:
vlmd3420d32006-09-14 10:35:20 +0000359 ModuleDefinition {
vlmfa67ddc2004-06-03 03:38:44 +0000360 $$ = asn1p_new();
361 checkmem($$);
362 TQ_ADD(&($$->modules), $1, mod_next);
363 }
vlmd3420d32006-09-14 10:35:20 +0000364 | ModuleList ModuleDefinition {
vlmfa67ddc2004-06-03 03:38:44 +0000365 $$ = $1;
366 TQ_ADD(&($$->modules), $2, mod_next);
367 }
368 ;
369
370/*
371 * ASN module definition.
372 * === EXAMPLE ===
373 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
374 * BEGIN
375 * ...
376 * END
377 * === EOF ===
378 */
379
vlmd3420d32006-09-14 10:35:20 +0000380ModuleDefinition:
vlm43c8ac52006-09-17 04:52:50 +0000381 TypeRefName { currentModule = asn1p_module_new(); }
382 optObjectIdentifier TOK_DEFINITIONS
vlmd3420d32006-09-14 10:35:20 +0000383 optModuleDefinitionFlags
vlmfa67ddc2004-06-03 03:38:44 +0000384 TOK_PPEQ TOK_BEGIN
vlmd3420d32006-09-14 10:35:20 +0000385 optModuleBody
vlmfa67ddc2004-06-03 03:38:44 +0000386 TOK_END {
387
vlm43c8ac52006-09-17 04:52:50 +0000388 $$ = currentModule;
389
390 if($8) {
391 asn1p_module_t tmp = *($$);
392 *($$) = *($8);
393 *($8) = tmp;
394 asn1p_module_free($8);
vlmfa67ddc2004-06-03 03:38:44 +0000395 } else {
396 /* There's a chance that a module is just plain empty */
vlmfa67ddc2004-06-03 03:38:44 +0000397 }
vlmfa67ddc2004-06-03 03:38:44 +0000398
vlm04a08da2005-08-12 10:06:17 +0000399 $$->ModuleName = $1;
vlm43c8ac52006-09-17 04:52:50 +0000400 $$->module_oid = $3;
401 $$->module_flags = $5;
vlmfa67ddc2004-06-03 03:38:44 +0000402 }
403 ;
404
405/*
406 * Object Identifier Definition
407 * { iso member-body(2) 3 }
408 */
409optObjectIdentifier:
410 { $$ = 0; }
411 | ObjectIdentifier { $$ = $1; }
412 ;
413
414ObjectIdentifier:
415 '{' ObjectIdentifierBody '}' {
416 $$ = $2;
417 }
418 | '{' '}' {
419 $$ = 0;
420 }
421 ;
422
423ObjectIdentifierBody:
424 ObjectIdentifierElement {
425 $$ = asn1p_oid_new();
426 asn1p_oid_add_arc($$, &$1);
427 if($1.name)
428 free($1.name);
429 }
430 | ObjectIdentifierBody ObjectIdentifierElement {
431 $$ = $1;
432 asn1p_oid_add_arc($$, &$2);
433 if($2.name)
434 free($2.name);
435 }
436 ;
437
438ObjectIdentifierElement:
439 Identifier { /* iso */
440 $$.name = $1;
441 $$.number = -1;
442 }
443 | Identifier '(' TOK_number ')' { /* iso(1) */
444 $$.name = $1;
445 $$.number = $3;
446 }
447 | TOK_number { /* 1 */
448 $$.name = 0;
449 $$.number = $1;
450 }
451 ;
452
453/*
454 * Optional module flags.
455 */
vlmd3420d32006-09-14 10:35:20 +0000456optModuleDefinitionFlags:
vlmfa67ddc2004-06-03 03:38:44 +0000457 { $$ = MSF_NOFLAGS; }
vlmd3420d32006-09-14 10:35:20 +0000458 | ModuleDefinitionFlags {
vlmfa67ddc2004-06-03 03:38:44 +0000459 $$ = $1;
460 }
461 ;
462
463/*
464 * Module flags.
465 */
vlmd3420d32006-09-14 10:35:20 +0000466ModuleDefinitionFlags:
467 ModuleDefinitionFlag {
vlmfa67ddc2004-06-03 03:38:44 +0000468 $$ = $1;
469 }
vlmd3420d32006-09-14 10:35:20 +0000470 | ModuleDefinitionFlags ModuleDefinitionFlag {
vlmfa67ddc2004-06-03 03:38:44 +0000471 $$ = $1 | $2;
472 }
473 ;
474
475/*
476 * Single module flag.
477 */
vlmd3420d32006-09-14 10:35:20 +0000478ModuleDefinitionFlag:
vlmfa67ddc2004-06-03 03:38:44 +0000479 TOK_EXPLICIT TOK_TAGS {
480 $$ = MSF_EXPLICIT_TAGS;
481 }
482 | TOK_IMPLICIT TOK_TAGS {
483 $$ = MSF_IMPLICIT_TAGS;
484 }
485 | TOK_AUTOMATIC TOK_TAGS {
486 $$ = MSF_AUTOMATIC_TAGS;
487 }
488 | TOK_EXTENSIBILITY TOK_IMPLIED {
489 $$ = MSF_EXTENSIBILITY_IMPLIED;
490 }
vlm9283dbe2004-08-18 04:59:12 +0000491 /* EncodingReferenceDefault */
492 | TOK_capitalreference TOK_INSTRUCTIONS {
493 /* X.680Amd1 specifies TAG and XER */
494 if(strcmp($1, "TAG") == 0) {
495 $$ = MSF_TAG_INSTRUCTIONS;
496 } else if(strcmp($1, "XER") == 0) {
497 $$ = MSF_XER_INSTRUCTIONS;
498 } else {
499 fprintf(stderr,
500 "WARNING: %s INSTRUCTIONS at line %d: "
501 "Unrecognized encoding reference\n",
502 $1, yylineno);
503 $$ = MSF_unk_INSTRUCTIONS;
504 }
505 free($1);
506 }
vlmfa67ddc2004-06-03 03:38:44 +0000507 ;
508
509/*
510 * Optional module body.
511 */
vlmd3420d32006-09-14 10:35:20 +0000512optModuleBody:
vlmfa67ddc2004-06-03 03:38:44 +0000513 { $$ = 0; }
vlmd3420d32006-09-14 10:35:20 +0000514 | ModuleBody {
vlmfa67ddc2004-06-03 03:38:44 +0000515 $$ = $1;
516 }
517 ;
518
519/*
520 * ASN.1 Module body.
521 */
vlmd3420d32006-09-14 10:35:20 +0000522ModuleBody:
523 optExports optImports AssignmentList {
524 $$ = asn1p_module_new();
525 AL_IMPORT($$, exports, $1, xp_next);
526 AL_IMPORT($$, imports, $2, xp_next);
527 AL_IMPORT($$, members, $3, next);
vlmfa67ddc2004-06-03 03:38:44 +0000528 }
529 ;
530
vlmd3420d32006-09-14 10:35:20 +0000531AssignmentList:
532 Assignment {
533 $$ = $1;
534 }
535 | AssignmentList Assignment {
536 if($1) {
537 $$ = $1;
538 } else {
539 $$ = $2;
540 break;
541 }
542 AL_IMPORT($$, members, $2, next);
543 }
544 ;
545
546
vlmfa67ddc2004-06-03 03:38:44 +0000547/*
548 * One of the elements of ASN.1 module specification.
549 */
vlmd3420d32006-09-14 10:35:20 +0000550Assignment:
551 DataTypeReference {
vlmfa67ddc2004-06-03 03:38:44 +0000552 $$ = asn1p_module_new();
553 checkmem($$);
554 assert($1->expr_type != A1TC_INVALID);
555 assert($1->meta_type != AMT_INVALID);
556 TQ_ADD(&($$->members), $1, next);
557 }
558 | ValueDefinition {
559 $$ = 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 }
565 /*
566 * Value set definition
567 * === EXAMPLE ===
568 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
569 * === EOF ===
570 */
vlm59b620a2006-03-21 07:46:48 +0000571 | ValueSetTypeAssignment {
vlmfa67ddc2004-06-03 03:38:44 +0000572 $$ = asn1p_module_new();
573 checkmem($$);
574 assert($1->expr_type != A1TC_INVALID);
575 assert($1->meta_type != AMT_INVALID);
576 TQ_ADD(&($$->members), $1, next);
577 }
vlm9283dbe2004-08-18 04:59:12 +0000578 | TOK_ENCODING_CONTROL TOK_capitalreference
579 { asn1p_lexer_hack_push_encoding_control(); }
580 {
581 fprintf(stderr,
582 "WARNING: ENCODING-CONTROL %s "
583 "specification at line %d ignored\n",
584 $2, yylineno);
585 free($2);
586 $$ = 0;
587 }
vlmfa67ddc2004-06-03 03:38:44 +0000588
589 /*
590 * Erroneous attemps
591 */
592 | BasicString {
593 return yyerror(
vlm1ac75e72005-11-26 11:21:55 +0000594 "Attempt to redefine a standard basic string type, "
595 "please comment out or remove this type redefinition.");
vlmfa67ddc2004-06-03 03:38:44 +0000596 }
597 ;
598
599/*
600 * === EXAMPLE ===
601 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
602 * === EOF ===
603 */
vlmd3420d32006-09-14 10:35:20 +0000604optImports:
605 { $$ = 0; }
606 | ImportsDefinition;
607
vlmfa67ddc2004-06-03 03:38:44 +0000608ImportsDefinition:
609 TOK_IMPORTS ImportsBundleSet ';' {
vlm04a08da2005-08-12 10:06:17 +0000610 if(!saved_aid && 0)
611 return yyerror("Unterminated IMPORTS FROM, "
612 "expected semicolon ';'");
613 saved_aid = 0;
vlmfa67ddc2004-06-03 03:38:44 +0000614 $$ = $2;
615 }
616 /*
617 * Some error cases.
618 */
619 | TOK_IMPORTS TOK_FROM /* ... */ {
620 return yyerror("Empty IMPORTS list");
621 }
622 ;
623
624ImportsBundleSet:
625 ImportsBundle {
626 $$ = asn1p_module_new();
627 checkmem($$);
628 TQ_ADD(&($$->imports), $1, xp_next);
629 }
630 | ImportsBundleSet ImportsBundle {
631 $$ = $1;
632 TQ_ADD(&($$->imports), $2, xp_next);
633 }
634 ;
635
vlm04a08da2005-08-12 10:06:17 +0000636AssignedIdentifier:
637 { memset(&$$, 0, sizeof($$)); }
638 | ObjectIdentifier { $$.oid = $1; };
639 /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
640
vlmfa67ddc2004-06-03 03:38:44 +0000641ImportsBundle:
vlm04a08da2005-08-12 10:06:17 +0000642 ImportsList TOK_FROM TypeRefName AssignedIdentifier {
vlmfa67ddc2004-06-03 03:38:44 +0000643 $$ = $1;
vlm04a08da2005-08-12 10:06:17 +0000644 $$->fromModuleName = $3;
645 $$->identifier = $4;
646 /* This stupid thing is used for look-back hack. */
647 saved_aid = $$->identifier.oid ? 0 : &($$->identifier);
vlmfa67ddc2004-06-03 03:38:44 +0000648 checkmem($$);
649 }
650 ;
651
652ImportsList:
653 ImportsElement {
654 $$ = asn1p_xports_new();
655 checkmem($$);
656 TQ_ADD(&($$->members), $1, next);
657 }
658 | ImportsList ',' ImportsElement {
659 $$ = $1;
660 TQ_ADD(&($$->members), $3, next);
661 }
662 ;
663
664ImportsElement:
665 TypeRefName {
vlm43c8ac52006-09-17 04:52:50 +0000666 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000667 checkmem($$);
668 $$->Identifier = $1;
669 $$->expr_type = A1TC_REFERENCE;
670 }
vlm0aa86902004-10-12 23:26:53 +0000671 | TypeRefName '{' '}' { /* Completely equivalent to above */
vlm43c8ac52006-09-17 04:52:50 +0000672 $$ = NEW_EXPR();
vlm0aa86902004-10-12 23:26:53 +0000673 checkmem($$);
674 $$->Identifier = $1;
675 $$->expr_type = A1TC_REFERENCE;
676 }
vlmfa67ddc2004-06-03 03:38:44 +0000677 | Identifier {
vlm43c8ac52006-09-17 04:52:50 +0000678 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000679 checkmem($$);
680 $$->Identifier = $1;
681 $$->expr_type = A1TC_REFERENCE;
682 }
683 ;
684
vlmd3420d32006-09-14 10:35:20 +0000685
686optExports:
687 { $$ = 0; }
688 | ExportsDefinition {
689 $$ = asn1p_module_new();
690 checkmem($$);
691 if($1) {
692 TQ_ADD(&($$->exports), $1, xp_next);
693 } else {
694 /* "EXPORTS ALL;" */
695 }
696 }
697 ;
698
vlmfa67ddc2004-06-03 03:38:44 +0000699ExportsDefinition:
700 TOK_EXPORTS ExportsBody ';' {
701 $$ = $2;
702 }
703 | TOK_EXPORTS TOK_ALL ';' {
704 $$ = 0;
705 }
706 | TOK_EXPORTS ';' {
707 /* Empty EXPORTS clause effectively prohibits export. */
708 $$ = asn1p_xports_new();
709 checkmem($$);
710 }
711 ;
712
713ExportsBody:
714 ExportsElement {
715 $$ = asn1p_xports_new();
716 assert($$);
717 TQ_ADD(&($$->members), $1, next);
718 }
719 | ExportsBody ',' ExportsElement {
720 $$ = $1;
721 TQ_ADD(&($$->members), $3, next);
722 }
723 ;
724
725ExportsElement:
726 TypeRefName {
vlm43c8ac52006-09-17 04:52:50 +0000727 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000728 checkmem($$);
729 $$->Identifier = $1;
730 $$->expr_type = A1TC_EXPORTVAR;
731 }
vlm0aa86902004-10-12 23:26:53 +0000732 | TypeRefName '{' '}' {
vlm43c8ac52006-09-17 04:52:50 +0000733 $$ = NEW_EXPR();
vlm0aa86902004-10-12 23:26:53 +0000734 checkmem($$);
735 $$->Identifier = $1;
736 $$->expr_type = A1TC_EXPORTVAR;
737 }
vlmfa67ddc2004-06-03 03:38:44 +0000738 | Identifier {
vlm43c8ac52006-09-17 04:52:50 +0000739 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000740 checkmem($$);
741 $$->Identifier = $1;
742 $$->expr_type = A1TC_EXPORTVAR;
743 }
744 ;
745
746
vlm1aeaddd2006-07-13 08:24:20 +0000747ValueSet: '{' ElementSetSpecs '}' { $$ = $2; };
vlm59b620a2006-03-21 07:46:48 +0000748
749ValueSetTypeAssignment:
750 TypeRefName DefinedType TOK_PPEQ ValueSet {
vlmfa67ddc2004-06-03 03:38:44 +0000751 $$ = $2;
752 assert($$->Identifier == 0);
753 $$->Identifier = $1;
754 $$->meta_type = AMT_VALUESET;
vlm59b620a2006-03-21 07:46:48 +0000755 $$->constraints = $4;
vlmfa67ddc2004-06-03 03:38:44 +0000756 }
757 ;
758
vlm17e65d02006-03-21 04:48:15 +0000759DefinedType:
760 BasicType {
761 $$ = $1;
762 }
763 /*
764 * A DefinedType reference.
765 * "CLASS1.&id.&id2"
766 * or
767 * "Module.Type"
768 * or
769 * "Module.identifier"
770 * or
771 * "Type"
772 */
773 | ComplexTypeReference {
vlm43c8ac52006-09-17 04:52:50 +0000774 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000775 checkmem($$);
776 $$->reference = $1;
777 $$->expr_type = A1TC_REFERENCE;
778 $$->meta_type = AMT_TYPEREF;
779 }
vlm17e65d02006-03-21 04:48:15 +0000780 /*
vlmdfbff8c2006-03-21 09:41:28 +0000781 * A parameterized assignment.
vlm17e65d02006-03-21 04:48:15 +0000782 */
vlmdfbff8c2006-03-21 09:41:28 +0000783 | ComplexTypeReference '{' ActualParameterList '}' {
vlm43c8ac52006-09-17 04:52:50 +0000784 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000785 checkmem($$);
vlm17e65d02006-03-21 04:48:15 +0000786 $$->reference = $1;
787 $$->rhs_pspecs = $3;
788 $$->expr_type = A1TC_REFERENCE;
789 $$->meta_type = AMT_TYPEREF;
vlmfa67ddc2004-06-03 03:38:44 +0000790 }
791 ;
792
vlmfa67ddc2004-06-03 03:38:44 +0000793/*
794 * Data Type Reference.
795 * === EXAMPLE ===
796 * Type3 ::= CHOICE { a Type1, b Type 2 }
797 * === EOF ===
798 */
vlmfa67ddc2004-06-03 03:38:44 +0000799DataTypeReference:
800 /*
801 * Optionally tagged type definition.
802 */
vlmdc7cf042006-03-09 08:49:26 +0000803 TypeRefName TOK_PPEQ Type {
vlmfce48a42004-09-14 02:36:39 +0000804 $$ = $3;
vlmfa67ddc2004-06-03 03:38:44 +0000805 $$->Identifier = $1;
vlmfa67ddc2004-06-03 03:38:44 +0000806 assert($$->expr_type);
807 assert($$->meta_type);
808 }
vlmdc7cf042006-03-09 08:49:26 +0000809 | TypeRefName TOK_PPEQ ObjectClass {
vlmfa67ddc2004-06-03 03:38:44 +0000810 $$ = $3;
811 $$->Identifier = $1;
812 assert($$->expr_type == A1TC_CLASSDEF);
vlmdc7cf042006-03-09 08:49:26 +0000813 assert($$->meta_type == AMT_OBJECTCLASS);
vlmfa67ddc2004-06-03 03:38:44 +0000814 }
815 /*
vlmdfbff8c2006-03-21 09:41:28 +0000816 * Parameterized <Type> declaration:
vlmfa67ddc2004-06-03 03:38:44 +0000817 * === EXAMPLE ===
818 * SIGNED { ToBeSigned } ::= SEQUENCE {
819 * toBeSigned ToBeSigned,
820 * algorithm AlgorithmIdentifier,
821 * signature BIT STRING
822 * }
823 * === EOF ===
824 */
vlmec8f6812004-08-22 03:19:54 +0000825 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
vlmfa67ddc2004-06-03 03:38:44 +0000826 $$ = $6;
vlmdfbff8c2006-03-21 09:41:28 +0000827 $$->Identifier = $1;
828 $$->lhs_params = $3;
829 }
830 /* Parameterized CLASS declaration */
831 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ ObjectClass {
832 $$ = $6;
vlmfa67ddc2004-06-03 03:38:44 +0000833 $$->Identifier = $1;
vlm0c6d3812006-03-21 03:40:38 +0000834 $$->lhs_params = $3;
vlmfa67ddc2004-06-03 03:38:44 +0000835 }
836 ;
837
838ParameterArgumentList:
839 ParameterArgumentName {
840 int ret;
841 $$ = asn1p_paramlist_new(yylineno);
842 checkmem($$);
843 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
844 checkmem(ret == 0);
845 if($1.governor) asn1p_ref_free($1.governor);
846 if($1.argument) free($1.argument);
847 }
848 | ParameterArgumentList ',' ParameterArgumentName {
849 int ret;
850 $$ = $1;
851 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
852 checkmem(ret == 0);
853 if($3.governor) asn1p_ref_free($3.governor);
854 if($3.argument) free($3.argument);
855 }
856 ;
857
858ParameterArgumentName:
859 TypeRefName {
860 $$.governor = NULL;
861 $$.argument = $1;
862 }
863 | TypeRefName ':' Identifier {
864 int ret;
865 $$.governor = asn1p_ref_new(yylineno);
866 ret = asn1p_ref_add_component($$.governor, $1, 0);
867 checkmem(ret == 0);
868 $$.argument = $3;
869 }
vlm4053ca52005-02-18 16:34:21 +0000870 | TypeRefName ':' TypeRefName {
871 int ret;
872 $$.governor = asn1p_ref_new(yylineno);
873 ret = asn1p_ref_add_component($$.governor, $1, 0);
874 checkmem(ret == 0);
875 $$.argument = $3;
876 }
vlmfa67ddc2004-06-03 03:38:44 +0000877 | BasicTypeId ':' Identifier {
878 int ret;
879 $$.governor = asn1p_ref_new(yylineno);
880 ret = asn1p_ref_add_component($$.governor,
881 ASN_EXPR_TYPE2STR($1), 1);
882 checkmem(ret == 0);
883 $$.argument = $3;
884 }
vlmdfbff8c2006-03-21 09:41:28 +0000885 | BasicTypeId ':' TypeRefName {
886 int ret;
887 $$.governor = asn1p_ref_new(yylineno);
888 ret = asn1p_ref_add_component($$.governor,
889 ASN_EXPR_TYPE2STR($1), 1);
890 checkmem(ret == 0);
891 $$.argument = $3;
892 }
vlmfa67ddc2004-06-03 03:38:44 +0000893 ;
894
vlmdfbff8c2006-03-21 09:41:28 +0000895ActualParameterList:
896 ActualParameter {
vlm43c8ac52006-09-17 04:52:50 +0000897 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000898 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000899 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000900 }
vlmdfbff8c2006-03-21 09:41:28 +0000901 | ActualParameterList ',' ActualParameter {
vlmfa67ddc2004-06-03 03:38:44 +0000902 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000903 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000904 }
905 ;
906
vlmdfbff8c2006-03-21 09:41:28 +0000907ActualParameter:
vlmec8f6812004-08-22 03:19:54 +0000908 Type {
vlmfa67ddc2004-06-03 03:38:44 +0000909 $$ = $1;
910 }
vlm17e65d02006-03-21 04:48:15 +0000911 | SimpleValue {
vlm43c8ac52006-09-17 04:52:50 +0000912 $$ = NEW_EXPR();
vlm17e65d02006-03-21 04:48:15 +0000913 checkmem($$);
914 $$->Identifier = "?";
915 $$->expr_type = A1TC_REFERENCE;
916 $$->meta_type = AMT_VALUE;
917 $$->value = $1;
918 }
vlmfa67ddc2004-06-03 03:38:44 +0000919 | Identifier {
vlm0c6d3812006-03-21 03:40:38 +0000920 asn1p_ref_t *ref;
vlm43c8ac52006-09-17 04:52:50 +0000921 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000922 checkmem($$);
923 $$->Identifier = $1;
924 $$->expr_type = A1TC_REFERENCE;
925 $$->meta_type = AMT_VALUE;
vlm0c6d3812006-03-21 03:40:38 +0000926 ref = asn1p_ref_new(yylineno);
927 asn1p_ref_add_component(ref, $1, RLT_lowercase);
928 $$->value = asn1p_value_fromref(ref, 0);
vlmfa67ddc2004-06-03 03:38:44 +0000929 }
vlmdfbff8c2006-03-21 09:41:28 +0000930 | ValueSet {
vlm43c8ac52006-09-17 04:52:50 +0000931 $$ = NEW_EXPR();
vlmdfbff8c2006-03-21 09:41:28 +0000932 $$->expr_type = A1TC_VALUESET;
933 $$->meta_type = AMT_VALUESET;
934 $$->constraints = $1;
935 }
vlmfa67ddc2004-06-03 03:38:44 +0000936 ;
937
938/*
vlmdfbff8c2006-03-21 09:41:28 +0000939 | '{' ActualParameter '}' {
vlm43c8ac52006-09-17 04:52:50 +0000940 $$ = NEW_EXPR();
vlm4053ca52005-02-18 16:34:21 +0000941 checkmem($$);
942 asn1p_expr_add($$, $2);
943 $$->expr_type = A1TC_PARAMETRIZED;
944 $$->meta_type = AMT_TYPE;
945 }
946 ;
947*/
948
949/*
vlmfa67ddc2004-06-03 03:38:44 +0000950 * A collection of constructed data type members.
951 */
vlm0aa86902004-10-12 23:26:53 +0000952optComponentTypeLists:
vlm43c8ac52006-09-17 04:52:50 +0000953 { $$ = NEW_EXPR(); }
vlm0aa86902004-10-12 23:26:53 +0000954 | ComponentTypeLists { $$ = $1; };
955
vlmec8f6812004-08-22 03:19:54 +0000956ComponentTypeLists:
957 ComponentType {
vlm43c8ac52006-09-17 04:52:50 +0000958 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000959 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000960 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000961 }
vlmec8f6812004-08-22 03:19:54 +0000962 | ComponentTypeLists ',' ComponentType {
vlmfa67ddc2004-06-03 03:38:44 +0000963 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000964 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000965 }
966 ;
967
vlmec8f6812004-08-22 03:19:54 +0000968ComponentType:
vlmfce48a42004-09-14 02:36:39 +0000969 Identifier Type optMarker {
vlmec8f6812004-08-22 03:19:54 +0000970 $$ = $2;
971 assert($$->Identifier == 0);
vlmfce48a42004-09-14 02:36:39 +0000972 $$->Identifier = $1;
vlm177a5b62005-09-05 05:17:57 +0000973 $3.flags |= $$->marker.flags;
vlmec8f6812004-08-22 03:19:54 +0000974 $$->marker = $3;
975 }
vlm177a5b62005-09-05 05:17:57 +0000976 | Type optMarker {
977 $$ = $1;
978 $2.flags |= $$->marker.flags;
979 $$->marker = $2;
980 _fixup_anonymous_identifier($$);
981 }
vlmec8f6812004-08-22 03:19:54 +0000982 | TOK_COMPONENTS TOK_OF Type {
vlm43c8ac52006-09-17 04:52:50 +0000983 $$ = NEW_EXPR();
vlmec8f6812004-08-22 03:19:54 +0000984 checkmem($$);
985 $$->meta_type = $3->meta_type;
986 $$->expr_type = A1TC_COMPONENTS_OF;
vlm6a02a8a2004-09-08 00:28:11 +0000987 asn1p_expr_add($$, $3);
vlmec8f6812004-08-22 03:19:54 +0000988 }
989 | ExtensionAndException {
990 $$ = $1;
991 }
992 ;
993
994AlternativeTypeLists:
995 AlternativeType {
vlm43c8ac52006-09-17 04:52:50 +0000996 $$ = NEW_EXPR();
vlmec8f6812004-08-22 03:19:54 +0000997 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000998 asn1p_expr_add($$, $1);
vlmec8f6812004-08-22 03:19:54 +0000999 }
1000 | AlternativeTypeLists ',' AlternativeType {
1001 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +00001002 asn1p_expr_add($$, $3);
vlmec8f6812004-08-22 03:19:54 +00001003 }
1004 ;
1005
1006AlternativeType:
vlmfce48a42004-09-14 02:36:39 +00001007 Identifier Type {
vlmec8f6812004-08-22 03:19:54 +00001008 $$ = $2;
1009 assert($$->Identifier == 0);
vlmfce48a42004-09-14 02:36:39 +00001010 $$->Identifier = $1;
vlmec8f6812004-08-22 03:19:54 +00001011 }
1012 | ExtensionAndException {
1013 $$ = $1;
1014 }
vlm5d89c3d2005-08-13 09:07:11 +00001015 | Type {
1016 $$ = $1;
1017 _fixup_anonymous_identifier($$);
1018 }
vlmec8f6812004-08-22 03:19:54 +00001019 ;
1020
vlmdc7cf042006-03-09 08:49:26 +00001021ObjectClass:
1022 TOK_CLASS '{' FieldSpec '}' optWithSyntax {
vlmfa67ddc2004-06-03 03:38:44 +00001023 $$ = $3;
1024 checkmem($$);
1025 $$->with_syntax = $5;
1026 assert($$->expr_type == A1TC_CLASSDEF);
vlmdc7cf042006-03-09 08:49:26 +00001027 assert($$->meta_type == AMT_OBJECTCLASS);
vlmfa67ddc2004-06-03 03:38:44 +00001028 }
1029 ;
1030
1031optUnique:
1032 { $$ = 0; }
1033 | TOK_UNIQUE { $$ = 1; }
1034 ;
1035
vlmdc7cf042006-03-09 08:49:26 +00001036FieldSpec:
vlmfa67ddc2004-06-03 03:38:44 +00001037 ClassField {
vlm43c8ac52006-09-17 04:52:50 +00001038 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001039 checkmem($$);
1040 $$->expr_type = A1TC_CLASSDEF;
vlmdc7cf042006-03-09 08:49:26 +00001041 $$->meta_type = AMT_OBJECTCLASS;
vlm6a02a8a2004-09-08 00:28:11 +00001042 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +00001043 }
vlmdc7cf042006-03-09 08:49:26 +00001044 | FieldSpec ',' ClassField {
vlmfa67ddc2004-06-03 03:38:44 +00001045 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +00001046 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001047 }
1048 ;
1049
vlmdc7cf042006-03-09 08:49:26 +00001050 /* X.681 */
vlmfa67ddc2004-06-03 03:38:44 +00001051ClassField:
vlmdc7cf042006-03-09 08:49:26 +00001052
1053 /* TypeFieldSpec ::= typefieldreference TypeOptionalitySpec? */
1054 TOK_typefieldreference optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001055 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001056 checkmem($$);
vlmdc7cf042006-03-09 08:49:26 +00001057 $$->Identifier = $1;
vlmfa67ddc2004-06-03 03:38:44 +00001058 $$->meta_type = AMT_OBJECTFIELD;
vlmdc7cf042006-03-09 08:49:26 +00001059 $$->expr_type = A1TC_CLASSFIELD_TFS; /* TypeFieldSpec */
vlmfa67ddc2004-06-03 03:38:44 +00001060 $$->marker = $2;
1061 }
vlmdc7cf042006-03-09 08:49:26 +00001062
1063 /* FixedTypeValueFieldSpec ::= valuefieldreference Type UNIQUE ? ValueOptionalitySpec ? */
1064 | TOK_valuefieldreference Type optUnique optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001065 $$ = NEW_EXPR();
vlmdc7cf042006-03-09 08:49:26 +00001066 $$->Identifier = $1;
1067 $$->meta_type = AMT_OBJECTFIELD;
1068 $$->expr_type = A1TC_CLASSFIELD_FTVFS; /* FixedTypeValueFieldSpec */
vlmbde35d42004-11-24 17:43:29 +00001069 $$->unique = $3;
vlmdc7cf042006-03-09 08:49:26 +00001070 $$->marker = $4;
1071 asn1p_expr_add($$, $2);
vlmfa67ddc2004-06-03 03:38:44 +00001072 }
vlmdc7cf042006-03-09 08:49:26 +00001073
1074 /* VariableTypeValueFieldSpec ::= valuefieldreference FieldName ValueOptionalitySpec ? */
1075 | TOK_valuefieldreference FieldName optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001076 $$ = NEW_EXPR();
vlmdc7cf042006-03-09 08:49:26 +00001077 $$->Identifier = $1;
1078 $$->meta_type = AMT_OBJECTFIELD;
1079 $$->expr_type = A1TC_CLASSFIELD_VTVFS;
1080 $$->reference = $2;
1081 $$->marker = $3;
1082 }
1083
vlmdc7cf042006-03-09 08:49:26 +00001084 /* ObjectFieldSpec ::= objectfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1085 | TOK_valuefieldreference DefinedObjectClass optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001086 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001087 checkmem($$);
vlmdc7cf042006-03-09 08:49:26 +00001088 $$->Identifier = $1;
1089 $$->reference = $2;
vlmfa67ddc2004-06-03 03:38:44 +00001090 $$->meta_type = AMT_OBJECTFIELD;
vlmdc7cf042006-03-09 08:49:26 +00001091 $$->expr_type = A1TC_CLASSFIELD_OFS;
1092 $$->marker = $3;
vlmfa67ddc2004-06-03 03:38:44 +00001093 }
vlmdc7cf042006-03-09 08:49:26 +00001094
vlmee7196e2006-03-09 09:08:49 +00001095 /* VariableTypeValueSetFieldSpec ::= valuesetfieldreference FieldName ValueOptionalitySpec ? */
1096 | TOK_typefieldreference FieldName optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001097 $$ = NEW_EXPR();
vlmdc7cf042006-03-09 08:49:26 +00001098 $$->Identifier = $1;
vlmdc7cf042006-03-09 08:49:26 +00001099 $$->meta_type = AMT_OBJECTFIELD;
vlmee7196e2006-03-09 09:08:49 +00001100 $$->expr_type = A1TC_CLASSFIELD_VTVSFS;
1101 $$->reference = $2;
vlmdc7cf042006-03-09 08:49:26 +00001102 $$->marker = $3;
1103 }
1104
1105 /* FixedTypeValueSetFieldSpec ::= valuesetfieldreference Type ValueSetOptionalitySpec ? */
1106 | TOK_typefieldreference Type optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001107 $$ = NEW_EXPR();
vlmdc7cf042006-03-09 08:49:26 +00001108 checkmem($$);
1109 $$->Identifier = $1;
1110 $$->meta_type = AMT_OBJECTFIELD;
1111 $$->expr_type = A1TC_CLASSFIELD_FTVSFS;
1112 asn1p_expr_add($$, $2);
1113 $$->marker = $3;
1114 }
1115
vlmee7196e2006-03-09 09:08:49 +00001116 /* ObjectSetFieldSpec ::= objectsetfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1117 | TOK_typefieldreference DefinedObjectClass optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001118 $$ = NEW_EXPR();
vlmee7196e2006-03-09 09:08:49 +00001119 checkmem($$);
1120 $$->Identifier = $1;
1121 $$->reference = $2;
1122 $$->meta_type = AMT_OBJECTFIELD;
1123 $$->expr_type = A1TC_CLASSFIELD_OSFS;
1124 $$->marker = $3;
1125 }
vlmfa67ddc2004-06-03 03:38:44 +00001126 ;
1127
1128optWithSyntax:
1129 { $$ = 0; }
1130 | WithSyntax {
1131 $$ = $1;
1132 }
1133 ;
1134
1135WithSyntax:
1136 TOK_WITH TOK_SYNTAX '{'
1137 { asn1p_lexer_hack_enable_with_syntax(); }
vlm808411d2006-03-14 16:31:37 +00001138 WithSyntaxList
vlmfa67ddc2004-06-03 03:38:44 +00001139 '}' {
1140 $$ = $5;
1141 }
1142 ;
1143
vlm808411d2006-03-14 16:31:37 +00001144WithSyntaxList:
1145 WithSyntaxToken {
vlmfa67ddc2004-06-03 03:38:44 +00001146 $$ = asn1p_wsyntx_new();
1147 TQ_ADD(&($$->chunks), $1, next);
1148 }
vlm808411d2006-03-14 16:31:37 +00001149 | WithSyntaxList WithSyntaxToken {
vlmfa67ddc2004-06-03 03:38:44 +00001150 $$ = $1;
1151 TQ_ADD(&($$->chunks), $2, next);
1152 }
1153 ;
1154
vlm808411d2006-03-14 16:31:37 +00001155WithSyntaxToken:
vlmeeb3c512006-03-16 05:11:14 +00001156 TOK_whitespace {
vlm1fcf7592006-08-18 02:27:55 +00001157 $$ = asn1p_wsyntx_chunk_fromstring($1.buf, 0);
vlmeeb3c512006-03-16 05:11:14 +00001158 $$->type = WC_WHITESPACE;
vlmfa67ddc2004-06-03 03:38:44 +00001159 }
vlm808411d2006-03-14 16:31:37 +00001160 | TOK_Literal {
vlm1fcf7592006-08-18 02:27:55 +00001161 $$ = asn1p_wsyntx_chunk_fromstring($1, 0);
vlm808411d2006-03-14 16:31:37 +00001162 }
vlma6a84d72006-03-16 10:03:35 +00001163 | PrimitiveFieldReference {
vlm1fcf7592006-08-18 02:27:55 +00001164 $$ = asn1p_wsyntx_chunk_fromstring($1.name, 0);
vlma6a84d72006-03-16 10:03:35 +00001165 $$->type = WC_FIELD;
vlmfa67ddc2004-06-03 03:38:44 +00001166 }
vlm808411d2006-03-14 16:31:37 +00001167 | '[' WithSyntaxList ']' {
1168 $$ = asn1p_wsyntx_chunk_fromsyntax($2);
1169 }
vlmfa67ddc2004-06-03 03:38:44 +00001170 ;
1171
vlmfa67ddc2004-06-03 03:38:44 +00001172ExtensionAndException:
1173 TOK_ThreeDots {
vlm43c8ac52006-09-17 04:52:50 +00001174 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001175 checkmem($$);
1176 $$->Identifier = strdup("...");
1177 checkmem($$->Identifier);
1178 $$->expr_type = A1TC_EXTENSIBLE;
1179 $$->meta_type = AMT_TYPE;
1180 }
1181 | TOK_ThreeDots '!' DefinedValue {
vlm43c8ac52006-09-17 04:52:50 +00001182 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001183 checkmem($$);
1184 $$->Identifier = strdup("...");
1185 checkmem($$->Identifier);
1186 $$->value = $3;
1187 $$->expr_type = A1TC_EXTENSIBLE;
1188 $$->meta_type = AMT_TYPE;
1189 }
1190 | TOK_ThreeDots '!' SignedNumber {
vlm43c8ac52006-09-17 04:52:50 +00001191 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001192 checkmem($$);
1193 $$->Identifier = strdup("...");
1194 $$->value = $3;
1195 checkmem($$->Identifier);
1196 $$->expr_type = A1TC_EXTENSIBLE;
1197 $$->meta_type = AMT_TYPE;
1198 }
1199 ;
1200
vlmec8f6812004-08-22 03:19:54 +00001201Type:
vlmfce48a42004-09-14 02:36:39 +00001202 optTag TypeDeclaration optConstraints {
1203 $$ = $2;
1204 $$->tag = $1;
vlmec8f6812004-08-22 03:19:54 +00001205 /*
1206 * Outer constraint for SEQUENCE OF and SET OF applies
1207 * to the inner type.
1208 */
1209 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1210 || $$->expr_type == ASN_CONSTR_SET_OF) {
1211 assert(!TQ_FIRST(&($$->members))->constraints);
vlmfce48a42004-09-14 02:36:39 +00001212 TQ_FIRST(&($$->members))->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001213 } else {
1214 if($$->constraints) {
1215 assert(!$2);
1216 } else {
vlmfce48a42004-09-14 02:36:39 +00001217 $$->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001218 }
1219 }
vlm177a5b62005-09-05 05:17:57 +00001220 }
1221 ;
1222
1223NSTD_IndirectMarker:
1224 {
1225 $$ = asn1p_as_pointer ? EM_INDIRECT : 0;
1226 asn1p_as_pointer = 0;
vlmec8f6812004-08-22 03:19:54 +00001227 }
1228 ;
1229
1230TypeDeclaration:
vlm177a5b62005-09-05 05:17:57 +00001231 NSTD_IndirectMarker TypeDeclarationSet {
vlm066dc102005-08-22 12:23:54 +00001232 $$ = $2;
vlm177a5b62005-09-05 05:17:57 +00001233 $$->marker.flags |= $1;
1234
1235 if(($$->marker.flags & EM_INDIRECT)
1236 && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
1237 fprintf(stderr,
1238 "INFO: Directive <ASN1C:RepresentAsPointer> "
1239 "applied to %s at line %d\n",
1240 ASN_EXPR_TYPE2STR($$->expr_type)
1241 ? ASN_EXPR_TYPE2STR($$->expr_type)
1242 : "member",
1243 $$->_lineno
1244 );
1245 }
vlm066dc102005-08-22 12:23:54 +00001246 }
vlm177a5b62005-09-05 05:17:57 +00001247 ;
vlm066dc102005-08-22 12:23:54 +00001248
1249TypeDeclarationSet:
vlm17e65d02006-03-21 04:48:15 +00001250 DefinedType {
vlmfa67ddc2004-06-03 03:38:44 +00001251 $$ = $1;
1252 }
vlm177a5b62005-09-05 05:17:57 +00001253 | TOK_CHOICE '{' AlternativeTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001254 $$ = $3;
1255 assert($$->expr_type == A1TC_INVALID);
1256 $$->expr_type = ASN_CONSTR_CHOICE;
1257 $$->meta_type = AMT_TYPE;
vlmfa67ddc2004-06-03 03:38:44 +00001258 }
vlm177a5b62005-09-05 05:17:57 +00001259 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001260 $$ = $3;
1261 assert($$->expr_type == A1TC_INVALID);
1262 $$->expr_type = ASN_CONSTR_SEQUENCE;
1263 $$->meta_type = AMT_TYPE;
1264 }
vlm177a5b62005-09-05 05:17:57 +00001265 | TOK_SET '{' optComponentTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001266 $$ = $3;
1267 assert($$->expr_type == A1TC_INVALID);
1268 $$->expr_type = ASN_CONSTR_SET;
1269 $$->meta_type = AMT_TYPE;
1270 }
vlm151c0b22004-09-22 16:03:36 +00001271 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
vlm43c8ac52006-09-17 04:52:50 +00001272 $$ = NEW_EXPR();
vlmec8f6812004-08-22 03:19:54 +00001273 checkmem($$);
1274 $$->constraints = $2;
1275 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1276 $$->meta_type = AMT_TYPE;
vlm151c0b22004-09-22 16:03:36 +00001277 $6->Identifier = $4;
1278 $6->tag = $5;
1279 asn1p_expr_add($$, $6);
vlmec8f6812004-08-22 03:19:54 +00001280 }
vlm151c0b22004-09-22 16:03:36 +00001281 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
vlm43c8ac52006-09-17 04:52:50 +00001282 $$ = NEW_EXPR();
vlmec8f6812004-08-22 03:19:54 +00001283 checkmem($$);
1284 $$->constraints = $2;
1285 $$->expr_type = ASN_CONSTR_SET_OF;
1286 $$->meta_type = AMT_TYPE;
vlm151c0b22004-09-22 16:03:36 +00001287 $6->Identifier = $4;
1288 $6->tag = $5;
1289 asn1p_expr_add($$, $6);
vlmec8f6812004-08-22 03:19:54 +00001290 }
1291 | TOK_ANY {
vlm43c8ac52006-09-17 04:52:50 +00001292 $$ = NEW_EXPR();
vlmec8f6812004-08-22 03:19:54 +00001293 checkmem($$);
vlm044f7442004-09-04 04:49:21 +00001294 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001295 $$->meta_type = AMT_TYPE;
1296 }
1297 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1298 int ret;
vlm43c8ac52006-09-17 04:52:50 +00001299 $$ = NEW_EXPR();
vlmec8f6812004-08-22 03:19:54 +00001300 checkmem($$);
1301 $$->reference = asn1p_ref_new(yylineno);
1302 ret = asn1p_ref_add_component($$->reference,
1303 $4, RLT_lowercase);
1304 checkmem(ret == 0);
vlm044f7442004-09-04 04:49:21 +00001305 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001306 $$->meta_type = AMT_TYPE;
1307 }
vlmfa67ddc2004-06-03 03:38:44 +00001308 | TOK_INSTANCE TOK_OF ComplexTypeReference {
vlm43c8ac52006-09-17 04:52:50 +00001309 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001310 checkmem($$);
1311 $$->reference = $3;
1312 $$->expr_type = A1TC_INSTANCE;
1313 $$->meta_type = AMT_TYPE;
1314 }
1315 ;
1316
1317/*
1318 * A type name consisting of several components.
1319 * === EXAMPLE ===
1320 * === EOF ===
1321 */
1322ComplexTypeReference:
1323 TOK_typereference {
1324 int ret;
1325 $$ = asn1p_ref_new(yylineno);
1326 checkmem($$);
1327 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1328 checkmem(ret == 0);
1329 free($1);
1330 }
1331 | TOK_typereference '.' TypeRefName {
1332 int ret;
1333 $$ = asn1p_ref_new(yylineno);
1334 checkmem($$);
1335 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1336 checkmem(ret == 0);
1337 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1338 checkmem(ret == 0);
1339 free($1);
1340 }
vlmc94e28f2004-09-15 11:59:51 +00001341 | ObjectClassReference '.' TypeRefName {
1342 int ret;
1343 $$ = asn1p_ref_new(yylineno);
1344 checkmem($$);
1345 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1346 checkmem(ret == 0);
1347 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1348 checkmem(ret == 0);
1349 free($1);
1350 }
vlmfa67ddc2004-06-03 03:38:44 +00001351 | TOK_typereference '.' Identifier {
1352 int ret;
1353 $$ = asn1p_ref_new(yylineno);
1354 checkmem($$);
1355 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1356 checkmem(ret == 0);
1357 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1358 checkmem(ret == 0);
1359 free($1);
1360 }
1361 | ObjectClassReference {
1362 int ret;
1363 $$ = asn1p_ref_new(yylineno);
1364 checkmem($$);
1365 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1366 free($1);
1367 checkmem(ret == 0);
1368 }
1369 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1370 int ret;
1371 $$ = $3;
1372 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1373 free($1);
1374 checkmem(ret == 0);
1375 /*
1376 * Move the last element infront.
1377 */
1378 {
1379 struct asn1p_ref_component_s tmp_comp;
1380 tmp_comp = $$->components[$$->comp_count-1];
1381 memmove(&$$->components[1],
1382 &$$->components[0],
1383 sizeof($$->components[0])
1384 * ($$->comp_count - 1));
1385 $$->components[0] = tmp_comp;
1386 }
1387 }
1388 ;
1389
1390ComplexTypeReferenceAmpList:
1391 ComplexTypeReferenceElement {
1392 int ret;
1393 $$ = asn1p_ref_new(yylineno);
1394 checkmem($$);
1395 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1396 free($1.name);
1397 checkmem(ret == 0);
1398 }
1399 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1400 int ret;
1401 $$ = $1;
1402 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1403 free($3.name);
1404 checkmem(ret == 0);
1405 }
1406 ;
1407
vlma6a84d72006-03-16 10:03:35 +00001408ComplexTypeReferenceElement: PrimitiveFieldReference;
vlmfa67ddc2004-06-03 03:38:44 +00001409
vlma6a84d72006-03-16 10:03:35 +00001410PrimitiveFieldReference:
vlmfa67ddc2004-06-03 03:38:44 +00001411 /* "&Type1" */
1412 TOK_typefieldreference {
1413 $$.lex_type = RLT_AmpUppercase;
1414 $$.name = $1;
1415 }
1416 /* "&id" */
1417 | TOK_valuefieldreference {
1418 $$.lex_type = RLT_Amplowercase;
1419 $$.name = $1;
1420 }
1421 ;
1422
1423
vlmdc7cf042006-03-09 08:49:26 +00001424FieldName:
1425 /* "&Type1" */
1426 TOK_typefieldreference {
1427 $$ = asn1p_ref_new(yylineno);
1428 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1429 }
1430 | FieldName '.' TOK_typefieldreference {
1431 $$ = $$;
1432 asn1p_ref_add_component($$, $3, RLT_AmpUppercase);
1433 }
1434 | FieldName '.' TOK_valuefieldreference {
1435 $$ = $$;
1436 asn1p_ref_add_component($$, $3, RLT_Amplowercase);
1437 }
1438 ;
1439
1440DefinedObjectClass:
1441 TOK_capitalreference {
1442 $$ = asn1p_ref_new(yylineno);
1443 asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1444 }
vlmee7196e2006-03-09 09:08:49 +00001445/*
vlmdc7cf042006-03-09 08:49:26 +00001446 | TypeRefName '.' TOK_capitalreference {
1447 $$ = asn1p_ref_new(yylineno);
1448 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1449 asn1p_ref_add_component($$, $3, RLT_CAPITALS);
1450 }
vlmee7196e2006-03-09 09:08:49 +00001451*/
vlmdc7cf042006-03-09 08:49:26 +00001452 ;
1453
1454
vlmfa67ddc2004-06-03 03:38:44 +00001455/*
1456 * === EXAMPLE ===
1457 * value INTEGER ::= 1
1458 * === EOF ===
1459 */
1460ValueDefinition:
vlm17e65d02006-03-21 04:48:15 +00001461 Identifier DefinedType TOK_PPEQ Value {
vlmfa67ddc2004-06-03 03:38:44 +00001462 $$ = $2;
1463 assert($$->Identifier == NULL);
1464 $$->Identifier = $1;
1465 $$->meta_type = AMT_VALUE;
1466 $$->value = $4;
1467 }
1468 ;
1469
vlmc94e28f2004-09-15 11:59:51 +00001470Value:
vlm17e65d02006-03-21 04:48:15 +00001471 SimpleValue
1472 | DefinedValue
1473 | Identifier ':' Value {
vlmc94e28f2004-09-15 11:59:51 +00001474 $$ = asn1p_value_fromint(0);
1475 checkmem($$);
1476 $$->type = ATV_CHOICE_IDENTIFIER;
1477 $$->value.choice_identifier.identifier = $1;
1478 $$->value.choice_identifier.value = $3;
1479 }
vlmd30bc6c2005-03-24 16:27:02 +00001480 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
vlmfa67ddc2004-06-03 03:38:44 +00001481 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1482 checkmem($$);
1483 $$->type = ATV_UNPARSED;
1484 }
vlmc94e28f2004-09-15 11:59:51 +00001485 | TOK_NULL {
1486 $$ = asn1p_value_fromint(0);
1487 checkmem($$);
1488 $$->type = ATV_NULL;
1489 }
vlm17e65d02006-03-21 04:48:15 +00001490 ;
1491
1492SimpleValue:
1493 TOK_FALSE {
vlmc94e28f2004-09-15 11:59:51 +00001494 $$ = asn1p_value_fromint(0);
1495 checkmem($$);
1496 $$->type = ATV_FALSE;
1497 }
1498 | TOK_TRUE {
1499 $$ = asn1p_value_fromint(0);
1500 checkmem($$);
1501 $$->type = ATV_TRUE;
1502 }
vlmfa67ddc2004-06-03 03:38:44 +00001503 | TOK_bstring {
1504 $$ = _convert_bitstring2binary($1, 'B');
1505 checkmem($$);
1506 }
1507 | TOK_hstring {
1508 $$ = _convert_bitstring2binary($1, 'H');
1509 checkmem($$);
1510 }
vlme1e6ed82005-03-24 14:26:38 +00001511 | RestrictedCharacterStringValue {
1512 $$ = $$;
vlmfa67ddc2004-06-03 03:38:44 +00001513 }
1514 | SignedNumber {
1515 $$ = $1;
1516 }
vlmfa67ddc2004-06-03 03:38:44 +00001517 ;
1518
1519DefinedValue:
1520 Identifier {
1521 asn1p_ref_t *ref;
1522 int ret;
1523 ref = asn1p_ref_new(yylineno);
1524 checkmem(ref);
1525 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1526 checkmem(ret == 0);
1527 $$ = asn1p_value_fromref(ref, 0);
1528 checkmem($$);
1529 free($1);
1530 }
1531 | TypeRefName '.' Identifier {
1532 asn1p_ref_t *ref;
1533 int ret;
1534 ref = asn1p_ref_new(yylineno);
1535 checkmem(ref);
1536 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1537 checkmem(ret == 0);
1538 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1539 checkmem(ret == 0);
1540 $$ = asn1p_value_fromref(ref, 0);
1541 checkmem($$);
1542 free($1);
1543 free($3);
1544 }
1545 ;
1546
vlme1e6ed82005-03-24 14:26:38 +00001547
1548RestrictedCharacterStringValue:
1549 TOK_cstring {
1550 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1551 checkmem($$);
1552 }
vlm2c8c44d2005-03-24 16:22:35 +00001553 | TOK_tuple {
1554 $$ = asn1p_value_fromint($1);
1555 checkmem($$);
1556 $$->type = ATV_TUPLE;
1557 }
1558 | TOK_quadruple {
1559 $$ = asn1p_value_fromint($1);
1560 checkmem($$);
1561 $$->type = ATV_QUADRUPLE;
1562 }
1563 /*
vlme1e6ed82005-03-24 14:26:38 +00001564 | '{' TOK_number ',' TOK_number '}' {
1565 asn1c_integer_t v = ($2 << 4) + $4;
1566 if($2 > 7) return yyerror("X.680:2003, #37.14 "
1567 "mandates 0..7 range for Tuple's TableColumn");
1568 if($4 > 15) return yyerror("X.680:2003, #37.14 "
1569 "mandates 0..15 range for Tuple's TableRow");
1570 $$ = asn1p_value_fromint(v);
1571 checkmem($$);
1572 $$->type = ATV_TUPLE;
1573 }
1574 | '{' TOK_number ',' TOK_number ',' TOK_number ',' TOK_number '}' {
1575 asn1c_integer_t v = ($2 << 24) | ($4 << 16) | ($6 << 8) | $8;
1576 if($2 > 127) return yyerror("X.680:2003, #37.12 "
1577 "mandates 0..127 range for Quadruple's Group");
1578 if($4 > 255) return yyerror("X.680:2003, #37.12 "
1579 "mandates 0..255 range for Quadruple's Plane");
1580 if($6 > 255) return yyerror("X.680:2003, #37.12 "
1581 "mandates 0..255 range for Quadruple's Row");
1582 if($8 > 255) return yyerror("X.680:2003, #37.12 "
1583 "mandates 0..255 range for Quadruple's Cell");
1584 $$ = asn1p_value_fromint(v);
1585 checkmem($$);
1586 $$->type = ATV_QUADRUPLE;
1587 }
vlm2c8c44d2005-03-24 16:22:35 +00001588 */
vlme1e6ed82005-03-24 14:26:38 +00001589 ;
1590
vlmfa67ddc2004-06-03 03:38:44 +00001591Opaque:
1592 TOK_opaque {
vlm6611add2005-03-20 14:28:32 +00001593 $$.len = $1.len + 1;
vlmfa67ddc2004-06-03 03:38:44 +00001594 $$.buf = malloc($$.len + 1);
1595 checkmem($$.buf);
1596 $$.buf[0] = '{';
vlm6611add2005-03-20 14:28:32 +00001597 memcpy($$.buf + 1, $1.buf, $1.len);
vlmfa67ddc2004-06-03 03:38:44 +00001598 $$.buf[$$.len] = '\0';
1599 free($1.buf);
1600 }
1601 | Opaque TOK_opaque {
1602 int newsize = $1.len + $2.len;
1603 char *p = malloc(newsize + 1);
1604 checkmem(p);
1605 memcpy(p , $1.buf, $1.len);
1606 memcpy(p + $1.len, $2.buf, $2.len);
1607 p[newsize] = '\0';
1608 free($1.buf);
1609 free($2.buf);
1610 $$.buf = p;
1611 $$.len = newsize;
1612 }
1613 ;
1614
1615BasicTypeId:
1616 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1617 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1618 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1619 | BasicTypeId_UniverationCompatible { $$ = $1; }
1620 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1621 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1622 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1623 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1624 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1625 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1626 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1627 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
vlm5e2c4b92005-03-20 11:12:40 +00001628 | BasicString { $$ = $1; }
vlmfa67ddc2004-06-03 03:38:44 +00001629 ;
1630
1631/*
1632 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1633 */
1634BasicTypeId_UniverationCompatible:
1635 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1636 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1637 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1638 ;
1639
1640BasicType:
1641 BasicTypeId {
vlm43c8ac52006-09-17 04:52:50 +00001642 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001643 checkmem($$);
1644 $$->expr_type = $1;
1645 $$->meta_type = AMT_TYPE;
1646 }
1647 | BasicTypeId_UniverationCompatible UniverationDefinition {
1648 if($2) {
1649 $$ = $2;
1650 } else {
vlm43c8ac52006-09-17 04:52:50 +00001651 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001652 checkmem($$);
1653 }
1654 $$->expr_type = $1;
1655 $$->meta_type = AMT_TYPE;
1656 }
1657 ;
1658
1659BasicString:
1660 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1661 | TOK_GeneralString {
1662 $$ = ASN_STRING_GeneralString;
vlmc94e28f2004-09-15 11:59:51 +00001663 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001664 }
1665 | TOK_GraphicString {
1666 $$ = ASN_STRING_GraphicString;
vlmc94e28f2004-09-15 11:59:51 +00001667 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001668 }
1669 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1670 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1671 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1672 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1673 | TOK_T61String {
1674 $$ = ASN_STRING_T61String;
vlmc94e28f2004-09-15 11:59:51 +00001675 fprintf(stderr, "WARNING: T61String is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001676 }
1677 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1678 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1679 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1680 | TOK_VideotexString {
1681 $$ = ASN_STRING_VideotexString;
vlmc94e28f2004-09-15 11:59:51 +00001682 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001683 }
1684 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1685 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1686 ;
1687
vlm5f0128b2004-08-20 13:25:29 +00001688
vlmfa67ddc2004-06-03 03:38:44 +00001689/*
1690 * Data type constraints.
1691 */
vlm1bc782f2006-09-21 01:50:37 +00001692UnionMark: '|' | TOK_UNION;
1693IntersectionMark: '^' | TOK_INTERSECTION;
vlmfa67ddc2004-06-03 03:38:44 +00001694
vlm9283dbe2004-08-18 04:59:12 +00001695optConstraints:
1696 { $$ = 0; }
vlm43c8ac52006-09-17 04:52:50 +00001697 | Constraint {
vlm5f0128b2004-08-20 13:25:29 +00001698 $$ = $1;
1699 }
1700 ;
1701
vlm43c8ac52006-09-17 04:52:50 +00001702Constraint:
1703 SubtypeConstraint
1704 | '(' GeneralConstraint ')' {
1705 $$ = $2;
1706 }
1707 ;
1708
1709SubtypeConstraint:
vlm5f0128b2004-08-20 13:25:29 +00001710 SetOfConstraints {
vlm9fe7c922005-08-12 10:08:45 +00001711 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
vlm9283dbe2004-08-18 04:59:12 +00001712 }
1713 | TOK_SIZE '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001714 /*
1715 * This is a special case, for compatibility purposes.
vlm9283dbe2004-08-18 04:59:12 +00001716 * It goes without parentheses.
vlmfa67ddc2004-06-03 03:38:44 +00001717 */
vlm9fe7c922005-08-12 10:08:45 +00001718 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001719 }
vlmfa67ddc2004-06-03 03:38:44 +00001720 ;
1721
vlm9283dbe2004-08-18 04:59:12 +00001722SetOfConstraints:
1723 '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001724 $$ = $2;
1725 }
vlm9283dbe2004-08-18 04:59:12 +00001726 | SetOfConstraints '(' ElementSetSpecs ')' {
vlm9fe7c922005-08-12 10:08:45 +00001727 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
vlm9283dbe2004-08-18 04:59:12 +00001728 }
vlmfa67ddc2004-06-03 03:38:44 +00001729 ;
1730
vlm9283dbe2004-08-18 04:59:12 +00001731ElementSetSpecs:
vlmdfbff8c2006-03-21 09:41:28 +00001732 TOK_ThreeDots {
1733 $$ = asn1p_constraint_new(yylineno);
1734 $$->type = ACT_EL_EXT;
1735 }
1736 | ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001737 $$ = $1;
1738 }
vlm9283dbe2004-08-18 04:59:12 +00001739 | ElementSetSpec ',' TOK_ThreeDots {
vlmfa67ddc2004-06-03 03:38:44 +00001740 asn1p_constraint_t *ct;
1741 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001742 ct->type = ACT_EL_EXT;
vlm9fe7c922005-08-12 10:08:45 +00001743 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlmfa67ddc2004-06-03 03:38:44 +00001744 }
vlm9283dbe2004-08-18 04:59:12 +00001745 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001746 asn1p_constraint_t *ct;
1747 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001748 ct->type = ACT_EL_EXT;
vlm9fe7c922005-08-12 10:08:45 +00001749 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlm6f5eb0b2004-08-13 12:35:09 +00001750 ct = $$;
vlm9fe7c922005-08-12 10:08:45 +00001751 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
vlmfa67ddc2004-06-03 03:38:44 +00001752 }
vlmfa67ddc2004-06-03 03:38:44 +00001753 ;
1754
vlm9283dbe2004-08-18 04:59:12 +00001755ElementSetSpec:
vlm1bc782f2006-09-21 01:50:37 +00001756 Unions
vlme1e6ed82005-03-24 14:26:38 +00001757 | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001758 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
vlme1e6ed82005-03-24 14:26:38 +00001759 }
vlm1bc782f2006-09-21 01:50:37 +00001760 ;
1761
1762Unions:
1763 Intersections
1764 | Unions UnionMark Intersections {
vlm9fe7c922005-08-12 10:08:45 +00001765 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001766 }
vlm1bc782f2006-09-21 01:50:37 +00001767 ;
1768
1769Intersections:
1770 IntersectionElements
1771 | Intersections IntersectionMark IntersectionElements {
vlm9fe7c922005-08-12 10:08:45 +00001772 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001773 }
vlm1bc782f2006-09-21 01:50:37 +00001774 ;
1775
1776
1777IntersectionElements:
1778 ConstraintSubtypeElement
1779 | ConstraintSubtypeElement TOK_EXCEPT ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001780 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001781 }
1782 ;
1783
1784ConstraintSubtypeElement:
vlm9283dbe2004-08-18 04:59:12 +00001785 ConstraintSpec '(' ElementSetSpecs ')' {
1786 int ret;
1787 $$ = asn1p_constraint_new(yylineno);
1788 checkmem($$);
1789 $$->type = $1;
1790 ret = asn1p_constraint_insert($$, $3);
1791 checkmem(ret == 0);
1792 }
1793 | '(' ElementSetSpecs ')' {
1794 int ret;
1795 $$ = asn1p_constraint_new(yylineno);
1796 checkmem($$);
1797 $$->type = ACT_CA_SET;
1798 ret = asn1p_constraint_insert($$, $2);
1799 checkmem(ret == 0);
1800 }
vlma6a12e32005-03-20 12:58:00 +00001801 | SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001802 $$ = asn1p_constraint_new(yylineno);
1803 checkmem($$);
1804 $$->type = ACT_EL_VALUE;
1805 $$->value = $1;
1806 }
vlma6a12e32005-03-20 12:58:00 +00001807 | ContainedSubtype {
1808 $$ = asn1p_constraint_new(yylineno);
1809 checkmem($$);
1810 $$->type = ACT_EL_TYPE;
1811 $$->containedSubtype = $1;
1812 }
1813 | SingleValue ConstraintRangeSpec SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001814 $$ = asn1p_constraint_new(yylineno);
1815 checkmem($$);
1816 $$->type = $2;
1817 $$->range_start = $1;
1818 $$->range_stop = $3;
1819 }
vlma6a12e32005-03-20 12:58:00 +00001820 | TOK_MIN ConstraintRangeSpec SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001821 $$ = asn1p_constraint_new(yylineno);
1822 checkmem($$);
vlm9283dbe2004-08-18 04:59:12 +00001823 $$->type = $2;
1824 $$->range_start = asn1p_value_fromint(-123);
1825 $$->range_stop = $3;
1826 $$->range_start->type = ATV_MIN;
1827 }
vlma6a12e32005-03-20 12:58:00 +00001828 | SingleValue ConstraintRangeSpec TOK_MAX {
vlm9283dbe2004-08-18 04:59:12 +00001829 $$ = asn1p_constraint_new(yylineno);
1830 checkmem($$);
1831 $$->type = $2;
1832 $$->range_start = $1;
1833 $$->range_stop = asn1p_value_fromint(321);
1834 $$->range_stop->type = ATV_MAX;
1835 }
1836 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1837 $$ = asn1p_constraint_new(yylineno);
1838 checkmem($$);
1839 $$->type = $2;
1840 $$->range_start = asn1p_value_fromint(-123);
1841 $$->range_stop = asn1p_value_fromint(321);
1842 $$->range_start->type = ATV_MIN;
1843 $$->range_stop->type = ATV_MAX;
vlmfa67ddc2004-06-03 03:38:44 +00001844 }
vlm7bbdc9f2005-03-28 15:01:27 +00001845 | InnerTypeConstraint {
vlmfa67ddc2004-06-03 03:38:44 +00001846 $$ = $1;
1847 }
vlmfa67ddc2004-06-03 03:38:44 +00001848 ;
1849
1850ConstraintSpec:
1851 TOK_SIZE {
1852 $$ = ACT_CT_SIZE;
1853 }
1854 | TOK_FROM {
1855 $$ = ACT_CT_FROM;
1856 }
1857 ;
1858
vlma6a12e32005-03-20 12:58:00 +00001859SingleValue:
vlm4053ca52005-02-18 16:34:21 +00001860 TOK_FALSE {
1861 $$ = asn1p_value_fromint(0);
1862 checkmem($$);
1863 $$->type = ATV_FALSE;
1864 }
1865 | TOK_TRUE {
1866 $$ = asn1p_value_fromint(1);
1867 checkmem($$);
1868 $$->type = ATV_TRUE;
1869 }
vlme745fcd2006-09-05 16:18:34 +00001870 | RealValue
1871 | RestrictedCharacterStringValue
vlmfa67ddc2004-06-03 03:38:44 +00001872 | Identifier {
1873 asn1p_ref_t *ref;
1874 int ret;
1875 ref = asn1p_ref_new(yylineno);
1876 checkmem(ref);
1877 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1878 checkmem(ret == 0);
1879 $$ = asn1p_value_fromref(ref, 0);
1880 checkmem($$);
1881 free($1);
1882 }
vlma6a12e32005-03-20 12:58:00 +00001883 ;
1884
1885ContainedSubtype:
1886 TypeRefName {
vlm4053ca52005-02-18 16:34:21 +00001887 asn1p_ref_t *ref;
1888 int ret;
1889 ref = asn1p_ref_new(yylineno);
1890 checkmem(ref);
1891 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1892 checkmem(ret == 0);
1893 $$ = asn1p_value_fromref(ref, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001894 checkmem($$);
vlm4053ca52005-02-18 16:34:21 +00001895 free($1);
vlmfa67ddc2004-06-03 03:38:44 +00001896 }
1897 ;
1898
vlm7bbdc9f2005-03-28 15:01:27 +00001899InnerTypeConstraint:
1900 TOK_WITH TOK_COMPONENT SetOfConstraints {
vlm9fe7c922005-08-12 10:08:45 +00001901 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
vlm7bbdc9f2005-03-28 15:01:27 +00001902 }
1903 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
vlm9fe7c922005-08-12 10:08:45 +00001904 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001905 }
1906 ;
1907
1908WithComponentsList:
1909 WithComponentsElement {
1910 $$ = $1;
1911 }
1912 | WithComponentsList ',' WithComponentsElement {
vlm9fe7c922005-08-12 10:08:45 +00001913 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001914 }
1915 ;
1916
1917WithComponentsElement:
1918 TOK_ThreeDots {
1919 $$ = asn1p_constraint_new(yylineno);
1920 checkmem($$);
1921 $$->type = ACT_EL_EXT;
vlm1aeaddd2006-07-13 08:24:20 +00001922 $$->value = asn1p_value_frombuf("...", 3, 1);
vlmfa67ddc2004-06-03 03:38:44 +00001923 }
1924 | Identifier optConstraints optPresenceConstraint {
1925 $$ = asn1p_constraint_new(yylineno);
1926 checkmem($$);
1927 $$->type = ACT_EL_VALUE;
1928 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1929 $$->presence = $3;
vlm7bbdc9f2005-03-28 15:01:27 +00001930 if($2) asn1p_constraint_insert($$, $2);
vlmfa67ddc2004-06-03 03:38:44 +00001931 }
1932 ;
1933
1934/*
1935 * presence constraint for WithComponents
1936 */
1937optPresenceConstraint:
1938 { $$ = ACPRES_DEFAULT; }
1939 | PresenceConstraint { $$ = $1; }
1940 ;
1941
1942PresenceConstraint:
1943 TOK_PRESENT {
1944 $$ = ACPRES_PRESENT;
1945 }
1946 | TOK_ABSENT {
1947 $$ = ACPRES_ABSENT;
1948 }
1949 | TOK_OPTIONAL {
1950 $$ = ACPRES_OPTIONAL;
1951 }
1952 ;
1953
vlm43c8ac52006-09-17 04:52:50 +00001954
1955/* X.682 */
1956GeneralConstraint:
1957 UserDefinedConstraint
1958 | TableConstraint
1959 | ContentsConstraint
1960 ;
1961
1962UserDefinedConstraint:
1963 TOK_CONSTRAINED TOK_BY '{'
1964 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1965 $$ = asn1p_constraint_new(yylineno);
1966 checkmem($$);
1967 $$->type = ACT_CT_CTDBY;
1968 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
1969 checkmem($$->value);
1970 $$->value->type = ATV_UNPARSED;
1971 }
1972 ;
1973
1974ContentsConstraint:
1975 TOK_CONTAINING Type {
1976 $$ = asn1p_constraint_new(yylineno);
1977 $$->type = ACT_CT_CTNG;
1978 $$->value = asn1p_value_fromtype($2);
1979 }
1980 ;
1981
1982ConstraintRangeSpec:
1983 TOK_TwoDots { $$ = ACT_EL_RANGE; }
1984 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
1985 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
1986 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
1987 ;
vlmfa67ddc2004-06-03 03:38:44 +00001988TableConstraint:
1989 SimpleTableConstraint {
1990 $$ = $1;
1991 }
1992 | ComponentRelationConstraint {
1993 $$ = $1;
1994 }
1995 ;
1996
1997/*
1998 * "{ExtensionSet}"
1999 */
2000SimpleTableConstraint:
2001 '{' TypeRefName '}' {
2002 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
2003 asn1p_constraint_t *ct;
2004 int ret;
2005 ret = asn1p_ref_add_component(ref, $2, 0);
2006 checkmem(ret == 0);
2007 ct = asn1p_constraint_new(yylineno);
2008 checkmem($$);
2009 ct->type = ACT_EL_VALUE;
2010 ct->value = asn1p_value_fromref(ref, 0);
vlm9fe7c922005-08-12 10:08:45 +00002011 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
vlmfa67ddc2004-06-03 03:38:44 +00002012 }
2013 ;
2014
2015ComponentRelationConstraint:
2016 SimpleTableConstraint '{' AtNotationList '}' {
vlm9fe7c922005-08-12 10:08:45 +00002017 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00002018 }
2019 ;
2020
2021AtNotationList:
2022 AtNotationElement {
2023 $$ = asn1p_constraint_new(yylineno);
2024 checkmem($$);
2025 $$->type = ACT_EL_VALUE;
2026 $$->value = asn1p_value_fromref($1, 0);
2027 }
2028 | AtNotationList ',' AtNotationElement {
2029 asn1p_constraint_t *ct;
2030 ct = asn1p_constraint_new(yylineno);
2031 checkmem(ct);
2032 ct->type = ACT_EL_VALUE;
2033 ct->value = asn1p_value_fromref($3, 0);
vlm9fe7c922005-08-12 10:08:45 +00002034 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlmfa67ddc2004-06-03 03:38:44 +00002035 }
2036 ;
2037
2038/*
2039 * @blah
2040 */
2041AtNotationElement:
2042 '@' ComponentIdList {
2043 char *p = malloc(strlen($2) + 2);
2044 int ret;
2045 *p = '@';
2046 strcpy(p + 1, $2);
2047 $$ = asn1p_ref_new(yylineno);
2048 ret = asn1p_ref_add_component($$, p, 0);
2049 checkmem(ret == 0);
2050 free(p);
2051 free($2);
2052 }
2053 | '@' '.' ComponentIdList {
2054 char *p = malloc(strlen($3) + 3);
2055 int ret;
2056 p[0] = '@';
2057 p[1] = '.';
2058 strcpy(p + 2, $3);
2059 $$ = asn1p_ref_new(yylineno);
2060 ret = asn1p_ref_add_component($$, p, 0);
2061 checkmem(ret == 0);
2062 free(p);
2063 free($3);
2064 }
2065 ;
2066
2067/* identifier "." ... */
2068ComponentIdList:
2069 Identifier {
2070 $$ = $1;
2071 }
2072 | ComponentIdList '.' Identifier {
2073 int l1 = strlen($1);
2074 int l3 = strlen($3);
2075 $$ = malloc(l1 + 1 + l3 + 1);
2076 memcpy($$, $1, l1);
2077 $$[l1] = '.';
2078 memcpy($$ + l1 + 1, $3, l3);
2079 $$[l1 + 1 + l3] = '\0';
2080 }
2081 ;
2082
2083
2084
2085/*
2086 * MARKERS
2087 */
2088
2089optMarker:
vlmc94e28f2004-09-15 11:59:51 +00002090 {
2091 $$.flags = EM_NOMARK;
2092 $$.default_value = 0;
2093 }
vlmfa67ddc2004-06-03 03:38:44 +00002094 | Marker { $$ = $1; }
2095 ;
2096
2097Marker:
2098 TOK_OPTIONAL {
vlm1ac75e72005-11-26 11:21:55 +00002099 $$.flags = EM_OPTIONAL | EM_INDIRECT;
vlmc94e28f2004-09-15 11:59:51 +00002100 $$.default_value = 0;
vlmfa67ddc2004-06-03 03:38:44 +00002101 }
vlmc94e28f2004-09-15 11:59:51 +00002102 | TOK_DEFAULT Value {
2103 $$.flags = EM_DEFAULT;
2104 $$.default_value = $2;
vlmfa67ddc2004-06-03 03:38:44 +00002105 }
2106 ;
2107
2108/*
2109 * Universal enumeration definition to use in INTEGER and ENUMERATED.
2110 * === EXAMPLE ===
2111 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
2112 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
2113 * === EOF ===
2114 */
2115/*
2116optUniverationDefinition:
2117 { $$ = 0; }
2118 | UniverationDefinition {
2119 $$ = $1;
2120 }
2121 ;
2122*/
2123
2124UniverationDefinition:
2125 '{' '}' {
vlm43c8ac52006-09-17 04:52:50 +00002126 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002127 checkmem($$);
2128 }
2129 | '{' UniverationList '}' {
2130 $$ = $2;
2131 }
2132 ;
2133
2134UniverationList:
2135 UniverationElement {
vlm43c8ac52006-09-17 04:52:50 +00002136 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002137 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +00002138 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +00002139 }
2140 | UniverationList ',' UniverationElement {
2141 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +00002142 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +00002143 }
2144 ;
2145
2146UniverationElement:
2147 Identifier {
vlm43c8ac52006-09-17 04:52:50 +00002148 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002149 checkmem($$);
2150 $$->expr_type = A1TC_UNIVERVAL;
2151 $$->meta_type = AMT_VALUE;
2152 $$->Identifier = $1;
2153 }
2154 | Identifier '(' SignedNumber ')' {
vlm43c8ac52006-09-17 04:52:50 +00002155 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002156 checkmem($$);
2157 $$->expr_type = A1TC_UNIVERVAL;
2158 $$->meta_type = AMT_VALUE;
2159 $$->Identifier = $1;
2160 $$->value = $3;
2161 }
2162 | Identifier '(' DefinedValue ')' {
vlm43c8ac52006-09-17 04:52:50 +00002163 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002164 checkmem($$);
2165 $$->expr_type = A1TC_UNIVERVAL;
2166 $$->meta_type = AMT_VALUE;
2167 $$->Identifier = $1;
2168 $$->value = $3;
2169 }
2170 | SignedNumber {
vlm43c8ac52006-09-17 04:52:50 +00002171 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002172 checkmem($$);
2173 $$->expr_type = A1TC_UNIVERVAL;
2174 $$->meta_type = AMT_VALUE;
2175 $$->value = $1;
2176 }
2177 | TOK_ThreeDots {
vlm43c8ac52006-09-17 04:52:50 +00002178 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002179 checkmem($$);
2180 $$->Identifier = strdup("...");
2181 checkmem($$->Identifier);
2182 $$->expr_type = A1TC_EXTENSIBLE;
2183 $$->meta_type = AMT_VALUE;
2184 }
2185 ;
2186
2187SignedNumber:
2188 TOK_number {
2189 $$ = asn1p_value_fromint($1);
2190 checkmem($$);
2191 }
2192 | TOK_number_negative {
2193 $$ = asn1p_value_fromint($1);
2194 checkmem($$);
2195 }
2196 ;
2197
vlme745fcd2006-09-05 16:18:34 +00002198RealValue:
2199 SignedNumber
2200 | TOK_realnumber {
2201 $$ = asn1p_value_fromdouble($1);
2202 checkmem($$);
2203 }
2204 ;
2205
vlmfa67ddc2004-06-03 03:38:44 +00002206/*
2207 * SEQUENCE definition.
2208 * === EXAMPLE ===
2209 * Struct1 ::= SEQUENCE {
2210 * memb1 Struct2,
2211 * memb2 SEQUENCE OF {
2212 * memb2-1 Struct 3
2213 * }
2214 * }
2215 * === EOF ===
2216 */
2217
2218
2219
2220/*
2221 * SET definition.
2222 * === EXAMPLE ===
2223 * Person ::= SET {
2224 * name [0] PrintableString (SIZE(1..20)),
2225 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2226 * }
2227 * === EOF ===
2228 */
2229
2230optTag:
2231 { memset(&$$, 0, sizeof($$)); }
2232 | Tag { $$ = $1; }
2233 ;
2234
2235Tag:
vlm2728a8d2005-01-23 09:51:44 +00002236 TagTypeValue TagPlicit {
vlmfa67ddc2004-06-03 03:38:44 +00002237 $$ = $1;
vlm2728a8d2005-01-23 09:51:44 +00002238 $$.tag_mode = $2.tag_mode;
vlmfa67ddc2004-06-03 03:38:44 +00002239 }
vlm2728a8d2005-01-23 09:51:44 +00002240 ;
2241
2242TagTypeValue:
2243 '[' TagClass TOK_number ']' {
2244 $$ = $2;
2245 $$.tag_value = $3;
2246 };
2247
2248TagClass:
2249 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2250 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2251 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2252 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2253 ;
2254
2255TagPlicit:
2256 { $$.tag_mode = TM_DEFAULT; }
2257 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2258 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
vlmfa67ddc2004-06-03 03:38:44 +00002259 ;
2260
2261TypeRefName:
2262 TOK_typereference {
2263 checkmem($1);
2264 $$ = $1;
2265 }
vlm9283dbe2004-08-18 04:59:12 +00002266 | TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00002267 checkmem($1);
2268 $$ = $1;
2269 }
2270 ;
2271
vlm9283dbe2004-08-18 04:59:12 +00002272
vlmfa67ddc2004-06-03 03:38:44 +00002273ObjectClassReference:
vlm9283dbe2004-08-18 04:59:12 +00002274 TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00002275 checkmem($1);
2276 $$ = $1;
2277 }
2278 ;
2279
vlm151c0b22004-09-22 16:03:36 +00002280optIdentifier:
2281 { $$ = 0; }
2282 | Identifier {
2283 $$ = $1;
2284 }
vlma5b977d2005-06-06 08:28:58 +00002285 ;
vlm151c0b22004-09-22 16:03:36 +00002286
vlmfa67ddc2004-06-03 03:38:44 +00002287Identifier:
2288 TOK_identifier {
2289 checkmem($1);
2290 $$ = $1;
2291 }
2292 ;
2293
vlmfa67ddc2004-06-03 03:38:44 +00002294%%
2295
2296
2297/*
2298 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2299 */
2300static asn1p_value_t *
2301_convert_bitstring2binary(char *str, int base) {
2302 asn1p_value_t *val;
2303 int slen;
2304 int memlen;
2305 int baselen;
2306 int bits;
2307 uint8_t *binary_vector;
2308 uint8_t *bv_ptr;
2309 uint8_t cur_val;
2310
2311 assert(str);
2312 assert(str[0] == '\'');
2313
2314 switch(base) {
2315 case 'B':
2316 baselen = 1;
2317 break;
2318 case 'H':
2319 baselen = 4;
2320 break;
2321 default:
2322 assert(base == 'B' || base == 'H');
2323 errno = EINVAL;
2324 return NULL;
2325 }
2326
2327 slen = strlen(str);
2328 assert(str[slen - 1] == base);
2329 assert(str[slen - 2] == '\'');
2330
2331 memlen = slen / (8 / baselen); /* Conservative estimate */
2332
2333 bv_ptr = binary_vector = malloc(memlen + 1);
2334 if(bv_ptr == NULL)
2335 /* ENOMEM */
2336 return NULL;
2337
2338 cur_val = 0;
2339 bits = 0;
2340 while(*(++str) != '\'') {
2341 switch(baselen) {
2342 case 1:
2343 switch(*str) {
2344 case '1':
2345 cur_val |= 1 << (7 - (bits % 8));
2346 case '0':
2347 break;
2348 default:
2349 assert(!"_y UNREACH1");
2350 case ' ': case '\r': case '\n':
2351 continue;
2352 }
2353 break;
2354 case 4:
2355 switch(*str) {
2356 case '0': case '1': case '2': case '3': case '4':
2357 case '5': case '6': case '7': case '8': case '9':
2358 cur_val |= (*str - '0') << (4 - (bits % 8));
2359 break;
2360 case 'A': case 'B': case 'C':
2361 case 'D': case 'E': case 'F':
2362 cur_val |= ((*str - 'A') + 10)
2363 << (4 - (bits % 8));
2364 break;
2365 default:
2366 assert(!"_y UNREACH2");
2367 case ' ': case '\r': case '\n':
2368 continue;
2369 }
2370 break;
2371 }
2372
2373 bits += baselen;
2374 if((bits % 8) == 0) {
2375 *bv_ptr++ = cur_val;
2376 cur_val = 0;
2377 }
2378 }
2379
2380 *bv_ptr = cur_val;
2381 assert((bv_ptr - binary_vector) <= memlen);
2382
2383 val = asn1p_value_frombits(binary_vector, bits, 0);
2384 if(val == NULL) {
2385 free(binary_vector);
2386 }
2387
2388 return val;
2389}
2390
vlm5d89c3d2005-08-13 09:07:11 +00002391/*
2392 * For unnamed types (used in old X.208 compliant modules)
2393 * generate some sort of interim names, to not to force human being to fix
2394 * the specification's compliance to modern ASN.1 standards.
2395 */
2396static void
2397_fixup_anonymous_identifier(asn1p_expr_t *expr) {
2398 char *p;
2399 assert(expr->Identifier == 0);
2400
2401 /*
2402 * Try to figure out the type name
2403 * without going too much into details
2404 */
2405 expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type);
2406 if(expr->reference && expr->reference->comp_count > 0)
2407 expr->Identifier = expr->reference->components[0].name;
2408
2409 fprintf(stderr,
2410 "WARNING: Line %d: expected lower-case member identifier, "
2411 "found an unnamed %s.\n"
2412 "WARNING: Obsolete X.208 syntax detected, "
2413 "please give the member a name.\n",
2414 yylineno, expr->Identifier ? expr->Identifier : "type");
2415
2416 if(!expr->Identifier)
2417 expr->Identifier = "unnamed";
2418 expr->Identifier = strdup(expr->Identifier);
2419 assert(expr->Identifier);
2420 /* Make a lowercase identifier from the type name */
2421 for(p = expr->Identifier; *p; p++) {
2422 switch(*p) {
2423 case 'A' ... 'Z': *p += 32; break;
2424 case ' ': *p = '_'; break;
2425 case '-': *p = '_'; break;
2426 }
2427 }
2428 fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". "
2429 "Name clash may occur later.\n",
2430 expr->Identifier);
2431}
2432
vlmfa67ddc2004-06-03 03:38:44 +00002433int
2434yyerror(const char *msg) {
vlm808411d2006-03-14 16:31:37 +00002435 extern char *asn1p_text;
vlmfa67ddc2004-06-03 03:38:44 +00002436 fprintf(stderr,
2437 "ASN.1 grammar parse error "
2438 "near line %d (token \"%s\"): %s\n",
vlm39e5ed72004-09-05 10:40:41 +00002439 yylineno, asn1p_text, msg);
vlmfa67ddc2004-06-03 03:38:44 +00002440 return -1;
2441}
2442