vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | %{ |
| 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 |
| 12 | #define YYERROR_VERBOSE |
| 13 | |
| 14 | int yylex(void); |
| 15 | int yyerror(const char *msg); |
| 16 | void asn1p_lexer_hack_push_opaque_state(void); |
| 17 | void asn1p_lexer_hack_enable_with_syntax(void); |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 18 | void asn1p_lexer_hack_push_encoding_control(void); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 19 | #define yylineno asn1p_lineno |
| 20 | extern int asn1p_lineno; |
| 21 | |
| 22 | |
| 23 | static asn1p_value_t * |
| 24 | _convert_bitstring2binary(char *str, int base); |
| 25 | |
vlm | 6a02a8a | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 26 | #define checkmem(ptr) do { \ |
| 27 | if(!(ptr)) \ |
| 28 | return yyerror("Memory failure"); \ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 29 | } while(0) |
| 30 | |
| 31 | #define CONSTRAINT_INSERT(root, constr_type, arg1, arg2) do { \ |
| 32 | if(arg1->type != constr_type) { \ |
| 33 | int __ret; \ |
| 34 | root = asn1p_constraint_new(yylineno); \ |
| 35 | checkmem(root); \ |
| 36 | root->type = constr_type; \ |
| 37 | __ret = asn1p_constraint_insert(root, \ |
| 38 | arg1); \ |
| 39 | checkmem(__ret == 0); \ |
| 40 | } else { \ |
| 41 | root = arg1; \ |
| 42 | } \ |
| 43 | if(arg2) { \ |
| 44 | int __ret \ |
| 45 | = asn1p_constraint_insert(root, arg2); \ |
| 46 | checkmem(__ret == 0); \ |
| 47 | } \ |
| 48 | } while(0) |
| 49 | |
| 50 | %} |
| 51 | |
| 52 | |
| 53 | /* |
| 54 | * Token value definition. |
| 55 | * a_*: ASN-specific types. |
| 56 | * tv_*: Locally meaningful types. |
| 57 | */ |
| 58 | %union { |
| 59 | asn1p_t *a_grammar; |
| 60 | asn1p_module_flags_e a_module_flags; |
| 61 | asn1p_module_t *a_module; |
| 62 | asn1p_expr_type_e a_type; /* ASN.1 Type */ |
| 63 | asn1p_expr_t *a_expr; /* Constructed collection */ |
| 64 | asn1p_constraint_t *a_constr; /* Constraint */ |
| 65 | enum asn1p_constraint_type_e a_ctype;/* Constraint type */ |
| 66 | asn1p_xports_t *a_xports; /* IMports/EXports */ |
| 67 | asn1p_oid_t *a_oid; /* Object Identifier */ |
| 68 | asn1p_oid_arc_t a_oid_arc; /* Single OID's arc */ |
| 69 | struct asn1p_type_tag_s a_tag; /* A tag */ |
| 70 | asn1p_ref_t *a_ref; /* Reference to custom type */ |
| 71 | asn1p_wsyntx_t *a_wsynt; /* WITH SYNTAX contents */ |
| 72 | asn1p_wsyntx_chunk_t *a_wchunk; /* WITH SYNTAX chunk */ |
| 73 | struct asn1p_ref_component_s a_refcomp; /* Component of a reference */ |
| 74 | asn1p_value_t *a_value; /* Number, DefinedValue, etc */ |
| 75 | struct asn1p_param_s a_parg; /* A parameter argument */ |
| 76 | asn1p_paramlist_t *a_plist; /* A pargs list */ |
vlm | c94e28f | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 77 | struct asn1p_expr_marker_s a_marker; /* OPTIONAL/DEFAULT */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 78 | enum asn1p_constr_pres_e a_pres; /* PRESENT/ABSENT/OPTIONAL */ |
vlm | 0aa8690 | 2004-10-12 23:26:53 +0000 | [diff] [blame] | 79 | asn1c_integer_t a_int; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 80 | char *tv_str; |
| 81 | struct { |
| 82 | char *buf; |
| 83 | int len; |
| 84 | } tv_opaque; |
| 85 | struct { |
| 86 | char *name; |
| 87 | struct asn1p_type_tag_s tag; |
| 88 | } tv_nametag; |
| 89 | }; |
| 90 | |
| 91 | /* |
| 92 | * Token types returned by scanner. |
| 93 | */ |
| 94 | %token TOK_PPEQ /* "::=", Pseudo Pascal EQuality */ |
| 95 | %token <tv_opaque> TOK_opaque /* opaque data (driven from .y) */ |
| 96 | %token <tv_str> TOK_bstring |
| 97 | %token <tv_opaque> TOK_cstring |
| 98 | %token <tv_str> TOK_hstring |
| 99 | %token <tv_str> TOK_identifier |
| 100 | %token <a_int> TOK_number |
| 101 | %token <a_int> TOK_number_negative |
| 102 | %token <tv_str> TOK_typereference |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 103 | %token <tv_str> TOK_capitalreference /* "CLASS1" */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 104 | %token <tv_str> TOK_typefieldreference /* "&Pork" */ |
| 105 | %token <tv_str> TOK_valuefieldreference /* "&id" */ |
| 106 | |
| 107 | /* |
| 108 | * Token types representing ASN.1 standard keywords. |
| 109 | */ |
| 110 | %token TOK_ABSENT |
| 111 | %token TOK_ABSTRACT_SYNTAX |
| 112 | %token TOK_ALL |
| 113 | %token TOK_ANY |
| 114 | %token TOK_APPLICATION |
| 115 | %token TOK_AUTOMATIC |
| 116 | %token TOK_BEGIN |
| 117 | %token TOK_BIT |
| 118 | %token TOK_BMPString |
| 119 | %token TOK_BOOLEAN |
| 120 | %token TOK_BY |
| 121 | %token TOK_CHARACTER |
| 122 | %token TOK_CHOICE |
| 123 | %token TOK_CLASS |
| 124 | %token TOK_COMPONENT |
| 125 | %token TOK_COMPONENTS |
| 126 | %token TOK_CONSTRAINED |
| 127 | %token TOK_CONTAINING |
| 128 | %token TOK_DEFAULT |
| 129 | %token TOK_DEFINITIONS |
| 130 | %token TOK_DEFINED |
| 131 | %token TOK_EMBEDDED |
| 132 | %token TOK_ENCODED |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 133 | %token TOK_ENCODING_CONTROL |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 134 | %token TOK_END |
| 135 | %token TOK_ENUMERATED |
| 136 | %token TOK_EXPLICIT |
| 137 | %token TOK_EXPORTS |
| 138 | %token TOK_EXTENSIBILITY |
| 139 | %token TOK_EXTERNAL |
| 140 | %token TOK_FALSE |
| 141 | %token TOK_FROM |
| 142 | %token TOK_GeneralizedTime |
| 143 | %token TOK_GeneralString |
| 144 | %token TOK_GraphicString |
| 145 | %token TOK_IA5String |
| 146 | %token TOK_IDENTIFIER |
| 147 | %token TOK_IMPLICIT |
| 148 | %token TOK_IMPLIED |
| 149 | %token TOK_IMPORTS |
| 150 | %token TOK_INCLUDES |
| 151 | %token TOK_INSTANCE |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 152 | %token TOK_INSTRUCTIONS |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 153 | %token TOK_INTEGER |
| 154 | %token TOK_ISO646String |
| 155 | %token TOK_MAX |
| 156 | %token TOK_MIN |
| 157 | %token TOK_MINUS_INFINITY |
| 158 | %token TOK_NULL |
| 159 | %token TOK_NumericString |
| 160 | %token TOK_OBJECT |
| 161 | %token TOK_ObjectDescriptor |
| 162 | %token TOK_OCTET |
| 163 | %token TOK_OF |
| 164 | %token TOK_OPTIONAL |
| 165 | %token TOK_PATTERN |
| 166 | %token TOK_PDV |
| 167 | %token TOK_PLUS_INFINITY |
| 168 | %token TOK_PRESENT |
| 169 | %token TOK_PrintableString |
| 170 | %token TOK_PRIVATE |
| 171 | %token TOK_REAL |
| 172 | %token TOK_RELATIVE_OID |
| 173 | %token TOK_SEQUENCE |
| 174 | %token TOK_SET |
| 175 | %token TOK_SIZE |
| 176 | %token TOK_STRING |
| 177 | %token TOK_SYNTAX |
| 178 | %token TOK_T61String |
| 179 | %token TOK_TAGS |
| 180 | %token TOK_TeletexString |
| 181 | %token TOK_TRUE |
| 182 | %token TOK_TYPE_IDENTIFIER |
| 183 | %token TOK_UNIQUE |
| 184 | %token TOK_UNIVERSAL |
| 185 | %token TOK_UniversalString |
| 186 | %token TOK_UTCTime |
| 187 | %token TOK_UTF8String |
| 188 | %token TOK_VideotexString |
| 189 | %token TOK_VisibleString |
| 190 | %token TOK_WITH |
| 191 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 192 | %left TOK_EXCEPT |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 193 | %left '^' TOK_INTERSECTION |
| 194 | %left '|' TOK_UNION |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 195 | |
| 196 | /* Misc tags */ |
| 197 | %token TOK_TwoDots /* .. */ |
| 198 | %token TOK_ThreeDots /* ... */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 199 | |
| 200 | |
| 201 | /* |
| 202 | * Types defined herein. |
| 203 | */ |
| 204 | %type <a_grammar> ModuleList |
| 205 | %type <a_module> ModuleSpecification |
| 206 | %type <a_module> ModuleSpecificationBody |
| 207 | %type <a_module> ModuleSpecificationElement |
| 208 | %type <a_module> optModuleSpecificationBody /* Optional */ |
| 209 | %type <a_module_flags> optModuleSpecificationFlags |
| 210 | %type <a_module_flags> ModuleSpecificationFlags /* Set of FL */ |
| 211 | %type <a_module_flags> ModuleSpecificationFlag /* Single FL */ |
| 212 | %type <a_module> ImportsDefinition |
| 213 | %type <a_module> ImportsBundleSet |
| 214 | %type <a_xports> ImportsBundle |
| 215 | %type <a_xports> ImportsList |
| 216 | %type <a_xports> ExportsDefinition |
| 217 | %type <a_xports> ExportsBody |
| 218 | %type <a_expr> ImportsElement |
| 219 | %type <a_expr> ExportsElement |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 220 | %type <a_expr> ExtensionAndException |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 221 | %type <a_expr> TypeDeclaration |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 222 | %type <a_ref> ComplexTypeReference |
| 223 | %type <a_ref> ComplexTypeReferenceAmpList |
| 224 | %type <a_refcomp> ComplexTypeReferenceElement |
| 225 | %type <a_refcomp> ClassFieldIdentifier |
| 226 | %type <a_refcomp> ClassFieldName |
| 227 | %type <a_expr> ClassFieldList |
| 228 | %type <a_expr> ClassField |
| 229 | %type <a_expr> ClassDeclaration |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 230 | %type <a_expr> Type |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 231 | %type <a_expr> DataTypeReference /* Type1 ::= Type2 */ |
| 232 | %type <a_expr> DefinedTypeRef |
| 233 | %type <a_expr> ValueSetDefinition /* Val INTEGER ::= {1|2} */ |
| 234 | %type <a_expr> ValueDefinition /* val INTEGER ::= 1*/ |
vlm | 39e5ed7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 235 | %type <a_expr> optValueSetBody |
| 236 | %type <a_expr> ValueSetBody |
| 237 | %type <a_expr> ValueSetElement |
vlm | c94e28f | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 238 | %type <a_value> Value |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 239 | %type <a_value> DefinedValue |
| 240 | %type <a_value> SignedNumber |
vlm | 0aa8690 | 2004-10-12 23:26:53 +0000 | [diff] [blame] | 241 | %type <a_expr> optComponentTypeLists |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 242 | %type <a_expr> ComponentTypeLists |
| 243 | %type <a_expr> ComponentType |
| 244 | %type <a_expr> AlternativeTypeLists |
| 245 | %type <a_expr> AlternativeType |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 246 | //%type <a_expr> optUniverationDefinition |
| 247 | %type <a_expr> UniverationDefinition |
| 248 | %type <a_expr> UniverationList |
| 249 | %type <a_expr> UniverationElement |
| 250 | %type <tv_str> TypeRefName |
| 251 | %type <tv_str> ObjectClassReference |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 252 | %type <tv_str> Identifier |
vlm | 151c0b2 | 2004-09-22 16:03:36 +0000 | [diff] [blame] | 253 | %type <tv_str> optIdentifier |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 254 | %type <a_parg> ParameterArgumentName |
| 255 | %type <a_plist> ParameterArgumentList |
| 256 | %type <a_expr> ActualParameter |
| 257 | %type <a_expr> ActualParameterList |
| 258 | %type <a_oid> ObjectIdentifier /* OID */ |
| 259 | %type <a_oid> optObjectIdentifier /* Optional OID */ |
| 260 | %type <a_oid> ObjectIdentifierBody |
| 261 | %type <a_oid_arc> ObjectIdentifierElement |
| 262 | %type <a_expr> BasicType |
| 263 | %type <a_type> BasicTypeId |
| 264 | %type <a_type> BasicTypeId_UniverationCompatible |
| 265 | %type <a_type> BasicString |
| 266 | %type <tv_opaque> Opaque |
| 267 | //%type <tv_opaque> StringValue |
vlm | 2728a8d | 2005-01-23 09:51:44 +0000 | [diff] [blame] | 268 | %type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */ |
| 269 | %type <a_tag> TagClass TagTypeValue TagPlicit |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 270 | %type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */ |
| 271 | %type <a_constr> optConstraints |
vlm | 5f0128b | 2004-08-20 13:25:29 +0000 | [diff] [blame] | 272 | %type <a_constr> Constraints |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 273 | %type <a_constr> SetOfConstraints |
| 274 | %type <a_constr> ElementSetSpecs /* 1..2,...,3 */ |
| 275 | %type <a_constr> ElementSetSpec /* 1..2,...,3 */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 276 | %type <a_constr> ConstraintSubtypeElement /* 1..2 */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 277 | %type <a_constr> SimpleTableConstraint |
| 278 | %type <a_constr> TableConstraint |
| 279 | %type <a_constr> WithComponents |
| 280 | %type <a_constr> WithComponentsList |
| 281 | %type <a_constr> WithComponentsElement |
| 282 | %type <a_constr> ComponentRelationConstraint |
| 283 | %type <a_constr> AtNotationList |
| 284 | %type <a_ref> AtNotationElement |
vlm | a6a12e3 | 2005-03-20 12:58:00 +0000 | [diff] [blame^] | 285 | %type <a_value> SingleValue |
| 286 | %type <a_value> ContainedSubtype |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 287 | %type <a_ctype> ConstraintSpec |
| 288 | %type <a_ctype> ConstraintRangeSpec |
| 289 | %type <a_wsynt> optWithSyntax |
| 290 | %type <a_wsynt> WithSyntax |
| 291 | %type <a_wsynt> WithSyntaxFormat |
| 292 | %type <a_wchunk> WithSyntaxFormatToken |
| 293 | %type <a_marker> optMarker Marker |
| 294 | %type <a_int> optUnique |
| 295 | %type <a_pres> optPresenceConstraint PresenceConstraint |
| 296 | %type <tv_str> ComponentIdList |
| 297 | |
| 298 | |
| 299 | %% |
| 300 | |
| 301 | |
| 302 | ParsedGrammar: |
| 303 | ModuleList { |
| 304 | *(void **)param = $1; |
| 305 | } |
| 306 | ; |
| 307 | |
| 308 | ModuleList: |
| 309 | ModuleSpecification { |
| 310 | $$ = asn1p_new(); |
| 311 | checkmem($$); |
| 312 | TQ_ADD(&($$->modules), $1, mod_next); |
| 313 | } |
| 314 | | ModuleList ModuleSpecification { |
| 315 | $$ = $1; |
| 316 | TQ_ADD(&($$->modules), $2, mod_next); |
| 317 | } |
| 318 | ; |
| 319 | |
| 320 | /* |
| 321 | * ASN module definition. |
| 322 | * === EXAMPLE === |
| 323 | * MySyntax DEFINITIONS AUTOMATIC TAGS ::= |
| 324 | * BEGIN |
| 325 | * ... |
| 326 | * END |
| 327 | * === EOF === |
| 328 | */ |
| 329 | |
| 330 | ModuleSpecification: |
| 331 | TypeRefName optObjectIdentifier TOK_DEFINITIONS |
| 332 | optModuleSpecificationFlags |
| 333 | TOK_PPEQ TOK_BEGIN |
| 334 | optModuleSpecificationBody |
| 335 | TOK_END { |
| 336 | |
| 337 | if($7) { |
| 338 | $$ = $7; |
| 339 | } else { |
| 340 | /* There's a chance that a module is just plain empty */ |
| 341 | $$ = asn1p_module_new(); |
| 342 | } |
| 343 | checkmem($$); |
| 344 | |
| 345 | $$->Identifier = $1; |
| 346 | $$->module_oid = $2; |
| 347 | $$->module_flags = $4; |
| 348 | } |
| 349 | ; |
| 350 | |
| 351 | /* |
| 352 | * Object Identifier Definition |
| 353 | * { iso member-body(2) 3 } |
| 354 | */ |
| 355 | optObjectIdentifier: |
| 356 | { $$ = 0; } |
| 357 | | ObjectIdentifier { $$ = $1; } |
| 358 | ; |
| 359 | |
| 360 | ObjectIdentifier: |
| 361 | '{' ObjectIdentifierBody '}' { |
| 362 | $$ = $2; |
| 363 | } |
| 364 | | '{' '}' { |
| 365 | $$ = 0; |
| 366 | } |
| 367 | ; |
| 368 | |
| 369 | ObjectIdentifierBody: |
| 370 | ObjectIdentifierElement { |
| 371 | $$ = asn1p_oid_new(); |
| 372 | asn1p_oid_add_arc($$, &$1); |
| 373 | if($1.name) |
| 374 | free($1.name); |
| 375 | } |
| 376 | | ObjectIdentifierBody ObjectIdentifierElement { |
| 377 | $$ = $1; |
| 378 | asn1p_oid_add_arc($$, &$2); |
| 379 | if($2.name) |
| 380 | free($2.name); |
| 381 | } |
| 382 | ; |
| 383 | |
| 384 | ObjectIdentifierElement: |
| 385 | Identifier { /* iso */ |
| 386 | $$.name = $1; |
| 387 | $$.number = -1; |
| 388 | } |
| 389 | | Identifier '(' TOK_number ')' { /* iso(1) */ |
| 390 | $$.name = $1; |
| 391 | $$.number = $3; |
| 392 | } |
| 393 | | TOK_number { /* 1 */ |
| 394 | $$.name = 0; |
| 395 | $$.number = $1; |
| 396 | } |
| 397 | ; |
| 398 | |
| 399 | /* |
| 400 | * Optional module flags. |
| 401 | */ |
| 402 | optModuleSpecificationFlags: |
| 403 | { $$ = MSF_NOFLAGS; } |
| 404 | | ModuleSpecificationFlags { |
| 405 | $$ = $1; |
| 406 | } |
| 407 | ; |
| 408 | |
| 409 | /* |
| 410 | * Module flags. |
| 411 | */ |
| 412 | ModuleSpecificationFlags: |
| 413 | ModuleSpecificationFlag { |
| 414 | $$ = $1; |
| 415 | } |
| 416 | | ModuleSpecificationFlags ModuleSpecificationFlag { |
| 417 | $$ = $1 | $2; |
| 418 | } |
| 419 | ; |
| 420 | |
| 421 | /* |
| 422 | * Single module flag. |
| 423 | */ |
| 424 | ModuleSpecificationFlag: |
| 425 | TOK_EXPLICIT TOK_TAGS { |
| 426 | $$ = MSF_EXPLICIT_TAGS; |
| 427 | } |
| 428 | | TOK_IMPLICIT TOK_TAGS { |
| 429 | $$ = MSF_IMPLICIT_TAGS; |
| 430 | } |
| 431 | | TOK_AUTOMATIC TOK_TAGS { |
| 432 | $$ = MSF_AUTOMATIC_TAGS; |
| 433 | } |
| 434 | | TOK_EXTENSIBILITY TOK_IMPLIED { |
| 435 | $$ = MSF_EXTENSIBILITY_IMPLIED; |
| 436 | } |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 437 | /* EncodingReferenceDefault */ |
| 438 | | TOK_capitalreference TOK_INSTRUCTIONS { |
| 439 | /* X.680Amd1 specifies TAG and XER */ |
| 440 | if(strcmp($1, "TAG") == 0) { |
| 441 | $$ = MSF_TAG_INSTRUCTIONS; |
| 442 | } else if(strcmp($1, "XER") == 0) { |
| 443 | $$ = MSF_XER_INSTRUCTIONS; |
| 444 | } else { |
| 445 | fprintf(stderr, |
| 446 | "WARNING: %s INSTRUCTIONS at line %d: " |
| 447 | "Unrecognized encoding reference\n", |
| 448 | $1, yylineno); |
| 449 | $$ = MSF_unk_INSTRUCTIONS; |
| 450 | } |
| 451 | free($1); |
| 452 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 453 | ; |
| 454 | |
| 455 | /* |
| 456 | * Optional module body. |
| 457 | */ |
| 458 | optModuleSpecificationBody: |
| 459 | { $$ = 0; } |
| 460 | | ModuleSpecificationBody { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 461 | $$ = $1; |
| 462 | } |
| 463 | ; |
| 464 | |
| 465 | /* |
| 466 | * ASN.1 Module body. |
| 467 | */ |
| 468 | ModuleSpecificationBody: |
| 469 | ModuleSpecificationElement { |
| 470 | $$ = $1; |
| 471 | } |
| 472 | | ModuleSpecificationBody ModuleSpecificationElement { |
| 473 | $$ = $1; |
| 474 | |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 475 | /* Behave well when one of them is skipped. */ |
| 476 | if(!($1)) { |
| 477 | if($2) $$ = $2; |
| 478 | break; |
| 479 | } |
| 480 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 481 | #ifdef MY_IMPORT |
| 482 | #error MY_IMPORT DEFINED ELSEWHERE! |
| 483 | #endif |
| 484 | #define MY_IMPORT(foo,field) do { \ |
vlm | 97ed715 | 2004-08-13 12:31:09 +0000 | [diff] [blame] | 485 | while(TQ_FIRST(&($2->foo))) { \ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 486 | TQ_ADD(&($$->foo), \ |
| 487 | TQ_REMOVE(&($2->foo), field), \ |
| 488 | field); \ |
vlm | 97ed715 | 2004-08-13 12:31:09 +0000 | [diff] [blame] | 489 | } \ |
| 490 | assert(TQ_FIRST(&($2->foo)) == 0); \ |
| 491 | } while(0) |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 492 | |
| 493 | MY_IMPORT(imports, xp_next); |
| 494 | MY_IMPORT(exports, xp_next); |
| 495 | MY_IMPORT(members, next); |
| 496 | #undef MY_IMPORT |
| 497 | |
| 498 | } |
| 499 | ; |
| 500 | |
| 501 | /* |
| 502 | * One of the elements of ASN.1 module specification. |
| 503 | */ |
| 504 | ModuleSpecificationElement: |
| 505 | ImportsDefinition { |
| 506 | $$ = $1; |
| 507 | } |
| 508 | | ExportsDefinition { |
| 509 | $$ = asn1p_module_new(); |
| 510 | checkmem($$); |
| 511 | if($1) { |
| 512 | TQ_ADD(&($$->exports), $1, xp_next); |
| 513 | } else { |
| 514 | /* "EXPORTS ALL;" ? */ |
| 515 | } |
| 516 | } |
| 517 | | DataTypeReference { |
| 518 | $$ = asn1p_module_new(); |
| 519 | checkmem($$); |
| 520 | assert($1->expr_type != A1TC_INVALID); |
| 521 | assert($1->meta_type != AMT_INVALID); |
| 522 | TQ_ADD(&($$->members), $1, next); |
| 523 | } |
| 524 | | ValueDefinition { |
| 525 | $$ = asn1p_module_new(); |
| 526 | checkmem($$); |
| 527 | assert($1->expr_type != A1TC_INVALID); |
| 528 | assert($1->meta_type != AMT_INVALID); |
| 529 | TQ_ADD(&($$->members), $1, next); |
| 530 | } |
| 531 | /* |
| 532 | * Value set definition |
| 533 | * === EXAMPLE === |
| 534 | * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 } |
| 535 | * === EOF === |
| 536 | */ |
| 537 | | ValueSetDefinition { |
| 538 | $$ = asn1p_module_new(); |
| 539 | checkmem($$); |
| 540 | assert($1->expr_type != A1TC_INVALID); |
| 541 | assert($1->meta_type != AMT_INVALID); |
| 542 | TQ_ADD(&($$->members), $1, next); |
| 543 | } |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 544 | | TOK_ENCODING_CONTROL TOK_capitalreference |
| 545 | { asn1p_lexer_hack_push_encoding_control(); } |
| 546 | { |
| 547 | fprintf(stderr, |
| 548 | "WARNING: ENCODING-CONTROL %s " |
| 549 | "specification at line %d ignored\n", |
| 550 | $2, yylineno); |
| 551 | free($2); |
| 552 | $$ = 0; |
| 553 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 554 | |
| 555 | /* |
| 556 | * Erroneous attemps |
| 557 | */ |
| 558 | | BasicString { |
| 559 | return yyerror( |
| 560 | "Attempt to redefine a standard basic type, " |
| 561 | "use -ftypesXY to switch back " |
| 562 | "to older version of ASN.1 standard"); |
| 563 | } |
| 564 | ; |
| 565 | |
| 566 | /* |
| 567 | * === EXAMPLE === |
| 568 | * IMPORTS Type1, value FROM Module { iso standard(0) } ; |
| 569 | * === EOF === |
| 570 | */ |
| 571 | ImportsDefinition: |
| 572 | TOK_IMPORTS ImportsBundleSet ';' { |
| 573 | $$ = $2; |
| 574 | } |
| 575 | /* |
| 576 | * Some error cases. |
| 577 | */ |
| 578 | | TOK_IMPORTS TOK_FROM /* ... */ { |
| 579 | return yyerror("Empty IMPORTS list"); |
| 580 | } |
| 581 | ; |
| 582 | |
| 583 | ImportsBundleSet: |
| 584 | ImportsBundle { |
| 585 | $$ = asn1p_module_new(); |
| 586 | checkmem($$); |
| 587 | TQ_ADD(&($$->imports), $1, xp_next); |
| 588 | } |
| 589 | | ImportsBundleSet ImportsBundle { |
| 590 | $$ = $1; |
| 591 | TQ_ADD(&($$->imports), $2, xp_next); |
| 592 | } |
| 593 | ; |
| 594 | |
| 595 | ImportsBundle: |
| 596 | ImportsList TOK_FROM TypeRefName optObjectIdentifier { |
| 597 | $$ = $1; |
| 598 | $$->from = $3; |
| 599 | $$->from_oid = $4; |
| 600 | checkmem($$); |
| 601 | } |
| 602 | ; |
| 603 | |
| 604 | ImportsList: |
| 605 | ImportsElement { |
| 606 | $$ = asn1p_xports_new(); |
| 607 | checkmem($$); |
| 608 | TQ_ADD(&($$->members), $1, next); |
| 609 | } |
| 610 | | ImportsList ',' ImportsElement { |
| 611 | $$ = $1; |
| 612 | TQ_ADD(&($$->members), $3, next); |
| 613 | } |
| 614 | ; |
| 615 | |
| 616 | ImportsElement: |
| 617 | TypeRefName { |
| 618 | $$ = asn1p_expr_new(yylineno); |
| 619 | checkmem($$); |
| 620 | $$->Identifier = $1; |
| 621 | $$->expr_type = A1TC_REFERENCE; |
| 622 | } |
vlm | 0aa8690 | 2004-10-12 23:26:53 +0000 | [diff] [blame] | 623 | | TypeRefName '{' '}' { /* Completely equivalent to above */ |
| 624 | $$ = asn1p_expr_new(yylineno); |
| 625 | checkmem($$); |
| 626 | $$->Identifier = $1; |
| 627 | $$->expr_type = A1TC_REFERENCE; |
| 628 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 629 | | Identifier { |
| 630 | $$ = asn1p_expr_new(yylineno); |
| 631 | checkmem($$); |
| 632 | $$->Identifier = $1; |
| 633 | $$->expr_type = A1TC_REFERENCE; |
| 634 | } |
| 635 | ; |
| 636 | |
| 637 | ExportsDefinition: |
| 638 | TOK_EXPORTS ExportsBody ';' { |
| 639 | $$ = $2; |
| 640 | } |
| 641 | | TOK_EXPORTS TOK_ALL ';' { |
| 642 | $$ = 0; |
| 643 | } |
| 644 | | TOK_EXPORTS ';' { |
| 645 | /* Empty EXPORTS clause effectively prohibits export. */ |
| 646 | $$ = asn1p_xports_new(); |
| 647 | checkmem($$); |
| 648 | } |
| 649 | ; |
| 650 | |
| 651 | ExportsBody: |
| 652 | ExportsElement { |
| 653 | $$ = asn1p_xports_new(); |
| 654 | assert($$); |
| 655 | TQ_ADD(&($$->members), $1, next); |
| 656 | } |
| 657 | | ExportsBody ',' ExportsElement { |
| 658 | $$ = $1; |
| 659 | TQ_ADD(&($$->members), $3, next); |
| 660 | } |
| 661 | ; |
| 662 | |
| 663 | ExportsElement: |
| 664 | TypeRefName { |
| 665 | $$ = asn1p_expr_new(yylineno); |
| 666 | checkmem($$); |
| 667 | $$->Identifier = $1; |
| 668 | $$->expr_type = A1TC_EXPORTVAR; |
| 669 | } |
vlm | 0aa8690 | 2004-10-12 23:26:53 +0000 | [diff] [blame] | 670 | | TypeRefName '{' '}' { |
| 671 | $$ = asn1p_expr_new(yylineno); |
| 672 | checkmem($$); |
| 673 | $$->Identifier = $1; |
| 674 | $$->expr_type = A1TC_EXPORTVAR; |
| 675 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 676 | | Identifier { |
| 677 | $$ = asn1p_expr_new(yylineno); |
| 678 | checkmem($$); |
| 679 | $$->Identifier = $1; |
| 680 | $$->expr_type = A1TC_EXPORTVAR; |
| 681 | } |
| 682 | ; |
| 683 | |
| 684 | |
| 685 | ValueSetDefinition: |
| 686 | TypeRefName DefinedTypeRef TOK_PPEQ '{' optValueSetBody '}' { |
| 687 | $$ = $2; |
| 688 | assert($$->Identifier == 0); |
| 689 | $$->Identifier = $1; |
| 690 | $$->meta_type = AMT_VALUESET; |
| 691 | // take care of optValueSetBody |
| 692 | } |
| 693 | ; |
| 694 | |
| 695 | DefinedTypeRef: |
| 696 | ComplexTypeReference { |
| 697 | $$ = asn1p_expr_new(yylineno); |
| 698 | checkmem($$); |
| 699 | $$->reference = $1; |
| 700 | $$->expr_type = A1TC_REFERENCE; |
| 701 | $$->meta_type = AMT_TYPEREF; |
| 702 | } |
| 703 | | BasicTypeId { |
| 704 | $$ = asn1p_expr_new(yylineno); |
| 705 | checkmem($$); |
| 706 | $$->expr_type = $1; |
| 707 | $$->meta_type = AMT_TYPE; |
| 708 | } |
| 709 | ; |
| 710 | |
| 711 | optValueSetBody: |
| 712 | { } |
vlm | 39e5ed7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 713 | | ValueSetBody { |
| 714 | } |
| 715 | ; |
| 716 | |
| 717 | /* |
| 718 | * X.680 does not permit ElementSetSpecs starting with ellipsis, |
| 719 | * i.e. (..., A, B). This is very strange: the ElementSetSpecs is used |
| 720 | * inside ValueSet, and ValueSets "in the wild" tend to have the first |
| 721 | * ellipsis. |
| 722 | */ |
| 723 | ValueSetBody: |
| 724 | ValueSetElement { |
| 725 | } |
| 726 | | ValueSetBody ',' ValueSetElement { |
| 727 | } |
| 728 | ; |
| 729 | |
| 730 | ValueSetElement: |
| 731 | TOK_ThreeDots { |
| 732 | } |
| 733 | | ElementSetSpec { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 734 | } |
| 735 | ; |
| 736 | |
| 737 | |
| 738 | /* |
| 739 | * Data Type Reference. |
| 740 | * === EXAMPLE === |
| 741 | * Type3 ::= CHOICE { a Type1, b Type 2 } |
| 742 | * === EOF === |
| 743 | */ |
| 744 | |
| 745 | DataTypeReference: |
| 746 | /* |
| 747 | * Optionally tagged type definition. |
| 748 | */ |
| 749 | TypeRefName TOK_PPEQ optTag TOK_TYPE_IDENTIFIER { |
| 750 | $$ = asn1p_expr_new(yylineno); |
| 751 | checkmem($$); |
| 752 | $$->Identifier = $1; |
| 753 | $$->tag = $3; |
| 754 | $$->expr_type = A1TC_TYPEID; |
| 755 | $$->meta_type = AMT_TYPE; |
| 756 | } |
vlm | fce48a4 | 2004-09-14 02:36:39 +0000 | [diff] [blame] | 757 | | TypeRefName TOK_PPEQ Type { |
| 758 | $$ = $3; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 759 | $$->Identifier = $1; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 760 | assert($$->expr_type); |
| 761 | assert($$->meta_type); |
| 762 | } |
| 763 | | TypeRefName TOK_PPEQ ClassDeclaration { |
| 764 | $$ = $3; |
| 765 | $$->Identifier = $1; |
| 766 | assert($$->expr_type == A1TC_CLASSDEF); |
| 767 | assert($$->meta_type == AMT_OBJECT); |
| 768 | } |
| 769 | /* |
| 770 | * Parametrized <Type> declaration: |
| 771 | * === EXAMPLE === |
| 772 | * SIGNED { ToBeSigned } ::= SEQUENCE { |
| 773 | * toBeSigned ToBeSigned, |
| 774 | * algorithm AlgorithmIdentifier, |
| 775 | * signature BIT STRING |
| 776 | * } |
| 777 | * === EOF === |
| 778 | */ |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 779 | | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 780 | $$ = $6; |
| 781 | assert($$->Identifier == 0); |
| 782 | $$->Identifier = $1; |
| 783 | $$->params = $3; |
| 784 | $$->meta_type = AMT_PARAMTYPE; |
| 785 | } |
| 786 | ; |
| 787 | |
| 788 | ParameterArgumentList: |
| 789 | ParameterArgumentName { |
| 790 | int ret; |
| 791 | $$ = asn1p_paramlist_new(yylineno); |
| 792 | checkmem($$); |
| 793 | ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument); |
| 794 | checkmem(ret == 0); |
| 795 | if($1.governor) asn1p_ref_free($1.governor); |
| 796 | if($1.argument) free($1.argument); |
| 797 | } |
| 798 | | ParameterArgumentList ',' ParameterArgumentName { |
| 799 | int ret; |
| 800 | $$ = $1; |
| 801 | ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument); |
| 802 | checkmem(ret == 0); |
| 803 | if($3.governor) asn1p_ref_free($3.governor); |
| 804 | if($3.argument) free($3.argument); |
| 805 | } |
| 806 | ; |
| 807 | |
| 808 | ParameterArgumentName: |
| 809 | TypeRefName { |
| 810 | $$.governor = NULL; |
| 811 | $$.argument = $1; |
| 812 | } |
| 813 | | TypeRefName ':' Identifier { |
| 814 | int ret; |
| 815 | $$.governor = asn1p_ref_new(yylineno); |
| 816 | ret = asn1p_ref_add_component($$.governor, $1, 0); |
| 817 | checkmem(ret == 0); |
| 818 | $$.argument = $3; |
| 819 | } |
vlm | 4053ca5 | 2005-02-18 16:34:21 +0000 | [diff] [blame] | 820 | | TypeRefName ':' TypeRefName { |
| 821 | int ret; |
| 822 | $$.governor = asn1p_ref_new(yylineno); |
| 823 | ret = asn1p_ref_add_component($$.governor, $1, 0); |
| 824 | checkmem(ret == 0); |
| 825 | $$.argument = $3; |
| 826 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 827 | | BasicTypeId ':' Identifier { |
| 828 | int ret; |
| 829 | $$.governor = asn1p_ref_new(yylineno); |
| 830 | ret = asn1p_ref_add_component($$.governor, |
| 831 | ASN_EXPR_TYPE2STR($1), 1); |
| 832 | checkmem(ret == 0); |
| 833 | $$.argument = $3; |
| 834 | } |
| 835 | ; |
| 836 | |
| 837 | ActualParameterList: |
| 838 | ActualParameter { |
| 839 | $$ = asn1p_expr_new(yylineno); |
| 840 | checkmem($$); |
vlm | 6a02a8a | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 841 | asn1p_expr_add($$, $1); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 842 | } |
| 843 | | ActualParameterList ',' ActualParameter { |
| 844 | $$ = $1; |
vlm | 6a02a8a | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 845 | asn1p_expr_add($$, $3); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 846 | } |
| 847 | ; |
| 848 | |
| 849 | ActualParameter: |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 850 | Type { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 851 | $$ = $1; |
| 852 | } |
| 853 | | Identifier { |
| 854 | $$ = asn1p_expr_new(yylineno); |
| 855 | checkmem($$); |
| 856 | $$->Identifier = $1; |
| 857 | $$->expr_type = A1TC_REFERENCE; |
| 858 | $$->meta_type = AMT_VALUE; |
| 859 | } |
| 860 | ; |
| 861 | |
| 862 | /* |
vlm | 4053ca5 | 2005-02-18 16:34:21 +0000 | [diff] [blame] | 863 | | '{' ActualParameter '}' { |
| 864 | $$ = asn1p_expr_new(yylineno); |
| 865 | checkmem($$); |
| 866 | asn1p_expr_add($$, $2); |
| 867 | $$->expr_type = A1TC_PARAMETRIZED; |
| 868 | $$->meta_type = AMT_TYPE; |
| 869 | } |
| 870 | ; |
| 871 | */ |
| 872 | |
| 873 | /* |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 874 | * A collection of constructed data type members. |
| 875 | */ |
vlm | 0aa8690 | 2004-10-12 23:26:53 +0000 | [diff] [blame] | 876 | optComponentTypeLists: |
| 877 | { $$ = asn1p_expr_new(yylineno); } |
| 878 | | ComponentTypeLists { $$ = $1; }; |
| 879 | |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 880 | ComponentTypeLists: |
| 881 | ComponentType { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 882 | $$ = asn1p_expr_new(yylineno); |
| 883 | checkmem($$); |
vlm | 6a02a8a | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 884 | asn1p_expr_add($$, $1); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 885 | } |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 886 | | ComponentTypeLists ',' ComponentType { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 887 | $$ = $1; |
vlm | 6a02a8a | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 888 | asn1p_expr_add($$, $3); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 889 | } |
| 890 | ; |
| 891 | |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 892 | ComponentType: |
vlm | fce48a4 | 2004-09-14 02:36:39 +0000 | [diff] [blame] | 893 | Identifier Type optMarker { |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 894 | $$ = $2; |
| 895 | assert($$->Identifier == 0); |
vlm | fce48a4 | 2004-09-14 02:36:39 +0000 | [diff] [blame] | 896 | $$->Identifier = $1; |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 897 | $$->marker = $3; |
| 898 | } |
| 899 | | TOK_COMPONENTS TOK_OF Type { |
| 900 | $$ = asn1p_expr_new(yylineno); |
| 901 | checkmem($$); |
| 902 | $$->meta_type = $3->meta_type; |
| 903 | $$->expr_type = A1TC_COMPONENTS_OF; |
vlm | 6a02a8a | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 904 | asn1p_expr_add($$, $3); |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 905 | } |
| 906 | | ExtensionAndException { |
| 907 | $$ = $1; |
| 908 | } |
| 909 | ; |
| 910 | |
| 911 | AlternativeTypeLists: |
| 912 | AlternativeType { |
| 913 | $$ = asn1p_expr_new(yylineno); |
| 914 | checkmem($$); |
vlm | 6a02a8a | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 915 | asn1p_expr_add($$, $1); |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 916 | } |
| 917 | | AlternativeTypeLists ',' AlternativeType { |
| 918 | $$ = $1; |
vlm | 6a02a8a | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 919 | asn1p_expr_add($$, $3); |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 920 | } |
| 921 | ; |
| 922 | |
| 923 | AlternativeType: |
vlm | fce48a4 | 2004-09-14 02:36:39 +0000 | [diff] [blame] | 924 | Identifier Type { |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 925 | $$ = $2; |
| 926 | assert($$->Identifier == 0); |
vlm | fce48a4 | 2004-09-14 02:36:39 +0000 | [diff] [blame] | 927 | $$->Identifier = $1; |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 928 | } |
| 929 | | ExtensionAndException { |
| 930 | $$ = $1; |
| 931 | } |
| 932 | ; |
| 933 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 934 | ClassDeclaration: |
| 935 | TOK_CLASS '{' ClassFieldList '}' optWithSyntax { |
| 936 | $$ = $3; |
| 937 | checkmem($$); |
| 938 | $$->with_syntax = $5; |
| 939 | assert($$->expr_type == A1TC_CLASSDEF); |
| 940 | assert($$->meta_type == AMT_OBJECT); |
| 941 | } |
| 942 | ; |
| 943 | |
| 944 | optUnique: |
| 945 | { $$ = 0; } |
| 946 | | TOK_UNIQUE { $$ = 1; } |
| 947 | ; |
| 948 | |
| 949 | ClassFieldList: |
| 950 | ClassField { |
| 951 | $$ = asn1p_expr_new(yylineno); |
| 952 | checkmem($$); |
| 953 | $$->expr_type = A1TC_CLASSDEF; |
| 954 | $$->meta_type = AMT_OBJECT; |
vlm | 6a02a8a | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 955 | asn1p_expr_add($$, $1); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 956 | } |
| 957 | | ClassFieldList ',' ClassField { |
| 958 | $$ = $1; |
vlm | 6a02a8a | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 959 | asn1p_expr_add($$, $3); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 960 | } |
| 961 | ; |
| 962 | |
| 963 | ClassField: |
| 964 | ClassFieldIdentifier optMarker { |
| 965 | $$ = asn1p_expr_new(yylineno); |
| 966 | checkmem($$); |
| 967 | $$->Identifier = $1.name; |
| 968 | $$->expr_type = A1TC_CLASSFIELD; |
| 969 | $$->meta_type = AMT_OBJECTFIELD; |
| 970 | $$->marker = $2; |
| 971 | } |
vlm | bde35d4 | 2004-11-24 17:43:29 +0000 | [diff] [blame] | 972 | | ClassFieldIdentifier Type optUnique optMarker { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 973 | $$ = $2; |
| 974 | $$->Identifier = $1.name; |
vlm | bde35d4 | 2004-11-24 17:43:29 +0000 | [diff] [blame] | 975 | $$->marker = $4; |
| 976 | $$->unique = $3; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 977 | } |
vlm | bde35d4 | 2004-11-24 17:43:29 +0000 | [diff] [blame] | 978 | | ClassFieldIdentifier ClassFieldIdentifier optUnique optMarker { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 979 | int ret; |
| 980 | $$ = asn1p_expr_new(yylineno); |
| 981 | checkmem($$); |
| 982 | $$->Identifier = $1.name; |
| 983 | $$->reference = asn1p_ref_new(yylineno); |
| 984 | checkmem($$->reference); |
| 985 | ret = asn1p_ref_add_component($$->reference, |
| 986 | $2.name, $2.lex_type); |
| 987 | checkmem(ret == 0); |
| 988 | $$->expr_type = A1TC_CLASSFIELD; |
| 989 | $$->meta_type = AMT_OBJECTFIELD; |
vlm | bde35d4 | 2004-11-24 17:43:29 +0000 | [diff] [blame] | 990 | $$->marker = $4; |
| 991 | $$->unique = $3; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 992 | } |
| 993 | ; |
| 994 | |
| 995 | optWithSyntax: |
| 996 | { $$ = 0; } |
| 997 | | WithSyntax { |
| 998 | $$ = $1; |
| 999 | } |
| 1000 | ; |
| 1001 | |
| 1002 | WithSyntax: |
| 1003 | TOK_WITH TOK_SYNTAX '{' |
| 1004 | { asn1p_lexer_hack_enable_with_syntax(); } |
| 1005 | WithSyntaxFormat |
| 1006 | '}' { |
| 1007 | $$ = $5; |
| 1008 | } |
| 1009 | ; |
| 1010 | |
| 1011 | WithSyntaxFormat: |
| 1012 | WithSyntaxFormatToken { |
| 1013 | $$ = asn1p_wsyntx_new(); |
| 1014 | TQ_ADD(&($$->chunks), $1, next); |
| 1015 | } |
| 1016 | | WithSyntaxFormat WithSyntaxFormatToken { |
| 1017 | $$ = $1; |
| 1018 | TQ_ADD(&($$->chunks), $2, next); |
| 1019 | } |
| 1020 | ; |
| 1021 | |
| 1022 | WithSyntaxFormatToken: |
| 1023 | TOK_opaque { |
| 1024 | $$ = asn1p_wsyntx_chunk_frombuf($1.buf, $1.len, 0); |
| 1025 | } |
| 1026 | | ClassFieldIdentifier { |
| 1027 | asn1p_ref_t *ref; |
| 1028 | int ret; |
| 1029 | ref = asn1p_ref_new(yylineno); |
| 1030 | checkmem(ref); |
| 1031 | ret = asn1p_ref_add_component(ref, $1.name, $1.lex_type); |
| 1032 | checkmem(ret == 0); |
| 1033 | $$ = asn1p_wsyntx_chunk_fromref(ref, 0); |
| 1034 | } |
| 1035 | ; |
| 1036 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1037 | ExtensionAndException: |
| 1038 | TOK_ThreeDots { |
vlm | 39e5ed7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1039 | $$ = asn1p_expr_new(yylineno); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1040 | checkmem($$); |
| 1041 | $$->Identifier = strdup("..."); |
| 1042 | checkmem($$->Identifier); |
| 1043 | $$->expr_type = A1TC_EXTENSIBLE; |
| 1044 | $$->meta_type = AMT_TYPE; |
| 1045 | } |
| 1046 | | TOK_ThreeDots '!' DefinedValue { |
vlm | 39e5ed7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1047 | $$ = asn1p_expr_new(yylineno); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1048 | checkmem($$); |
| 1049 | $$->Identifier = strdup("..."); |
| 1050 | checkmem($$->Identifier); |
| 1051 | $$->value = $3; |
| 1052 | $$->expr_type = A1TC_EXTENSIBLE; |
| 1053 | $$->meta_type = AMT_TYPE; |
| 1054 | } |
| 1055 | | TOK_ThreeDots '!' SignedNumber { |
vlm | 39e5ed7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1056 | $$ = asn1p_expr_new(yylineno); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1057 | checkmem($$); |
| 1058 | $$->Identifier = strdup("..."); |
| 1059 | $$->value = $3; |
| 1060 | checkmem($$->Identifier); |
| 1061 | $$->expr_type = A1TC_EXTENSIBLE; |
| 1062 | $$->meta_type = AMT_TYPE; |
| 1063 | } |
| 1064 | ; |
| 1065 | |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1066 | Type: |
vlm | fce48a4 | 2004-09-14 02:36:39 +0000 | [diff] [blame] | 1067 | optTag TypeDeclaration optConstraints { |
| 1068 | $$ = $2; |
| 1069 | $$->tag = $1; |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1070 | /* |
| 1071 | * Outer constraint for SEQUENCE OF and SET OF applies |
| 1072 | * to the inner type. |
| 1073 | */ |
| 1074 | if($$->expr_type == ASN_CONSTR_SEQUENCE_OF |
| 1075 | || $$->expr_type == ASN_CONSTR_SET_OF) { |
| 1076 | assert(!TQ_FIRST(&($$->members))->constraints); |
vlm | fce48a4 | 2004-09-14 02:36:39 +0000 | [diff] [blame] | 1077 | TQ_FIRST(&($$->members))->constraints = $3; |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1078 | } else { |
| 1079 | if($$->constraints) { |
| 1080 | assert(!$2); |
| 1081 | } else { |
vlm | fce48a4 | 2004-09-14 02:36:39 +0000 | [diff] [blame] | 1082 | $$->constraints = $3; |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1083 | } |
| 1084 | } |
| 1085 | } |
| 1086 | ; |
| 1087 | |
| 1088 | TypeDeclaration: |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1089 | BasicType { |
| 1090 | $$ = $1; |
| 1091 | } |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1092 | | TOK_CHOICE '{' AlternativeTypeLists '}' { |
| 1093 | $$ = $3; |
| 1094 | assert($$->expr_type == A1TC_INVALID); |
| 1095 | $$->expr_type = ASN_CONSTR_CHOICE; |
| 1096 | $$->meta_type = AMT_TYPE; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1097 | } |
vlm | 0aa8690 | 2004-10-12 23:26:53 +0000 | [diff] [blame] | 1098 | | TOK_SEQUENCE '{' optComponentTypeLists '}' { |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1099 | $$ = $3; |
| 1100 | assert($$->expr_type == A1TC_INVALID); |
| 1101 | $$->expr_type = ASN_CONSTR_SEQUENCE; |
| 1102 | $$->meta_type = AMT_TYPE; |
| 1103 | } |
vlm | 0aa8690 | 2004-10-12 23:26:53 +0000 | [diff] [blame] | 1104 | | TOK_SET '{' optComponentTypeLists '}' { |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1105 | $$ = $3; |
| 1106 | assert($$->expr_type == A1TC_INVALID); |
| 1107 | $$->expr_type = ASN_CONSTR_SET; |
| 1108 | $$->meta_type = AMT_TYPE; |
| 1109 | } |
vlm | 151c0b2 | 2004-09-22 16:03:36 +0000 | [diff] [blame] | 1110 | | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration { |
vlm | 39e5ed7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1111 | $$ = asn1p_expr_new(yylineno); |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1112 | checkmem($$); |
| 1113 | $$->constraints = $2; |
| 1114 | $$->expr_type = ASN_CONSTR_SEQUENCE_OF; |
| 1115 | $$->meta_type = AMT_TYPE; |
vlm | 151c0b2 | 2004-09-22 16:03:36 +0000 | [diff] [blame] | 1116 | $6->Identifier = $4; |
| 1117 | $6->tag = $5; |
| 1118 | asn1p_expr_add($$, $6); |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1119 | } |
vlm | 151c0b2 | 2004-09-22 16:03:36 +0000 | [diff] [blame] | 1120 | | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration { |
vlm | 39e5ed7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1121 | $$ = asn1p_expr_new(yylineno); |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1122 | checkmem($$); |
| 1123 | $$->constraints = $2; |
| 1124 | $$->expr_type = ASN_CONSTR_SET_OF; |
| 1125 | $$->meta_type = AMT_TYPE; |
vlm | 151c0b2 | 2004-09-22 16:03:36 +0000 | [diff] [blame] | 1126 | $6->Identifier = $4; |
| 1127 | $6->tag = $5; |
| 1128 | asn1p_expr_add($$, $6); |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1129 | } |
| 1130 | | TOK_ANY { |
vlm | 39e5ed7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1131 | $$ = asn1p_expr_new(yylineno); |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1132 | checkmem($$); |
vlm | 044f744 | 2004-09-04 04:49:21 +0000 | [diff] [blame] | 1133 | $$->expr_type = ASN_TYPE_ANY; |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1134 | $$->meta_type = AMT_TYPE; |
| 1135 | } |
| 1136 | | TOK_ANY TOK_DEFINED TOK_BY Identifier { |
| 1137 | int ret; |
vlm | 39e5ed7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1138 | $$ = asn1p_expr_new(yylineno); |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1139 | checkmem($$); |
| 1140 | $$->reference = asn1p_ref_new(yylineno); |
| 1141 | ret = asn1p_ref_add_component($$->reference, |
| 1142 | $4, RLT_lowercase); |
| 1143 | checkmem(ret == 0); |
vlm | 044f744 | 2004-09-04 04:49:21 +0000 | [diff] [blame] | 1144 | $$->expr_type = ASN_TYPE_ANY; |
vlm | ec8f681 | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1145 | $$->meta_type = AMT_TYPE; |
| 1146 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1147 | /* |
| 1148 | * A parametrized assignment. |
| 1149 | */ |
| 1150 | | TypeRefName '{' ActualParameterList '}' { |
| 1151 | int ret; |
| 1152 | $$ = $3; |
| 1153 | assert($$->expr_type == 0); |
| 1154 | assert($$->meta_type == 0); |
| 1155 | assert($$->reference == 0); |
| 1156 | $$->reference = asn1p_ref_new(yylineno); |
| 1157 | checkmem($$->reference); |
| 1158 | ret = asn1p_ref_add_component($$->reference, $1, RLT_UNKNOWN); |
| 1159 | checkmem(ret == 0); |
| 1160 | free($1); |
| 1161 | $$->expr_type = A1TC_PARAMETRIZED; |
| 1162 | $$->meta_type = AMT_TYPE; |
| 1163 | } |
| 1164 | /* |
| 1165 | * A DefinedType reference. |
| 1166 | * "CLASS1.&id.&id2" |
| 1167 | * or |
| 1168 | * "Module.Type" |
| 1169 | * or |
| 1170 | * "Module.identifier" |
| 1171 | * or |
| 1172 | * "Type" |
| 1173 | */ |
| 1174 | | ComplexTypeReference { |
| 1175 | $$ = asn1p_expr_new(yylineno); |
| 1176 | checkmem($$); |
| 1177 | $$->reference = $1; |
| 1178 | $$->expr_type = A1TC_REFERENCE; |
| 1179 | $$->meta_type = AMT_TYPEREF; |
| 1180 | } |
| 1181 | | TOK_INSTANCE TOK_OF ComplexTypeReference { |
| 1182 | $$ = asn1p_expr_new(yylineno); |
| 1183 | checkmem($$); |
| 1184 | $$->reference = $3; |
| 1185 | $$->expr_type = A1TC_INSTANCE; |
| 1186 | $$->meta_type = AMT_TYPE; |
| 1187 | } |
| 1188 | ; |
| 1189 | |
| 1190 | /* |
| 1191 | * A type name consisting of several components. |
| 1192 | * === EXAMPLE === |
| 1193 | * === EOF === |
| 1194 | */ |
| 1195 | ComplexTypeReference: |
| 1196 | TOK_typereference { |
| 1197 | int ret; |
| 1198 | $$ = asn1p_ref_new(yylineno); |
| 1199 | checkmem($$); |
| 1200 | ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN); |
| 1201 | checkmem(ret == 0); |
| 1202 | free($1); |
| 1203 | } |
| 1204 | | TOK_typereference '.' TypeRefName { |
| 1205 | int ret; |
| 1206 | $$ = asn1p_ref_new(yylineno); |
| 1207 | checkmem($$); |
| 1208 | ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN); |
| 1209 | checkmem(ret == 0); |
| 1210 | ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN); |
| 1211 | checkmem(ret == 0); |
| 1212 | free($1); |
| 1213 | } |
vlm | c94e28f | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1214 | | ObjectClassReference '.' TypeRefName { |
| 1215 | int ret; |
| 1216 | $$ = asn1p_ref_new(yylineno); |
| 1217 | checkmem($$); |
| 1218 | ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN); |
| 1219 | checkmem(ret == 0); |
| 1220 | ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN); |
| 1221 | checkmem(ret == 0); |
| 1222 | free($1); |
| 1223 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1224 | | TOK_typereference '.' Identifier { |
| 1225 | int ret; |
| 1226 | $$ = asn1p_ref_new(yylineno); |
| 1227 | checkmem($$); |
| 1228 | ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN); |
| 1229 | checkmem(ret == 0); |
| 1230 | ret = asn1p_ref_add_component($$, $3, RLT_lowercase); |
| 1231 | checkmem(ret == 0); |
| 1232 | free($1); |
| 1233 | } |
| 1234 | | ObjectClassReference { |
| 1235 | int ret; |
| 1236 | $$ = asn1p_ref_new(yylineno); |
| 1237 | checkmem($$); |
| 1238 | ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS); |
| 1239 | free($1); |
| 1240 | checkmem(ret == 0); |
| 1241 | } |
| 1242 | | ObjectClassReference '.' ComplexTypeReferenceAmpList { |
| 1243 | int ret; |
| 1244 | $$ = $3; |
| 1245 | ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS); |
| 1246 | free($1); |
| 1247 | checkmem(ret == 0); |
| 1248 | /* |
| 1249 | * Move the last element infront. |
| 1250 | */ |
| 1251 | { |
| 1252 | struct asn1p_ref_component_s tmp_comp; |
| 1253 | tmp_comp = $$->components[$$->comp_count-1]; |
| 1254 | memmove(&$$->components[1], |
| 1255 | &$$->components[0], |
| 1256 | sizeof($$->components[0]) |
| 1257 | * ($$->comp_count - 1)); |
| 1258 | $$->components[0] = tmp_comp; |
| 1259 | } |
| 1260 | } |
| 1261 | ; |
| 1262 | |
| 1263 | ComplexTypeReferenceAmpList: |
| 1264 | ComplexTypeReferenceElement { |
| 1265 | int ret; |
| 1266 | $$ = asn1p_ref_new(yylineno); |
| 1267 | checkmem($$); |
| 1268 | ret = asn1p_ref_add_component($$, $1.name, $1.lex_type); |
| 1269 | free($1.name); |
| 1270 | checkmem(ret == 0); |
| 1271 | } |
| 1272 | | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement { |
| 1273 | int ret; |
| 1274 | $$ = $1; |
| 1275 | ret = asn1p_ref_add_component($$, $3.name, $3.lex_type); |
| 1276 | free($3.name); |
| 1277 | checkmem(ret == 0); |
| 1278 | } |
| 1279 | ; |
| 1280 | |
| 1281 | ComplexTypeReferenceElement: ClassFieldName; |
| 1282 | ClassFieldIdentifier: ClassFieldName; |
| 1283 | |
| 1284 | ClassFieldName: |
| 1285 | /* "&Type1" */ |
| 1286 | TOK_typefieldreference { |
| 1287 | $$.lex_type = RLT_AmpUppercase; |
| 1288 | $$.name = $1; |
| 1289 | } |
| 1290 | /* "&id" */ |
| 1291 | | TOK_valuefieldreference { |
| 1292 | $$.lex_type = RLT_Amplowercase; |
| 1293 | $$.name = $1; |
| 1294 | } |
| 1295 | ; |
| 1296 | |
| 1297 | |
| 1298 | /* |
| 1299 | * === EXAMPLE === |
| 1300 | * value INTEGER ::= 1 |
| 1301 | * === EOF === |
| 1302 | */ |
| 1303 | ValueDefinition: |
vlm | c94e28f | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1304 | Identifier DefinedTypeRef TOK_PPEQ Value { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1305 | $$ = $2; |
| 1306 | assert($$->Identifier == NULL); |
| 1307 | $$->Identifier = $1; |
| 1308 | $$->meta_type = AMT_VALUE; |
| 1309 | $$->value = $4; |
| 1310 | } |
| 1311 | ; |
| 1312 | |
vlm | c94e28f | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1313 | Value: |
| 1314 | Identifier ':' Value { |
| 1315 | $$ = asn1p_value_fromint(0); |
| 1316 | checkmem($$); |
| 1317 | $$->type = ATV_CHOICE_IDENTIFIER; |
| 1318 | $$->value.choice_identifier.identifier = $1; |
| 1319 | $$->value.choice_identifier.value = $3; |
| 1320 | } |
| 1321 | | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1322 | $$ = asn1p_value_frombuf($3.buf, $3.len, 0); |
| 1323 | checkmem($$); |
| 1324 | $$->type = ATV_UNPARSED; |
| 1325 | } |
vlm | c94e28f | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1326 | | TOK_NULL { |
| 1327 | $$ = asn1p_value_fromint(0); |
| 1328 | checkmem($$); |
| 1329 | $$->type = ATV_NULL; |
| 1330 | } |
| 1331 | | TOK_FALSE { |
| 1332 | $$ = asn1p_value_fromint(0); |
| 1333 | checkmem($$); |
| 1334 | $$->type = ATV_FALSE; |
| 1335 | } |
| 1336 | | TOK_TRUE { |
| 1337 | $$ = asn1p_value_fromint(0); |
| 1338 | checkmem($$); |
| 1339 | $$->type = ATV_TRUE; |
| 1340 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1341 | | TOK_bstring { |
| 1342 | $$ = _convert_bitstring2binary($1, 'B'); |
| 1343 | checkmem($$); |
| 1344 | } |
| 1345 | | TOK_hstring { |
| 1346 | $$ = _convert_bitstring2binary($1, 'H'); |
| 1347 | checkmem($$); |
| 1348 | } |
| 1349 | | TOK_cstring { |
| 1350 | $$ = asn1p_value_frombuf($1.buf, $1.len, 0); |
| 1351 | checkmem($$); |
| 1352 | } |
| 1353 | | SignedNumber { |
| 1354 | $$ = $1; |
| 1355 | } |
| 1356 | | DefinedValue { |
| 1357 | $$ = $1; |
| 1358 | } |
| 1359 | ; |
| 1360 | |
| 1361 | DefinedValue: |
| 1362 | Identifier { |
| 1363 | asn1p_ref_t *ref; |
| 1364 | int ret; |
| 1365 | ref = asn1p_ref_new(yylineno); |
| 1366 | checkmem(ref); |
| 1367 | ret = asn1p_ref_add_component(ref, $1, RLT_lowercase); |
| 1368 | checkmem(ret == 0); |
| 1369 | $$ = asn1p_value_fromref(ref, 0); |
| 1370 | checkmem($$); |
| 1371 | free($1); |
| 1372 | } |
| 1373 | | TypeRefName '.' Identifier { |
| 1374 | asn1p_ref_t *ref; |
| 1375 | int ret; |
| 1376 | ref = asn1p_ref_new(yylineno); |
| 1377 | checkmem(ref); |
| 1378 | ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN); |
| 1379 | checkmem(ret == 0); |
| 1380 | ret = asn1p_ref_add_component(ref, $3, RLT_lowercase); |
| 1381 | checkmem(ret == 0); |
| 1382 | $$ = asn1p_value_fromref(ref, 0); |
| 1383 | checkmem($$); |
| 1384 | free($1); |
| 1385 | free($3); |
| 1386 | } |
| 1387 | ; |
| 1388 | |
| 1389 | Opaque: |
| 1390 | TOK_opaque { |
| 1391 | $$.len = $1.len + 2; |
| 1392 | $$.buf = malloc($$.len + 1); |
| 1393 | checkmem($$.buf); |
| 1394 | $$.buf[0] = '{'; |
| 1395 | $$.buf[1] = ' '; |
| 1396 | memcpy($$.buf + 2, $1.buf, $1.len); |
| 1397 | $$.buf[$$.len] = '\0'; |
| 1398 | free($1.buf); |
| 1399 | } |
| 1400 | | Opaque TOK_opaque { |
| 1401 | int newsize = $1.len + $2.len; |
| 1402 | char *p = malloc(newsize + 1); |
| 1403 | checkmem(p); |
| 1404 | memcpy(p , $1.buf, $1.len); |
| 1405 | memcpy(p + $1.len, $2.buf, $2.len); |
| 1406 | p[newsize] = '\0'; |
| 1407 | free($1.buf); |
| 1408 | free($2.buf); |
| 1409 | $$.buf = p; |
| 1410 | $$.len = newsize; |
| 1411 | } |
| 1412 | ; |
| 1413 | |
| 1414 | BasicTypeId: |
| 1415 | TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; } |
| 1416 | | TOK_NULL { $$ = ASN_BASIC_NULL; } |
| 1417 | | TOK_REAL { $$ = ASN_BASIC_REAL; } |
| 1418 | | BasicTypeId_UniverationCompatible { $$ = $1; } |
| 1419 | | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; } |
| 1420 | | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; } |
| 1421 | | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; } |
| 1422 | | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; } |
| 1423 | | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; } |
| 1424 | | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; } |
| 1425 | | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; } |
| 1426 | | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; } |
vlm | 5e2c4b9 | 2005-03-20 11:12:40 +0000 | [diff] [blame] | 1427 | | BasicString { $$ = $1; } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1428 | ; |
| 1429 | |
| 1430 | /* |
| 1431 | * A type identifier which may be used with "{ a(1), b(2) }" clause. |
| 1432 | */ |
| 1433 | BasicTypeId_UniverationCompatible: |
| 1434 | TOK_INTEGER { $$ = ASN_BASIC_INTEGER; } |
| 1435 | | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; } |
| 1436 | | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; } |
| 1437 | ; |
| 1438 | |
| 1439 | BasicType: |
| 1440 | BasicTypeId { |
vlm | 39e5ed7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1441 | $$ = asn1p_expr_new(yylineno); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1442 | checkmem($$); |
| 1443 | $$->expr_type = $1; |
| 1444 | $$->meta_type = AMT_TYPE; |
| 1445 | } |
| 1446 | | BasicTypeId_UniverationCompatible UniverationDefinition { |
| 1447 | if($2) { |
| 1448 | $$ = $2; |
| 1449 | } else { |
vlm | 39e5ed7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1450 | $$ = asn1p_expr_new(yylineno); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1451 | checkmem($$); |
| 1452 | } |
| 1453 | $$->expr_type = $1; |
| 1454 | $$->meta_type = AMT_TYPE; |
| 1455 | } |
| 1456 | ; |
| 1457 | |
| 1458 | BasicString: |
| 1459 | TOK_BMPString { $$ = ASN_STRING_BMPString; } |
| 1460 | | TOK_GeneralString { |
| 1461 | $$ = ASN_STRING_GeneralString; |
vlm | c94e28f | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1462 | fprintf(stderr, "WARNING: GeneralString is not fully supported\n"); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1463 | } |
| 1464 | | TOK_GraphicString { |
| 1465 | $$ = ASN_STRING_GraphicString; |
vlm | c94e28f | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1466 | fprintf(stderr, "WARNING: GraphicString is not fully supported\n"); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1467 | } |
| 1468 | | TOK_IA5String { $$ = ASN_STRING_IA5String; } |
| 1469 | | TOK_ISO646String { $$ = ASN_STRING_ISO646String; } |
| 1470 | | TOK_NumericString { $$ = ASN_STRING_NumericString; } |
| 1471 | | TOK_PrintableString { $$ = ASN_STRING_PrintableString; } |
| 1472 | | TOK_T61String { |
| 1473 | $$ = ASN_STRING_T61String; |
vlm | c94e28f | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1474 | fprintf(stderr, "WARNING: T61String is not fully supported\n"); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1475 | } |
| 1476 | | TOK_TeletexString { $$ = ASN_STRING_TeletexString; } |
| 1477 | | TOK_UniversalString { $$ = ASN_STRING_UniversalString; } |
| 1478 | | TOK_UTF8String { $$ = ASN_STRING_UTF8String; } |
| 1479 | | TOK_VideotexString { |
| 1480 | $$ = ASN_STRING_VideotexString; |
vlm | c94e28f | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1481 | fprintf(stderr, "WARNING: VideotexString is not fully supported\n"); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1482 | } |
| 1483 | | TOK_VisibleString { $$ = ASN_STRING_VisibleString; } |
| 1484 | | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; } |
| 1485 | ; |
| 1486 | |
vlm | 5f0128b | 2004-08-20 13:25:29 +0000 | [diff] [blame] | 1487 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1488 | /* |
| 1489 | * Data type constraints. |
| 1490 | */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1491 | Union: '|' | TOK_UNION; |
| 1492 | Intersection: '^' | TOK_INTERSECTION; |
| 1493 | Except: TOK_EXCEPT; |
| 1494 | |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1495 | optConstraints: |
| 1496 | { $$ = 0; } |
vlm | 5f0128b | 2004-08-20 13:25:29 +0000 | [diff] [blame] | 1497 | | Constraints { |
| 1498 | $$ = $1; |
| 1499 | } |
| 1500 | ; |
| 1501 | |
| 1502 | Constraints: |
| 1503 | SetOfConstraints { |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1504 | CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0); |
| 1505 | } |
| 1506 | | TOK_SIZE '(' ElementSetSpecs ')' { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1507 | /* |
| 1508 | * This is a special case, for compatibility purposes. |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1509 | * It goes without parentheses. |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1510 | */ |
vlm | 5f0128b | 2004-08-20 13:25:29 +0000 | [diff] [blame] | 1511 | CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1512 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1513 | ; |
| 1514 | |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1515 | SetOfConstraints: |
| 1516 | '(' ElementSetSpecs ')' { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1517 | $$ = $2; |
| 1518 | } |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1519 | | SetOfConstraints '(' ElementSetSpecs ')' { |
| 1520 | CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3); |
| 1521 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1522 | ; |
| 1523 | |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1524 | ElementSetSpecs: |
| 1525 | ElementSetSpec { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1526 | $$ = $1; |
| 1527 | } |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1528 | | ElementSetSpec ',' TOK_ThreeDots { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1529 | asn1p_constraint_t *ct; |
| 1530 | ct = asn1p_constraint_new(yylineno); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1531 | ct->type = ACT_EL_EXT; |
| 1532 | CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct); |
| 1533 | } |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1534 | | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1535 | asn1p_constraint_t *ct; |
| 1536 | ct = asn1p_constraint_new(yylineno); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1537 | ct->type = ACT_EL_EXT; |
| 1538 | CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct); |
vlm | 6f5eb0b | 2004-08-13 12:35:09 +0000 | [diff] [blame] | 1539 | ct = $$; |
| 1540 | CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1541 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1542 | ; |
| 1543 | |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1544 | ElementSetSpec: |
| 1545 | ConstraintSubtypeElement { |
| 1546 | $$ = $1; |
| 1547 | } |
| 1548 | | ElementSetSpec Union ConstraintSubtypeElement { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1549 | CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3); |
| 1550 | } |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1551 | | ElementSetSpec Intersection ConstraintSubtypeElement { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1552 | CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3); |
| 1553 | } |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1554 | | ConstraintSubtypeElement Except ConstraintSubtypeElement { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1555 | CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3); |
| 1556 | } |
| 1557 | ; |
| 1558 | |
| 1559 | ConstraintSubtypeElement: |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1560 | ConstraintSpec '(' ElementSetSpecs ')' { |
| 1561 | int ret; |
| 1562 | $$ = asn1p_constraint_new(yylineno); |
| 1563 | checkmem($$); |
| 1564 | $$->type = $1; |
| 1565 | ret = asn1p_constraint_insert($$, $3); |
| 1566 | checkmem(ret == 0); |
| 1567 | } |
| 1568 | | '(' ElementSetSpecs ')' { |
| 1569 | int ret; |
| 1570 | $$ = asn1p_constraint_new(yylineno); |
| 1571 | checkmem($$); |
| 1572 | $$->type = ACT_CA_SET; |
| 1573 | ret = asn1p_constraint_insert($$, $2); |
| 1574 | checkmem(ret == 0); |
| 1575 | } |
vlm | a6a12e3 | 2005-03-20 12:58:00 +0000 | [diff] [blame^] | 1576 | | SingleValue { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1577 | $$ = asn1p_constraint_new(yylineno); |
| 1578 | checkmem($$); |
| 1579 | $$->type = ACT_EL_VALUE; |
| 1580 | $$->value = $1; |
| 1581 | } |
vlm | a6a12e3 | 2005-03-20 12:58:00 +0000 | [diff] [blame^] | 1582 | | ContainedSubtype { |
| 1583 | $$ = asn1p_constraint_new(yylineno); |
| 1584 | checkmem($$); |
| 1585 | $$->type = ACT_EL_TYPE; |
| 1586 | $$->containedSubtype = $1; |
| 1587 | } |
| 1588 | | SingleValue ConstraintRangeSpec SingleValue { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1589 | $$ = asn1p_constraint_new(yylineno); |
| 1590 | checkmem($$); |
| 1591 | $$->type = $2; |
| 1592 | $$->range_start = $1; |
| 1593 | $$->range_stop = $3; |
| 1594 | } |
vlm | a6a12e3 | 2005-03-20 12:58:00 +0000 | [diff] [blame^] | 1595 | | TOK_MIN ConstraintRangeSpec SingleValue { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1596 | $$ = asn1p_constraint_new(yylineno); |
| 1597 | checkmem($$); |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1598 | $$->type = $2; |
| 1599 | $$->range_start = asn1p_value_fromint(-123); |
| 1600 | $$->range_stop = $3; |
| 1601 | $$->range_start->type = ATV_MIN; |
| 1602 | } |
vlm | a6a12e3 | 2005-03-20 12:58:00 +0000 | [diff] [blame^] | 1603 | | SingleValue ConstraintRangeSpec TOK_MAX { |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1604 | $$ = asn1p_constraint_new(yylineno); |
| 1605 | checkmem($$); |
| 1606 | $$->type = $2; |
| 1607 | $$->range_start = $1; |
| 1608 | $$->range_stop = asn1p_value_fromint(321); |
| 1609 | $$->range_stop->type = ATV_MAX; |
| 1610 | } |
| 1611 | | TOK_MIN ConstraintRangeSpec TOK_MAX { |
| 1612 | $$ = asn1p_constraint_new(yylineno); |
| 1613 | checkmem($$); |
| 1614 | $$->type = $2; |
| 1615 | $$->range_start = asn1p_value_fromint(-123); |
| 1616 | $$->range_stop = asn1p_value_fromint(321); |
| 1617 | $$->range_start->type = ATV_MIN; |
| 1618 | $$->range_stop->type = ATV_MAX; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1619 | } |
| 1620 | | TableConstraint { |
| 1621 | $$ = $1; |
| 1622 | } |
| 1623 | | WithComponents { |
| 1624 | $$ = $1; |
| 1625 | } |
| 1626 | ; |
| 1627 | |
| 1628 | ConstraintRangeSpec: |
| 1629 | TOK_TwoDots { $$ = ACT_EL_RANGE; } |
| 1630 | | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; } |
| 1631 | | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; } |
| 1632 | | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; } |
| 1633 | ; |
| 1634 | |
| 1635 | ConstraintSpec: |
| 1636 | TOK_SIZE { |
| 1637 | $$ = ACT_CT_SIZE; |
| 1638 | } |
| 1639 | | TOK_FROM { |
| 1640 | $$ = ACT_CT_FROM; |
| 1641 | } |
| 1642 | ; |
| 1643 | |
vlm | a6a12e3 | 2005-03-20 12:58:00 +0000 | [diff] [blame^] | 1644 | SingleValue: |
vlm | 4053ca5 | 2005-02-18 16:34:21 +0000 | [diff] [blame] | 1645 | TOK_FALSE { |
| 1646 | $$ = asn1p_value_fromint(0); |
| 1647 | checkmem($$); |
| 1648 | $$->type = ATV_FALSE; |
| 1649 | } |
| 1650 | | TOK_TRUE { |
| 1651 | $$ = asn1p_value_fromint(1); |
| 1652 | checkmem($$); |
| 1653 | $$->type = ATV_TRUE; |
| 1654 | } |
| 1655 | | SignedNumber { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1656 | $$ = $1; |
| 1657 | } |
vlm | 4053ca5 | 2005-02-18 16:34:21 +0000 | [diff] [blame] | 1658 | | TOK_cstring { |
| 1659 | $$ = asn1p_value_frombuf($1.buf, $1.len, 0); |
| 1660 | checkmem($$); |
| 1661 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1662 | | Identifier { |
| 1663 | asn1p_ref_t *ref; |
| 1664 | int ret; |
| 1665 | ref = asn1p_ref_new(yylineno); |
| 1666 | checkmem(ref); |
| 1667 | ret = asn1p_ref_add_component(ref, $1, RLT_lowercase); |
| 1668 | checkmem(ret == 0); |
| 1669 | $$ = asn1p_value_fromref(ref, 0); |
| 1670 | checkmem($$); |
| 1671 | free($1); |
| 1672 | } |
vlm | a6a12e3 | 2005-03-20 12:58:00 +0000 | [diff] [blame^] | 1673 | ; |
| 1674 | |
| 1675 | ContainedSubtype: |
| 1676 | TypeRefName { |
vlm | 4053ca5 | 2005-02-18 16:34:21 +0000 | [diff] [blame] | 1677 | asn1p_ref_t *ref; |
| 1678 | int ret; |
| 1679 | ref = asn1p_ref_new(yylineno); |
| 1680 | checkmem(ref); |
| 1681 | ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN); |
| 1682 | checkmem(ret == 0); |
| 1683 | $$ = asn1p_value_fromref(ref, 0); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1684 | checkmem($$); |
vlm | 4053ca5 | 2005-02-18 16:34:21 +0000 | [diff] [blame] | 1685 | free($1); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1686 | } |
| 1687 | ; |
| 1688 | |
| 1689 | WithComponents: |
| 1690 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' { |
| 1691 | CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0); |
| 1692 | } |
| 1693 | ; |
| 1694 | |
| 1695 | WithComponentsList: |
| 1696 | WithComponentsElement { |
| 1697 | $$ = $1; |
| 1698 | } |
| 1699 | | WithComponentsList ',' WithComponentsElement { |
| 1700 | CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3); |
| 1701 | } |
| 1702 | ; |
| 1703 | |
| 1704 | WithComponentsElement: |
| 1705 | TOK_ThreeDots { |
| 1706 | $$ = asn1p_constraint_new(yylineno); |
| 1707 | checkmem($$); |
| 1708 | $$->type = ACT_EL_EXT; |
| 1709 | } |
| 1710 | | Identifier optConstraints optPresenceConstraint { |
| 1711 | $$ = asn1p_constraint_new(yylineno); |
| 1712 | checkmem($$); |
| 1713 | $$->type = ACT_EL_VALUE; |
| 1714 | $$->value = asn1p_value_frombuf($1, strlen($1), 0); |
| 1715 | $$->presence = $3; |
| 1716 | } |
| 1717 | ; |
| 1718 | |
| 1719 | /* |
| 1720 | * presence constraint for WithComponents |
| 1721 | */ |
| 1722 | optPresenceConstraint: |
| 1723 | { $$ = ACPRES_DEFAULT; } |
| 1724 | | PresenceConstraint { $$ = $1; } |
| 1725 | ; |
| 1726 | |
| 1727 | PresenceConstraint: |
| 1728 | TOK_PRESENT { |
| 1729 | $$ = ACPRES_PRESENT; |
| 1730 | } |
| 1731 | | TOK_ABSENT { |
| 1732 | $$ = ACPRES_ABSENT; |
| 1733 | } |
| 1734 | | TOK_OPTIONAL { |
| 1735 | $$ = ACPRES_OPTIONAL; |
| 1736 | } |
| 1737 | ; |
| 1738 | |
| 1739 | TableConstraint: |
| 1740 | SimpleTableConstraint { |
| 1741 | $$ = $1; |
| 1742 | } |
| 1743 | | ComponentRelationConstraint { |
| 1744 | $$ = $1; |
| 1745 | } |
| 1746 | ; |
| 1747 | |
| 1748 | /* |
| 1749 | * "{ExtensionSet}" |
| 1750 | */ |
| 1751 | SimpleTableConstraint: |
| 1752 | '{' TypeRefName '}' { |
| 1753 | asn1p_ref_t *ref = asn1p_ref_new(yylineno); |
| 1754 | asn1p_constraint_t *ct; |
| 1755 | int ret; |
| 1756 | ret = asn1p_ref_add_component(ref, $2, 0); |
| 1757 | checkmem(ret == 0); |
| 1758 | ct = asn1p_constraint_new(yylineno); |
| 1759 | checkmem($$); |
| 1760 | ct->type = ACT_EL_VALUE; |
| 1761 | ct->value = asn1p_value_fromref(ref, 0); |
| 1762 | CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0); |
| 1763 | } |
| 1764 | ; |
| 1765 | |
| 1766 | ComponentRelationConstraint: |
| 1767 | SimpleTableConstraint '{' AtNotationList '}' { |
| 1768 | CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3); |
| 1769 | } |
| 1770 | ; |
| 1771 | |
| 1772 | AtNotationList: |
| 1773 | AtNotationElement { |
| 1774 | $$ = asn1p_constraint_new(yylineno); |
| 1775 | checkmem($$); |
| 1776 | $$->type = ACT_EL_VALUE; |
| 1777 | $$->value = asn1p_value_fromref($1, 0); |
| 1778 | } |
| 1779 | | AtNotationList ',' AtNotationElement { |
| 1780 | asn1p_constraint_t *ct; |
| 1781 | ct = asn1p_constraint_new(yylineno); |
| 1782 | checkmem(ct); |
| 1783 | ct->type = ACT_EL_VALUE; |
| 1784 | ct->value = asn1p_value_fromref($3, 0); |
| 1785 | CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct); |
| 1786 | } |
| 1787 | ; |
| 1788 | |
| 1789 | /* |
| 1790 | * @blah |
| 1791 | */ |
| 1792 | AtNotationElement: |
| 1793 | '@' ComponentIdList { |
| 1794 | char *p = malloc(strlen($2) + 2); |
| 1795 | int ret; |
| 1796 | *p = '@'; |
| 1797 | strcpy(p + 1, $2); |
| 1798 | $$ = asn1p_ref_new(yylineno); |
| 1799 | ret = asn1p_ref_add_component($$, p, 0); |
| 1800 | checkmem(ret == 0); |
| 1801 | free(p); |
| 1802 | free($2); |
| 1803 | } |
| 1804 | | '@' '.' ComponentIdList { |
| 1805 | char *p = malloc(strlen($3) + 3); |
| 1806 | int ret; |
| 1807 | p[0] = '@'; |
| 1808 | p[1] = '.'; |
| 1809 | strcpy(p + 2, $3); |
| 1810 | $$ = asn1p_ref_new(yylineno); |
| 1811 | ret = asn1p_ref_add_component($$, p, 0); |
| 1812 | checkmem(ret == 0); |
| 1813 | free(p); |
| 1814 | free($3); |
| 1815 | } |
| 1816 | ; |
| 1817 | |
| 1818 | /* identifier "." ... */ |
| 1819 | ComponentIdList: |
| 1820 | Identifier { |
| 1821 | $$ = $1; |
| 1822 | } |
| 1823 | | ComponentIdList '.' Identifier { |
| 1824 | int l1 = strlen($1); |
| 1825 | int l3 = strlen($3); |
| 1826 | $$ = malloc(l1 + 1 + l3 + 1); |
| 1827 | memcpy($$, $1, l1); |
| 1828 | $$[l1] = '.'; |
| 1829 | memcpy($$ + l1 + 1, $3, l3); |
| 1830 | $$[l1 + 1 + l3] = '\0'; |
| 1831 | } |
| 1832 | ; |
| 1833 | |
| 1834 | |
| 1835 | |
| 1836 | /* |
| 1837 | * MARKERS |
| 1838 | */ |
| 1839 | |
| 1840 | optMarker: |
vlm | c94e28f | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1841 | { |
| 1842 | $$.flags = EM_NOMARK; |
| 1843 | $$.default_value = 0; |
| 1844 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1845 | | Marker { $$ = $1; } |
| 1846 | ; |
| 1847 | |
| 1848 | Marker: |
| 1849 | TOK_OPTIONAL { |
vlm | c94e28f | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1850 | $$.flags = EM_OPTIONAL; |
| 1851 | $$.default_value = 0; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1852 | } |
vlm | c94e28f | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1853 | | TOK_DEFAULT Value { |
| 1854 | $$.flags = EM_DEFAULT; |
| 1855 | $$.default_value = $2; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1856 | } |
| 1857 | ; |
| 1858 | |
| 1859 | /* |
| 1860 | * Universal enumeration definition to use in INTEGER and ENUMERATED. |
| 1861 | * === EXAMPLE === |
| 1862 | * Gender ::= ENUMERATED { unknown(0), male(1), female(2) } |
| 1863 | * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) } |
| 1864 | * === EOF === |
| 1865 | */ |
| 1866 | /* |
| 1867 | optUniverationDefinition: |
| 1868 | { $$ = 0; } |
| 1869 | | UniverationDefinition { |
| 1870 | $$ = $1; |
| 1871 | } |
| 1872 | ; |
| 1873 | */ |
| 1874 | |
| 1875 | UniverationDefinition: |
| 1876 | '{' '}' { |
vlm | 39e5ed7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1877 | $$ = asn1p_expr_new(yylineno); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1878 | checkmem($$); |
| 1879 | } |
| 1880 | | '{' UniverationList '}' { |
| 1881 | $$ = $2; |
| 1882 | } |
| 1883 | ; |
| 1884 | |
| 1885 | UniverationList: |
| 1886 | UniverationElement { |
vlm | 39e5ed7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1887 | $$ = asn1p_expr_new(yylineno); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1888 | checkmem($$); |
vlm | 6a02a8a | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 1889 | asn1p_expr_add($$, $1); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1890 | } |
| 1891 | | UniverationList ',' UniverationElement { |
| 1892 | $$ = $1; |
vlm | 6a02a8a | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 1893 | asn1p_expr_add($$, $3); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1894 | } |
| 1895 | ; |
| 1896 | |
| 1897 | UniverationElement: |
| 1898 | Identifier { |
vlm | 39e5ed7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1899 | $$ = asn1p_expr_new(yylineno); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1900 | checkmem($$); |
| 1901 | $$->expr_type = A1TC_UNIVERVAL; |
| 1902 | $$->meta_type = AMT_VALUE; |
| 1903 | $$->Identifier = $1; |
| 1904 | } |
| 1905 | | Identifier '(' SignedNumber ')' { |
vlm | 39e5ed7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1906 | $$ = asn1p_expr_new(yylineno); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1907 | checkmem($$); |
| 1908 | $$->expr_type = A1TC_UNIVERVAL; |
| 1909 | $$->meta_type = AMT_VALUE; |
| 1910 | $$->Identifier = $1; |
| 1911 | $$->value = $3; |
| 1912 | } |
| 1913 | | Identifier '(' DefinedValue ')' { |
vlm | 39e5ed7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1914 | $$ = asn1p_expr_new(yylineno); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1915 | checkmem($$); |
| 1916 | $$->expr_type = A1TC_UNIVERVAL; |
| 1917 | $$->meta_type = AMT_VALUE; |
| 1918 | $$->Identifier = $1; |
| 1919 | $$->value = $3; |
| 1920 | } |
| 1921 | | SignedNumber { |
vlm | 39e5ed7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1922 | $$ = asn1p_expr_new(yylineno); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1923 | checkmem($$); |
| 1924 | $$->expr_type = A1TC_UNIVERVAL; |
| 1925 | $$->meta_type = AMT_VALUE; |
| 1926 | $$->value = $1; |
| 1927 | } |
| 1928 | | TOK_ThreeDots { |
vlm | 39e5ed7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1929 | $$ = asn1p_expr_new(yylineno); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1930 | checkmem($$); |
| 1931 | $$->Identifier = strdup("..."); |
| 1932 | checkmem($$->Identifier); |
| 1933 | $$->expr_type = A1TC_EXTENSIBLE; |
| 1934 | $$->meta_type = AMT_VALUE; |
| 1935 | } |
| 1936 | ; |
| 1937 | |
| 1938 | SignedNumber: |
| 1939 | TOK_number { |
| 1940 | $$ = asn1p_value_fromint($1); |
| 1941 | checkmem($$); |
| 1942 | } |
| 1943 | | TOK_number_negative { |
| 1944 | $$ = asn1p_value_fromint($1); |
| 1945 | checkmem($$); |
| 1946 | } |
| 1947 | ; |
| 1948 | |
| 1949 | /* |
| 1950 | * SEQUENCE definition. |
| 1951 | * === EXAMPLE === |
| 1952 | * Struct1 ::= SEQUENCE { |
| 1953 | * memb1 Struct2, |
| 1954 | * memb2 SEQUENCE OF { |
| 1955 | * memb2-1 Struct 3 |
| 1956 | * } |
| 1957 | * } |
| 1958 | * === EOF === |
| 1959 | */ |
| 1960 | |
| 1961 | |
| 1962 | |
| 1963 | /* |
| 1964 | * SET definition. |
| 1965 | * === EXAMPLE === |
| 1966 | * Person ::= SET { |
| 1967 | * name [0] PrintableString (SIZE(1..20)), |
| 1968 | * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country, |
| 1969 | * } |
| 1970 | * === EOF === |
| 1971 | */ |
| 1972 | |
| 1973 | optTag: |
| 1974 | { memset(&$$, 0, sizeof($$)); } |
| 1975 | | Tag { $$ = $1; } |
| 1976 | ; |
| 1977 | |
| 1978 | Tag: |
vlm | 2728a8d | 2005-01-23 09:51:44 +0000 | [diff] [blame] | 1979 | TagTypeValue TagPlicit { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1980 | $$ = $1; |
vlm | 2728a8d | 2005-01-23 09:51:44 +0000 | [diff] [blame] | 1981 | $$.tag_mode = $2.tag_mode; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1982 | } |
vlm | 2728a8d | 2005-01-23 09:51:44 +0000 | [diff] [blame] | 1983 | ; |
| 1984 | |
| 1985 | TagTypeValue: |
| 1986 | '[' TagClass TOK_number ']' { |
| 1987 | $$ = $2; |
| 1988 | $$.tag_value = $3; |
| 1989 | }; |
| 1990 | |
| 1991 | TagClass: |
| 1992 | { $$.tag_class = TC_CONTEXT_SPECIFIC; } |
| 1993 | | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; } |
| 1994 | | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; } |
| 1995 | | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; } |
| 1996 | ; |
| 1997 | |
| 1998 | TagPlicit: |
| 1999 | { $$.tag_mode = TM_DEFAULT; } |
| 2000 | | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; } |
| 2001 | | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2002 | ; |
| 2003 | |
| 2004 | TypeRefName: |
| 2005 | TOK_typereference { |
| 2006 | checkmem($1); |
| 2007 | $$ = $1; |
| 2008 | } |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 2009 | | TOK_capitalreference { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2010 | checkmem($1); |
| 2011 | $$ = $1; |
| 2012 | } |
| 2013 | ; |
| 2014 | |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 2015 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2016 | ObjectClassReference: |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 2017 | TOK_capitalreference { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2018 | checkmem($1); |
| 2019 | $$ = $1; |
| 2020 | } |
| 2021 | ; |
| 2022 | |
vlm | 151c0b2 | 2004-09-22 16:03:36 +0000 | [diff] [blame] | 2023 | optIdentifier: |
| 2024 | { $$ = 0; } |
| 2025 | | Identifier { |
| 2026 | $$ = $1; |
| 2027 | } |
| 2028 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2029 | Identifier: |
| 2030 | TOK_identifier { |
| 2031 | checkmem($1); |
| 2032 | $$ = $1; |
| 2033 | } |
| 2034 | ; |
| 2035 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2036 | %% |
| 2037 | |
| 2038 | |
| 2039 | /* |
| 2040 | * Convert Xstring ('0101'B or '5'H) to the binary vector. |
| 2041 | */ |
| 2042 | static asn1p_value_t * |
| 2043 | _convert_bitstring2binary(char *str, int base) { |
| 2044 | asn1p_value_t *val; |
| 2045 | int slen; |
| 2046 | int memlen; |
| 2047 | int baselen; |
| 2048 | int bits; |
| 2049 | uint8_t *binary_vector; |
| 2050 | uint8_t *bv_ptr; |
| 2051 | uint8_t cur_val; |
| 2052 | |
| 2053 | assert(str); |
| 2054 | assert(str[0] == '\''); |
| 2055 | |
| 2056 | switch(base) { |
| 2057 | case 'B': |
| 2058 | baselen = 1; |
| 2059 | break; |
| 2060 | case 'H': |
| 2061 | baselen = 4; |
| 2062 | break; |
| 2063 | default: |
| 2064 | assert(base == 'B' || base == 'H'); |
| 2065 | errno = EINVAL; |
| 2066 | return NULL; |
| 2067 | } |
| 2068 | |
| 2069 | slen = strlen(str); |
| 2070 | assert(str[slen - 1] == base); |
| 2071 | assert(str[slen - 2] == '\''); |
| 2072 | |
| 2073 | memlen = slen / (8 / baselen); /* Conservative estimate */ |
| 2074 | |
| 2075 | bv_ptr = binary_vector = malloc(memlen + 1); |
| 2076 | if(bv_ptr == NULL) |
| 2077 | /* ENOMEM */ |
| 2078 | return NULL; |
| 2079 | |
| 2080 | cur_val = 0; |
| 2081 | bits = 0; |
| 2082 | while(*(++str) != '\'') { |
| 2083 | switch(baselen) { |
| 2084 | case 1: |
| 2085 | switch(*str) { |
| 2086 | case '1': |
| 2087 | cur_val |= 1 << (7 - (bits % 8)); |
| 2088 | case '0': |
| 2089 | break; |
| 2090 | default: |
| 2091 | assert(!"_y UNREACH1"); |
| 2092 | case ' ': case '\r': case '\n': |
| 2093 | continue; |
| 2094 | } |
| 2095 | break; |
| 2096 | case 4: |
| 2097 | switch(*str) { |
| 2098 | case '0': case '1': case '2': case '3': case '4': |
| 2099 | case '5': case '6': case '7': case '8': case '9': |
| 2100 | cur_val |= (*str - '0') << (4 - (bits % 8)); |
| 2101 | break; |
| 2102 | case 'A': case 'B': case 'C': |
| 2103 | case 'D': case 'E': case 'F': |
| 2104 | cur_val |= ((*str - 'A') + 10) |
| 2105 | << (4 - (bits % 8)); |
| 2106 | break; |
| 2107 | default: |
| 2108 | assert(!"_y UNREACH2"); |
| 2109 | case ' ': case '\r': case '\n': |
| 2110 | continue; |
| 2111 | } |
| 2112 | break; |
| 2113 | } |
| 2114 | |
| 2115 | bits += baselen; |
| 2116 | if((bits % 8) == 0) { |
| 2117 | *bv_ptr++ = cur_val; |
| 2118 | cur_val = 0; |
| 2119 | } |
| 2120 | } |
| 2121 | |
| 2122 | *bv_ptr = cur_val; |
| 2123 | assert((bv_ptr - binary_vector) <= memlen); |
| 2124 | |
| 2125 | val = asn1p_value_frombits(binary_vector, bits, 0); |
| 2126 | if(val == NULL) { |
| 2127 | free(binary_vector); |
| 2128 | } |
| 2129 | |
| 2130 | return val; |
| 2131 | } |
| 2132 | |
| 2133 | extern char *asn1p_text; |
| 2134 | |
| 2135 | int |
| 2136 | yyerror(const char *msg) { |
| 2137 | fprintf(stderr, |
| 2138 | "ASN.1 grammar parse error " |
| 2139 | "near line %d (token \"%s\"): %s\n", |
vlm | 39e5ed7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 2140 | yylineno, asn1p_text, msg); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2141 | return -1; |
| 2142 | } |
| 2143 | |
| 2144 | |