blob: c96a1621f9767bea03f0024e39ee4b7cb5efb42b [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001%{
2
3#include <string.h>
4#include <errno.h>
5#include <assert.h>
6
7#include "asn1parser.h"
8#include "asn1p_y.h"
9
10int asn1p_lex(void);
11void asn1p_lexer_hack_push_opaque_state(void); /* Used in .y */
12void asn1p_lexer_hack_enable_with_syntax(void); /* Used in .y */
Lev Walkinf59d0752004-08-18 04:59:12 +000013void asn1p_lexer_hack_push_encoding_control(void); /* Used in .y */
Lev Walkinf15320b2004-06-03 03:38:44 +000014
15#define YY_FATAL_ERROR(msg) do { \
16 fprintf(stderr, \
17 "lexer error at line %d, " \
18 "text \"%s\"\n", \
19 yylineno, yytext); \
20 exit(1); \
21 } while(0)
22
23int asn1p_lexer_pedantic_1990 = 0;
24int asn1p_lexer_types_year = 0;
25int asn1p_lexer_constructs_year = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +000026
Lev Walkin4696c742005-08-22 12:23:54 +000027int asn1p_as_pointer;
28
Lev Walkind370e9f2006-03-16 10:03:35 +000029static asn1c_integer_t _lex_atoi(const char *ptr);
Lev Walkinadf863f2006-09-05 16:18:34 +000030static double _lex_atod(const char *ptr);
Lev Walkind370e9f2006-03-16 10:03:35 +000031
Lev Walkinf15320b2004-06-03 03:38:44 +000032/*
33 * Check that the type is defined in the year of the standard choosen.
34 */
35#define TYPE_LIFETIME(fyr, lyr) \
36 (!asn1p_lexer_types_year \
37 || (fyr && fyr <= asn1p_lexer_types_year) \
38 || (lyr && lyr > asn1p_lexer_types_year))
39
40/*
41 * Check the the construction (or concept, i.e. CLASS) is defined in
42 * a given year.
43 */
44#define CONSTRUCT_LIFETIME(fyr, lyr) \
45 (!asn1p_lexer_constructs_year \
46 || (fyr && fyr <= asn1p_lexer_constructs_year) \
47 || (lyr && lyr > asn1p_lexer_constructs_year))
48
49/*
Lev Walkinf15320b2004-06-03 03:38:44 +000050 * Append quoted string.
51 */
52#define QAPPEND(text, tlen) do { \
53 char *prev_text = asn1p_lval.tv_opaque.buf; \
54 int prev_len = asn1p_lval.tv_opaque.len; \
55 char *p; \
56 \
57 p = malloc((tlen) + prev_len + 1); \
58 if(p == NULL) return -1; \
59 \
60 if(prev_text) memcpy(p, prev_text, prev_len); \
61 memcpy(p + prev_len, text, tlen); \
62 p[prev_len + (tlen)] = '\0'; \
63 \
64 free(asn1p_lval.tv_opaque.buf); \
65 asn1p_lval.tv_opaque.buf = p; \
66 asn1p_lval.tv_opaque.len = (tlen) + prev_len; \
67 } while(0)
68
69%}
70
71%option never-interactive
Lev Walkinf59d0752004-08-18 04:59:12 +000072%option noinput
Lev Walkinf15320b2004-06-03 03:38:44 +000073%option noyywrap stack
74/* Performance penalty is OK */
75%option yylineno
76/* Controlled from within application */
77%option debug
78
79%pointer
80
81%x dash_comment
Lev Walkin2535a692005-07-02 21:42:40 +000082%x idash_comment
Lev Walkinf15320b2004-06-03 03:38:44 +000083%x cpp_comment
84%x quoted
85%x opaque
Lev Walkinf59d0752004-08-18 04:59:12 +000086%x encoding_control
Lev Walkinf15320b2004-06-03 03:38:44 +000087%x with_syntax
88
89/* Newline */
90NL [\r\v\f\n]
91/* White-space */
92WSP [\t\r\v\f\n ]
93
94%%
95
Lev Walkin752e9732017-08-04 02:06:22 -070096<INITIAL>"\xef\xbb\xbf" return UTF8_BOM;
97
Lev Walkin2535a692005-07-02 21:42:40 +000098-{3,}/[\r\n] /* Immediately terminated long comment */
99-{3,}/[^-\r\n] yy_push_state(idash_comment); /* Incorrect, but acceptable */
100<idash_comment>{
101 -{3,} yy_pop_state(); /* Acceptable end of comment */
102}
103
Lev Walkinef625402005-09-05 05:17:57 +0000104--<[ \t]*ASN1C.RepresentAsPointer[ \t]*>-- asn1p_as_pointer = 1;
105
Lev Walkin9d542d22006-03-14 16:31:37 +0000106<INITIAL,with_syntax>-- yy_push_state(dash_comment);
Lev Walkin2535a692005-07-02 21:42:40 +0000107<dash_comment,idash_comment>{
Lev Walkinf15320b2004-06-03 03:38:44 +0000108
109 {NL} yy_pop_state();
110
111 -- yy_pop_state(); /* End of comment */
112 - /* Eat single dash */
Lev Walkinef625402005-09-05 05:17:57 +0000113 [^\r\v\f\n-]+ /* Eat */
Lev Walkinf15320b2004-06-03 03:38:44 +0000114}
Lev Walkin2535a692005-07-02 21:42:40 +0000115
Lev Walkin9d542d22006-03-14 16:31:37 +0000116<INITIAL,cpp_comment,with_syntax>"/*" yy_push_state(cpp_comment);
Lev Walkinf15320b2004-06-03 03:38:44 +0000117<cpp_comment>{
Lev Walkin4696c742005-08-22 12:23:54 +0000118 [^*/<] /* Eat */
Lev Walkinf15320b2004-06-03 03:38:44 +0000119 "*/" yy_pop_state();
120 . /* Eat */
121}
122
123
124 /*
125 * This is state is being set from corresponding .y module when
126 * higher-level data is necessary to make proper parsing of the
127 * underlying data. Thus, we enter the <opaque> state and save
128 * everything for later processing.
129 */
130<opaque>{
131
132 "{" {
133 yy_push_state(opaque);
134 asn1p_lval.tv_opaque.buf = strdup(yytext);
135 asn1p_lval.tv_opaque.len = yyleng;
136 return TOK_opaque;
137 }
138
139 "}" {
140 yy_pop_state();
141 asn1p_lval.tv_opaque.buf = strdup(yytext);
142 asn1p_lval.tv_opaque.len = yyleng;
143 return TOK_opaque;
144 }
145
146 [^{}:=]+ {
147 asn1p_lval.tv_opaque.buf = strdup(yytext);
148 asn1p_lval.tv_opaque.len = yyleng;
149 return TOK_opaque;
150 }
151
152 "::=" {
153 fprintf(stderr,
154 "ASN.1 Parser syncronization failure: "
155 "\"%s\" at line %d must not appear "
156 "inside value definition\n",
157 yytext, yylineno);
158 return -1;
159 }
160
161 [:=] {
162 asn1p_lval.tv_opaque.buf = strdup(yytext);
163 asn1p_lval.tv_opaque.len = yyleng;
164 return TOK_opaque;
165 }
166
167 }
168
169\"[^\"]* {
170 asn1p_lval.tv_opaque.buf = 0;
171 asn1p_lval.tv_opaque.len = 0;
172 QAPPEND(yytext+1, yyleng-1);
173 yy_push_state(quoted);
174 }
175<quoted>{
176
177 \"\" { QAPPEND(yytext, yyleng-1); } /* Add a single quote */
178 [^\"]+ { QAPPEND(yytext, yyleng); }
179
180 \" {
181 yy_pop_state();
182 /* Do not append last quote:
183 // QAPPEND(yytext, yyleng); */
184
185 if(asn1p_lexer_pedantic_1990
186 && strchr(yytext, '\n')) {
187 fprintf(stderr, "%s: "
188 "Newlines are prohibited by ASN.1:1990\n",
189 asn1p_lval.tv_opaque.buf);
190 return -1;
191 }
192
193 return TOK_cstring;
194 }
195
196 }
197
Lev Walkinf59d0752004-08-18 04:59:12 +0000198<encoding_control>{
199 ENCODING-CONTROL {
200 const char *s = "ENCODING-CONTROL";
201 const char *p = s + sizeof("ENCODING-CONTROL") - 2;
202 for(; p >= s; p--) unput(*p);
203 yy_pop_state();
204 }
205 END unput('D'); unput('N'); unput('E'); yy_pop_state();
206 [^{} \t\r\v\f\n]+
207 [[:alnum:]]+
208 . /* Eat everything else */
209 "\n"
210 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000211
212'[0-9A-F \t\r\v\f\n]+'H {
213 /* " \t\r\n" weren't allowed in ASN.1:1990. */
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800214 asn1p_lval.tv_str = strdup(yytext);
Lev Walkinf15320b2004-06-03 03:38:44 +0000215 return TOK_hstring;
216 }
217
218'[01 \t\r\v\f\n]+'B {
219 /* " \t\r\n" weren't allowed in ASN.1:1990. */
220 asn1p_lval.tv_str = strdup(yytext);
221 return TOK_bstring;
222 }
223
224
225-[1-9][0-9]* {
Lev Walkind370e9f2006-03-16 10:03:35 +0000226 asn1p_lval.a_int = _lex_atoi(yytext);
Lev Walkinf15320b2004-06-03 03:38:44 +0000227 if(errno == ERANGE)
228 return -1;
229 return TOK_number_negative;
230 }
231
232[1-9][0-9]* {
Lev Walkind370e9f2006-03-16 10:03:35 +0000233 asn1p_lval.a_int = _lex_atoi(yytext);
Lev Walkinf15320b2004-06-03 03:38:44 +0000234 if(errno == ERANGE)
235 return -1;
236 return TOK_number;
237 }
238
239"0" {
Lev Walkind370e9f2006-03-16 10:03:35 +0000240 asn1p_lval.a_int = _lex_atoi(yytext);
Lev Walkinf15320b2004-06-03 03:38:44 +0000241 if(errno == ERANGE)
242 return -1;
243 return TOK_number;
244 }
245
Lev Walkinadf863f2006-09-05 16:18:34 +0000246[-+]?[0-9]+[.]?([eE][-+]?)?[0-9]+ {
247 asn1p_lval.a_dbl = _lex_atod(yytext);
248 if(errno == ERANGE)
249 return -1;
250 return TOK_realnumber;
251 }
252
Lev Walkinf15320b2004-06-03 03:38:44 +0000253ABSENT return TOK_ABSENT;
Lev Walkinf15320b2004-06-03 03:38:44 +0000254ALL return TOK_ALL;
255ANY {
256 /* Appeared in 1990, removed in 1997 */
257 if(TYPE_LIFETIME(1990, 1997))
258 return TOK_ANY;
259 fprintf(stderr, "Keyword \"%s\" at line %d "
260 "is obsolete\n", yytext, yylineno);
261 REJECT;
262 }
263APPLICATION return TOK_APPLICATION;
264AUTOMATIC return TOK_AUTOMATIC;
265BEGIN return TOK_BEGIN;
266BIT return TOK_BIT;
267BMPString {
268 if(TYPE_LIFETIME(1994, 0))
269 return TOK_BMPString;
270 REJECT;
271 }
272BOOLEAN return TOK_BOOLEAN;
273BY return TOK_BY;
274CHARACTER return TOK_CHARACTER;
275CHOICE return TOK_CHOICE;
276CLASS return TOK_CLASS;
277COMPONENT return TOK_COMPONENT;
278COMPONENTS return TOK_COMPONENTS;
Lev Walkin1893ddf2005-03-20 14:28:32 +0000279CONSTRAINED return TOK_CONSTRAINED;
Lev Walkinf15320b2004-06-03 03:38:44 +0000280CONTAINING return TOK_CONTAINING;
281DEFAULT return TOK_DEFAULT;
282DEFINED {
283 /* Appeared in 1990, removed in 1997 */
284 if(TYPE_LIFETIME(1990, 1997))
285 return TOK_DEFINED;
286 fprintf(stderr, "Keyword \"%s\" at line %d "
287 "is obsolete\n", yytext, yylineno);
288 /* Deprecated since */
289 REJECT;
290 }
291DEFINITIONS return TOK_DEFINITIONS;
292EMBEDDED return TOK_EMBEDDED;
293ENCODED return TOK_ENCODED;
Lev Walkinf59d0752004-08-18 04:59:12 +0000294ENCODING-CONTROL return TOK_ENCODING_CONTROL;
Lev Walkinf15320b2004-06-03 03:38:44 +0000295END return TOK_END;
296ENUMERATED return TOK_ENUMERATED;
297EXCEPT return TOK_EXCEPT;
298EXPLICIT return TOK_EXPLICIT;
299EXPORTS return TOK_EXPORTS;
300EXTENSIBILITY return TOK_EXTENSIBILITY;
301EXTERNAL return TOK_EXTERNAL;
302FALSE return TOK_FALSE;
303FROM return TOK_FROM;
304GeneralizedTime return TOK_GeneralizedTime;
305GeneralString return TOK_GeneralString;
306GraphicString return TOK_GraphicString;
307IA5String return TOK_IA5String;
308IDENTIFIER return TOK_IDENTIFIER;
309IMPLICIT return TOK_IMPLICIT;
310IMPLIED return TOK_IMPLIED;
311IMPORTS return TOK_IMPORTS;
312INCLUDES return TOK_INCLUDES;
313INSTANCE return TOK_INSTANCE;
Lev Walkinf59d0752004-08-18 04:59:12 +0000314INSTRUCTIONS return TOK_INSTRUCTIONS;
Lev Walkinf15320b2004-06-03 03:38:44 +0000315INTEGER return TOK_INTEGER;
316INTERSECTION return TOK_INTERSECTION;
317ISO646String return TOK_ISO646String;
318MAX return TOK_MAX;
319MIN return TOK_MIN;
320MINUS-INFINITY return TOK_MINUS_INFINITY;
321NULL return TOK_NULL;
322NumericString return TOK_NumericString;
323OBJECT return TOK_OBJECT;
324ObjectDescriptor return TOK_ObjectDescriptor;
325OCTET return TOK_OCTET;
326OF return TOK_OF;
327OPTIONAL return TOK_OPTIONAL;
328PATTERN return TOK_PATTERN;
329PDV return TOK_PDV;
330PLUS-INFINITY return TOK_PLUS_INFINITY;
331PRESENT return TOK_PRESENT;
332PrintableString return TOK_PrintableString;
333PRIVATE return TOK_PRIVATE;
334REAL return TOK_REAL;
335RELATIVE-OID return TOK_RELATIVE_OID;
336SEQUENCE return TOK_SEQUENCE;
337SET return TOK_SET;
338SIZE return TOK_SIZE;
339STRING return TOK_STRING;
340SYNTAX return TOK_SYNTAX;
341T61String return TOK_T61String;
342TAGS return TOK_TAGS;
343TeletexString return TOK_TeletexString;
344TRUE return TOK_TRUE;
Lev Walkinf15320b2004-06-03 03:38:44 +0000345UNION return TOK_UNION;
346UNIQUE return TOK_UNIQUE;
347UNIVERSAL return TOK_UNIVERSAL;
348UniversalString {
349 if(TYPE_LIFETIME(1994, 0))
350 return TOK_UniversalString;
351 REJECT;
352 }
353UTCTime return TOK_UTCTime;
354UTF8String {
355 if(TYPE_LIFETIME(1994, 0))
356 return TOK_UTF8String;
357 REJECT;
358 }
359VideotexString return TOK_VideotexString;
360VisibleString return TOK_VisibleString;
361WITH return TOK_WITH;
362
363
Lev Walkin2535a692005-07-02 21:42:40 +0000364<INITIAL,with_syntax>&[A-Z][A-Za-z0-9]*([-][A-Za-z0-9]+)* {
Lev Walkinf15320b2004-06-03 03:38:44 +0000365 asn1p_lval.tv_str = strdup(yytext);
366 return TOK_typefieldreference;
367 }
368
Lev Walkin2535a692005-07-02 21:42:40 +0000369<INITIAL,with_syntax>&[a-z][a-zA-Z0-9]*([-][a-zA-Z0-9]+)* {
Lev Walkinf15320b2004-06-03 03:38:44 +0000370 asn1p_lval.tv_str = strdup(yytext);
371 return TOK_valuefieldreference;
372 }
373
374
Lev Walkin2535a692005-07-02 21:42:40 +0000375[a-z][a-zA-Z0-9]*([-][a-zA-Z0-9]+)* {
Lev Walkinf15320b2004-06-03 03:38:44 +0000376 asn1p_lval.tv_str = strdup(yytext);
377 return TOK_identifier;
378 }
379
380 /*
381 * objectclassreference
382 */
Lev Walkin2535a692005-07-02 21:42:40 +0000383[A-Z][A-Z0-9]*([-][A-Z0-9]+)* {
Lev Walkinf15320b2004-06-03 03:38:44 +0000384 asn1p_lval.tv_str = strdup(yytext);
Lev Walkinf59d0752004-08-18 04:59:12 +0000385 return TOK_capitalreference;
Lev Walkinf15320b2004-06-03 03:38:44 +0000386 }
387
388 /*
389 * typereference, modulereference
390 * NOTE: TOK_objectclassreference must be combined
391 * with this token to produce true typereference.
392 */
Lev Walkin2535a692005-07-02 21:42:40 +0000393[A-Z][A-Za-z0-9]*([-][A-Za-z0-9]+)* {
Lev Walkinf15320b2004-06-03 03:38:44 +0000394 asn1p_lval.tv_str = strdup(yytext);
395 return TOK_typereference;
396 }
397
398"::=" return TOK_PPEQ;
399
400"..." return TOK_ThreeDots;
401".." return TOK_TwoDots;
402
Lev Walkinf15320b2004-06-03 03:38:44 +0000403<with_syntax>{
404
Lev Walkin9d542d22006-03-14 16:31:37 +0000405 [A-Z][A-Za-z0-9]*([-][A-Za-z0-9]+)* {
406 asn1p_lval.tv_str = strdup(yytext);
407 return TOK_Literal;
Lev Walkinf15320b2004-06-03 03:38:44 +0000408 }
409
Lev Walkin9d542d22006-03-14 16:31:37 +0000410 "," {
411 asn1p_lval.tv_str = strdup(yytext);
412 return TOK_Literal;
413 }
414
415 "{" {
416 yy_push_state(with_syntax);
417 asn1p_lval.tv_str = strdup(yytext);
418 return TOK_Literal;
419 }
420
421 "[" return '[';
422 "]" return ']';
423
Lev Walkinf15320b2004-06-03 03:38:44 +0000424 {WSP}+ {
425 asn1p_lval.tv_opaque.buf = strdup(yytext);
426 asn1p_lval.tv_opaque.len = yyleng;
Lev Walkin57074f12006-03-16 05:11:14 +0000427 return TOK_whitespace;
Lev Walkinf15320b2004-06-03 03:38:44 +0000428 }
429
430 "}" {
431 yy_pop_state();
Lev Walkin9d542d22006-03-14 16:31:37 +0000432 if(YYSTATE == with_syntax) {
433 asn1p_lval.tv_str = strdup(yytext);
434 return TOK_Literal;
435 } else {
436 return '}';
437 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000438 }
439
440}
441
Lev Walkind9574ae2005-03-24 16:22:35 +0000442
443{WSP}+ /* Ignore whitespace */
444
445
446[{][\t\r\v\f\n ]*[0-7][,][\t\r\v\f\n ]*[0-9]+[\t\r\v\f\n ]*[}] {
447 asn1c_integer_t v1 = -1, v2 = -1;
448 char *p;
449 for(p = yytext; *p; p++)
450 if(*p >= '0' && *p <= '9')
Lev Walkind370e9f2006-03-16 10:03:35 +0000451 { v1 = _lex_atoi(p); break; }
Lev Walkind9574ae2005-03-24 16:22:35 +0000452 while(*p >= '0' && *p <= '9') p++; /* Skip digits */
453 for(; *p; p++) if(*p >= '0' && *p <= '9')
Lev Walkind370e9f2006-03-16 10:03:35 +0000454 { v2 = _lex_atoi(p); break; }
Lev Walkind9574ae2005-03-24 16:22:35 +0000455 if(v1 < 0 || v1 > 7) {
456 fprintf(stderr, "%s at line %d: X.680:2003, #37.14 "
457 "mandates 0..7 range for Tuple's TableColumn\n",
458 yytext, yylineno);
459 return -1;
460 }
461 if(v2 < 0 || v2 > 15) {
462 fprintf(stderr, "%s at line %d: X.680:2003, #37.14 "
463 "mandates 0..15 range for Tuple's TableRow\n",
464 yytext, yylineno);
465 return -1;
466 }
467 asn1p_lval.a_int = (v1 << 4) + v2;
468 return TOK_tuple;
469 }
470
471[{][\t\r\v\f\n ]*[0-9]+[,][\t\r\v\f\n ]*[0-9]+[,][\t\r\v\f\n ]*[0-9]+[,][\t\r\v\f\n ]*[0-9]+[\t\r\v\f\n ]*[}] {
472 asn1c_integer_t v1 = -1, v2 = -1, v3 = -1, v4 = -1;
473 char *p;
474 for(p = yytext; *p; p++)
475 if(*p >= '0' && *p <= '9')
Lev Walkind370e9f2006-03-16 10:03:35 +0000476 { v1 = _lex_atoi(p); break; }
Lev Walkind9574ae2005-03-24 16:22:35 +0000477 while(*p >= '0' && *p <= '9') p++; /* Skip digits */
478 for(; *p; p++) if(*p >= '0' && *p <= '9')
Lev Walkind370e9f2006-03-16 10:03:35 +0000479 { v2 = _lex_atoi(p); break; }
Lev Walkind9574ae2005-03-24 16:22:35 +0000480 while(*p >= '0' && *p <= '9') p++;
481 for(; *p; p++) if(*p >= '0' && *p <= '9')
Lev Walkind370e9f2006-03-16 10:03:35 +0000482 { v3 = _lex_atoi(p); break; }
Lev Walkind9574ae2005-03-24 16:22:35 +0000483 while(*p >= '0' && *p <= '9') p++;
484 for(; *p; p++) if(*p >= '0' && *p <= '9')
Lev Walkind370e9f2006-03-16 10:03:35 +0000485 { v4 = _lex_atoi(p); break; }
Lev Walkind9574ae2005-03-24 16:22:35 +0000486 if(v1 < 0 || v1 > 127) {
487 fprintf(stderr, "%s at line %d: X.680:2003, #37.12 "
488 "mandates 0..127 range for Quadruple's Group\n",
489 yytext, yylineno);
490 return -1;
491 }
492 if(v2 < 0 || v2 > 255) {
493 fprintf(stderr, "%s at line %d: X.680:2003, #37.12 "
494 "mandates 0..255 range for Quadruple's Plane\n",
495 yytext, yylineno);
496 return -1;
497 }
498 if(v3 < 0 || v3 > 255) {
499 fprintf(stderr, "%s at line %d: X.680:2003, #37.12 "
500 "mandates 0..255 range for Quadruple's Row\n",
501 yytext, yylineno);
502 return -1;
503 }
504 if(v4 < 0 || v4 > 255) {
505 fprintf(stderr, "%s at line %d: X.680:2003, #37.12 "
506 "mandates 0..255 range for Quadruple's Cell\n",
507 yytext, yylineno);
508 return -1;
509 }
510 asn1p_lval.a_int = (v1 << 24) | (v2 << 16) | (v3 << 8) | v4;
511 return TOK_quadruple;
512 }
513
514
Lev Walkin0e90aa02013-03-19 16:17:13 -0700515"[[" return TOK_VBracketLeft;
516"]]" return TOK_VBracketRight;
517
Lev Walkind9574ae2005-03-24 16:22:35 +0000518[(){},;:|!.&@\[\]^] return yytext[0];
519
520[^A-Za-z0-9:=,{}<.@()[]'\"|&^*;!-] {
521 if(TYPE_LIFETIME(1994, 0))
522 fprintf(stderr, "ERROR: ");
523 fprintf(stderr,
524 "Symbol '%c' at line %d is prohibited "
525 "by ASN.1:1994 and ASN.1:1997\n",
526 yytext[0], yylineno);
527 if(TYPE_LIFETIME(1994, 0))
528 return -1;
529 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000530
531<*>. {
532 fprintf(stderr,
533 "Unexpected token at line %d: \"%s\"\n",
534 yylineno, yytext);
535 while(YYSTATE != INITIAL)
536 yy_pop_state();
Lev Walkin9c974182004-09-15 11:59:51 +0000537 if(0) {
538 yy_top_state(); /* Just to use this function. */
539 yy_fatal_error("Parse error");
540 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000541 return -1;
542}
543
544<*><<EOF>> {
545 while(YYSTATE != INITIAL)
546 yy_pop_state();
547 yyterminate();
548 }
549
550
551%%
552
553/*
554 * Very dirty but wonderful hack allowing to rule states from within .y file.
555 */
Lev Walkinf59d0752004-08-18 04:59:12 +0000556void asn1p_lexer_hack_push_opaque_state() { yy_push_state(opaque); }
Lev Walkinf15320b2004-06-03 03:38:44 +0000557
558/*
559 * Another hack which disables recognizing some tokens when inside WITH SYNTAX.
560 */
Lev Walkinf59d0752004-08-18 04:59:12 +0000561void asn1p_lexer_hack_enable_with_syntax() { yy_push_state(with_syntax); }
562
563/* Yet another */
564void asn1p_lexer_hack_push_encoding_control() {
565 yy_push_state(encoding_control);
Lev Walkinf15320b2004-06-03 03:38:44 +0000566}
567
Lev Walkinc603f102005-01-23 09:51:44 +0000568static asn1c_integer_t
Lev Walkind370e9f2006-03-16 10:03:35 +0000569_lex_atoi(const char *ptr) {
Lev Walkinc603f102005-01-23 09:51:44 +0000570 asn1c_integer_t value;
Lev Walkind370e9f2006-03-16 10:03:35 +0000571 if(asn1p_atoi(ptr, &value)) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000572 fprintf(stderr,
573 "Value \"%s\" at line %d is too large "
Lev Walkin129a79e2005-04-05 08:46:22 +0000574 "for this compiler! Please contact the asn1c author.\n",
Lev Walkinf15320b2004-06-03 03:38:44 +0000575 ptr, yylineno);
Lev Walkind370e9f2006-03-16 10:03:35 +0000576 errno = ERANGE;
Lev Walkinf15320b2004-06-03 03:38:44 +0000577 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000578 return value;
579}
Lev Walkinadf863f2006-09-05 16:18:34 +0000580
581static double
582_lex_atod(const char *ptr) {
583 double value;
584 errno = 0;
585 value = strtod(ptr, 0);
586 if(errno) {
587 fprintf(stderr,
588 "Value \"%s\" at line %d is outside of `double` range "
589 "in this compiler! Please contact the asn1c author.\n",
590 ptr, yylineno);
591 errno = ERANGE;
592 }
593 return value;
594}
595