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