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