cf/largefile.m4: Fix build with autoconf-2.72
[heimdal.git] / lib / asn1 / lex.l
blob4554a9477c6043d9b0eb9c8e93eeca9f1360e5c7
1 %{
2 /*
3  * Copyright (c) 1997 - 2017 Kungliga Tekniska Högskolan
4  * (Royal Institute of Technology, Stockholm, Sweden).
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * 3. Neither the name of the Institute nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
35 /* $Id$ */
37 #ifdef HAVE_CONFIG_H
38 #include <config.h>
39 #endif
40 #include <stdio.h>
41 #include <stdarg.h>
42 #include <stdlib.h>
43 #include <stdint.h>
44 #include <string.h>
45 #ifdef HAVE_UNISTD_H
46 #include <unistd.h>
47 #endif
48 #undef ECHO
49 #include "symbol.h"
50 #include "asn1parse.h"
51 #include "lex.h"
52 #include "gen_locl.h"
54 static unsigned lineno = 1;
56 #undef ECHO
58 static void unterminated(const char *, unsigned);
62 /* This is for broken old lexes (solaris 10 and hpux) */
63 %e 2000
64 %p 5000
65 %a 5000
66 %n 1000
67 %o 10000
70 ABSENT                  { return kw_ABSENT; }
71 ABSTRACT-SYNTAX         { return kw_ABSTRACT_SYNTAX; }
72 ALL                     { return kw_ALL; }
73 APPLICATION             { return kw_APPLICATION; }
74 AUTOMATIC               { return kw_AUTOMATIC; }
75 BEGIN                   { return kw_BEGIN; }
76 BIT                     { return kw_BIT; }
77 BMPString               { return kw_BMPString; }
78 BOOLEAN                 { return kw_BOOLEAN; }
79 BY                      { return kw_BY; }
80 CHARACTER               { return kw_CHARACTER; }
81 CHOICE                  { return kw_CHOICE; }
82 CLASS                   { return kw_CLASS; }
83 COMPONENT               { return kw_COMPONENT; }
84 COMPONENTS              { return kw_COMPONENTS; }
85 CONSTRAINED             { return kw_CONSTRAINED; }
86 CONTAINING              { return kw_CONTAINING; }
87 DEFAULT                 { return kw_DEFAULT; }
88 DEFINITIONS             { return kw_DEFINITIONS; }
89 EMBEDDED                { return kw_EMBEDDED; }
90 ENCODED                 { return kw_ENCODED; }
91 END                     { return kw_END; }
92 ENUMERATED              { return kw_ENUMERATED; }
93 EXCEPT                  { return kw_EXCEPT; }
94 EXPLICIT                { return kw_EXPLICIT; }
95 EXPORTS                 { return kw_EXPORTS; }
96 EXTENSIBILITY           { return kw_EXTENSIBILITY; }
97 EXTERNAL                { return kw_EXTERNAL; }
98 FALSE                   { return kw_FALSE; }
99 FROM                    { return kw_FROM; }
100 GeneralString           { return kw_GeneralString; }
101 GeneralizedTime         { return kw_GeneralizedTime; }
102 GraphicString           { return kw_GraphicString; }
103 IA5String               { return kw_IA5String; }
104 IDENTIFIER              { return kw_IDENTIFIER; }
105 IMPLICIT                { return kw_IMPLICIT; }
106 IMPLIED                 { return kw_IMPLIED; }
107 IMPORTS                 { return kw_IMPORTS; }
108 INCLUDES                { return kw_INCLUDES; }
109 INSTANCE                { return kw_INSTANCE; }
110 INTEGER                 { return kw_INTEGER; }
111 INTERSECTION            { return kw_INTERSECTION; }
112 ISO646String            { return kw_ISO646String; }
113 MAX                     { return kw_MAX; }
114 MIN                     { return kw_MIN; }
115 MINUS-INFINITY          { return kw_MINUS_INFINITY; }
116 NULL                    { return kw_NULL; }
117 NumericString           { return kw_NumericString; }
118 OBJECT                  { return kw_OBJECT; }
119 OCTET                   { return kw_OCTET; }
120 OF                      { return kw_OF; }
121 OPTIONAL                { return kw_OPTIONAL; }
122 ObjectDescriptor        { return kw_ObjectDescriptor; }
123 PATTERN                 { return kw_PATTERN; }
124 PDV                     { return kw_PDV; }
125 PLUS-INFINITY           { return kw_PLUS_INFINITY; }
126 PRESENT                 { return kw_PRESENT; }
127 PRIVATE                 { return kw_PRIVATE; }
128 PrintableString         { return kw_PrintableString; }
129 REAL                    { return kw_REAL; }
130 RELATIVE_OID            { return kw_RELATIVE_OID; }
131 SEQUENCE                { return kw_SEQUENCE; }
132 SET                     { return kw_SET; }
133 SIZE                    { return kw_SIZE; }
134 STRING                  { return kw_STRING; }
135 SYNTAX                  { return kw_SYNTAX; }
136 T61String               { return kw_T61String; }
137 TAGS                    { return kw_TAGS; }
138 TRUE                    { return kw_TRUE; }
139 TYPE-IDENTIFIER         { return kw_TYPE_IDENTIFIER; }
140 TeletexString           { return kw_TeletexString; }
141 UNION                   { return kw_UNION; }
142 UNIQUE                  { return kw_UNIQUE; }
143 UNIVERSAL               { return kw_UNIVERSAL; }
144 UTCTime                 { return kw_UTCTime; }
145 UTF8String              { return kw_UTF8String; }
146 UniversalString         { return kw_UniversalString; }
147 VideotexString          { return kw_VideotexString; }
148 VisibleString           { return kw_VisibleString; }
149 WITH                    { return kw_WITH; }
150 [-,;{}()|]              { return *yytext; }
151 "["                     { return *yytext; }
152 "]"                     { return *yytext; }
153 "&"                     { return *yytext; }
154 "."                     { return *yytext; }
155 ":"                     { return *yytext; }
156 "@"                     { return *yytext; }
157 ::=                     { return EEQUAL; }
158 --                      {
159                             int c, start_lineno = lineno;
160                             int f = 0;
161                             while((c = input()) != EOF) {
162                                 if(f && c == '-')
163                                     break;
164                                 if(c == '-') {
165                                     f = 1;
166                                     continue;
167                                 }
168                                 if(c == '\n') {
169                                     lineno++;
170                                     break;
171                                 }
172                                 f = 0;
173                             }
174                             if(c == EOF)
175                                 unterminated("comment", start_lineno);
176                         }
177 \/\*                    {
178                             int c, start_lineno = lineno;
179                             int level = 1;
180                             int seen_star = 0;
181                             int seen_slash = 0;
182                             while((c = input()) != EOF) {
183                                 if(c == '/') {
184                                     if(seen_star) {
185                                         if(--level == 0)
186                                             break;
187                                         seen_star = 0;
188                                         continue;
189                                     }
190                                     seen_slash = 1;
191                                     continue;
192                                 }
193                                 if(seen_star && c == '/') {
194                                     if(--level == 0)
195                                         break;
196                                     seen_star = 0;
197                                     continue;
198                                 }
199                                 if(c == '*') {
200                                     if(seen_slash) {
201                                         level++;
202                                         seen_star = seen_slash = 0;
203                                         continue;
204                                     }
205                                     seen_star = 1;
206                                     continue;
207                                 }
208                                 seen_star = seen_slash = 0;
209                                 if(c == '\n') {
210                                     lineno++;
211                                     continue;
212                                 }
213                             }
214                             if(c == EOF)
215                                 unterminated("comment", start_lineno);
216                         }
217 "\""                    {
218                             int start_lineno = lineno;
219                             int c;
220                             char buf[1024];
221                             char *p = buf;
222                             int f = 0;
223                             int skip_ws = 0;
225                             while((c = input()) != EOF) {
226                                 if(isspace(c) && skip_ws) {
227                                     if(c == '\n')
228                                         lineno++;
229                                     continue;
230                                 }
231                                 skip_ws = 0;
233                                 if(c == '"') {
234                                     if(f) {
235                                         *p++ = '"';
236                                         f = 0;
237                                     } else
238                                         f = 1;
239                                     continue;
240                                 }
241                                 if(f == 1) {
242                                     unput(c);
243                                     break;
244                                 }
245                                 if(c == '\n') {
246                                     lineno++;
247                                     while(p > buf && isspace((unsigned char)p[-1]))
248                                         p--;
249                                     skip_ws = 1;
250                                     continue;
251                                 }
252                                 *p++ = c;
253                             }
254                             if(c == EOF)
255                                 unterminated("string", start_lineno);
256                             *p++ = '\0';
257                             yylval.name = estrdup(buf);
258                             return STRING;
259                         }
261 -?0x[0-9A-Fa-f]+|-?[0-9]+ { char *e, *y = yytext;
262                           yylval.constant = strtoll((const char *)yytext,
263                                                    &e, 0);
264                           if(e == y)
265                             lex_error_message("malformed constant (%s)", yytext);
266                           else
267                             return NUMBER;
268                         }
269 [_][-A-Z0-9]*           {
270                           yylval.name =  estrdup ((const char *)yytext);
271                           return CLASS_IDENTIFIER;
272                         }
273 [A-Z][-A-Za-z0-9_]*     {
274                           yylval.name =  estrdup ((const char *)yytext);
275                           return TYPE_IDENTIFIER;
276                         }
277 [a-z][-A-Za-z0-9_]*     {
278                           yylval.name =  estrdup ((const char *)yytext);
279                           return VALUE_IDENTIFIER;
280                         }
281 [ \t]                   ;
282 \n                      { ++lineno; }
283 \.\.\.                  { return ELLIPSIS; }
284 \.\.                    { return RANGE; }
285 .                       { lex_error_message("Ignoring char(%c)\n", *yytext); }
289 yywrap ()
291      return 1;
294 void
295 lex_error_message (const char *format, ...)
297     va_list args;
299     va_start (args, format);
300     fprintf (stderr, "%s:%d: ", get_filename(), lineno);
301     vfprintf (stderr, format, args);
302     va_end (args);
303     error_flag++;
306 static void
307 unterminated(const char *type, unsigned start_lineno)
309     lex_error_message("unterminated %s, possibly started on line %d\n", type, start_lineno);