blob: 9baa9ce686bb20165630f3638242e9b86e5a400d [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
vlmfa67ddc2004-06-03 03:38:44 +0000229%left TOK_EXCEPT
vlm9283dbe2004-08-18 04:59:12 +0000230%left '^' TOK_INTERSECTION
231%left '|' TOK_UNION
vlmfa67ddc2004-06-03 03:38:44 +0000232
233/* Misc tags */
234%token TOK_TwoDots /* .. */
235%token TOK_ThreeDots /* ... */
vlmfa67ddc2004-06-03 03:38:44 +0000236
237
238/*
239 * Types defined herein.
240 */
241%type <a_grammar> ModuleList
vlmd3420d32006-09-14 10:35:20 +0000242%type <a_module> ModuleDefinition
243%type <a_module> ModuleBody
244%type <a_module> AssignmentList
245%type <a_module> Assignment
246%type <a_module> optModuleBody /* Optional */
247%type <a_module_flags> optModuleDefinitionFlags
248%type <a_module_flags> ModuleDefinitionFlags /* Set of FL */
249%type <a_module_flags> ModuleDefinitionFlag /* Single FL */
250%type <a_module> optImports
251%type <a_module> optExports
vlmfa67ddc2004-06-03 03:38:44 +0000252%type <a_module> ImportsDefinition
253%type <a_module> ImportsBundleSet
254%type <a_xports> ImportsBundle
255%type <a_xports> ImportsList
256%type <a_xports> ExportsDefinition
257%type <a_xports> ExportsBody
258%type <a_expr> ImportsElement
259%type <a_expr> ExportsElement
vlmfa67ddc2004-06-03 03:38:44 +0000260%type <a_expr> ExtensionAndException
vlm43c8ac52006-09-17 04:52:50 +0000261%type <a_expr> Type
vlmec8f6812004-08-22 03:19:54 +0000262%type <a_expr> TypeDeclaration
vlm066dc102005-08-22 12:23:54 +0000263%type <a_expr> TypeDeclarationSet
vlmfa67ddc2004-06-03 03:38:44 +0000264%type <a_ref> ComplexTypeReference
265%type <a_ref> ComplexTypeReferenceAmpList
266%type <a_refcomp> ComplexTypeReferenceElement
vlma6a84d72006-03-16 10:03:35 +0000267%type <a_refcomp> PrimitiveFieldReference
vlmdc7cf042006-03-09 08:49:26 +0000268%type <a_expr> FieldSpec
269%type <a_ref> FieldName
270%type <a_ref> DefinedObjectClass
vlmfa67ddc2004-06-03 03:38:44 +0000271%type <a_expr> ClassField
vlmdc7cf042006-03-09 08:49:26 +0000272%type <a_expr> ObjectClass
vlmfa67ddc2004-06-03 03:38:44 +0000273%type <a_expr> DataTypeReference /* Type1 ::= Type2 */
vlm17e65d02006-03-21 04:48:15 +0000274%type <a_expr> DefinedType
vlm59b620a2006-03-21 07:46:48 +0000275%type <a_constr> ValueSet /* {a|b|c}*/
276%type <a_expr> ValueSetTypeAssignment /* Val INTEGER ::= {1|2} */
vlmfa67ddc2004-06-03 03:38:44 +0000277%type <a_expr> ValueDefinition /* val INTEGER ::= 1*/
vlmc94e28f2004-09-15 11:59:51 +0000278%type <a_value> Value
vlm17e65d02006-03-21 04:48:15 +0000279%type <a_value> SimpleValue
vlmfa67ddc2004-06-03 03:38:44 +0000280%type <a_value> DefinedValue
281%type <a_value> SignedNumber
vlme745fcd2006-09-05 16:18:34 +0000282%type <a_value> RealValue
vlm0aa86902004-10-12 23:26:53 +0000283%type <a_expr> optComponentTypeLists
vlmec8f6812004-08-22 03:19:54 +0000284%type <a_expr> ComponentTypeLists
285%type <a_expr> ComponentType
286%type <a_expr> AlternativeTypeLists
287%type <a_expr> AlternativeType
vlmfa67ddc2004-06-03 03:38:44 +0000288%type <a_expr> UniverationDefinition
289%type <a_expr> UniverationList
290%type <a_expr> UniverationElement
291%type <tv_str> TypeRefName
292%type <tv_str> ObjectClassReference
vlmfa67ddc2004-06-03 03:38:44 +0000293%type <tv_str> Identifier
vlm151c0b22004-09-22 16:03:36 +0000294%type <tv_str> optIdentifier
vlmfa67ddc2004-06-03 03:38:44 +0000295%type <a_parg> ParameterArgumentName
296%type <a_plist> ParameterArgumentList
vlmdfbff8c2006-03-21 09:41:28 +0000297%type <a_expr> ActualParameter
298%type <a_expr> ActualParameterList
vlm04a08da2005-08-12 10:06:17 +0000299%type <a_aid> AssignedIdentifier /* OID/DefinedValue */
vlmfa67ddc2004-06-03 03:38:44 +0000300%type <a_oid> ObjectIdentifier /* OID */
301%type <a_oid> optObjectIdentifier /* Optional OID */
302%type <a_oid> ObjectIdentifierBody
303%type <a_oid_arc> ObjectIdentifierElement
304%type <a_expr> BasicType
305%type <a_type> BasicTypeId
306%type <a_type> BasicTypeId_UniverationCompatible
307%type <a_type> BasicString
308%type <tv_opaque> Opaque
vlm2728a8d2005-01-23 09:51:44 +0000309%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
310%type <a_tag> TagClass TagTypeValue TagPlicit
vlmfa67ddc2004-06-03 03:38:44 +0000311%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
312%type <a_constr> optConstraints
vlm43c8ac52006-09-17 04:52:50 +0000313%type <a_constr> Constraint
314%type <a_constr> SubtypeConstraint
315%type <a_constr> GeneralConstraint
vlm9283dbe2004-08-18 04:59:12 +0000316%type <a_constr> SetOfConstraints
317%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
318%type <a_constr> ElementSetSpec /* 1..2,...,3 */
vlmfa67ddc2004-06-03 03:38:44 +0000319%type <a_constr> ConstraintSubtypeElement /* 1..2 */
vlmfa67ddc2004-06-03 03:38:44 +0000320%type <a_constr> SimpleTableConstraint
vlm43c8ac52006-09-17 04:52:50 +0000321%type <a_constr> UserDefinedConstraint
vlmfa67ddc2004-06-03 03:38:44 +0000322%type <a_constr> TableConstraint
vlm43c8ac52006-09-17 04:52:50 +0000323%type <a_constr> ContentsConstraint
vlm7bbdc9f2005-03-28 15:01:27 +0000324%type <a_constr> InnerTypeConstraint
vlmfa67ddc2004-06-03 03:38:44 +0000325%type <a_constr> WithComponentsList
326%type <a_constr> WithComponentsElement
327%type <a_constr> ComponentRelationConstraint
328%type <a_constr> AtNotationList
329%type <a_ref> AtNotationElement
vlma6a12e32005-03-20 12:58:00 +0000330%type <a_value> SingleValue
331%type <a_value> ContainedSubtype
vlmfa67ddc2004-06-03 03:38:44 +0000332%type <a_ctype> ConstraintSpec
333%type <a_ctype> ConstraintRangeSpec
vlme1e6ed82005-03-24 14:26:38 +0000334%type <a_value> RestrictedCharacterStringValue
vlmfa67ddc2004-06-03 03:38:44 +0000335%type <a_wsynt> optWithSyntax
336%type <a_wsynt> WithSyntax
vlm808411d2006-03-14 16:31:37 +0000337%type <a_wsynt> WithSyntaxList
338%type <a_wchunk> WithSyntaxToken
vlmfa67ddc2004-06-03 03:38:44 +0000339%type <a_marker> optMarker Marker
340%type <a_int> optUnique
341%type <a_pres> optPresenceConstraint PresenceConstraint
342%type <tv_str> ComponentIdList
vlm177a5b62005-09-05 05:17:57 +0000343%type <a_int> NSTD_IndirectMarker
vlmfa67ddc2004-06-03 03:38:44 +0000344
345
346%%
347
348
349ParsedGrammar:
350 ModuleList {
351 *(void **)param = $1;
352 }
353 ;
354
355ModuleList:
vlmd3420d32006-09-14 10:35:20 +0000356 ModuleDefinition {
vlmfa67ddc2004-06-03 03:38:44 +0000357 $$ = asn1p_new();
358 checkmem($$);
359 TQ_ADD(&($$->modules), $1, mod_next);
360 }
vlmd3420d32006-09-14 10:35:20 +0000361 | ModuleList ModuleDefinition {
vlmfa67ddc2004-06-03 03:38:44 +0000362 $$ = $1;
363 TQ_ADD(&($$->modules), $2, mod_next);
364 }
365 ;
366
367/*
368 * ASN module definition.
369 * === EXAMPLE ===
370 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
371 * BEGIN
372 * ...
373 * END
374 * === EOF ===
375 */
376
vlmd3420d32006-09-14 10:35:20 +0000377ModuleDefinition:
vlm43c8ac52006-09-17 04:52:50 +0000378 TypeRefName { currentModule = asn1p_module_new(); }
379 optObjectIdentifier TOK_DEFINITIONS
vlmd3420d32006-09-14 10:35:20 +0000380 optModuleDefinitionFlags
vlmfa67ddc2004-06-03 03:38:44 +0000381 TOK_PPEQ TOK_BEGIN
vlmd3420d32006-09-14 10:35:20 +0000382 optModuleBody
vlmfa67ddc2004-06-03 03:38:44 +0000383 TOK_END {
384
vlm43c8ac52006-09-17 04:52:50 +0000385 $$ = currentModule;
386
387 if($8) {
388 asn1p_module_t tmp = *($$);
389 *($$) = *($8);
390 *($8) = tmp;
391 asn1p_module_free($8);
vlmfa67ddc2004-06-03 03:38:44 +0000392 } else {
393 /* There's a chance that a module is just plain empty */
vlmfa67ddc2004-06-03 03:38:44 +0000394 }
vlmfa67ddc2004-06-03 03:38:44 +0000395
vlm04a08da2005-08-12 10:06:17 +0000396 $$->ModuleName = $1;
vlm43c8ac52006-09-17 04:52:50 +0000397 $$->module_oid = $3;
398 $$->module_flags = $5;
vlmfa67ddc2004-06-03 03:38:44 +0000399 }
400 ;
401
402/*
403 * Object Identifier Definition
404 * { iso member-body(2) 3 }
405 */
406optObjectIdentifier:
407 { $$ = 0; }
408 | ObjectIdentifier { $$ = $1; }
409 ;
410
411ObjectIdentifier:
412 '{' ObjectIdentifierBody '}' {
413 $$ = $2;
414 }
415 | '{' '}' {
416 $$ = 0;
417 }
418 ;
419
420ObjectIdentifierBody:
421 ObjectIdentifierElement {
422 $$ = asn1p_oid_new();
423 asn1p_oid_add_arc($$, &$1);
424 if($1.name)
425 free($1.name);
426 }
427 | ObjectIdentifierBody ObjectIdentifierElement {
428 $$ = $1;
429 asn1p_oid_add_arc($$, &$2);
430 if($2.name)
431 free($2.name);
432 }
433 ;
434
435ObjectIdentifierElement:
436 Identifier { /* iso */
437 $$.name = $1;
438 $$.number = -1;
439 }
440 | Identifier '(' TOK_number ')' { /* iso(1) */
441 $$.name = $1;
442 $$.number = $3;
443 }
444 | TOK_number { /* 1 */
445 $$.name = 0;
446 $$.number = $1;
447 }
448 ;
449
450/*
451 * Optional module flags.
452 */
vlmd3420d32006-09-14 10:35:20 +0000453optModuleDefinitionFlags:
vlmfa67ddc2004-06-03 03:38:44 +0000454 { $$ = MSF_NOFLAGS; }
vlmd3420d32006-09-14 10:35:20 +0000455 | ModuleDefinitionFlags {
vlmfa67ddc2004-06-03 03:38:44 +0000456 $$ = $1;
457 }
458 ;
459
460/*
461 * Module flags.
462 */
vlmd3420d32006-09-14 10:35:20 +0000463ModuleDefinitionFlags:
464 ModuleDefinitionFlag {
vlmfa67ddc2004-06-03 03:38:44 +0000465 $$ = $1;
466 }
vlmd3420d32006-09-14 10:35:20 +0000467 | ModuleDefinitionFlags ModuleDefinitionFlag {
vlmfa67ddc2004-06-03 03:38:44 +0000468 $$ = $1 | $2;
469 }
470 ;
471
472/*
473 * Single module flag.
474 */
vlmd3420d32006-09-14 10:35:20 +0000475ModuleDefinitionFlag:
vlmfa67ddc2004-06-03 03:38:44 +0000476 TOK_EXPLICIT TOK_TAGS {
477 $$ = MSF_EXPLICIT_TAGS;
478 }
479 | TOK_IMPLICIT TOK_TAGS {
480 $$ = MSF_IMPLICIT_TAGS;
481 }
482 | TOK_AUTOMATIC TOK_TAGS {
483 $$ = MSF_AUTOMATIC_TAGS;
484 }
485 | TOK_EXTENSIBILITY TOK_IMPLIED {
486 $$ = MSF_EXTENSIBILITY_IMPLIED;
487 }
vlm9283dbe2004-08-18 04:59:12 +0000488 /* EncodingReferenceDefault */
489 | TOK_capitalreference TOK_INSTRUCTIONS {
490 /* X.680Amd1 specifies TAG and XER */
491 if(strcmp($1, "TAG") == 0) {
492 $$ = MSF_TAG_INSTRUCTIONS;
493 } else if(strcmp($1, "XER") == 0) {
494 $$ = MSF_XER_INSTRUCTIONS;
495 } else {
496 fprintf(stderr,
497 "WARNING: %s INSTRUCTIONS at line %d: "
498 "Unrecognized encoding reference\n",
499 $1, yylineno);
500 $$ = MSF_unk_INSTRUCTIONS;
501 }
502 free($1);
503 }
vlmfa67ddc2004-06-03 03:38:44 +0000504 ;
505
506/*
507 * Optional module body.
508 */
vlmd3420d32006-09-14 10:35:20 +0000509optModuleBody:
vlmfa67ddc2004-06-03 03:38:44 +0000510 { $$ = 0; }
vlmd3420d32006-09-14 10:35:20 +0000511 | ModuleBody {
vlmfa67ddc2004-06-03 03:38:44 +0000512 $$ = $1;
513 }
514 ;
515
516/*
517 * ASN.1 Module body.
518 */
vlmd3420d32006-09-14 10:35:20 +0000519ModuleBody:
520 optExports optImports AssignmentList {
521 $$ = asn1p_module_new();
522 AL_IMPORT($$, exports, $1, xp_next);
523 AL_IMPORT($$, imports, $2, xp_next);
524 AL_IMPORT($$, members, $3, next);
vlmfa67ddc2004-06-03 03:38:44 +0000525 }
526 ;
527
vlmd3420d32006-09-14 10:35:20 +0000528AssignmentList:
529 Assignment {
530 $$ = $1;
531 }
532 | AssignmentList Assignment {
533 if($1) {
534 $$ = $1;
535 } else {
536 $$ = $2;
537 break;
538 }
539 AL_IMPORT($$, members, $2, next);
540 }
541 ;
542
543
vlmfa67ddc2004-06-03 03:38:44 +0000544/*
545 * One of the elements of ASN.1 module specification.
546 */
vlmd3420d32006-09-14 10:35:20 +0000547Assignment:
548 DataTypeReference {
vlmfa67ddc2004-06-03 03:38:44 +0000549 $$ = asn1p_module_new();
550 checkmem($$);
551 assert($1->expr_type != A1TC_INVALID);
552 assert($1->meta_type != AMT_INVALID);
553 TQ_ADD(&($$->members), $1, next);
554 }
555 | ValueDefinition {
556 $$ = asn1p_module_new();
557 checkmem($$);
558 assert($1->expr_type != A1TC_INVALID);
559 assert($1->meta_type != AMT_INVALID);
560 TQ_ADD(&($$->members), $1, next);
561 }
562 /*
563 * Value set definition
564 * === EXAMPLE ===
565 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
566 * === EOF ===
567 */
vlm59b620a2006-03-21 07:46:48 +0000568 | ValueSetTypeAssignment {
vlmfa67ddc2004-06-03 03:38:44 +0000569 $$ = asn1p_module_new();
570 checkmem($$);
571 assert($1->expr_type != A1TC_INVALID);
572 assert($1->meta_type != AMT_INVALID);
573 TQ_ADD(&($$->members), $1, next);
574 }
vlm9283dbe2004-08-18 04:59:12 +0000575 | TOK_ENCODING_CONTROL TOK_capitalreference
576 { asn1p_lexer_hack_push_encoding_control(); }
577 {
578 fprintf(stderr,
579 "WARNING: ENCODING-CONTROL %s "
580 "specification at line %d ignored\n",
581 $2, yylineno);
582 free($2);
583 $$ = 0;
584 }
vlmfa67ddc2004-06-03 03:38:44 +0000585
586 /*
587 * Erroneous attemps
588 */
589 | BasicString {
590 return yyerror(
vlm1ac75e72005-11-26 11:21:55 +0000591 "Attempt to redefine a standard basic string type, "
592 "please comment out or remove this type redefinition.");
vlmfa67ddc2004-06-03 03:38:44 +0000593 }
594 ;
595
596/*
597 * === EXAMPLE ===
598 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
599 * === EOF ===
600 */
vlmd3420d32006-09-14 10:35:20 +0000601optImports:
602 { $$ = 0; }
603 | ImportsDefinition;
604
vlmfa67ddc2004-06-03 03:38:44 +0000605ImportsDefinition:
606 TOK_IMPORTS ImportsBundleSet ';' {
vlm04a08da2005-08-12 10:06:17 +0000607 if(!saved_aid && 0)
608 return yyerror("Unterminated IMPORTS FROM, "
609 "expected semicolon ';'");
610 saved_aid = 0;
vlmfa67ddc2004-06-03 03:38:44 +0000611 $$ = $2;
612 }
613 /*
614 * Some error cases.
615 */
616 | TOK_IMPORTS TOK_FROM /* ... */ {
617 return yyerror("Empty IMPORTS list");
618 }
619 ;
620
621ImportsBundleSet:
622 ImportsBundle {
623 $$ = asn1p_module_new();
624 checkmem($$);
625 TQ_ADD(&($$->imports), $1, xp_next);
626 }
627 | ImportsBundleSet ImportsBundle {
628 $$ = $1;
629 TQ_ADD(&($$->imports), $2, xp_next);
630 }
631 ;
632
vlm04a08da2005-08-12 10:06:17 +0000633AssignedIdentifier:
634 { memset(&$$, 0, sizeof($$)); }
635 | ObjectIdentifier { $$.oid = $1; };
636 /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
637
vlmfa67ddc2004-06-03 03:38:44 +0000638ImportsBundle:
vlm04a08da2005-08-12 10:06:17 +0000639 ImportsList TOK_FROM TypeRefName AssignedIdentifier {
vlmfa67ddc2004-06-03 03:38:44 +0000640 $$ = $1;
vlm04a08da2005-08-12 10:06:17 +0000641 $$->fromModuleName = $3;
642 $$->identifier = $4;
643 /* This stupid thing is used for look-back hack. */
644 saved_aid = $$->identifier.oid ? 0 : &($$->identifier);
vlmfa67ddc2004-06-03 03:38:44 +0000645 checkmem($$);
646 }
647 ;
648
649ImportsList:
650 ImportsElement {
651 $$ = asn1p_xports_new();
652 checkmem($$);
653 TQ_ADD(&($$->members), $1, next);
654 }
655 | ImportsList ',' ImportsElement {
656 $$ = $1;
657 TQ_ADD(&($$->members), $3, next);
658 }
659 ;
660
661ImportsElement:
662 TypeRefName {
vlm43c8ac52006-09-17 04:52:50 +0000663 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000664 checkmem($$);
665 $$->Identifier = $1;
666 $$->expr_type = A1TC_REFERENCE;
667 }
vlm0aa86902004-10-12 23:26:53 +0000668 | TypeRefName '{' '}' { /* Completely equivalent to above */
vlm43c8ac52006-09-17 04:52:50 +0000669 $$ = NEW_EXPR();
vlm0aa86902004-10-12 23:26:53 +0000670 checkmem($$);
671 $$->Identifier = $1;
672 $$->expr_type = A1TC_REFERENCE;
673 }
vlmfa67ddc2004-06-03 03:38:44 +0000674 | Identifier {
vlm43c8ac52006-09-17 04:52:50 +0000675 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000676 checkmem($$);
677 $$->Identifier = $1;
678 $$->expr_type = A1TC_REFERENCE;
679 }
680 ;
681
vlmd3420d32006-09-14 10:35:20 +0000682
683optExports:
684 { $$ = 0; }
685 | ExportsDefinition {
686 $$ = asn1p_module_new();
687 checkmem($$);
688 if($1) {
689 TQ_ADD(&($$->exports), $1, xp_next);
690 } else {
691 /* "EXPORTS ALL;" */
692 }
693 }
694 ;
695
vlmfa67ddc2004-06-03 03:38:44 +0000696ExportsDefinition:
697 TOK_EXPORTS ExportsBody ';' {
698 $$ = $2;
699 }
700 | TOK_EXPORTS TOK_ALL ';' {
701 $$ = 0;
702 }
703 | TOK_EXPORTS ';' {
704 /* Empty EXPORTS clause effectively prohibits export. */
705 $$ = asn1p_xports_new();
706 checkmem($$);
707 }
708 ;
709
710ExportsBody:
711 ExportsElement {
712 $$ = asn1p_xports_new();
713 assert($$);
714 TQ_ADD(&($$->members), $1, next);
715 }
716 | ExportsBody ',' ExportsElement {
717 $$ = $1;
718 TQ_ADD(&($$->members), $3, next);
719 }
720 ;
721
722ExportsElement:
723 TypeRefName {
vlm43c8ac52006-09-17 04:52:50 +0000724 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000725 checkmem($$);
726 $$->Identifier = $1;
727 $$->expr_type = A1TC_EXPORTVAR;
728 }
vlm0aa86902004-10-12 23:26:53 +0000729 | TypeRefName '{' '}' {
vlm43c8ac52006-09-17 04:52:50 +0000730 $$ = NEW_EXPR();
vlm0aa86902004-10-12 23:26:53 +0000731 checkmem($$);
732 $$->Identifier = $1;
733 $$->expr_type = A1TC_EXPORTVAR;
734 }
vlmfa67ddc2004-06-03 03:38:44 +0000735 | Identifier {
vlm43c8ac52006-09-17 04:52:50 +0000736 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000737 checkmem($$);
738 $$->Identifier = $1;
739 $$->expr_type = A1TC_EXPORTVAR;
740 }
741 ;
742
743
vlm1aeaddd2006-07-13 08:24:20 +0000744ValueSet: '{' ElementSetSpecs '}' { $$ = $2; };
vlm59b620a2006-03-21 07:46:48 +0000745
746ValueSetTypeAssignment:
747 TypeRefName DefinedType TOK_PPEQ ValueSet {
vlmfa67ddc2004-06-03 03:38:44 +0000748 $$ = $2;
749 assert($$->Identifier == 0);
750 $$->Identifier = $1;
751 $$->meta_type = AMT_VALUESET;
vlm59b620a2006-03-21 07:46:48 +0000752 $$->constraints = $4;
vlmfa67ddc2004-06-03 03:38:44 +0000753 }
754 ;
755
vlm17e65d02006-03-21 04:48:15 +0000756DefinedType:
757 BasicType {
758 $$ = $1;
759 }
760 /*
761 * A DefinedType reference.
762 * "CLASS1.&id.&id2"
763 * or
764 * "Module.Type"
765 * or
766 * "Module.identifier"
767 * or
768 * "Type"
769 */
770 | ComplexTypeReference {
vlm43c8ac52006-09-17 04:52:50 +0000771 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000772 checkmem($$);
773 $$->reference = $1;
774 $$->expr_type = A1TC_REFERENCE;
775 $$->meta_type = AMT_TYPEREF;
776 }
vlm17e65d02006-03-21 04:48:15 +0000777 /*
vlmdfbff8c2006-03-21 09:41:28 +0000778 * A parameterized assignment.
vlm17e65d02006-03-21 04:48:15 +0000779 */
vlmdfbff8c2006-03-21 09:41:28 +0000780 | ComplexTypeReference '{' ActualParameterList '}' {
vlm43c8ac52006-09-17 04:52:50 +0000781 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000782 checkmem($$);
vlm17e65d02006-03-21 04:48:15 +0000783 $$->reference = $1;
784 $$->rhs_pspecs = $3;
785 $$->expr_type = A1TC_REFERENCE;
786 $$->meta_type = AMT_TYPEREF;
vlmfa67ddc2004-06-03 03:38:44 +0000787 }
788 ;
789
vlmfa67ddc2004-06-03 03:38:44 +0000790/*
791 * Data Type Reference.
792 * === EXAMPLE ===
793 * Type3 ::= CHOICE { a Type1, b Type 2 }
794 * === EOF ===
795 */
vlmfa67ddc2004-06-03 03:38:44 +0000796DataTypeReference:
797 /*
798 * Optionally tagged type definition.
799 */
vlmdc7cf042006-03-09 08:49:26 +0000800 TypeRefName TOK_PPEQ Type {
vlmfce48a42004-09-14 02:36:39 +0000801 $$ = $3;
vlmfa67ddc2004-06-03 03:38:44 +0000802 $$->Identifier = $1;
vlmfa67ddc2004-06-03 03:38:44 +0000803 assert($$->expr_type);
804 assert($$->meta_type);
805 }
vlmdc7cf042006-03-09 08:49:26 +0000806 | TypeRefName TOK_PPEQ ObjectClass {
vlmfa67ddc2004-06-03 03:38:44 +0000807 $$ = $3;
808 $$->Identifier = $1;
809 assert($$->expr_type == A1TC_CLASSDEF);
vlmdc7cf042006-03-09 08:49:26 +0000810 assert($$->meta_type == AMT_OBJECTCLASS);
vlmfa67ddc2004-06-03 03:38:44 +0000811 }
812 /*
vlmdfbff8c2006-03-21 09:41:28 +0000813 * Parameterized <Type> declaration:
vlmfa67ddc2004-06-03 03:38:44 +0000814 * === EXAMPLE ===
815 * SIGNED { ToBeSigned } ::= SEQUENCE {
816 * toBeSigned ToBeSigned,
817 * algorithm AlgorithmIdentifier,
818 * signature BIT STRING
819 * }
820 * === EOF ===
821 */
vlmec8f6812004-08-22 03:19:54 +0000822 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
vlmfa67ddc2004-06-03 03:38:44 +0000823 $$ = $6;
vlmdfbff8c2006-03-21 09:41:28 +0000824 $$->Identifier = $1;
825 $$->lhs_params = $3;
826 }
827 /* Parameterized CLASS declaration */
828 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ ObjectClass {
829 $$ = $6;
vlmfa67ddc2004-06-03 03:38:44 +0000830 $$->Identifier = $1;
vlm0c6d3812006-03-21 03:40:38 +0000831 $$->lhs_params = $3;
vlmfa67ddc2004-06-03 03:38:44 +0000832 }
833 ;
834
835ParameterArgumentList:
836 ParameterArgumentName {
837 int ret;
838 $$ = asn1p_paramlist_new(yylineno);
839 checkmem($$);
840 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
841 checkmem(ret == 0);
842 if($1.governor) asn1p_ref_free($1.governor);
843 if($1.argument) free($1.argument);
844 }
845 | ParameterArgumentList ',' ParameterArgumentName {
846 int ret;
847 $$ = $1;
848 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
849 checkmem(ret == 0);
850 if($3.governor) asn1p_ref_free($3.governor);
851 if($3.argument) free($3.argument);
852 }
853 ;
854
855ParameterArgumentName:
856 TypeRefName {
857 $$.governor = NULL;
858 $$.argument = $1;
859 }
860 | TypeRefName ':' Identifier {
861 int ret;
862 $$.governor = asn1p_ref_new(yylineno);
863 ret = asn1p_ref_add_component($$.governor, $1, 0);
864 checkmem(ret == 0);
865 $$.argument = $3;
866 }
vlm4053ca52005-02-18 16:34:21 +0000867 | TypeRefName ':' TypeRefName {
868 int ret;
869 $$.governor = asn1p_ref_new(yylineno);
870 ret = asn1p_ref_add_component($$.governor, $1, 0);
871 checkmem(ret == 0);
872 $$.argument = $3;
873 }
vlmfa67ddc2004-06-03 03:38:44 +0000874 | BasicTypeId ':' Identifier {
875 int ret;
876 $$.governor = asn1p_ref_new(yylineno);
877 ret = asn1p_ref_add_component($$.governor,
878 ASN_EXPR_TYPE2STR($1), 1);
879 checkmem(ret == 0);
880 $$.argument = $3;
881 }
vlmdfbff8c2006-03-21 09:41:28 +0000882 | BasicTypeId ':' TypeRefName {
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 }
vlmfa67ddc2004-06-03 03:38:44 +0000890 ;
891
vlmdfbff8c2006-03-21 09:41:28 +0000892ActualParameterList:
893 ActualParameter {
vlm43c8ac52006-09-17 04:52:50 +0000894 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000895 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000896 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000897 }
vlmdfbff8c2006-03-21 09:41:28 +0000898 | ActualParameterList ',' ActualParameter {
vlmfa67ddc2004-06-03 03:38:44 +0000899 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000900 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000901 }
902 ;
903
vlmdfbff8c2006-03-21 09:41:28 +0000904ActualParameter:
vlmec8f6812004-08-22 03:19:54 +0000905 Type {
vlmfa67ddc2004-06-03 03:38:44 +0000906 $$ = $1;
907 }
vlm17e65d02006-03-21 04:48:15 +0000908 | SimpleValue {
vlm43c8ac52006-09-17 04:52:50 +0000909 $$ = NEW_EXPR();
vlm17e65d02006-03-21 04:48:15 +0000910 checkmem($$);
911 $$->Identifier = "?";
912 $$->expr_type = A1TC_REFERENCE;
913 $$->meta_type = AMT_VALUE;
914 $$->value = $1;
915 }
vlmfa67ddc2004-06-03 03:38:44 +0000916 | Identifier {
vlm0c6d3812006-03-21 03:40:38 +0000917 asn1p_ref_t *ref;
vlm43c8ac52006-09-17 04:52:50 +0000918 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000919 checkmem($$);
920 $$->Identifier = $1;
921 $$->expr_type = A1TC_REFERENCE;
922 $$->meta_type = AMT_VALUE;
vlm0c6d3812006-03-21 03:40:38 +0000923 ref = asn1p_ref_new(yylineno);
924 asn1p_ref_add_component(ref, $1, RLT_lowercase);
925 $$->value = asn1p_value_fromref(ref, 0);
vlmfa67ddc2004-06-03 03:38:44 +0000926 }
vlmdfbff8c2006-03-21 09:41:28 +0000927 | ValueSet {
vlm43c8ac52006-09-17 04:52:50 +0000928 $$ = NEW_EXPR();
vlmdfbff8c2006-03-21 09:41:28 +0000929 $$->expr_type = A1TC_VALUESET;
930 $$->meta_type = AMT_VALUESET;
931 $$->constraints = $1;
932 }
vlmfa67ddc2004-06-03 03:38:44 +0000933 ;
934
935/*
vlmdfbff8c2006-03-21 09:41:28 +0000936 | '{' ActualParameter '}' {
vlm43c8ac52006-09-17 04:52:50 +0000937 $$ = NEW_EXPR();
vlm4053ca52005-02-18 16:34:21 +0000938 checkmem($$);
939 asn1p_expr_add($$, $2);
940 $$->expr_type = A1TC_PARAMETRIZED;
941 $$->meta_type = AMT_TYPE;
942 }
943 ;
944*/
945
946/*
vlmfa67ddc2004-06-03 03:38:44 +0000947 * A collection of constructed data type members.
948 */
vlm0aa86902004-10-12 23:26:53 +0000949optComponentTypeLists:
vlm43c8ac52006-09-17 04:52:50 +0000950 { $$ = NEW_EXPR(); }
vlm0aa86902004-10-12 23:26:53 +0000951 | ComponentTypeLists { $$ = $1; };
952
vlmec8f6812004-08-22 03:19:54 +0000953ComponentTypeLists:
954 ComponentType {
vlm43c8ac52006-09-17 04:52:50 +0000955 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +0000956 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000957 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +0000958 }
vlmec8f6812004-08-22 03:19:54 +0000959 | ComponentTypeLists ',' ComponentType {
vlmfa67ddc2004-06-03 03:38:44 +0000960 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000961 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +0000962 }
963 ;
964
vlmec8f6812004-08-22 03:19:54 +0000965ComponentType:
vlmfce48a42004-09-14 02:36:39 +0000966 Identifier Type optMarker {
vlmec8f6812004-08-22 03:19:54 +0000967 $$ = $2;
968 assert($$->Identifier == 0);
vlmfce48a42004-09-14 02:36:39 +0000969 $$->Identifier = $1;
vlm177a5b62005-09-05 05:17:57 +0000970 $3.flags |= $$->marker.flags;
vlmec8f6812004-08-22 03:19:54 +0000971 $$->marker = $3;
972 }
vlm177a5b62005-09-05 05:17:57 +0000973 | Type optMarker {
974 $$ = $1;
975 $2.flags |= $$->marker.flags;
976 $$->marker = $2;
977 _fixup_anonymous_identifier($$);
978 }
vlmec8f6812004-08-22 03:19:54 +0000979 | TOK_COMPONENTS TOK_OF Type {
vlm43c8ac52006-09-17 04:52:50 +0000980 $$ = NEW_EXPR();
vlmec8f6812004-08-22 03:19:54 +0000981 checkmem($$);
982 $$->meta_type = $3->meta_type;
983 $$->expr_type = A1TC_COMPONENTS_OF;
vlm6a02a8a2004-09-08 00:28:11 +0000984 asn1p_expr_add($$, $3);
vlmec8f6812004-08-22 03:19:54 +0000985 }
986 | ExtensionAndException {
987 $$ = $1;
988 }
989 ;
990
991AlternativeTypeLists:
992 AlternativeType {
vlm43c8ac52006-09-17 04:52:50 +0000993 $$ = NEW_EXPR();
vlmec8f6812004-08-22 03:19:54 +0000994 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +0000995 asn1p_expr_add($$, $1);
vlmec8f6812004-08-22 03:19:54 +0000996 }
997 | AlternativeTypeLists ',' AlternativeType {
998 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +0000999 asn1p_expr_add($$, $3);
vlmec8f6812004-08-22 03:19:54 +00001000 }
1001 ;
1002
1003AlternativeType:
vlmfce48a42004-09-14 02:36:39 +00001004 Identifier Type {
vlmec8f6812004-08-22 03:19:54 +00001005 $$ = $2;
1006 assert($$->Identifier == 0);
vlmfce48a42004-09-14 02:36:39 +00001007 $$->Identifier = $1;
vlmec8f6812004-08-22 03:19:54 +00001008 }
1009 | ExtensionAndException {
1010 $$ = $1;
1011 }
vlm5d89c3d2005-08-13 09:07:11 +00001012 | Type {
1013 $$ = $1;
1014 _fixup_anonymous_identifier($$);
1015 }
vlmec8f6812004-08-22 03:19:54 +00001016 ;
1017
vlmdc7cf042006-03-09 08:49:26 +00001018ObjectClass:
1019 TOK_CLASS '{' FieldSpec '}' optWithSyntax {
vlmfa67ddc2004-06-03 03:38:44 +00001020 $$ = $3;
1021 checkmem($$);
1022 $$->with_syntax = $5;
1023 assert($$->expr_type == A1TC_CLASSDEF);
vlmdc7cf042006-03-09 08:49:26 +00001024 assert($$->meta_type == AMT_OBJECTCLASS);
vlmfa67ddc2004-06-03 03:38:44 +00001025 }
1026 ;
1027
1028optUnique:
1029 { $$ = 0; }
1030 | TOK_UNIQUE { $$ = 1; }
1031 ;
1032
vlmdc7cf042006-03-09 08:49:26 +00001033FieldSpec:
vlmfa67ddc2004-06-03 03:38:44 +00001034 ClassField {
vlm43c8ac52006-09-17 04:52:50 +00001035 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001036 checkmem($$);
1037 $$->expr_type = A1TC_CLASSDEF;
vlmdc7cf042006-03-09 08:49:26 +00001038 $$->meta_type = AMT_OBJECTCLASS;
vlm6a02a8a2004-09-08 00:28:11 +00001039 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +00001040 }
vlmdc7cf042006-03-09 08:49:26 +00001041 | FieldSpec ',' ClassField {
vlmfa67ddc2004-06-03 03:38:44 +00001042 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +00001043 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001044 }
1045 ;
1046
vlmdc7cf042006-03-09 08:49:26 +00001047 /* X.681 */
vlmfa67ddc2004-06-03 03:38:44 +00001048ClassField:
vlmdc7cf042006-03-09 08:49:26 +00001049
1050 /* TypeFieldSpec ::= typefieldreference TypeOptionalitySpec? */
1051 TOK_typefieldreference optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001052 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001053 checkmem($$);
vlmdc7cf042006-03-09 08:49:26 +00001054 $$->Identifier = $1;
vlmfa67ddc2004-06-03 03:38:44 +00001055 $$->meta_type = AMT_OBJECTFIELD;
vlmdc7cf042006-03-09 08:49:26 +00001056 $$->expr_type = A1TC_CLASSFIELD_TFS; /* TypeFieldSpec */
vlmfa67ddc2004-06-03 03:38:44 +00001057 $$->marker = $2;
1058 }
vlmdc7cf042006-03-09 08:49:26 +00001059
1060 /* FixedTypeValueFieldSpec ::= valuefieldreference Type UNIQUE ? ValueOptionalitySpec ? */
1061 | TOK_valuefieldreference Type optUnique optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001062 $$ = NEW_EXPR();
vlmdc7cf042006-03-09 08:49:26 +00001063 $$->Identifier = $1;
1064 $$->meta_type = AMT_OBJECTFIELD;
1065 $$->expr_type = A1TC_CLASSFIELD_FTVFS; /* FixedTypeValueFieldSpec */
vlmbde35d42004-11-24 17:43:29 +00001066 $$->unique = $3;
vlmdc7cf042006-03-09 08:49:26 +00001067 $$->marker = $4;
1068 asn1p_expr_add($$, $2);
vlmfa67ddc2004-06-03 03:38:44 +00001069 }
vlmdc7cf042006-03-09 08:49:26 +00001070
1071 /* VariableTypeValueFieldSpec ::= valuefieldreference FieldName ValueOptionalitySpec ? */
1072 | TOK_valuefieldreference FieldName optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001073 $$ = NEW_EXPR();
vlmdc7cf042006-03-09 08:49:26 +00001074 $$->Identifier = $1;
1075 $$->meta_type = AMT_OBJECTFIELD;
1076 $$->expr_type = A1TC_CLASSFIELD_VTVFS;
1077 $$->reference = $2;
1078 $$->marker = $3;
1079 }
1080
vlmdc7cf042006-03-09 08:49:26 +00001081 /* ObjectFieldSpec ::= objectfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1082 | TOK_valuefieldreference DefinedObjectClass optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001083 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001084 checkmem($$);
vlmdc7cf042006-03-09 08:49:26 +00001085 $$->Identifier = $1;
1086 $$->reference = $2;
vlmfa67ddc2004-06-03 03:38:44 +00001087 $$->meta_type = AMT_OBJECTFIELD;
vlmdc7cf042006-03-09 08:49:26 +00001088 $$->expr_type = A1TC_CLASSFIELD_OFS;
1089 $$->marker = $3;
vlmfa67ddc2004-06-03 03:38:44 +00001090 }
vlmdc7cf042006-03-09 08:49:26 +00001091
vlmee7196e2006-03-09 09:08:49 +00001092 /* VariableTypeValueSetFieldSpec ::= valuesetfieldreference FieldName ValueOptionalitySpec ? */
1093 | TOK_typefieldreference FieldName optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001094 $$ = NEW_EXPR();
vlmdc7cf042006-03-09 08:49:26 +00001095 $$->Identifier = $1;
vlmdc7cf042006-03-09 08:49:26 +00001096 $$->meta_type = AMT_OBJECTFIELD;
vlmee7196e2006-03-09 09:08:49 +00001097 $$->expr_type = A1TC_CLASSFIELD_VTVSFS;
1098 $$->reference = $2;
vlmdc7cf042006-03-09 08:49:26 +00001099 $$->marker = $3;
1100 }
1101
1102 /* FixedTypeValueSetFieldSpec ::= valuesetfieldreference Type ValueSetOptionalitySpec ? */
1103 | TOK_typefieldreference Type optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001104 $$ = NEW_EXPR();
vlmdc7cf042006-03-09 08:49:26 +00001105 checkmem($$);
1106 $$->Identifier = $1;
1107 $$->meta_type = AMT_OBJECTFIELD;
1108 $$->expr_type = A1TC_CLASSFIELD_FTVSFS;
1109 asn1p_expr_add($$, $2);
1110 $$->marker = $3;
1111 }
1112
vlmee7196e2006-03-09 09:08:49 +00001113 /* ObjectSetFieldSpec ::= objectsetfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1114 | TOK_typefieldreference DefinedObjectClass optMarker {
vlm43c8ac52006-09-17 04:52:50 +00001115 $$ = NEW_EXPR();
vlmee7196e2006-03-09 09:08:49 +00001116 checkmem($$);
1117 $$->Identifier = $1;
1118 $$->reference = $2;
1119 $$->meta_type = AMT_OBJECTFIELD;
1120 $$->expr_type = A1TC_CLASSFIELD_OSFS;
1121 $$->marker = $3;
1122 }
vlmfa67ddc2004-06-03 03:38:44 +00001123 ;
1124
1125optWithSyntax:
1126 { $$ = 0; }
1127 | WithSyntax {
1128 $$ = $1;
1129 }
1130 ;
1131
1132WithSyntax:
1133 TOK_WITH TOK_SYNTAX '{'
1134 { asn1p_lexer_hack_enable_with_syntax(); }
vlm808411d2006-03-14 16:31:37 +00001135 WithSyntaxList
vlmfa67ddc2004-06-03 03:38:44 +00001136 '}' {
1137 $$ = $5;
1138 }
1139 ;
1140
vlm808411d2006-03-14 16:31:37 +00001141WithSyntaxList:
1142 WithSyntaxToken {
vlmfa67ddc2004-06-03 03:38:44 +00001143 $$ = asn1p_wsyntx_new();
1144 TQ_ADD(&($$->chunks), $1, next);
1145 }
vlm808411d2006-03-14 16:31:37 +00001146 | WithSyntaxList WithSyntaxToken {
vlmfa67ddc2004-06-03 03:38:44 +00001147 $$ = $1;
1148 TQ_ADD(&($$->chunks), $2, next);
1149 }
1150 ;
1151
vlm808411d2006-03-14 16:31:37 +00001152WithSyntaxToken:
vlmeeb3c512006-03-16 05:11:14 +00001153 TOK_whitespace {
vlm1fcf7592006-08-18 02:27:55 +00001154 $$ = asn1p_wsyntx_chunk_fromstring($1.buf, 0);
vlmeeb3c512006-03-16 05:11:14 +00001155 $$->type = WC_WHITESPACE;
vlmfa67ddc2004-06-03 03:38:44 +00001156 }
vlm808411d2006-03-14 16:31:37 +00001157 | TOK_Literal {
vlm1fcf7592006-08-18 02:27:55 +00001158 $$ = asn1p_wsyntx_chunk_fromstring($1, 0);
vlm808411d2006-03-14 16:31:37 +00001159 }
vlma6a84d72006-03-16 10:03:35 +00001160 | PrimitiveFieldReference {
vlm1fcf7592006-08-18 02:27:55 +00001161 $$ = asn1p_wsyntx_chunk_fromstring($1.name, 0);
vlma6a84d72006-03-16 10:03:35 +00001162 $$->type = WC_FIELD;
vlmfa67ddc2004-06-03 03:38:44 +00001163 }
vlm808411d2006-03-14 16:31:37 +00001164 | '[' WithSyntaxList ']' {
1165 $$ = asn1p_wsyntx_chunk_fromsyntax($2);
1166 }
vlmfa67ddc2004-06-03 03:38:44 +00001167 ;
1168
vlmfa67ddc2004-06-03 03:38:44 +00001169ExtensionAndException:
1170 TOK_ThreeDots {
vlm43c8ac52006-09-17 04:52:50 +00001171 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001172 checkmem($$);
1173 $$->Identifier = strdup("...");
1174 checkmem($$->Identifier);
1175 $$->expr_type = A1TC_EXTENSIBLE;
1176 $$->meta_type = AMT_TYPE;
1177 }
1178 | TOK_ThreeDots '!' DefinedValue {
vlm43c8ac52006-09-17 04:52:50 +00001179 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001180 checkmem($$);
1181 $$->Identifier = strdup("...");
1182 checkmem($$->Identifier);
1183 $$->value = $3;
1184 $$->expr_type = A1TC_EXTENSIBLE;
1185 $$->meta_type = AMT_TYPE;
1186 }
1187 | TOK_ThreeDots '!' SignedNumber {
vlm43c8ac52006-09-17 04:52:50 +00001188 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001189 checkmem($$);
1190 $$->Identifier = strdup("...");
1191 $$->value = $3;
1192 checkmem($$->Identifier);
1193 $$->expr_type = A1TC_EXTENSIBLE;
1194 $$->meta_type = AMT_TYPE;
1195 }
1196 ;
1197
vlmec8f6812004-08-22 03:19:54 +00001198Type:
vlmfce48a42004-09-14 02:36:39 +00001199 optTag TypeDeclaration optConstraints {
1200 $$ = $2;
1201 $$->tag = $1;
vlmec8f6812004-08-22 03:19:54 +00001202 /*
1203 * Outer constraint for SEQUENCE OF and SET OF applies
1204 * to the inner type.
1205 */
1206 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1207 || $$->expr_type == ASN_CONSTR_SET_OF) {
1208 assert(!TQ_FIRST(&($$->members))->constraints);
vlmfce48a42004-09-14 02:36:39 +00001209 TQ_FIRST(&($$->members))->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001210 } else {
1211 if($$->constraints) {
1212 assert(!$2);
1213 } else {
vlmfce48a42004-09-14 02:36:39 +00001214 $$->constraints = $3;
vlmec8f6812004-08-22 03:19:54 +00001215 }
1216 }
vlm177a5b62005-09-05 05:17:57 +00001217 }
1218 ;
1219
1220NSTD_IndirectMarker:
1221 {
1222 $$ = asn1p_as_pointer ? EM_INDIRECT : 0;
1223 asn1p_as_pointer = 0;
vlmec8f6812004-08-22 03:19:54 +00001224 }
1225 ;
1226
1227TypeDeclaration:
vlm177a5b62005-09-05 05:17:57 +00001228 NSTD_IndirectMarker TypeDeclarationSet {
vlm066dc102005-08-22 12:23:54 +00001229 $$ = $2;
vlm177a5b62005-09-05 05:17:57 +00001230 $$->marker.flags |= $1;
1231
1232 if(($$->marker.flags & EM_INDIRECT)
1233 && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
1234 fprintf(stderr,
1235 "INFO: Directive <ASN1C:RepresentAsPointer> "
1236 "applied to %s at line %d\n",
1237 ASN_EXPR_TYPE2STR($$->expr_type)
1238 ? ASN_EXPR_TYPE2STR($$->expr_type)
1239 : "member",
1240 $$->_lineno
1241 );
1242 }
vlm066dc102005-08-22 12:23:54 +00001243 }
vlm177a5b62005-09-05 05:17:57 +00001244 ;
vlm066dc102005-08-22 12:23:54 +00001245
1246TypeDeclarationSet:
vlm17e65d02006-03-21 04:48:15 +00001247 DefinedType {
vlmfa67ddc2004-06-03 03:38:44 +00001248 $$ = $1;
1249 }
vlm177a5b62005-09-05 05:17:57 +00001250 | TOK_CHOICE '{' AlternativeTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001251 $$ = $3;
1252 assert($$->expr_type == A1TC_INVALID);
1253 $$->expr_type = ASN_CONSTR_CHOICE;
1254 $$->meta_type = AMT_TYPE;
vlmfa67ddc2004-06-03 03:38:44 +00001255 }
vlm177a5b62005-09-05 05:17:57 +00001256 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001257 $$ = $3;
1258 assert($$->expr_type == A1TC_INVALID);
1259 $$->expr_type = ASN_CONSTR_SEQUENCE;
1260 $$->meta_type = AMT_TYPE;
1261 }
vlm177a5b62005-09-05 05:17:57 +00001262 | TOK_SET '{' optComponentTypeLists '}' {
vlmec8f6812004-08-22 03:19:54 +00001263 $$ = $3;
1264 assert($$->expr_type == A1TC_INVALID);
1265 $$->expr_type = ASN_CONSTR_SET;
1266 $$->meta_type = AMT_TYPE;
1267 }
vlm151c0b22004-09-22 16:03:36 +00001268 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
vlm43c8ac52006-09-17 04:52:50 +00001269 $$ = NEW_EXPR();
vlmec8f6812004-08-22 03:19:54 +00001270 checkmem($$);
1271 $$->constraints = $2;
1272 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1273 $$->meta_type = AMT_TYPE;
vlm151c0b22004-09-22 16:03:36 +00001274 $6->Identifier = $4;
1275 $6->tag = $5;
1276 asn1p_expr_add($$, $6);
vlmec8f6812004-08-22 03:19:54 +00001277 }
vlm151c0b22004-09-22 16:03:36 +00001278 | TOK_SET 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_SET_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 }
1288 | TOK_ANY {
vlm43c8ac52006-09-17 04:52:50 +00001289 $$ = NEW_EXPR();
vlmec8f6812004-08-22 03:19:54 +00001290 checkmem($$);
vlm044f7442004-09-04 04:49:21 +00001291 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001292 $$->meta_type = AMT_TYPE;
1293 }
1294 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1295 int ret;
vlm43c8ac52006-09-17 04:52:50 +00001296 $$ = NEW_EXPR();
vlmec8f6812004-08-22 03:19:54 +00001297 checkmem($$);
1298 $$->reference = asn1p_ref_new(yylineno);
1299 ret = asn1p_ref_add_component($$->reference,
1300 $4, RLT_lowercase);
1301 checkmem(ret == 0);
vlm044f7442004-09-04 04:49:21 +00001302 $$->expr_type = ASN_TYPE_ANY;
vlmec8f6812004-08-22 03:19:54 +00001303 $$->meta_type = AMT_TYPE;
1304 }
vlmfa67ddc2004-06-03 03:38:44 +00001305 | TOK_INSTANCE TOK_OF ComplexTypeReference {
vlm43c8ac52006-09-17 04:52:50 +00001306 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001307 checkmem($$);
1308 $$->reference = $3;
1309 $$->expr_type = A1TC_INSTANCE;
1310 $$->meta_type = AMT_TYPE;
1311 }
1312 ;
1313
1314/*
1315 * A type name consisting of several components.
1316 * === EXAMPLE ===
1317 * === EOF ===
1318 */
1319ComplexTypeReference:
1320 TOK_typereference {
1321 int ret;
1322 $$ = asn1p_ref_new(yylineno);
1323 checkmem($$);
1324 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1325 checkmem(ret == 0);
1326 free($1);
1327 }
1328 | TOK_typereference '.' TypeRefName {
1329 int ret;
1330 $$ = asn1p_ref_new(yylineno);
1331 checkmem($$);
1332 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1333 checkmem(ret == 0);
1334 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1335 checkmem(ret == 0);
1336 free($1);
1337 }
vlmc94e28f2004-09-15 11:59:51 +00001338 | ObjectClassReference '.' 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 }
vlmfa67ddc2004-06-03 03:38:44 +00001348 | TOK_typereference '.' Identifier {
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_lowercase);
1355 checkmem(ret == 0);
1356 free($1);
1357 }
1358 | ObjectClassReference {
1359 int ret;
1360 $$ = asn1p_ref_new(yylineno);
1361 checkmem($$);
1362 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1363 free($1);
1364 checkmem(ret == 0);
1365 }
1366 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1367 int ret;
1368 $$ = $3;
1369 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1370 free($1);
1371 checkmem(ret == 0);
1372 /*
1373 * Move the last element infront.
1374 */
1375 {
1376 struct asn1p_ref_component_s tmp_comp;
1377 tmp_comp = $$->components[$$->comp_count-1];
1378 memmove(&$$->components[1],
1379 &$$->components[0],
1380 sizeof($$->components[0])
1381 * ($$->comp_count - 1));
1382 $$->components[0] = tmp_comp;
1383 }
1384 }
1385 ;
1386
1387ComplexTypeReferenceAmpList:
1388 ComplexTypeReferenceElement {
1389 int ret;
1390 $$ = asn1p_ref_new(yylineno);
1391 checkmem($$);
1392 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1393 free($1.name);
1394 checkmem(ret == 0);
1395 }
1396 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1397 int ret;
1398 $$ = $1;
1399 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1400 free($3.name);
1401 checkmem(ret == 0);
1402 }
1403 ;
1404
vlma6a84d72006-03-16 10:03:35 +00001405ComplexTypeReferenceElement: PrimitiveFieldReference;
vlmfa67ddc2004-06-03 03:38:44 +00001406
vlma6a84d72006-03-16 10:03:35 +00001407PrimitiveFieldReference:
vlmfa67ddc2004-06-03 03:38:44 +00001408 /* "&Type1" */
1409 TOK_typefieldreference {
1410 $$.lex_type = RLT_AmpUppercase;
1411 $$.name = $1;
1412 }
1413 /* "&id" */
1414 | TOK_valuefieldreference {
1415 $$.lex_type = RLT_Amplowercase;
1416 $$.name = $1;
1417 }
1418 ;
1419
1420
vlmdc7cf042006-03-09 08:49:26 +00001421FieldName:
1422 /* "&Type1" */
1423 TOK_typefieldreference {
1424 $$ = asn1p_ref_new(yylineno);
1425 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1426 }
1427 | FieldName '.' TOK_typefieldreference {
1428 $$ = $$;
1429 asn1p_ref_add_component($$, $3, RLT_AmpUppercase);
1430 }
1431 | FieldName '.' TOK_valuefieldreference {
1432 $$ = $$;
1433 asn1p_ref_add_component($$, $3, RLT_Amplowercase);
1434 }
1435 ;
1436
1437DefinedObjectClass:
1438 TOK_capitalreference {
1439 $$ = asn1p_ref_new(yylineno);
1440 asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1441 }
vlmee7196e2006-03-09 09:08:49 +00001442/*
vlmdc7cf042006-03-09 08:49:26 +00001443 | TypeRefName '.' TOK_capitalreference {
1444 $$ = asn1p_ref_new(yylineno);
1445 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1446 asn1p_ref_add_component($$, $3, RLT_CAPITALS);
1447 }
vlmee7196e2006-03-09 09:08:49 +00001448*/
vlmdc7cf042006-03-09 08:49:26 +00001449 ;
1450
1451
vlmfa67ddc2004-06-03 03:38:44 +00001452/*
1453 * === EXAMPLE ===
1454 * value INTEGER ::= 1
1455 * === EOF ===
1456 */
1457ValueDefinition:
vlm17e65d02006-03-21 04:48:15 +00001458 Identifier DefinedType TOK_PPEQ Value {
vlmfa67ddc2004-06-03 03:38:44 +00001459 $$ = $2;
1460 assert($$->Identifier == NULL);
1461 $$->Identifier = $1;
1462 $$->meta_type = AMT_VALUE;
1463 $$->value = $4;
1464 }
1465 ;
1466
vlmc94e28f2004-09-15 11:59:51 +00001467Value:
vlm17e65d02006-03-21 04:48:15 +00001468 SimpleValue
1469 | DefinedValue
1470 | Identifier ':' Value {
vlmc94e28f2004-09-15 11:59:51 +00001471 $$ = asn1p_value_fromint(0);
1472 checkmem($$);
1473 $$->type = ATV_CHOICE_IDENTIFIER;
1474 $$->value.choice_identifier.identifier = $1;
1475 $$->value.choice_identifier.value = $3;
1476 }
vlmd30bc6c2005-03-24 16:27:02 +00001477 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
vlmfa67ddc2004-06-03 03:38:44 +00001478 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1479 checkmem($$);
1480 $$->type = ATV_UNPARSED;
1481 }
vlmc94e28f2004-09-15 11:59:51 +00001482 | TOK_NULL {
1483 $$ = asn1p_value_fromint(0);
1484 checkmem($$);
1485 $$->type = ATV_NULL;
1486 }
vlm17e65d02006-03-21 04:48:15 +00001487 ;
1488
1489SimpleValue:
1490 TOK_FALSE {
vlmc94e28f2004-09-15 11:59:51 +00001491 $$ = asn1p_value_fromint(0);
1492 checkmem($$);
1493 $$->type = ATV_FALSE;
1494 }
1495 | TOK_TRUE {
1496 $$ = asn1p_value_fromint(0);
1497 checkmem($$);
1498 $$->type = ATV_TRUE;
1499 }
vlmfa67ddc2004-06-03 03:38:44 +00001500 | TOK_bstring {
1501 $$ = _convert_bitstring2binary($1, 'B');
1502 checkmem($$);
1503 }
1504 | TOK_hstring {
1505 $$ = _convert_bitstring2binary($1, 'H');
1506 checkmem($$);
1507 }
vlme1e6ed82005-03-24 14:26:38 +00001508 | RestrictedCharacterStringValue {
1509 $$ = $$;
vlmfa67ddc2004-06-03 03:38:44 +00001510 }
1511 | SignedNumber {
1512 $$ = $1;
1513 }
vlmfa67ddc2004-06-03 03:38:44 +00001514 ;
1515
1516DefinedValue:
1517 Identifier {
1518 asn1p_ref_t *ref;
1519 int ret;
1520 ref = asn1p_ref_new(yylineno);
1521 checkmem(ref);
1522 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1523 checkmem(ret == 0);
1524 $$ = asn1p_value_fromref(ref, 0);
1525 checkmem($$);
1526 free($1);
1527 }
1528 | TypeRefName '.' Identifier {
1529 asn1p_ref_t *ref;
1530 int ret;
1531 ref = asn1p_ref_new(yylineno);
1532 checkmem(ref);
1533 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1534 checkmem(ret == 0);
1535 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1536 checkmem(ret == 0);
1537 $$ = asn1p_value_fromref(ref, 0);
1538 checkmem($$);
1539 free($1);
1540 free($3);
1541 }
1542 ;
1543
vlme1e6ed82005-03-24 14:26:38 +00001544
1545RestrictedCharacterStringValue:
1546 TOK_cstring {
1547 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1548 checkmem($$);
1549 }
vlm2c8c44d2005-03-24 16:22:35 +00001550 | TOK_tuple {
1551 $$ = asn1p_value_fromint($1);
1552 checkmem($$);
1553 $$->type = ATV_TUPLE;
1554 }
1555 | TOK_quadruple {
1556 $$ = asn1p_value_fromint($1);
1557 checkmem($$);
1558 $$->type = ATV_QUADRUPLE;
1559 }
1560 /*
vlme1e6ed82005-03-24 14:26:38 +00001561 | '{' TOK_number ',' TOK_number '}' {
1562 asn1c_integer_t v = ($2 << 4) + $4;
1563 if($2 > 7) return yyerror("X.680:2003, #37.14 "
1564 "mandates 0..7 range for Tuple's TableColumn");
1565 if($4 > 15) return yyerror("X.680:2003, #37.14 "
1566 "mandates 0..15 range for Tuple's TableRow");
1567 $$ = asn1p_value_fromint(v);
1568 checkmem($$);
1569 $$->type = ATV_TUPLE;
1570 }
1571 | '{' TOK_number ',' TOK_number ',' TOK_number ',' TOK_number '}' {
1572 asn1c_integer_t v = ($2 << 24) | ($4 << 16) | ($6 << 8) | $8;
1573 if($2 > 127) return yyerror("X.680:2003, #37.12 "
1574 "mandates 0..127 range for Quadruple's Group");
1575 if($4 > 255) return yyerror("X.680:2003, #37.12 "
1576 "mandates 0..255 range for Quadruple's Plane");
1577 if($6 > 255) return yyerror("X.680:2003, #37.12 "
1578 "mandates 0..255 range for Quadruple's Row");
1579 if($8 > 255) return yyerror("X.680:2003, #37.12 "
1580 "mandates 0..255 range for Quadruple's Cell");
1581 $$ = asn1p_value_fromint(v);
1582 checkmem($$);
1583 $$->type = ATV_QUADRUPLE;
1584 }
vlm2c8c44d2005-03-24 16:22:35 +00001585 */
vlme1e6ed82005-03-24 14:26:38 +00001586 ;
1587
vlmfa67ddc2004-06-03 03:38:44 +00001588Opaque:
1589 TOK_opaque {
vlm6611add2005-03-20 14:28:32 +00001590 $$.len = $1.len + 1;
vlmfa67ddc2004-06-03 03:38:44 +00001591 $$.buf = malloc($$.len + 1);
1592 checkmem($$.buf);
1593 $$.buf[0] = '{';
vlm6611add2005-03-20 14:28:32 +00001594 memcpy($$.buf + 1, $1.buf, $1.len);
vlmfa67ddc2004-06-03 03:38:44 +00001595 $$.buf[$$.len] = '\0';
1596 free($1.buf);
1597 }
1598 | Opaque TOK_opaque {
1599 int newsize = $1.len + $2.len;
1600 char *p = malloc(newsize + 1);
1601 checkmem(p);
1602 memcpy(p , $1.buf, $1.len);
1603 memcpy(p + $1.len, $2.buf, $2.len);
1604 p[newsize] = '\0';
1605 free($1.buf);
1606 free($2.buf);
1607 $$.buf = p;
1608 $$.len = newsize;
1609 }
1610 ;
1611
1612BasicTypeId:
1613 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1614 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1615 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1616 | BasicTypeId_UniverationCompatible { $$ = $1; }
1617 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1618 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1619 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1620 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1621 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1622 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1623 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1624 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
vlm5e2c4b92005-03-20 11:12:40 +00001625 | BasicString { $$ = $1; }
vlmfa67ddc2004-06-03 03:38:44 +00001626 ;
1627
1628/*
1629 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1630 */
1631BasicTypeId_UniverationCompatible:
1632 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1633 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1634 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1635 ;
1636
1637BasicType:
1638 BasicTypeId {
vlm43c8ac52006-09-17 04:52:50 +00001639 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001640 checkmem($$);
1641 $$->expr_type = $1;
1642 $$->meta_type = AMT_TYPE;
1643 }
1644 | BasicTypeId_UniverationCompatible UniverationDefinition {
1645 if($2) {
1646 $$ = $2;
1647 } else {
vlm43c8ac52006-09-17 04:52:50 +00001648 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00001649 checkmem($$);
1650 }
1651 $$->expr_type = $1;
1652 $$->meta_type = AMT_TYPE;
1653 }
1654 ;
1655
1656BasicString:
1657 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1658 | TOK_GeneralString {
1659 $$ = ASN_STRING_GeneralString;
vlmc94e28f2004-09-15 11:59:51 +00001660 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001661 }
1662 | TOK_GraphicString {
1663 $$ = ASN_STRING_GraphicString;
vlmc94e28f2004-09-15 11:59:51 +00001664 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001665 }
1666 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1667 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1668 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1669 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1670 | TOK_T61String {
1671 $$ = ASN_STRING_T61String;
vlmc94e28f2004-09-15 11:59:51 +00001672 fprintf(stderr, "WARNING: T61String is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001673 }
1674 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1675 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1676 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1677 | TOK_VideotexString {
1678 $$ = ASN_STRING_VideotexString;
vlmc94e28f2004-09-15 11:59:51 +00001679 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
vlmfa67ddc2004-06-03 03:38:44 +00001680 }
1681 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1682 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1683 ;
1684
vlm5f0128b2004-08-20 13:25:29 +00001685
vlmfa67ddc2004-06-03 03:38:44 +00001686/*
1687 * Data type constraints.
1688 */
vlmfa67ddc2004-06-03 03:38:44 +00001689Union: '|' | TOK_UNION;
1690Intersection: '^' | TOK_INTERSECTION;
1691Except: TOK_EXCEPT;
1692
vlm9283dbe2004-08-18 04:59:12 +00001693optConstraints:
1694 { $$ = 0; }
vlm43c8ac52006-09-17 04:52:50 +00001695 | Constraint {
vlm5f0128b2004-08-20 13:25:29 +00001696 $$ = $1;
1697 }
1698 ;
1699
vlm43c8ac52006-09-17 04:52:50 +00001700Constraint:
1701 SubtypeConstraint
1702 | '(' GeneralConstraint ')' {
1703 $$ = $2;
1704 }
1705 ;
1706
1707SubtypeConstraint:
vlm5f0128b2004-08-20 13:25:29 +00001708 SetOfConstraints {
vlm9fe7c922005-08-12 10:08:45 +00001709 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
vlm9283dbe2004-08-18 04:59:12 +00001710 }
1711 | TOK_SIZE '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001712 /*
1713 * This is a special case, for compatibility purposes.
vlm9283dbe2004-08-18 04:59:12 +00001714 * It goes without parentheses.
vlmfa67ddc2004-06-03 03:38:44 +00001715 */
vlm9fe7c922005-08-12 10:08:45 +00001716 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001717 }
vlmfa67ddc2004-06-03 03:38:44 +00001718 ;
1719
vlm9283dbe2004-08-18 04:59:12 +00001720SetOfConstraints:
1721 '(' ElementSetSpecs ')' {
vlmfa67ddc2004-06-03 03:38:44 +00001722 $$ = $2;
1723 }
vlm9283dbe2004-08-18 04:59:12 +00001724 | SetOfConstraints '(' ElementSetSpecs ')' {
vlm9fe7c922005-08-12 10:08:45 +00001725 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
vlm9283dbe2004-08-18 04:59:12 +00001726 }
vlmfa67ddc2004-06-03 03:38:44 +00001727 ;
1728
vlm9283dbe2004-08-18 04:59:12 +00001729ElementSetSpecs:
vlmdfbff8c2006-03-21 09:41:28 +00001730 TOK_ThreeDots {
1731 $$ = asn1p_constraint_new(yylineno);
1732 $$->type = ACT_EL_EXT;
1733 }
1734 | ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001735 $$ = $1;
1736 }
vlm9283dbe2004-08-18 04:59:12 +00001737 | ElementSetSpec ',' TOK_ThreeDots {
vlmfa67ddc2004-06-03 03:38:44 +00001738 asn1p_constraint_t *ct;
1739 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001740 ct->type = ACT_EL_EXT;
vlm9fe7c922005-08-12 10:08:45 +00001741 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlmfa67ddc2004-06-03 03:38:44 +00001742 }
vlm9283dbe2004-08-18 04:59:12 +00001743 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
vlmfa67ddc2004-06-03 03:38:44 +00001744 asn1p_constraint_t *ct;
1745 ct = asn1p_constraint_new(yylineno);
vlmfa67ddc2004-06-03 03:38:44 +00001746 ct->type = ACT_EL_EXT;
vlm9fe7c922005-08-12 10:08:45 +00001747 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlm6f5eb0b2004-08-13 12:35:09 +00001748 ct = $$;
vlm9fe7c922005-08-12 10:08:45 +00001749 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
vlmfa67ddc2004-06-03 03:38:44 +00001750 }
vlmfa67ddc2004-06-03 03:38:44 +00001751 ;
1752
vlm9283dbe2004-08-18 04:59:12 +00001753ElementSetSpec:
1754 ConstraintSubtypeElement {
1755 $$ = $1;
1756 }
vlme1e6ed82005-03-24 14:26:38 +00001757 | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001758 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
vlme1e6ed82005-03-24 14:26:38 +00001759 }
vlm9283dbe2004-08-18 04:59:12 +00001760 | ElementSetSpec Union ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001761 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001762 }
vlm9283dbe2004-08-18 04:59:12 +00001763 | ElementSetSpec Intersection ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001764 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001765 }
vlm9283dbe2004-08-18 04:59:12 +00001766 | ConstraintSubtypeElement Except ConstraintSubtypeElement {
vlm9fe7c922005-08-12 10:08:45 +00001767 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001768 }
1769 ;
1770
1771ConstraintSubtypeElement:
vlm9283dbe2004-08-18 04:59:12 +00001772 ConstraintSpec '(' ElementSetSpecs ')' {
1773 int ret;
1774 $$ = asn1p_constraint_new(yylineno);
1775 checkmem($$);
1776 $$->type = $1;
1777 ret = asn1p_constraint_insert($$, $3);
1778 checkmem(ret == 0);
1779 }
1780 | '(' ElementSetSpecs ')' {
1781 int ret;
1782 $$ = asn1p_constraint_new(yylineno);
1783 checkmem($$);
1784 $$->type = ACT_CA_SET;
1785 ret = asn1p_constraint_insert($$, $2);
1786 checkmem(ret == 0);
1787 }
vlma6a12e32005-03-20 12:58:00 +00001788 | SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001789 $$ = asn1p_constraint_new(yylineno);
1790 checkmem($$);
1791 $$->type = ACT_EL_VALUE;
1792 $$->value = $1;
1793 }
vlma6a12e32005-03-20 12:58:00 +00001794 | ContainedSubtype {
1795 $$ = asn1p_constraint_new(yylineno);
1796 checkmem($$);
1797 $$->type = ACT_EL_TYPE;
1798 $$->containedSubtype = $1;
1799 }
1800 | SingleValue ConstraintRangeSpec SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001801 $$ = asn1p_constraint_new(yylineno);
1802 checkmem($$);
1803 $$->type = $2;
1804 $$->range_start = $1;
1805 $$->range_stop = $3;
1806 }
vlma6a12e32005-03-20 12:58:00 +00001807 | TOK_MIN ConstraintRangeSpec SingleValue {
vlmfa67ddc2004-06-03 03:38:44 +00001808 $$ = asn1p_constraint_new(yylineno);
1809 checkmem($$);
vlm9283dbe2004-08-18 04:59:12 +00001810 $$->type = $2;
1811 $$->range_start = asn1p_value_fromint(-123);
1812 $$->range_stop = $3;
1813 $$->range_start->type = ATV_MIN;
1814 }
vlma6a12e32005-03-20 12:58:00 +00001815 | SingleValue ConstraintRangeSpec TOK_MAX {
vlm9283dbe2004-08-18 04:59:12 +00001816 $$ = asn1p_constraint_new(yylineno);
1817 checkmem($$);
1818 $$->type = $2;
1819 $$->range_start = $1;
1820 $$->range_stop = asn1p_value_fromint(321);
1821 $$->range_stop->type = ATV_MAX;
1822 }
1823 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1824 $$ = asn1p_constraint_new(yylineno);
1825 checkmem($$);
1826 $$->type = $2;
1827 $$->range_start = asn1p_value_fromint(-123);
1828 $$->range_stop = asn1p_value_fromint(321);
1829 $$->range_start->type = ATV_MIN;
1830 $$->range_stop->type = ATV_MAX;
vlmfa67ddc2004-06-03 03:38:44 +00001831 }
vlm7bbdc9f2005-03-28 15:01:27 +00001832 | InnerTypeConstraint {
vlmfa67ddc2004-06-03 03:38:44 +00001833 $$ = $1;
1834 }
vlmfa67ddc2004-06-03 03:38:44 +00001835 ;
1836
1837ConstraintSpec:
1838 TOK_SIZE {
1839 $$ = ACT_CT_SIZE;
1840 }
1841 | TOK_FROM {
1842 $$ = ACT_CT_FROM;
1843 }
1844 ;
1845
vlma6a12e32005-03-20 12:58:00 +00001846SingleValue:
vlm4053ca52005-02-18 16:34:21 +00001847 TOK_FALSE {
1848 $$ = asn1p_value_fromint(0);
1849 checkmem($$);
1850 $$->type = ATV_FALSE;
1851 }
1852 | TOK_TRUE {
1853 $$ = asn1p_value_fromint(1);
1854 checkmem($$);
1855 $$->type = ATV_TRUE;
1856 }
vlme745fcd2006-09-05 16:18:34 +00001857 | RealValue
1858 | RestrictedCharacterStringValue
vlmfa67ddc2004-06-03 03:38:44 +00001859 | Identifier {
1860 asn1p_ref_t *ref;
1861 int ret;
1862 ref = asn1p_ref_new(yylineno);
1863 checkmem(ref);
1864 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1865 checkmem(ret == 0);
1866 $$ = asn1p_value_fromref(ref, 0);
1867 checkmem($$);
1868 free($1);
1869 }
vlma6a12e32005-03-20 12:58:00 +00001870 ;
1871
1872ContainedSubtype:
1873 TypeRefName {
vlm4053ca52005-02-18 16:34:21 +00001874 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_UNKNOWN);
1879 checkmem(ret == 0);
1880 $$ = asn1p_value_fromref(ref, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001881 checkmem($$);
vlm4053ca52005-02-18 16:34:21 +00001882 free($1);
vlmfa67ddc2004-06-03 03:38:44 +00001883 }
1884 ;
1885
vlm7bbdc9f2005-03-28 15:01:27 +00001886InnerTypeConstraint:
1887 TOK_WITH TOK_COMPONENT SetOfConstraints {
vlm9fe7c922005-08-12 10:08:45 +00001888 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
vlm7bbdc9f2005-03-28 15:01:27 +00001889 }
1890 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
vlm9fe7c922005-08-12 10:08:45 +00001891 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001892 }
1893 ;
1894
1895WithComponentsList:
1896 WithComponentsElement {
1897 $$ = $1;
1898 }
1899 | WithComponentsList ',' WithComponentsElement {
vlm9fe7c922005-08-12 10:08:45 +00001900 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00001901 }
1902 ;
1903
1904WithComponentsElement:
1905 TOK_ThreeDots {
1906 $$ = asn1p_constraint_new(yylineno);
1907 checkmem($$);
1908 $$->type = ACT_EL_EXT;
vlm1aeaddd2006-07-13 08:24:20 +00001909 $$->value = asn1p_value_frombuf("...", 3, 1);
vlmfa67ddc2004-06-03 03:38:44 +00001910 }
1911 | Identifier optConstraints optPresenceConstraint {
1912 $$ = asn1p_constraint_new(yylineno);
1913 checkmem($$);
1914 $$->type = ACT_EL_VALUE;
1915 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1916 $$->presence = $3;
vlm7bbdc9f2005-03-28 15:01:27 +00001917 if($2) asn1p_constraint_insert($$, $2);
vlmfa67ddc2004-06-03 03:38:44 +00001918 }
1919 ;
1920
1921/*
1922 * presence constraint for WithComponents
1923 */
1924optPresenceConstraint:
1925 { $$ = ACPRES_DEFAULT; }
1926 | PresenceConstraint { $$ = $1; }
1927 ;
1928
1929PresenceConstraint:
1930 TOK_PRESENT {
1931 $$ = ACPRES_PRESENT;
1932 }
1933 | TOK_ABSENT {
1934 $$ = ACPRES_ABSENT;
1935 }
1936 | TOK_OPTIONAL {
1937 $$ = ACPRES_OPTIONAL;
1938 }
1939 ;
1940
vlm43c8ac52006-09-17 04:52:50 +00001941
1942/* X.682 */
1943GeneralConstraint:
1944 UserDefinedConstraint
1945 | TableConstraint
1946 | ContentsConstraint
1947 ;
1948
1949UserDefinedConstraint:
1950 TOK_CONSTRAINED TOK_BY '{'
1951 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1952 $$ = asn1p_constraint_new(yylineno);
1953 checkmem($$);
1954 $$->type = ACT_CT_CTDBY;
1955 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
1956 checkmem($$->value);
1957 $$->value->type = ATV_UNPARSED;
1958 }
1959 ;
1960
1961ContentsConstraint:
1962 TOK_CONTAINING Type {
1963 $$ = asn1p_constraint_new(yylineno);
1964 $$->type = ACT_CT_CTNG;
1965 $$->value = asn1p_value_fromtype($2);
1966 }
1967 ;
1968
1969ConstraintRangeSpec:
1970 TOK_TwoDots { $$ = ACT_EL_RANGE; }
1971 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
1972 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
1973 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
1974 ;
vlmfa67ddc2004-06-03 03:38:44 +00001975TableConstraint:
1976 SimpleTableConstraint {
1977 $$ = $1;
1978 }
1979 | ComponentRelationConstraint {
1980 $$ = $1;
1981 }
1982 ;
1983
1984/*
1985 * "{ExtensionSet}"
1986 */
1987SimpleTableConstraint:
1988 '{' TypeRefName '}' {
1989 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
1990 asn1p_constraint_t *ct;
1991 int ret;
1992 ret = asn1p_ref_add_component(ref, $2, 0);
1993 checkmem(ret == 0);
1994 ct = asn1p_constraint_new(yylineno);
1995 checkmem($$);
1996 ct->type = ACT_EL_VALUE;
1997 ct->value = asn1p_value_fromref(ref, 0);
vlm9fe7c922005-08-12 10:08:45 +00001998 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
vlmfa67ddc2004-06-03 03:38:44 +00001999 }
2000 ;
2001
2002ComponentRelationConstraint:
2003 SimpleTableConstraint '{' AtNotationList '}' {
vlm9fe7c922005-08-12 10:08:45 +00002004 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
vlmfa67ddc2004-06-03 03:38:44 +00002005 }
2006 ;
2007
2008AtNotationList:
2009 AtNotationElement {
2010 $$ = asn1p_constraint_new(yylineno);
2011 checkmem($$);
2012 $$->type = ACT_EL_VALUE;
2013 $$->value = asn1p_value_fromref($1, 0);
2014 }
2015 | AtNotationList ',' AtNotationElement {
2016 asn1p_constraint_t *ct;
2017 ct = asn1p_constraint_new(yylineno);
2018 checkmem(ct);
2019 ct->type = ACT_EL_VALUE;
2020 ct->value = asn1p_value_fromref($3, 0);
vlm9fe7c922005-08-12 10:08:45 +00002021 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
vlmfa67ddc2004-06-03 03:38:44 +00002022 }
2023 ;
2024
2025/*
2026 * @blah
2027 */
2028AtNotationElement:
2029 '@' ComponentIdList {
2030 char *p = malloc(strlen($2) + 2);
2031 int ret;
2032 *p = '@';
2033 strcpy(p + 1, $2);
2034 $$ = asn1p_ref_new(yylineno);
2035 ret = asn1p_ref_add_component($$, p, 0);
2036 checkmem(ret == 0);
2037 free(p);
2038 free($2);
2039 }
2040 | '@' '.' ComponentIdList {
2041 char *p = malloc(strlen($3) + 3);
2042 int ret;
2043 p[0] = '@';
2044 p[1] = '.';
2045 strcpy(p + 2, $3);
2046 $$ = asn1p_ref_new(yylineno);
2047 ret = asn1p_ref_add_component($$, p, 0);
2048 checkmem(ret == 0);
2049 free(p);
2050 free($3);
2051 }
2052 ;
2053
2054/* identifier "." ... */
2055ComponentIdList:
2056 Identifier {
2057 $$ = $1;
2058 }
2059 | ComponentIdList '.' Identifier {
2060 int l1 = strlen($1);
2061 int l3 = strlen($3);
2062 $$ = malloc(l1 + 1 + l3 + 1);
2063 memcpy($$, $1, l1);
2064 $$[l1] = '.';
2065 memcpy($$ + l1 + 1, $3, l3);
2066 $$[l1 + 1 + l3] = '\0';
2067 }
2068 ;
2069
2070
2071
2072/*
2073 * MARKERS
2074 */
2075
2076optMarker:
vlmc94e28f2004-09-15 11:59:51 +00002077 {
2078 $$.flags = EM_NOMARK;
2079 $$.default_value = 0;
2080 }
vlmfa67ddc2004-06-03 03:38:44 +00002081 | Marker { $$ = $1; }
2082 ;
2083
2084Marker:
2085 TOK_OPTIONAL {
vlm1ac75e72005-11-26 11:21:55 +00002086 $$.flags = EM_OPTIONAL | EM_INDIRECT;
vlmc94e28f2004-09-15 11:59:51 +00002087 $$.default_value = 0;
vlmfa67ddc2004-06-03 03:38:44 +00002088 }
vlmc94e28f2004-09-15 11:59:51 +00002089 | TOK_DEFAULT Value {
2090 $$.flags = EM_DEFAULT;
2091 $$.default_value = $2;
vlmfa67ddc2004-06-03 03:38:44 +00002092 }
2093 ;
2094
2095/*
2096 * Universal enumeration definition to use in INTEGER and ENUMERATED.
2097 * === EXAMPLE ===
2098 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
2099 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
2100 * === EOF ===
2101 */
2102/*
2103optUniverationDefinition:
2104 { $$ = 0; }
2105 | UniverationDefinition {
2106 $$ = $1;
2107 }
2108 ;
2109*/
2110
2111UniverationDefinition:
2112 '{' '}' {
vlm43c8ac52006-09-17 04:52:50 +00002113 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002114 checkmem($$);
2115 }
2116 | '{' UniverationList '}' {
2117 $$ = $2;
2118 }
2119 ;
2120
2121UniverationList:
2122 UniverationElement {
vlm43c8ac52006-09-17 04:52:50 +00002123 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002124 checkmem($$);
vlm6a02a8a2004-09-08 00:28:11 +00002125 asn1p_expr_add($$, $1);
vlmfa67ddc2004-06-03 03:38:44 +00002126 }
2127 | UniverationList ',' UniverationElement {
2128 $$ = $1;
vlm6a02a8a2004-09-08 00:28:11 +00002129 asn1p_expr_add($$, $3);
vlmfa67ddc2004-06-03 03:38:44 +00002130 }
2131 ;
2132
2133UniverationElement:
2134 Identifier {
vlm43c8ac52006-09-17 04:52:50 +00002135 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002136 checkmem($$);
2137 $$->expr_type = A1TC_UNIVERVAL;
2138 $$->meta_type = AMT_VALUE;
2139 $$->Identifier = $1;
2140 }
2141 | Identifier '(' SignedNumber ')' {
vlm43c8ac52006-09-17 04:52:50 +00002142 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002143 checkmem($$);
2144 $$->expr_type = A1TC_UNIVERVAL;
2145 $$->meta_type = AMT_VALUE;
2146 $$->Identifier = $1;
2147 $$->value = $3;
2148 }
2149 | Identifier '(' DefinedValue ')' {
vlm43c8ac52006-09-17 04:52:50 +00002150 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002151 checkmem($$);
2152 $$->expr_type = A1TC_UNIVERVAL;
2153 $$->meta_type = AMT_VALUE;
2154 $$->Identifier = $1;
2155 $$->value = $3;
2156 }
2157 | SignedNumber {
vlm43c8ac52006-09-17 04:52:50 +00002158 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002159 checkmem($$);
2160 $$->expr_type = A1TC_UNIVERVAL;
2161 $$->meta_type = AMT_VALUE;
2162 $$->value = $1;
2163 }
2164 | TOK_ThreeDots {
vlm43c8ac52006-09-17 04:52:50 +00002165 $$ = NEW_EXPR();
vlmfa67ddc2004-06-03 03:38:44 +00002166 checkmem($$);
2167 $$->Identifier = strdup("...");
2168 checkmem($$->Identifier);
2169 $$->expr_type = A1TC_EXTENSIBLE;
2170 $$->meta_type = AMT_VALUE;
2171 }
2172 ;
2173
2174SignedNumber:
2175 TOK_number {
2176 $$ = asn1p_value_fromint($1);
2177 checkmem($$);
2178 }
2179 | TOK_number_negative {
2180 $$ = asn1p_value_fromint($1);
2181 checkmem($$);
2182 }
2183 ;
2184
vlme745fcd2006-09-05 16:18:34 +00002185RealValue:
2186 SignedNumber
2187 | TOK_realnumber {
2188 $$ = asn1p_value_fromdouble($1);
2189 checkmem($$);
2190 }
2191 ;
2192
vlmfa67ddc2004-06-03 03:38:44 +00002193/*
2194 * SEQUENCE definition.
2195 * === EXAMPLE ===
2196 * Struct1 ::= SEQUENCE {
2197 * memb1 Struct2,
2198 * memb2 SEQUENCE OF {
2199 * memb2-1 Struct 3
2200 * }
2201 * }
2202 * === EOF ===
2203 */
2204
2205
2206
2207/*
2208 * SET definition.
2209 * === EXAMPLE ===
2210 * Person ::= SET {
2211 * name [0] PrintableString (SIZE(1..20)),
2212 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2213 * }
2214 * === EOF ===
2215 */
2216
2217optTag:
2218 { memset(&$$, 0, sizeof($$)); }
2219 | Tag { $$ = $1; }
2220 ;
2221
2222Tag:
vlm2728a8d2005-01-23 09:51:44 +00002223 TagTypeValue TagPlicit {
vlmfa67ddc2004-06-03 03:38:44 +00002224 $$ = $1;
vlm2728a8d2005-01-23 09:51:44 +00002225 $$.tag_mode = $2.tag_mode;
vlmfa67ddc2004-06-03 03:38:44 +00002226 }
vlm2728a8d2005-01-23 09:51:44 +00002227 ;
2228
2229TagTypeValue:
2230 '[' TagClass TOK_number ']' {
2231 $$ = $2;
2232 $$.tag_value = $3;
2233 };
2234
2235TagClass:
2236 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2237 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2238 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2239 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2240 ;
2241
2242TagPlicit:
2243 { $$.tag_mode = TM_DEFAULT; }
2244 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2245 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
vlmfa67ddc2004-06-03 03:38:44 +00002246 ;
2247
2248TypeRefName:
2249 TOK_typereference {
2250 checkmem($1);
2251 $$ = $1;
2252 }
vlm9283dbe2004-08-18 04:59:12 +00002253 | TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00002254 checkmem($1);
2255 $$ = $1;
2256 }
2257 ;
2258
vlm9283dbe2004-08-18 04:59:12 +00002259
vlmfa67ddc2004-06-03 03:38:44 +00002260ObjectClassReference:
vlm9283dbe2004-08-18 04:59:12 +00002261 TOK_capitalreference {
vlmfa67ddc2004-06-03 03:38:44 +00002262 checkmem($1);
2263 $$ = $1;
2264 }
2265 ;
2266
vlm151c0b22004-09-22 16:03:36 +00002267optIdentifier:
2268 { $$ = 0; }
2269 | Identifier {
2270 $$ = $1;
2271 }
vlma5b977d2005-06-06 08:28:58 +00002272 ;
vlm151c0b22004-09-22 16:03:36 +00002273
vlmfa67ddc2004-06-03 03:38:44 +00002274Identifier:
2275 TOK_identifier {
2276 checkmem($1);
2277 $$ = $1;
2278 }
2279 ;
2280
vlmfa67ddc2004-06-03 03:38:44 +00002281%%
2282
2283
2284/*
2285 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2286 */
2287static asn1p_value_t *
2288_convert_bitstring2binary(char *str, int base) {
2289 asn1p_value_t *val;
2290 int slen;
2291 int memlen;
2292 int baselen;
2293 int bits;
2294 uint8_t *binary_vector;
2295 uint8_t *bv_ptr;
2296 uint8_t cur_val;
2297
2298 assert(str);
2299 assert(str[0] == '\'');
2300
2301 switch(base) {
2302 case 'B':
2303 baselen = 1;
2304 break;
2305 case 'H':
2306 baselen = 4;
2307 break;
2308 default:
2309 assert(base == 'B' || base == 'H');
2310 errno = EINVAL;
2311 return NULL;
2312 }
2313
2314 slen = strlen(str);
2315 assert(str[slen - 1] == base);
2316 assert(str[slen - 2] == '\'');
2317
2318 memlen = slen / (8 / baselen); /* Conservative estimate */
2319
2320 bv_ptr = binary_vector = malloc(memlen + 1);
2321 if(bv_ptr == NULL)
2322 /* ENOMEM */
2323 return NULL;
2324
2325 cur_val = 0;
2326 bits = 0;
2327 while(*(++str) != '\'') {
2328 switch(baselen) {
2329 case 1:
2330 switch(*str) {
2331 case '1':
2332 cur_val |= 1 << (7 - (bits % 8));
2333 case '0':
2334 break;
2335 default:
2336 assert(!"_y UNREACH1");
2337 case ' ': case '\r': case '\n':
2338 continue;
2339 }
2340 break;
2341 case 4:
2342 switch(*str) {
2343 case '0': case '1': case '2': case '3': case '4':
2344 case '5': case '6': case '7': case '8': case '9':
2345 cur_val |= (*str - '0') << (4 - (bits % 8));
2346 break;
2347 case 'A': case 'B': case 'C':
2348 case 'D': case 'E': case 'F':
2349 cur_val |= ((*str - 'A') + 10)
2350 << (4 - (bits % 8));
2351 break;
2352 default:
2353 assert(!"_y UNREACH2");
2354 case ' ': case '\r': case '\n':
2355 continue;
2356 }
2357 break;
2358 }
2359
2360 bits += baselen;
2361 if((bits % 8) == 0) {
2362 *bv_ptr++ = cur_val;
2363 cur_val = 0;
2364 }
2365 }
2366
2367 *bv_ptr = cur_val;
2368 assert((bv_ptr - binary_vector) <= memlen);
2369
2370 val = asn1p_value_frombits(binary_vector, bits, 0);
2371 if(val == NULL) {
2372 free(binary_vector);
2373 }
2374
2375 return val;
2376}
2377
vlm5d89c3d2005-08-13 09:07:11 +00002378/*
2379 * For unnamed types (used in old X.208 compliant modules)
2380 * generate some sort of interim names, to not to force human being to fix
2381 * the specification's compliance to modern ASN.1 standards.
2382 */
2383static void
2384_fixup_anonymous_identifier(asn1p_expr_t *expr) {
2385 char *p;
2386 assert(expr->Identifier == 0);
2387
2388 /*
2389 * Try to figure out the type name
2390 * without going too much into details
2391 */
2392 expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type);
2393 if(expr->reference && expr->reference->comp_count > 0)
2394 expr->Identifier = expr->reference->components[0].name;
2395
2396 fprintf(stderr,
2397 "WARNING: Line %d: expected lower-case member identifier, "
2398 "found an unnamed %s.\n"
2399 "WARNING: Obsolete X.208 syntax detected, "
2400 "please give the member a name.\n",
2401 yylineno, expr->Identifier ? expr->Identifier : "type");
2402
2403 if(!expr->Identifier)
2404 expr->Identifier = "unnamed";
2405 expr->Identifier = strdup(expr->Identifier);
2406 assert(expr->Identifier);
2407 /* Make a lowercase identifier from the type name */
2408 for(p = expr->Identifier; *p; p++) {
2409 switch(*p) {
2410 case 'A' ... 'Z': *p += 32; break;
2411 case ' ': *p = '_'; break;
2412 case '-': *p = '_'; break;
2413 }
2414 }
2415 fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". "
2416 "Name clash may occur later.\n",
2417 expr->Identifier);
2418}
2419
vlmfa67ddc2004-06-03 03:38:44 +00002420int
2421yyerror(const char *msg) {
vlm808411d2006-03-14 16:31:37 +00002422 extern char *asn1p_text;
vlmfa67ddc2004-06-03 03:38:44 +00002423 fprintf(stderr,
2424 "ASN.1 grammar parse error "
2425 "near line %d (token \"%s\"): %s\n",
vlm39e5ed72004-09-05 10:40:41 +00002426 yylineno, asn1p_text, msg);
vlmfa67ddc2004-06-03 03:38:44 +00002427 return -1;
2428}
2429