10 #include "asn1parser.h"
12 #define YYPARSE_PARAM param
13 #define YYPARSE_PARAM_TYPE void **
14 #define YYERROR_VERBOSE
16 #define YYFPRINTF prefixed_fprintf
19 * Prefix parser debug with "PARSER: " for easier human eye scanning.
22 __attribute__((format(printf, 2, 3)))
23 prefixed_fprintf(FILE *f, const char *fmt, ...) {
24 static int line_ended = 1;
28 fprintf(f, "PARSER: ");
31 size_t len = strlen(fmt);
32 if(len && fmt[len-1] == '\n') {
35 int ret = vfprintf(f, fmt, ap);
41 static int yyerror(const char *msg);
44 int yyparse(void **param); /* byacc does not produce a prototype */
46 void asn1p_lexer_hack_push_opaque_state(void);
47 void asn1p_lexer_hack_enable_with_syntax(void);
48 void asn1p_lexer_hack_push_encoding_control(void);
49 #define yylineno asn1p_lineno
50 extern int asn1p_lineno;
51 const char *asn1p_parse_debug_filename;
52 #define ASN_FILENAME asn1p_parse_debug_filename
55 * Process directives as <ASN1C:RepresentAsPointer>
57 extern int asn1p_as_pointer;
60 * This temporary variable is used to solve the shortcomings of 1-lookahead
63 static struct AssignedIdentifier *saved_aid;
65 static asn1p_value_t *_convert_bitstring2binary(char *str, int base);
66 static void _fixup_anonymous_identifier(asn1p_expr_t *expr);
68 static asn1p_module_t *currentModule;
69 #define NEW_EXPR() (asn1p_expr_new(yylineno, currentModule))
71 #define checkmem(ptr) do { \
73 return yyerror("Memory failure"); \
76 #define CONSTRAINT_INSERT(root, constr_type, arg1, arg2) do { \
77 if(arg1->type != constr_type) { \
79 root = asn1p_constraint_new(yylineno, currentModule); \
81 root->type = constr_type; \
82 __ret = asn1p_constraint_insert(root, \
84 checkmem(__ret == 0); \
90 = asn1p_constraint_insert(root, arg2); \
91 checkmem(__ret == 0); \
96 #error AL_IMPORT DEFINED ELSEWHERE!
98 #define AL_IMPORT(to, where, from, field) \
101 while(TQ_FIRST(&((from)->where))) { \
102 TQ_ADD(&((to)->where), TQ_REMOVE(&((from)->where), field), field); \
104 assert(TQ_FIRST(&((from)->where)) == 0); \
111 * Token value definition.
112 * a_*: ASN-specific types.
113 * tv_*: Locally meaningful types.
117 asn1p_module_flags_e a_module_flags;
118 asn1p_module_t *a_module;
119 asn1p_expr_type_e a_type; /* ASN.1 Type */
120 asn1p_expr_t *a_expr; /* Constructed collection */
121 asn1p_constraint_t *a_constr; /* Constraint */
122 enum asn1p_constraint_type_e a_ctype;/* Constraint type */
123 asn1p_xports_t *a_xports; /* IMports/EXports */
124 struct AssignedIdentifier a_aid; /* Assigned Identifier */
125 asn1p_oid_t *a_oid; /* Object Identifier */
126 asn1p_oid_arc_t a_oid_arc; /* Single OID's arc */
127 struct asn1p_type_tag_s a_tag; /* A tag */
128 asn1p_ref_t *a_ref; /* Reference to custom type */
129 asn1p_wsyntx_t *a_wsynt; /* WITH SYNTAX contents */
130 asn1p_wsyntx_chunk_t *a_wchunk; /* WITH SYNTAX chunk */
131 struct asn1p_ref_component_s a_refcomp; /* Component of a reference */
132 asn1p_value_t *a_value; /* Number, DefinedValue, etc */
133 struct asn1p_param_s a_parg; /* A parameter argument */
134 asn1p_paramlist_t *a_plist; /* A pargs list */
135 struct asn1p_expr_marker_s a_marker; /* OPTIONAL/DEFAULT */
136 enum asn1p_constr_pres_e a_pres; /* PRESENT/ABSENT/OPTIONAL */
137 asn1c_integer_t a_int;
146 struct asn1p_type_tag_s tag;
151 * Token types returned by scanner.
153 %token TOK_PPEQ /* "::=", Pseudo Pascal EQuality */
154 %token TOK_VBracketLeft TOK_VBracketRight /* "[[", "]]" */
155 %token <tv_opaque> TOK_whitespace /* A span of whitespace */
156 %token <tv_opaque> TOK_opaque /* opaque data (driven from .y) */
157 %token <tv_str> TOK_bstring
158 %token <tv_opaque> TOK_cstring
159 %token <tv_str> TOK_hstring
160 %token <tv_str> TOK_identifier "identifier"
161 %token <a_int> TOK_number "number"
162 %token <a_int> TOK_number_negative "negative number"
163 %token <a_dbl> TOK_realnumber
164 %token <a_int> TOK_tuple
165 %token <a_int> TOK_quadruple
166 %token <tv_str> TOK_typereference
167 %token <tv_str> TOK_capitalreference /* "CLASS1" */
168 %token <tv_str> TOK_typefieldreference /* "&Pork" */
169 %token <tv_str> TOK_valuefieldreference /* "&id" */
170 %token <tv_str> TOK_Literal /* "BY" */
173 * Tokens available with asn1p_lexer_hack_push_extended_values().
175 %token TOK_ExtValue_BIT_STRING
178 * Token types representing ASN.1 standard keywords.
181 %token TOK_ABSTRACT_SYNTAX
184 %token TOK_APPLICATION
195 %token TOK_COMPONENTS
196 %token TOK_CONSTRAINED
197 %token TOK_CONTAINING
199 %token TOK_DEFINITIONS
203 %token TOK_ENCODING_CONTROL
205 %token TOK_ENUMERATED
208 %token TOK_EXTENSIBILITY
212 %token TOK_GeneralizedTime
213 %token TOK_GeneralString
214 %token TOK_GraphicString
216 %token TOK_IDENTIFIER
222 %token TOK_INSTRUCTIONS
224 %token TOK_ISO646String
227 %token TOK_MINUS_INFINITY
229 %token TOK_NumericString
231 %token TOK_ObjectDescriptor
237 %token TOK_PLUS_INFINITY
239 %token TOK_PrintableString
242 %token TOK_RELATIVE_OID
250 %token TOK_TeletexString
252 %token TOK_TYPE_IDENTIFIER
255 %token TOK_UniversalString
257 %token TOK_UTF8String
258 %token TOK_VideotexString
259 %token TOK_VisibleString
261 %token UTF8_BOM "UTF-8 byte order mark"
264 %left '^' TOK_INTERSECTION
268 %token TOK_TwoDots ".."
269 %token TOK_ThreeDots "..."
273 * Types defined herein.
275 %type <a_grammar> ModuleList
276 %type <a_module> ModuleDefinition
277 %type <a_module> ModuleBody
278 %type <a_module> AssignmentList
279 %type <a_module> Assignment
280 %type <a_module> optModuleBody /* Optional */
281 %type <a_module_flags> optModuleDefinitionFlags
282 %type <a_module_flags> ModuleDefinitionFlags /* Set of FL */
283 %type <a_module_flags> ModuleDefinitionFlag /* Single FL */
284 %type <a_module> optImports
285 %type <a_module> optExports
286 %type <a_module> ImportsDefinition
287 %type <a_module> optImportsBundleSet
288 %type <a_module> ImportsBundleSet
289 %type <a_xports> ImportsBundle
290 %type <a_xports> ImportsList
291 %type <a_xports> ExportsDefinition
292 %type <a_xports> ExportsBody
293 %type <a_expr> ImportsElement
294 %type <a_expr> ExportsElement
295 %type <a_expr> ExtensionAndException
297 %type <a_expr> TaggedType
298 %type <a_expr> MaybeIndirectTaggedType
299 %type <a_expr> UntaggedType
300 %type <a_expr> DefinedUntaggedType
301 %type <a_expr> ConcreteTypeDeclaration "concrete TypeDeclaration"
302 %type <a_expr> TypeDeclaration
303 %type <a_expr> MaybeIndirectTypeDeclaration
304 %type <a_ref> ComplexTypeReference
305 %type <a_ref> ComplexTypeReferenceAmpList
306 %type <a_refcomp> ComplexTypeReferenceElement
307 %type <a_refcomp> PrimitiveFieldReference
308 %type <a_expr> FieldSpec
309 %type <a_ref> FieldName
310 %type <a_ref> DefinedObjectClass
311 %type <a_expr> ClassField
312 %type <a_expr> ObjectClass
313 %type <a_expr> DataTypeReference /* Type1 ::= Type2 */
314 %type <a_expr> DefinedType
315 %type <a_constr> ValueSet /* {a|b|c}*/
316 %type <a_expr> ValueSetTypeAssignment /* Val INTEGER ::= {1|2} */
317 %type <a_expr> ValueAssignment /* val INTEGER ::= 1*/
318 %type <a_value> Value
319 %type <a_value> SimpleValue
320 %type <a_value> DefinedValue
321 %type <a_value> SignedNumber
322 %type <a_value> RealValue
323 %type <a_value> BitStringValue
324 %type <a_expr> optComponentTypeLists
325 %type <a_expr> ComponentTypeLists
326 %type <a_expr> ComponentType
327 %type <a_expr> AlternativeTypeLists
328 %type <a_expr> AlternativeType
329 %type <a_expr> UniverationList
330 %type <a_expr> Enumerations
331 %type <a_expr> NamedBitList
332 %type <a_expr> NamedBit
333 %type <a_expr> NamedNumberList
334 %type <a_expr> NamedNumber
335 %type <a_expr> IdentifierList
336 %type <a_expr> IdentifierElement
337 %type <a_expr> UniverationElement
338 %type <tv_str> TypeRefName
339 %type <tv_str> Identifier
340 %type <a_ref> IdentifierAsReference
341 %type <a_value> IdentifierAsValue
342 %type <tv_str> optIdentifier
343 %type <a_parg> ParameterArgumentName
344 %type <a_plist> ParameterArgumentList
345 %type <a_expr> ActualParameter
346 %type <a_expr> ActualParameterList
347 %type <a_aid> AssignedIdentifier /* OID/DefinedValue */
348 %type <a_oid> ObjectIdentifier /* OID */
349 %type <a_oid> optObjectIdentifier /* Optional OID */
350 %type <a_oid> ObjectIdentifierBody
351 %type <a_oid_arc> ObjectIdentifierElement
352 %type <a_expr> BuiltinType
353 %type <a_type> BasicTypeId
354 %type <a_type> BasicTypeId_UniverationCompatible
355 %type <a_type> BasicString
356 %type <tv_opaque> Opaque
357 %type <tv_opaque> OpaqueFirstToken
358 %type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
359 %type <a_tag> TagClass TagTypeValue TagPlicit
360 %type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
361 %type <a_constr> optConstraint
362 %type <a_constr> optManyConstraints /* Only for Type */
363 %type <a_constr> ManyConstraints
364 %type <a_constr> optSizeOrConstraint
365 %type <a_constr> Constraint
366 %type <a_constr> PermittedAlphabet
367 %type <a_constr> SizeConstraint
368 %type <a_constr> SingleTypeConstraint
369 %type <a_constr> MultipleTypeConstraints
370 %type <a_constr> NamedConstraint
371 %type <a_constr> FullSpecification
372 %type <a_constr> PartialSpecification
373 %type <a_constr> TypeConstraints
374 %type <a_constr> ConstraintSpec
375 %type <a_constr> SubtypeConstraint
376 %type <a_constr> GeneralConstraint
377 %type <a_constr> ElementSetSpecs /* 1..2,...,3 */
378 %type <a_constr> ElementSetSpec /* 1..2 */
379 %type <a_constr> Unions
380 %type <a_constr> Intersections
381 %type <a_constr> IntersectionElements
382 %type <a_constr> Elements
383 %type <a_constr> SubtypeElements /* 1..2 */
384 %type <a_constr> SimpleTableConstraint
385 %type <a_constr> UserDefinedConstraint
386 %type <a_constr> TableConstraint
387 %type <a_constr> ContentsConstraint
388 %type <a_constr> PatternConstraint
389 %type <a_constr> InnerTypeConstraints
390 %type <a_constr> ValueRange
391 %type <a_constr> ComponentRelationConstraint
392 %type <a_constr> AtNotationList
393 %type <a_ref> AtNotationElement
394 %type <a_value> SingleValue
395 %type <a_value> LowerEndValue
396 %type <a_value> UpperEndValue
397 %type <a_value> ContainedSubtype
398 %type <a_ctype> ConstraintRangeSpec
399 %type <a_value> RestrictedCharacterStringValue
400 %type <a_wsynt> optWithSyntax
401 %type <a_wsynt> WithSyntax
402 %type <a_wsynt> WithSyntaxList
403 %type <a_wchunk> WithSyntaxToken
404 %type <a_marker> optMarker Marker
405 %type <a_int> optUNIQUE
406 %type <a_pres> optPresenceConstraint PresenceConstraint
407 %type <tv_str> ComponentIdList
408 %type <a_int> NSTD_IndirectMarker
414 UTF8_BOM ModuleList {
415 *(void **)param = $2;
418 *(void **)param = $1;
426 TQ_ADD(&($$->modules), $1, mod_next);
428 | ModuleList ModuleDefinition {
430 TQ_ADD(&($$->modules), $2, mod_next);
435 * ASN module definition.
437 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
445 TypeRefName { currentModule = asn1p_module_new(); }
446 optObjectIdentifier TOK_DEFINITIONS
447 optModuleDefinitionFlags
455 asn1p_module_t tmp = *($$);
458 asn1p_module_free($8);
460 /* There's a chance that a module is just plain empty */
465 $$->module_flags = $5;
470 * Object Identifier Definition
471 * { iso member-body(2) 3 }
475 | ObjectIdentifier { $$ = $1; }
479 '{' ObjectIdentifierBody '}' {
487 ObjectIdentifierBody:
488 ObjectIdentifierElement {
489 $$ = asn1p_oid_new();
490 asn1p_oid_add_arc($$, &$1);
494 | ObjectIdentifierBody ObjectIdentifierElement {
496 asn1p_oid_add_arc($$, &$2);
502 ObjectIdentifierElement:
503 Identifier { /* iso */
507 | Identifier '(' TOK_number ')' { /* iso(1) */
511 | TOK_number { /* 1 */
518 * Optional module flags.
520 optModuleDefinitionFlags:
521 { $$ = MSF_NOFLAGS; }
522 | ModuleDefinitionFlags {
530 ModuleDefinitionFlags:
531 ModuleDefinitionFlag {
534 | ModuleDefinitionFlags ModuleDefinitionFlag {
540 * Single module flag.
542 ModuleDefinitionFlag:
543 TOK_EXPLICIT TOK_TAGS {
544 $$ = MSF_EXPLICIT_TAGS;
546 | TOK_IMPLICIT TOK_TAGS {
547 $$ = MSF_IMPLICIT_TAGS;
549 | TOK_AUTOMATIC TOK_TAGS {
550 $$ = MSF_AUTOMATIC_TAGS;
552 | TOK_EXTENSIBILITY TOK_IMPLIED {
553 $$ = MSF_EXTENSIBILITY_IMPLIED;
555 /* EncodingReferenceDefault */
556 | TOK_capitalreference TOK_INSTRUCTIONS {
557 /* X.680Amd1 specifies TAG and XER */
558 if(strcmp($1, "TAG") == 0) {
559 $$ = MSF_TAG_INSTRUCTIONS;
560 } else if(strcmp($1, "XER") == 0) {
561 $$ = MSF_XER_INSTRUCTIONS;
564 "WARNING: %s INSTRUCTIONS at %s:%d: "
565 "Unrecognized encoding reference\n",
566 $1, ASN_FILENAME, yylineno);
567 $$ = MSF_unk_INSTRUCTIONS;
574 * Optional module body.
587 optExports optImports AssignmentList {
588 $$ = asn1p_module_new();
589 AL_IMPORT($$, exports, $1, xp_next);
590 AL_IMPORT($$, imports, $2, xp_next);
591 asn1p_module_move_members($$, $3);
593 asn1p_module_free($1);
594 asn1p_module_free($2);
595 asn1p_module_free($3);
603 | AssignmentList Assignment {
610 asn1p_module_move_members($$, $2);
611 asn1p_module_free($2);
617 * One of the elements of ASN.1 module specification.
621 $$ = asn1p_module_new();
623 assert($1->expr_type != A1TC_INVALID);
624 assert($1->meta_type != AMT_INVALID);
625 asn1p_module_member_add($$, $1);
628 $$ = asn1p_module_new();
630 assert($1->expr_type != A1TC_INVALID);
631 assert($1->meta_type != AMT_INVALID);
632 asn1p_module_member_add($$, $1);
635 * Value set definition
637 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
639 * Also ObjectClassSet.
641 | ValueSetTypeAssignment {
642 $$ = asn1p_module_new();
644 assert($1->expr_type != A1TC_INVALID);
645 assert($1->meta_type != AMT_INVALID);
646 asn1p_module_member_add($$, $1);
648 | TOK_ENCODING_CONTROL TOK_capitalreference
649 { asn1p_lexer_hack_push_encoding_control(); }
652 "WARNING: ENCODING-CONTROL %s "
653 "specification at %s:%d ignored\n",
654 $2, ASN_FILENAME, yylineno);
664 "Attempt to redefine a standard basic string type, "
665 "please comment out or remove this type redefinition.");
671 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
679 TOK_IMPORTS optImportsBundleSet ';' {
681 return yyerror("Unterminated IMPORTS FROM, "
682 "expected semicolon ';'");
689 | TOK_IMPORTS TOK_FROM /* ... */ {
690 return yyerror("Empty IMPORTS list");
695 { $$ = asn1p_module_new(); }
700 $$ = asn1p_module_new();
702 TQ_ADD(&($$->imports), $1, xp_next);
704 | ImportsBundleSet ImportsBundle {
706 TQ_ADD(&($$->imports), $2, xp_next);
711 { memset(&$$, 0, sizeof($$)); }
712 | ObjectIdentifier { $$.oid = $1; };
713 /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
716 ImportsList TOK_FROM TypeRefName AssignedIdentifier {
718 $$->fromModuleName = $3;
720 /* This stupid thing is used for look-back hack. */
721 saved_aid = $$->identifier.oid ? 0 : &($$->identifier);
728 $$ = asn1p_xports_new();
730 TQ_ADD(&($$->xp_members), $1, next);
732 | ImportsList ',' ImportsElement {
734 TQ_ADD(&($$->xp_members), $3, next);
743 $$->expr_type = A1TC_REFERENCE;
745 | TypeRefName '{' '}' { /* Completely equivalent to above */
749 $$->expr_type = A1TC_REFERENCE;
755 $$->expr_type = A1TC_REFERENCE;
762 | ExportsDefinition {
763 $$ = asn1p_module_new();
766 TQ_ADD(&($$->exports), $1, xp_next);
774 TOK_EXPORTS ExportsBody ';' {
777 | TOK_EXPORTS TOK_ALL ';' {
781 /* Empty EXPORTS clause effectively prohibits export. */
782 $$ = asn1p_xports_new();
789 $$ = asn1p_xports_new();
791 TQ_ADD(&($$->xp_members), $1, next);
793 | ExportsBody ',' ExportsElement {
795 TQ_ADD(&($$->xp_members), $3, next);
804 $$->expr_type = A1TC_EXPORTVAR;
806 | TypeRefName '{' '}' {
810 $$->expr_type = A1TC_EXPORTVAR;
816 $$->expr_type = A1TC_EXPORTVAR;
821 ValueSet: '{' ElementSetSpecs '}' { $$ = $2; };
823 ValueSetTypeAssignment:
824 TypeRefName Type TOK_PPEQ ValueSet {
826 assert($$->Identifier == 0);
828 $$->meta_type = AMT_VALUESET;
829 $$->constraints = $4;
835 * A DefinedType reference.
840 * "Module.identifier"
844 ComplexTypeReference {
848 $$->expr_type = A1TC_REFERENCE;
849 $$->meta_type = AMT_TYPEREF;
852 * A parameterized assignment.
854 | ComplexTypeReference '{' ActualParameterList '}' {
859 $$->expr_type = A1TC_REFERENCE;
860 $$->meta_type = AMT_TYPEREF;
865 * Data Type Reference.
867 * Type3 ::= CHOICE { a Type1, b Type 2 }
872 * Optionally tagged type definition.
874 TypeRefName TOK_PPEQ Type {
877 assert($$->expr_type);
878 assert($$->meta_type);
880 | TypeRefName TOK_PPEQ ObjectClass {
883 assert($$->expr_type == A1TC_CLASSDEF);
884 assert($$->meta_type == AMT_OBJECTCLASS);
887 * Parameterized <Type> declaration:
889 * SIGNED { ToBeSigned } ::= SEQUENCE {
890 * toBeSigned ToBeSigned,
891 * algorithm AlgorithmIdentifier,
892 * signature BIT STRING
896 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
901 /* Parameterized CLASS declaration */
902 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ ObjectClass {
909 ParameterArgumentList:
910 ParameterArgumentName {
912 $$ = asn1p_paramlist_new(yylineno);
914 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
916 asn1p_ref_free($1.governor);
919 | ParameterArgumentList ',' ParameterArgumentName {
922 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
924 asn1p_ref_free($3.governor);
929 ParameterArgumentName:
934 | TypeRefName ':' Identifier {
936 $$.governor = asn1p_ref_new(yylineno, currentModule);
937 ret = asn1p_ref_add_component($$.governor, $1, 0);
942 | TypeRefName ':' TypeRefName {
944 $$.governor = asn1p_ref_new(yylineno, currentModule);
945 ret = asn1p_ref_add_component($$.governor, $1, 0);
950 | BasicTypeId ':' Identifier {
952 $$.governor = asn1p_ref_new(yylineno, currentModule);
953 ret = asn1p_ref_add_component($$.governor,
954 ASN_EXPR_TYPE2STR($1), 1);
958 | BasicTypeId ':' TypeRefName {
960 $$.governor = asn1p_ref_new(yylineno, currentModule);
961 ret = asn1p_ref_add_component($$.governor,
962 ASN_EXPR_TYPE2STR($1), 1);
972 asn1p_expr_add($$, $1);
974 | ActualParameterList ',' ActualParameter {
976 asn1p_expr_add($$, $3);
981 UntaggedType /* act. Type */
985 $$->Identifier = strdup("?");
986 $$->expr_type = A1TC_REFERENCE;
987 $$->meta_type = AMT_VALUE;
993 $$->Identifier = strdup("?");
994 $$->expr_type = A1TC_REFERENCE;
995 $$->meta_type = AMT_VALUE;
1000 $$->expr_type = A1TC_VALUESET;
1001 $$->meta_type = AMT_VALUESET;
1002 $$->constraints = $1;
1007 | '{' ActualParameter '}' {
1010 asn1p_expr_add($$, $2);
1011 $$->expr_type = A1TC_PARAMETRIZED;
1012 $$->meta_type = AMT_TYPE;
1018 * A collection of constructed data type members.
1020 optComponentTypeLists:
1021 { $$ = NEW_EXPR(); }
1022 | ComponentTypeLists { $$ = $1; };
1028 asn1p_expr_add($$, $1);
1030 | ComponentTypeLists ',' ComponentType {
1032 asn1p_expr_add($$, $3);
1034 | ComponentTypeLists ',' TOK_VBracketLeft ComponentTypeLists TOK_VBracketRight {
1036 $4->meta_type = AMT_TYPE;
1037 $4->expr_type = ASN_CONSTR_SEQUENCE;
1038 $4->marker.flags |= EM_OPTIONAL;
1039 asn1p_expr_add($$, $4);
1044 Identifier MaybeIndirectTaggedType optMarker {
1046 assert($$->Identifier == 0);
1047 $$->Identifier = $1;
1048 $3.flags |= $$->marker.flags;
1051 | MaybeIndirectTaggedType optMarker {
1053 $2.flags |= $$->marker.flags;
1055 _fixup_anonymous_identifier($$);
1057 | TOK_COMPONENTS TOK_OF MaybeIndirectTaggedType {
1060 $$->meta_type = $3->meta_type;
1061 $$->expr_type = A1TC_COMPONENTS_OF;
1062 asn1p_expr_add($$, $3);
1064 | ExtensionAndException {
1069 AlternativeTypeLists:
1073 asn1p_expr_add($$, $1);
1075 | AlternativeTypeLists ',' AlternativeType {
1077 asn1p_expr_add($$, $3);
1082 Identifier MaybeIndirectTaggedType {
1084 assert($$->Identifier == 0);
1085 $$->Identifier = $1;
1087 | ExtensionAndException {
1090 | MaybeIndirectTaggedType {
1092 _fixup_anonymous_identifier($$);
1097 TOK_CLASS '{' FieldSpec '}' optWithSyntax {
1100 $$->with_syntax = $5;
1101 assert($$->expr_type == A1TC_CLASSDEF);
1102 assert($$->meta_type == AMT_OBJECTCLASS);
1108 | TOK_UNIQUE { $$ = 1; }
1115 $$->expr_type = A1TC_CLASSDEF;
1116 $$->meta_type = AMT_OBJECTCLASS;
1117 asn1p_expr_add($$, $1);
1119 | FieldSpec ',' ClassField {
1121 asn1p_expr_add($$, $3);
1128 /* TypeFieldSpec ::= typefieldreference TypeOptionalitySpec? */
1129 TOK_typefieldreference optMarker {
1132 $$->Identifier = $1;
1133 $$->meta_type = AMT_OBJECTFIELD;
1134 $$->expr_type = A1TC_CLASSFIELD_TFS; /* TypeFieldSpec */
1138 /* FixedTypeValueFieldSpec ::= valuefieldreference Type UNIQUE ? ValueOptionalitySpec ? */
1139 | TOK_valuefieldreference Type optUNIQUE optMarker {
1141 $$->Identifier = $1;
1142 $$->meta_type = AMT_OBJECTFIELD;
1143 $$->expr_type = A1TC_CLASSFIELD_FTVFS; /* FixedTypeValueFieldSpec */
1146 asn1p_expr_add($$, $2);
1149 /* VariableTypeValueFieldSpec ::= valuefieldreference FieldName ValueOptionalitySpec ? */
1150 | TOK_valuefieldreference FieldName optMarker {
1152 $$->Identifier = $1;
1153 $$->meta_type = AMT_OBJECTFIELD;
1154 $$->expr_type = A1TC_CLASSFIELD_VTVFS;
1159 /* ObjectFieldSpec ::= objectfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1160 | TOK_valuefieldreference DefinedObjectClass optMarker {
1163 $$->Identifier = $1;
1165 $$->meta_type = AMT_OBJECTFIELD;
1166 $$->expr_type = A1TC_CLASSFIELD_OFS;
1170 /* VariableTypeValueSetFieldSpec ::= valuesetfieldreference FieldName ValueOptionalitySpec ? */
1171 | TOK_typefieldreference FieldName optMarker {
1173 $$->Identifier = $1;
1174 $$->meta_type = AMT_OBJECTFIELD;
1175 $$->expr_type = A1TC_CLASSFIELD_VTVSFS;
1180 /* FixedTypeValueSetFieldSpec ::= valuesetfieldreference Type ValueSetOptionalitySpec ? */
1181 | TOK_typefieldreference Type optMarker {
1184 $$->Identifier = $1;
1185 $$->meta_type = AMT_OBJECTFIELD;
1186 $$->expr_type = A1TC_CLASSFIELD_FTVSFS;
1187 asn1p_expr_add($$, $2);
1191 /* ObjectSetFieldSpec ::= objectsetfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1192 | TOK_typefieldreference DefinedObjectClass optMarker {
1195 $$->Identifier = $1;
1197 $$->meta_type = AMT_OBJECTFIELD;
1198 $$->expr_type = A1TC_CLASSFIELD_OSFS;
1211 TOK_WITH TOK_SYNTAX '{'
1212 { asn1p_lexer_hack_enable_with_syntax(); }
1221 $$ = asn1p_wsyntx_new();
1222 TQ_ADD(&($$->chunks), $1, next);
1224 | WithSyntaxList WithSyntaxToken {
1226 TQ_ADD(&($$->chunks), $2, next);
1232 $$ = asn1p_wsyntx_chunk_fromstring($1.buf, 0);
1233 $$->type = WC_WHITESPACE;
1236 $$ = asn1p_wsyntx_chunk_fromstring($1, 0);
1238 | PrimitiveFieldReference {
1239 $$ = asn1p_wsyntx_chunk_fromstring($1.name, 0);
1240 $$->type = WC_FIELD;
1242 | '[' WithSyntaxList ']' {
1243 $$ = asn1p_wsyntx_chunk_fromsyntax($2);
1247 ExtensionAndException:
1251 $$->Identifier = strdup("...");
1252 checkmem($$->Identifier);
1253 $$->expr_type = A1TC_EXTENSIBLE;
1254 $$->meta_type = AMT_TYPE;
1256 | TOK_ThreeDots '!' DefinedValue {
1259 $$->Identifier = strdup("...");
1260 checkmem($$->Identifier);
1262 $$->expr_type = A1TC_EXTENSIBLE;
1263 $$->meta_type = AMT_TYPE;
1265 | TOK_ThreeDots '!' SignedNumber {
1268 $$->Identifier = strdup("...");
1270 checkmem($$->Identifier);
1271 $$->expr_type = A1TC_EXTENSIBLE;
1272 $$->meta_type = AMT_TYPE;
1279 optTag UntaggedType {
1285 DefinedUntaggedType:
1286 DefinedType optManyConstraints {
1289 * Outer constraint for SEQUENCE OF and SET OF applies
1290 * to the inner type.
1292 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1293 || $$->expr_type == ASN_CONSTR_SET_OF) {
1294 assert(!TQ_FIRST(&($$->members))->constraints);
1295 TQ_FIRST(&($$->members))->constraints = $2;
1297 if($$->constraints) {
1299 /* Check this : optManyConstraints is not used ?! */
1300 asn1p_constraint_free($2);
1302 $$->constraints = $2;
1309 TypeDeclaration optManyConstraints {
1312 * Outer constraint for SEQUENCE OF and SET OF applies
1313 * to the inner type.
1315 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1316 || $$->expr_type == ASN_CONSTR_SET_OF) {
1317 assert(!TQ_FIRST(&($$->members))->constraints);
1318 TQ_FIRST(&($$->members))->constraints = $2;
1320 if($$->constraints) {
1322 /* Check this : optManyConstraints is not used ?! */
1323 asn1p_constraint_free($2);
1325 $$->constraints = $2;
1331 MaybeIndirectTaggedType:
1332 optTag MaybeIndirectTypeDeclaration optManyConstraints {
1336 * Outer constraint for SEQUENCE OF and SET OF applies
1337 * to the inner type.
1339 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1340 || $$->expr_type == ASN_CONSTR_SET_OF) {
1341 assert(!TQ_FIRST(&($$->members))->constraints);
1342 TQ_FIRST(&($$->members))->constraints = $3;
1344 if($$->constraints) {
1346 /* Check this : optManyConstraints is not used ?! */
1347 asn1p_constraint_free($3);
1349 $$->constraints = $3;
1355 NSTD_IndirectMarker:
1357 $$ = asn1p_as_pointer ? EM_INDIRECT : 0;
1358 asn1p_as_pointer = 0;
1362 MaybeIndirectTypeDeclaration:
1363 NSTD_IndirectMarker TypeDeclaration {
1365 $$->marker.flags |= $1;
1367 if(($$->marker.flags & EM_INDIRECT)
1368 && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
1370 "INFO: Directive <ASN1C:RepresentAsPointer> "
1371 "applied to %s at %s:%d\n",
1372 ASN_EXPR_TYPE2STR($$->expr_type)
1373 ? ASN_EXPR_TYPE2STR($$->expr_type)
1375 ASN_FILENAME, $$->_lineno
1382 ConcreteTypeDeclaration
1385 ConcreteTypeDeclaration:
1387 | TOK_CHOICE '{' AlternativeTypeLists '}' {
1389 assert($$->expr_type == A1TC_INVALID);
1390 $$->expr_type = ASN_CONSTR_CHOICE;
1391 $$->meta_type = AMT_TYPE;
1393 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
1395 assert($$->expr_type == A1TC_INVALID);
1396 $$->expr_type = ASN_CONSTR_SEQUENCE;
1397 $$->meta_type = AMT_TYPE;
1399 | TOK_SET '{' optComponentTypeLists '}' {
1401 assert($$->expr_type == A1TC_INVALID);
1402 $$->expr_type = ASN_CONSTR_SET;
1403 $$->meta_type = AMT_TYPE;
1405 | TOK_SEQUENCE optSizeOrConstraint TOK_OF optIdentifier optTag MaybeIndirectTypeDeclaration {
1408 $$->constraints = $2;
1409 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1410 $$->meta_type = AMT_TYPE;
1411 $6->Identifier = $4;
1413 asn1p_expr_add($$, $6);
1415 | TOK_SET optSizeOrConstraint TOK_OF optIdentifier optTag MaybeIndirectTypeDeclaration {
1418 $$->constraints = $2;
1419 $$->expr_type = ASN_CONSTR_SET_OF;
1420 $$->meta_type = AMT_TYPE;
1421 $6->Identifier = $4;
1423 asn1p_expr_add($$, $6);
1428 $$->expr_type = ASN_TYPE_ANY;
1429 $$->meta_type = AMT_TYPE;
1431 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1435 $$->reference = asn1p_ref_new(yylineno, currentModule);
1436 ret = asn1p_ref_add_component($$->reference,
1439 $$->expr_type = ASN_TYPE_ANY;
1440 $$->meta_type = AMT_TYPE;
1443 | TOK_INSTANCE TOK_OF ComplexTypeReference {
1447 $$->expr_type = A1TC_INSTANCE;
1448 $$->meta_type = AMT_TYPE;
1453 * A type name consisting of several components.
1457 ComplexTypeReference:
1460 $$ = asn1p_ref_new(yylineno, currentModule);
1462 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1466 | TOK_capitalreference {
1468 $$ = asn1p_ref_new(yylineno, currentModule);
1470 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1474 | TOK_typereference '.' TypeRefName {
1476 $$ = asn1p_ref_new(yylineno, currentModule);
1478 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1480 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1485 | TOK_capitalreference '.' TypeRefName {
1487 $$ = asn1p_ref_new(yylineno, currentModule);
1489 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1491 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1496 | TOK_capitalreference '.' ComplexTypeReferenceAmpList {
1499 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1503 * Move the last element infront.
1506 struct asn1p_ref_component_s tmp_comp;
1507 tmp_comp = $$->components[$$->comp_count-1];
1508 memmove(&$$->components[1],
1510 sizeof($$->components[0])
1511 * ($$->comp_count - 1));
1512 $$->components[0] = tmp_comp;
1517 ComplexTypeReferenceAmpList:
1518 ComplexTypeReferenceElement {
1520 $$ = asn1p_ref_new(yylineno, currentModule);
1522 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1526 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1529 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1535 ComplexTypeReferenceElement: PrimitiveFieldReference;
1537 PrimitiveFieldReference:
1539 TOK_typefieldreference {
1540 $$.lex_type = RLT_AmpUppercase;
1544 | TOK_valuefieldreference {
1545 $$.lex_type = RLT_Amplowercase;
1553 TOK_typefieldreference {
1554 $$ = asn1p_ref_new(yylineno, currentModule);
1555 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1558 | FieldName '.' TOK_typefieldreference {
1560 asn1p_ref_add_component($$, $3, RLT_AmpUppercase);
1563 | FieldName '.' TOK_valuefieldreference {
1565 asn1p_ref_add_component($$, $3, RLT_Amplowercase);
1571 TOK_capitalreference {
1572 $$ = asn1p_ref_new(yylineno, currentModule);
1573 asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1577 | TypeRefName '.' TOK_capitalreference {
1578 $$ = asn1p_ref_new(yylineno, currentModule);
1579 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1580 asn1p_ref_add_component($$, $3, RLT_CAPITALS);
1590 * value INTEGER ::= 1
1594 Identifier Type TOK_PPEQ Value {
1596 assert($$->Identifier == NULL);
1597 $$->Identifier = $1;
1598 $$->meta_type = AMT_VALUE;
1606 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque {
1607 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1609 $$->type = ATV_UNPARSED;
1615 $$ = asn1p_value_fromint(0);
1617 $$->type = ATV_NULL;
1620 $$ = asn1p_value_fromint(0);
1622 $$->type = ATV_FALSE;
1625 $$ = asn1p_value_fromint(1);
1627 $$->type = ATV_TRUE;
1631 | RestrictedCharacterStringValue
1637 | TypeRefName '.' Identifier {
1640 ref = asn1p_ref_new(yylineno, currentModule);
1642 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1644 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1646 $$ = asn1p_value_fromref(ref, 0);
1654 RestrictedCharacterStringValue:
1656 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1660 $$ = asn1p_value_fromint($1);
1662 $$->type = ATV_TUPLE;
1665 $$ = asn1p_value_fromint($1);
1667 $$->type = ATV_QUADRUPLE;
1673 $$.len = $1.len + 1;
1674 $$.buf = malloc(1 + $$.len + 1);
1677 memcpy($$.buf + 1, $1.buf, $1.len);
1678 $$.buf[$$.len] = '\0';
1681 | Opaque TOK_opaque {
1682 int newsize = $1.len + $2.len;
1683 char *p = malloc(newsize + 1);
1685 memcpy(p , $1.buf, $1.len);
1686 memcpy(p + $1.len, $2.buf, $2.len);
1698 $$.len = strlen($1);
1703 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1704 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1705 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1706 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1707 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1708 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1709 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1710 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1711 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1712 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1713 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
1715 | BasicTypeId_UniverationCompatible
1719 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1721 BasicTypeId_UniverationCompatible:
1722 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1723 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1724 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1732 $$->meta_type = AMT_TYPE;
1734 | TOK_INTEGER '{' NamedNumberList '}' {
1736 $$->expr_type = ASN_BASIC_INTEGER;
1737 $$->meta_type = AMT_TYPE;
1739 | TOK_ENUMERATED '{' Enumerations '}' {
1741 $$->expr_type = ASN_BASIC_ENUMERATED;
1742 $$->meta_type = AMT_TYPE;
1744 | TOK_BIT TOK_STRING '{' NamedBitList '}' {
1746 $$->expr_type = ASN_BASIC_BIT_STRING;
1747 $$->meta_type = AMT_TYPE;
1749 | TOK_ExtValue_BIT_STRING '{' IdentifierList '}' {
1751 $$->expr_type = ASN_BASIC_BIT_STRING;
1752 $$->meta_type = AMT_TYPE;
1754 | TOK_ExtValue_BIT_STRING '{' '}' {
1757 $$->expr_type = ASN_BASIC_BIT_STRING;
1758 $$->meta_type = AMT_TYPE;
1763 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1764 | TOK_GeneralString {
1765 $$ = ASN_STRING_GeneralString;
1766 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
1768 | TOK_GraphicString {
1769 $$ = ASN_STRING_GraphicString;
1770 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
1772 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1773 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1774 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1775 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1777 $$ = ASN_STRING_T61String;
1778 fprintf(stderr, "WARNING: T61String is not fully supported\n");
1780 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1781 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1782 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1783 | TOK_VideotexString {
1784 $$ = ASN_STRING_VideotexString;
1785 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
1787 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1788 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1793 * Data type constraints.
1795 UnionMark: '|' | TOK_UNION;
1796 IntersectionMark: '^' | TOK_INTERSECTION;
1798 /* empty | Constraint */
1803 /* empty | Constraint... */
1808 /* empty | Constraint | SIZE(...) */
1809 optSizeOrConstraint:
1816 '(' ConstraintSpec ')' {
1817 CONSTRAINT_INSERT($$, ACT_CA_SET, $2, 0);
1823 | ManyConstraints Constraint {
1824 if($2->type == ACT_CA_SET && $2->el_count == 1) {
1825 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $2->elements[0]);
1827 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $2);
1832 ConstraintSpec: SubtypeConstraint | GeneralConstraint;
1834 SubtypeConstraint: ElementSetSpecs;
1838 $$ = asn1p_constraint_new(yylineno, currentModule);
1839 $$->type = ACT_EL_EXT;
1842 | ElementSetSpec ',' TOK_ThreeDots {
1843 asn1p_constraint_t *ct;
1844 ct = asn1p_constraint_new(yylineno, currentModule);
1845 ct->type = ACT_EL_EXT;
1846 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
1848 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
1849 asn1p_constraint_t *ct;
1850 ct = asn1p_constraint_new(yylineno, currentModule);
1851 ct->type = ACT_EL_EXT;
1852 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
1854 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
1860 | TOK_ALL TOK_EXCEPT Elements {
1861 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
1867 | Unions UnionMark Intersections {
1868 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
1873 IntersectionElements
1874 | Intersections IntersectionMark IntersectionElements {
1875 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
1880 IntersectionElements:
1882 | Elements TOK_EXCEPT Elements {
1883 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
1889 | '(' ElementSetSpec ')' {
1891 $$ = asn1p_constraint_new(yylineno, currentModule);
1893 $$->type = ACT_CA_SET;
1894 ret = asn1p_constraint_insert($$, $2);
1901 $$ = asn1p_constraint_new(yylineno, currentModule);
1903 $$->type = ACT_EL_VALUE;
1906 | ContainedSubtype {
1907 $$ = asn1p_constraint_new(yylineno, currentModule);
1909 $$->type = ACT_EL_TYPE;
1910 $$->containedSubtype = $1;
1912 | PermittedAlphabet /* FROM ... */
1913 | SizeConstraint /* SIZE ... */
1914 /* | TypeConstraint is via ContainedSubtype */
1915 | InnerTypeConstraints /* WITH COMPONENT[S] ... */
1916 | PatternConstraint /* PATTERN ... */
1922 TOK_FROM Constraint {
1923 CONSTRAINT_INSERT($$, ACT_CT_FROM, $2, 0);
1927 TOK_SIZE Constraint {
1928 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $2, 0);
1932 TOK_PATTERN TOK_cstring {
1933 $$ = asn1p_constraint_new(yylineno, currentModule);
1934 $$->type = ACT_CT_PATTERN;
1935 $$->value = asn1p_value_frombuf($2.buf, $2.len, 0);
1937 | TOK_PATTERN Identifier {
1939 $$ = asn1p_constraint_new(yylineno, currentModule);
1940 $$->type = ACT_CT_PATTERN;
1941 ref = asn1p_ref_new(yylineno, currentModule);
1942 asn1p_ref_add_component(ref, $2, RLT_lowercase);
1943 $$->value = asn1p_value_fromref(ref, 0);
1949 LowerEndValue ConstraintRangeSpec UpperEndValue {
1950 $$ = asn1p_constraint_new(yylineno, currentModule);
1953 $$->range_start = $1;
1954 $$->range_stop = $3;
1960 $$ = asn1p_value_fromint(-123);
1967 $$ = asn1p_value_fromint(321);
1975 $$ = _convert_bitstring2binary($1, 'B');
1980 $$ = _convert_bitstring2binary($1, 'H');
1988 $$ = asn1p_value_fromtype($2);
1990 asn1p_expr_free($2);
1992 /* Can't put Type here because of conflicts. Simplified subset */
1993 | DefinedUntaggedType {
1994 $$ = asn1p_value_fromtype($1);
1996 asn1p_expr_free($1);
2004 InnerTypeConstraints:
2005 TOK_WITH TOK_COMPONENT SingleTypeConstraint {
2006 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
2008 | TOK_WITH TOK_COMPONENTS MultipleTypeConstraints {
2009 assert($3->type == ACT_CA_CSV);
2010 $3->type = ACT_CT_WCOMPS;
2014 SingleTypeConstraint: Constraint;
2015 MultipleTypeConstraints: FullSpecification | PartialSpecification;
2016 FullSpecification: '{' TypeConstraints '}' { $$ = $2; };
2017 PartialSpecification:
2018 '{' TOK_ThreeDots ',' TypeConstraints '}' {
2019 assert($4->type == ACT_CA_CSV);
2020 $$ = asn1p_constraint_new(yylineno, currentModule);
2021 $$->type = ACT_CA_CSV;
2022 asn1p_constraint_t *ct = asn1p_constraint_new(yylineno, currentModule);
2024 ct->type = ACT_EL_EXT;
2025 asn1p_constraint_insert($$, ct);
2026 for(unsigned i = 0; i < $4->el_count; i++) {
2027 asn1p_constraint_insert($$, $4->elements[i]);
2032 $$ = asn1p_constraint_new(yylineno, currentModule);
2033 $$->type = ACT_CA_CSV;
2034 asn1p_constraint_insert($$, $1);
2036 | TypeConstraints ',' NamedConstraint {
2038 asn1p_constraint_insert($$, $3);
2042 IdentifierAsValue optConstraint optPresenceConstraint {
2043 $$ = asn1p_constraint_new(yylineno, currentModule);
2045 $$->type = ACT_EL_VALUE;
2047 if($2) asn1p_constraint_insert($$, $2);
2053 * presence constraint for NamedConstraint
2055 optPresenceConstraint:
2056 { $$ = ACPRES_DEFAULT; }
2057 | PresenceConstraint { $$ = $1; }
2062 $$ = ACPRES_PRESENT;
2068 $$ = ACPRES_OPTIONAL;
2075 UserDefinedConstraint
2077 | ContentsConstraint
2080 UserDefinedConstraint:
2081 TOK_CONSTRAINED TOK_BY '{'
2082 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
2083 $$ = asn1p_constraint_new(yylineno, currentModule);
2085 $$->type = ACT_CT_CTDBY;
2086 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
2087 checkmem($$->value);
2088 $$->value->type = ATV_UNPARSED;
2093 TOK_CONTAINING Type {
2094 $$ = asn1p_constraint_new(yylineno, currentModule);
2095 $$->type = ACT_CT_CTNG;
2096 $$->value = asn1p_value_fromtype($2);
2097 asn1p_expr_free($2);
2101 ConstraintRangeSpec:
2102 TOK_TwoDots { $$ = ACT_EL_RANGE; }
2103 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
2104 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
2105 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
2108 SimpleTableConstraint {
2111 | ComponentRelationConstraint {
2119 SimpleTableConstraint:
2120 '{' TypeRefName '}' {
2121 asn1p_ref_t *ref = asn1p_ref_new(yylineno, currentModule);
2122 asn1p_constraint_t *ct;
2124 ret = asn1p_ref_add_component(ref, $2, 0);
2126 ct = asn1p_constraint_new(yylineno, currentModule);
2128 ct->type = ACT_EL_VALUE;
2129 ct->value = asn1p_value_fromref(ref, 0);
2130 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
2135 ComponentRelationConstraint:
2136 SimpleTableConstraint '{' AtNotationList '}' {
2137 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
2143 $$ = asn1p_constraint_new(yylineno, currentModule);
2145 $$->type = ACT_EL_VALUE;
2146 $$->value = asn1p_value_fromref($1, 0);
2148 | AtNotationList ',' AtNotationElement {
2149 asn1p_constraint_t *ct;
2150 ct = asn1p_constraint_new(yylineno, currentModule);
2152 ct->type = ACT_EL_VALUE;
2153 ct->value = asn1p_value_fromref($3, 0);
2154 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
2162 '@' ComponentIdList {
2163 char *p = malloc(strlen($2) + 2);
2167 $$ = asn1p_ref_new(yylineno, currentModule);
2168 ret = asn1p_ref_add_component($$, p, 0);
2173 | '@' '.' ComponentIdList {
2174 char *p = malloc(strlen($3) + 3);
2179 $$ = asn1p_ref_new(yylineno, currentModule);
2180 ret = asn1p_ref_add_component($$, p, 0);
2187 /* identifier "." ... */
2192 | ComponentIdList '.' Identifier {
2193 int l1 = strlen($1);
2194 int l3 = strlen($3);
2195 $$ = malloc(l1 + 1 + l3 + 1);
2198 memcpy($$ + l1 + 1, $3, l3);
2199 $$[l1 + 1 + l3] = '\0';
2213 $$.flags = EM_NOMARK;
2214 $$.default_value = 0;
2216 | Marker { $$ = $1; }
2221 $$.flags = EM_OPTIONAL | EM_INDIRECT;
2222 $$.default_value = 0;
2224 | TOK_DEFAULT Value {
2225 $$.flags = EM_DEFAULT;
2226 $$.default_value = $2;
2234 asn1p_expr_add($$, $1);
2236 | IdentifierList ',' IdentifierElement {
2238 asn1p_expr_add($$, $3);
2245 $$->expr_type = A1TC_UNIVERVAL;
2246 $$->meta_type = AMT_VALUE;
2247 $$->Identifier = $1;
2254 asn1p_expr_add($$, $1);
2256 | NamedNumberList ',' NamedNumber {
2258 asn1p_expr_add($$, $3);
2263 Identifier '(' SignedNumber ')' {
2266 $$->expr_type = A1TC_UNIVERVAL;
2267 $$->meta_type = AMT_VALUE;
2268 $$->Identifier = $1;
2271 | Identifier '(' DefinedValue ')' {
2274 $$->expr_type = A1TC_UNIVERVAL;
2275 $$->meta_type = AMT_VALUE;
2276 $$->Identifier = $1;
2284 asn1p_expr_add($$, $1);
2286 | NamedBitList ',' NamedBit {
2288 asn1p_expr_add($$, $3);
2293 Identifier '(' TOK_number ')' {
2296 $$->expr_type = A1TC_UNIVERVAL;
2297 $$->meta_type = AMT_VALUE;
2298 $$->Identifier = $1;
2299 $$->value = asn1p_value_fromint($3);
2301 | Identifier '(' DefinedValue ')' {
2304 $$->expr_type = A1TC_UNIVERVAL;
2305 $$->meta_type = AMT_VALUE;
2306 $$->Identifier = $1;
2313 asn1p_expr_t *first_memb = TQ_FIRST(&($$->members));
2315 if(first_memb->expr_type == A1TC_EXTENSIBLE) {
2317 "The ENUMERATION cannot start with extension (...).");
2321 "The ENUMERATION list cannot be empty.");
2326 UniverationElement {
2329 asn1p_expr_add($$, $1);
2331 | UniverationList ',' UniverationElement {
2333 asn1p_expr_add($$, $3);
2341 $$->expr_type = A1TC_UNIVERVAL;
2342 $$->meta_type = AMT_VALUE;
2343 $$->Identifier = $1;
2345 | Identifier '(' SignedNumber ')' {
2348 $$->expr_type = A1TC_UNIVERVAL;
2349 $$->meta_type = AMT_VALUE;
2350 $$->Identifier = $1;
2353 | Identifier '(' DefinedValue ')' {
2356 $$->expr_type = A1TC_UNIVERVAL;
2357 $$->meta_type = AMT_VALUE;
2358 $$->Identifier = $1;
2364 $$->expr_type = A1TC_UNIVERVAL;
2365 $$->meta_type = AMT_VALUE;
2371 $$->Identifier = strdup("...");
2372 checkmem($$->Identifier);
2373 $$->expr_type = A1TC_EXTENSIBLE;
2374 $$->meta_type = AMT_VALUE;
2380 $$ = asn1p_value_fromint($1);
2383 | TOK_number_negative {
2384 $$ = asn1p_value_fromint($1);
2391 $$ = asn1p_value_fromdouble($1);
2397 * SEQUENCE definition.
2399 * Struct1 ::= SEQUENCE {
2401 * memb2 SEQUENCE OF {
2414 * name [0] PrintableString (SIZE(1..20)),
2415 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2421 { memset(&$$, 0, sizeof($$)); }
2426 TagTypeValue TagPlicit {
2428 $$.tag_mode = $2.tag_mode;
2433 '[' TagClass TOK_number ']' {
2439 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2440 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2441 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2442 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2446 { $$.tag_mode = TM_DEFAULT; }
2447 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2448 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
2456 | TOK_capitalreference {
2477 IdentifierAsReference:
2479 $$ = asn1p_ref_new(yylineno, currentModule);
2480 asn1p_ref_add_component($$, $1, RLT_lowercase);
2485 IdentifierAsReference {
2486 $$ = asn1p_value_fromref($1, 0);
2493 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2495 static asn1p_value_t *
2496 _convert_bitstring2binary(char *str, int base) {
2502 uint8_t *binary_vector;
2507 assert(str[0] == '\'');
2517 assert(base == 'B' || base == 'H');
2523 assert(str[slen - 1] == base);
2524 assert(str[slen - 2] == '\'');
2526 memlen = slen / (8 / baselen); /* Conservative estimate */
2528 bv_ptr = binary_vector = malloc(memlen + 1);
2535 while(*(++str) != '\'') {
2540 cur_val |= 1 << (7 - (bits % 8));
2544 assert(!"_y UNREACH1");
2545 case ' ': case '\r': case '\n':
2551 case '0': case '1': case '2': case '3': case '4':
2552 case '5': case '6': case '7': case '8': case '9':
2553 cur_val |= (*str - '0') << (4 - (bits % 8));
2555 case 'A': case 'B': case 'C':
2556 case 'D': case 'E': case 'F':
2557 cur_val |= ((*str - 'A') + 10)
2558 << (4 - (bits % 8));
2561 assert(!"_y UNREACH2");
2562 case ' ': case '\r': case '\n':
2569 if((bits % 8) == 0) {
2570 *bv_ptr++ = cur_val;
2576 assert((bv_ptr - binary_vector) <= memlen);
2578 val = asn1p_value_frombits(binary_vector, bits, 0);
2580 free(binary_vector);
2587 * For unnamed types (used in old X.208 compliant modules)
2588 * generate some sort of interim names, to not to force human being to fix
2589 * the specification's compliance to modern ASN.1 standards.
2592 _fixup_anonymous_identifier(asn1p_expr_t *expr) {
2594 assert(expr->Identifier == 0);
2597 * Try to figure out the type name
2598 * without going too much into details
2600 expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type);
2601 if(expr->reference && expr->reference->comp_count > 0)
2602 expr->Identifier = expr->reference->components[0].name;
2605 "WARNING: Line %d: expected lower-case member identifier, "
2606 "found an unnamed %s.\n"
2607 "WARNING: Obsolete X.208 syntax detected, "
2608 "please give the member a name.\n",
2609 yylineno, expr->Identifier ? expr->Identifier : "type");
2611 if(!expr->Identifier)
2612 expr->Identifier = "unnamed";
2613 expr->Identifier = strdup(expr->Identifier);
2614 assert(expr->Identifier);
2615 /* Make a lowercase identifier from the type name */
2616 for(p = expr->Identifier; *p; p++) {
2618 case 'A' ... 'Z': *p += 32; break;
2619 case ' ': *p = '_'; break;
2620 case '-': *p = '_'; break;
2623 fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". "
2624 "Name clash may occur later.\n",
2629 yyerror(const char *msg) {
2630 extern char *asn1p_text;
2632 "ASN.1 grammar parse error "
2633 "near %s:%d (token \"%s\"): %s\n",
2634 ASN_FILENAME, yylineno, asn1p_text, msg);