blob: 7757216312f04dc09e2d3a45135ba47991a9390e [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 Walkinbe518fa2017-09-07 02:05:28 -070026int asn1p_lexer_extended_values = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +000027
Lev Walkin4696c742005-08-22 12:23:54 +000028int asn1p_as_pointer;
29
Lev Walkind370e9f2006-03-16 10:03:35 +000030static asn1c_integer_t _lex_atoi(const char *ptr);
Lev Walkinadf863f2006-09-05 16:18:34 +000031static double _lex_atod(const char *ptr);
Lev Walkind370e9f2006-03-16 10:03:35 +000032
Lev Walkinf15320b2004-06-03 03:38:44 +000033/*
34 * Check that the type is defined in the year of the standard choosen.
35 */
36#define TYPE_LIFETIME(fyr, lyr) \
37 (!asn1p_lexer_types_year \
38 || (fyr && fyr <= asn1p_lexer_types_year) \
39 || (lyr && lyr > asn1p_lexer_types_year))
40
41/*
42 * Check the the construction (or concept, i.e. CLASS) is defined in
43 * a given year.
44 */
45#define CONSTRUCT_LIFETIME(fyr, lyr) \
46 (!asn1p_lexer_constructs_year \
47 || (fyr && fyr <= asn1p_lexer_constructs_year) \
48 || (lyr && lyr > asn1p_lexer_constructs_year))
49
50/*
Lev Walkinf15320b2004-06-03 03:38:44 +000051 * Append quoted string.
52 */
53#define QAPPEND(text, tlen) do { \
54 char *prev_text = asn1p_lval.tv_opaque.buf; \
55 int prev_len = asn1p_lval.tv_opaque.len; \
56 char *p; \
57 \
58 p = malloc((tlen) + prev_len + 1); \
59 if(p == NULL) return -1; \
60 \
61 if(prev_text) memcpy(p, prev_text, prev_len); \
62 memcpy(p + prev_len, text, tlen); \
63 p[prev_len + (tlen)] = '\0'; \
64 \
65 free(asn1p_lval.tv_opaque.buf); \
66 asn1p_lval.tv_opaque.buf = p; \
67 asn1p_lval.tv_opaque.len = (tlen) + prev_len; \
68 } while(0)
69
70%}
71
72%option never-interactive
Lev Walkinf59d0752004-08-18 04:59:12 +000073%option noinput
Lev Walkinf15320b2004-06-03 03:38:44 +000074%option noyywrap stack
75/* Performance penalty is OK */
76%option yylineno
77/* Controlled from within application */
78%option debug
79
80%pointer
81
82%x dash_comment
Lev Walkin2535a692005-07-02 21:42:40 +000083%x idash_comment
Lev Walkinf15320b2004-06-03 03:38:44 +000084%x cpp_comment
85%x quoted
86%x opaque
Lev Walkinf59d0752004-08-18 04:59:12 +000087%x encoding_control
Lev Walkinf15320b2004-06-03 03:38:44 +000088%x with_syntax
Lev Walkinbe518fa2017-09-07 02:05:28 -070089%x extended_values
Lev Walkinf15320b2004-06-03 03:38:44 +000090
91/* Newline */
92NL [\r\v\f\n]
93/* White-space */
94WSP [\t\r\v\f\n ]
95
96%%
97
Lev Walkin752e9732017-08-04 02:06:22 -070098<INITIAL>"\xef\xbb\xbf" return UTF8_BOM;
99
Lev Walkin2535a692005-07-02 21:42:40 +0000100-{3,}/[\r\n] /* Immediately terminated long comment */
101-{3,}/[^-\r\n] yy_push_state(idash_comment); /* Incorrect, but acceptable */
102<idash_comment>{
103 -{3,} yy_pop_state(); /* Acceptable end of comment */
104}
105
Lev Walkinef625402005-09-05 05:17:57 +0000106--<[ \t]*ASN1C.RepresentAsPointer[ \t]*>-- asn1p_as_pointer = 1;
107
Lev Walkinbe518fa2017-09-07 02:05:28 -0700108<extended_values>{
109 "#BIT STRING" {
110 yy_pop_state();
111 return TOK_ExtValue_BIT_STRING;
112 }
113}
114
Lev Walkin9d542d22006-03-14 16:31:37 +0000115<INITIAL,with_syntax>-- yy_push_state(dash_comment);
Lev Walkin2535a692005-07-02 21:42:40 +0000116<dash_comment,idash_comment>{
Lev Walkinf15320b2004-06-03 03:38:44 +0000117
118 {NL} yy_pop_state();
119
120 -- yy_pop_state(); /* End of comment */
121 - /* Eat single dash */
Lev Walkinef625402005-09-05 05:17:57 +0000122 [^\r\v\f\n-]+ /* Eat */
Lev Walkinf15320b2004-06-03 03:38:44 +0000123}
Lev Walkin2535a692005-07-02 21:42:40 +0000124
Lev Walkin9d542d22006-03-14 16:31:37 +0000125<INITIAL,cpp_comment,with_syntax>"/*" yy_push_state(cpp_comment);
Lev Walkinf15320b2004-06-03 03:38:44 +0000126<cpp_comment>{
Lev Walkin4696c742005-08-22 12:23:54 +0000127 [^*/<] /* Eat */
Lev Walkinf15320b2004-06-03 03:38:44 +0000128 "*/" yy_pop_state();
129 . /* Eat */
130}
131
132
133 /*
134 * This is state is being set from corresponding .y module when
135 * higher-level data is necessary to make proper parsing of the
136 * underlying data. Thus, we enter the <opaque> state and save
137 * everything for later processing.
138 */
139<opaque>{
140
141 "{" {
142 yy_push_state(opaque);
143 asn1p_lval.tv_opaque.buf = strdup(yytext);
144 asn1p_lval.tv_opaque.len = yyleng;
145 return TOK_opaque;
146 }
147
148 "}" {
149 yy_pop_state();
150 asn1p_lval.tv_opaque.buf = strdup(yytext);
151 asn1p_lval.tv_opaque.len = yyleng;
152 return TOK_opaque;
153 }
154
155 [^{}:=]+ {
156 asn1p_lval.tv_opaque.buf = strdup(yytext);
157 asn1p_lval.tv_opaque.len = yyleng;
158 return TOK_opaque;
159 }
160
161 "::=" {
162 fprintf(stderr,
Lev Walkinbf979152017-09-07 23:36:11 -0700163 "ASN.1 Parser synchronization failure: "
Lev Walkinf15320b2004-06-03 03:38:44 +0000164 "\"%s\" at line %d must not appear "
165 "inside value definition\n",
166 yytext, yylineno);
167 return -1;
168 }
169
170 [:=] {
171 asn1p_lval.tv_opaque.buf = strdup(yytext);
172 asn1p_lval.tv_opaque.len = yyleng;
173 return TOK_opaque;
174 }
175
176 }
177
178\"[^\"]* {
179 asn1p_lval.tv_opaque.buf = 0;
180 asn1p_lval.tv_opaque.len = 0;
181 QAPPEND(yytext+1, yyleng-1);
182 yy_push_state(quoted);
183 }
184<quoted>{
185
186 \"\" { QAPPEND(yytext, yyleng-1); } /* Add a single quote */
187 [^\"]+ { QAPPEND(yytext, yyleng); }
188
189 \" {
190 yy_pop_state();
191 /* Do not append last quote:
192 // QAPPEND(yytext, yyleng); */
193
194 if(asn1p_lexer_pedantic_1990
195 && strchr(yytext, '\n')) {
196 fprintf(stderr, "%s: "
197 "Newlines are prohibited by ASN.1:1990\n",
198 asn1p_lval.tv_opaque.buf);
199 return -1;
200 }
201
202 return TOK_cstring;
203 }
204
205 }
206
Lev Walkinf59d0752004-08-18 04:59:12 +0000207<encoding_control>{
208 ENCODING-CONTROL {
209 const char *s = "ENCODING-CONTROL";
210 const char *p = s + sizeof("ENCODING-CONTROL") - 2;
211 for(; p >= s; p--) unput(*p);
212 yy_pop_state();
213 }
214 END unput('D'); unput('N'); unput('E'); yy_pop_state();
215 [^{} \t\r\v\f\n]+
216 [[:alnum:]]+
217 . /* Eat everything else */
218 "\n"
219 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000220
221'[0-9A-F \t\r\v\f\n]+'H {
222 /* " \t\r\n" weren't allowed in ASN.1:1990. */
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800223 asn1p_lval.tv_str = strdup(yytext);
Lev Walkinf15320b2004-06-03 03:38:44 +0000224 return TOK_hstring;
225 }
226
227'[01 \t\r\v\f\n]+'B {
228 /* " \t\r\n" weren't allowed in ASN.1:1990. */
229 asn1p_lval.tv_str = strdup(yytext);
230 return TOK_bstring;
231 }
232
233
234-[1-9][0-9]* {
Lev Walkind370e9f2006-03-16 10:03:35 +0000235 asn1p_lval.a_int = _lex_atoi(yytext);
Lev Walkinf15320b2004-06-03 03:38:44 +0000236 if(errno == ERANGE)
237 return -1;
238 return TOK_number_negative;
239 }
240
241[1-9][0-9]* {
Lev Walkind370e9f2006-03-16 10:03:35 +0000242 asn1p_lval.a_int = _lex_atoi(yytext);
Lev Walkinf15320b2004-06-03 03:38:44 +0000243 if(errno == ERANGE)
244 return -1;
245 return TOK_number;
246 }
247
248"0" {
Lev Walkind370e9f2006-03-16 10:03:35 +0000249 asn1p_lval.a_int = _lex_atoi(yytext);
Lev Walkinf15320b2004-06-03 03:38:44 +0000250 if(errno == ERANGE)
251 return -1;
252 return TOK_number;
253 }
254
Lev Walkinadf863f2006-09-05 16:18:34 +0000255[-+]?[0-9]+[.]?([eE][-+]?)?[0-9]+ {
256 asn1p_lval.a_dbl = _lex_atod(yytext);
257 if(errno == ERANGE)
258 return -1;
259 return TOK_realnumber;
260 }
261
Lev Walkinf15320b2004-06-03 03:38:44 +0000262ABSENT return TOK_ABSENT;
Lev Walkinf15320b2004-06-03 03:38:44 +0000263ALL return TOK_ALL;
264ANY {
265 /* Appeared in 1990, removed in 1997 */
266 if(TYPE_LIFETIME(1990, 1997))
267 return TOK_ANY;
268 fprintf(stderr, "Keyword \"%s\" at line %d "
269 "is obsolete\n", yytext, yylineno);
270 REJECT;
271 }
272APPLICATION return TOK_APPLICATION;
273AUTOMATIC return TOK_AUTOMATIC;
Lev Walkinbe518fa2017-09-07 02:05:28 -0700274BEGIN {
275 if(asn1p_lexer_extended_values) {
276 yy_push_state(extended_values);
277 }
278 return TOK_BEGIN;
279 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000280BIT return TOK_BIT;
281BMPString {
282 if(TYPE_LIFETIME(1994, 0))
283 return TOK_BMPString;
284 REJECT;
285 }
286BOOLEAN return TOK_BOOLEAN;
287BY return TOK_BY;
288CHARACTER return TOK_CHARACTER;
289CHOICE return TOK_CHOICE;
290CLASS return TOK_CLASS;
291COMPONENT return TOK_COMPONENT;
292COMPONENTS return TOK_COMPONENTS;
Lev Walkin1893ddf2005-03-20 14:28:32 +0000293CONSTRAINED return TOK_CONSTRAINED;
Lev Walkinf15320b2004-06-03 03:38:44 +0000294CONTAINING return TOK_CONTAINING;
295DEFAULT return TOK_DEFAULT;
296DEFINED {
297 /* Appeared in 1990, removed in 1997 */
298 if(TYPE_LIFETIME(1990, 1997))
299 return TOK_DEFINED;
300 fprintf(stderr, "Keyword \"%s\" at line %d "
301 "is obsolete\n", yytext, yylineno);
302 /* Deprecated since */
303 REJECT;
304 }
305DEFINITIONS return TOK_DEFINITIONS;
306EMBEDDED return TOK_EMBEDDED;
307ENCODED return TOK_ENCODED;
Lev Walkinf59d0752004-08-18 04:59:12 +0000308ENCODING-CONTROL return TOK_ENCODING_CONTROL;
Lev Walkinbe518fa2017-09-07 02:05:28 -0700309END {
310 if(YYSTATE == extended_values) {
311 yy_pop_state();
312 }
313 return TOK_END;
314 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000315ENUMERATED return TOK_ENUMERATED;
316EXCEPT return TOK_EXCEPT;
317EXPLICIT return TOK_EXPLICIT;
318EXPORTS return TOK_EXPORTS;
319EXTENSIBILITY return TOK_EXTENSIBILITY;
320EXTERNAL return TOK_EXTERNAL;
321FALSE return TOK_FALSE;
322FROM return TOK_FROM;
323GeneralizedTime return TOK_GeneralizedTime;
324GeneralString return TOK_GeneralString;
325GraphicString return TOK_GraphicString;
326IA5String return TOK_IA5String;
327IDENTIFIER return TOK_IDENTIFIER;
328IMPLICIT return TOK_IMPLICIT;
329IMPLIED return TOK_IMPLIED;
330IMPORTS return TOK_IMPORTS;
331INCLUDES return TOK_INCLUDES;
332INSTANCE return TOK_INSTANCE;
Lev Walkinf59d0752004-08-18 04:59:12 +0000333INSTRUCTIONS return TOK_INSTRUCTIONS;
Lev Walkinf15320b2004-06-03 03:38:44 +0000334INTEGER return TOK_INTEGER;
335INTERSECTION return TOK_INTERSECTION;
336ISO646String return TOK_ISO646String;
337MAX return TOK_MAX;
338MIN return TOK_MIN;
339MINUS-INFINITY return TOK_MINUS_INFINITY;
340NULL return TOK_NULL;
341NumericString return TOK_NumericString;
342OBJECT return TOK_OBJECT;
343ObjectDescriptor return TOK_ObjectDescriptor;
344OCTET return TOK_OCTET;
345OF return TOK_OF;
346OPTIONAL return TOK_OPTIONAL;
347PATTERN return TOK_PATTERN;
348PDV return TOK_PDV;
349PLUS-INFINITY return TOK_PLUS_INFINITY;
350PRESENT return TOK_PRESENT;
351PrintableString return TOK_PrintableString;
352PRIVATE return TOK_PRIVATE;
353REAL return TOK_REAL;
354RELATIVE-OID return TOK_RELATIVE_OID;
355SEQUENCE return TOK_SEQUENCE;
356SET return TOK_SET;
357SIZE return TOK_SIZE;
358STRING return TOK_STRING;
359SYNTAX return TOK_SYNTAX;
360T61String return TOK_T61String;
361TAGS return TOK_TAGS;
362TeletexString return TOK_TeletexString;
363TRUE return TOK_TRUE;
Lev Walkinf15320b2004-06-03 03:38:44 +0000364UNION return TOK_UNION;
365UNIQUE return TOK_UNIQUE;
366UNIVERSAL return TOK_UNIVERSAL;
367UniversalString {
368 if(TYPE_LIFETIME(1994, 0))
369 return TOK_UniversalString;
370 REJECT;
371 }
372UTCTime return TOK_UTCTime;
373UTF8String {
374 if(TYPE_LIFETIME(1994, 0))
375 return TOK_UTF8String;
376 REJECT;
377 }
378VideotexString return TOK_VideotexString;
379VisibleString return TOK_VisibleString;
380WITH return TOK_WITH;
381
382
Lev Walkin2535a692005-07-02 21:42:40 +0000383<INITIAL,with_syntax>&[A-Z][A-Za-z0-9]*([-][A-Za-z0-9]+)* {
Lev Walkinf15320b2004-06-03 03:38:44 +0000384 asn1p_lval.tv_str = strdup(yytext);
385 return TOK_typefieldreference;
386 }
387
Lev Walkin2535a692005-07-02 21:42:40 +0000388<INITIAL,with_syntax>&[a-z][a-zA-Z0-9]*([-][a-zA-Z0-9]+)* {
Lev Walkinf15320b2004-06-03 03:38:44 +0000389 asn1p_lval.tv_str = strdup(yytext);
390 return TOK_valuefieldreference;
391 }
392
393
Lev Walkin2535a692005-07-02 21:42:40 +0000394[a-z][a-zA-Z0-9]*([-][a-zA-Z0-9]+)* {
Lev Walkinf15320b2004-06-03 03:38:44 +0000395 asn1p_lval.tv_str = strdup(yytext);
396 return TOK_identifier;
397 }
398
399 /*
400 * objectclassreference
401 */
Lev Walkinbe518fa2017-09-07 02:05:28 -0700402<INITIAL,extended_values>[A-Z][A-Z0-9]*([-][A-Z0-9]+)* {
Lev Walkinf15320b2004-06-03 03:38:44 +0000403 asn1p_lval.tv_str = strdup(yytext);
Lev Walkinf59d0752004-08-18 04:59:12 +0000404 return TOK_capitalreference;
Lev Walkinf15320b2004-06-03 03:38:44 +0000405 }
406
407 /*
408 * typereference, modulereference
409 * NOTE: TOK_objectclassreference must be combined
410 * with this token to produce true typereference.
411 */
Lev Walkin2535a692005-07-02 21:42:40 +0000412[A-Z][A-Za-z0-9]*([-][A-Za-z0-9]+)* {
Lev Walkinf15320b2004-06-03 03:38:44 +0000413 asn1p_lval.tv_str = strdup(yytext);
414 return TOK_typereference;
415 }
416
Lev Walkinbe518fa2017-09-07 02:05:28 -0700417<INITIAL,extended_values>"::=" return TOK_PPEQ;
Lev Walkinf15320b2004-06-03 03:38:44 +0000418
419"..." return TOK_ThreeDots;
420".." return TOK_TwoDots;
421
Lev Walkinf15320b2004-06-03 03:38:44 +0000422<with_syntax>{
423
Lev Walkin9d542d22006-03-14 16:31:37 +0000424 [A-Z][A-Za-z0-9]*([-][A-Za-z0-9]+)* {
425 asn1p_lval.tv_str = strdup(yytext);
426 return TOK_Literal;
Lev Walkinf15320b2004-06-03 03:38:44 +0000427 }
428
Lev Walkin9d542d22006-03-14 16:31:37 +0000429 "," {
430 asn1p_lval.tv_str = strdup(yytext);
431 return TOK_Literal;
432 }
433
434 "{" {
435 yy_push_state(with_syntax);
436 asn1p_lval.tv_str = strdup(yytext);
437 return TOK_Literal;
438 }
439
440 "[" return '[';
441 "]" return ']';
442
Lev Walkinf15320b2004-06-03 03:38:44 +0000443 {WSP}+ {
444 asn1p_lval.tv_opaque.buf = strdup(yytext);
445 asn1p_lval.tv_opaque.len = yyleng;
Lev Walkin57074f12006-03-16 05:11:14 +0000446 return TOK_whitespace;
Lev Walkinf15320b2004-06-03 03:38:44 +0000447 }
448
449 "}" {
450 yy_pop_state();
Lev Walkin9d542d22006-03-14 16:31:37 +0000451 if(YYSTATE == with_syntax) {
452 asn1p_lval.tv_str = strdup(yytext);
453 return TOK_Literal;
454 } else {
455 return '}';
456 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000457 }
458
459}
460
Lev Walkind9574ae2005-03-24 16:22:35 +0000461
Lev Walkinbe518fa2017-09-07 02:05:28 -0700462<INITIAL,extended_values>{WSP}+ /* Ignore whitespace */
Lev Walkind9574ae2005-03-24 16:22:35 +0000463
464
465[{][\t\r\v\f\n ]*[0-7][,][\t\r\v\f\n ]*[0-9]+[\t\r\v\f\n ]*[}] {
466 asn1c_integer_t v1 = -1, v2 = -1;
467 char *p;
468 for(p = yytext; *p; p++)
469 if(*p >= '0' && *p <= '9')
Lev Walkind370e9f2006-03-16 10:03:35 +0000470 { v1 = _lex_atoi(p); break; }
Lev Walkind9574ae2005-03-24 16:22:35 +0000471 while(*p >= '0' && *p <= '9') p++; /* Skip digits */
472 for(; *p; p++) if(*p >= '0' && *p <= '9')
Lev Walkind370e9f2006-03-16 10:03:35 +0000473 { v2 = _lex_atoi(p); break; }
Lev Walkind9574ae2005-03-24 16:22:35 +0000474 if(v1 < 0 || v1 > 7) {
475 fprintf(stderr, "%s at line %d: X.680:2003, #37.14 "
476 "mandates 0..7 range for Tuple's TableColumn\n",
477 yytext, yylineno);
478 return -1;
479 }
480 if(v2 < 0 || v2 > 15) {
481 fprintf(stderr, "%s at line %d: X.680:2003, #37.14 "
482 "mandates 0..15 range for Tuple's TableRow\n",
483 yytext, yylineno);
484 return -1;
485 }
486 asn1p_lval.a_int = (v1 << 4) + v2;
487 return TOK_tuple;
488 }
489
490[{][\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 ]*[}] {
491 asn1c_integer_t v1 = -1, v2 = -1, v3 = -1, v4 = -1;
492 char *p;
493 for(p = yytext; *p; p++)
494 if(*p >= '0' && *p <= '9')
Lev Walkind370e9f2006-03-16 10:03:35 +0000495 { v1 = _lex_atoi(p); break; }
Lev Walkind9574ae2005-03-24 16:22:35 +0000496 while(*p >= '0' && *p <= '9') p++; /* Skip digits */
497 for(; *p; p++) if(*p >= '0' && *p <= '9')
Lev Walkind370e9f2006-03-16 10:03:35 +0000498 { v2 = _lex_atoi(p); break; }
Lev Walkind9574ae2005-03-24 16:22:35 +0000499 while(*p >= '0' && *p <= '9') p++;
500 for(; *p; p++) if(*p >= '0' && *p <= '9')
Lev Walkind370e9f2006-03-16 10:03:35 +0000501 { v3 = _lex_atoi(p); break; }
Lev Walkind9574ae2005-03-24 16:22:35 +0000502 while(*p >= '0' && *p <= '9') p++;
503 for(; *p; p++) if(*p >= '0' && *p <= '9')
Lev Walkind370e9f2006-03-16 10:03:35 +0000504 { v4 = _lex_atoi(p); break; }
Lev Walkind9574ae2005-03-24 16:22:35 +0000505 if(v1 < 0 || v1 > 127) {
506 fprintf(stderr, "%s at line %d: X.680:2003, #37.12 "
507 "mandates 0..127 range for Quadruple's Group\n",
508 yytext, yylineno);
509 return -1;
510 }
511 if(v2 < 0 || v2 > 255) {
512 fprintf(stderr, "%s at line %d: X.680:2003, #37.12 "
513 "mandates 0..255 range for Quadruple's Plane\n",
514 yytext, yylineno);
515 return -1;
516 }
517 if(v3 < 0 || v3 > 255) {
518 fprintf(stderr, "%s at line %d: X.680:2003, #37.12 "
519 "mandates 0..255 range for Quadruple's Row\n",
520 yytext, yylineno);
521 return -1;
522 }
523 if(v4 < 0 || v4 > 255) {
524 fprintf(stderr, "%s at line %d: X.680:2003, #37.12 "
525 "mandates 0..255 range for Quadruple's Cell\n",
526 yytext, yylineno);
527 return -1;
528 }
529 asn1p_lval.a_int = (v1 << 24) | (v2 << 16) | (v3 << 8) | v4;
530 return TOK_quadruple;
531 }
532
533
Lev Walkin0e90aa02013-03-19 16:17:13 -0700534"[[" return TOK_VBracketLeft;
535"]]" return TOK_VBracketRight;
536
Lev Walkind9574ae2005-03-24 16:22:35 +0000537[(){},;:|!.&@\[\]^] return yytext[0];
538
539[^A-Za-z0-9:=,{}<.@()[]'\"|&^*;!-] {
540 if(TYPE_LIFETIME(1994, 0))
541 fprintf(stderr, "ERROR: ");
542 fprintf(stderr,
543 "Symbol '%c' at line %d is prohibited "
544 "by ASN.1:1994 and ASN.1:1997\n",
545 yytext[0], yylineno);
546 if(TYPE_LIFETIME(1994, 0))
547 return -1;
548 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000549
550<*>. {
551 fprintf(stderr,
552 "Unexpected token at line %d: \"%s\"\n",
553 yylineno, yytext);
554 while(YYSTATE != INITIAL)
555 yy_pop_state();
Lev Walkin9c974182004-09-15 11:59:51 +0000556 if(0) {
557 yy_top_state(); /* Just to use this function. */
558 yy_fatal_error("Parse error");
559 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000560 return -1;
561}
562
563<*><<EOF>> {
564 while(YYSTATE != INITIAL)
565 yy_pop_state();
566 yyterminate();
567 }
568
569
570%%
571
572/*
573 * Very dirty but wonderful hack allowing to rule states from within .y file.
574 */
Lev Walkinf59d0752004-08-18 04:59:12 +0000575void asn1p_lexer_hack_push_opaque_state() { yy_push_state(opaque); }
Lev Walkinf15320b2004-06-03 03:38:44 +0000576
577/*
578 * Another hack which disables recognizing some tokens when inside WITH SYNTAX.
579 */
Lev Walkinf59d0752004-08-18 04:59:12 +0000580void asn1p_lexer_hack_enable_with_syntax() { yy_push_state(with_syntax); }
581
582/* Yet another */
583void asn1p_lexer_hack_push_encoding_control() {
584 yy_push_state(encoding_control);
Lev Walkinf15320b2004-06-03 03:38:44 +0000585}
586
Lev Walkinc603f102005-01-23 09:51:44 +0000587static asn1c_integer_t
Lev Walkind370e9f2006-03-16 10:03:35 +0000588_lex_atoi(const char *ptr) {
Lev Walkinc603f102005-01-23 09:51:44 +0000589 asn1c_integer_t value;
Lev Walkind370e9f2006-03-16 10:03:35 +0000590 if(asn1p_atoi(ptr, &value)) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000591 fprintf(stderr,
592 "Value \"%s\" at line %d is too large "
Lev Walkin129a79e2005-04-05 08:46:22 +0000593 "for this compiler! Please contact the asn1c author.\n",
Lev Walkinf15320b2004-06-03 03:38:44 +0000594 ptr, yylineno);
Lev Walkind370e9f2006-03-16 10:03:35 +0000595 errno = ERANGE;
Lev Walkinf15320b2004-06-03 03:38:44 +0000596 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000597 return value;
598}
Lev Walkinadf863f2006-09-05 16:18:34 +0000599
600static double
601_lex_atod(const char *ptr) {
602 double value;
603 errno = 0;
604 value = strtod(ptr, 0);
605 if(errno) {
606 fprintf(stderr,
607 "Value \"%s\" at line %d is outside of `double` range "
608 "in this compiler! Please contact the asn1c author.\n",
609 ptr, yylineno);
610 errno = ERANGE;
611 }
612 return value;
613}
614