1 /* original parser id follows */
2 /* yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93" */
3 /* (use YYMAJOR/YYMINOR for ifdefs dependent on parser version) */
4
5 #define YYBYACC 1
6 #define YYMAJOR 1
7 #define YYMINOR 9
8
9 #define YYEMPTY (-1)
10 #define yyclearin (yychar = YYEMPTY)
11 #define yyerrok (yyerrflag = 0)
12 #define YYRECOVERING() (yyerrflag != 0)
13 #define YYENOMEM (-2)
14 #define YYEOF 0
15 #undef YYBTYACC
16 #define YYBTYACC 0
17 #define YYDEBUGSTR YYPREFIX "debug"
18 #define YYPREFIX "yy"
19
20 #define YYPURE 0
21
22 /* Copyright (c) 1990 The Regents of the University of California. */
23 /* All rights reserved. */
24
25 /* This code is derived from software contributed to Berkeley by */
26 /* Vern Paxson. */
27
28 /* The United States Government has rights in this work pursuant */
29 /* to contract no. DE-AC03-76SF00098 between the United States */
30 /* Department of Energy and the University of California. */
31
32 /* This file is part of flex. */
33
34 /* Redistribution and use in source and binary forms, with or without */
35 /* modification, are permitted provided that the following conditions */
36 /* are met: */
37
38 /* 1. Redistributions of source code must retain the above copyright */
39 /* notice, this list of conditions and the following disclaimer. */
40 /* 2. Redistributions in binary form must reproduce the above copyright */
41 /* notice, this list of conditions and the following disclaimer in the */
42 /* documentation and/or other materials provided with the distribution. */
43
44 /* Neither the name of the University nor the names of its contributors */
45 /* may be used to endorse or promote products derived from this software */
46 /* without specific prior written permission. */
47
48 /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */
49 /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */
50 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
51 /* PURPOSE. */
52 #include "flexdef.h"
53 __RCSID("$NetBSD: initparse.c,v 1.4 2017/01/07 15:43:27 christos Exp $");
54
55 #include "tables.h"
56
57 int pat, scnum, eps, headcnt, trailcnt, lastchar, i, rulelen;
58 int trlcontxt, xcluflg, currccl, cclsorted, varlength, variable_trail_rule;
59
60 int *scon_stk;
61 int scon_stk_ptr;
62
63 static int madeany = false; /* whether we've made the '.' character class */
64 static int ccldot, cclany;
65 int previous_continued_action; /* whether the previous rule's action was '|' */
66
67 #define format_warn3(fmt, a1, a2) \
68 do{ \
69 char fw3_msg[MAXLINE];\
70 snprintf( fw3_msg, MAXLINE,(fmt), (a1), (a2) );\
71 lwarn( fw3_msg );\
72 }while(0)
73
74 /* Expand a POSIX character class expression. */
75 #define CCL_EXPR(func) \
76 do{ \
77 int c; \
78 for ( c = 0; c < csize; ++c ) \
79 if ( isascii(c) && func(c) ) \
80 ccladd( currccl, c ); \
81 }while(0)
82
83 /* negated class */
84 #define CCL_NEG_EXPR(func) \
85 do{ \
86 int c; \
87 for ( c = 0; c < csize; ++c ) \
88 if ( !func(c) ) \
89 ccladd( currccl, c ); \
90 }while(0)
91
92 /* While POSIX defines isblank(), it's not ANSI C. */
93 #define IS_BLANK(c) ((c) == ' ' || (c) == '\t')
94
95 /* On some over-ambitious machines, such as DEC Alpha's, the default
96 * token type is "long" instead of "int"; this leads to problems with
97 * declaring yylval in flexdef.h. But so far, all the yacc's I've seen
98 * wrap their definitions of YYSTYPE with "#ifndef YYSTYPE"'s, so the
99 * following should ensure that the default token type is "int".
100 */
101 #define YYSTYPE int
102
103
104 #if ! defined(YYSTYPE) && ! defined(YYSTYPE_IS_DECLARED)
105 /* Default: YYSTYPE is the semantic value type. */
106 typedef int YYSTYPE;
107 # define YYSTYPE_IS_DECLARED 1
108 #endif
109
110 /* compatibility with bison */
111 #ifdef YYPARSE_PARAM
112 /* compatibility with FreeBSD */
113 # ifdef YYPARSE_PARAM_TYPE
114 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
115 # else
116 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
117 # endif
118 #else
119 # define YYPARSE_DECL() yyparse(void)
120 #endif
121
122 /* Parameters sent to lex. */
123 #ifdef YYLEX_PARAM
124 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
125 # define YYLEX yylex(YYLEX_PARAM)
126 #else
127 # define YYLEX_DECL() yylex(void)
128 # define YYLEX yylex()
129 #endif
130
131 /* Parameters sent to yyerror. */
132 #ifndef YYERROR_DECL
133 #define YYERROR_DECL() yyerror(const char *s)
134 #endif
135 #ifndef YYERROR_CALL
136 #define YYERROR_CALL(msg) yyerror(msg)
137 #endif
138
139 extern int YYPARSE_DECL();
140
141 #define CHAR 257
142 #define NUMBER 258
143 #define SECTEND 259
144 #define SCDECL 260
145 #define XSCDECL 261
146 #define NAME 262
147 #define PREVCCL 263
148 #define EOF_OP 264
149 #define TOK_OPTION 265
150 #define TOK_OUTFILE 266
151 #define TOK_PREFIX 267
152 #define TOK_YYCLASS 268
153 #define TOK_HEADER_FILE 269
154 #define TOK_EXTRA_TYPE 270
155 #define TOK_TABLES_FILE 271
156 #define CCE_ALNUM 272
157 #define CCE_ALPHA 273
158 #define CCE_BLANK 274
159 #define CCE_CNTRL 275
160 #define CCE_DIGIT 276
161 #define CCE_GRAPH 277
162 #define CCE_LOWER 278
163 #define CCE_PRINT 279
164 #define CCE_PUNCT 280
165 #define CCE_SPACE 281
166 #define CCE_UPPER 282
167 #define CCE_XDIGIT 283
168 #define CCE_NEG_ALNUM 284
169 #define CCE_NEG_ALPHA 285
170 #define CCE_NEG_BLANK 286
171 #define CCE_NEG_CNTRL 287
172 #define CCE_NEG_DIGIT 288
173 #define CCE_NEG_GRAPH 289
174 #define CCE_NEG_LOWER 290
175 #define CCE_NEG_PRINT 291
176 #define CCE_NEG_PUNCT 292
177 #define CCE_NEG_SPACE 293
178 #define CCE_NEG_UPPER 294
179 #define CCE_NEG_XDIGIT 295
180 #define CCL_OP_DIFF 296
181 #define CCL_OP_UNION 297
182 #define BEGIN_REPEAT_POSIX 298
183 #define END_REPEAT_POSIX 299
184 #define BEGIN_REPEAT_FLEX 300
185 #define END_REPEAT_FLEX 301
186 #define YYERRCODE 256
187 typedef int YYINT;
188 static const YYINT yylhs[] = { -1,
189 0, 1, 2, 2, 2, 2, 3, 6, 6, 7,
190 7, 7, 8, 9, 9, 10, 10, 10, 10, 10,
191 10, 4, 4, 4, 5, 12, 12, 12, 12, 14,
192 11, 11, 11, 15, 15, 15, 16, 13, 13, 13,
193 13, 18, 18, 17, 19, 19, 19, 19, 19, 20,
194 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
195 20, 21, 21, 21, 23, 23, 24, 24, 24, 24,
196 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
197 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
198 25, 25, 25, 25, 22, 22,
199 };
200 static const YYINT yylen[] = { 2,
201 5, 0, 3, 2, 0, 1, 1, 1, 1, 2,
202 1, 1, 2, 2, 0, 3, 3, 3, 3, 3,
203 3, 5, 5, 0, 0, 2, 1, 1, 1, 0,
204 4, 3, 0, 3, 1, 1, 1, 2, 3, 2,
205 1, 3, 1, 2, 2, 1, 6, 5, 4, 2,
206 2, 2, 6, 5, 4, 1, 1, 1, 3, 3,
207 1, 3, 3, 1, 3, 4, 4, 2, 2, 0,
208 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
209 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
210 1, 1, 1, 1, 2, 0,
211 };
212 static const YYINT yydefred[] = { 2,
213 0, 0, 6, 0, 7, 8, 9, 15, 24, 0,
214 4, 0, 0, 12, 11, 0, 0, 0, 0, 0,
215 0, 0, 14, 0, 1, 0, 10, 0, 0, 0,
216 0, 0, 0, 0, 0, 24, 0, 16, 18, 19,
217 20, 17, 21, 32, 36, 37, 0, 35, 0, 29,
218 61, 58, 28, 0, 56, 96, 0, 0, 0, 27,
219 0, 0, 0, 0, 0, 64, 31, 0, 23, 26,
220 0, 0, 70, 0, 22, 0, 40, 0, 44, 0,
221 0, 0, 50, 51, 52, 0, 0, 34, 95, 59,
222 60, 0, 0, 71, 72, 73, 74, 75, 76, 77,
223 78, 79, 80, 82, 81, 83, 84, 85, 86, 87,
224 88, 93, 89, 90, 91, 94, 92, 65, 69, 39,
225 0, 0, 0, 62, 63, 66, 0, 49, 0, 55,
226 0, 67, 0, 48, 0, 54, 47, 53,
227 };
228 #if defined(YYDESTRUCT_CALL) || defined(YYSTYPE_TOSTRING)
229 static const YYINT yystos[] = { 0,
230 303, 304, 256, 305, 259, 260, 261, 265, 306, 309,
231 311, 312, 307, 256, 262, 310, 266, 267, 268, 269,
232 270, 271, 313, 60, 308, 314, 262, 61, 61, 61,
233 61, 61, 61, 42, 317, 123, 308, 262, 262, 262,
234 262, 262, 262, 62, 256, 262, 318, 319, 307, 256,
235 257, 263, 264, 94, 46, 34, 40, 91, 315, 316,
236 320, 321, 322, 323, 324, 326, 62, 44, 125, 316,
237 325, 321, 94, 327, 10, 321, 36, 124, 47, 298,
238 323, 300, 42, 43, 63, 296, 297, 319, 257, 34,
239 41, 327, 257, 272, 273, 274, 275, 276, 277, 278,
240 279, 280, 281, 282, 283, 284, 285, 286, 287, 288,
241 289, 290, 291, 292, 293, 294, 295, 93, 328, 36,
242 322, 258, 258, 326, 326, 93, 45, 299, 44, 301,
243 44, 257, 258, 299, 258, 301, 299, 301,
244 };
245 #endif /* YYDESTRUCT_CALL || YYSTYPE_TOSTRING */
246 static const YYINT yydgoto[] = { 1,
247 2, 4, 9, 13, 25, 10, 16, 11, 12, 23,
248 26, 59, 60, 35, 47, 48, 61, 62, 63, 64,
249 65, 71, 66, 74, 119,
250 };
251 static const YYINT yysindex[] = { 0,
252 0, -222, 0, -155, 0, 0, 0, 0, 0, -215,
253 0, -123, 6, 0, 0, -193, 10, 21, 26, 31,
254 35, 37, 0, 59, 0, -44, 0, -147, -145, -140,
255 -133, -132, -129, 75, -214, 0, -19, 0, 0, 0,
256 0, 0, 0, 0, 0, 0, 23, 0, -48, 0,
257 0, 0, 0, -17, 0, 0, -17, 27, 128, 0,
258 -17, -1, -30, -41, -189, 0, 0, -121, 0, 0,
259 -31, -34, 0, -87, 0, -25, 0, -17, 0, -109,
260 -41, -108, 0, 0, 0, 60, 60, 0, 0, 0,
261 0, 46, 107, 0, 0, 0, 0, 0, 0, 0,
262 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
263 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
264 -30, -36, -39, 0, 0, 0, -104, 0, -219, 0,
265 -238, 0, -144, 0, -143, 0, 0, 0,
266 };
267 static const YYINT yyrindex[] = { 0,
268 0, -141, 0, 0, 0, 0, 0, 0, 0, 0,
269 0, -134, 9, 0, 0, -125, 0, 0, 0, 0,
270 0, 0, 0, -178, 0, 22, 0, 0, 0, 0,
271 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
272 0, 0, 0, 0, 0, 0, 0, 0, -21, 0,
273 0, 0, 0, 0, 0, 0, 0, 85, 0, 0,
274 0, 144, 47, 4, -10, 0, 0, 0, 0, 0,
275 0, 0, 0, 0, 0, 146, 0, 0, 0, 0,
276 18, 0, 0, 0, 0, 0, 0, 0, 0, 0,
277 0, 0, 124, 0, 0, 0, 0, 0, 0, 0,
278 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
279 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
280 50, 0, 0, 0, 0, 0, 0, 0, 0, 0,
281 0, 0, 0, 0, 0, 0, 0, 0,
282 };
283 #if YYBTYACC
284 static const YYINT yycindex[] = { 0,
285 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
286 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
287 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
288 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
289 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
290 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
291 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
292 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
293 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
294 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
295 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
296 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
297 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
298 0, 0, 0, 0, 0, 0, 0, 0,
299 };
300 #endif
301 static const YYINT yygindex[] = { 0,
302 0, 0, 0, 121, 133, 0, 0, 0, 0, 0,
303 0, 0, 106, 0, 0, 93, 0, 32, 84, -45,
304 0, 0, 25, 90, 0,
305 };
306 #define YYTABLESIZE 419
307 static const YYINT yytable[] = { 57,
308 83, 84, 90, 56, 131, 118, 91, 129, 25, 57,
309 120, 24, 33, 46, 56, 55, 56, 81, 33, 135,
310 57, 85, 57, 57, 33, 57, 55, 45, 55, 57,
311 57, 57, 57, 3, 77, 57, 57, 46, 133, 46,
312 14, 45, 33, 46, 46, 79, 15, 46, 33, 46,
313 46, 45, 57, 45, 33, 25, 43, 45, 45, 42,
314 58, 25, 136, 45, 45, 24, 68, 25, 27, 33,
315 28, 58, 33, 58, 54, 81, 69, 30, 36, 134,
316 57, 29, 43, 30, 67, 42, 30, 43, 72, 78,
317 42, 31, 76, 43, 46, 32, 42, 33, 78, 33,
318 34, 33, 33, 5, 6, 7, 86, 87, 45, 8,
319 124, 125, 25, 57, 38, 25, 39, 5, 5, 5,
320 73, 40, 78, 5, 13, 13, 13, 46, 41, 42,
321 13, 33, 43, 3, 3, 3, 44, 75, 126, 3,
322 46, 45, 17, 18, 19, 20, 21, 22, 122, 123,
323 58, 127, 132, 41, 137, 38, 49, 138, 37, 70,
324 88, 121, 92, 0, 0, 0, 0, 0, 0, 93,
325 43, 0, 0, 42, 0, 0, 0, 70, 0, 0,
326 0, 0, 0, 0, 94, 95, 96, 97, 98, 99,
327 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
328 110, 111, 112, 113, 114, 115, 116, 117, 0, 0,
329 0, 0, 0, 0, 0, 0, 68, 0, 0, 0,
330 0, 0, 0, 0, 0, 89, 51, 0, 0, 0,
331 0, 0, 52, 0, 33, 33, 50, 51, 0, 51,
332 0, 33, 33, 52, 53, 52, 57, 0, 0, 0,
333 0, 0, 57, 0, 0, 0, 0, 0, 82, 0,
334 46, 130, 128, 0, 33, 33, 46, 80, 0, 0,
335 0, 33, 33, 0, 45, 0, 0, 25, 25, 0,
336 45, 0, 0, 0, 25, 25, 0, 57, 0, 57,
337 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
338 0, 46, 93, 0, 0, 0, 0, 0, 0, 0,
339 0, 0, 0, 0, 0, 45, 0, 94, 95, 96,
340 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
341 107, 108, 109, 110, 111, 112, 113, 114, 115, 116,
342 117, 70, 0, 0, 0, 0, 0, 0, 0, 0,
343 0, 0, 0, 0, 0, 0, 70, 70, 70, 70,
344 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
345 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
346 68, 0, 0, 0, 0, 0, 0, 0, 0, 0,
347 0, 0, 0, 0, 0, 68, 68, 68, 68, 68,
348 68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
349 68, 68, 68, 68, 68, 68, 68, 68, 68,
350 };
351 static const YYINT yycheck[] = { 10,
352 42, 43, 34, 34, 44, 93, 41, 44, 0, 40,
353 36, 60, 34, 10, 34, 46, 34, 63, 40, 258,
354 40, 63, 40, 34, 46, 36, 46, 10, 46, 40,
355 41, 42, 43, 256, 36, 46, 47, 34, 258, 36,
356 256, 256, 34, 40, 41, 47, 262, 262, 40, 46,
357 47, 34, 63, 36, 46, 34, 10, 40, 41, 10,
358 91, 40, 301, 46, 47, 60, 44, 46, 262, 91,
359 61, 91, 94, 91, 94, 121, 125, 256, 123, 299,
360 91, 61, 36, 262, 62, 36, 61, 41, 57, 124,
361 41, 61, 61, 47, 91, 61, 47, 61, 124, 91,
362 42, 123, 94, 259, 260, 261, 296, 297, 91, 265,
363 86, 87, 91, 124, 262, 94, 262, 259, 260, 261,
364 94, 262, 124, 265, 259, 260, 261, 124, 262, 262,
365 265, 123, 262, 259, 260, 261, 62, 10, 93, 265,
366 262, 124, 266, 267, 268, 269, 270, 271, 258, 258,
367 91, 45, 257, 10, 299, 10, 36, 301, 26, 54,
368 68, 78, 73, -1, -1, -1, -1, -1, -1, 257,
369 124, -1, -1, 124, -1, -1, -1, 93, -1, -1,
370 -1, -1, -1, -1, 272, 273, 274, 275, 276, 277,
371 278, 279, 280, 281, 282, 283, 284, 285, 286, 287,
372 288, 289, 290, 291, 292, 293, 294, 295, -1, -1,
373 -1, -1, -1, -1, -1, -1, 93, -1, -1, -1,
374 -1, -1, -1, -1, -1, 257, 257, -1, -1, -1,
375 -1, -1, 263, -1, 256, 257, 256, 257, -1, 257,
376 -1, 263, 264, 263, 264, 263, 257, -1, -1, -1,
377 -1, -1, 263, -1, -1, -1, -1, -1, 300, -1,
378 257, 301, 299, -1, 256, 257, 263, 298, -1, -1,
379 -1, 263, 264, -1, 257, -1, -1, 256, 257, -1,
380 263, -1, -1, -1, 263, 264, -1, 298, -1, 300,
381 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
382 -1, 298, 257, -1, -1, -1, -1, -1, -1, -1,
383 -1, -1, -1, -1, -1, 298, -1, 272, 273, 274,
384 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
385 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
386 295, 257, -1, -1, -1, -1, -1, -1, -1, -1,
387 -1, -1, -1, -1, -1, -1, 272, 273, 274, 275,
388 276, 277, 278, 279, 280, 281, 282, 283, 284, 285,
389 286, 287, 288, 289, 290, 291, 292, 293, 294, 295,
390 257, -1, -1, -1, -1, -1, -1, -1, -1, -1,
391 -1, -1, -1, -1, -1, 272, 273, 274, 275, 276,
392 277, 278, 279, 280, 281, 282, 283, 284, 285, 286,
393 287, 288, 289, 290, 291, 292, 293, 294, 295,
394 };
395 #if YYBTYACC
396 static const YYINT yyctable[] = { -1,
397 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
398 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
399 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
400 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
401 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
402 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
403 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
404 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
405 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
406 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
407 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
408 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
409 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
410 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
411 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
412 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
413 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
414 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
415 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
416 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
417 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
418 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
419 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
420 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
421 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
422 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
423 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
424 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
425 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
426 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
427 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
428 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
429 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
430 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
431 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
432 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
433 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
434 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
435 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
436 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
437 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
438 -1, -1, -1, -1, -1, -1, -1, -1,
439 };
440 #endif
441 #define YYFINAL 1
442 #ifndef YYDEBUG
443 #define YYDEBUG 0
444 #endif
445 #define YYMAXTOKEN 301
446 #define YYUNDFTOKEN 329
447 #define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? YYUNDFTOKEN : (a))
448 #if YYDEBUG
449 static const char *const yyname[] = {
450
451 "$end",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
452 "'\"'",0,"'$'",0,0,0,"'('","')'","'*'","'+'","','","'-'","'.'","'/'",0,0,0,0,0,
453 0,0,0,0,0,0,0,"'<'","'='","'>'","'?'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
454 0,0,0,0,0,0,"'['",0,"']'","'^'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
455 0,0,0,0,"'{'","'|'","'}'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
456 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
457 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
458 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"error","CHAR","NUMBER","SECTEND",
459 "SCDECL","XSCDECL","NAME","PREVCCL","EOF_OP","TOK_OPTION","TOK_OUTFILE",
460 "TOK_PREFIX","TOK_YYCLASS","TOK_HEADER_FILE","TOK_EXTRA_TYPE","TOK_TABLES_FILE",
461 "CCE_ALNUM","CCE_ALPHA","CCE_BLANK","CCE_CNTRL","CCE_DIGIT","CCE_GRAPH",
462 "CCE_LOWER","CCE_PRINT","CCE_PUNCT","CCE_SPACE","CCE_UPPER","CCE_XDIGIT",
463 "CCE_NEG_ALNUM","CCE_NEG_ALPHA","CCE_NEG_BLANK","CCE_NEG_CNTRL","CCE_NEG_DIGIT",
464 "CCE_NEG_GRAPH","CCE_NEG_LOWER","CCE_NEG_PRINT","CCE_NEG_PUNCT","CCE_NEG_SPACE",
465 "CCE_NEG_UPPER","CCE_NEG_XDIGIT","CCL_OP_DIFF","CCL_OP_UNION",
466 "BEGIN_REPEAT_POSIX","END_REPEAT_POSIX","BEGIN_REPEAT_FLEX","END_REPEAT_FLEX",
467 "$accept","goal","initlex","sect1","sect1end","sect2","initforrule",
468 "startconddecl","namelist1","options","optionlist","option","scon","flexrule",
469 "rule","scon_stk_ptr","namelist2","sconname","re2","re","series","singleton",
470 "fullccl","string","braceccl","ccl","ccl_expr","illegal-symbol",
471 };
472 static const char *const yyrule[] = {
473 "$accept : goal",
474 "goal : initlex sect1 sect1end sect2 initforrule",
475 "initlex :",
476 "sect1 : sect1 startconddecl namelist1",
477 "sect1 : sect1 options",
478 "sect1 :",
479 "sect1 : error",
480 "sect1end : SECTEND",
481 "startconddecl : SCDECL",
482 "startconddecl : XSCDECL",
483 "namelist1 : namelist1 NAME",
484 "namelist1 : NAME",
485 "namelist1 : error",
486 "options : TOK_OPTION optionlist",
487 "optionlist : optionlist option",
488 "optionlist :",
489 "option : TOK_OUTFILE '=' NAME",
490 "option : TOK_EXTRA_TYPE '=' NAME",
491 "option : TOK_PREFIX '=' NAME",
492 "option : TOK_YYCLASS '=' NAME",
493 "option : TOK_HEADER_FILE '=' NAME",
494 "option : TOK_TABLES_FILE '=' NAME",
495 "sect2 : sect2 scon initforrule flexrule '\\n'",
496 "sect2 : sect2 scon '{' sect2 '}'",
497 "sect2 :",
498 "initforrule :",
499 "flexrule : '^' rule",
500 "flexrule : rule",
501 "flexrule : EOF_OP",
502 "flexrule : error",
503 "scon_stk_ptr :",
504 "scon : '<' scon_stk_ptr namelist2 '>'",
505 "scon : '<' '*' '>'",
506 "scon :",
507 "namelist2 : namelist2 ',' sconname",
508 "namelist2 : sconname",
509 "namelist2 : error",
510 "sconname : NAME",
511 "rule : re2 re",
512 "rule : re2 re '$'",
513 "rule : re '$'",
514 "rule : re",
515 "re : re '|' series",
516 "re : series",
517 "re2 : re '/'",
518 "series : series singleton",
519 "series : singleton",
520 "series : series BEGIN_REPEAT_POSIX NUMBER ',' NUMBER END_REPEAT_POSIX",
521 "series : series BEGIN_REPEAT_POSIX NUMBER ',' END_REPEAT_POSIX",
522 "series : series BEGIN_REPEAT_POSIX NUMBER END_REPEAT_POSIX",
523 "singleton : singleton '*'",
524 "singleton : singleton '+'",
525 "singleton : singleton '?'",
526 "singleton : singleton BEGIN_REPEAT_FLEX NUMBER ',' NUMBER END_REPEAT_FLEX",
527 "singleton : singleton BEGIN_REPEAT_FLEX NUMBER ',' END_REPEAT_FLEX",
528 "singleton : singleton BEGIN_REPEAT_FLEX NUMBER END_REPEAT_FLEX",
529 "singleton : '.'",
530 "singleton : fullccl",
531 "singleton : PREVCCL",
532 "singleton : '\"' string '\"'",
533 "singleton : '(' re ')'",
534 "singleton : CHAR",
535 "fullccl : fullccl CCL_OP_DIFF braceccl",
536 "fullccl : fullccl CCL_OP_UNION braceccl",
537 "fullccl : braceccl",
538 "braceccl : '[' ccl ']'",
539 "braceccl : '[' '^' ccl ']'",
540 "ccl : ccl CHAR '-' CHAR",
541 "ccl : ccl CHAR",
542 "ccl : ccl ccl_expr",
543 "ccl :",
544 "ccl_expr : CCE_ALNUM",
545 "ccl_expr : CCE_ALPHA",
546 "ccl_expr : CCE_BLANK",
547 "ccl_expr : CCE_CNTRL",
548 "ccl_expr : CCE_DIGIT",
549 "ccl_expr : CCE_GRAPH",
550 "ccl_expr : CCE_LOWER",
551 "ccl_expr : CCE_PRINT",
552 "ccl_expr : CCE_PUNCT",
553 "ccl_expr : CCE_SPACE",
554 "ccl_expr : CCE_XDIGIT",
555 "ccl_expr : CCE_UPPER",
556 "ccl_expr : CCE_NEG_ALNUM",
557 "ccl_expr : CCE_NEG_ALPHA",
558 "ccl_expr : CCE_NEG_BLANK",
559 "ccl_expr : CCE_NEG_CNTRL",
560 "ccl_expr : CCE_NEG_DIGIT",
561 "ccl_expr : CCE_NEG_GRAPH",
562 "ccl_expr : CCE_NEG_PRINT",
563 "ccl_expr : CCE_NEG_PUNCT",
564 "ccl_expr : CCE_NEG_SPACE",
565 "ccl_expr : CCE_NEG_XDIGIT",
566 "ccl_expr : CCE_NEG_LOWER",
567 "ccl_expr : CCE_NEG_UPPER",
568 "string : string CHAR",
569 "string :",
570
571 };
572 #endif
573
574 int yydebug;
575 int yynerrs;
576
577 int yyerrflag;
578 int yychar;
579 YYSTYPE yyval;
580 YYSTYPE yylval;
581
582 /* define the initial stack-sizes */
583 #ifdef YYSTACKSIZE
584 #undef YYMAXDEPTH
585 #define YYMAXDEPTH YYSTACKSIZE
586 #else
587 #ifdef YYMAXDEPTH
588 #define YYSTACKSIZE YYMAXDEPTH
589 #else
590 #define YYSTACKSIZE 10000
591 #define YYMAXDEPTH 10000
592 #endif
593 #endif
594
595 #define YYINITSTACKSIZE 200
596
597 typedef struct {
598 unsigned stacksize;
599 YYINT *s_base;
600 YYINT *s_mark;
601 YYINT *s_last;
602 YYSTYPE *l_base;
603 YYSTYPE *l_mark;
604 } YYSTACKDATA;
605 /* variables for the parser stack */
606 static YYSTACKDATA yystack;
607
608
609 /* build_eof_action - build the "<<EOF>>" action for the active start
610 * conditions
611 */
612
build_eof_action(void)613 void build_eof_action(void)
614 {
615 int i;
616 char action_text[MAXLINE];
617
618 for ( i = 1; i <= scon_stk_ptr; ++i )
619 {
620 if ( sceof[scon_stk[i]] )
621 format_pinpoint_message(
622 "multiple <<EOF>> rules for start condition %s",
623 scname[scon_stk[i]] );
624
625 else
626 {
627 sceof[scon_stk[i]] = true;
628
629 if (previous_continued_action /* && previous action was regular */)
630 add_action("YY_RULE_SETUP\n");
631
632 snprintf( action_text, sizeof(action_text), "case YY_STATE_EOF(%s):\n",
633 scname[scon_stk[i]] );
634 add_action( action_text );
635 }
636 }
637
638 line_directive_out(NULL, 1);
639 add_action("[[");
640
641 /* This isn't a normal rule after all - don't count it as
642 * such, so we don't have any holes in the rule numbering
643 * (which make generating "rule can never match" warnings
644 * more difficult.
645 */
646 --num_rules;
647 ++num_eof_rules;
648 }
649
650
651 /* format_synerr - write out formatted syntax error */
652
format_synerr(const char * msg,const char arg[])653 void format_synerr( const char *msg, const char arg[] )
654 {
655 char errmsg[MAXLINE];
656
657 (void) snprintf( errmsg, sizeof(errmsg), msg, arg );
658 synerr( errmsg );
659 }
660
661
662 /* synerr - report a syntax error */
663
synerr(const char * str)664 void synerr( const char *str )
665 {
666 syntaxerror = true;
667 pinpoint_message( str );
668 }
669
670
671 /* format_warn - write out formatted warning */
672
format_warn(const char * msg,const char arg[])673 void format_warn( const char *msg, const char arg[] )
674 {
675 char warn_msg[MAXLINE];
676
677 snprintf( warn_msg, sizeof(warn_msg), msg, arg );
678 lwarn( warn_msg );
679 }
680
681
682 /* lwarn - report a warning, unless -w was given */
683
lwarn(const char * str)684 void lwarn( const char *str )
685 {
686 line_warning( str, linenum );
687 }
688
689 /* format_pinpoint_message - write out a message formatted with one string,
690 * pinpointing its location
691 */
692
format_pinpoint_message(const char * msg,const char arg[])693 void format_pinpoint_message( const char *msg, const char arg[] )
694 {
695 char errmsg[MAXLINE];
696
697 snprintf( errmsg, sizeof(errmsg), msg, arg );
698 pinpoint_message( errmsg );
699 }
700
701
702 /* pinpoint_message - write out a message, pinpointing its location */
703
pinpoint_message(const char * str)704 void pinpoint_message( const char *str )
705 {
706 line_pinpoint( str, linenum );
707 }
708
709
710 /* line_warning - report a warning at a given line, unless -w was given */
711
line_warning(const char * str,int line)712 void line_warning( const char *str, int line )
713 {
714 char warning[MAXLINE];
715
716 if ( ! nowarn )
717 {
718 snprintf( warning, sizeof(warning), "warning, %s", str );
719 line_pinpoint( warning, line );
720 }
721 }
722
723
724 /* line_pinpoint - write out a message, pinpointing it at the given line */
725
line_pinpoint(const char * str,int line)726 void line_pinpoint( const char *str, int line )
727 {
728 fprintf( stderr, "%s:%d: %s\n", infilename, line, str );
729 }
730
731
732 /* yyerror - eat up an error message from the parser;
733 * currently, messages are ignore
734 */
735
yyerror(const char * msg)736 void yyerror( const char *msg )
737 {
738 (void)msg;
739 }
740
741 #if YYDEBUG
742 #include <stdio.h> /* needed for printf */
743 #endif
744
745 #include <stdlib.h> /* needed for malloc, etc */
746 #include <string.h> /* needed for memset */
747
748 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
yygrowstack(YYSTACKDATA * data)749 static int yygrowstack(YYSTACKDATA *data)
750 {
751 int i;
752 unsigned newsize;
753 YYINT *newss;
754 YYSTYPE *newvs;
755
756 if ((newsize = data->stacksize) == 0)
757 newsize = YYINITSTACKSIZE;
758 else if (newsize >= YYMAXDEPTH)
759 return YYENOMEM;
760 else if ((newsize *= 2) > YYMAXDEPTH)
761 newsize = YYMAXDEPTH;
762
763 i = (int) (data->s_mark - data->s_base);
764 newss = (YYINT *)realloc(data->s_base, newsize * sizeof(*newss));
765 if (newss == 0)
766 return YYENOMEM;
767
768 data->s_base = newss;
769 data->s_mark = newss + i;
770
771 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
772 if (newvs == 0)
773 return YYENOMEM;
774
775 data->l_base = newvs;
776 data->l_mark = newvs + i;
777
778 data->stacksize = newsize;
779 data->s_last = data->s_base + newsize - 1;
780 return 0;
781 }
782
783 #if YYPURE || defined(YY_NO_LEAKS)
yyfreestack(YYSTACKDATA * data)784 static void yyfreestack(YYSTACKDATA *data)
785 {
786 free(data->s_base);
787 free(data->l_base);
788 memset(data, 0, sizeof(*data));
789 }
790 #else
791 #define yyfreestack(data) /* nothing */
792 #endif
793
794 #define YYABORT goto yyabort
795 #define YYREJECT goto yyabort
796 #define YYACCEPT goto yyaccept
797 #define YYERROR goto yyerrlab
798
799 int
YYPARSE_DECL()800 YYPARSE_DECL()
801 {
802 int yym, yyn, yystate;
803 #if YYDEBUG
804 const char *yys;
805
806 if ((yys = getenv("YYDEBUG")) != 0)
807 {
808 yyn = *yys;
809 if (yyn >= '0' && yyn <= '9')
810 yydebug = yyn - '0';
811 }
812 #endif
813
814 yynerrs = 0;
815 yyerrflag = 0;
816 yychar = YYEMPTY;
817 yystate = 0;
818
819 #if YYPURE
820 memset(&yystack, 0, sizeof(yystack));
821 #endif
822
823 if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
824 yystack.s_mark = yystack.s_base;
825 yystack.l_mark = yystack.l_base;
826 yystate = 0;
827 *yystack.s_mark = 0;
828
829 yyloop:
830 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
831 if (yychar < 0)
832 {
833 if ((yychar = YYLEX) < 0) yychar = YYEOF;
834 #if YYDEBUG
835 if (yydebug)
836 {
837 yys = yyname[YYTRANSLATE(yychar)];
838 printf("%sdebug: state %d, reading %d (%s)\n",
839 YYPREFIX, yystate, yychar, yys);
840 }
841 #endif
842 }
843 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
844 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
845 {
846 #if YYDEBUG
847 if (yydebug)
848 printf("%sdebug: state %d, shifting to state %d\n",
849 YYPREFIX, yystate, yytable[yyn]);
850 #endif
851 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM)
852 {
853 goto yyoverflow;
854 }
855 yystate = yytable[yyn];
856 *++yystack.s_mark = yytable[yyn];
857 *++yystack.l_mark = yylval;
858 yychar = YYEMPTY;
859 if (yyerrflag > 0) --yyerrflag;
860 goto yyloop;
861 }
862 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
863 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
864 {
865 yyn = yytable[yyn];
866 goto yyreduce;
867 }
868 if (yyerrflag) goto yyinrecovery;
869
870 YYERROR_CALL("syntax error");
871
872 goto yyerrlab;
873
874 yyerrlab:
875 ++yynerrs;
876
877 yyinrecovery:
878 if (yyerrflag < 3)
879 {
880 yyerrflag = 3;
881 for (;;)
882 {
883 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
884 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
885 {
886 #if YYDEBUG
887 if (yydebug)
888 printf("%sdebug: state %d, error recovery shifting\
889 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
890 #endif
891 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM)
892 {
893 goto yyoverflow;
894 }
895 yystate = yytable[yyn];
896 *++yystack.s_mark = yytable[yyn];
897 *++yystack.l_mark = yylval;
898 goto yyloop;
899 }
900 else
901 {
902 #if YYDEBUG
903 if (yydebug)
904 printf("%sdebug: error recovery discarding state %d\n",
905 YYPREFIX, *yystack.s_mark);
906 #endif
907 if (yystack.s_mark <= yystack.s_base) goto yyabort;
908 --yystack.s_mark;
909 --yystack.l_mark;
910 }
911 }
912 }
913 else
914 {
915 if (yychar == YYEOF) goto yyabort;
916 #if YYDEBUG
917 if (yydebug)
918 {
919 yys = yyname[YYTRANSLATE(yychar)];
920 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
921 YYPREFIX, yystate, yychar, yys);
922 }
923 #endif
924 yychar = YYEMPTY;
925 goto yyloop;
926 }
927
928 yyreduce:
929 #if YYDEBUG
930 if (yydebug)
931 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
932 YYPREFIX, yystate, yyn, yyrule[yyn]);
933 #endif
934 yym = yylen[yyn];
935 if (yym)
936 yyval = yystack.l_mark[1-yym];
937 else
938 memset(&yyval, 0, sizeof yyval);
939 switch (yyn)
940 {
941 case 1:
942 { /* add default rule */
943 int def_rule;
944
945 pat = cclinit();
946 cclnegate( pat );
947
948 def_rule = mkstate( -pat );
949
950 /* Remember the number of the default rule so we
951 * don't generate "can't match" warnings for it.
952 */
953 default_rule = num_rules;
954
955 finish_rule( def_rule, false, 0, 0, 0);
956
957 for ( i = 1; i <= lastsc; ++i )
958 scset[i] = mkbranch( scset[i], def_rule );
959
960 if ( spprdflt )
961 add_action(
962 "YY_FATAL_ERROR( \"flex scanner jammed\" )" );
963 else
964 add_action( "ECHO" );
965
966 add_action( ";\n\tYY_BREAK]]\n" );
967 }
968 break;
969 case 2:
970 { /* initialize for processing rules */
971
972 /* Create default DFA start condition. */
973 scinstal( "INITIAL", false );
974 }
975 break;
976 case 6:
977 { synerr( _("unknown error processing section 1") ); }
978 break;
979 case 7:
980 {
981 check_options();
982 scon_stk = allocate_integer_array( lastsc + 1 );
983 scon_stk_ptr = 0;
984 }
985 break;
986 case 8:
987 { xcluflg = false; }
988 break;
989 case 9:
990 { xcluflg = true; }
991 break;
992 case 10:
993 { scinstal( nmstr, xcluflg ); }
994 break;
995 case 11:
996 { scinstal( nmstr, xcluflg ); }
997 break;
998 case 12:
999 { synerr( _("bad start condition list") ); }
1000 break;
1001 case 16:
1002 {
1003 outfilename = xstrdup(nmstr);
1004 did_outfilename = 1;
1005 }
1006 break;
1007 case 17:
1008 { extra_type = xstrdup(nmstr); }
1009 break;
1010 case 18:
1011 { prefix = xstrdup(nmstr);
1012 if (strchr(prefix, '[') || strchr(prefix, ']'))
1013 flexerror(_("Prefix must not contain [ or ]")); }
1014 break;
1015 case 19:
1016 { yyclass = xstrdup(nmstr); }
1017 break;
1018 case 20:
1019 { headerfilename = xstrdup(nmstr); }
1020 break;
1021 case 21:
1022 { tablesext = true; tablesfilename = xstrdup(nmstr); }
1023 break;
1024 case 22:
1025 { scon_stk_ptr = yystack.l_mark[-3]; }
1026 break;
1027 case 23:
1028 { scon_stk_ptr = yystack.l_mark[-3]; }
1029 break;
1030 case 25:
1031 {
1032 /* Initialize for a parse of one rule. */
1033 trlcontxt = variable_trail_rule = varlength = false;
1034 trailcnt = headcnt = rulelen = 0;
1035 current_state_type = STATE_NORMAL;
1036 previous_continued_action = continued_action;
1037 in_rule = true;
1038
1039 new_rule();
1040 }
1041 break;
1042 case 26:
1043 {
1044 pat = yystack.l_mark[0];
1045 finish_rule( pat, variable_trail_rule,
1046 headcnt, trailcnt , previous_continued_action);
1047
1048 if ( scon_stk_ptr > 0 )
1049 {
1050 for ( i = 1; i <= scon_stk_ptr; ++i )
1051 scbol[scon_stk[i]] =
1052 mkbranch( scbol[scon_stk[i]],
1053 pat );
1054 }
1055
1056 else
1057 {
1058 /* Add to all non-exclusive start conditions,
1059 * including the default (0) start condition.
1060 */
1061
1062 for ( i = 1; i <= lastsc; ++i )
1063 if ( ! scxclu[i] )
1064 scbol[i] = mkbranch( scbol[i],
1065 pat );
1066 }
1067
1068 if ( ! bol_needed )
1069 {
1070 bol_needed = true;
1071
1072 if ( performance_report > 1 )
1073 pinpoint_message(
1074 "'^' operator results in sub-optimal performance" );
1075 }
1076 }
1077 break;
1078 case 27:
1079 {
1080 pat = yystack.l_mark[0];
1081 finish_rule( pat, variable_trail_rule,
1082 headcnt, trailcnt , previous_continued_action);
1083
1084 if ( scon_stk_ptr > 0 )
1085 {
1086 for ( i = 1; i <= scon_stk_ptr; ++i )
1087 scset[scon_stk[i]] =
1088 mkbranch( scset[scon_stk[i]],
1089 pat );
1090 }
1091
1092 else
1093 {
1094 for ( i = 1; i <= lastsc; ++i )
1095 if ( ! scxclu[i] )
1096 scset[i] =
1097 mkbranch( scset[i],
1098 pat );
1099 }
1100 }
1101 break;
1102 case 28:
1103 {
1104 if ( scon_stk_ptr > 0 )
1105 build_eof_action();
1106
1107 else
1108 {
1109 /* This EOF applies to all start conditions
1110 * which don't already have EOF actions.
1111 */
1112 for ( i = 1; i <= lastsc; ++i )
1113 if ( ! sceof[i] )
1114 scon_stk[++scon_stk_ptr] = i;
1115
1116 if ( scon_stk_ptr == 0 )
1117 lwarn(
1118 "all start conditions already have <<EOF>> rules" );
1119
1120 else
1121 build_eof_action();
1122 }
1123 }
1124 break;
1125 case 29:
1126 { synerr( _("unrecognized rule") ); }
1127 break;
1128 case 30:
1129 { yyval = scon_stk_ptr; }
1130 break;
1131 case 31:
1132 { yyval = yystack.l_mark[-2]; }
1133 break;
1134 case 32:
1135 {
1136 yyval = scon_stk_ptr;
1137
1138 for ( i = 1; i <= lastsc; ++i )
1139 {
1140 int j;
1141
1142 for ( j = 1; j <= scon_stk_ptr; ++j )
1143 if ( scon_stk[j] == i )
1144 break;
1145
1146 if ( j > scon_stk_ptr )
1147 scon_stk[++scon_stk_ptr] = i;
1148 }
1149 }
1150 break;
1151 case 33:
1152 { yyval = scon_stk_ptr; }
1153 break;
1154 case 36:
1155 { synerr( _("bad start condition list") ); }
1156 break;
1157 case 37:
1158 {
1159 if ( (scnum = sclookup( nmstr )) == 0 )
1160 format_pinpoint_message(
1161 "undeclared start condition %s",
1162 nmstr );
1163 else
1164 {
1165 for ( i = 1; i <= scon_stk_ptr; ++i )
1166 if ( scon_stk[i] == scnum )
1167 {
1168 format_warn(
1169 "<%s> specified twice",
1170 scname[scnum] );
1171 break;
1172 }
1173
1174 if ( i > scon_stk_ptr )
1175 scon_stk[++scon_stk_ptr] = scnum;
1176 }
1177 }
1178 break;
1179 case 38:
1180 {
1181 if ( transchar[lastst[yystack.l_mark[0]]] != SYM_EPSILON )
1182 /* Provide final transition \now/ so it
1183 * will be marked as a trailing context
1184 * state.
1185 */
1186 yystack.l_mark[0] = link_machines( yystack.l_mark[0],
1187 mkstate( SYM_EPSILON ) );
1188
1189 mark_beginning_as_normal( yystack.l_mark[0] );
1190 current_state_type = STATE_NORMAL;
1191
1192 if ( previous_continued_action )
1193 {
1194 /* We need to treat this as variable trailing
1195 * context so that the backup does not happen
1196 * in the action but before the action switch
1197 * statement. If the backup happens in the
1198 * action, then the rules "falling into" this
1199 * one's action will *also* do the backup,
1200 * erroneously.
1201 */
1202 if ( ! varlength || headcnt != 0 )
1203 lwarn(
1204 "trailing context made variable due to preceding '|' action" );
1205
1206 /* Mark as variable. */
1207 varlength = true;
1208 headcnt = 0;
1209
1210 }
1211
1212 if ( lex_compat || (varlength && headcnt == 0) )
1213 { /* variable trailing context rule */
1214 /* Mark the first part of the rule as the
1215 * accepting "head" part of a trailing
1216 * context rule.
1217 *
1218 * By the way, we didn't do this at the
1219 * beginning of this production because back
1220 * then current_state_type was set up for a
1221 * trail rule, and add_accept() can create
1222 * a new state ...
1223 */
1224 add_accept( yystack.l_mark[-1],
1225 num_rules | YY_TRAILING_HEAD_MASK );
1226 variable_trail_rule = true;
1227 }
1228
1229 else
1230 trailcnt = rulelen;
1231
1232 yyval = link_machines( yystack.l_mark[-1], yystack.l_mark[0] );
1233 }
1234 break;
1235 case 39:
1236 { synerr( _("trailing context used twice") ); }
1237 break;
1238 case 40:
1239 {
1240 headcnt = 0;
1241 trailcnt = 1;
1242 rulelen = 1;
1243 varlength = false;
1244
1245 current_state_type = STATE_TRAILING_CONTEXT;
1246
1247 if ( trlcontxt )
1248 {
1249 synerr( _("trailing context used twice") );
1250 yyval = mkstate( SYM_EPSILON );
1251 }
1252
1253 else if ( previous_continued_action )
1254 {
1255 /* See the comment in the rule for "re2 re"
1256 * above.
1257 */
1258 lwarn(
1259 "trailing context made variable due to preceding '|' action" );
1260
1261 varlength = true;
1262 }
1263
1264 if ( lex_compat || varlength )
1265 {
1266 /* Again, see the comment in the rule for
1267 * "re2 re" above.
1268 */
1269 add_accept( yystack.l_mark[-1],
1270 num_rules | YY_TRAILING_HEAD_MASK );
1271 variable_trail_rule = true;
1272 }
1273
1274 trlcontxt = true;
1275
1276 eps = mkstate( SYM_EPSILON );
1277 yyval = link_machines( yystack.l_mark[-1],
1278 link_machines( eps, mkstate( '\n' ) ) );
1279 }
1280 break;
1281 case 41:
1282 {
1283 yyval = yystack.l_mark[0];
1284
1285 if ( trlcontxt )
1286 {
1287 if ( lex_compat || (varlength && headcnt == 0) )
1288 /* Both head and trail are
1289 * variable-length.
1290 */
1291 variable_trail_rule = true;
1292 else
1293 trailcnt = rulelen;
1294 }
1295 }
1296 break;
1297 case 42:
1298 {
1299 varlength = true;
1300 yyval = mkor( yystack.l_mark[-2], yystack.l_mark[0] );
1301 }
1302 break;
1303 case 43:
1304 { yyval = yystack.l_mark[0]; }
1305 break;
1306 case 44:
1307 {
1308 /* This rule is written separately so the
1309 * reduction will occur before the trailing
1310 * series is parsed.
1311 */
1312
1313 if ( trlcontxt )
1314 synerr( _("trailing context used twice") );
1315 else
1316 trlcontxt = true;
1317
1318 if ( varlength )
1319 /* We hope the trailing context is
1320 * fixed-length.
1321 */
1322 varlength = false;
1323 else
1324 headcnt = rulelen;
1325
1326 rulelen = 0;
1327
1328 current_state_type = STATE_TRAILING_CONTEXT;
1329 yyval = yystack.l_mark[-1];
1330 }
1331 break;
1332 case 45:
1333 {
1334 /* This is where concatenation of adjacent patterns
1335 * gets done.
1336 */
1337 yyval = link_machines( yystack.l_mark[-1], yystack.l_mark[0] );
1338 }
1339 break;
1340 case 46:
1341 { yyval = yystack.l_mark[0]; }
1342 break;
1343 case 47:
1344 {
1345 varlength = true;
1346
1347 if ( yystack.l_mark[-3] > yystack.l_mark[-1] || yystack.l_mark[-3] < 0 )
1348 {
1349 synerr( _("bad iteration values") );
1350 yyval = yystack.l_mark[-5];
1351 }
1352 else
1353 {
1354 if ( yystack.l_mark[-3] == 0 )
1355 {
1356 if ( yystack.l_mark[-1] <= 0 )
1357 {
1358 synerr(
1359 _("bad iteration values") );
1360 yyval = yystack.l_mark[-5];
1361 }
1362 else
1363 yyval = mkopt(
1364 mkrep( yystack.l_mark[-5], 1, yystack.l_mark[-1] ) );
1365 }
1366 else
1367 yyval = mkrep( yystack.l_mark[-5], yystack.l_mark[-3], yystack.l_mark[-1] );
1368 }
1369 }
1370 break;
1371 case 48:
1372 {
1373 varlength = true;
1374
1375 if ( yystack.l_mark[-2] <= 0 )
1376 {
1377 synerr( _("iteration value must be positive") );
1378 yyval = yystack.l_mark[-4];
1379 }
1380
1381 else
1382 yyval = mkrep( yystack.l_mark[-4], yystack.l_mark[-2], INFINITE_REPEAT );
1383 }
1384 break;
1385 case 49:
1386 {
1387 /* The series could be something like "(foo)",
1388 * in which case we have no idea what its length
1389 * is, so we punt here.
1390 */
1391 varlength = true;
1392
1393 if ( yystack.l_mark[-1] <= 0 )
1394 {
1395 synerr( _("iteration value must be positive")
1396 );
1397 yyval = yystack.l_mark[-3];
1398 }
1399
1400 else
1401 yyval = link_machines( yystack.l_mark[-3],
1402 copysingl( yystack.l_mark[-3], yystack.l_mark[-1] - 1 ) );
1403 }
1404 break;
1405 case 50:
1406 {
1407 varlength = true;
1408
1409 yyval = mkclos( yystack.l_mark[-1] );
1410 }
1411 break;
1412 case 51:
1413 {
1414 varlength = true;
1415 yyval = mkposcl( yystack.l_mark[-1] );
1416 }
1417 break;
1418 case 52:
1419 {
1420 varlength = true;
1421 yyval = mkopt( yystack.l_mark[-1] );
1422 }
1423 break;
1424 case 53:
1425 {
1426 varlength = true;
1427
1428 if ( yystack.l_mark[-3] > yystack.l_mark[-1] || yystack.l_mark[-3] < 0 )
1429 {
1430 synerr( _("bad iteration values") );
1431 yyval = yystack.l_mark[-5];
1432 }
1433 else
1434 {
1435 if ( yystack.l_mark[-3] == 0 )
1436 {
1437 if ( yystack.l_mark[-1] <= 0 )
1438 {
1439 synerr(
1440 _("bad iteration values") );
1441 yyval = yystack.l_mark[-5];
1442 }
1443 else
1444 yyval = mkopt(
1445 mkrep( yystack.l_mark[-5], 1, yystack.l_mark[-1] ) );
1446 }
1447 else
1448 yyval = mkrep( yystack.l_mark[-5], yystack.l_mark[-3], yystack.l_mark[-1] );
1449 }
1450 }
1451 break;
1452 case 54:
1453 {
1454 varlength = true;
1455
1456 if ( yystack.l_mark[-2] <= 0 )
1457 {
1458 synerr( _("iteration value must be positive") );
1459 yyval = yystack.l_mark[-4];
1460 }
1461
1462 else
1463 yyval = mkrep( yystack.l_mark[-4], yystack.l_mark[-2], INFINITE_REPEAT );
1464 }
1465 break;
1466 case 55:
1467 {
1468 /* The singleton could be something like "(foo)",
1469 * in which case we have no idea what its length
1470 * is, so we punt here.
1471 */
1472 varlength = true;
1473
1474 if ( yystack.l_mark[-1] <= 0 )
1475 {
1476 synerr( _("iteration value must be positive") );
1477 yyval = yystack.l_mark[-3];
1478 }
1479
1480 else
1481 yyval = link_machines( yystack.l_mark[-3],
1482 copysingl( yystack.l_mark[-3], yystack.l_mark[-1] - 1 ) );
1483 }
1484 break;
1485 case 56:
1486 {
1487 if ( ! madeany )
1488 {
1489 /* Create the '.' character class. */
1490 ccldot = cclinit();
1491 ccladd( ccldot, '\n' );
1492 cclnegate( ccldot );
1493
1494 if ( useecs )
1495 mkeccl( ccltbl + cclmap[ccldot],
1496 ccllen[ccldot], nextecm,
1497 ecgroup, csize, csize );
1498
1499 /* Create the (?s:'.') character class. */
1500 cclany = cclinit();
1501 cclnegate( cclany );
1502
1503 if ( useecs )
1504 mkeccl( ccltbl + cclmap[cclany],
1505 ccllen[cclany], nextecm,
1506 ecgroup, csize, csize );
1507
1508 madeany = true;
1509 }
1510
1511 ++rulelen;
1512
1513 if (sf_dot_all())
1514 yyval = mkstate( -cclany );
1515 else
1516 yyval = mkstate( -ccldot );
1517 }
1518 break;
1519 case 57:
1520 {
1521 /* Sort characters for fast searching.
1522 */
1523 qsort( ccltbl + cclmap[yystack.l_mark[0]], (size_t) ccllen[yystack.l_mark[0]], sizeof (*ccltbl), cclcmp );
1524
1525 if ( useecs )
1526 mkeccl( ccltbl + cclmap[yystack.l_mark[0]], ccllen[yystack.l_mark[0]],
1527 nextecm, ecgroup, csize, csize );
1528
1529 ++rulelen;
1530
1531 if (ccl_has_nl[yystack.l_mark[0]])
1532 rule_has_nl[num_rules] = true;
1533
1534 yyval = mkstate( -yystack.l_mark[0] );
1535 }
1536 break;
1537 case 58:
1538 {
1539 ++rulelen;
1540
1541 if (ccl_has_nl[yystack.l_mark[0]])
1542 rule_has_nl[num_rules] = true;
1543
1544 yyval = mkstate( -yystack.l_mark[0] );
1545 }
1546 break;
1547 case 59:
1548 { yyval = yystack.l_mark[-1]; }
1549 break;
1550 case 60:
1551 { yyval = yystack.l_mark[-1]; }
1552 break;
1553 case 61:
1554 {
1555 ++rulelen;
1556
1557 if (yystack.l_mark[0] == nlch)
1558 rule_has_nl[num_rules] = true;
1559
1560 if (sf_case_ins() && has_case(yystack.l_mark[0]))
1561 /* create an alternation, as in (a|A) */
1562 yyval = mkor (mkstate(yystack.l_mark[0]), mkstate(reverse_case(yystack.l_mark[0])));
1563 else
1564 yyval = mkstate( yystack.l_mark[0] );
1565 }
1566 break;
1567 case 62:
1568 { yyval = ccl_set_diff (yystack.l_mark[-2], yystack.l_mark[0]); }
1569 break;
1570 case 63:
1571 { yyval = ccl_set_union (yystack.l_mark[-2], yystack.l_mark[0]); }
1572 break;
1573 case 65:
1574 { yyval = yystack.l_mark[-1]; }
1575 break;
1576 case 66:
1577 {
1578 cclnegate( yystack.l_mark[-1] );
1579 yyval = yystack.l_mark[-1];
1580 }
1581 break;
1582 case 67:
1583 {
1584
1585 if (sf_case_ins())
1586 {
1587
1588 /* If one end of the range has case and the other
1589 * does not, or the cases are different, then we're not
1590 * sure what range the user is trying to express.
1591 * Examples: [@-z] or [S-t]
1592 */
1593 if (has_case (yystack.l_mark[-2]) != has_case (yystack.l_mark[0])
1594 || (has_case (yystack.l_mark[-2]) && (b_islower (yystack.l_mark[-2]) != b_islower (yystack.l_mark[0])))
1595 || (has_case (yystack.l_mark[-2]) && (b_isupper (yystack.l_mark[-2]) != b_isupper (yystack.l_mark[0]))))
1596 format_warn3 (
1597 _("the character range [%c-%c] is ambiguous in a case-insensitive scanner"),
1598 yystack.l_mark[-2], yystack.l_mark[0]);
1599
1600 /* If the range spans uppercase characters but not
1601 * lowercase (or vice-versa), then should we automatically
1602 * include lowercase characters in the range?
1603 * Example: [@-_] spans [a-z] but not [A-Z]
1604 */
1605 else if (!has_case (yystack.l_mark[-2]) && !has_case (yystack.l_mark[0]) && !range_covers_case (yystack.l_mark[-2], yystack.l_mark[0]))
1606 format_warn3 (
1607 _("the character range [%c-%c] is ambiguous in a case-insensitive scanner"),
1608 yystack.l_mark[-2], yystack.l_mark[0]);
1609 }
1610
1611 if ( yystack.l_mark[-2] > yystack.l_mark[0] )
1612 synerr( _("negative range in character class") );
1613
1614 else
1615 {
1616 for ( i = yystack.l_mark[-2]; i <= yystack.l_mark[0]; ++i )
1617 ccladd( yystack.l_mark[-3], i );
1618
1619 /* Keep track if this ccl is staying in
1620 * alphabetical order.
1621 */
1622 cclsorted = cclsorted && (yystack.l_mark[-2] > lastchar);
1623 lastchar = yystack.l_mark[0];
1624
1625 /* Do it again for upper/lowercase */
1626 if (sf_case_ins() && has_case(yystack.l_mark[-2]) && has_case(yystack.l_mark[0])){
1627 yystack.l_mark[-2] = reverse_case (yystack.l_mark[-2]);
1628 yystack.l_mark[0] = reverse_case (yystack.l_mark[0]);
1629
1630 for ( i = yystack.l_mark[-2]; i <= yystack.l_mark[0]; ++i )
1631 ccladd( yystack.l_mark[-3], i );
1632
1633 cclsorted = cclsorted && (yystack.l_mark[-2] > lastchar);
1634 lastchar = yystack.l_mark[0];
1635 }
1636
1637 }
1638
1639 yyval = yystack.l_mark[-3];
1640 }
1641 break;
1642 case 68:
1643 {
1644 ccladd( yystack.l_mark[-1], yystack.l_mark[0] );
1645 cclsorted = cclsorted && (yystack.l_mark[0] > lastchar);
1646 lastchar = yystack.l_mark[0];
1647
1648 /* Do it again for upper/lowercase */
1649 if (sf_case_ins() && has_case(yystack.l_mark[0])){
1650 yystack.l_mark[0] = reverse_case (yystack.l_mark[0]);
1651 ccladd (yystack.l_mark[-1], yystack.l_mark[0]);
1652
1653 cclsorted = cclsorted && (yystack.l_mark[0] > lastchar);
1654 lastchar = yystack.l_mark[0];
1655 }
1656
1657 yyval = yystack.l_mark[-1];
1658 }
1659 break;
1660 case 69:
1661 {
1662 /* Too hard to properly maintain cclsorted. */
1663 cclsorted = false;
1664 yyval = yystack.l_mark[-1];
1665 }
1666 break;
1667 case 70:
1668 {
1669 cclsorted = true;
1670 lastchar = 0;
1671 currccl = yyval = cclinit();
1672 }
1673 break;
1674 case 71:
1675 { CCL_EXPR(isalnum); }
1676 break;
1677 case 72:
1678 { CCL_EXPR(isalpha); }
1679 break;
1680 case 73:
1681 { CCL_EXPR(IS_BLANK); }
1682 break;
1683 case 74:
1684 { CCL_EXPR(iscntrl); }
1685 break;
1686 case 75:
1687 { CCL_EXPR(isdigit); }
1688 break;
1689 case 76:
1690 { CCL_EXPR(isgraph); }
1691 break;
1692 case 77:
1693 {
1694 CCL_EXPR(islower);
1695 if (sf_case_ins())
1696 CCL_EXPR(isupper);
1697 }
1698 break;
1699 case 78:
1700 { CCL_EXPR(isprint); }
1701 break;
1702 case 79:
1703 { CCL_EXPR(ispunct); }
1704 break;
1705 case 80:
1706 { CCL_EXPR(isspace); }
1707 break;
1708 case 81:
1709 { CCL_EXPR(isxdigit); }
1710 break;
1711 case 82:
1712 {
1713 CCL_EXPR(isupper);
1714 if (sf_case_ins())
1715 CCL_EXPR(islower);
1716 }
1717 break;
1718 case 83:
1719 { CCL_NEG_EXPR(isalnum); }
1720 break;
1721 case 84:
1722 { CCL_NEG_EXPR(isalpha); }
1723 break;
1724 case 85:
1725 { CCL_NEG_EXPR(IS_BLANK); }
1726 break;
1727 case 86:
1728 { CCL_NEG_EXPR(iscntrl); }
1729 break;
1730 case 87:
1731 { CCL_NEG_EXPR(isdigit); }
1732 break;
1733 case 88:
1734 { CCL_NEG_EXPR(isgraph); }
1735 break;
1736 case 89:
1737 { CCL_NEG_EXPR(isprint); }
1738 break;
1739 case 90:
1740 { CCL_NEG_EXPR(ispunct); }
1741 break;
1742 case 91:
1743 { CCL_NEG_EXPR(isspace); }
1744 break;
1745 case 92:
1746 { CCL_NEG_EXPR(isxdigit); }
1747 break;
1748 case 93:
1749 {
1750 if ( sf_case_ins() )
1751 lwarn(_("[:^lower:] is ambiguous in case insensitive scanner"));
1752 else
1753 CCL_NEG_EXPR(islower);
1754 }
1755 break;
1756 case 94:
1757 {
1758 if ( sf_case_ins() )
1759 lwarn(_("[:^upper:] ambiguous in case insensitive scanner"));
1760 else
1761 CCL_NEG_EXPR(isupper);
1762 }
1763 break;
1764 case 95:
1765 {
1766 if ( yystack.l_mark[0] == nlch )
1767 rule_has_nl[num_rules] = true;
1768
1769 ++rulelen;
1770
1771 if (sf_case_ins() && has_case(yystack.l_mark[0]))
1772 yyval = mkor (mkstate(yystack.l_mark[0]), mkstate(reverse_case(yystack.l_mark[0])));
1773 else
1774 yyval = mkstate (yystack.l_mark[0]);
1775
1776 yyval = link_machines( yystack.l_mark[-1], yyval);
1777 }
1778 break;
1779 case 96:
1780 { yyval = mkstate( SYM_EPSILON ); }
1781 break;
1782 }
1783 yystack.s_mark -= yym;
1784 yystate = *yystack.s_mark;
1785 yystack.l_mark -= yym;
1786 yym = yylhs[yyn];
1787 if (yystate == 0 && yym == 0)
1788 {
1789 #if YYDEBUG
1790 if (yydebug)
1791 printf("%sdebug: after reduction, shifting from state 0 to\
1792 state %d\n", YYPREFIX, YYFINAL);
1793 #endif
1794 yystate = YYFINAL;
1795 *++yystack.s_mark = YYFINAL;
1796 *++yystack.l_mark = yyval;
1797 if (yychar < 0)
1798 {
1799 if ((yychar = YYLEX) < 0) yychar = YYEOF;
1800 #if YYDEBUG
1801 if (yydebug)
1802 {
1803 yys = yyname[YYTRANSLATE(yychar)];
1804 printf("%sdebug: state %d, reading %d (%s)\n",
1805 YYPREFIX, YYFINAL, yychar, yys);
1806 }
1807 #endif
1808 }
1809 if (yychar == YYEOF) goto yyaccept;
1810 goto yyloop;
1811 }
1812 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
1813 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
1814 yystate = yytable[yyn];
1815 else
1816 yystate = yydgoto[yym];
1817 #if YYDEBUG
1818 if (yydebug)
1819 printf("%sdebug: after reduction, shifting from state %d \
1820 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
1821 #endif
1822 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM)
1823 {
1824 goto yyoverflow;
1825 }
1826 *++yystack.s_mark = (YYINT) yystate;
1827 *++yystack.l_mark = yyval;
1828 goto yyloop;
1829
1830 yyoverflow:
1831 YYERROR_CALL("yacc stack overflow");
1832
1833 yyabort:
1834 yyfreestack(&yystack);
1835 return (1);
1836
1837 yyaccept:
1838 yyfreestack(&yystack);
1839 return (0);
1840 }
1841