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