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