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