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