blob: 997be27ed77f3daf3c71bab3fd4af4cd39932d24 [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} */
vlmb9f1c0d2006-10-21 05:54:49 +0000278%type <a_expr> ValueAssignment /* 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
vlm64aaa9e2006-10-27 05:37:39 +0000284%type <a_value> BitStringValue
vlm0aa86902004-10-12 23:26:53 +0000285%type <a_expr> optComponentTypeLists
vlmec8f6812004-08-22 03:19:54 +0000286%type <a_expr> ComponentTypeLists
287%type <a_expr> ComponentType
288%type <a_expr> AlternativeTypeLists
289%type <a_expr> AlternativeType
vlmfa67ddc2004-06-03 03:38:44 +0000290%type <a_expr> UniverationDefinition
291%type <a_expr> UniverationList
292%type <a_expr> UniverationElement
293%type <tv_str> TypeRefName
294%type <tv_str> ObjectClassReference
vlmfa67ddc2004-06-03 03:38:44 +0000295%type <tv_str> Identifier
vlm151c0b22004-09-22 16:03:36 +0000296%type <tv_str> optIdentifier
vlmfa67ddc2004-06-03 03:38:44 +0000297%type <a_parg> ParameterArgumentName
298%type <a_plist> ParameterArgumentList
vlmdfbff8c2006-03-21 09:41:28 +0000299%type <a_expr> ActualParameter
300%type <a_expr> ActualParameterList
vlm04a08da2005-08-12 10:06:17 +0000301%type <a_aid> AssignedIdentifier /* OID/DefinedValue */
vlmfa67ddc2004-06-03 03:38:44 +0000302%type <a_oid> ObjectIdentifier /* OID */
303%type <a_oid> optObjectIdentifier /* Optional OID */
304%type <a_oid> ObjectIdentifierBody
305%type <a_oid_arc> ObjectIdentifierElement
306%type <a_expr> BasicType
307%type <a_type> BasicTypeId
308%type <a_type> BasicTypeId_UniverationCompatible
309%type <a_type> BasicString
310%type <tv_opaque> Opaque
vlm2728a8d2005-01-23 09:51:44 +0000311%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
312%type <a_tag> TagClass TagTypeValue TagPlicit
vlmfa67ddc2004-06-03 03:38:44 +0000313%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
314%type <a_constr> optConstraints
vlm43c8ac52006-09-17 04:52:50 +0000315%type <a_constr> Constraint
316%type <a_constr> SubtypeConstraint
317%type <a_constr> GeneralConstraint
vlm9283dbe2004-08-18 04:59:12 +0000318%type <a_constr> SetOfConstraints
319%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
320%type <a_constr> ElementSetSpec /* 1..2,...,3 */
vlm1bc782f2006-09-21 01:50:37 +0000321%type <a_constr> Unions
322%type <a_constr> Intersections
323%type <a_constr> IntersectionElements
vlmfa67ddc2004-06-03 03:38:44 +0000324%type <a_constr> ConstraintSubtypeElement /* 1..2 */
vlmfa67ddc2004-06-03 03:38:44 +0000325%type <a_constr> SimpleTableConstraint
vlm43c8ac52006-09-17 04:52:50 +0000326%type <a_constr> UserDefinedConstraint
vlmfa67ddc2004-06-03 03:38:44 +0000327%type <a_constr> TableConstraint
vlm43c8ac52006-09-17 04:52:50 +0000328%type <a_constr> ContentsConstraint
vlm8cc3f742006-10-18 18:40:14 +0000329%type <a_constr> PatternConstraint
vlm7bbdc9f2005-03-28 15:01:27 +0000330%type <a_constr> InnerTypeConstraint
vlmfa67ddc2004-06-03 03:38:44 +0000331%type <a_constr> WithComponentsList
332%type <a_constr> WithComponentsElement
333%type <a_constr> ComponentRelationConstraint
334%type <a_constr> AtNotationList
335%type <a_ref> AtNotationElement
vlma6a12e32005-03-20 12:58:00 +0000336%type <a_value> SingleValue
337%type <a_value> ContainedSubtype
vlmfa67ddc2004-06-03 03:38:44 +0000338%type <a_ctype> ConstraintSpec
339%type <a_ctype> ConstraintRangeSpec
vlme1e6ed82005-03-24 14:26:38 +0000340%type <a_value> RestrictedCharacterStringValue
vlmfa67ddc2004-06-03 03:38:44 +0000341%type <a_wsynt> optWithSyntax
342%type <a_wsynt> WithSyntax
vlm808411d2006-03-14 16:31:37 +0000343%type <a_wsynt> WithSyntaxList
344%type <a_wchunk> WithSyntaxToken
vlmfa67ddc2004-06-03 03:38:44 +0000345%type <a_marker> optMarker Marker
346%type <a_int> optUnique
347%type <a_pres> optPresenceConstraint PresenceConstraint
348%type <tv_str> ComponentIdList
vlm177a5b62005-09-05 05:17:57 +0000349%type <a_int> NSTD_IndirectMarker
vlmfa67ddc2004-06-03 03:38:44 +0000350
351
352%%
353
354
355ParsedGrammar:
356 ModuleList {
357 *(void **)param = $1;
358 }
359 ;
360
361ModuleList:
vlmd3420d32006-09-14 10:35:20 +0000362 ModuleDefinition {
vlmfa67ddc2004-06-03 03:38:44 +0000363 $$ = asn1p_new();
364 checkmem($$);
365 TQ_ADD(&($$->modules), $1, mod_next);
366 }
vlmd3420d32006-09-14 10:35:20 +0000367 | ModuleList ModuleDefinition {
vlmfa67ddc2004-06-03 03:38:44 +0000368 $$ = $1;
369 TQ_ADD(&($$->modules), $2, mod_next);
370 }
371 ;
372
373/*
374 * ASN module definition.
375 * === EXAMPLE ===
376 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
377 * BEGIN
378 * ...
379 * END
380 * === EOF ===
381 */
382
vlmd3420d32006-09-14 10:35:20 +0000383ModuleDefinition:
vlm43c8ac52006-09-17 04:52:50 +0000384 TypeRefName { currentModule = asn1p_module_new(); }
385 optObjectIdentifier TOK_DEFINITIONS
vlmd3420d32006-09-14 10:35:20 +0000386 optModuleDefinitionFlags
vlmfa67ddc2004-06-03 03:38:44 +0000387 TOK_PPEQ TOK_BEGIN
vlmd3420d32006-09-14 10:35:20 +0000388 optModuleBody
vlmfa67ddc2004-06-03 03:38:44 +0000389 TOK_END {
390
vlm43c8ac52006-09-17 04:52:50 +0000391 $$ = currentModule;
392
393 if($8) {
394 asn1p_module_t tmp = *($$);
395 *($$) = *($8);
396 *($8) = tmp;
397 asn1p_module_free($8);
vlmfa67ddc2004-06-03 03:38:44 +0000398 } else {
399 /* There's a chance that a module is just plain empty */
vlmfa67ddc2004-06-03 03:38:44 +0000400 }
vlmfa67ddc2004-06-03 03:38:44 +0000401
vlm04a08da2005-08-12 10:06:17 +0000402 $$->ModuleName = $1;
vlm43c8ac52006-09-17 04:52:50 +0000403 $$->module_oid = $3;
404 $$->module_flags = $5;
vlmfa67ddc2004-06-03 03:38:44 +0000405 }
406 ;
407
408/*
409 * Object Identifier Definition
410 * { iso member-body(2) 3 }
411 */
412optObjectIdentifier:
413 { $$ = 0; }
414 | ObjectIdentifier { $$ = $1; }
415 ;
416
417ObjectIdentifier:
418 '{' ObjectIdentifierBody '}' {
419 $$ = $2;
420 }
421 | '{' '}' {
422 $$ = 0;
423 }
424 ;
425
426ObjectIdentifierBody:
427 ObjectIdentifierElement {
428 $$ = asn1p_oid_new();
429 asn1p_oid_add_arc($$, &$1);
430 if($1.name)
431 free($1.name);
432 }
433 | ObjectIdentifierBody ObjectIdentifierElement {
434 $$ = $1;
435 asn1p_oid_add_arc($$, &$2);
436 if($2.name)
437 free($2.name);
438 }
439 ;
440
441ObjectIdentifierElement:
442 Identifier { /* iso */
443 $$.name = $1;
444 $$.number = -1;
445 }
446 | Identifier '(' TOK_number ')' { /* iso(1) */
447 $$.name = $1;
448 $$.number = $3;
449 }
450 | TOK_number { /* 1 */
451 $$.name = 0;
452 $$.number = $1;
453 }
454 ;
455
456/*
457 * Optional module flags.
458 */
vlmd3420d32006-09-14 10:35:20 +0000459optModuleDefinitionFlags:
vlmfa67ddc2004-06-03 03:38:44 +0000460 { $$ = MSF_NOFLAGS; }
vlmd3420d32006-09-14 10:35:20 +0000461 | ModuleDefinitionFlags {
vlmfa67ddc2004-06-03 03:38:44 +0000462 $$ = $1;
463 }
464 ;
465
466/*
467 * Module flags.
468 */
vlmd3420d32006-09-14 10:35:20 +0000469ModuleDefinitionFlags:
470 ModuleDefinitionFlag {
vlmfa67ddc2004-06-03 03:38:44 +0000471 $$ = $1;
472 }
vlmd3420d32006-09-14 10:35:20 +0000473 | ModuleDefinitionFlags ModuleDefinitionFlag {
vlmfa67ddc2004-06-03 03:38:44 +0000474 $$ = $1 | $2;
475 }
476 ;
477
478/*
479 * Single module flag.
480 */
vlmd3420d32006-09-14 10:35:20 +0000481ModuleDefinitionFlag:
vlmfa67ddc2004-06-03 03:38:44 +0000482 TOK_EXPLICIT TOK_TAGS {
483 $$ = MSF_EXPLICIT_TAGS;
484 }
485 | TOK_IMPLICIT TOK_TAGS {
486 $$ = MSF_IMPLICIT_TAGS;
487 }
488 | TOK_AUTOMATIC TOK_TAGS {
489 $$ = MSF_AUTOMATIC_TAGS;
490 }
491 | TOK_EXTENSIBILITY TOK_IMPLIED {
492 $$ = MSF_EXTENSIBILITY_IMPLIED;
493 }
vlm9283dbe2004-08-18 04:59:12 +0000494 /* EncodingReferenceDefault */
495 | TOK_capitalreference TOK_INSTRUCTIONS {
496 /* X.680Amd1 specifies TAG and XER */
497 if(strcmp($1, "TAG") == 0) {
498 $$ = MSF_TAG_INSTRUCTIONS;
499 } else if(strcmp($1, "XER") == 0) {
500 $$ = MSF_XER_INSTRUCTIONS;
501 } else {
502 fprintf(stderr,
503 "WARNING: %s INSTRUCTIONS at line %d: "
504 "Unrecognized encoding reference\n",
505 $1, yylineno);
506 $$ = MSF_unk_INSTRUCTIONS;
507 }
508 free($1);
509 }
vlmfa67ddc2004-06-03 03:38:44 +0000510 ;
511
512/*
513 * Optional module body.
514 */
vlmd3420d32006-09-14 10:35:20 +0000515optModuleBody:
vlmfa67ddc2004-06-03 03:38:44 +0000516 { $$ = 0; }
vlmd3420d32006-09-14 10:35:20 +0000517 | ModuleBody {
vlmfa67ddc2004-06-03 03:38:44 +0000518 $$ = $1;
519 }
520 ;
521
522/*
523 * ASN.1 Module body.
524 */
vlmd3420d32006-09-14 10:35:20 +0000525ModuleBody:
526 optExports optImports AssignmentList {
527 $$ = asn1p_module_new();
528 AL_IMPORT($$, exports, $1, xp_next);
529 AL_IMPORT($$, imports, $2, xp_next);
530 AL_IMPORT($$, members, $3, next);
vlmfa67ddc2004-06-03 03:38:44 +0000531 }
532 ;
533
vlmd3420d32006-09-14 10:35:20 +0000534AssignmentList:
535 Assignment {
536 $$ = $1;
537 }
538 | AssignmentList Assignment {
539 if($1) {
540 $$ = $1;
541 } else {
542 $$ = $2;
543 break;
544 }
545 AL_IMPORT($$, members, $2, next);
546 }
547 ;
548
549
vlmfa67ddc2004-06-03 03:38:44 +0000550/*
551 * One of the elements of ASN.1 module specification.
552 */
vlmd3420d32006-09-14 10:35:20 +0000553Assignment:
554 DataTypeReference {
vlmfa67ddc2004-06-03 03:38:44 +0000555 $$ = asn1p_module_new();
556 checkmem($$);
557 assert($1->expr_type != A1TC_INVALID);
558 assert($1->meta_type != AMT_INVALID);
559 TQ_ADD(&($$->members), $1, next);
560 }
vlmb9f1c0d2006-10-21 05:54:49 +0000561 | ValueAssignment {
vlmfa67ddc2004-06-03 03:38:44 +0000562 $$ = asn1p_module_new();
563 checkmem($$);
564 assert($1->expr_type != A1TC_INVALID);
565 assert($1->meta_type != AMT_INVALID);
566 TQ_ADD(&($$->members), $1, next);
567 }
568 /*
569 * Value set definition
570 * === EXAMPLE ===
571 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
572 * === EOF ===
573 */
vlm59b620a2006-03-21 07:46:48 +0000574 | ValueSetTypeAssignment {
vlmfa67ddc2004-06-03 03:38:44 +0000575 $$ = asn1p_module_new();
576 checkmem($$);
577 assert($1->expr_type != A1TC_INVALID);
578 assert($1->meta_type != AMT_INVALID);
579 TQ_ADD(&($$->members), $1, next);
580 }
vlm9283dbe2004-08-18 04:59:12 +0000581 | TOK_ENCODING_CONTROL TOK_capitalreference
582 { asn1p_lexer_hack_push_encoding_control(); }
583 {
584 fprintf(stderr,
585 "WARNING: ENCODING-CONTROL %s "
586 "specification at line %d ignored\n",
587 $2, yylineno);
588 free($2);
589 $$ = 0;
590 }
vlmfa67ddc2004-06-03 03:38:44 +0000591
592 /*
593 * Erroneous attemps
594 */
595 | BasicString {
596 return yyerror(
vlm1ac75e72005-11-26 11:21:55 +0000597 "Attempt to redefine a standard basic string type, "
598 "please comment out or remove this type redefinition.");
vlmfa67ddc2004-06-03 03:38:44 +0000599 }
600 ;
601
602/*
603 * === EXAMPLE ===
604 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
605 * === EOF ===
606 */
vlmd3420d32006-09-14 10:35:20 +0000607optImports:
608 { $$ = 0; }
609 | ImportsDefinition;
610
vlmfa67ddc2004-06-03 03:38:44 +0000611ImportsDefinition:
vlm86851cd2006-10-13 12:37:39 +0000612 TOK_IMPORTS optImportsBundleSet ';' {
vlm04a08da2005-08-12 10:06:17 +0000613 if(!saved_aid && 0)
614 return yyerror("Unterminated IMPORTS FROM, "
615 "expected semicolon ';'");
616 saved_aid = 0;
vlmfa67ddc2004-06-03 03:38:44 +0000617 $$ = $2;
618 }
619 /*
620 * Some error cases.
621 */
622 | TOK_IMPORTS TOK_FROM /* ... */ {
623 return yyerror("Empty IMPORTS list");
624 }
625 ;
626
vlm86851cd2006-10-13 12:37:39 +0000627optImportsBundleSet:
628 { $$ = asn1p_module_new(); }
629 | ImportsBundleSet;
630
vlmfa67ddc2004-06-03 03:38:44 +0000631ImportsBundleSet:
632 ImportsBundle {
633 $$ = asn1p_module_new();
634 checkmem($$);
635 TQ_ADD(&($$->imports), $1, xp_next);
636 }
637 | ImportsBundleSet ImportsBundle {
638 $$ = $1;
639 TQ_ADD(&($$->imports), $2, xp_next);
640 }
641 ;
642
vlm04a08da2005-08-12 10:06:17 +0000643AssignedIdentifier:
644 { memset(&$$, 0, sizeof($$)); }
645 | ObjectIdentifier { $$.oid = $1; };
646 /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
647
vlmfa67ddc2004-06-03 03:38:44 +0000648ImportsBundle:
vlm04a08da2005-08-12 10:06:17 +0000649 ImportsList TOK_FROM TypeRefName AssignedIdentifier {
vlmfa67ddc2004-06-03 03:38:44 +0000650 $$ = $1;
vlm04a08da2005-08-12 10:06:17 +0000651 $$->fromModuleName = $3;
652 $$->identifier = $4;
653 /* This stupid thing is used for look-back hack. */
654 saved_aid = $$->identifier.oid ? 0 : &($$->identifier);
vlmfa67ddc2004-06-03 03:38:44 +0000655 checkmem($$);
656 }
657 ;
658
659ImportsList:
660 ImportsElement {
661 $$ = asn1p_xports_new();
662 checkmem($$);
663 TQ_ADD(&($$->members), $1, next);
664 }
665 | ImportsList ',' ImportsElement {
666 $$ = $1;
667 TQ_ADD(&($$->members), $3, next);
668 }
669 ;
670
671ImportsElement:
672 TypeRefName {
vlm43c8ac52006-09-17 04:52:50 +0000673 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000674 checkmem($$);
675 $$->Identifier = $1;
676 $$->expr_type = A1TC_REFERENCE;
677 }
vlm0aa86902004-10-12 23:26:53 +0000678 | TypeRefName '{' '}' { /* Completely equivalent to above */
vlm43c8ac52006-09-17 04:52:50 +0000679 $$ = NEW_EXPR();
vlm0aa86902004-10-12 23:26:53 +0000680 checkmem($$);
681 $$->Identifier = $1;
682 $$->expr_type = A1TC_REFERENCE;
683 }
vlmfa67ddc2004-06-03 03:38:44 +0000684 | Identifier {
vlm43c8ac52006-09-17 04:52:50 +0000685 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000686 checkmem($$);
687 $$->Identifier = $1;
688 $$->expr_type = A1TC_REFERENCE;
689 }
690 ;
691
vlmd3420d32006-09-14 10:35:20 +0000692
693optExports:
694 { $$ = 0; }
695 | ExportsDefinition {
696 $$ = asn1p_module_new();
697 checkmem($$);
698 if($1) {
699 TQ_ADD(&($$->exports), $1, xp_next);
700 } else {
701 /* "EXPORTS ALL;" */
702 }
703 }
704 ;
705
vlmfa67ddc2004-06-03 03:38:44 +0000706ExportsDefinition:
707 TOK_EXPORTS ExportsBody ';' {
708 $$ = $2;
709 }
710 | TOK_EXPORTS TOK_ALL ';' {
711 $$ = 0;
712 }
713 | TOK_EXPORTS ';' {
714 /* Empty EXPORTS clause effectively prohibits export. */
715 $$ = asn1p_xports_new();
716 checkmem($$);
717 }
718 ;
719
720ExportsBody:
721 ExportsElement {
722 $$ = asn1p_xports_new();
723 assert($$);
724 TQ_ADD(&($$->members), $1, next);
725 }
726 | ExportsBody ',' ExportsElement {
727 $$ = $1;
728 TQ_ADD(&($$->members), $3, next);
729 }
730 ;
731
732ExportsElement:
733 TypeRefName {
vlm43c8ac52006-09-17 04:52:50 +0000734 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000735 checkmem($$);
736 $$->Identifier = $1;
737 $$->expr_type = A1TC_EXPORTVAR;
738 }
vlm0aa86902004-10-12 23:26:53 +0000739 | TypeRefName '{' '}' {
vlm43c8ac52006-09-17 04:52:50 +0000740 $$ = NEW_EXPR();
vlm0aa86902004-10-12 23:26:53 +0000741 checkmem($$);
742 $$->Identifier = $1;
743 $$->expr_type = A1TC_EXPORTVAR;
744 }
vlmfa67ddc2004-06-03 03:38:44 +0000745 | Identifier {
vlm43c8ac52006-09-17 04:52:50 +0000746 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000747 checkmem($$);
748 $$->Identifier = $1;
749 $$->expr_type = A1TC_EXPORTVAR;
750 }
751 ;
752
753
vlm1aeaddd2006-07-13 08:24:20 +0000754ValueSet: '{' ElementSetSpecs '}' { $$ = $2; };
vlm59b620a2006-03-21 07:46:48 +0000755
756ValueSetTypeAssignment:
757 TypeRefName DefinedType TOK_PPEQ ValueSet {
vlmfa67ddc2004-06-03 03:38:44 +0000758 $$ = $2;
759 assert($$->Identifier == 0);
760 $$->Identifier = $1;
761 $$->meta_type = AMT_VALUESET;
vlm59b620a2006-03-21 07:46:48 +0000762 $$->constraints = $4;
vlmfa67ddc2004-06-03 03:38:44 +0000763 }
764 ;
765
vlm17e65d02006-03-21 04:48:15 +0000766DefinedType:
767 BasicType {
768 $$ = $1;
769 }
770 /*
771 * A DefinedType reference.
772 * "CLASS1.&id.&id2"
773 * or
774 * "Module.Type"
775 * or
776 * "Module.identifier"
777 * or
778 * "Type"
779 */
780 | ComplexTypeReference {
vlm43c8ac52006-09-17 04:52:50 +0000781 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000782 checkmem($$);
783 $$->reference = $1;
784 $$->expr_type = A1TC_REFERENCE;
785 $$->meta_type = AMT_TYPEREF;
786 }
vlm17e65d02006-03-21 04:48:15 +0000787 /*
vlmdfbff8c2006-03-21 09:41:28 +0000788 * A parameterized assignment.
vlm17e65d02006-03-21 04:48:15 +0000789 */
vlmdfbff8c2006-03-21 09:41:28 +0000790 | ComplexTypeReference '{' ActualParameterList '}' {
vlm43c8ac52006-09-17 04:52:50 +0000791 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000792 checkmem($$);
vlm17e65d02006-03-21 04:48:15 +0000793 $$->reference = $1;
794 $$->rhs_pspecs = $3;
795 $$->expr_type = A1TC_REFERENCE;
796 $$->meta_type = AMT_TYPEREF;
vlmfa67ddc2004-06-03 03:38:44 +0000797 }
798 ;
799
vlmfa67ddc2004-06-03 03:38:44 +0000800/*
801 * Data Type Reference.
802 * === EXAMPLE ===
803 * Type3 ::= CHOICE { a Type1, b Type 2 }
804 * === EOF ===
805 */
vlmfa67ddc2004-06-03 03:38:44 +0000806DataTypeReference:
807 /*
808 * Optionally tagged type definition.
809 */
vlmdc7cf042006-03-09 08:49:26 +0000810 TypeRefName TOK_PPEQ Type {
vlmfce48a42004-09-14 02:36:39 +0000811 $$ = $3;
vlmfa67ddc2004-06-03 03:38:44 +0000812 $$->Identifier = $1;
vlmfa67ddc2004-06-03 03:38:44 +0000813 assert($$->expr_type);
814 assert($$->meta_type);
815 }
vlmdc7cf042006-03-09 08:49:26 +0000816 | TypeRefName TOK_PPEQ ObjectClass {
vlmfa67ddc2004-06-03 03:38:44 +0000817 $$ = $3;
818 $$->Identifier = $1;
819 assert($$->expr_type == A1TC_CLASSDEF);
vlmdc7cf042006-03-09 08:49:26 +0000820 assert($$->meta_type == AMT_OBJECTCLASS);
vlmfa67ddc2004-06-03 03:38:44 +0000821 }
822 /*
vlmdfbff8c2006-03-21 09:41:28 +0000823 * Parameterized <Type> declaration:
vlmfa67ddc2004-06-03 03:38:44 +0000824 * === EXAMPLE ===
825 * SIGNED { ToBeSigned } ::= SEQUENCE {
826 * toBeSigned ToBeSigned,
827 * algorithm AlgorithmIdentifier,
828 * signature BIT STRING
829 * }
830 * === EOF ===
831 */
vlmec8f6812004-08-22 03:19:54 +0000832 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
vlmfa67ddc2004-06-03 03:38:44 +0000833 $$ = $6;
vlmdfbff8c2006-03-21 09:41:28 +0000834 $$->Identifier = $1;
835 $$->lhs_params = $3;
836 }
837 /* Parameterized CLASS declaration */
838 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ ObjectClass {
839 $$ = $6;
vlmfa67ddc2004-06-03 03:38:44 +0000840 $$->Identifier = $1;
vlm0c6d3812006-03-21 03:40:38 +0000841 $$->lhs_params = $3;
vlmfa67ddc2004-06-03 03:38:44 +0000842 }
843 ;
844
845ParameterArgumentList:
846 ParameterArgumentName {
847 int ret;
848 $$ = asn1p_paramlist_new(yylineno);
849 checkmem($$);
850 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
851 checkmem(ret == 0);
852 if($1.governor) asn1p_ref_free($1.governor);
853 if($1.argument) free($1.argument);
854 }
855 | ParameterArgumentList ',' ParameterArgumentName {
856 int ret;
857 $$ = $1;
858 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
859 checkmem(ret == 0);
860 if($3.governor) asn1p_ref_free($3.governor);
861 if($3.argument) free($3.argument);
862 }
863 ;
864
865ParameterArgumentName:
866 TypeRefName {
867 $$.governor = NULL;
868 $$.argument = $1;
869 }
870 | TypeRefName ':' Identifier {
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 }
vlm4053ca52005-02-18 16:34:21 +0000877 | TypeRefName ':' TypeRefName {
878 int ret;
879 $$.governor = asn1p_ref_new(yylineno);
880 ret = asn1p_ref_add_component($$.governor, $1, 0);
881 checkmem(ret == 0);
882 $$.argument = $3;
883 }
vlmfa67ddc2004-06-03 03:38:44 +0000884 | BasicTypeId ':' Identifier {
885 int ret;
886 $$.governor = asn1p_ref_new(yylineno);
887 ret = asn1p_ref_add_component($$.governor,
888 ASN_EXPR_TYPE2STR($1), 1);
889 checkmem(ret == 0);
890 $$.argument = $3;
891 }
vlmdfbff8c2006-03-21 09:41:28 +0000892 | BasicTypeId ':' TypeRefName {
893 int ret;
894 $$.governor = asn1p_ref_new(yylineno);
895 ret = asn1p_ref_add_component($$.governor,
896 ASN_EXPR_TYPE2STR($1), 1);
897 checkmem(ret == 0);
898 $$.argument = $3;
899 }
vlmfa67ddc2004-06-03 03:38:44 +0000900 ;
901
vlmdfbff8c2006-03-21 09:41:28 +0000902ActualParameterList:
903 ActualParameter {
vlm43c8ac52006-09-17 04:52:50 +0000904 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000905 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000906 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000907 }
vlmdfbff8c2006-03-21 09:41:28 +0000908 | ActualParameterList ',' ActualParameter {
vlmfa67ddc2004-06-03 03:38:44 +0000909 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000910 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000911 }
912 ;
913
vlmdfbff8c2006-03-21 09:41:28 +0000914ActualParameter:
vlmec8f6812004-08-22 03:19:54 +0000915 Type {
vlmfa67ddc2004-06-03 03:38:44 +0000916 $$ = $1;
917 }
vlm17e65d02006-03-21 04:48:15 +0000918 | SimpleValue {
vlm43c8ac52006-09-17 04:52:50 +0000919 $$ = NEW_EXPR();
vlm17e65d02006-03-21 04:48:15 +0000920 checkmem($$);
921 $$->Identifier = "?";
922 $$->expr_type = A1TC_REFERENCE;
923 $$->meta_type = AMT_VALUE;
924 $$->value = $1;
925 }
vlmfa67ddc2004-06-03 03:38:44 +0000926 | Identifier {
vlm0c6d3812006-03-21 03:40:38 +0000927 asn1p_ref_t *ref;
vlm43c8ac52006-09-17 04:52:50 +0000928 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000929 checkmem($$);
930 $$->Identifier = $1;
931 $$->expr_type = A1TC_REFERENCE;
932 $$->meta_type = AMT_VALUE;
vlm0c6d3812006-03-21 03:40:38 +0000933 ref = asn1p_ref_new(yylineno);
934 asn1p_ref_add_component(ref, $1, RLT_lowercase);
935 $$->value = asn1p_value_fromref(ref, 0);
vlmfa67ddc2004-06-03 03:38:44 +0000936 }
vlmdfbff8c2006-03-21 09:41:28 +0000937 | ValueSet {
vlm43c8ac52006-09-17 04:52:50 +0000938 $$ = NEW_EXPR();
vlmdfbff8c2006-03-21 09:41:28 +0000939 $$->expr_type = A1TC_VALUESET;
940 $$->meta_type = AMT_VALUESET;
941 $$->constraints = $1;
942 }
vlmfa67ddc2004-06-03 03:38:44 +0000943 ;
944
945/*
vlmdfbff8c2006-03-21 09:41:28 +0000946 | '{' ActualParameter '}' {
vlm43c8ac52006-09-17 04:52:50 +0000947 $$ = NEW_EXPR();
vlm4053ca52005-02-18 16:34:21 +0000948 checkmem($$);
949 asn1p_expr_add($$, $2);
950 $$->expr_type = A1TC_PARAMETRIZED;
951 $$->meta_type = AMT_TYPE;
952 }
953 ;
954*/
955
956/*
vlmfa67ddc2004-06-03 03:38:44 +0000957 * A collection of constructed data type members.
958 */
vlm0aa86902004-10-12 23:26:53 +0000959optComponentTypeLists:
vlm43c8ac52006-09-17 04:52:50 +0000960 { $$ = NEW_EXPR(); }
vlm0aa86902004-10-12 23:26:53 +0000961 | ComponentTypeLists { $$ = $1; };
962
vlmec8f6812004-08-22 03:19:54 +0000963ComponentTypeLists:
964 ComponentType {
vlm43c8ac52006-09-17 04:52:50 +0000965 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000966 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000967 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000968 }
vlmec8f6812004-08-22 03:19:54 +0000969 | ComponentTypeLists ',' ComponentType {
vlmfa67ddc2004-06-03 03:38:44 +0000970 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000971 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000972 }
973 ;
974
vlmec8f6812004-08-22 03:19:54 +0000975ComponentType:
vlmfce48a42004-09-14 02:36:39 +0000976 Identifier Type optMarker {
vlmec8f6812004-08-22 03:19:54 +0000977 $$ = $2;
978 assert($$->Identifier == 0);
vlmfce48a42004-09-14 02:36:39 +0000979 $$->Identifier = $1;
vlm177a5b62005-09-05 05:17:57 +0000980 $3.flags |= $$->marker.flags;
vlmec8f6812004-08-22 03:19:54 +0000981 $$->marker = $3;
982 }
vlm177a5b62005-09-05 05:17:57 +0000983 | Type optMarker {
984 $$ = $1;
985 $2.flags |= $$->marker.flags;
986 $$->marker = $2;
987 _fixup_anonymous_identifier($$);
988 }
vlmec8f6812004-08-22 03:19:54 +0000989 | TOK_COMPONENTS TOK_OF Type {
vlm43c8ac52006-09-17 04:52:50 +0000990 $$ = NEW_EXPR();
vlmec8f6812004-08-22 03:19:54 +0000991 checkmem($$);
992 $$->meta_type = $3->meta_type;
993 $$->expr_type = A1TC_COMPONENTS_OF;
vlm6a02a8a2004-09-08 00:28:11 +0000994 asn1p_expr_add($$, $3);
vlmec8f6812004-08-22 03:19:54 +0000995 }
996 | ExtensionAndException {
997 $$ = $1;
998 }
999 ;
1000
1001AlternativeTypeLists:
1002 AlternativeType {
vlm43c8ac52006-09-17 04:52:50 +00001003 $$ = NEW_EXPR();
vlmec8f6812004-08-22 03:19:54 +00001004 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +00001005 asn1p_expr_add($$, $1);
vlmec8f6812004-08-22 03:19:54 +00001006 }
1007 | AlternativeTypeLists ',' AlternativeType {
1008 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +00001009 asn1p_expr_add($$, $3);
vlmec8f6812004-08-22 03:19:54 +00001010 }
1011 ;
1012
1013AlternativeType:
vlmfce48a42004-09-14 02:36:39 +00001014 Identifier Type {
vlmec8f6812004-08-22 03:19:54 +00001015 $$ = $2;
1016 assert($$->Identifier == 0);
vlmfce48a42004-09-14 02:36:39 +00001017 $$->Identifier = $1;
vlmec8f6812004-08-22 03:19:54 +00001018 }
1019 | ExtensionAndException {
1020 $$ = $1;
1021 }
vlm5d89c3d2005-08-13 09:07:11 +00001022 | Type {
1023 $$ = $1;
1024 _fixup_anonymous_identifier($$);
1025 }
vlmec8f6812004-08-22 03:19:54 +00001026 ;
1027
vlmdc7cf042006-03-09 08:49:26 +00001028ObjectClass:
1029 TOK_CLASS '{' FieldSpec '}' optWithSyntax {
vlmfa67ddc2004-06-03 03:38:44 +00001030 $$ = $3;
1031 checkmem($$);
1032 $$->with_syntax = $5;
1033 assert($$->expr_type == A1TC_CLASSDEF);
vlmdc7cf042006-03-09 08:49:26 +00001034 assert($$->meta_type == AMT_OBJECTCLASS);
vlmfa67ddc2004-06-03 03:38:44 +00001035 }
1036 ;
1037
1038optUnique:
1039 { $$ = 0; }
1040 | TOK_UNIQUE { $$ = 1; }
1041 ;
1042
vlmdc7cf042006-03-09 08:49:26 +00001043FieldSpec:
vlmfa67ddc2004-06-03 03:38:44 +00001044 ClassField {
vlm43c8ac52006-09-17 04:52:50 +00001045 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001046 checkmem($$);
1047 $$->expr_type = A1TC_CLASSDEF;
vlmdc7cf042006-03-09 08:49:26 +00001048 $$->meta_type = AMT_OBJECTCLASS;
vlm6a02a8a2004-09-08 00:28:11 +00001049 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +00001050 }
vlmdc7cf042006-03-09 08:49:26 +00001051 | FieldSpec ',' ClassField {
vlmfa67ddc2004-06-03 03:38:44 +00001052 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +00001053 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001054 }
1055 ;
1056
vlmdc7cf042006-03-09 08:49:26 +00001057 /* X.681 */
vlmfa67ddc2004-06-03 03:38:44 +00001058ClassField:
vlmdc7cf042006-03-09 08:49:26 +00001059
1060 /* TypeFieldSpec ::= typefieldreference TypeOptionalitySpec? */
1061 TOK_typefieldreference optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001062 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001063 checkmem($$);
vlmdc7cf042006-03-09 08:49:26 +00001064 $$->Identifier = $1;
vlmfa67ddc2004-06-03 03:38:44 +00001065 $$->meta_type = AMT_OBJECTFIELD;
vlmdc7cf042006-03-09 08:49:26 +00001066 $$->expr_type = A1TC_CLASSFIELD_TFS; /* TypeFieldSpec */
vlmfa67ddc2004-06-03 03:38:44 +00001067 $$->marker = $2;
1068 }
vlmdc7cf042006-03-09 08:49:26 +00001069
1070 /* FixedTypeValueFieldSpec ::= valuefieldreference Type UNIQUE ? ValueOptionalitySpec ? */
1071 | TOK_valuefieldreference Type optUnique optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001072 $$ = NEW_EXPR();
vlmdc7cf042006-03-09 08:49:26 +00001073 $$->Identifier = $1;
1074 $$->meta_type = AMT_OBJECTFIELD;
1075 $$->expr_type = A1TC_CLASSFIELD_FTVFS; /* FixedTypeValueFieldSpec */
vlmbde35d42004-11-24 17:43:29 +00001076 $$->unique = $3;
vlmdc7cf042006-03-09 08:49:26 +00001077 $$->marker = $4;
1078 asn1p_expr_add($$, $2);
vlmfa67ddc2004-06-03 03:38:44 +00001079 }
vlmdc7cf042006-03-09 08:49:26 +00001080
1081 /* VariableTypeValueFieldSpec ::= valuefieldreference FieldName ValueOptionalitySpec ? */
1082 | TOK_valuefieldreference FieldName optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001083 $$ = NEW_EXPR();
vlmdc7cf042006-03-09 08:49:26 +00001084 $$->Identifier = $1;
1085 $$->meta_type = AMT_OBJECTFIELD;
1086 $$->expr_type = A1TC_CLASSFIELD_VTVFS;
1087 $$->reference = $2;
1088 $$->marker = $3;
1089 }
1090
vlmdc7cf042006-03-09 08:49:26 +00001091 /* ObjectFieldSpec ::= objectfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1092 | TOK_valuefieldreference DefinedObjectClass optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001093 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001094 checkmem($$);
vlmdc7cf042006-03-09 08:49:26 +00001095 $$->Identifier = $1;
1096 $$->reference = $2;
vlmfa67ddc2004-06-03 03:38:44 +00001097 $$->meta_type = AMT_OBJECTFIELD;
vlmdc7cf042006-03-09 08:49:26 +00001098 $$->expr_type = A1TC_CLASSFIELD_OFS;
1099 $$->marker = $3;
vlmfa67ddc2004-06-03 03:38:44 +00001100 }
vlmdc7cf042006-03-09 08:49:26 +00001101
vlmee7196e2006-03-09 09:08:49 +00001102 /* VariableTypeValueSetFieldSpec ::= valuesetfieldreference FieldName ValueOptionalitySpec ? */
1103 | TOK_typefieldreference FieldName optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001104 $$ = NEW_EXPR();
vlmdc7cf042006-03-09 08:49:26 +00001105 $$->Identifier = $1;
vlmdc7cf042006-03-09 08:49:26 +00001106 $$->meta_type = AMT_OBJECTFIELD;
vlmee7196e2006-03-09 09:08:49 +00001107 $$->expr_type = A1TC_CLASSFIELD_VTVSFS;
1108 $$->reference = $2;
vlmdc7cf042006-03-09 08:49:26 +00001109 $$->marker = $3;
1110 }
1111
1112 /* FixedTypeValueSetFieldSpec ::= valuesetfieldreference Type ValueSetOptionalitySpec ? */
1113 | TOK_typefieldreference Type optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001114 $$ = NEW_EXPR();
vlmdc7cf042006-03-09 08:49:26 +00001115 checkmem($$);
1116 $$->Identifier = $1;
1117 $$->meta_type = AMT_OBJECTFIELD;
1118 $$->expr_type = A1TC_CLASSFIELD_FTVSFS;
1119 asn1p_expr_add($$, $2);
1120 $$->marker = $3;
1121 }
1122
vlmee7196e2006-03-09 09:08:49 +00001123 /* ObjectSetFieldSpec ::= objectsetfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1124 | TOK_typefieldreference DefinedObjectClass optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001125 $$ = NEW_EXPR();
vlmee7196e2006-03-09 09:08:49 +00001126 checkmem($$);
1127 $$->Identifier = $1;
1128 $$->reference = $2;
1129 $$->meta_type = AMT_OBJECTFIELD;
1130 $$->expr_type = A1TC_CLASSFIELD_OSFS;
1131 $$->marker = $3;
1132 }
vlmfa67ddc2004-06-03 03:38:44 +00001133 ;
1134
1135optWithSyntax:
1136 { $$ = 0; }
1137 | WithSyntax {
1138 $$ = $1;
1139 }
1140 ;
1141
1142WithSyntax:
1143 TOK_WITH TOK_SYNTAX '{'
1144 { asn1p_lexer_hack_enable_with_syntax(); }
vlm808411d2006-03-14 16:31:37 +00001145 WithSyntaxList
vlmfa67ddc2004-06-03 03:38:44 +00001146 '}' {
1147 $$ = $5;
1148 }
1149 ;
1150
vlm808411d2006-03-14 16:31:37 +00001151WithSyntaxList:
1152 WithSyntaxToken {
vlmfa67ddc2004-06-03 03:38:44 +00001153 $$ = asn1p_wsyntx_new();
1154 TQ_ADD(&($$->chunks), $1, next);
1155 }
vlm808411d2006-03-14 16:31:37 +00001156 | WithSyntaxList WithSyntaxToken {
vlmfa67ddc2004-06-03 03:38:44 +00001157 $$ = $1;
1158 TQ_ADD(&($$->chunks), $2, next);
1159 }
1160 ;
1161
vlm808411d2006-03-14 16:31:37 +00001162WithSyntaxToken:
vlmeeb3c512006-03-16 05:11:14 +00001163 TOK_whitespace {
vlm1fcf7592006-08-18 02:27:55 +00001164 $$ = asn1p_wsyntx_chunk_fromstring($1.buf, 0);
vlmeeb3c512006-03-16 05:11:14 +00001165 $$->type = WC_WHITESPACE;
vlmfa67ddc2004-06-03 03:38:44 +00001166 }
vlm808411d2006-03-14 16:31:37 +00001167 | TOK_Literal {
vlm1fcf7592006-08-18 02:27:55 +00001168 $$ = asn1p_wsyntx_chunk_fromstring($1, 0);
vlm808411d2006-03-14 16:31:37 +00001169 }
vlma6a84d72006-03-16 10:03:35 +00001170 | PrimitiveFieldReference {
vlm1fcf7592006-08-18 02:27:55 +00001171 $$ = asn1p_wsyntx_chunk_fromstring($1.name, 0);
vlma6a84d72006-03-16 10:03:35 +00001172 $$->type = WC_FIELD;
vlmfa67ddc2004-06-03 03:38:44 +00001173 }
vlm808411d2006-03-14 16:31:37 +00001174 | '[' WithSyntaxList ']' {
1175 $$ = asn1p_wsyntx_chunk_fromsyntax($2);
1176 }
vlmfa67ddc2004-06-03 03:38:44 +00001177 ;
1178
vlmfa67ddc2004-06-03 03:38:44 +00001179ExtensionAndException:
1180 TOK_ThreeDots {
vlm43c8ac52006-09-17 04:52:50 +00001181 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001182 checkmem($$);
1183 $$->Identifier = strdup("...");
1184 checkmem($$->Identifier);
1185 $$->expr_type = A1TC_EXTENSIBLE;
1186 $$->meta_type = AMT_TYPE;
1187 }
1188 | TOK_ThreeDots '!' DefinedValue {
vlm43c8ac52006-09-17 04:52:50 +00001189 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001190 checkmem($$);
1191 $$->Identifier = strdup("...");
1192 checkmem($$->Identifier);
1193 $$->value = $3;
1194 $$->expr_type = A1TC_EXTENSIBLE;
1195 $$->meta_type = AMT_TYPE;
1196 }
1197 | TOK_ThreeDots '!' SignedNumber {
vlm43c8ac52006-09-17 04:52:50 +00001198 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001199 checkmem($$);
1200 $$->Identifier = strdup("...");
1201 $$->value = $3;
1202 checkmem($$->Identifier);
1203 $$->expr_type = A1TC_EXTENSIBLE;
1204 $$->meta_type = AMT_TYPE;
1205 }
1206 ;
1207
vlmec8f6812004-08-22 03:19:54 +00001208Type:
vlmfce48a42004-09-14 02:36:39 +00001209 optTag TypeDeclaration optConstraints {
1210 $$ = $2;
1211 $$->tag = $1;
vlmec8f6812004-08-22 03:19:54 +00001212 /*
1213 * Outer constraint for SEQUENCE OF and SET OF applies
1214 * to the inner type.
1215 */
1216 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1217 || $$->expr_type == ASN_CONSTR_SET_OF) {
1218 assert(!TQ_FIRST(&($$->members))->constraints);
vlmfce48a42004-09-14 02:36:39 +00001219 TQ_FIRST(&($$->members))->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001220 } else {
1221 if($$->constraints) {
1222 assert(!$2);
1223 } else {
vlmfce48a42004-09-14 02:36:39 +00001224 $$->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001225 }
1226 }
vlm177a5b62005-09-05 05:17:57 +00001227 }
1228 ;
1229
1230NSTD_IndirectMarker:
1231 {
1232 $$ = asn1p_as_pointer ? EM_INDIRECT : 0;
1233 asn1p_as_pointer = 0;
vlmec8f6812004-08-22 03:19:54 +00001234 }
1235 ;
1236
1237TypeDeclaration:
vlm177a5b62005-09-05 05:17:57 +00001238 NSTD_IndirectMarker TypeDeclarationSet {
vlm066dc102005-08-22 12:23:54 +00001239 $$ = $2;
vlm177a5b62005-09-05 05:17:57 +00001240 $$->marker.flags |= $1;
1241
1242 if(($$->marker.flags & EM_INDIRECT)
1243 && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
1244 fprintf(stderr,
1245 "INFO: Directive <ASN1C:RepresentAsPointer> "
1246 "applied to %s at line %d\n",
1247 ASN_EXPR_TYPE2STR($$->expr_type)
1248 ? ASN_EXPR_TYPE2STR($$->expr_type)
1249 : "member",
1250 $$->_lineno
1251 );
1252 }
vlm066dc102005-08-22 12:23:54 +00001253 }
vlm177a5b62005-09-05 05:17:57 +00001254 ;
vlm066dc102005-08-22 12:23:54 +00001255
1256TypeDeclarationSet:
vlm17e65d02006-03-21 04:48:15 +00001257 DefinedType {
vlmfa67ddc2004-06-03 03:38:44 +00001258 $$ = $1;
1259 }
vlm177a5b62005-09-05 05:17:57 +00001260 | TOK_CHOICE '{' AlternativeTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001261 $$ = $3;
1262 assert($$->expr_type == A1TC_INVALID);
1263 $$->expr_type = ASN_CONSTR_CHOICE;
1264 $$->meta_type = AMT_TYPE;
vlmfa67ddc2004-06-03 03:38:44 +00001265 }
vlm177a5b62005-09-05 05:17:57 +00001266 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001267 $$ = $3;
1268 assert($$->expr_type == A1TC_INVALID);
1269 $$->expr_type = ASN_CONSTR_SEQUENCE;
1270 $$->meta_type = AMT_TYPE;
1271 }
vlm177a5b62005-09-05 05:17:57 +00001272 | TOK_SET '{' optComponentTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001273 $$ = $3;
1274 assert($$->expr_type == A1TC_INVALID);
1275 $$->expr_type = ASN_CONSTR_SET;
1276 $$->meta_type = AMT_TYPE;
1277 }
vlm151c0b22004-09-22 16:03:36 +00001278 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
vlm43c8ac52006-09-17 04:52:50 +00001279 $$ = NEW_EXPR();
vlmec8f6812004-08-22 03:19:54 +00001280 checkmem($$);
1281 $$->constraints = $2;
1282 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1283 $$->meta_type = AMT_TYPE;
vlm151c0b22004-09-22 16:03:36 +00001284 $6->Identifier = $4;
1285 $6->tag = $5;
1286 asn1p_expr_add($$, $6);
vlmec8f6812004-08-22 03:19:54 +00001287 }
vlm151c0b22004-09-22 16:03:36 +00001288 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
vlm43c8ac52006-09-17 04:52:50 +00001289 $$ = NEW_EXPR();
vlmec8f6812004-08-22 03:19:54 +00001290 checkmem($$);
1291 $$->constraints = $2;
1292 $$->expr_type = ASN_CONSTR_SET_OF;
1293 $$->meta_type = AMT_TYPE;
vlm151c0b22004-09-22 16:03:36 +00001294 $6->Identifier = $4;
1295 $6->tag = $5;
1296 asn1p_expr_add($$, $6);
vlmec8f6812004-08-22 03:19:54 +00001297 }
1298 | TOK_ANY {
vlm43c8ac52006-09-17 04:52:50 +00001299 $$ = NEW_EXPR();
vlmec8f6812004-08-22 03:19:54 +00001300 checkmem($$);
vlm044f7442004-09-04 04:49:21 +00001301 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001302 $$->meta_type = AMT_TYPE;
1303 }
1304 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1305 int ret;
vlm43c8ac52006-09-17 04:52:50 +00001306 $$ = NEW_EXPR();
vlmec8f6812004-08-22 03:19:54 +00001307 checkmem($$);
1308 $$->reference = asn1p_ref_new(yylineno);
1309 ret = asn1p_ref_add_component($$->reference,
1310 $4, RLT_lowercase);
1311 checkmem(ret == 0);
vlm044f7442004-09-04 04:49:21 +00001312 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001313 $$->meta_type = AMT_TYPE;
1314 }
vlmfa67ddc2004-06-03 03:38:44 +00001315 | TOK_INSTANCE TOK_OF ComplexTypeReference {
vlm43c8ac52006-09-17 04:52:50 +00001316 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001317 checkmem($$);
1318 $$->reference = $3;
1319 $$->expr_type = A1TC_INSTANCE;
1320 $$->meta_type = AMT_TYPE;
1321 }
1322 ;
1323
1324/*
1325 * A type name consisting of several components.
1326 * === EXAMPLE ===
1327 * === EOF ===
1328 */
1329ComplexTypeReference:
1330 TOK_typereference {
1331 int ret;
1332 $$ = asn1p_ref_new(yylineno);
1333 checkmem($$);
1334 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1335 checkmem(ret == 0);
1336 free($1);
1337 }
1338 | TOK_typereference '.' TypeRefName {
1339 int ret;
1340 $$ = asn1p_ref_new(yylineno);
1341 checkmem($$);
1342 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1343 checkmem(ret == 0);
1344 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1345 checkmem(ret == 0);
1346 free($1);
1347 }
vlmc94e28f2004-09-15 11:59:51 +00001348 | ObjectClassReference '.' TypeRefName {
1349 int ret;
1350 $$ = asn1p_ref_new(yylineno);
1351 checkmem($$);
1352 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1353 checkmem(ret == 0);
1354 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1355 checkmem(ret == 0);
1356 free($1);
1357 }
vlmfa67ddc2004-06-03 03:38:44 +00001358 | TOK_typereference '.' Identifier {
1359 int ret;
1360 $$ = asn1p_ref_new(yylineno);
1361 checkmem($$);
1362 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1363 checkmem(ret == 0);
1364 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1365 checkmem(ret == 0);
1366 free($1);
1367 }
1368 | ObjectClassReference {
1369 int ret;
1370 $$ = asn1p_ref_new(yylineno);
1371 checkmem($$);
1372 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1373 free($1);
1374 checkmem(ret == 0);
1375 }
1376 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1377 int ret;
1378 $$ = $3;
1379 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1380 free($1);
1381 checkmem(ret == 0);
1382 /*
1383 * Move the last element infront.
1384 */
1385 {
1386 struct asn1p_ref_component_s tmp_comp;
1387 tmp_comp = $$->components[$$->comp_count-1];
1388 memmove(&$$->components[1],
1389 &$$->components[0],
1390 sizeof($$->components[0])
1391 * ($$->comp_count - 1));
1392 $$->components[0] = tmp_comp;
1393 }
1394 }
1395 ;
1396
1397ComplexTypeReferenceAmpList:
1398 ComplexTypeReferenceElement {
1399 int ret;
1400 $$ = asn1p_ref_new(yylineno);
1401 checkmem($$);
1402 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1403 free($1.name);
1404 checkmem(ret == 0);
1405 }
1406 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1407 int ret;
1408 $$ = $1;
1409 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1410 free($3.name);
1411 checkmem(ret == 0);
1412 }
1413 ;
1414
vlma6a84d72006-03-16 10:03:35 +00001415ComplexTypeReferenceElement: PrimitiveFieldReference;
vlmfa67ddc2004-06-03 03:38:44 +00001416
vlma6a84d72006-03-16 10:03:35 +00001417PrimitiveFieldReference:
vlmfa67ddc2004-06-03 03:38:44 +00001418 /* "&Type1" */
1419 TOK_typefieldreference {
1420 $$.lex_type = RLT_AmpUppercase;
1421 $$.name = $1;
1422 }
1423 /* "&id" */
1424 | TOK_valuefieldreference {
1425 $$.lex_type = RLT_Amplowercase;
1426 $$.name = $1;
1427 }
1428 ;
1429
1430
vlmdc7cf042006-03-09 08:49:26 +00001431FieldName:
1432 /* "&Type1" */
1433 TOK_typefieldreference {
1434 $$ = asn1p_ref_new(yylineno);
1435 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1436 }
1437 | FieldName '.' TOK_typefieldreference {
1438 $$ = $$;
1439 asn1p_ref_add_component($$, $3, RLT_AmpUppercase);
1440 }
1441 | FieldName '.' TOK_valuefieldreference {
1442 $$ = $$;
1443 asn1p_ref_add_component($$, $3, RLT_Amplowercase);
1444 }
1445 ;
1446
1447DefinedObjectClass:
1448 TOK_capitalreference {
1449 $$ = asn1p_ref_new(yylineno);
1450 asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1451 }
vlmee7196e2006-03-09 09:08:49 +00001452/*
vlmdc7cf042006-03-09 08:49:26 +00001453 | TypeRefName '.' TOK_capitalreference {
1454 $$ = asn1p_ref_new(yylineno);
1455 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1456 asn1p_ref_add_component($$, $3, RLT_CAPITALS);
1457 }
vlmee7196e2006-03-09 09:08:49 +00001458*/
vlmdc7cf042006-03-09 08:49:26 +00001459 ;
1460
1461
vlmfa67ddc2004-06-03 03:38:44 +00001462/*
1463 * === EXAMPLE ===
1464 * value INTEGER ::= 1
1465 * === EOF ===
1466 */
vlmb9f1c0d2006-10-21 05:54:49 +00001467ValueAssignment:
1468 Identifier Type TOK_PPEQ Value {
vlmfa67ddc2004-06-03 03:38:44 +00001469 $$ = $2;
1470 assert($$->Identifier == NULL);
1471 $$->Identifier = $1;
1472 $$->meta_type = AMT_VALUE;
1473 $$->value = $4;
1474 }
1475 ;
1476
vlmc94e28f2004-09-15 11:59:51 +00001477Value:
vlm17e65d02006-03-21 04:48:15 +00001478 SimpleValue
1479 | DefinedValue
1480 | Identifier ':' Value {
vlmc94e28f2004-09-15 11:59:51 +00001481 $$ = asn1p_value_fromint(0);
1482 checkmem($$);
1483 $$->type = ATV_CHOICE_IDENTIFIER;
1484 $$->value.choice_identifier.identifier = $1;
1485 $$->value.choice_identifier.value = $3;
1486 }
vlmd30bc6c2005-03-24 16:27:02 +00001487 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
vlmfa67ddc2004-06-03 03:38:44 +00001488 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1489 checkmem($$);
1490 $$->type = ATV_UNPARSED;
1491 }
vlmc94e28f2004-09-15 11:59:51 +00001492 | TOK_NULL {
1493 $$ = asn1p_value_fromint(0);
1494 checkmem($$);
1495 $$->type = ATV_NULL;
1496 }
vlm17e65d02006-03-21 04:48:15 +00001497 ;
1498
1499SimpleValue:
1500 TOK_FALSE {
vlmc94e28f2004-09-15 11:59:51 +00001501 $$ = asn1p_value_fromint(0);
1502 checkmem($$);
1503 $$->type = ATV_FALSE;
1504 }
1505 | TOK_TRUE {
1506 $$ = asn1p_value_fromint(0);
1507 checkmem($$);
1508 $$->type = ATV_TRUE;
1509 }
vlmfa67ddc2004-06-03 03:38:44 +00001510 | TOK_bstring {
1511 $$ = _convert_bitstring2binary($1, 'B');
1512 checkmem($$);
1513 }
1514 | TOK_hstring {
1515 $$ = _convert_bitstring2binary($1, 'H');
1516 checkmem($$);
1517 }
vlme1e6ed82005-03-24 14:26:38 +00001518 | RestrictedCharacterStringValue {
1519 $$ = $$;
vlmfa67ddc2004-06-03 03:38:44 +00001520 }
1521 | SignedNumber {
1522 $$ = $1;
1523 }
vlmfa67ddc2004-06-03 03:38:44 +00001524 ;
1525
1526DefinedValue:
1527 Identifier {
1528 asn1p_ref_t *ref;
1529 int ret;
1530 ref = asn1p_ref_new(yylineno);
1531 checkmem(ref);
1532 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1533 checkmem(ret == 0);
1534 $$ = asn1p_value_fromref(ref, 0);
1535 checkmem($$);
1536 free($1);
1537 }
1538 | TypeRefName '.' Identifier {
1539 asn1p_ref_t *ref;
1540 int ret;
1541 ref = asn1p_ref_new(yylineno);
1542 checkmem(ref);
1543 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1544 checkmem(ret == 0);
1545 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1546 checkmem(ret == 0);
1547 $$ = asn1p_value_fromref(ref, 0);
1548 checkmem($$);
1549 free($1);
1550 free($3);
1551 }
1552 ;
1553
vlme1e6ed82005-03-24 14:26:38 +00001554
1555RestrictedCharacterStringValue:
1556 TOK_cstring {
1557 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1558 checkmem($$);
1559 }
vlm2c8c44d2005-03-24 16:22:35 +00001560 | TOK_tuple {
1561 $$ = asn1p_value_fromint($1);
1562 checkmem($$);
1563 $$->type = ATV_TUPLE;
1564 }
1565 | TOK_quadruple {
1566 $$ = asn1p_value_fromint($1);
1567 checkmem($$);
1568 $$->type = ATV_QUADRUPLE;
1569 }
vlme1e6ed82005-03-24 14:26:38 +00001570 ;
1571
vlmfa67ddc2004-06-03 03:38:44 +00001572Opaque:
1573 TOK_opaque {
vlm6611add2005-03-20 14:28:32 +00001574 $$.len = $1.len + 1;
vlmfa67ddc2004-06-03 03:38:44 +00001575 $$.buf = malloc($$.len + 1);
1576 checkmem($$.buf);
1577 $$.buf[0] = '{';
vlm6611add2005-03-20 14:28:32 +00001578 memcpy($$.buf + 1, $1.buf, $1.len);
vlmfa67ddc2004-06-03 03:38:44 +00001579 $$.buf[$$.len] = '\0';
1580 free($1.buf);
1581 }
1582 | Opaque TOK_opaque {
1583 int newsize = $1.len + $2.len;
1584 char *p = malloc(newsize + 1);
1585 checkmem(p);
1586 memcpy(p , $1.buf, $1.len);
1587 memcpy(p + $1.len, $2.buf, $2.len);
1588 p[newsize] = '\0';
1589 free($1.buf);
1590 free($2.buf);
1591 $$.buf = p;
1592 $$.len = newsize;
1593 }
1594 ;
1595
1596BasicTypeId:
1597 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1598 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1599 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1600 | BasicTypeId_UniverationCompatible { $$ = $1; }
1601 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1602 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1603 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1604 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1605 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1606 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1607 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1608 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
vlm5e2c4b92005-03-20 11:12:40 +00001609 | BasicString { $$ = $1; }
vlmfa67ddc2004-06-03 03:38:44 +00001610 ;
1611
1612/*
1613 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1614 */
1615BasicTypeId_UniverationCompatible:
1616 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1617 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1618 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1619 ;
1620
1621BasicType:
1622 BasicTypeId {
vlm43c8ac52006-09-17 04:52:50 +00001623 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001624 checkmem($$);
1625 $$->expr_type = $1;
1626 $$->meta_type = AMT_TYPE;
1627 }
1628 | BasicTypeId_UniverationCompatible UniverationDefinition {
1629 if($2) {
1630 $$ = $2;
1631 } else {
vlm43c8ac52006-09-17 04:52:50 +00001632 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001633 checkmem($$);
1634 }
1635 $$->expr_type = $1;
1636 $$->meta_type = AMT_TYPE;
1637 }
1638 ;
1639
1640BasicString:
1641 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1642 | TOK_GeneralString {
1643 $$ = ASN_STRING_GeneralString;
vlmc94e28f2004-09-15 11:59:51 +00001644 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001645 }
1646 | TOK_GraphicString {
1647 $$ = ASN_STRING_GraphicString;
vlmc94e28f2004-09-15 11:59:51 +00001648 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001649 }
1650 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1651 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1652 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1653 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1654 | TOK_T61String {
1655 $$ = ASN_STRING_T61String;
vlmc94e28f2004-09-15 11:59:51 +00001656 fprintf(stderr, "WARNING: T61String is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001657 }
1658 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1659 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1660 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1661 | TOK_VideotexString {
1662 $$ = ASN_STRING_VideotexString;
vlmc94e28f2004-09-15 11:59:51 +00001663 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001664 }
1665 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1666 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1667 ;
1668
vlm5f0128b2004-08-20 13:25:29 +00001669
vlmfa67ddc2004-06-03 03:38:44 +00001670/*
1671 * Data type constraints.
1672 */
vlm1bc782f2006-09-21 01:50:37 +00001673UnionMark: '|' | TOK_UNION;
1674IntersectionMark: '^' | TOK_INTERSECTION;
vlmfa67ddc2004-06-03 03:38:44 +00001675
vlm9283dbe2004-08-18 04:59:12 +00001676optConstraints:
1677 { $$ = 0; }
vlm43c8ac52006-09-17 04:52:50 +00001678 | Constraint {
vlm5f0128b2004-08-20 13:25:29 +00001679 $$ = $1;
1680 }
1681 ;
1682
vlm43c8ac52006-09-17 04:52:50 +00001683Constraint:
1684 SubtypeConstraint
vlm43c8ac52006-09-17 04:52:50 +00001685 ;
1686
1687SubtypeConstraint:
vlm5f0128b2004-08-20 13:25:29 +00001688 SetOfConstraints {
vlm9fe7c922005-08-12 10:08:45 +00001689 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
vlm9283dbe2004-08-18 04:59:12 +00001690 }
1691 | TOK_SIZE '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001692 /*
1693 * This is a special case, for compatibility purposes.
vlm9283dbe2004-08-18 04:59:12 +00001694 * It goes without parentheses.
vlmfa67ddc2004-06-03 03:38:44 +00001695 */
vlm9fe7c922005-08-12 10:08:45 +00001696 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001697 }
vlmfa67ddc2004-06-03 03:38:44 +00001698 ;
1699
vlm9283dbe2004-08-18 04:59:12 +00001700SetOfConstraints:
1701 '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001702 $$ = $2;
1703 }
vlm9283dbe2004-08-18 04:59:12 +00001704 | SetOfConstraints '(' ElementSetSpecs ')' {
vlm9fe7c922005-08-12 10:08:45 +00001705 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
vlm9283dbe2004-08-18 04:59:12 +00001706 }
vlmfa67ddc2004-06-03 03:38:44 +00001707 ;
1708
vlm9283dbe2004-08-18 04:59:12 +00001709ElementSetSpecs:
vlmdfbff8c2006-03-21 09:41:28 +00001710 TOK_ThreeDots {
1711 $$ = asn1p_constraint_new(yylineno);
1712 $$->type = ACT_EL_EXT;
1713 }
1714 | ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001715 $$ = $1;
1716 }
vlm9283dbe2004-08-18 04:59:12 +00001717 | ElementSetSpec ',' TOK_ThreeDots {
vlmfa67ddc2004-06-03 03:38:44 +00001718 asn1p_constraint_t *ct;
1719 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001720 ct->type = ACT_EL_EXT;
vlm9fe7c922005-08-12 10:08:45 +00001721 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlmfa67ddc2004-06-03 03:38:44 +00001722 }
vlm9283dbe2004-08-18 04:59:12 +00001723 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001724 asn1p_constraint_t *ct;
1725 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001726 ct->type = ACT_EL_EXT;
vlm9fe7c922005-08-12 10:08:45 +00001727 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlm6f5eb0b2004-08-13 12:35:09 +00001728 ct = $$;
vlm9fe7c922005-08-12 10:08:45 +00001729 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
vlmfa67ddc2004-06-03 03:38:44 +00001730 }
vlmb9f1c0d2006-10-21 05:54:49 +00001731 | GeneralConstraint {
1732 $$ = $1;
1733 }
vlmfa67ddc2004-06-03 03:38:44 +00001734 ;
1735
vlm9283dbe2004-08-18 04:59:12 +00001736ElementSetSpec:
vlm1bc782f2006-09-21 01:50:37 +00001737 Unions
vlme1e6ed82005-03-24 14:26:38 +00001738 | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001739 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
vlme1e6ed82005-03-24 14:26:38 +00001740 }
vlm1bc782f2006-09-21 01:50:37 +00001741 ;
1742
1743Unions:
1744 Intersections
1745 | Unions UnionMark Intersections {
vlm9fe7c922005-08-12 10:08:45 +00001746 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001747 }
vlm1bc782f2006-09-21 01:50:37 +00001748 ;
1749
1750Intersections:
1751 IntersectionElements
1752 | Intersections IntersectionMark IntersectionElements {
vlm9fe7c922005-08-12 10:08:45 +00001753 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001754 }
vlm1bc782f2006-09-21 01:50:37 +00001755 ;
1756
1757
1758IntersectionElements:
1759 ConstraintSubtypeElement
1760 | ConstraintSubtypeElement TOK_EXCEPT ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001761 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001762 }
1763 ;
1764
1765ConstraintSubtypeElement:
vlm9283dbe2004-08-18 04:59:12 +00001766 ConstraintSpec '(' ElementSetSpecs ')' {
1767 int ret;
1768 $$ = asn1p_constraint_new(yylineno);
1769 checkmem($$);
1770 $$->type = $1;
1771 ret = asn1p_constraint_insert($$, $3);
1772 checkmem(ret == 0);
1773 }
1774 | '(' ElementSetSpecs ')' {
1775 int ret;
1776 $$ = asn1p_constraint_new(yylineno);
1777 checkmem($$);
1778 $$->type = ACT_CA_SET;
1779 ret = asn1p_constraint_insert($$, $2);
1780 checkmem(ret == 0);
1781 }
vlma6a12e32005-03-20 12:58:00 +00001782 | SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001783 $$ = asn1p_constraint_new(yylineno);
1784 checkmem($$);
1785 $$->type = ACT_EL_VALUE;
1786 $$->value = $1;
1787 }
vlma6a12e32005-03-20 12:58:00 +00001788 | ContainedSubtype {
1789 $$ = asn1p_constraint_new(yylineno);
1790 checkmem($$);
1791 $$->type = ACT_EL_TYPE;
1792 $$->containedSubtype = $1;
1793 }
1794 | SingleValue ConstraintRangeSpec SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001795 $$ = asn1p_constraint_new(yylineno);
1796 checkmem($$);
1797 $$->type = $2;
1798 $$->range_start = $1;
1799 $$->range_stop = $3;
1800 }
vlma6a12e32005-03-20 12:58:00 +00001801 | TOK_MIN ConstraintRangeSpec SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001802 $$ = asn1p_constraint_new(yylineno);
1803 checkmem($$);
vlm9283dbe2004-08-18 04:59:12 +00001804 $$->type = $2;
1805 $$->range_start = asn1p_value_fromint(-123);
1806 $$->range_stop = $3;
1807 $$->range_start->type = ATV_MIN;
1808 }
vlma6a12e32005-03-20 12:58:00 +00001809 | SingleValue ConstraintRangeSpec TOK_MAX {
vlm9283dbe2004-08-18 04:59:12 +00001810 $$ = asn1p_constraint_new(yylineno);
1811 checkmem($$);
1812 $$->type = $2;
1813 $$->range_start = $1;
1814 $$->range_stop = asn1p_value_fromint(321);
1815 $$->range_stop->type = ATV_MAX;
1816 }
1817 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1818 $$ = asn1p_constraint_new(yylineno);
1819 checkmem($$);
1820 $$->type = $2;
1821 $$->range_start = asn1p_value_fromint(-123);
1822 $$->range_stop = asn1p_value_fromint(321);
1823 $$->range_start->type = ATV_MIN;
1824 $$->range_stop->type = ATV_MAX;
vlmfa67ddc2004-06-03 03:38:44 +00001825 }
vlm7bbdc9f2005-03-28 15:01:27 +00001826 | InnerTypeConstraint {
vlmfa67ddc2004-06-03 03:38:44 +00001827 $$ = $1;
1828 }
vlm8cc3f742006-10-18 18:40:14 +00001829 | PatternConstraint {
1830 $$ = $1;
1831 }
1832 ;
1833
1834PatternConstraint:
1835 TOK_PATTERN TOK_cstring {
1836 $$ = asn1p_constraint_new(yylineno);
1837 $$->type = ACT_CT_PATTERN;
1838 $$->value = asn1p_value_frombuf($2.buf, $2.len, 0);
1839 }
1840 | TOK_PATTERN Identifier {
1841 asn1p_ref_t *ref;
1842 $$ = asn1p_constraint_new(yylineno);
1843 $$->type = ACT_CT_PATTERN;
1844 ref = asn1p_ref_new(yylineno);
1845 asn1p_ref_add_component(ref, $2, RLT_lowercase);
1846 $$->value = asn1p_value_fromref(ref, 0);
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
vlm64aaa9e2006-10-27 05:37:39 +00001872 | BitStringValue
vlmfa67ddc2004-06-03 03:38:44 +00001873 | Identifier {
1874 asn1p_ref_t *ref;
1875 int ret;
1876 ref = asn1p_ref_new(yylineno);
1877 checkmem(ref);
1878 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1879 checkmem(ret == 0);
1880 $$ = asn1p_value_fromref(ref, 0);
1881 checkmem($$);
1882 free($1);
1883 }
vlma6a12e32005-03-20 12:58:00 +00001884 ;
1885
vlm64aaa9e2006-10-27 05:37:39 +00001886BitStringValue:
1887 TOK_bstring {
1888 $$ = _convert_bitstring2binary($1, 'B');
1889 checkmem($$);
1890 }
1891 | TOK_hstring {
1892 $$ = _convert_bitstring2binary($1, 'H');
1893 checkmem($$);
1894 }
1895 ;
1896
vlma6a12e32005-03-20 12:58:00 +00001897ContainedSubtype:
1898 TypeRefName {
vlm4053ca52005-02-18 16:34:21 +00001899 asn1p_ref_t *ref;
1900 int ret;
1901 ref = asn1p_ref_new(yylineno);
1902 checkmem(ref);
1903 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1904 checkmem(ret == 0);
1905 $$ = asn1p_value_fromref(ref, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001906 checkmem($$);
vlm4053ca52005-02-18 16:34:21 +00001907 free($1);
vlmfa67ddc2004-06-03 03:38:44 +00001908 }
1909 ;
1910
vlm7bbdc9f2005-03-28 15:01:27 +00001911InnerTypeConstraint:
1912 TOK_WITH TOK_COMPONENT SetOfConstraints {
vlm9fe7c922005-08-12 10:08:45 +00001913 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
vlm7bbdc9f2005-03-28 15:01:27 +00001914 }
1915 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
vlm9fe7c922005-08-12 10:08:45 +00001916 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001917 }
1918 ;
1919
1920WithComponentsList:
1921 WithComponentsElement {
1922 $$ = $1;
1923 }
1924 | WithComponentsList ',' WithComponentsElement {
vlm9fe7c922005-08-12 10:08:45 +00001925 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001926 }
1927 ;
1928
1929WithComponentsElement:
1930 TOK_ThreeDots {
1931 $$ = asn1p_constraint_new(yylineno);
1932 checkmem($$);
1933 $$->type = ACT_EL_EXT;
vlm1aeaddd2006-07-13 08:24:20 +00001934 $$->value = asn1p_value_frombuf("...", 3, 1);
vlmfa67ddc2004-06-03 03:38:44 +00001935 }
1936 | Identifier optConstraints optPresenceConstraint {
1937 $$ = asn1p_constraint_new(yylineno);
1938 checkmem($$);
1939 $$->type = ACT_EL_VALUE;
1940 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1941 $$->presence = $3;
vlm7bbdc9f2005-03-28 15:01:27 +00001942 if($2) asn1p_constraint_insert($$, $2);
vlmfa67ddc2004-06-03 03:38:44 +00001943 }
1944 ;
1945
1946/*
1947 * presence constraint for WithComponents
1948 */
1949optPresenceConstraint:
1950 { $$ = ACPRES_DEFAULT; }
1951 | PresenceConstraint { $$ = $1; }
1952 ;
1953
1954PresenceConstraint:
1955 TOK_PRESENT {
1956 $$ = ACPRES_PRESENT;
1957 }
1958 | TOK_ABSENT {
1959 $$ = ACPRES_ABSENT;
1960 }
1961 | TOK_OPTIONAL {
1962 $$ = ACPRES_OPTIONAL;
1963 }
1964 ;
1965
vlm43c8ac52006-09-17 04:52:50 +00001966
1967/* X.682 */
1968GeneralConstraint:
1969 UserDefinedConstraint
1970 | TableConstraint
1971 | ContentsConstraint
1972 ;
1973
1974UserDefinedConstraint:
1975 TOK_CONSTRAINED TOK_BY '{'
1976 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1977 $$ = asn1p_constraint_new(yylineno);
1978 checkmem($$);
1979 $$->type = ACT_CT_CTDBY;
1980 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
1981 checkmem($$->value);
1982 $$->value->type = ATV_UNPARSED;
1983 }
1984 ;
1985
1986ContentsConstraint:
1987 TOK_CONTAINING Type {
1988 $$ = asn1p_constraint_new(yylineno);
1989 $$->type = ACT_CT_CTNG;
1990 $$->value = asn1p_value_fromtype($2);
1991 }
1992 ;
1993
1994ConstraintRangeSpec:
1995 TOK_TwoDots { $$ = ACT_EL_RANGE; }
1996 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
1997 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
1998 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
1999 ;
vlmfa67ddc2004-06-03 03:38:44 +00002000TableConstraint:
2001 SimpleTableConstraint {
2002 $$ = $1;
2003 }
2004 | ComponentRelationConstraint {
2005 $$ = $1;
2006 }
2007 ;
2008
2009/*
2010 * "{ExtensionSet}"
2011 */
2012SimpleTableConstraint:
2013 '{' TypeRefName '}' {
2014 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
2015 asn1p_constraint_t *ct;
2016 int ret;
2017 ret = asn1p_ref_add_component(ref, $2, 0);
2018 checkmem(ret == 0);
2019 ct = asn1p_constraint_new(yylineno);
2020 checkmem($$);
2021 ct->type = ACT_EL_VALUE;
2022 ct->value = asn1p_value_fromref(ref, 0);
vlm9fe7c922005-08-12 10:08:45 +00002023 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
vlmfa67ddc2004-06-03 03:38:44 +00002024 }
2025 ;
2026
2027ComponentRelationConstraint:
2028 SimpleTableConstraint '{' AtNotationList '}' {
vlm9fe7c922005-08-12 10:08:45 +00002029 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00002030 }
2031 ;
2032
2033AtNotationList:
2034 AtNotationElement {
2035 $$ = asn1p_constraint_new(yylineno);
2036 checkmem($$);
2037 $$->type = ACT_EL_VALUE;
2038 $$->value = asn1p_value_fromref($1, 0);
2039 }
2040 | AtNotationList ',' AtNotationElement {
2041 asn1p_constraint_t *ct;
2042 ct = asn1p_constraint_new(yylineno);
2043 checkmem(ct);
2044 ct->type = ACT_EL_VALUE;
2045 ct->value = asn1p_value_fromref($3, 0);
vlm9fe7c922005-08-12 10:08:45 +00002046 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlmfa67ddc2004-06-03 03:38:44 +00002047 }
2048 ;
2049
2050/*
2051 * @blah
2052 */
2053AtNotationElement:
2054 '@' ComponentIdList {
2055 char *p = malloc(strlen($2) + 2);
2056 int ret;
2057 *p = '@';
2058 strcpy(p + 1, $2);
2059 $$ = asn1p_ref_new(yylineno);
2060 ret = asn1p_ref_add_component($$, p, 0);
2061 checkmem(ret == 0);
2062 free(p);
2063 free($2);
2064 }
2065 | '@' '.' ComponentIdList {
2066 char *p = malloc(strlen($3) + 3);
2067 int ret;
2068 p[0] = '@';
2069 p[1] = '.';
2070 strcpy(p + 2, $3);
2071 $$ = asn1p_ref_new(yylineno);
2072 ret = asn1p_ref_add_component($$, p, 0);
2073 checkmem(ret == 0);
2074 free(p);
2075 free($3);
2076 }
2077 ;
2078
2079/* identifier "." ... */
2080ComponentIdList:
2081 Identifier {
2082 $$ = $1;
2083 }
2084 | ComponentIdList '.' Identifier {
2085 int l1 = strlen($1);
2086 int l3 = strlen($3);
2087 $$ = malloc(l1 + 1 + l3 + 1);
2088 memcpy($$, $1, l1);
2089 $$[l1] = '.';
2090 memcpy($$ + l1 + 1, $3, l3);
2091 $$[l1 + 1 + l3] = '\0';
2092 }
2093 ;
2094
2095
2096
2097/*
2098 * MARKERS
2099 */
2100
2101optMarker:
vlmc94e28f2004-09-15 11:59:51 +00002102 {
2103 $$.flags = EM_NOMARK;
2104 $$.default_value = 0;
2105 }
vlmfa67ddc2004-06-03 03:38:44 +00002106 | Marker { $$ = $1; }
2107 ;
2108
2109Marker:
2110 TOK_OPTIONAL {
vlm1ac75e72005-11-26 11:21:55 +00002111 $$.flags = EM_OPTIONAL | EM_INDIRECT;
vlmc94e28f2004-09-15 11:59:51 +00002112 $$.default_value = 0;
vlmfa67ddc2004-06-03 03:38:44 +00002113 }
vlmc94e28f2004-09-15 11:59:51 +00002114 | TOK_DEFAULT Value {
2115 $$.flags = EM_DEFAULT;
2116 $$.default_value = $2;
vlmfa67ddc2004-06-03 03:38:44 +00002117 }
2118 ;
2119
2120/*
2121 * Universal enumeration definition to use in INTEGER and ENUMERATED.
2122 * === EXAMPLE ===
2123 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
2124 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
2125 * === EOF ===
2126 */
2127/*
2128optUniverationDefinition:
2129 { $$ = 0; }
2130 | UniverationDefinition {
2131 $$ = $1;
2132 }
2133 ;
2134*/
2135
2136UniverationDefinition:
2137 '{' '}' {
vlm43c8ac52006-09-17 04:52:50 +00002138 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002139 checkmem($$);
2140 }
2141 | '{' UniverationList '}' {
2142 $$ = $2;
2143 }
2144 ;
2145
2146UniverationList:
2147 UniverationElement {
vlm43c8ac52006-09-17 04:52:50 +00002148 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002149 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +00002150 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +00002151 }
2152 | UniverationList ',' UniverationElement {
2153 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +00002154 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +00002155 }
2156 ;
2157
2158UniverationElement:
2159 Identifier {
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 }
2166 | Identifier '(' SignedNumber ')' {
vlm43c8ac52006-09-17 04:52:50 +00002167 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002168 checkmem($$);
2169 $$->expr_type = A1TC_UNIVERVAL;
2170 $$->meta_type = AMT_VALUE;
2171 $$->Identifier = $1;
2172 $$->value = $3;
2173 }
2174 | Identifier '(' DefinedValue ')' {
vlm43c8ac52006-09-17 04:52:50 +00002175 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002176 checkmem($$);
2177 $$->expr_type = A1TC_UNIVERVAL;
2178 $$->meta_type = AMT_VALUE;
2179 $$->Identifier = $1;
2180 $$->value = $3;
2181 }
2182 | SignedNumber {
vlm43c8ac52006-09-17 04:52:50 +00002183 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002184 checkmem($$);
2185 $$->expr_type = A1TC_UNIVERVAL;
2186 $$->meta_type = AMT_VALUE;
2187 $$->value = $1;
2188 }
2189 | TOK_ThreeDots {
vlm43c8ac52006-09-17 04:52:50 +00002190 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002191 checkmem($$);
2192 $$->Identifier = strdup("...");
2193 checkmem($$->Identifier);
2194 $$->expr_type = A1TC_EXTENSIBLE;
2195 $$->meta_type = AMT_VALUE;
2196 }
2197 ;
2198
2199SignedNumber:
2200 TOK_number {
2201 $$ = asn1p_value_fromint($1);
2202 checkmem($$);
2203 }
2204 | TOK_number_negative {
2205 $$ = asn1p_value_fromint($1);
2206 checkmem($$);
2207 }
2208 ;
2209
vlme745fcd2006-09-05 16:18:34 +00002210RealValue:
2211 SignedNumber
2212 | TOK_realnumber {
2213 $$ = asn1p_value_fromdouble($1);
2214 checkmem($$);
2215 }
2216 ;
2217
vlmfa67ddc2004-06-03 03:38:44 +00002218/*
2219 * SEQUENCE definition.
2220 * === EXAMPLE ===
2221 * Struct1 ::= SEQUENCE {
2222 * memb1 Struct2,
2223 * memb2 SEQUENCE OF {
2224 * memb2-1 Struct 3
2225 * }
2226 * }
2227 * === EOF ===
2228 */
2229
2230
2231
2232/*
2233 * SET definition.
2234 * === EXAMPLE ===
2235 * Person ::= SET {
2236 * name [0] PrintableString (SIZE(1..20)),
2237 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2238 * }
2239 * === EOF ===
2240 */
2241
2242optTag:
2243 { memset(&$$, 0, sizeof($$)); }
2244 | Tag { $$ = $1; }
2245 ;
2246
2247Tag:
vlm2728a8d2005-01-23 09:51:44 +00002248 TagTypeValue TagPlicit {
vlmfa67ddc2004-06-03 03:38:44 +00002249 $$ = $1;
vlm2728a8d2005-01-23 09:51:44 +00002250 $$.tag_mode = $2.tag_mode;
vlmfa67ddc2004-06-03 03:38:44 +00002251 }
vlm2728a8d2005-01-23 09:51:44 +00002252 ;
2253
2254TagTypeValue:
2255 '[' TagClass TOK_number ']' {
2256 $$ = $2;
2257 $$.tag_value = $3;
2258 };
2259
2260TagClass:
2261 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2262 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2263 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2264 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2265 ;
2266
2267TagPlicit:
2268 { $$.tag_mode = TM_DEFAULT; }
2269 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2270 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
vlmfa67ddc2004-06-03 03:38:44 +00002271 ;
2272
2273TypeRefName:
2274 TOK_typereference {
2275 checkmem($1);
2276 $$ = $1;
2277 }
vlm9283dbe2004-08-18 04:59:12 +00002278 | TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00002279 checkmem($1);
2280 $$ = $1;
2281 }
2282 ;
2283
vlm9283dbe2004-08-18 04:59:12 +00002284
vlmfa67ddc2004-06-03 03:38:44 +00002285ObjectClassReference:
vlm9283dbe2004-08-18 04:59:12 +00002286 TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00002287 checkmem($1);
2288 $$ = $1;
2289 }
2290 ;
2291
vlm151c0b22004-09-22 16:03:36 +00002292optIdentifier:
2293 { $$ = 0; }
2294 | Identifier {
2295 $$ = $1;
2296 }
vlma5b977d2005-06-06 08:28:58 +00002297 ;
vlm151c0b22004-09-22 16:03:36 +00002298
vlmfa67ddc2004-06-03 03:38:44 +00002299Identifier:
2300 TOK_identifier {
2301 checkmem($1);
2302 $$ = $1;
2303 }
2304 ;
2305
vlmfa67ddc2004-06-03 03:38:44 +00002306%%
2307
2308
2309/*
2310 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2311 */
2312static asn1p_value_t *
2313_convert_bitstring2binary(char *str, int base) {
2314 asn1p_value_t *val;
2315 int slen;
2316 int memlen;
2317 int baselen;
2318 int bits;
2319 uint8_t *binary_vector;
2320 uint8_t *bv_ptr;
2321 uint8_t cur_val;
2322
2323 assert(str);
2324 assert(str[0] == '\'');
2325
2326 switch(base) {
2327 case 'B':
2328 baselen = 1;
2329 break;
2330 case 'H':
2331 baselen = 4;
2332 break;
2333 default:
2334 assert(base == 'B' || base == 'H');
2335 errno = EINVAL;
2336 return NULL;
2337 }
2338
2339 slen = strlen(str);
2340 assert(str[slen - 1] == base);
2341 assert(str[slen - 2] == '\'');
2342
2343 memlen = slen / (8 / baselen); /* Conservative estimate */
2344
2345 bv_ptr = binary_vector = malloc(memlen + 1);
2346 if(bv_ptr == NULL)
2347 /* ENOMEM */
2348 return NULL;
2349
2350 cur_val = 0;
2351 bits = 0;
2352 while(*(++str) != '\'') {
2353 switch(baselen) {
2354 case 1:
2355 switch(*str) {
2356 case '1':
2357 cur_val |= 1 << (7 - (bits % 8));
2358 case '0':
2359 break;
2360 default:
2361 assert(!"_y UNREACH1");
2362 case ' ': case '\r': case '\n':
2363 continue;
2364 }
2365 break;
2366 case 4:
2367 switch(*str) {
2368 case '0': case '1': case '2': case '3': case '4':
2369 case '5': case '6': case '7': case '8': case '9':
2370 cur_val |= (*str - '0') << (4 - (bits % 8));
2371 break;
2372 case 'A': case 'B': case 'C':
2373 case 'D': case 'E': case 'F':
2374 cur_val |= ((*str - 'A') + 10)
2375 << (4 - (bits % 8));
2376 break;
2377 default:
2378 assert(!"_y UNREACH2");
2379 case ' ': case '\r': case '\n':
2380 continue;
2381 }
2382 break;
2383 }
2384
2385 bits += baselen;
2386 if((bits % 8) == 0) {
2387 *bv_ptr++ = cur_val;
2388 cur_val = 0;
2389 }
2390 }
2391
2392 *bv_ptr = cur_val;
2393 assert((bv_ptr - binary_vector) <= memlen);
2394
2395 val = asn1p_value_frombits(binary_vector, bits, 0);
2396 if(val == NULL) {
2397 free(binary_vector);
2398 }
2399
2400 return val;
2401}
2402
vlm5d89c3d2005-08-13 09:07:11 +00002403/*
2404 * For unnamed types (used in old X.208 compliant modules)
2405 * generate some sort of interim names, to not to force human being to fix
2406 * the specification's compliance to modern ASN.1 standards.
2407 */
2408static void
2409_fixup_anonymous_identifier(asn1p_expr_t *expr) {
2410 char *p;
2411 assert(expr->Identifier == 0);
2412
2413 /*
2414 * Try to figure out the type name
2415 * without going too much into details
2416 */
2417 expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type);
2418 if(expr->reference && expr->reference->comp_count > 0)
2419 expr->Identifier = expr->reference->components[0].name;
2420
2421 fprintf(stderr,
2422 "WARNING: Line %d: expected lower-case member identifier, "
2423 "found an unnamed %s.\n"
2424 "WARNING: Obsolete X.208 syntax detected, "
2425 "please give the member a name.\n",
2426 yylineno, expr->Identifier ? expr->Identifier : "type");
2427
2428 if(!expr->Identifier)
2429 expr->Identifier = "unnamed";
2430 expr->Identifier = strdup(expr->Identifier);
2431 assert(expr->Identifier);
2432 /* Make a lowercase identifier from the type name */
2433 for(p = expr->Identifier; *p; p++) {
2434 switch(*p) {
2435 case 'A' ... 'Z': *p += 32; break;
2436 case ' ': *p = '_'; break;
2437 case '-': *p = '_'; break;
2438 }
2439 }
2440 fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". "
2441 "Name clash may occur later.\n",
2442 expr->Identifier);
2443}
2444
vlmfa67ddc2004-06-03 03:38:44 +00002445int
2446yyerror(const char *msg) {
vlm808411d2006-03-14 16:31:37 +00002447 extern char *asn1p_text;
vlmfa67ddc2004-06-03 03:38:44 +00002448 fprintf(stderr,
2449 "ASN.1 grammar parse error "
2450 "near line %d (token \"%s\"): %s\n",
vlm39e5ed72004-09-05 10:40:41 +00002451 yylineno, asn1p_text, msg);
vlmfa67ddc2004-06-03 03:38:44 +00002452 return -1;
2453}
2454