blob: 7e638534c583c40c8d87cf15294524bdeeb4c3fc [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
vlm86851cd2006-10-13 12:37:39 +0000253%type <a_module> optImportsBundleSet
vlmfa67ddc2004-06-03 03:38:44 +0000254%type <a_module> ImportsBundleSet
255%type <a_xports> ImportsBundle
256%type <a_xports> ImportsList
257%type <a_xports> ExportsDefinition
258%type <a_xports> ExportsBody
259%type <a_expr> ImportsElement
260%type <a_expr> ExportsElement
vlmfa67ddc2004-06-03 03:38:44 +0000261%type <a_expr> ExtensionAndException
vlm43c8ac52006-09-17 04:52:50 +0000262%type <a_expr> Type
vlmec8f6812004-08-22 03:19:54 +0000263%type <a_expr> TypeDeclaration
vlm066dc102005-08-22 12:23:54 +0000264%type <a_expr> TypeDeclarationSet
vlmfa67ddc2004-06-03 03:38:44 +0000265%type <a_ref> ComplexTypeReference
266%type <a_ref> ComplexTypeReferenceAmpList
267%type <a_refcomp> ComplexTypeReferenceElement
vlma6a84d72006-03-16 10:03:35 +0000268%type <a_refcomp> PrimitiveFieldReference
vlmdc7cf042006-03-09 08:49:26 +0000269%type <a_expr> FieldSpec
270%type <a_ref> FieldName
271%type <a_ref> DefinedObjectClass
vlmfa67ddc2004-06-03 03:38:44 +0000272%type <a_expr> ClassField
vlmdc7cf042006-03-09 08:49:26 +0000273%type <a_expr> ObjectClass
vlmfa67ddc2004-06-03 03:38:44 +0000274%type <a_expr> DataTypeReference /* Type1 ::= Type2 */
vlm17e65d02006-03-21 04:48:15 +0000275%type <a_expr> DefinedType
vlm59b620a2006-03-21 07:46:48 +0000276%type <a_constr> ValueSet /* {a|b|c}*/
277%type <a_expr> ValueSetTypeAssignment /* Val INTEGER ::= {1|2} */
vlmfa67ddc2004-06-03 03:38:44 +0000278%type <a_expr> ValueDefinition /* val INTEGER ::= 1*/
vlmc94e28f2004-09-15 11:59:51 +0000279%type <a_value> Value
vlm17e65d02006-03-21 04:48:15 +0000280%type <a_value> SimpleValue
vlmfa67ddc2004-06-03 03:38:44 +0000281%type <a_value> DefinedValue
282%type <a_value> SignedNumber
vlme745fcd2006-09-05 16:18:34 +0000283%type <a_value> RealValue
vlm0aa86902004-10-12 23:26:53 +0000284%type <a_expr> optComponentTypeLists
vlmec8f6812004-08-22 03:19:54 +0000285%type <a_expr> ComponentTypeLists
286%type <a_expr> ComponentType
287%type <a_expr> AlternativeTypeLists
288%type <a_expr> AlternativeType
vlmfa67ddc2004-06-03 03:38:44 +0000289%type <a_expr> UniverationDefinition
290%type <a_expr> UniverationList
291%type <a_expr> UniverationElement
292%type <tv_str> TypeRefName
293%type <tv_str> ObjectClassReference
vlmfa67ddc2004-06-03 03:38:44 +0000294%type <tv_str> Identifier
vlm151c0b22004-09-22 16:03:36 +0000295%type <tv_str> optIdentifier
vlmfa67ddc2004-06-03 03:38:44 +0000296%type <a_parg> ParameterArgumentName
297%type <a_plist> ParameterArgumentList
vlmdfbff8c2006-03-21 09:41:28 +0000298%type <a_expr> ActualParameter
299%type <a_expr> ActualParameterList
vlm04a08da2005-08-12 10:06:17 +0000300%type <a_aid> AssignedIdentifier /* OID/DefinedValue */
vlmfa67ddc2004-06-03 03:38:44 +0000301%type <a_oid> ObjectIdentifier /* OID */
302%type <a_oid> optObjectIdentifier /* Optional OID */
303%type <a_oid> ObjectIdentifierBody
304%type <a_oid_arc> ObjectIdentifierElement
305%type <a_expr> BasicType
306%type <a_type> BasicTypeId
307%type <a_type> BasicTypeId_UniverationCompatible
308%type <a_type> BasicString
309%type <tv_opaque> Opaque
vlm2728a8d2005-01-23 09:51:44 +0000310%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
311%type <a_tag> TagClass TagTypeValue TagPlicit
vlmfa67ddc2004-06-03 03:38:44 +0000312%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
313%type <a_constr> optConstraints
vlm43c8ac52006-09-17 04:52:50 +0000314%type <a_constr> Constraint
315%type <a_constr> SubtypeConstraint
316%type <a_constr> GeneralConstraint
vlm9283dbe2004-08-18 04:59:12 +0000317%type <a_constr> SetOfConstraints
318%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
319%type <a_constr> ElementSetSpec /* 1..2,...,3 */
vlm1bc782f2006-09-21 01:50:37 +0000320%type <a_constr> Unions
321%type <a_constr> Intersections
322%type <a_constr> IntersectionElements
vlmfa67ddc2004-06-03 03:38:44 +0000323%type <a_constr> ConstraintSubtypeElement /* 1..2 */
vlmfa67ddc2004-06-03 03:38:44 +0000324%type <a_constr> SimpleTableConstraint
vlm43c8ac52006-09-17 04:52:50 +0000325%type <a_constr> UserDefinedConstraint
vlmfa67ddc2004-06-03 03:38:44 +0000326%type <a_constr> TableConstraint
vlm43c8ac52006-09-17 04:52:50 +0000327%type <a_constr> ContentsConstraint
vlm7bbdc9f2005-03-28 15:01:27 +0000328%type <a_constr> InnerTypeConstraint
vlmfa67ddc2004-06-03 03:38:44 +0000329%type <a_constr> WithComponentsList
330%type <a_constr> WithComponentsElement
331%type <a_constr> ComponentRelationConstraint
332%type <a_constr> AtNotationList
333%type <a_ref> AtNotationElement
vlma6a12e32005-03-20 12:58:00 +0000334%type <a_value> SingleValue
335%type <a_value> ContainedSubtype
vlmfa67ddc2004-06-03 03:38:44 +0000336%type <a_ctype> ConstraintSpec
337%type <a_ctype> ConstraintRangeSpec
vlme1e6ed82005-03-24 14:26:38 +0000338%type <a_value> RestrictedCharacterStringValue
vlmfa67ddc2004-06-03 03:38:44 +0000339%type <a_wsynt> optWithSyntax
340%type <a_wsynt> WithSyntax
vlm808411d2006-03-14 16:31:37 +0000341%type <a_wsynt> WithSyntaxList
342%type <a_wchunk> WithSyntaxToken
vlmfa67ddc2004-06-03 03:38:44 +0000343%type <a_marker> optMarker Marker
344%type <a_int> optUnique
345%type <a_pres> optPresenceConstraint PresenceConstraint
346%type <tv_str> ComponentIdList
vlm177a5b62005-09-05 05:17:57 +0000347%type <a_int> NSTD_IndirectMarker
vlmfa67ddc2004-06-03 03:38:44 +0000348
349
350%%
351
352
353ParsedGrammar:
354 ModuleList {
355 *(void **)param = $1;
356 }
357 ;
358
359ModuleList:
vlmd3420d32006-09-14 10:35:20 +0000360 ModuleDefinition {
vlmfa67ddc2004-06-03 03:38:44 +0000361 $$ = asn1p_new();
362 checkmem($$);
363 TQ_ADD(&($$->modules), $1, mod_next);
364 }
vlmd3420d32006-09-14 10:35:20 +0000365 | ModuleList ModuleDefinition {
vlmfa67ddc2004-06-03 03:38:44 +0000366 $$ = $1;
367 TQ_ADD(&($$->modules), $2, mod_next);
368 }
369 ;
370
371/*
372 * ASN module definition.
373 * === EXAMPLE ===
374 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
375 * BEGIN
376 * ...
377 * END
378 * === EOF ===
379 */
380
vlmd3420d32006-09-14 10:35:20 +0000381ModuleDefinition:
vlm43c8ac52006-09-17 04:52:50 +0000382 TypeRefName { currentModule = asn1p_module_new(); }
383 optObjectIdentifier TOK_DEFINITIONS
vlmd3420d32006-09-14 10:35:20 +0000384 optModuleDefinitionFlags
vlmfa67ddc2004-06-03 03:38:44 +0000385 TOK_PPEQ TOK_BEGIN
vlmd3420d32006-09-14 10:35:20 +0000386 optModuleBody
vlmfa67ddc2004-06-03 03:38:44 +0000387 TOK_END {
388
vlm43c8ac52006-09-17 04:52:50 +0000389 $$ = currentModule;
390
391 if($8) {
392 asn1p_module_t tmp = *($$);
393 *($$) = *($8);
394 *($8) = tmp;
395 asn1p_module_free($8);
vlmfa67ddc2004-06-03 03:38:44 +0000396 } else {
397 /* There's a chance that a module is just plain empty */
vlmfa67ddc2004-06-03 03:38:44 +0000398 }
vlmfa67ddc2004-06-03 03:38:44 +0000399
vlm04a08da2005-08-12 10:06:17 +0000400 $$->ModuleName = $1;
vlm43c8ac52006-09-17 04:52:50 +0000401 $$->module_oid = $3;
402 $$->module_flags = $5;
vlmfa67ddc2004-06-03 03:38:44 +0000403 }
404 ;
405
406/*
407 * Object Identifier Definition
408 * { iso member-body(2) 3 }
409 */
410optObjectIdentifier:
411 { $$ = 0; }
412 | ObjectIdentifier { $$ = $1; }
413 ;
414
415ObjectIdentifier:
416 '{' ObjectIdentifierBody '}' {
417 $$ = $2;
418 }
419 | '{' '}' {
420 $$ = 0;
421 }
422 ;
423
424ObjectIdentifierBody:
425 ObjectIdentifierElement {
426 $$ = asn1p_oid_new();
427 asn1p_oid_add_arc($$, &$1);
428 if($1.name)
429 free($1.name);
430 }
431 | ObjectIdentifierBody ObjectIdentifierElement {
432 $$ = $1;
433 asn1p_oid_add_arc($$, &$2);
434 if($2.name)
435 free($2.name);
436 }
437 ;
438
439ObjectIdentifierElement:
440 Identifier { /* iso */
441 $$.name = $1;
442 $$.number = -1;
443 }
444 | Identifier '(' TOK_number ')' { /* iso(1) */
445 $$.name = $1;
446 $$.number = $3;
447 }
448 | TOK_number { /* 1 */
449 $$.name = 0;
450 $$.number = $1;
451 }
452 ;
453
454/*
455 * Optional module flags.
456 */
vlmd3420d32006-09-14 10:35:20 +0000457optModuleDefinitionFlags:
vlmfa67ddc2004-06-03 03:38:44 +0000458 { $$ = MSF_NOFLAGS; }
vlmd3420d32006-09-14 10:35:20 +0000459 | ModuleDefinitionFlags {
vlmfa67ddc2004-06-03 03:38:44 +0000460 $$ = $1;
461 }
462 ;
463
464/*
465 * Module flags.
466 */
vlmd3420d32006-09-14 10:35:20 +0000467ModuleDefinitionFlags:
468 ModuleDefinitionFlag {
vlmfa67ddc2004-06-03 03:38:44 +0000469 $$ = $1;
470 }
vlmd3420d32006-09-14 10:35:20 +0000471 | ModuleDefinitionFlags ModuleDefinitionFlag {
vlmfa67ddc2004-06-03 03:38:44 +0000472 $$ = $1 | $2;
473 }
474 ;
475
476/*
477 * Single module flag.
478 */
vlmd3420d32006-09-14 10:35:20 +0000479ModuleDefinitionFlag:
vlmfa67ddc2004-06-03 03:38:44 +0000480 TOK_EXPLICIT TOK_TAGS {
481 $$ = MSF_EXPLICIT_TAGS;
482 }
483 | TOK_IMPLICIT TOK_TAGS {
484 $$ = MSF_IMPLICIT_TAGS;
485 }
486 | TOK_AUTOMATIC TOK_TAGS {
487 $$ = MSF_AUTOMATIC_TAGS;
488 }
489 | TOK_EXTENSIBILITY TOK_IMPLIED {
490 $$ = MSF_EXTENSIBILITY_IMPLIED;
491 }
vlm9283dbe2004-08-18 04:59:12 +0000492 /* EncodingReferenceDefault */
493 | TOK_capitalreference TOK_INSTRUCTIONS {
494 /* X.680Amd1 specifies TAG and XER */
495 if(strcmp($1, "TAG") == 0) {
496 $$ = MSF_TAG_INSTRUCTIONS;
497 } else if(strcmp($1, "XER") == 0) {
498 $$ = MSF_XER_INSTRUCTIONS;
499 } else {
500 fprintf(stderr,
501 "WARNING: %s INSTRUCTIONS at line %d: "
502 "Unrecognized encoding reference\n",
503 $1, yylineno);
504 $$ = MSF_unk_INSTRUCTIONS;
505 }
506 free($1);
507 }
vlmfa67ddc2004-06-03 03:38:44 +0000508 ;
509
510/*
511 * Optional module body.
512 */
vlmd3420d32006-09-14 10:35:20 +0000513optModuleBody:
vlmfa67ddc2004-06-03 03:38:44 +0000514 { $$ = 0; }
vlmd3420d32006-09-14 10:35:20 +0000515 | ModuleBody {
vlmfa67ddc2004-06-03 03:38:44 +0000516 $$ = $1;
517 }
518 ;
519
520/*
521 * ASN.1 Module body.
522 */
vlmd3420d32006-09-14 10:35:20 +0000523ModuleBody:
524 optExports optImports AssignmentList {
525 $$ = asn1p_module_new();
526 AL_IMPORT($$, exports, $1, xp_next);
527 AL_IMPORT($$, imports, $2, xp_next);
528 AL_IMPORT($$, members, $3, next);
vlmfa67ddc2004-06-03 03:38:44 +0000529 }
530 ;
531
vlmd3420d32006-09-14 10:35:20 +0000532AssignmentList:
533 Assignment {
534 $$ = $1;
535 }
536 | AssignmentList Assignment {
537 if($1) {
538 $$ = $1;
539 } else {
540 $$ = $2;
541 break;
542 }
543 AL_IMPORT($$, members, $2, next);
544 }
545 ;
546
547
vlmfa67ddc2004-06-03 03:38:44 +0000548/*
549 * One of the elements of ASN.1 module specification.
550 */
vlmd3420d32006-09-14 10:35:20 +0000551Assignment:
552 DataTypeReference {
vlmfa67ddc2004-06-03 03:38:44 +0000553 $$ = asn1p_module_new();
554 checkmem($$);
555 assert($1->expr_type != A1TC_INVALID);
556 assert($1->meta_type != AMT_INVALID);
557 TQ_ADD(&($$->members), $1, next);
558 }
559 | ValueDefinition {
560 $$ = asn1p_module_new();
561 checkmem($$);
562 assert($1->expr_type != A1TC_INVALID);
563 assert($1->meta_type != AMT_INVALID);
564 TQ_ADD(&($$->members), $1, next);
565 }
566 /*
567 * Value set definition
568 * === EXAMPLE ===
569 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
570 * === EOF ===
571 */
vlm59b620a2006-03-21 07:46:48 +0000572 | ValueSetTypeAssignment {
vlmfa67ddc2004-06-03 03:38:44 +0000573 $$ = asn1p_module_new();
574 checkmem($$);
575 assert($1->expr_type != A1TC_INVALID);
576 assert($1->meta_type != AMT_INVALID);
577 TQ_ADD(&($$->members), $1, next);
578 }
vlm9283dbe2004-08-18 04:59:12 +0000579 | TOK_ENCODING_CONTROL TOK_capitalreference
580 { asn1p_lexer_hack_push_encoding_control(); }
581 {
582 fprintf(stderr,
583 "WARNING: ENCODING-CONTROL %s "
584 "specification at line %d ignored\n",
585 $2, yylineno);
586 free($2);
587 $$ = 0;
588 }
vlmfa67ddc2004-06-03 03:38:44 +0000589
590 /*
591 * Erroneous attemps
592 */
593 | BasicString {
594 return yyerror(
vlm1ac75e72005-11-26 11:21:55 +0000595 "Attempt to redefine a standard basic string type, "
596 "please comment out or remove this type redefinition.");
vlmfa67ddc2004-06-03 03:38:44 +0000597 }
598 ;
599
600/*
601 * === EXAMPLE ===
602 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
603 * === EOF ===
604 */
vlmd3420d32006-09-14 10:35:20 +0000605optImports:
606 { $$ = 0; }
607 | ImportsDefinition;
608
vlmfa67ddc2004-06-03 03:38:44 +0000609ImportsDefinition:
vlm86851cd2006-10-13 12:37:39 +0000610 TOK_IMPORTS optImportsBundleSet ';' {
vlm04a08da2005-08-12 10:06:17 +0000611 if(!saved_aid && 0)
612 return yyerror("Unterminated IMPORTS FROM, "
613 "expected semicolon ';'");
614 saved_aid = 0;
vlmfa67ddc2004-06-03 03:38:44 +0000615 $$ = $2;
616 }
617 /*
618 * Some error cases.
619 */
620 | TOK_IMPORTS TOK_FROM /* ... */ {
621 return yyerror("Empty IMPORTS list");
622 }
623 ;
624
vlm86851cd2006-10-13 12:37:39 +0000625optImportsBundleSet:
626 { $$ = asn1p_module_new(); }
627 | ImportsBundleSet;
628
vlmfa67ddc2004-06-03 03:38:44 +0000629ImportsBundleSet:
630 ImportsBundle {
631 $$ = asn1p_module_new();
632 checkmem($$);
633 TQ_ADD(&($$->imports), $1, xp_next);
634 }
635 | ImportsBundleSet ImportsBundle {
636 $$ = $1;
637 TQ_ADD(&($$->imports), $2, xp_next);
638 }
639 ;
640
vlm04a08da2005-08-12 10:06:17 +0000641AssignedIdentifier:
642 { memset(&$$, 0, sizeof($$)); }
643 | ObjectIdentifier { $$.oid = $1; };
644 /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
645
vlmfa67ddc2004-06-03 03:38:44 +0000646ImportsBundle:
vlm04a08da2005-08-12 10:06:17 +0000647 ImportsList TOK_FROM TypeRefName AssignedIdentifier {
vlmfa67ddc2004-06-03 03:38:44 +0000648 $$ = $1;
vlm04a08da2005-08-12 10:06:17 +0000649 $$->fromModuleName = $3;
650 $$->identifier = $4;
651 /* This stupid thing is used for look-back hack. */
652 saved_aid = $$->identifier.oid ? 0 : &($$->identifier);
vlmfa67ddc2004-06-03 03:38:44 +0000653 checkmem($$);
654 }
655 ;
656
657ImportsList:
658 ImportsElement {
659 $$ = asn1p_xports_new();
660 checkmem($$);
661 TQ_ADD(&($$->members), $1, next);
662 }
663 | ImportsList ',' ImportsElement {
664 $$ = $1;
665 TQ_ADD(&($$->members), $3, next);
666 }
667 ;
668
669ImportsElement:
670 TypeRefName {
vlm43c8ac52006-09-17 04:52:50 +0000671 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000672 checkmem($$);
673 $$->Identifier = $1;
674 $$->expr_type = A1TC_REFERENCE;
675 }
vlm0aa86902004-10-12 23:26:53 +0000676 | TypeRefName '{' '}' { /* Completely equivalent to above */
vlm43c8ac52006-09-17 04:52:50 +0000677 $$ = NEW_EXPR();
vlm0aa86902004-10-12 23:26:53 +0000678 checkmem($$);
679 $$->Identifier = $1;
680 $$->expr_type = A1TC_REFERENCE;
681 }
vlmfa67ddc2004-06-03 03:38:44 +0000682 | Identifier {
vlm43c8ac52006-09-17 04:52:50 +0000683 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000684 checkmem($$);
685 $$->Identifier = $1;
686 $$->expr_type = A1TC_REFERENCE;
687 }
688 ;
689
vlmd3420d32006-09-14 10:35:20 +0000690
691optExports:
692 { $$ = 0; }
693 | ExportsDefinition {
694 $$ = asn1p_module_new();
695 checkmem($$);
696 if($1) {
697 TQ_ADD(&($$->exports), $1, xp_next);
698 } else {
699 /* "EXPORTS ALL;" */
700 }
701 }
702 ;
703
vlmfa67ddc2004-06-03 03:38:44 +0000704ExportsDefinition:
705 TOK_EXPORTS ExportsBody ';' {
706 $$ = $2;
707 }
708 | TOK_EXPORTS TOK_ALL ';' {
709 $$ = 0;
710 }
711 | TOK_EXPORTS ';' {
712 /* Empty EXPORTS clause effectively prohibits export. */
713 $$ = asn1p_xports_new();
714 checkmem($$);
715 }
716 ;
717
718ExportsBody:
719 ExportsElement {
720 $$ = asn1p_xports_new();
721 assert($$);
722 TQ_ADD(&($$->members), $1, next);
723 }
724 | ExportsBody ',' ExportsElement {
725 $$ = $1;
726 TQ_ADD(&($$->members), $3, next);
727 }
728 ;
729
730ExportsElement:
731 TypeRefName {
vlm43c8ac52006-09-17 04:52:50 +0000732 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000733 checkmem($$);
734 $$->Identifier = $1;
735 $$->expr_type = A1TC_EXPORTVAR;
736 }
vlm0aa86902004-10-12 23:26:53 +0000737 | TypeRefName '{' '}' {
vlm43c8ac52006-09-17 04:52:50 +0000738 $$ = NEW_EXPR();
vlm0aa86902004-10-12 23:26:53 +0000739 checkmem($$);
740 $$->Identifier = $1;
741 $$->expr_type = A1TC_EXPORTVAR;
742 }
vlmfa67ddc2004-06-03 03:38:44 +0000743 | Identifier {
vlm43c8ac52006-09-17 04:52:50 +0000744 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000745 checkmem($$);
746 $$->Identifier = $1;
747 $$->expr_type = A1TC_EXPORTVAR;
748 }
749 ;
750
751
vlm1aeaddd2006-07-13 08:24:20 +0000752ValueSet: '{' ElementSetSpecs '}' { $$ = $2; };
vlm59b620a2006-03-21 07:46:48 +0000753
754ValueSetTypeAssignment:
755 TypeRefName DefinedType TOK_PPEQ ValueSet {
vlmfa67ddc2004-06-03 03:38:44 +0000756 $$ = $2;
757 assert($$->Identifier == 0);
758 $$->Identifier = $1;
759 $$->meta_type = AMT_VALUESET;
vlm59b620a2006-03-21 07:46:48 +0000760 $$->constraints = $4;
vlmfa67ddc2004-06-03 03:38:44 +0000761 }
762 ;
763
vlm17e65d02006-03-21 04:48:15 +0000764DefinedType:
765 BasicType {
766 $$ = $1;
767 }
768 /*
769 * A DefinedType reference.
770 * "CLASS1.&id.&id2"
771 * or
772 * "Module.Type"
773 * or
774 * "Module.identifier"
775 * or
776 * "Type"
777 */
778 | ComplexTypeReference {
vlm43c8ac52006-09-17 04:52:50 +0000779 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000780 checkmem($$);
781 $$->reference = $1;
782 $$->expr_type = A1TC_REFERENCE;
783 $$->meta_type = AMT_TYPEREF;
784 }
vlm17e65d02006-03-21 04:48:15 +0000785 /*
vlmdfbff8c2006-03-21 09:41:28 +0000786 * A parameterized assignment.
vlm17e65d02006-03-21 04:48:15 +0000787 */
vlmdfbff8c2006-03-21 09:41:28 +0000788 | ComplexTypeReference '{' ActualParameterList '}' {
vlm43c8ac52006-09-17 04:52:50 +0000789 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000790 checkmem($$);
vlm17e65d02006-03-21 04:48:15 +0000791 $$->reference = $1;
792 $$->rhs_pspecs = $3;
793 $$->expr_type = A1TC_REFERENCE;
794 $$->meta_type = AMT_TYPEREF;
vlmfa67ddc2004-06-03 03:38:44 +0000795 }
796 ;
797
vlmfa67ddc2004-06-03 03:38:44 +0000798/*
799 * Data Type Reference.
800 * === EXAMPLE ===
801 * Type3 ::= CHOICE { a Type1, b Type 2 }
802 * === EOF ===
803 */
vlmfa67ddc2004-06-03 03:38:44 +0000804DataTypeReference:
805 /*
806 * Optionally tagged type definition.
807 */
vlmdc7cf042006-03-09 08:49:26 +0000808 TypeRefName TOK_PPEQ Type {
vlmfce48a42004-09-14 02:36:39 +0000809 $$ = $3;
vlmfa67ddc2004-06-03 03:38:44 +0000810 $$->Identifier = $1;
vlmfa67ddc2004-06-03 03:38:44 +0000811 assert($$->expr_type);
812 assert($$->meta_type);
813 }
vlmdc7cf042006-03-09 08:49:26 +0000814 | TypeRefName TOK_PPEQ ObjectClass {
vlmfa67ddc2004-06-03 03:38:44 +0000815 $$ = $3;
816 $$->Identifier = $1;
817 assert($$->expr_type == A1TC_CLASSDEF);
vlmdc7cf042006-03-09 08:49:26 +0000818 assert($$->meta_type == AMT_OBJECTCLASS);
vlmfa67ddc2004-06-03 03:38:44 +0000819 }
820 /*
vlmdfbff8c2006-03-21 09:41:28 +0000821 * Parameterized <Type> declaration:
vlmfa67ddc2004-06-03 03:38:44 +0000822 * === EXAMPLE ===
823 * SIGNED { ToBeSigned } ::= SEQUENCE {
824 * toBeSigned ToBeSigned,
825 * algorithm AlgorithmIdentifier,
826 * signature BIT STRING
827 * }
828 * === EOF ===
829 */
vlmec8f6812004-08-22 03:19:54 +0000830 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
vlmfa67ddc2004-06-03 03:38:44 +0000831 $$ = $6;
vlmdfbff8c2006-03-21 09:41:28 +0000832 $$->Identifier = $1;
833 $$->lhs_params = $3;
834 }
835 /* Parameterized CLASS declaration */
836 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ ObjectClass {
837 $$ = $6;
vlmfa67ddc2004-06-03 03:38:44 +0000838 $$->Identifier = $1;
vlm0c6d3812006-03-21 03:40:38 +0000839 $$->lhs_params = $3;
vlmfa67ddc2004-06-03 03:38:44 +0000840 }
841 ;
842
843ParameterArgumentList:
844 ParameterArgumentName {
845 int ret;
846 $$ = asn1p_paramlist_new(yylineno);
847 checkmem($$);
848 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
849 checkmem(ret == 0);
850 if($1.governor) asn1p_ref_free($1.governor);
851 if($1.argument) free($1.argument);
852 }
853 | ParameterArgumentList ',' ParameterArgumentName {
854 int ret;
855 $$ = $1;
856 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
857 checkmem(ret == 0);
858 if($3.governor) asn1p_ref_free($3.governor);
859 if($3.argument) free($3.argument);
860 }
861 ;
862
863ParameterArgumentName:
864 TypeRefName {
865 $$.governor = NULL;
866 $$.argument = $1;
867 }
868 | TypeRefName ':' Identifier {
869 int ret;
870 $$.governor = asn1p_ref_new(yylineno);
871 ret = asn1p_ref_add_component($$.governor, $1, 0);
872 checkmem(ret == 0);
873 $$.argument = $3;
874 }
vlm4053ca52005-02-18 16:34:21 +0000875 | TypeRefName ':' TypeRefName {
876 int ret;
877 $$.governor = asn1p_ref_new(yylineno);
878 ret = asn1p_ref_add_component($$.governor, $1, 0);
879 checkmem(ret == 0);
880 $$.argument = $3;
881 }
vlmfa67ddc2004-06-03 03:38:44 +0000882 | BasicTypeId ':' Identifier {
883 int ret;
884 $$.governor = asn1p_ref_new(yylineno);
885 ret = asn1p_ref_add_component($$.governor,
886 ASN_EXPR_TYPE2STR($1), 1);
887 checkmem(ret == 0);
888 $$.argument = $3;
889 }
vlmdfbff8c2006-03-21 09:41:28 +0000890 | BasicTypeId ':' TypeRefName {
891 int ret;
892 $$.governor = asn1p_ref_new(yylineno);
893 ret = asn1p_ref_add_component($$.governor,
894 ASN_EXPR_TYPE2STR($1), 1);
895 checkmem(ret == 0);
896 $$.argument = $3;
897 }
vlmfa67ddc2004-06-03 03:38:44 +0000898 ;
899
vlmdfbff8c2006-03-21 09:41:28 +0000900ActualParameterList:
901 ActualParameter {
vlm43c8ac52006-09-17 04:52:50 +0000902 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000903 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000904 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000905 }
vlmdfbff8c2006-03-21 09:41:28 +0000906 | ActualParameterList ',' ActualParameter {
vlmfa67ddc2004-06-03 03:38:44 +0000907 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000908 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000909 }
910 ;
911
vlmdfbff8c2006-03-21 09:41:28 +0000912ActualParameter:
vlmec8f6812004-08-22 03:19:54 +0000913 Type {
vlmfa67ddc2004-06-03 03:38:44 +0000914 $$ = $1;
915 }
vlm17e65d02006-03-21 04:48:15 +0000916 | SimpleValue {
vlm43c8ac52006-09-17 04:52:50 +0000917 $$ = NEW_EXPR();
vlm17e65d02006-03-21 04:48:15 +0000918 checkmem($$);
919 $$->Identifier = "?";
920 $$->expr_type = A1TC_REFERENCE;
921 $$->meta_type = AMT_VALUE;
922 $$->value = $1;
923 }
vlmfa67ddc2004-06-03 03:38:44 +0000924 | Identifier {
vlm0c6d3812006-03-21 03:40:38 +0000925 asn1p_ref_t *ref;
vlm43c8ac52006-09-17 04:52:50 +0000926 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000927 checkmem($$);
928 $$->Identifier = $1;
929 $$->expr_type = A1TC_REFERENCE;
930 $$->meta_type = AMT_VALUE;
vlm0c6d3812006-03-21 03:40:38 +0000931 ref = asn1p_ref_new(yylineno);
932 asn1p_ref_add_component(ref, $1, RLT_lowercase);
933 $$->value = asn1p_value_fromref(ref, 0);
vlmfa67ddc2004-06-03 03:38:44 +0000934 }
vlmdfbff8c2006-03-21 09:41:28 +0000935 | ValueSet {
vlm43c8ac52006-09-17 04:52:50 +0000936 $$ = NEW_EXPR();
vlmdfbff8c2006-03-21 09:41:28 +0000937 $$->expr_type = A1TC_VALUESET;
938 $$->meta_type = AMT_VALUESET;
939 $$->constraints = $1;
940 }
vlmfa67ddc2004-06-03 03:38:44 +0000941 ;
942
943/*
vlmdfbff8c2006-03-21 09:41:28 +0000944 | '{' ActualParameter '}' {
vlm43c8ac52006-09-17 04:52:50 +0000945 $$ = NEW_EXPR();
vlm4053ca52005-02-18 16:34:21 +0000946 checkmem($$);
947 asn1p_expr_add($$, $2);
948 $$->expr_type = A1TC_PARAMETRIZED;
949 $$->meta_type = AMT_TYPE;
950 }
951 ;
952*/
953
954/*
vlmfa67ddc2004-06-03 03:38:44 +0000955 * A collection of constructed data type members.
956 */
vlm0aa86902004-10-12 23:26:53 +0000957optComponentTypeLists:
vlm43c8ac52006-09-17 04:52:50 +0000958 { $$ = NEW_EXPR(); }
vlm0aa86902004-10-12 23:26:53 +0000959 | ComponentTypeLists { $$ = $1; };
960
vlmec8f6812004-08-22 03:19:54 +0000961ComponentTypeLists:
962 ComponentType {
vlm43c8ac52006-09-17 04:52:50 +0000963 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000964 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000965 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000966 }
vlmec8f6812004-08-22 03:19:54 +0000967 | ComponentTypeLists ',' ComponentType {
vlmfa67ddc2004-06-03 03:38:44 +0000968 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000969 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000970 }
971 ;
972
vlmec8f6812004-08-22 03:19:54 +0000973ComponentType:
vlmfce48a42004-09-14 02:36:39 +0000974 Identifier Type optMarker {
vlmec8f6812004-08-22 03:19:54 +0000975 $$ = $2;
976 assert($$->Identifier == 0);
vlmfce48a42004-09-14 02:36:39 +0000977 $$->Identifier = $1;
vlm177a5b62005-09-05 05:17:57 +0000978 $3.flags |= $$->marker.flags;
vlmec8f6812004-08-22 03:19:54 +0000979 $$->marker = $3;
980 }
vlm177a5b62005-09-05 05:17:57 +0000981 | Type optMarker {
982 $$ = $1;
983 $2.flags |= $$->marker.flags;
984 $$->marker = $2;
985 _fixup_anonymous_identifier($$);
986 }
vlmec8f6812004-08-22 03:19:54 +0000987 | TOK_COMPONENTS TOK_OF Type {
vlm43c8ac52006-09-17 04:52:50 +0000988 $$ = NEW_EXPR();
vlmec8f6812004-08-22 03:19:54 +0000989 checkmem($$);
990 $$->meta_type = $3->meta_type;
991 $$->expr_type = A1TC_COMPONENTS_OF;
vlm6a02a8a2004-09-08 00:28:11 +0000992 asn1p_expr_add($$, $3);
vlmec8f6812004-08-22 03:19:54 +0000993 }
994 | ExtensionAndException {
995 $$ = $1;
996 }
997 ;
998
999AlternativeTypeLists:
1000 AlternativeType {
vlm43c8ac52006-09-17 04:52:50 +00001001 $$ = NEW_EXPR();
vlmec8f6812004-08-22 03:19:54 +00001002 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +00001003 asn1p_expr_add($$, $1);
vlmec8f6812004-08-22 03:19:54 +00001004 }
1005 | AlternativeTypeLists ',' AlternativeType {
1006 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +00001007 asn1p_expr_add($$, $3);
vlmec8f6812004-08-22 03:19:54 +00001008 }
1009 ;
1010
1011AlternativeType:
vlmfce48a42004-09-14 02:36:39 +00001012 Identifier Type {
vlmec8f6812004-08-22 03:19:54 +00001013 $$ = $2;
1014 assert($$->Identifier == 0);
vlmfce48a42004-09-14 02:36:39 +00001015 $$->Identifier = $1;
vlmec8f6812004-08-22 03:19:54 +00001016 }
1017 | ExtensionAndException {
1018 $$ = $1;
1019 }
vlm5d89c3d2005-08-13 09:07:11 +00001020 | Type {
1021 $$ = $1;
1022 _fixup_anonymous_identifier($$);
1023 }
vlmec8f6812004-08-22 03:19:54 +00001024 ;
1025
vlmdc7cf042006-03-09 08:49:26 +00001026ObjectClass:
1027 TOK_CLASS '{' FieldSpec '}' optWithSyntax {
vlmfa67ddc2004-06-03 03:38:44 +00001028 $$ = $3;
1029 checkmem($$);
1030 $$->with_syntax = $5;
1031 assert($$->expr_type == A1TC_CLASSDEF);
vlmdc7cf042006-03-09 08:49:26 +00001032 assert($$->meta_type == AMT_OBJECTCLASS);
vlmfa67ddc2004-06-03 03:38:44 +00001033 }
1034 ;
1035
1036optUnique:
1037 { $$ = 0; }
1038 | TOK_UNIQUE { $$ = 1; }
1039 ;
1040
vlmdc7cf042006-03-09 08:49:26 +00001041FieldSpec:
vlmfa67ddc2004-06-03 03:38:44 +00001042 ClassField {
vlm43c8ac52006-09-17 04:52:50 +00001043 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001044 checkmem($$);
1045 $$->expr_type = A1TC_CLASSDEF;
vlmdc7cf042006-03-09 08:49:26 +00001046 $$->meta_type = AMT_OBJECTCLASS;
vlm6a02a8a2004-09-08 00:28:11 +00001047 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +00001048 }
vlmdc7cf042006-03-09 08:49:26 +00001049 | FieldSpec ',' ClassField {
vlmfa67ddc2004-06-03 03:38:44 +00001050 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +00001051 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001052 }
1053 ;
1054
vlmdc7cf042006-03-09 08:49:26 +00001055 /* X.681 */
vlmfa67ddc2004-06-03 03:38:44 +00001056ClassField:
vlmdc7cf042006-03-09 08:49:26 +00001057
1058 /* TypeFieldSpec ::= typefieldreference TypeOptionalitySpec? */
1059 TOK_typefieldreference optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001060 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001061 checkmem($$);
vlmdc7cf042006-03-09 08:49:26 +00001062 $$->Identifier = $1;
vlmfa67ddc2004-06-03 03:38:44 +00001063 $$->meta_type = AMT_OBJECTFIELD;
vlmdc7cf042006-03-09 08:49:26 +00001064 $$->expr_type = A1TC_CLASSFIELD_TFS; /* TypeFieldSpec */
vlmfa67ddc2004-06-03 03:38:44 +00001065 $$->marker = $2;
1066 }
vlmdc7cf042006-03-09 08:49:26 +00001067
1068 /* FixedTypeValueFieldSpec ::= valuefieldreference Type UNIQUE ? ValueOptionalitySpec ? */
1069 | TOK_valuefieldreference Type optUnique optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001070 $$ = NEW_EXPR();
vlmdc7cf042006-03-09 08:49:26 +00001071 $$->Identifier = $1;
1072 $$->meta_type = AMT_OBJECTFIELD;
1073 $$->expr_type = A1TC_CLASSFIELD_FTVFS; /* FixedTypeValueFieldSpec */
vlmbde35d42004-11-24 17:43:29 +00001074 $$->unique = $3;
vlmdc7cf042006-03-09 08:49:26 +00001075 $$->marker = $4;
1076 asn1p_expr_add($$, $2);
vlmfa67ddc2004-06-03 03:38:44 +00001077 }
vlmdc7cf042006-03-09 08:49:26 +00001078
1079 /* VariableTypeValueFieldSpec ::= valuefieldreference FieldName ValueOptionalitySpec ? */
1080 | TOK_valuefieldreference FieldName optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001081 $$ = NEW_EXPR();
vlmdc7cf042006-03-09 08:49:26 +00001082 $$->Identifier = $1;
1083 $$->meta_type = AMT_OBJECTFIELD;
1084 $$->expr_type = A1TC_CLASSFIELD_VTVFS;
1085 $$->reference = $2;
1086 $$->marker = $3;
1087 }
1088
vlmdc7cf042006-03-09 08:49:26 +00001089 /* ObjectFieldSpec ::= objectfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1090 | TOK_valuefieldreference DefinedObjectClass optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001091 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001092 checkmem($$);
vlmdc7cf042006-03-09 08:49:26 +00001093 $$->Identifier = $1;
1094 $$->reference = $2;
vlmfa67ddc2004-06-03 03:38:44 +00001095 $$->meta_type = AMT_OBJECTFIELD;
vlmdc7cf042006-03-09 08:49:26 +00001096 $$->expr_type = A1TC_CLASSFIELD_OFS;
1097 $$->marker = $3;
vlmfa67ddc2004-06-03 03:38:44 +00001098 }
vlmdc7cf042006-03-09 08:49:26 +00001099
vlmee7196e2006-03-09 09:08:49 +00001100 /* VariableTypeValueSetFieldSpec ::= valuesetfieldreference FieldName ValueOptionalitySpec ? */
1101 | TOK_typefieldreference FieldName optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001102 $$ = NEW_EXPR();
vlmdc7cf042006-03-09 08:49:26 +00001103 $$->Identifier = $1;
vlmdc7cf042006-03-09 08:49:26 +00001104 $$->meta_type = AMT_OBJECTFIELD;
vlmee7196e2006-03-09 09:08:49 +00001105 $$->expr_type = A1TC_CLASSFIELD_VTVSFS;
1106 $$->reference = $2;
vlmdc7cf042006-03-09 08:49:26 +00001107 $$->marker = $3;
1108 }
1109
1110 /* FixedTypeValueSetFieldSpec ::= valuesetfieldreference Type ValueSetOptionalitySpec ? */
1111 | TOK_typefieldreference Type optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001112 $$ = NEW_EXPR();
vlmdc7cf042006-03-09 08:49:26 +00001113 checkmem($$);
1114 $$->Identifier = $1;
1115 $$->meta_type = AMT_OBJECTFIELD;
1116 $$->expr_type = A1TC_CLASSFIELD_FTVSFS;
1117 asn1p_expr_add($$, $2);
1118 $$->marker = $3;
1119 }
1120
vlmee7196e2006-03-09 09:08:49 +00001121 /* ObjectSetFieldSpec ::= objectsetfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1122 | TOK_typefieldreference DefinedObjectClass optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001123 $$ = NEW_EXPR();
vlmee7196e2006-03-09 09:08:49 +00001124 checkmem($$);
1125 $$->Identifier = $1;
1126 $$->reference = $2;
1127 $$->meta_type = AMT_OBJECTFIELD;
1128 $$->expr_type = A1TC_CLASSFIELD_OSFS;
1129 $$->marker = $3;
1130 }
vlmfa67ddc2004-06-03 03:38:44 +00001131 ;
1132
1133optWithSyntax:
1134 { $$ = 0; }
1135 | WithSyntax {
1136 $$ = $1;
1137 }
1138 ;
1139
1140WithSyntax:
1141 TOK_WITH TOK_SYNTAX '{'
1142 { asn1p_lexer_hack_enable_with_syntax(); }
vlm808411d2006-03-14 16:31:37 +00001143 WithSyntaxList
vlmfa67ddc2004-06-03 03:38:44 +00001144 '}' {
1145 $$ = $5;
1146 }
1147 ;
1148
vlm808411d2006-03-14 16:31:37 +00001149WithSyntaxList:
1150 WithSyntaxToken {
vlmfa67ddc2004-06-03 03:38:44 +00001151 $$ = asn1p_wsyntx_new();
1152 TQ_ADD(&($$->chunks), $1, next);
1153 }
vlm808411d2006-03-14 16:31:37 +00001154 | WithSyntaxList WithSyntaxToken {
vlmfa67ddc2004-06-03 03:38:44 +00001155 $$ = $1;
1156 TQ_ADD(&($$->chunks), $2, next);
1157 }
1158 ;
1159
vlm808411d2006-03-14 16:31:37 +00001160WithSyntaxToken:
vlmeeb3c512006-03-16 05:11:14 +00001161 TOK_whitespace {
vlm1fcf7592006-08-18 02:27:55 +00001162 $$ = asn1p_wsyntx_chunk_fromstring($1.buf, 0);
vlmeeb3c512006-03-16 05:11:14 +00001163 $$->type = WC_WHITESPACE;
vlmfa67ddc2004-06-03 03:38:44 +00001164 }
vlm808411d2006-03-14 16:31:37 +00001165 | TOK_Literal {
vlm1fcf7592006-08-18 02:27:55 +00001166 $$ = asn1p_wsyntx_chunk_fromstring($1, 0);
vlm808411d2006-03-14 16:31:37 +00001167 }
vlma6a84d72006-03-16 10:03:35 +00001168 | PrimitiveFieldReference {
vlm1fcf7592006-08-18 02:27:55 +00001169 $$ = asn1p_wsyntx_chunk_fromstring($1.name, 0);
vlma6a84d72006-03-16 10:03:35 +00001170 $$->type = WC_FIELD;
vlmfa67ddc2004-06-03 03:38:44 +00001171 }
vlm808411d2006-03-14 16:31:37 +00001172 | '[' WithSyntaxList ']' {
1173 $$ = asn1p_wsyntx_chunk_fromsyntax($2);
1174 }
vlmfa67ddc2004-06-03 03:38:44 +00001175 ;
1176
vlmfa67ddc2004-06-03 03:38:44 +00001177ExtensionAndException:
1178 TOK_ThreeDots {
vlm43c8ac52006-09-17 04:52:50 +00001179 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001180 checkmem($$);
1181 $$->Identifier = strdup("...");
1182 checkmem($$->Identifier);
1183 $$->expr_type = A1TC_EXTENSIBLE;
1184 $$->meta_type = AMT_TYPE;
1185 }
1186 | TOK_ThreeDots '!' DefinedValue {
vlm43c8ac52006-09-17 04:52:50 +00001187 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001188 checkmem($$);
1189 $$->Identifier = strdup("...");
1190 checkmem($$->Identifier);
1191 $$->value = $3;
1192 $$->expr_type = A1TC_EXTENSIBLE;
1193 $$->meta_type = AMT_TYPE;
1194 }
1195 | TOK_ThreeDots '!' SignedNumber {
vlm43c8ac52006-09-17 04:52:50 +00001196 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001197 checkmem($$);
1198 $$->Identifier = strdup("...");
1199 $$->value = $3;
1200 checkmem($$->Identifier);
1201 $$->expr_type = A1TC_EXTENSIBLE;
1202 $$->meta_type = AMT_TYPE;
1203 }
1204 ;
1205
vlmec8f6812004-08-22 03:19:54 +00001206Type:
vlmfce48a42004-09-14 02:36:39 +00001207 optTag TypeDeclaration optConstraints {
1208 $$ = $2;
1209 $$->tag = $1;
vlmec8f6812004-08-22 03:19:54 +00001210 /*
1211 * Outer constraint for SEQUENCE OF and SET OF applies
1212 * to the inner type.
1213 */
1214 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1215 || $$->expr_type == ASN_CONSTR_SET_OF) {
1216 assert(!TQ_FIRST(&($$->members))->constraints);
vlmfce48a42004-09-14 02:36:39 +00001217 TQ_FIRST(&($$->members))->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001218 } else {
1219 if($$->constraints) {
1220 assert(!$2);
1221 } else {
vlmfce48a42004-09-14 02:36:39 +00001222 $$->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001223 }
1224 }
vlm177a5b62005-09-05 05:17:57 +00001225 }
1226 ;
1227
1228NSTD_IndirectMarker:
1229 {
1230 $$ = asn1p_as_pointer ? EM_INDIRECT : 0;
1231 asn1p_as_pointer = 0;
vlmec8f6812004-08-22 03:19:54 +00001232 }
1233 ;
1234
1235TypeDeclaration:
vlm177a5b62005-09-05 05:17:57 +00001236 NSTD_IndirectMarker TypeDeclarationSet {
vlm066dc102005-08-22 12:23:54 +00001237 $$ = $2;
vlm177a5b62005-09-05 05:17:57 +00001238 $$->marker.flags |= $1;
1239
1240 if(($$->marker.flags & EM_INDIRECT)
1241 && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
1242 fprintf(stderr,
1243 "INFO: Directive <ASN1C:RepresentAsPointer> "
1244 "applied to %s at line %d\n",
1245 ASN_EXPR_TYPE2STR($$->expr_type)
1246 ? ASN_EXPR_TYPE2STR($$->expr_type)
1247 : "member",
1248 $$->_lineno
1249 );
1250 }
vlm066dc102005-08-22 12:23:54 +00001251 }
vlm177a5b62005-09-05 05:17:57 +00001252 ;
vlm066dc102005-08-22 12:23:54 +00001253
1254TypeDeclarationSet:
vlm17e65d02006-03-21 04:48:15 +00001255 DefinedType {
vlmfa67ddc2004-06-03 03:38:44 +00001256 $$ = $1;
1257 }
vlm177a5b62005-09-05 05:17:57 +00001258 | TOK_CHOICE '{' AlternativeTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001259 $$ = $3;
1260 assert($$->expr_type == A1TC_INVALID);
1261 $$->expr_type = ASN_CONSTR_CHOICE;
1262 $$->meta_type = AMT_TYPE;
vlmfa67ddc2004-06-03 03:38:44 +00001263 }
vlm177a5b62005-09-05 05:17:57 +00001264 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001265 $$ = $3;
1266 assert($$->expr_type == A1TC_INVALID);
1267 $$->expr_type = ASN_CONSTR_SEQUENCE;
1268 $$->meta_type = AMT_TYPE;
1269 }
vlm177a5b62005-09-05 05:17:57 +00001270 | TOK_SET '{' optComponentTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001271 $$ = $3;
1272 assert($$->expr_type == A1TC_INVALID);
1273 $$->expr_type = ASN_CONSTR_SET;
1274 $$->meta_type = AMT_TYPE;
1275 }
vlm151c0b22004-09-22 16:03:36 +00001276 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
vlm43c8ac52006-09-17 04:52:50 +00001277 $$ = NEW_EXPR();
vlmec8f6812004-08-22 03:19:54 +00001278 checkmem($$);
1279 $$->constraints = $2;
1280 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1281 $$->meta_type = AMT_TYPE;
vlm151c0b22004-09-22 16:03:36 +00001282 $6->Identifier = $4;
1283 $6->tag = $5;
1284 asn1p_expr_add($$, $6);
vlmec8f6812004-08-22 03:19:54 +00001285 }
vlm151c0b22004-09-22 16:03:36 +00001286 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
vlm43c8ac52006-09-17 04:52:50 +00001287 $$ = NEW_EXPR();
vlmec8f6812004-08-22 03:19:54 +00001288 checkmem($$);
1289 $$->constraints = $2;
1290 $$->expr_type = ASN_CONSTR_SET_OF;
1291 $$->meta_type = AMT_TYPE;
vlm151c0b22004-09-22 16:03:36 +00001292 $6->Identifier = $4;
1293 $6->tag = $5;
1294 asn1p_expr_add($$, $6);
vlmec8f6812004-08-22 03:19:54 +00001295 }
1296 | TOK_ANY {
vlm43c8ac52006-09-17 04:52:50 +00001297 $$ = NEW_EXPR();
vlmec8f6812004-08-22 03:19:54 +00001298 checkmem($$);
vlm044f7442004-09-04 04:49:21 +00001299 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001300 $$->meta_type = AMT_TYPE;
1301 }
1302 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1303 int ret;
vlm43c8ac52006-09-17 04:52:50 +00001304 $$ = NEW_EXPR();
vlmec8f6812004-08-22 03:19:54 +00001305 checkmem($$);
1306 $$->reference = asn1p_ref_new(yylineno);
1307 ret = asn1p_ref_add_component($$->reference,
1308 $4, RLT_lowercase);
1309 checkmem(ret == 0);
vlm044f7442004-09-04 04:49:21 +00001310 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001311 $$->meta_type = AMT_TYPE;
1312 }
vlmfa67ddc2004-06-03 03:38:44 +00001313 | TOK_INSTANCE TOK_OF ComplexTypeReference {
vlm43c8ac52006-09-17 04:52:50 +00001314 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001315 checkmem($$);
1316 $$->reference = $3;
1317 $$->expr_type = A1TC_INSTANCE;
1318 $$->meta_type = AMT_TYPE;
1319 }
1320 ;
1321
1322/*
1323 * A type name consisting of several components.
1324 * === EXAMPLE ===
1325 * === EOF ===
1326 */
1327ComplexTypeReference:
1328 TOK_typereference {
1329 int ret;
1330 $$ = asn1p_ref_new(yylineno);
1331 checkmem($$);
1332 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1333 checkmem(ret == 0);
1334 free($1);
1335 }
1336 | TOK_typereference '.' TypeRefName {
1337 int ret;
1338 $$ = asn1p_ref_new(yylineno);
1339 checkmem($$);
1340 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1341 checkmem(ret == 0);
1342 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1343 checkmem(ret == 0);
1344 free($1);
1345 }
vlmc94e28f2004-09-15 11:59:51 +00001346 | ObjectClassReference '.' TypeRefName {
1347 int ret;
1348 $$ = asn1p_ref_new(yylineno);
1349 checkmem($$);
1350 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1351 checkmem(ret == 0);
1352 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1353 checkmem(ret == 0);
1354 free($1);
1355 }
vlmfa67ddc2004-06-03 03:38:44 +00001356 | TOK_typereference '.' Identifier {
1357 int ret;
1358 $$ = asn1p_ref_new(yylineno);
1359 checkmem($$);
1360 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1361 checkmem(ret == 0);
1362 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1363 checkmem(ret == 0);
1364 free($1);
1365 }
1366 | ObjectClassReference {
1367 int ret;
1368 $$ = asn1p_ref_new(yylineno);
1369 checkmem($$);
1370 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1371 free($1);
1372 checkmem(ret == 0);
1373 }
1374 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1375 int ret;
1376 $$ = $3;
1377 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1378 free($1);
1379 checkmem(ret == 0);
1380 /*
1381 * Move the last element infront.
1382 */
1383 {
1384 struct asn1p_ref_component_s tmp_comp;
1385 tmp_comp = $$->components[$$->comp_count-1];
1386 memmove(&$$->components[1],
1387 &$$->components[0],
1388 sizeof($$->components[0])
1389 * ($$->comp_count - 1));
1390 $$->components[0] = tmp_comp;
1391 }
1392 }
1393 ;
1394
1395ComplexTypeReferenceAmpList:
1396 ComplexTypeReferenceElement {
1397 int ret;
1398 $$ = asn1p_ref_new(yylineno);
1399 checkmem($$);
1400 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1401 free($1.name);
1402 checkmem(ret == 0);
1403 }
1404 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1405 int ret;
1406 $$ = $1;
1407 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1408 free($3.name);
1409 checkmem(ret == 0);
1410 }
1411 ;
1412
vlma6a84d72006-03-16 10:03:35 +00001413ComplexTypeReferenceElement: PrimitiveFieldReference;
vlmfa67ddc2004-06-03 03:38:44 +00001414
vlma6a84d72006-03-16 10:03:35 +00001415PrimitiveFieldReference:
vlmfa67ddc2004-06-03 03:38:44 +00001416 /* "&Type1" */
1417 TOK_typefieldreference {
1418 $$.lex_type = RLT_AmpUppercase;
1419 $$.name = $1;
1420 }
1421 /* "&id" */
1422 | TOK_valuefieldreference {
1423 $$.lex_type = RLT_Amplowercase;
1424 $$.name = $1;
1425 }
1426 ;
1427
1428
vlmdc7cf042006-03-09 08:49:26 +00001429FieldName:
1430 /* "&Type1" */
1431 TOK_typefieldreference {
1432 $$ = asn1p_ref_new(yylineno);
1433 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1434 }
1435 | FieldName '.' TOK_typefieldreference {
1436 $$ = $$;
1437 asn1p_ref_add_component($$, $3, RLT_AmpUppercase);
1438 }
1439 | FieldName '.' TOK_valuefieldreference {
1440 $$ = $$;
1441 asn1p_ref_add_component($$, $3, RLT_Amplowercase);
1442 }
1443 ;
1444
1445DefinedObjectClass:
1446 TOK_capitalreference {
1447 $$ = asn1p_ref_new(yylineno);
1448 asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1449 }
vlmee7196e2006-03-09 09:08:49 +00001450/*
vlmdc7cf042006-03-09 08:49:26 +00001451 | TypeRefName '.' TOK_capitalreference {
1452 $$ = asn1p_ref_new(yylineno);
1453 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1454 asn1p_ref_add_component($$, $3, RLT_CAPITALS);
1455 }
vlmee7196e2006-03-09 09:08:49 +00001456*/
vlmdc7cf042006-03-09 08:49:26 +00001457 ;
1458
1459
vlmfa67ddc2004-06-03 03:38:44 +00001460/*
1461 * === EXAMPLE ===
1462 * value INTEGER ::= 1
1463 * === EOF ===
1464 */
1465ValueDefinition:
vlm17e65d02006-03-21 04:48:15 +00001466 Identifier DefinedType TOK_PPEQ Value {
vlmfa67ddc2004-06-03 03:38:44 +00001467 $$ = $2;
1468 assert($$->Identifier == NULL);
1469 $$->Identifier = $1;
1470 $$->meta_type = AMT_VALUE;
1471 $$->value = $4;
1472 }
1473 ;
1474
vlmc94e28f2004-09-15 11:59:51 +00001475Value:
vlm17e65d02006-03-21 04:48:15 +00001476 SimpleValue
1477 | DefinedValue
1478 | Identifier ':' Value {
vlmc94e28f2004-09-15 11:59:51 +00001479 $$ = asn1p_value_fromint(0);
1480 checkmem($$);
1481 $$->type = ATV_CHOICE_IDENTIFIER;
1482 $$->value.choice_identifier.identifier = $1;
1483 $$->value.choice_identifier.value = $3;
1484 }
vlmd30bc6c2005-03-24 16:27:02 +00001485 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
vlmfa67ddc2004-06-03 03:38:44 +00001486 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1487 checkmem($$);
1488 $$->type = ATV_UNPARSED;
1489 }
vlmc94e28f2004-09-15 11:59:51 +00001490 | TOK_NULL {
1491 $$ = asn1p_value_fromint(0);
1492 checkmem($$);
1493 $$->type = ATV_NULL;
1494 }
vlm17e65d02006-03-21 04:48:15 +00001495 ;
1496
1497SimpleValue:
1498 TOK_FALSE {
vlmc94e28f2004-09-15 11:59:51 +00001499 $$ = asn1p_value_fromint(0);
1500 checkmem($$);
1501 $$->type = ATV_FALSE;
1502 }
1503 | TOK_TRUE {
1504 $$ = asn1p_value_fromint(0);
1505 checkmem($$);
1506 $$->type = ATV_TRUE;
1507 }
vlmfa67ddc2004-06-03 03:38:44 +00001508 | TOK_bstring {
1509 $$ = _convert_bitstring2binary($1, 'B');
1510 checkmem($$);
1511 }
1512 | TOK_hstring {
1513 $$ = _convert_bitstring2binary($1, 'H');
1514 checkmem($$);
1515 }
vlme1e6ed82005-03-24 14:26:38 +00001516 | RestrictedCharacterStringValue {
1517 $$ = $$;
vlmfa67ddc2004-06-03 03:38:44 +00001518 }
1519 | SignedNumber {
1520 $$ = $1;
1521 }
vlmfa67ddc2004-06-03 03:38:44 +00001522 ;
1523
1524DefinedValue:
1525 Identifier {
1526 asn1p_ref_t *ref;
1527 int ret;
1528 ref = asn1p_ref_new(yylineno);
1529 checkmem(ref);
1530 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1531 checkmem(ret == 0);
1532 $$ = asn1p_value_fromref(ref, 0);
1533 checkmem($$);
1534 free($1);
1535 }
1536 | TypeRefName '.' Identifier {
1537 asn1p_ref_t *ref;
1538 int ret;
1539 ref = asn1p_ref_new(yylineno);
1540 checkmem(ref);
1541 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1542 checkmem(ret == 0);
1543 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1544 checkmem(ret == 0);
1545 $$ = asn1p_value_fromref(ref, 0);
1546 checkmem($$);
1547 free($1);
1548 free($3);
1549 }
1550 ;
1551
vlme1e6ed82005-03-24 14:26:38 +00001552
1553RestrictedCharacterStringValue:
1554 TOK_cstring {
1555 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1556 checkmem($$);
1557 }
vlm2c8c44d2005-03-24 16:22:35 +00001558 | TOK_tuple {
1559 $$ = asn1p_value_fromint($1);
1560 checkmem($$);
1561 $$->type = ATV_TUPLE;
1562 }
1563 | TOK_quadruple {
1564 $$ = asn1p_value_fromint($1);
1565 checkmem($$);
1566 $$->type = ATV_QUADRUPLE;
1567 }
1568 /*
vlme1e6ed82005-03-24 14:26:38 +00001569 | '{' TOK_number ',' TOK_number '}' {
1570 asn1c_integer_t v = ($2 << 4) + $4;
1571 if($2 > 7) return yyerror("X.680:2003, #37.14 "
1572 "mandates 0..7 range for Tuple's TableColumn");
1573 if($4 > 15) return yyerror("X.680:2003, #37.14 "
1574 "mandates 0..15 range for Tuple's TableRow");
1575 $$ = asn1p_value_fromint(v);
1576 checkmem($$);
1577 $$->type = ATV_TUPLE;
1578 }
1579 | '{' TOK_number ',' TOK_number ',' TOK_number ',' TOK_number '}' {
1580 asn1c_integer_t v = ($2 << 24) | ($4 << 16) | ($6 << 8) | $8;
1581 if($2 > 127) return yyerror("X.680:2003, #37.12 "
1582 "mandates 0..127 range for Quadruple's Group");
1583 if($4 > 255) return yyerror("X.680:2003, #37.12 "
1584 "mandates 0..255 range for Quadruple's Plane");
1585 if($6 > 255) return yyerror("X.680:2003, #37.12 "
1586 "mandates 0..255 range for Quadruple's Row");
1587 if($8 > 255) return yyerror("X.680:2003, #37.12 "
1588 "mandates 0..255 range for Quadruple's Cell");
1589 $$ = asn1p_value_fromint(v);
1590 checkmem($$);
1591 $$->type = ATV_QUADRUPLE;
1592 }
vlm2c8c44d2005-03-24 16:22:35 +00001593 */
vlme1e6ed82005-03-24 14:26:38 +00001594 ;
1595
vlmfa67ddc2004-06-03 03:38:44 +00001596Opaque:
1597 TOK_opaque {
vlm6611add2005-03-20 14:28:32 +00001598 $$.len = $1.len + 1;
vlmfa67ddc2004-06-03 03:38:44 +00001599 $$.buf = malloc($$.len + 1);
1600 checkmem($$.buf);
1601 $$.buf[0] = '{';
vlm6611add2005-03-20 14:28:32 +00001602 memcpy($$.buf + 1, $1.buf, $1.len);
vlmfa67ddc2004-06-03 03:38:44 +00001603 $$.buf[$$.len] = '\0';
1604 free($1.buf);
1605 }
1606 | Opaque TOK_opaque {
1607 int newsize = $1.len + $2.len;
1608 char *p = malloc(newsize + 1);
1609 checkmem(p);
1610 memcpy(p , $1.buf, $1.len);
1611 memcpy(p + $1.len, $2.buf, $2.len);
1612 p[newsize] = '\0';
1613 free($1.buf);
1614 free($2.buf);
1615 $$.buf = p;
1616 $$.len = newsize;
1617 }
1618 ;
1619
1620BasicTypeId:
1621 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1622 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1623 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1624 | BasicTypeId_UniverationCompatible { $$ = $1; }
1625 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1626 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1627 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1628 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1629 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1630 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1631 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1632 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
vlm5e2c4b92005-03-20 11:12:40 +00001633 | BasicString { $$ = $1; }
vlmfa67ddc2004-06-03 03:38:44 +00001634 ;
1635
1636/*
1637 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1638 */
1639BasicTypeId_UniverationCompatible:
1640 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1641 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1642 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1643 ;
1644
1645BasicType:
1646 BasicTypeId {
vlm43c8ac52006-09-17 04:52:50 +00001647 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001648 checkmem($$);
1649 $$->expr_type = $1;
1650 $$->meta_type = AMT_TYPE;
1651 }
1652 | BasicTypeId_UniverationCompatible UniverationDefinition {
1653 if($2) {
1654 $$ = $2;
1655 } else {
vlm43c8ac52006-09-17 04:52:50 +00001656 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001657 checkmem($$);
1658 }
1659 $$->expr_type = $1;
1660 $$->meta_type = AMT_TYPE;
1661 }
1662 ;
1663
1664BasicString:
1665 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1666 | TOK_GeneralString {
1667 $$ = ASN_STRING_GeneralString;
vlmc94e28f2004-09-15 11:59:51 +00001668 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001669 }
1670 | TOK_GraphicString {
1671 $$ = ASN_STRING_GraphicString;
vlmc94e28f2004-09-15 11:59:51 +00001672 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001673 }
1674 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1675 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1676 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1677 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1678 | TOK_T61String {
1679 $$ = ASN_STRING_T61String;
vlmc94e28f2004-09-15 11:59:51 +00001680 fprintf(stderr, "WARNING: T61String is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001681 }
1682 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1683 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1684 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1685 | TOK_VideotexString {
1686 $$ = ASN_STRING_VideotexString;
vlmc94e28f2004-09-15 11:59:51 +00001687 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001688 }
1689 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1690 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1691 ;
1692
vlm5f0128b2004-08-20 13:25:29 +00001693
vlmfa67ddc2004-06-03 03:38:44 +00001694/*
1695 * Data type constraints.
1696 */
vlm1bc782f2006-09-21 01:50:37 +00001697UnionMark: '|' | TOK_UNION;
1698IntersectionMark: '^' | TOK_INTERSECTION;
vlmfa67ddc2004-06-03 03:38:44 +00001699
vlm9283dbe2004-08-18 04:59:12 +00001700optConstraints:
1701 { $$ = 0; }
vlm43c8ac52006-09-17 04:52:50 +00001702 | Constraint {
vlm5f0128b2004-08-20 13:25:29 +00001703 $$ = $1;
1704 }
1705 ;
1706
vlm43c8ac52006-09-17 04:52:50 +00001707Constraint:
1708 SubtypeConstraint
1709 | '(' GeneralConstraint ')' {
1710 $$ = $2;
1711 }
1712 ;
1713
1714SubtypeConstraint:
vlm5f0128b2004-08-20 13:25:29 +00001715 SetOfConstraints {
vlm9fe7c922005-08-12 10:08:45 +00001716 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
vlm9283dbe2004-08-18 04:59:12 +00001717 }
1718 | TOK_SIZE '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001719 /*
1720 * This is a special case, for compatibility purposes.
vlm9283dbe2004-08-18 04:59:12 +00001721 * It goes without parentheses.
vlmfa67ddc2004-06-03 03:38:44 +00001722 */
vlm9fe7c922005-08-12 10:08:45 +00001723 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001724 }
vlmfa67ddc2004-06-03 03:38:44 +00001725 ;
1726
vlm9283dbe2004-08-18 04:59:12 +00001727SetOfConstraints:
1728 '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001729 $$ = $2;
1730 }
vlm9283dbe2004-08-18 04:59:12 +00001731 | SetOfConstraints '(' ElementSetSpecs ')' {
vlm9fe7c922005-08-12 10:08:45 +00001732 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
vlm9283dbe2004-08-18 04:59:12 +00001733 }
vlmfa67ddc2004-06-03 03:38:44 +00001734 ;
1735
vlm9283dbe2004-08-18 04:59:12 +00001736ElementSetSpecs:
vlmdfbff8c2006-03-21 09:41:28 +00001737 TOK_ThreeDots {
1738 $$ = asn1p_constraint_new(yylineno);
1739 $$->type = ACT_EL_EXT;
1740 }
1741 | ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001742 $$ = $1;
1743 }
vlm9283dbe2004-08-18 04:59:12 +00001744 | ElementSetSpec ',' TOK_ThreeDots {
vlmfa67ddc2004-06-03 03:38:44 +00001745 asn1p_constraint_t *ct;
1746 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001747 ct->type = ACT_EL_EXT;
vlm9fe7c922005-08-12 10:08:45 +00001748 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlmfa67ddc2004-06-03 03:38:44 +00001749 }
vlm9283dbe2004-08-18 04:59:12 +00001750 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001751 asn1p_constraint_t *ct;
1752 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001753 ct->type = ACT_EL_EXT;
vlm9fe7c922005-08-12 10:08:45 +00001754 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlm6f5eb0b2004-08-13 12:35:09 +00001755 ct = $$;
vlm9fe7c922005-08-12 10:08:45 +00001756 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
vlmfa67ddc2004-06-03 03:38:44 +00001757 }
vlmfa67ddc2004-06-03 03:38:44 +00001758 ;
1759
vlm9283dbe2004-08-18 04:59:12 +00001760ElementSetSpec:
vlm1bc782f2006-09-21 01:50:37 +00001761 Unions
vlme1e6ed82005-03-24 14:26:38 +00001762 | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001763 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
vlme1e6ed82005-03-24 14:26:38 +00001764 }
vlm1bc782f2006-09-21 01:50:37 +00001765 ;
1766
1767Unions:
1768 Intersections
1769 | Unions UnionMark Intersections {
vlm9fe7c922005-08-12 10:08:45 +00001770 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001771 }
vlm1bc782f2006-09-21 01:50:37 +00001772 ;
1773
1774Intersections:
1775 IntersectionElements
1776 | Intersections IntersectionMark IntersectionElements {
vlm9fe7c922005-08-12 10:08:45 +00001777 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001778 }
vlm1bc782f2006-09-21 01:50:37 +00001779 ;
1780
1781
1782IntersectionElements:
1783 ConstraintSubtypeElement
1784 | ConstraintSubtypeElement TOK_EXCEPT ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001785 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001786 }
1787 ;
1788
1789ConstraintSubtypeElement:
vlm9283dbe2004-08-18 04:59:12 +00001790 ConstraintSpec '(' ElementSetSpecs ')' {
1791 int ret;
1792 $$ = asn1p_constraint_new(yylineno);
1793 checkmem($$);
1794 $$->type = $1;
1795 ret = asn1p_constraint_insert($$, $3);
1796 checkmem(ret == 0);
1797 }
1798 | '(' ElementSetSpecs ')' {
1799 int ret;
1800 $$ = asn1p_constraint_new(yylineno);
1801 checkmem($$);
1802 $$->type = ACT_CA_SET;
1803 ret = asn1p_constraint_insert($$, $2);
1804 checkmem(ret == 0);
1805 }
vlma6a12e32005-03-20 12:58:00 +00001806 | SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001807 $$ = asn1p_constraint_new(yylineno);
1808 checkmem($$);
1809 $$->type = ACT_EL_VALUE;
1810 $$->value = $1;
1811 }
vlma6a12e32005-03-20 12:58:00 +00001812 | ContainedSubtype {
1813 $$ = asn1p_constraint_new(yylineno);
1814 checkmem($$);
1815 $$->type = ACT_EL_TYPE;
1816 $$->containedSubtype = $1;
1817 }
1818 | SingleValue ConstraintRangeSpec SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001819 $$ = asn1p_constraint_new(yylineno);
1820 checkmem($$);
1821 $$->type = $2;
1822 $$->range_start = $1;
1823 $$->range_stop = $3;
1824 }
vlma6a12e32005-03-20 12:58:00 +00001825 | TOK_MIN ConstraintRangeSpec SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001826 $$ = asn1p_constraint_new(yylineno);
1827 checkmem($$);
vlm9283dbe2004-08-18 04:59:12 +00001828 $$->type = $2;
1829 $$->range_start = asn1p_value_fromint(-123);
1830 $$->range_stop = $3;
1831 $$->range_start->type = ATV_MIN;
1832 }
vlma6a12e32005-03-20 12:58:00 +00001833 | SingleValue ConstraintRangeSpec TOK_MAX {
vlm9283dbe2004-08-18 04:59:12 +00001834 $$ = asn1p_constraint_new(yylineno);
1835 checkmem($$);
1836 $$->type = $2;
1837 $$->range_start = $1;
1838 $$->range_stop = asn1p_value_fromint(321);
1839 $$->range_stop->type = ATV_MAX;
1840 }
1841 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1842 $$ = asn1p_constraint_new(yylineno);
1843 checkmem($$);
1844 $$->type = $2;
1845 $$->range_start = asn1p_value_fromint(-123);
1846 $$->range_stop = asn1p_value_fromint(321);
1847 $$->range_start->type = ATV_MIN;
1848 $$->range_stop->type = ATV_MAX;
vlmfa67ddc2004-06-03 03:38:44 +00001849 }
vlm7bbdc9f2005-03-28 15:01:27 +00001850 | InnerTypeConstraint {
vlmfa67ddc2004-06-03 03:38:44 +00001851 $$ = $1;
1852 }
vlmfa67ddc2004-06-03 03:38:44 +00001853 ;
1854
1855ConstraintSpec:
1856 TOK_SIZE {
1857 $$ = ACT_CT_SIZE;
1858 }
1859 | TOK_FROM {
1860 $$ = ACT_CT_FROM;
1861 }
1862 ;
1863
vlma6a12e32005-03-20 12:58:00 +00001864SingleValue:
vlm4053ca52005-02-18 16:34:21 +00001865 TOK_FALSE {
1866 $$ = asn1p_value_fromint(0);
1867 checkmem($$);
1868 $$->type = ATV_FALSE;
1869 }
1870 | TOK_TRUE {
1871 $$ = asn1p_value_fromint(1);
1872 checkmem($$);
1873 $$->type = ATV_TRUE;
1874 }
vlme745fcd2006-09-05 16:18:34 +00001875 | RealValue
1876 | RestrictedCharacterStringValue
vlmfa67ddc2004-06-03 03:38:44 +00001877 | Identifier {
1878 asn1p_ref_t *ref;
1879 int ret;
1880 ref = asn1p_ref_new(yylineno);
1881 checkmem(ref);
1882 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1883 checkmem(ret == 0);
1884 $$ = asn1p_value_fromref(ref, 0);
1885 checkmem($$);
1886 free($1);
1887 }
vlma6a12e32005-03-20 12:58:00 +00001888 ;
1889
1890ContainedSubtype:
1891 TypeRefName {
vlm4053ca52005-02-18 16:34:21 +00001892 asn1p_ref_t *ref;
1893 int ret;
1894 ref = asn1p_ref_new(yylineno);
1895 checkmem(ref);
1896 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1897 checkmem(ret == 0);
1898 $$ = asn1p_value_fromref(ref, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001899 checkmem($$);
vlm4053ca52005-02-18 16:34:21 +00001900 free($1);
vlmfa67ddc2004-06-03 03:38:44 +00001901 }
1902 ;
1903
vlm7bbdc9f2005-03-28 15:01:27 +00001904InnerTypeConstraint:
1905 TOK_WITH TOK_COMPONENT SetOfConstraints {
vlm9fe7c922005-08-12 10:08:45 +00001906 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
vlm7bbdc9f2005-03-28 15:01:27 +00001907 }
1908 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
vlm9fe7c922005-08-12 10:08:45 +00001909 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001910 }
1911 ;
1912
1913WithComponentsList:
1914 WithComponentsElement {
1915 $$ = $1;
1916 }
1917 | WithComponentsList ',' WithComponentsElement {
vlm9fe7c922005-08-12 10:08:45 +00001918 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001919 }
1920 ;
1921
1922WithComponentsElement:
1923 TOK_ThreeDots {
1924 $$ = asn1p_constraint_new(yylineno);
1925 checkmem($$);
1926 $$->type = ACT_EL_EXT;
vlm1aeaddd2006-07-13 08:24:20 +00001927 $$->value = asn1p_value_frombuf("...", 3, 1);
vlmfa67ddc2004-06-03 03:38:44 +00001928 }
1929 | Identifier optConstraints optPresenceConstraint {
1930 $$ = asn1p_constraint_new(yylineno);
1931 checkmem($$);
1932 $$->type = ACT_EL_VALUE;
1933 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1934 $$->presence = $3;
vlm7bbdc9f2005-03-28 15:01:27 +00001935 if($2) asn1p_constraint_insert($$, $2);
vlmfa67ddc2004-06-03 03:38:44 +00001936 }
1937 ;
1938
1939/*
1940 * presence constraint for WithComponents
1941 */
1942optPresenceConstraint:
1943 { $$ = ACPRES_DEFAULT; }
1944 | PresenceConstraint { $$ = $1; }
1945 ;
1946
1947PresenceConstraint:
1948 TOK_PRESENT {
1949 $$ = ACPRES_PRESENT;
1950 }
1951 | TOK_ABSENT {
1952 $$ = ACPRES_ABSENT;
1953 }
1954 | TOK_OPTIONAL {
1955 $$ = ACPRES_OPTIONAL;
1956 }
1957 ;
1958
vlm43c8ac52006-09-17 04:52:50 +00001959
1960/* X.682 */
1961GeneralConstraint:
1962 UserDefinedConstraint
1963 | TableConstraint
1964 | ContentsConstraint
1965 ;
1966
1967UserDefinedConstraint:
1968 TOK_CONSTRAINED TOK_BY '{'
1969 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1970 $$ = asn1p_constraint_new(yylineno);
1971 checkmem($$);
1972 $$->type = ACT_CT_CTDBY;
1973 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
1974 checkmem($$->value);
1975 $$->value->type = ATV_UNPARSED;
1976 }
1977 ;
1978
1979ContentsConstraint:
1980 TOK_CONTAINING Type {
1981 $$ = asn1p_constraint_new(yylineno);
1982 $$->type = ACT_CT_CTNG;
1983 $$->value = asn1p_value_fromtype($2);
1984 }
1985 ;
1986
1987ConstraintRangeSpec:
1988 TOK_TwoDots { $$ = ACT_EL_RANGE; }
1989 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
1990 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
1991 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
1992 ;
vlmfa67ddc2004-06-03 03:38:44 +00001993TableConstraint:
1994 SimpleTableConstraint {
1995 $$ = $1;
1996 }
1997 | ComponentRelationConstraint {
1998 $$ = $1;
1999 }
2000 ;
2001
2002/*
2003 * "{ExtensionSet}"
2004 */
2005SimpleTableConstraint:
2006 '{' TypeRefName '}' {
2007 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
2008 asn1p_constraint_t *ct;
2009 int ret;
2010 ret = asn1p_ref_add_component(ref, $2, 0);
2011 checkmem(ret == 0);
2012 ct = asn1p_constraint_new(yylineno);
2013 checkmem($$);
2014 ct->type = ACT_EL_VALUE;
2015 ct->value = asn1p_value_fromref(ref, 0);
vlm9fe7c922005-08-12 10:08:45 +00002016 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
vlmfa67ddc2004-06-03 03:38:44 +00002017 }
2018 ;
2019
2020ComponentRelationConstraint:
2021 SimpleTableConstraint '{' AtNotationList '}' {
vlm9fe7c922005-08-12 10:08:45 +00002022 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00002023 }
2024 ;
2025
2026AtNotationList:
2027 AtNotationElement {
2028 $$ = asn1p_constraint_new(yylineno);
2029 checkmem($$);
2030 $$->type = ACT_EL_VALUE;
2031 $$->value = asn1p_value_fromref($1, 0);
2032 }
2033 | AtNotationList ',' AtNotationElement {
2034 asn1p_constraint_t *ct;
2035 ct = asn1p_constraint_new(yylineno);
2036 checkmem(ct);
2037 ct->type = ACT_EL_VALUE;
2038 ct->value = asn1p_value_fromref($3, 0);
vlm9fe7c922005-08-12 10:08:45 +00002039 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlmfa67ddc2004-06-03 03:38:44 +00002040 }
2041 ;
2042
2043/*
2044 * @blah
2045 */
2046AtNotationElement:
2047 '@' ComponentIdList {
2048 char *p = malloc(strlen($2) + 2);
2049 int ret;
2050 *p = '@';
2051 strcpy(p + 1, $2);
2052 $$ = asn1p_ref_new(yylineno);
2053 ret = asn1p_ref_add_component($$, p, 0);
2054 checkmem(ret == 0);
2055 free(p);
2056 free($2);
2057 }
2058 | '@' '.' ComponentIdList {
2059 char *p = malloc(strlen($3) + 3);
2060 int ret;
2061 p[0] = '@';
2062 p[1] = '.';
2063 strcpy(p + 2, $3);
2064 $$ = asn1p_ref_new(yylineno);
2065 ret = asn1p_ref_add_component($$, p, 0);
2066 checkmem(ret == 0);
2067 free(p);
2068 free($3);
2069 }
2070 ;
2071
2072/* identifier "." ... */
2073ComponentIdList:
2074 Identifier {
2075 $$ = $1;
2076 }
2077 | ComponentIdList '.' Identifier {
2078 int l1 = strlen($1);
2079 int l3 = strlen($3);
2080 $$ = malloc(l1 + 1 + l3 + 1);
2081 memcpy($$, $1, l1);
2082 $$[l1] = '.';
2083 memcpy($$ + l1 + 1, $3, l3);
2084 $$[l1 + 1 + l3] = '\0';
2085 }
2086 ;
2087
2088
2089
2090/*
2091 * MARKERS
2092 */
2093
2094optMarker:
vlmc94e28f2004-09-15 11:59:51 +00002095 {
2096 $$.flags = EM_NOMARK;
2097 $$.default_value = 0;
2098 }
vlmfa67ddc2004-06-03 03:38:44 +00002099 | Marker { $$ = $1; }
2100 ;
2101
2102Marker:
2103 TOK_OPTIONAL {
vlm1ac75e72005-11-26 11:21:55 +00002104 $$.flags = EM_OPTIONAL | EM_INDIRECT;
vlmc94e28f2004-09-15 11:59:51 +00002105 $$.default_value = 0;
vlmfa67ddc2004-06-03 03:38:44 +00002106 }
vlmc94e28f2004-09-15 11:59:51 +00002107 | TOK_DEFAULT Value {
2108 $$.flags = EM_DEFAULT;
2109 $$.default_value = $2;
vlmfa67ddc2004-06-03 03:38:44 +00002110 }
2111 ;
2112
2113/*
2114 * Universal enumeration definition to use in INTEGER and ENUMERATED.
2115 * === EXAMPLE ===
2116 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
2117 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
2118 * === EOF ===
2119 */
2120/*
2121optUniverationDefinition:
2122 { $$ = 0; }
2123 | UniverationDefinition {
2124 $$ = $1;
2125 }
2126 ;
2127*/
2128
2129UniverationDefinition:
2130 '{' '}' {
vlm43c8ac52006-09-17 04:52:50 +00002131 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002132 checkmem($$);
2133 }
2134 | '{' UniverationList '}' {
2135 $$ = $2;
2136 }
2137 ;
2138
2139UniverationList:
2140 UniverationElement {
vlm43c8ac52006-09-17 04:52:50 +00002141 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002142 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +00002143 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +00002144 }
2145 | UniverationList ',' UniverationElement {
2146 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +00002147 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +00002148 }
2149 ;
2150
2151UniverationElement:
2152 Identifier {
vlm43c8ac52006-09-17 04:52:50 +00002153 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002154 checkmem($$);
2155 $$->expr_type = A1TC_UNIVERVAL;
2156 $$->meta_type = AMT_VALUE;
2157 $$->Identifier = $1;
2158 }
2159 | Identifier '(' SignedNumber ')' {
vlm43c8ac52006-09-17 04:52:50 +00002160 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002161 checkmem($$);
2162 $$->expr_type = A1TC_UNIVERVAL;
2163 $$->meta_type = AMT_VALUE;
2164 $$->Identifier = $1;
2165 $$->value = $3;
2166 }
2167 | Identifier '(' DefinedValue ')' {
vlm43c8ac52006-09-17 04:52:50 +00002168 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002169 checkmem($$);
2170 $$->expr_type = A1TC_UNIVERVAL;
2171 $$->meta_type = AMT_VALUE;
2172 $$->Identifier = $1;
2173 $$->value = $3;
2174 }
2175 | SignedNumber {
vlm43c8ac52006-09-17 04:52:50 +00002176 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002177 checkmem($$);
2178 $$->expr_type = A1TC_UNIVERVAL;
2179 $$->meta_type = AMT_VALUE;
2180 $$->value = $1;
2181 }
2182 | TOK_ThreeDots {
vlm43c8ac52006-09-17 04:52:50 +00002183 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002184 checkmem($$);
2185 $$->Identifier = strdup("...");
2186 checkmem($$->Identifier);
2187 $$->expr_type = A1TC_EXTENSIBLE;
2188 $$->meta_type = AMT_VALUE;
2189 }
2190 ;
2191
2192SignedNumber:
2193 TOK_number {
2194 $$ = asn1p_value_fromint($1);
2195 checkmem($$);
2196 }
2197 | TOK_number_negative {
2198 $$ = asn1p_value_fromint($1);
2199 checkmem($$);
2200 }
2201 ;
2202
vlme745fcd2006-09-05 16:18:34 +00002203RealValue:
2204 SignedNumber
2205 | TOK_realnumber {
2206 $$ = asn1p_value_fromdouble($1);
2207 checkmem($$);
2208 }
2209 ;
2210
vlmfa67ddc2004-06-03 03:38:44 +00002211/*
2212 * SEQUENCE definition.
2213 * === EXAMPLE ===
2214 * Struct1 ::= SEQUENCE {
2215 * memb1 Struct2,
2216 * memb2 SEQUENCE OF {
2217 * memb2-1 Struct 3
2218 * }
2219 * }
2220 * === EOF ===
2221 */
2222
2223
2224
2225/*
2226 * SET definition.
2227 * === EXAMPLE ===
2228 * Person ::= SET {
2229 * name [0] PrintableString (SIZE(1..20)),
2230 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2231 * }
2232 * === EOF ===
2233 */
2234
2235optTag:
2236 { memset(&$$, 0, sizeof($$)); }
2237 | Tag { $$ = $1; }
2238 ;
2239
2240Tag:
vlm2728a8d2005-01-23 09:51:44 +00002241 TagTypeValue TagPlicit {
vlmfa67ddc2004-06-03 03:38:44 +00002242 $$ = $1;
vlm2728a8d2005-01-23 09:51:44 +00002243 $$.tag_mode = $2.tag_mode;
vlmfa67ddc2004-06-03 03:38:44 +00002244 }
vlm2728a8d2005-01-23 09:51:44 +00002245 ;
2246
2247TagTypeValue:
2248 '[' TagClass TOK_number ']' {
2249 $$ = $2;
2250 $$.tag_value = $3;
2251 };
2252
2253TagClass:
2254 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2255 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2256 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2257 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2258 ;
2259
2260TagPlicit:
2261 { $$.tag_mode = TM_DEFAULT; }
2262 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2263 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
vlmfa67ddc2004-06-03 03:38:44 +00002264 ;
2265
2266TypeRefName:
2267 TOK_typereference {
2268 checkmem($1);
2269 $$ = $1;
2270 }
vlm9283dbe2004-08-18 04:59:12 +00002271 | TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00002272 checkmem($1);
2273 $$ = $1;
2274 }
2275 ;
2276
vlm9283dbe2004-08-18 04:59:12 +00002277
vlmfa67ddc2004-06-03 03:38:44 +00002278ObjectClassReference:
vlm9283dbe2004-08-18 04:59:12 +00002279 TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00002280 checkmem($1);
2281 $$ = $1;
2282 }
2283 ;
2284
vlm151c0b22004-09-22 16:03:36 +00002285optIdentifier:
2286 { $$ = 0; }
2287 | Identifier {
2288 $$ = $1;
2289 }
vlma5b977d2005-06-06 08:28:58 +00002290 ;
vlm151c0b22004-09-22 16:03:36 +00002291
vlmfa67ddc2004-06-03 03:38:44 +00002292Identifier:
2293 TOK_identifier {
2294 checkmem($1);
2295 $$ = $1;
2296 }
2297 ;
2298
vlmfa67ddc2004-06-03 03:38:44 +00002299%%
2300
2301
2302/*
2303 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2304 */
2305static asn1p_value_t *
2306_convert_bitstring2binary(char *str, int base) {
2307 asn1p_value_t *val;
2308 int slen;
2309 int memlen;
2310 int baselen;
2311 int bits;
2312 uint8_t *binary_vector;
2313 uint8_t *bv_ptr;
2314 uint8_t cur_val;
2315
2316 assert(str);
2317 assert(str[0] == '\'');
2318
2319 switch(base) {
2320 case 'B':
2321 baselen = 1;
2322 break;
2323 case 'H':
2324 baselen = 4;
2325 break;
2326 default:
2327 assert(base == 'B' || base == 'H');
2328 errno = EINVAL;
2329 return NULL;
2330 }
2331
2332 slen = strlen(str);
2333 assert(str[slen - 1] == base);
2334 assert(str[slen - 2] == '\'');
2335
2336 memlen = slen / (8 / baselen); /* Conservative estimate */
2337
2338 bv_ptr = binary_vector = malloc(memlen + 1);
2339 if(bv_ptr == NULL)
2340 /* ENOMEM */
2341 return NULL;
2342
2343 cur_val = 0;
2344 bits = 0;
2345 while(*(++str) != '\'') {
2346 switch(baselen) {
2347 case 1:
2348 switch(*str) {
2349 case '1':
2350 cur_val |= 1 << (7 - (bits % 8));
2351 case '0':
2352 break;
2353 default:
2354 assert(!"_y UNREACH1");
2355 case ' ': case '\r': case '\n':
2356 continue;
2357 }
2358 break;
2359 case 4:
2360 switch(*str) {
2361 case '0': case '1': case '2': case '3': case '4':
2362 case '5': case '6': case '7': case '8': case '9':
2363 cur_val |= (*str - '0') << (4 - (bits % 8));
2364 break;
2365 case 'A': case 'B': case 'C':
2366 case 'D': case 'E': case 'F':
2367 cur_val |= ((*str - 'A') + 10)
2368 << (4 - (bits % 8));
2369 break;
2370 default:
2371 assert(!"_y UNREACH2");
2372 case ' ': case '\r': case '\n':
2373 continue;
2374 }
2375 break;
2376 }
2377
2378 bits += baselen;
2379 if((bits % 8) == 0) {
2380 *bv_ptr++ = cur_val;
2381 cur_val = 0;
2382 }
2383 }
2384
2385 *bv_ptr = cur_val;
2386 assert((bv_ptr - binary_vector) <= memlen);
2387
2388 val = asn1p_value_frombits(binary_vector, bits, 0);
2389 if(val == NULL) {
2390 free(binary_vector);
2391 }
2392
2393 return val;
2394}
2395
vlm5d89c3d2005-08-13 09:07:11 +00002396/*
2397 * For unnamed types (used in old X.208 compliant modules)
2398 * generate some sort of interim names, to not to force human being to fix
2399 * the specification's compliance to modern ASN.1 standards.
2400 */
2401static void
2402_fixup_anonymous_identifier(asn1p_expr_t *expr) {
2403 char *p;
2404 assert(expr->Identifier == 0);
2405
2406 /*
2407 * Try to figure out the type name
2408 * without going too much into details
2409 */
2410 expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type);
2411 if(expr->reference && expr->reference->comp_count > 0)
2412 expr->Identifier = expr->reference->components[0].name;
2413
2414 fprintf(stderr,
2415 "WARNING: Line %d: expected lower-case member identifier, "
2416 "found an unnamed %s.\n"
2417 "WARNING: Obsolete X.208 syntax detected, "
2418 "please give the member a name.\n",
2419 yylineno, expr->Identifier ? expr->Identifier : "type");
2420
2421 if(!expr->Identifier)
2422 expr->Identifier = "unnamed";
2423 expr->Identifier = strdup(expr->Identifier);
2424 assert(expr->Identifier);
2425 /* Make a lowercase identifier from the type name */
2426 for(p = expr->Identifier; *p; p++) {
2427 switch(*p) {
2428 case 'A' ... 'Z': *p += 32; break;
2429 case ' ': *p = '_'; break;
2430 case '-': *p = '_'; break;
2431 }
2432 }
2433 fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". "
2434 "Name clash may occur later.\n",
2435 expr->Identifier);
2436}
2437
vlmfa67ddc2004-06-03 03:38:44 +00002438int
2439yyerror(const char *msg) {
vlm808411d2006-03-14 16:31:37 +00002440 extern char *asn1p_text;
vlmfa67ddc2004-06-03 03:38:44 +00002441 fprintf(stderr,
2442 "ASN.1 grammar parse error "
2443 "near line %d (token \"%s\"): %s\n",
vlm39e5ed72004-09-05 10:40:41 +00002444 yylineno, asn1p_text, msg);
vlmfa67ddc2004-06-03 03:38:44 +00002445 return -1;
2446}
2447