Merge from vendor branch CVS:
[dragonfly.git] / contrib / awk / awktab.c
1
2 /*  A Bison parser, made from ./awk.y
3  by  GNU Bison version 1.25
4   */
5
6 #define YYBISON 1  /* Identify Bison output.  */
7
8 #define FUNC_CALL       258
9 #define NAME    259
10 #define REGEXP  260
11 #define ERROR   261
12 #define YNUMBER 262
13 #define YSTRING 263
14 #define RELOP   264
15 #define APPEND_OP       265
16 #define ASSIGNOP        266
17 #define MATCHOP 267
18 #define NEWLINE 268
19 #define CONCAT_OP       269
20 #define LEX_BEGIN       270
21 #define LEX_END 271
22 #define LEX_IF  272
23 #define LEX_ELSE        273
24 #define LEX_RETURN      274
25 #define LEX_DELETE      275
26 #define LEX_WHILE       276
27 #define LEX_DO  277
28 #define LEX_FOR 278
29 #define LEX_BREAK       279
30 #define LEX_CONTINUE    280
31 #define LEX_PRINT       281
32 #define LEX_PRINTF      282
33 #define LEX_NEXT        283
34 #define LEX_EXIT        284
35 #define LEX_FUNCTION    285
36 #define LEX_GETLINE     286
37 #define LEX_NEXTFILE    287
38 #define LEX_IN  288
39 #define LEX_AND 289
40 #define LEX_OR  290
41 #define INCREMENT       291
42 #define DECREMENT       292
43 #define LEX_BUILTIN     293
44 #define LEX_LENGTH      294
45 #define UNARY   295
46
47 #line 26 "./awk.y"
48
49 #ifdef DEBUG
50 #define YYDEBUG 12
51 #endif
52
53 #include "awk.h"
54
55 #define CAN_FREE        TRUE
56 #define DONT_FREE       FALSE
57
58 #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
59 static void yyerror(const char *m, ...) ;
60 #else
61 static void yyerror(); /* va_alist */
62 #endif
63 static char *get_src_buf P((void));
64 static int yylex P((void));
65 static NODE *node_common P((NODETYPE op));
66 static NODE *snode P((NODE *subn, NODETYPE op, int sindex));
67 static NODE *mkrangenode P((NODE *cpair));
68 static NODE *make_for_loop P((NODE *init, NODE *cond, NODE *incr));
69 static NODE *append_right P((NODE *list, NODE *new));
70 static void func_install P((NODE *params, NODE *def));
71 static void pop_var P((NODE *np, int freeit));
72 static void pop_params P((NODE *params));
73 static NODE *make_param P((char *name));
74 static NODE *mk_rexp P((NODE *exp));
75 static int dup_parms P((NODE *func));
76 static void param_sanity P((NODE *arglist));
77 static int isnoeffect P((NODETYPE t));
78 static int isassignable P((NODE *n));
79
80 enum defref { FUNC_DEFINE, FUNC_USE };
81 static void func_use P((char *name, enum defref how));
82 static void check_funcs P((void));
83
84 static int want_assign;         /* lexical scanning kludge */
85 static int want_regexp;         /* lexical scanning kludge */
86 static int can_return;          /* lexical scanning kludge */
87 static int io_allowed = TRUE;   /* lexical scanning kludge */
88 static char *lexptr;            /* pointer to next char during parsing */
89 static char *lexend;
90 static char *lexptr_begin;      /* keep track of where we were for error msgs */
91 static char *lexeme;            /* beginning of lexeme for debugging */
92 static char *thisline = NULL;
93 #define YYDEBUG_LEXER_TEXT (lexeme)
94 static int param_counter;
95 static char *tokstart = NULL;
96 static char *tok = NULL;
97 static char *tokend;
98
99 #define HASHSIZE        1021    /* this constant only used here */
100 NODE *variables[HASHSIZE];
101
102 extern char *source;
103 extern int sourceline;
104 extern struct src *srcfiles;
105 extern int numfiles;
106 extern int errcount;
107 extern NODE *begin_block;
108 extern NODE *end_block;
109
110 #line 89 "./awk.y"
111 typedef union {
112         long lval;
113         AWKNUM fval;
114         NODE *nodeval;
115         NODETYPE nodetypeval;
116         char *sval;
117         NODE *(*ptrval)();
118 } YYSTYPE;
119 #include <stdio.h>
120
121 #ifndef __cplusplus
122 #ifndef __STDC__
123 #define const
124 #endif
125 #endif
126
127
128
129 #define YYFINAL         312
130 #define YYFLAG          -32768
131 #define YYNTBASE        62
132
133 #define YYTRANSLATE(x) ((unsigned)(x) <= 295 ? yytranslate[x] : 107)
134
135 static const char yytranslate[] = {     0,
136      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
137      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
138      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
139      2,     2,    51,     2,     2,    54,    50,     2,     2,    55,
140     56,    48,    46,    42,    47,     2,    49,     2,     2,     2,
141      2,     2,     2,     2,     2,     2,     2,    41,    61,    43,
142      2,    44,    40,     2,     2,     2,     2,     2,     2,     2,
143      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
144      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
145     57,     2,    58,    53,     2,     2,     2,     2,     2,     2,
146      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
147      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
148      2,     2,    59,    45,    60,     2,     2,     2,     2,     2,
149      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
150      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
151      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
152      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
153      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
154      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
155      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
156      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
157      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
158      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
159      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
160      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
161      2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
162      6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
163     16,    17,    18,    19,    20,    21,    22,    23,    24,    25,
164     26,    27,    28,    29,    30,    31,    32,    33,    34,    35,
165     36,    37,    38,    39,    52
166 };
167
168 #if YYDEBUG != 0
169 static const short yyprhs[] = {     0,
170      0,     4,     6,     9,    11,    14,    15,    16,    20,    21,
171     25,    28,    31,    34,    36,    39,    42,    44,    46,    48,
172     50,    52,    53,    61,    66,    71,    73,    77,    78,    83,
173     89,    94,    96,    99,   101,   104,   106,   109,   112,   115,
174    119,   121,   128,   137,   146,   157,   167,   170,   173,   180,
175    185,   189,   192,   196,   197,   202,   209,   213,   216,   218,
176    220,   227,   237,   239,   242,   243,   245,   246,   249,   250,
177    253,   256,   259,   260,   262,   264,   268,   270,   273,   277,
178    278,   280,   281,   283,   285,   289,   291,   294,   298,   302,
179    303,   305,   307,   311,   313,   316,   320,   324,   325,   330,
180    336,   341,   345,   349,   353,   357,   359,   362,   366,   370,
181    374,   378,   384,   386,   389,   390,   395,   399,   403,   407,
182    409,   412,   416,   420,   424,   430,   432,   435,   437,   441,
183    445,   449,   453,   457,   461,   464,   467,   470,   474,   479,
184    484,   486,   491,   493,   496,   499,   501,   503,   506,   509,
185    510,   512,   514,   519,   522,   525,   528,   530,   531,   533,
186    535
187 };
188
189 static const short yyrhs[] = {    83,
190     63,    83,     0,    64,     0,    63,    64,     0,     1,     0,
191     63,     1,     0,     0,     0,    15,    65,    75,     0,     0,
192     16,    66,    75,     0,    15,    77,     0,    16,    77,     0,
193     72,    75,     0,    75,     0,    72,    77,     0,    69,    71,
194      0,     4,     0,     3,     0,    68,     0,    38,     0,    39,
195      0,     0,    30,    70,    67,    55,    86,   103,    83,     0,
196    101,    76,   102,   104,     0,   101,   102,   104,    83,     0,
197     93,     0,    93,    42,    93,     0,     0,    49,    74,     5,
198     49,     0,   101,    76,   102,   104,    83,     0,   101,   102,
199    104,    83,     0,    78,     0,    76,    78,     0,     1,     0,
200     76,     1,     0,    82,     0,   105,    83,     0,   105,    83,
201      0,   101,   102,     0,   101,    76,   102,     0,    81,     0,
202     21,    55,    93,   103,    83,    78,     0,    22,    83,    78,
203     21,    55,    93,   103,    83,     0,    23,    55,     4,    33,
204      4,   103,    83,    78,     0,    23,    55,    88,   105,    93,
205    105,    88,   103,    83,    78,     0,    23,    55,    88,   105,
206    105,    88,   103,    83,    78,     0,    24,    77,     0,    25,
207     77,     0,    80,    55,    92,   103,    85,    77,     0,    80,
208     89,    85,    77,     0,    28,    88,    77,     0,    32,    77,
209      0,    29,    88,    77,     0,     0,    19,    79,    88,    77,
210      0,    20,     4,    57,    92,    58,    77,     0,    20,     4,
211     77,     0,    93,    77,     0,    26,     0,    27,     0,    17,
212     55,    93,   103,    83,    78,     0,    17,    55,    93,   103,
213     83,    78,    18,    83,    78,     0,    13,     0,    82,    13,
214      0,     0,    82,     0,     0,    43,    97,     0,     0,    44,
215     93,     0,    10,    93,     0,    45,    93,     0,     0,    87,
216      0,     4,     0,    87,   106,     4,     0,     1,     0,    87,
217      1,     0,    87,   106,     1,     0,     0,    93,     0,     0,
218     90,     0,    95,     0,    90,   106,    95,     0,     1,     0,
219     90,     1,     0,    90,     1,    95,     0,    90,   106,     1,
220      0,     0,    92,     0,    93,     0,    92,   106,    93,     0,
221      1,     0,    92,     1,     0,    92,     1,    93,     0,    92,
222    106,     1,     0,     0,   100,    11,    94,    93,     0,    55,
223     92,   103,    33,     4,     0,    93,    45,    31,    99,     0,
224     31,    99,    84,     0,    93,    34,    93,     0,    93,    35,
225     93,     0,    93,    12,    93,     0,    73,     0,    51,    73,
226      0,    93,    33,     4,     0,    93,     9,    93,     0,    93,
227     43,    93,     0,    93,    44,    93,     0,    93,    40,    93,
228     41,    93,     0,    97,     0,    93,    97,     0,     0,   100,
229     11,    96,    95,     0,    95,    34,    95,     0,    95,    35,
230     95,     0,    31,    99,    84,     0,    73,     0,    51,    73,
231      0,    95,    12,    95,     0,    95,    33,     4,     0,    95,
232      9,    95,     0,    95,    40,    95,    41,    95,     0,    97,
233      0,    95,    97,     0,    98,     0,    97,    53,    97,     0,
234     97,    48,    97,     0,    97,    49,    97,     0,    97,    50,
235     97,     0,    97,    46,    97,     0,    97,    47,    97,     0,
236    100,    36,     0,   100,    37,     0,    51,    97,     0,    55,
237     93,   103,     0,    38,    55,    91,   103,     0,    39,    55,
238     91,   103,     0,    39,     0,     3,    55,    91,   103,     0,
239    100,     0,    36,   100,     0,    37,   100,     0,     7,     0,
240      8,     0,    47,    97,     0,    46,    97,     0,     0,   100,
241      0,     4,     0,     4,    57,    92,    58,     0,    54,    98,
242      0,    59,    83,     0,    60,    83,     0,    56,     0,     0,
243    105,     0,    61,     0,    42,    83,     0
244 };
245
246 #endif
247
248 #if YYDEBUG != 0
249 static const short yyrline[] = { 0,
250    150,   158,   166,   182,   183,   184,   188,   190,   204,   206,
251    220,   226,   232,   234,   236,   249,   258,   260,   262,   272,
252    273,   277,   281,   296,   301,   310,   312,   321,   323,   341,
253    343,   348,   354,   362,   364,   369,   370,   374,   376,   378,
254    380,   382,   384,   386,   413,   417,   422,   425,   428,   430,
255    450,   489,   508,   510,   515,   517,   519,   533,   538,   540,
256    545,   550,   557,   559,   563,   564,   568,   570,   575,   577,
257    579,   581,   586,   588,   593,   595,   597,   599,   601,   607,
258    609,   614,   616,   621,   623,   629,   631,   633,   635,   640,
259    642,   647,   649,   655,   657,   659,   661,   666,   669,   674,
260    676,   681,   687,   689,   691,   697,   707,   715,   717,   723,
261    725,   727,   729,   731,   736,   739,   740,   742,   744,   750,
262    752,   754,   756,   758,   760,   762,   764,   769,   771,   773,
263    775,   777,   779,   781,   783,   785,   790,   792,   794,   797,
264    799,   807,   814,   815,   817,   819,   821,   824,   832,   843,
265    845,   850,   852,   862,   867,   871,   875,   879,   880,   884,
266    887
267 };
268 #endif
269
270
271 #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
272
273 static const char * const yytname[] = {   "$","error","$undefined.","FUNC_CALL",
274 "NAME","REGEXP","ERROR","YNUMBER","YSTRING","RELOP","APPEND_OP","ASSIGNOP","MATCHOP",
275 "NEWLINE","CONCAT_OP","LEX_BEGIN","LEX_END","LEX_IF","LEX_ELSE","LEX_RETURN",
276 "LEX_DELETE","LEX_WHILE","LEX_DO","LEX_FOR","LEX_BREAK","LEX_CONTINUE","LEX_PRINT",
277 "LEX_PRINTF","LEX_NEXT","LEX_EXIT","LEX_FUNCTION","LEX_GETLINE","LEX_NEXTFILE",
278 "LEX_IN","LEX_AND","LEX_OR","INCREMENT","DECREMENT","LEX_BUILTIN","LEX_LENGTH",
279 "'?'","':'","','","'<'","'>'","'|'","'+'","'-'","'*'","'/'","'%'","'!'","UNARY",
280 "'^'","'$'","'('","')'","'['","']'","'{'","'}'","';'","start","program","rule",
281 "@1","@2","func_name","lex_builtin","function_prologue","@3","function_body",
282 "pattern","regexp","@4","action","statements","statement_term","statement","@5",
283 "print","if_statement","nls","opt_nls","input_redir","output_redir","opt_param_list",
284 "param_list","opt_exp","opt_rexpression_list","rexpression_list","opt_expression_list",
285 "expression_list","exp","@6","rexp","@7","simp_exp","non_post_simp_exp","opt_variable",
286 "variable","l_brace","r_brace","r_paren","opt_semi","semi","comma", NULL
287 };
288 #endif
289
290 static const short yyr1[] = {     0,
291     62,    63,    63,    63,    63,    63,    65,    64,    66,    64,
292     64,    64,    64,    64,    64,    64,    67,    67,    67,    68,
293     68,    70,    69,    71,    71,    72,    72,    74,    73,    75,
294     75,    76,    76,    76,    76,    77,    77,    78,    78,    78,
295     78,    78,    78,    78,    78,    78,    78,    78,    78,    78,
296     78,    78,    78,    79,    78,    78,    78,    78,    80,    80,
297     81,    81,    82,    82,    83,    83,    84,    84,    85,    85,
298     85,    85,    86,    86,    87,    87,    87,    87,    87,    88,
299     88,    89,    89,    90,    90,    90,    90,    90,    90,    91,
300     91,    92,    92,    92,    92,    92,    92,    94,    93,    93,
301     93,    93,    93,    93,    93,    93,    93,    93,    93,    93,
302     93,    93,    93,    93,    96,    95,    95,    95,    95,    95,
303     95,    95,    95,    95,    95,    95,    95,    97,    97,    97,
304     97,    97,    97,    97,    97,    97,    98,    98,    98,    98,
305     98,    98,    98,    98,    98,    98,    98,    98,    98,    99,
306     99,   100,   100,   100,   101,   102,   103,   104,   104,   105,
307    106
308 };
309
310 static const short yyr2[] = {     0,
311      3,     1,     2,     1,     2,     0,     0,     3,     0,     3,
312      2,     2,     2,     1,     2,     2,     1,     1,     1,     1,
313      1,     0,     7,     4,     4,     1,     3,     0,     4,     5,
314      4,     1,     2,     1,     2,     1,     2,     2,     2,     3,
315      1,     6,     8,     8,    10,     9,     2,     2,     6,     4,
316      3,     2,     3,     0,     4,     6,     3,     2,     1,     1,
317      6,     9,     1,     2,     0,     1,     0,     2,     0,     2,
318      2,     2,     0,     1,     1,     3,     1,     2,     3,     0,
319      1,     0,     1,     1,     3,     1,     2,     3,     3,     0,
320      1,     1,     3,     1,     2,     3,     3,     0,     4,     5,
321      4,     3,     3,     3,     3,     1,     2,     3,     3,     3,
322      3,     5,     1,     2,     0,     4,     3,     3,     3,     1,
323      2,     3,     3,     3,     5,     1,     2,     1,     3,     3,
324      3,     3,     3,     3,     2,     2,     2,     3,     4,     4,
325      1,     4,     1,     2,     2,     1,     1,     2,     2,     0,
326      1,     1,     4,     2,     2,     2,     1,     0,     1,     1,
327      2
328 };
329
330 static const short yydefact[] = {    65,
331     63,    66,     0,    64,     4,     0,   152,   146,   147,     7,
332      9,    22,   150,     0,     0,     0,   141,     0,     0,    28,
333      0,     0,     0,    65,     0,     2,     0,     0,   106,    14,
334     26,   113,   128,   143,     0,     0,     0,   160,     0,    11,
335     36,    65,     0,    12,     0,    67,   151,   144,   145,     0,
336      0,     0,     0,   149,   143,   148,     0,   107,   137,   154,
337    143,    94,     0,    92,   155,     5,     3,     1,    16,     0,
338     13,    15,     0,     0,     0,     0,     0,     0,     0,     0,
339      0,     0,   114,     0,     0,     0,     0,     0,     0,    98,
340    135,   136,    34,     0,    54,     0,     0,    65,     0,     0,
341      0,    59,    60,    80,    80,     0,    65,     0,    32,     0,
342     41,     0,     0,   158,    65,     0,     0,    92,     0,     8,
343     37,    10,    18,    17,    20,    21,     0,    19,     0,   102,
344      0,     0,     0,     0,    95,    65,   157,     0,     0,   138,
345      0,   158,   109,   105,   108,   103,   104,     0,    27,   110,
346    111,   150,   133,   134,   130,   131,   132,   129,     0,     0,
347     80,     0,     0,     0,    80,    47,    48,     0,    81,     0,
348     52,   156,    35,    33,   158,    86,   150,     0,     0,   120,
349     69,     0,    84,   126,   143,    58,     0,    39,    65,   159,
350     38,   142,   153,     0,    68,   139,   140,    29,    96,   161,
351      0,    97,    93,   158,    65,     0,   101,    99,     0,     0,
352      0,    57,     0,     0,   152,     0,    51,    53,    65,    67,
353    121,     0,     0,     0,     0,     0,    87,     0,     0,     0,
354      0,     0,     0,     0,   127,   115,    40,    31,    77,    75,
355      0,     0,   100,    24,    25,   112,    65,    55,     0,    65,
356      0,     0,     0,    30,   119,    69,    71,    70,    72,    50,
357     88,    89,    85,   124,   122,   123,   117,   118,     0,     0,
358     65,    78,     0,     0,     0,     0,     0,     0,     0,    80,
359      0,     0,   116,    23,    79,    76,    61,    56,    42,     0,
360     65,    80,     0,    49,   125,    65,    65,     0,     0,    65,
361      0,    43,    44,    65,     0,    62,     0,    46,    45,     0,
362      0,     0
363 };
364
365 static const short yydefgoto[] = {   310,
366     25,    26,    39,    43,   127,   128,    27,    45,    69,    28,
367     29,    57,    30,   108,    40,   109,   161,   110,   111,     2,
368      3,   130,   226,   241,   242,   168,   181,   182,   116,   117,
369    112,   159,   183,   270,    32,    33,    46,    34,   113,   114,
370    140,   189,    42,   139
371 };
372
373 static const short yypact[] = {    -6,
374 -32768,     0,   875,-32768,-32768,   -40,   -38,-32768,-32768,    -7,
375     -7,-32768,    10,    10,    10,   -31,   -26,  1735,  1735,-32768,
376   1715,  1735,  1131,    -6,   932,-32768,   -24,    72,-32768,-32768,
377   1304,   205,-32768,     5,   709,  1110,  1131,-32768,   -24,-32768,
378      0,    -6,   -24,-32768,    85,     3,-32768,-32768,-32768,  1110,
379   1110,  1735,  1620,     8,   106,     8,    81,-32768,     8,-32768,
380 -32768,-32768,    37,  1250,-32768,-32768,-32768,-32768,-32768,   709,
381 -32768,-32768,  1620,  1620,    90,  1620,  1620,  1620,  1620,  1620,
382   1620,    65,   205,  1735,  1735,  1735,  1735,  1735,  1735,-32768,
383 -32768,-32768,-32768,    50,-32768,   111,    70,    -6,    93,    -7,
384     -7,-32768,-32768,  1620,  1620,    -7,    -6,   758,-32768,   819,
385 -32768,  1040,   709,   100,    -6,    99,    55,  1402,     9,-32768,
386 -32768,-32768,-32768,-32768,-32768,-32768,   109,-32768,  1735,-32768,
387     99,    99,  1250,   119,  1620,    -6,-32768,   133,  1180,-32768,
388    758,   100,  1327,   794,-32768,  1515,  1451,  1353,  1402,  1327,
389   1327,    10,   125,   125,     8,     8,     8,     8,  1620,  1620,
390   1620,    42,  1620,   981,  1657,-32768,-32768,    -7,  1402,    -7,
391 -32768,-32768,-32768,-32768,   100,-32768,    10,  1715,  1131,-32768,
392     96,    39,  1538,   205,   117,-32768,   758,-32768,    -6,-32768,
393 -32768,-32768,-32768,     7,   205,-32768,-32768,-32768,  1402,-32768,
394    166,-32768,  1402,   100,    -6,  1620,-32768,  1402,  1250,    -7,
395   1131,-32768,  1250,   151,   -12,   100,-32768,-32768,    -6,     3,
396 -32768,    37,  1620,  1620,  1620,    -7,  1678,  1201,  1678,  1678,
397    181,  1678,  1678,  1678,   205,-32768,-32768,-32768,-32768,-32768,
398     99,    56,-32768,-32768,-32768,  1402,    -6,-32768,    11,    -6,
399    131,   183,  1061,-32768,-32768,    96,  1402,  1402,  1402,-32768,
400   1538,-32768,  1538,   635,    83,-32768,  1599,  1579,  1474,  1678,
401     -6,-32768,   103,   981,    -7,   981,  1620,    99,   623,  1620,
402     -7,  1678,  1538,-32768,-32768,-32768,   170,-32768,-32768,  1250,
403     -6,  1620,    99,-32768,  1538,    -6,    -6,   981,    99,    -6,
404    981,-32768,-32768,    -6,   981,-32768,   981,-32768,-32768,   190,
405    191,-32768
406 };
407
408 static const short yypgoto[] = {-32768,
409 -32768,   167,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
410    211,-32768,   107,   -53,   315,  -105,-32768,-32768,-32768,   199,
411     97,   -22,   -62,-32768,-32768,  -103,-32768,-32768,    94,   -14,
412     -3,-32768,  -202,-32768,   318,   177,  -134,    95,   124,   -69,
413    407,  -138,   420,  -177
414 };
415
416
417 #define YYLAST          1790
418
419
420 static const short yytable[] = {    31,
421    142,   170,   174,   205,   228,     1,     1,   239,    63,   135,
422    240,   135,     4,     7,    36,    90,   141,   207,    37,    64,
423    252,    31,   119,    50,   261,   263,   264,   265,    51,   267,
424    268,   269,   118,   118,    24,   174,   219,   135,   175,   227,
425     91,    92,   220,   188,    37,   129,   118,   118,   -83,   133,
426    136,   -83,   136,    38,     1,   135,   272,   210,   214,   187,
427     89,   216,   -73,    22,   273,   244,   193,   283,   275,   143,
428    144,   204,   146,   147,   148,   149,   150,   151,   136,   295,
429    136,   174,   -83,   -83,     1,   134,     7,   123,   124,     8,
430      9,   229,   137,   145,-32768,   152,   136,   136,   211,   -83,
431    169,   169,    38,   285,   160,   223,   286,    47,    48,    49,
432    -91,   -74,    55,    55,   162,    55,    61,   237,    14,    15,
433     65,    68,   125,   126,   163,    55,    35,   236,    18,    19,
434     24,   199,    38,    52,    71,   203,    22,    53,   121,   224,
435    225,    91,    92,   131,   132,   120,    55,   165,    35,   122,
436     70,    35,    91,    92,   137,   208,   209,   169,    55,   213,
437     38,   169,    35,   194,   222,   201,    35,   198,   287,   243,
438    289,   251,    86,    87,    88,    64,   293,    89,    55,    55,
439     55,    55,    55,    55,   266,   277,   278,   296,   299,   311,
440    312,    67,   303,   281,   164,   306,   249,   255,    60,   308,
441      0,   309,   246,   172,   185,     0,    55,   118,    41,    41,
442      0,   191,    55,     0,     0,     0,     0,     0,     0,   257,
443    258,   259,     0,    55,     0,     0,    41,    55,     0,     0,
444      0,    58,   200,     0,     0,     0,     0,    55,    55,     0,
445     55,    55,    55,    55,    55,    55,    47,     0,     0,   279,
446     84,    85,    86,    87,    88,     0,     0,    89,     0,     0,
447      0,     0,     0,    55,     0,     0,     0,     0,     0,     0,
448      0,    47,    55,   290,     0,     0,   169,    55,     0,     0,
449      0,     0,     0,     0,     0,   238,     0,     0,   169,     0,
450      0,     0,     0,    55,     0,     0,     0,    55,    41,    41,
451      0,   245,    55,    55,    41,     0,     0,    55,     0,     0,
452     41,     0,     0,     0,     0,   254,     0,     0,     0,     0,
453    180,   185,   185,   185,   185,    44,   185,   185,   185,     0,
454      0,     0,     0,     0,     0,    54,    56,     0,    59,     0,
455     55,     0,    72,   274,     0,     0,   276,     0,    83,     0,
456      0,    55,    55,    55,     0,    55,     0,    55,    55,    55,
457     41,    55,    55,    55,   185,     0,    41,   284,    41,    59,
458      0,     0,     0,    55,     0,     0,   185,    55,     0,     0,
459      0,    83,     0,     0,    55,     0,     0,   298,   221,    55,
460      0,     0,   301,   302,     0,     0,   305,     0,     0,     0,
461    307,   153,   154,   155,   156,   157,   158,     0,    41,     0,
462      0,     0,     0,     0,   166,   167,     0,     0,     0,     0,
463    171,     0,     0,     0,    41,     0,   186,   184,     0,    83,
464      0,     0,     0,     0,     0,    83,     0,   180,   180,   180,
465    180,     0,   180,   180,   180,     0,   195,     0,     0,     0,
466     83,     0,     0,     0,   115,     0,     0,     0,     0,     0,
467     83,    83,     0,    83,    83,    83,    83,    83,    83,   138,
468      0,     0,     0,    41,     0,     0,   212,     0,     0,    41,
469    180,     0,   217,     0,   218,     0,    83,     0,     0,   115,
470      0,     0,   180,     0,     0,    59,     0,     0,     0,     0,
471    235,     0,     0,     0,     0,     0,     0,     0,     0,     0,
472      0,     0,     0,     0,     0,     0,    83,     0,     0,     0,
473     83,     0,   192,     0,   248,    83,    83,   115,     0,     0,
474     83,     0,   115,   190,     0,     0,     0,   196,   197,     0,
475    260,     0,     0,     0,   184,   184,   184,   184,     0,   184,
476    184,   184,     0,     0,     0,     0,     0,     0,     0,     0,
477    115,   190,     0,    83,     0,     0,     0,     0,     0,     0,
478      0,     0,     0,     0,    83,    83,    83,     0,   235,     0,
479    235,   235,   235,   115,   235,   235,   235,   184,     0,   288,
480      0,     0,     0,     0,   190,   294,    83,     0,     0,   184,
481    235,     0,     0,     0,     0,     0,   115,    83,     0,     0,
482      0,     0,   235,     0,     0,   247,     0,     0,     0,   250,
483      0,     0,     0,   190,     0,     6,     7,     0,   256,     8,
484      9,    73,     0,     0,    74,   253,     0,     0,     7,     0,
485      0,     8,     9,-32768,     0,     0,     0,   271,     0,     0,
486      0,     0,     0,     0,     0,    75,    76,    77,    14,    15,
487     16,    17,    78,     0,     0,    80,    81,    82,    18,    19,
488     14,    15,   280,    52,     0,     0,    22,    53,     0,     0,
489     18,    19,     0,    38,   291,    52,     0,     0,    22,    53,
490      0,     0,     0,   115,     0,   115,   297,     0,   292,   300,
491      0,     0,     0,     0,     0,   304,     0,     0,     0,    93,
492      0,     6,     7,     0,     0,     8,     9,   115,     0,     0,
493    115,     0,     0,     0,   115,    94,   115,    95,    96,    97,
494     98,    99,   100,   101,   102,   103,   104,   105,     0,    13,
495    106,     0,     0,     0,    14,    15,    16,    17,     0,     0,
496      0,     0,     0,     0,    18,    19,     0,    20,   173,    21,
497      6,     7,    22,    23,     8,     9,     0,    24,   107,    38,
498      0,     0,     0,     0,    94,     0,    95,    96,    97,    98,
499     99,   100,   101,   102,   103,   104,   105,     0,    13,   106,
500      0,     0,     0,    14,    15,    16,    17,     7,     0,     0,
501      8,     9,    73,    18,    19,-32768,    20,     0,    21,     0,
502      0,    22,    23,     0,     0,     0,    24,   107,    38,   176,
503      0,     6,     7,     0,     0,     8,     9,     0,   -82,    14,
504     15,   -82,     0,     0,     0,     0,    80,    81,    82,    18,
505     19,     0,     0,     0,    52,     0,     0,    22,    53,   177,
506      0,     0,     0,     0,    14,    15,    16,    17,     0,     0,
507      0,     0,   -82,   -82,    18,    19,     0,    20,     0,   178,
508      0,     0,    22,   179,    -6,     5,     0,     6,     7,   -82,
509      0,     8,     9,     0,     0,     0,     0,    -6,     0,    10,
510     11,     0,     0,     0,     0,     0,     0,     0,     0,     0,
511      0,     0,     0,     0,    12,    13,     0,     0,     0,     0,
512     14,    15,    16,    17,     0,     0,     0,     0,     0,     0,
513     18,    19,     0,    20,     0,    21,     0,     0,    22,    23,
514      0,   -65,    66,    24,     6,     7,     0,     0,     8,     9,
515      0,     0,     0,     0,     1,     0,    10,    11,     0,     0,
516      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
517      0,    12,    13,     0,     0,     0,     0,    14,    15,    16,
518     17,     0,     0,     0,     0,     0,     0,    18,    19,     0,
519     20,     0,    21,     6,     7,    22,    23,     8,     9,     0,
520     24,     0,     0,     0,     0,     0,     0,    94,     0,    95,
521     96,    97,    98,    99,   100,   101,   102,   103,   104,   105,
522      0,    13,   106,     0,     0,     0,    14,    15,    16,    17,
523      0,     0,     0,     0,     0,     0,    18,    19,     0,    20,
524      0,    21,     0,     0,    22,    23,     0,     0,     0,    24,
525      0,    38,     6,     7,     0,     0,     8,     9,    73,     0,
526      0,    74,     1,     0,     0,     0,     0,     0,     0,     0,
527      0,     0,     0,     6,     7,     0,     0,     8,     9,     0,
528      0,     0,    75,    76,    77,    14,    15,    16,    17,    78,
529      0,     0,    80,    81,    82,    18,    19,     0,     0,     0,
530     52,    13,     0,    22,    53,     0,    14,    15,    16,    17,
531     38,     0,     0,     0,     0,     0,    18,    19,     0,    20,
532     62,    21,     6,     7,    22,    23,     8,     9,     0,     0,
533      0,    38,     0,     0,     0,     0,     0,     0,     0,     0,
534      0,    62,     0,     6,     7,     0,     0,     8,     9,     0,
535     13,     0,     0,     0,     0,    14,    15,    16,    17,     0,
536      0,     0,     0,     0,     0,    18,    19,     0,    20,     0,
537     21,    13,     0,    22,    23,   -90,    14,    15,    16,    17,
538      0,     0,     0,     0,     0,     0,    18,    19,     0,    20,
539    202,    21,     6,     7,    22,    23,     8,     9,     0,     0,
540      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
541      0,   262,     0,     6,     7,     0,     0,     8,     9,     0,
542     13,     0,     0,     0,     0,    14,    15,    16,    17,     0,
543      0,     0,     0,     0,     0,    18,    19,     0,    20,     0,
544     21,   177,     0,    22,    23,     0,    14,    15,    16,    17,
545      0,     0,     0,     0,     0,     0,    18,    19,     0,    20,
546      0,   178,     6,     7,    22,    53,     8,     9,    73,     0,
547      0,    74,     0,     0,     0,     0,     0,     0,     0,     0,
548      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
549      0,     0,    75,    76,    77,    14,    15,    16,    17,    78,
550      0,     0,    80,    81,    82,    18,    19,     0,     0,     0,
551     52,     0,     0,    22,    53,   137,     6,     7,     0,     0,
552      8,     9,    73,     0,     0,    74,     0,     0,     0,     0,
553      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
554      7,     0,     0,     8,     9,-32768,    75,    76,    77,    14,
555     15,    16,    17,    78,     0,    79,    80,    81,    82,    18,
556     19,     0,     0,     0,    52,     6,     7,    22,    53,     8,
557      9,    73,    14,    15,    74,     0,     0,     0,     0,-32768,
558 -32768,-32768,    18,    19,     0,     0,     0,    52,     0,     0,
559     22,    53,     0,     0,     0,    75,    76,    77,    14,    15,
560     16,    17,    78,   206,     0,    80,    81,    82,    18,    19,
561      0,     0,     0,    52,     6,     7,    22,    53,     8,     9,
562     73,     0,     0,    74,     0,     0,     0,     0,     0,     0,
563      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
564      0,     0,     0,     0,    75,    76,    77,    14,    15,    16,
565     17,    78,     0,     0,    80,    81,    82,    18,    19,     0,
566      0,     0,    52,     6,     7,    22,    53,     8,     9,    73,
567      0,     0,    74,     0,     0,     0,     0,     0,     0,     0,
568      0,     0,     0,     0,     0,     0,     6,     7,     0,     0,
569      8,     9,   229,    75,    76,   230,    14,    15,    16,    17,
570      0,     0,     0,    80,    81,    82,    18,    19,     0,     0,
571      0,    52,     0,     0,    22,    53,   231,   232,   233,    14,
572     15,    16,    17,   234,   282,     0,     0,     6,     7,    18,
573     19,     8,     9,    73,    52,     0,    74,    22,    53,     0,
574      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
575      6,     7,     0,     0,     8,     9,   229,    75,     0,   230,
576     14,    15,    16,    17,     0,     0,     0,    80,    81,    82,
577     18,    19,     0,     0,     0,    52,     0,     0,    22,    53,
578    231,   232,   233,    14,    15,    16,    17,   234,     0,     0,
579      0,     6,     7,    18,    19,     8,     9,   229,    52,     0,
580    230,    22,    53,     0,     0,     0,     0,     0,     0,     0,
581      0,     6,     7,     0,     0,     8,     9,   229,     0,     0,
582    230,   231,   232,     0,    14,    15,    16,    17,     0,     0,
583      0,     0,     6,     7,    18,    19,     8,     9,     0,    52,
584      0,   231,    22,    53,    14,    15,    16,    17,     0,     0,
585      0,     0,     0,     0,    18,    19,     0,     0,     0,    52,
586     13,     0,    22,    53,     0,    14,    15,    16,    17,     6,
587    215,     0,     0,     8,     9,    18,    19,     0,    20,     0,
588     21,     0,     0,    22,    23,     0,     0,     0,     0,     0,
589      6,     7,     0,     0,     8,     9,     0,    13,     0,     0,
590      0,     0,    14,    15,    16,    17,     0,     0,     0,     0,
591      0,     0,    18,    19,     0,    20,     0,    21,   177,     0,
592     22,    23,     0,    14,    15,    16,    17,     6,     7,     0,
593      0,     8,     9,    18,    19,     0,    20,     0,   178,     0,
594      0,    22,    53,     0,     0,     0,     0,     6,     7,     0,
595      0,     8,     9,     0,     0,     0,     0,     0,     0,     0,
596     14,    15,    16,    17,     0,     0,     0,     0,     0,     0,
597     18,    19,     0,    20,     0,    52,     0,     0,    22,    53,
598     14,    15,    16,    17,     0,     0,     0,     0,     0,     0,
599     18,    19,     0,     0,     0,    52,     0,     0,    22,    53
600 };
601
602 static const short yycheck[] = {     3,
603     70,   105,   108,   142,   182,    13,    13,     1,    23,     1,
604      4,     1,    13,     4,    55,    11,    70,   152,    57,    23,
605     33,    25,    37,    55,   227,   228,   229,   230,    55,   232,
606    233,   234,    36,    37,    59,   141,   175,     1,   108,     1,
607     36,    37,   177,   113,    57,    43,    50,    51,    10,    53,
608     42,    13,    42,    61,    13,     1,     1,   161,   164,   113,
609     53,   165,    56,    54,   242,   204,    58,   270,    58,    73,
610     74,   141,    76,    77,    78,    79,    80,    81,    42,   282,
611     42,   187,    44,    45,    13,     5,     4,     3,     4,     7,
612      8,     9,    56,     4,    12,    31,    42,    42,    57,    61,
613    104,   105,    61,     1,    55,    10,     4,    13,    14,    15,
614     56,    56,    18,    19,     4,    21,    22,   187,    36,    37,
615     24,    25,    38,    39,    55,    31,     3,    11,    46,    47,
616     59,   135,    61,    51,    28,   139,    54,    55,    42,    44,
617     45,    36,    37,    50,    51,    39,    52,    55,    25,    43,
618     27,    28,    36,    37,    56,   159,   160,   161,    64,   163,
619     61,   165,    39,    55,   179,    33,    43,    49,   274,     4,
620    276,    21,    48,    49,    50,   179,   280,    53,    84,    85,
621     86,    87,    88,    89,     4,    55,     4,    18,   292,     0,
622      0,    25,   298,   256,    98,   301,   211,   220,    22,   305,
623     -1,   307,   206,   107,   110,    -1,   112,   211,    10,    11,
624     -1,   115,   118,    -1,    -1,    -1,    -1,    -1,    -1,   223,
625    224,   225,    -1,   129,    -1,    -1,    28,   133,    -1,    -1,
626     -1,    21,   136,    -1,    -1,    -1,    -1,   143,   144,    -1,
627    146,   147,   148,   149,   150,   151,   152,    -1,    -1,   253,
628     46,    47,    48,    49,    50,    -1,    -1,    53,    -1,    -1,
629     -1,    -1,    -1,   169,    -1,    -1,    -1,    -1,    -1,    -1,
630     -1,   177,   178,   277,    -1,    -1,   280,   183,    -1,    -1,
631     -1,    -1,    -1,    -1,    -1,   189,    -1,    -1,   292,    -1,
632     -1,    -1,    -1,   199,    -1,    -1,    -1,   203,   100,   101,
633     -1,   205,   208,   209,   106,    -1,    -1,   213,    -1,    -1,
634    112,    -1,    -1,    -1,    -1,   219,    -1,    -1,    -1,    -1,
635    110,   227,   228,   229,   230,    11,   232,   233,   234,    -1,
636     -1,    -1,    -1,    -1,    -1,    18,    19,    -1,    21,    -1,
637    246,    -1,    28,   247,    -1,    -1,   250,    -1,    31,    -1,
638     -1,   257,   258,   259,    -1,   261,    -1,   263,   264,   265,
639    162,   267,   268,   269,   270,    -1,   168,   271,   170,    52,
640     -1,    -1,    -1,   279,    -1,    -1,   282,   283,    -1,    -1,
641     -1,    64,    -1,    -1,   290,    -1,    -1,   291,   178,   295,
642     -1,    -1,   296,   297,    -1,    -1,   300,    -1,    -1,    -1,
643    304,    84,    85,    86,    87,    88,    89,    -1,   210,    -1,
644     -1,    -1,    -1,    -1,   100,   101,    -1,    -1,    -1,    -1,
645    106,    -1,    -1,    -1,   226,    -1,   112,   110,    -1,   112,
646     -1,    -1,    -1,    -1,    -1,   118,    -1,   227,   228,   229,
647    230,    -1,   232,   233,   234,    -1,   129,    -1,    -1,    -1,
648    133,    -1,    -1,    -1,    35,    -1,    -1,    -1,    -1,    -1,
649    143,   144,    -1,   146,   147,   148,   149,   150,   151,    63,
650     -1,    -1,    -1,   275,    -1,    -1,   162,    -1,    -1,   281,
651    270,    -1,   168,    -1,   170,    -1,   169,    -1,    -1,    70,
652     -1,    -1,   282,    -1,    -1,   178,    -1,    -1,    -1,    -1,
653    183,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
654     -1,    -1,    -1,    -1,    -1,    -1,   199,    -1,    -1,    -1,
655    203,    -1,   116,    -1,   210,   208,   209,   108,    -1,    -1,
656    213,    -1,   113,   114,    -1,    -1,    -1,   131,   132,    -1,
657    226,    -1,    -1,    -1,   227,   228,   229,   230,    -1,   232,
658    233,   234,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
659    141,   142,    -1,   246,    -1,    -1,    -1,    -1,    -1,    -1,
660     -1,    -1,    -1,    -1,   257,   258,   259,    -1,   261,    -1,
661    263,   264,   265,   164,   267,   268,   269,   270,    -1,   275,
662     -1,    -1,    -1,    -1,   175,   281,   279,    -1,    -1,   282,
663    283,    -1,    -1,    -1,    -1,    -1,   187,   290,    -1,    -1,
664     -1,    -1,   295,    -1,    -1,   209,    -1,    -1,    -1,   213,
665     -1,    -1,    -1,   204,    -1,     3,     4,    -1,   222,     7,
666      8,     9,    -1,    -1,    12,   216,    -1,    -1,     4,    -1,
667     -1,     7,     8,     9,    -1,    -1,    -1,   241,    -1,    -1,
668     -1,    -1,    -1,    -1,    -1,    33,    34,    35,    36,    37,
669     38,    39,    40,    -1,    -1,    43,    44,    45,    46,    47,
670     36,    37,   253,    51,    -1,    -1,    54,    55,    -1,    -1,
671     46,    47,    -1,    61,   278,    51,    -1,    -1,    54,    55,
672     -1,    -1,    -1,   274,    -1,   276,   290,    -1,   279,   293,
673     -1,    -1,    -1,    -1,    -1,   299,    -1,    -1,    -1,     1,
674     -1,     3,     4,    -1,    -1,     7,     8,   298,    -1,    -1,
675    301,    -1,    -1,    -1,   305,    17,   307,    19,    20,    21,
676     22,    23,    24,    25,    26,    27,    28,    29,    -1,    31,
677     32,    -1,    -1,    -1,    36,    37,    38,    39,    -1,    -1,
678     -1,    -1,    -1,    -1,    46,    47,    -1,    49,     1,    51,
679      3,     4,    54,    55,     7,     8,    -1,    59,    60,    61,
680     -1,    -1,    -1,    -1,    17,    -1,    19,    20,    21,    22,
681     23,    24,    25,    26,    27,    28,    29,    -1,    31,    32,
682     -1,    -1,    -1,    36,    37,    38,    39,     4,    -1,    -1,
683      7,     8,     9,    46,    47,    12,    49,    -1,    51,    -1,
684     -1,    54,    55,    -1,    -1,    -1,    59,    60,    61,     1,
685     -1,     3,     4,    -1,    -1,     7,     8,    -1,    10,    36,
686     37,    13,    -1,    -1,    -1,    -1,    43,    44,    45,    46,
687     47,    -1,    -1,    -1,    51,    -1,    -1,    54,    55,    31,
688     -1,    -1,    -1,    -1,    36,    37,    38,    39,    -1,    -1,
689     -1,    -1,    44,    45,    46,    47,    -1,    49,    -1,    51,
690     -1,    -1,    54,    55,     0,     1,    -1,     3,     4,    61,
691     -1,     7,     8,    -1,    -1,    -1,    -1,    13,    -1,    15,
692     16,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
693     -1,    -1,    -1,    -1,    30,    31,    -1,    -1,    -1,    -1,
694     36,    37,    38,    39,    -1,    -1,    -1,    -1,    -1,    -1,
695     46,    47,    -1,    49,    -1,    51,    -1,    -1,    54,    55,
696     -1,     0,     1,    59,     3,     4,    -1,    -1,     7,     8,
697     -1,    -1,    -1,    -1,    13,    -1,    15,    16,    -1,    -1,
698     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
699     -1,    30,    31,    -1,    -1,    -1,    -1,    36,    37,    38,
700     39,    -1,    -1,    -1,    -1,    -1,    -1,    46,    47,    -1,
701     49,    -1,    51,     3,     4,    54,    55,     7,     8,    -1,
702     59,    -1,    -1,    -1,    -1,    -1,    -1,    17,    -1,    19,
703     20,    21,    22,    23,    24,    25,    26,    27,    28,    29,
704     -1,    31,    32,    -1,    -1,    -1,    36,    37,    38,    39,
705     -1,    -1,    -1,    -1,    -1,    -1,    46,    47,    -1,    49,
706     -1,    51,    -1,    -1,    54,    55,    -1,    -1,    -1,    59,
707     -1,    61,     3,     4,    -1,    -1,     7,     8,     9,    -1,
708     -1,    12,    13,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
709     -1,    -1,    -1,     3,     4,    -1,    -1,     7,     8,    -1,
710     -1,    -1,    33,    34,    35,    36,    37,    38,    39,    40,
711     -1,    -1,    43,    44,    45,    46,    47,    -1,    -1,    -1,
712     51,    31,    -1,    54,    55,    -1,    36,    37,    38,    39,
713     61,    -1,    -1,    -1,    -1,    -1,    46,    47,    -1,    49,
714      1,    51,     3,     4,    54,    55,     7,     8,    -1,    -1,
715     -1,    61,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
716     -1,     1,    -1,     3,     4,    -1,    -1,     7,     8,    -1,
717     31,    -1,    -1,    -1,    -1,    36,    37,    38,    39,    -1,
718     -1,    -1,    -1,    -1,    -1,    46,    47,    -1,    49,    -1,
719     51,    31,    -1,    54,    55,    56,    36,    37,    38,    39,
720     -1,    -1,    -1,    -1,    -1,    -1,    46,    47,    -1,    49,
721      1,    51,     3,     4,    54,    55,     7,     8,    -1,    -1,
722     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
723     -1,     1,    -1,     3,     4,    -1,    -1,     7,     8,    -1,
724     31,    -1,    -1,    -1,    -1,    36,    37,    38,    39,    -1,
725     -1,    -1,    -1,    -1,    -1,    46,    47,    -1,    49,    -1,
726     51,    31,    -1,    54,    55,    -1,    36,    37,    38,    39,
727     -1,    -1,    -1,    -1,    -1,    -1,    46,    47,    -1,    49,
728     -1,    51,     3,     4,    54,    55,     7,     8,     9,    -1,
729     -1,    12,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
730     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
731     -1,    -1,    33,    34,    35,    36,    37,    38,    39,    40,
732     -1,    -1,    43,    44,    45,    46,    47,    -1,    -1,    -1,
733     51,    -1,    -1,    54,    55,    56,     3,     4,    -1,    -1,
734      7,     8,     9,    -1,    -1,    12,    -1,    -1,    -1,    -1,
735     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
736      4,    -1,    -1,     7,     8,     9,    33,    34,    35,    36,
737     37,    38,    39,    40,    -1,    42,    43,    44,    45,    46,
738     47,    -1,    -1,    -1,    51,     3,     4,    54,    55,     7,
739      8,     9,    36,    37,    12,    -1,    -1,    -1,    -1,    43,
740     44,    45,    46,    47,    -1,    -1,    -1,    51,    -1,    -1,
741     54,    55,    -1,    -1,    -1,    33,    34,    35,    36,    37,
742     38,    39,    40,    41,    -1,    43,    44,    45,    46,    47,
743     -1,    -1,    -1,    51,     3,     4,    54,    55,     7,     8,
744      9,    -1,    -1,    12,    -1,    -1,    -1,    -1,    -1,    -1,
745     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
746     -1,    -1,    -1,    -1,    33,    34,    35,    36,    37,    38,
747     39,    40,    -1,    -1,    43,    44,    45,    46,    47,    -1,
748     -1,    -1,    51,     3,     4,    54,    55,     7,     8,     9,
749     -1,    -1,    12,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
750     -1,    -1,    -1,    -1,    -1,    -1,     3,     4,    -1,    -1,
751      7,     8,     9,    33,    34,    12,    36,    37,    38,    39,
752     -1,    -1,    -1,    43,    44,    45,    46,    47,    -1,    -1,
753     -1,    51,    -1,    -1,    54,    55,    33,    34,    35,    36,
754     37,    38,    39,    40,    41,    -1,    -1,     3,     4,    46,
755     47,     7,     8,     9,    51,    -1,    12,    54,    55,    -1,
756     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
757      3,     4,    -1,    -1,     7,     8,     9,    33,    -1,    12,
758     36,    37,    38,    39,    -1,    -1,    -1,    43,    44,    45,
759     46,    47,    -1,    -1,    -1,    51,    -1,    -1,    54,    55,
760     33,    34,    35,    36,    37,    38,    39,    40,    -1,    -1,
761     -1,     3,     4,    46,    47,     7,     8,     9,    51,    -1,
762     12,    54,    55,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
763     -1,     3,     4,    -1,    -1,     7,     8,     9,    -1,    -1,
764     12,    33,    34,    -1,    36,    37,    38,    39,    -1,    -1,
765     -1,    -1,     3,     4,    46,    47,     7,     8,    -1,    51,
766     -1,    33,    54,    55,    36,    37,    38,    39,    -1,    -1,
767     -1,    -1,    -1,    -1,    46,    47,    -1,    -1,    -1,    51,
768     31,    -1,    54,    55,    -1,    36,    37,    38,    39,     3,
769      4,    -1,    -1,     7,     8,    46,    47,    -1,    49,    -1,
770     51,    -1,    -1,    54,    55,    -1,    -1,    -1,    -1,    -1,
771      3,     4,    -1,    -1,     7,     8,    -1,    31,    -1,    -1,
772     -1,    -1,    36,    37,    38,    39,    -1,    -1,    -1,    -1,
773     -1,    -1,    46,    47,    -1,    49,    -1,    51,    31,    -1,
774     54,    55,    -1,    36,    37,    38,    39,     3,     4,    -1,
775     -1,     7,     8,    46,    47,    -1,    49,    -1,    51,    -1,
776     -1,    54,    55,    -1,    -1,    -1,    -1,     3,     4,    -1,
777     -1,     7,     8,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
778     36,    37,    38,    39,    -1,    -1,    -1,    -1,    -1,    -1,
779     46,    47,    -1,    49,    -1,    51,    -1,    -1,    54,    55,
780     36,    37,    38,    39,    -1,    -1,    -1,    -1,    -1,    -1,
781     46,    47,    -1,    -1,    -1,    51,    -1,    -1,    54,    55
782 };
783 /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
784 #line 3 "/usr/share/bison.simple"
785
786 /* Skeleton output parser for bison,
787    Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
788
789    This program is free software; you can redistribute it and/or modify
790    it under the terms of the GNU General Public License as published by
791    the Free Software Foundation; either version 2, or (at your option)
792    any later version.
793
794    This program is distributed in the hope that it will be useful,
795    but WITHOUT ANY WARRANTY; without even the implied warranty of
796    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
797    GNU General Public License for more details.
798
799    You should have received a copy of the GNU General Public License
800    along with this program; if not, write to the Free Software
801    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
802
803 /* As a special exception, when this file is copied by Bison into a
804    Bison output file, you may use that output file without restriction.
805    This special exception was added by the Free Software Foundation
806    in version 1.24 of Bison.  */
807
808 #ifndef alloca
809 #ifdef __GNUC__
810 #define alloca __builtin_alloca
811 #else /* not GNU C.  */
812 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
813 #include <alloca.h>
814 #else /* not sparc */
815 #if defined (MSDOS) && !defined (__TURBOC__)
816 #include <malloc.h>
817 #else /* not MSDOS, or __TURBOC__ */
818 #if defined(_AIX)
819 #include <malloc.h>
820  #pragma alloca
821 #else /* not MSDOS, __TURBOC__, or _AIX */
822 #ifdef __hpux
823 #ifdef __cplusplus
824 extern "C" {
825 void *alloca (unsigned int);
826 };
827 #else /* not __cplusplus */
828 void *alloca ();
829 #endif /* not __cplusplus */
830 #endif /* __hpux */
831 #endif /* not _AIX */
832 #endif /* not MSDOS, or __TURBOC__ */
833 #endif /* not sparc.  */
834 #endif /* not GNU C.  */
835 #endif /* alloca not defined.  */
836
837 /* This is the parser code that is written into each bison parser
838   when the %semantic_parser declaration is not specified in the grammar.
839   It was written by Richard Stallman by simplifying the hairy parser
840   used when %semantic_parser is specified.  */
841
842 /* Note: there must be only one dollar sign in this file.
843    It is replaced by the list of actions, each action
844    as one case of the switch.  */
845
846 #define yyerrok         (yyerrstatus = 0)
847 #define yyclearin       (yychar = YYEMPTY)
848 #define YYEMPTY         -2
849 #define YYEOF           0
850 #define YYACCEPT        return(0)
851 #define YYABORT         return(1)
852 #define YYERROR         goto yyerrlab1
853 /* Like YYERROR except do call yyerror.
854    This remains here temporarily to ease the
855    transition to the new meaning of YYERROR, for GCC.
856    Once GCC version 2 has supplanted version 1, this can go.  */
857 #define YYFAIL          goto yyerrlab
858 #define YYRECOVERING()  (!!yyerrstatus)
859 #define YYBACKUP(token, value) \
860 do                                                              \
861   if (yychar == YYEMPTY && yylen == 1)                          \
862     { yychar = (token), yylval = (value);                       \
863       yychar1 = YYTRANSLATE (yychar);                           \
864       YYPOPSTACK;                                               \
865       goto yybackup;                                            \
866     }                                                           \
867   else                                                          \
868     { yyerror ("syntax error: cannot back up"); YYERROR; }      \
869 while (0)
870
871 #define YYTERROR        1
872 #define YYERRCODE       256
873
874 #ifndef YYPURE
875 #define YYLEX           yylex()
876 #endif
877
878 #ifdef YYPURE
879 #ifdef YYLSP_NEEDED
880 #ifdef YYLEX_PARAM
881 #define YYLEX           yylex(&yylval, &yylloc, YYLEX_PARAM)
882 #else
883 #define YYLEX           yylex(&yylval, &yylloc)
884 #endif
885 #else /* not YYLSP_NEEDED */
886 #ifdef YYLEX_PARAM
887 #define YYLEX           yylex(&yylval, YYLEX_PARAM)
888 #else
889 #define YYLEX           yylex(&yylval)
890 #endif
891 #endif /* not YYLSP_NEEDED */
892 #endif
893
894 /* If nonreentrant, generate the variables here */
895
896 #ifndef YYPURE
897
898 int     yychar;                 /*  the lookahead symbol                */
899 YYSTYPE yylval;                 /*  the semantic value of the           */
900                                 /*  lookahead symbol                    */
901
902 #ifdef YYLSP_NEEDED
903 YYLTYPE yylloc;                 /*  location data for the lookahead     */
904                                 /*  symbol                              */
905 #endif
906
907 int yynerrs;                    /*  number of parse errors so far       */
908 #endif  /* not YYPURE */
909
910 #if YYDEBUG != 0
911 int yydebug;                    /*  nonzero means print parse trace     */
912 /* Since this is uninitialized, it does not stop multiple parsers
913    from coexisting.  */
914 #endif
915
916 /*  YYINITDEPTH indicates the initial size of the parser's stacks       */
917
918 #ifndef YYINITDEPTH
919 #define YYINITDEPTH 200
920 #endif
921
922 /*  YYMAXDEPTH is the maximum size the stacks can grow to
923     (effective only if the built-in stack extension method is used).  */
924
925 #if YYMAXDEPTH == 0
926 #undef YYMAXDEPTH
927 #endif
928
929 #ifndef YYMAXDEPTH
930 #define YYMAXDEPTH 10000
931 #endif
932
933 #ifndef YYPARSE_RETURN_TYPE
934 #define YYPARSE_RETURN_TYPE int
935 #endif
936
937 /* Prevent warning if -Wstrict-prototypes.  */
938 #ifdef __GNUC__
939 YYPARSE_RETURN_TYPE yyparse (void);
940 #endif
941 \f
942 #if __GNUC__ > 1                /* GNU C and GNU C++ define this.  */
943 #define __yy_memcpy(TO,FROM,COUNT)      __builtin_memcpy(TO,FROM,COUNT)
944 #else                           /* not GNU C or C++ */
945 #ifndef __cplusplus
946
947 /* This is the most reliable way to avoid incompatibilities
948    in available built-in functions on various systems.  */
949 static void
950 __yy_memcpy (to, from, count)
951      char *to;
952      char *from;
953      int count;
954 {
955   register char *f = from;
956   register char *t = to;
957   register int i = count;
958
959   while (i-- > 0)
960     *t++ = *f++;
961 }
962
963 #else /* __cplusplus */
964
965 /* This is the most reliable way to avoid incompatibilities
966    in available built-in functions on various systems.  */
967 static void
968 __yy_memcpy (char *to, char *from, int count)
969 {
970   register char *f = from;
971   register char *t = to;
972   register int i = count;
973
974   while (i-- > 0)
975     *t++ = *f++;
976 }
977
978 #endif
979 #endif
980 \f
981 #line 196 "/usr/share/bison.simple"
982
983 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
984    into yyparse.  The argument should have type void *.
985    It should actually point to an object.
986    Grammar actions can access the variable by casting it
987    to the proper pointer type.  */
988
989 #ifdef YYPARSE_PARAM
990 #ifdef __cplusplus
991 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
992 #define YYPARSE_PARAM_DECL
993 #else /* not __cplusplus */
994 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
995 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
996 #endif /* not __cplusplus */
997 #else /* not YYPARSE_PARAM */
998 #define YYPARSE_PARAM_ARG
999 #define YYPARSE_PARAM_DECL
1000 #endif /* not YYPARSE_PARAM */
1001
1002 YYPARSE_RETURN_TYPE
1003 yyparse(YYPARSE_PARAM_ARG)
1004      YYPARSE_PARAM_DECL
1005 {
1006   register int yystate;
1007   register int yyn;
1008   register short *yyssp;
1009   register YYSTYPE *yyvsp;
1010   int yyerrstatus;      /*  number of tokens to shift before error messages enabled */
1011   int yychar1 = 0;              /*  lookahead token as an internal (translated) token number */
1012
1013   short yyssa[YYINITDEPTH];     /*  the state stack                     */
1014   YYSTYPE yyvsa[YYINITDEPTH];   /*  the semantic value stack            */
1015
1016   short *yyss = yyssa;          /*  refer to the stacks thru separate pointers */
1017   YYSTYPE *yyvs = yyvsa;        /*  to allow yyoverflow to reallocate them elsewhere */
1018
1019 #ifdef YYLSP_NEEDED
1020   YYLTYPE yylsa[YYINITDEPTH];   /*  the location stack                  */
1021   YYLTYPE *yyls = yylsa;
1022   YYLTYPE *yylsp;
1023
1024 #define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
1025 #else
1026 #define YYPOPSTACK   (yyvsp--, yyssp--)
1027 #endif
1028
1029   int yystacksize = YYINITDEPTH;
1030
1031 #ifdef YYPURE
1032   int yychar;
1033   YYSTYPE yylval;
1034   int yynerrs;
1035 #ifdef YYLSP_NEEDED
1036   YYLTYPE yylloc;
1037 #endif
1038 #endif
1039
1040   YYSTYPE yyval;                /*  the variable used to return         */
1041                                 /*  semantic values from the action     */
1042                                 /*  routines                            */
1043
1044   int yylen;
1045
1046 #if YYDEBUG != 0
1047   if (yydebug)
1048     fprintf(stderr, "Starting parse\n");
1049 #endif
1050
1051   yystate = 0;
1052   yyerrstatus = 0;
1053   yynerrs = 0;
1054   yychar = YYEMPTY;             /* Cause a token to be read.  */
1055
1056   /* Initialize stack pointers.
1057      Waste one element of value and location stack
1058      so that they stay on the same level as the state stack.
1059      The wasted elements are never initialized.  */
1060
1061   yyssp = yyss - 1;
1062   yyvsp = yyvs;
1063 #ifdef YYLSP_NEEDED
1064   yylsp = yyls;
1065 #endif
1066
1067 /* Push a new state, which is found in  yystate  .  */
1068 /* In all cases, when you get here, the value and location stacks
1069    have just been pushed. so pushing a state here evens the stacks.  */
1070 yynewstate:
1071
1072   *++yyssp = yystate;
1073
1074   if (yyssp >= yyss + yystacksize - 1)
1075     {
1076       /* Give user a chance to reallocate the stack */
1077       /* Use copies of these so that the &'s don't force the real ones into memory. */
1078       YYSTYPE *yyvs1 = yyvs;
1079       short *yyss1 = yyss;
1080 #ifdef YYLSP_NEEDED
1081       YYLTYPE *yyls1 = yyls;
1082 #endif
1083
1084       /* Get the current used size of the three stacks, in elements.  */
1085       int size = yyssp - yyss + 1;
1086
1087 #ifdef yyoverflow
1088       /* Each stack pointer address is followed by the size of
1089          the data in use in that stack, in bytes.  */
1090 #ifdef YYLSP_NEEDED
1091       /* This used to be a conditional around just the two extra args,
1092          but that might be undefined if yyoverflow is a macro.  */
1093       yyoverflow("parser stack overflow",
1094                  &yyss1, size * sizeof (*yyssp),
1095                  &yyvs1, size * sizeof (*yyvsp),
1096                  &yyls1, size * sizeof (*yylsp),
1097                  &yystacksize);
1098 #else
1099       yyoverflow("parser stack overflow",
1100                  &yyss1, size * sizeof (*yyssp),
1101                  &yyvs1, size * sizeof (*yyvsp),
1102                  &yystacksize);
1103 #endif
1104
1105       yyss = yyss1; yyvs = yyvs1;
1106 #ifdef YYLSP_NEEDED
1107       yyls = yyls1;
1108 #endif
1109 #else /* no yyoverflow */
1110       /* Extend the stack our own way.  */
1111       if (yystacksize >= YYMAXDEPTH)
1112         {
1113           yyerror("parser stack overflow");
1114           return 2;
1115         }
1116       yystacksize *= 2;
1117       if (yystacksize > YYMAXDEPTH)
1118         yystacksize = YYMAXDEPTH;
1119       yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
1120       __yy_memcpy ((char *)yyss, (char *)yyss1, size * sizeof (*yyssp));
1121       yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
1122       __yy_memcpy ((char *)yyvs, (char *)yyvs1, size * sizeof (*yyvsp));
1123 #ifdef YYLSP_NEEDED
1124       yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
1125       __yy_memcpy ((char *)yyls, (char *)yyls1, size * sizeof (*yylsp));
1126 #endif
1127 #endif /* no yyoverflow */
1128
1129       yyssp = yyss + size - 1;
1130       yyvsp = yyvs + size - 1;
1131 #ifdef YYLSP_NEEDED
1132       yylsp = yyls + size - 1;
1133 #endif
1134
1135 #if YYDEBUG != 0
1136       if (yydebug)
1137         fprintf(stderr, "Stack size increased to %d\n", yystacksize);
1138 #endif
1139
1140       if (yyssp >= yyss + yystacksize - 1)
1141         YYABORT;
1142     }
1143
1144 #if YYDEBUG != 0
1145   if (yydebug)
1146     fprintf(stderr, "Entering state %d\n", yystate);
1147 #endif
1148
1149   goto yybackup;
1150  yybackup:
1151
1152 /* Do appropriate processing given the current state.  */
1153 /* Read a lookahead token if we need one and don't already have one.  */
1154 /* yyresume: */
1155
1156   /* First try to decide what to do without reference to lookahead token.  */
1157
1158   yyn = yypact[yystate];
1159   if (yyn == YYFLAG)
1160     goto yydefault;
1161
1162   /* Not known => get a lookahead token if don't already have one.  */
1163
1164   /* yychar is either YYEMPTY or YYEOF
1165      or a valid token in external form.  */
1166
1167   if (yychar == YYEMPTY)
1168     {
1169 #if YYDEBUG != 0
1170       if (yydebug)
1171         fprintf(stderr, "Reading a token: ");
1172 #endif
1173       yychar = YYLEX;
1174     }
1175
1176   /* Convert token to internal form (in yychar1) for indexing tables with */
1177
1178   if (yychar <= 0)              /* This means end of input. */
1179     {
1180       yychar1 = 0;
1181       yychar = YYEOF;           /* Don't call YYLEX any more */
1182
1183 #if YYDEBUG != 0
1184       if (yydebug)
1185         fprintf(stderr, "Now at end of input.\n");
1186 #endif
1187     }
1188   else
1189     {
1190       yychar1 = YYTRANSLATE(yychar);
1191
1192 #if YYDEBUG != 0
1193       if (yydebug)
1194         {
1195           fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
1196           /* Give the individual parser a way to print the precise meaning
1197              of a token, for further debugging info.  */
1198 #ifdef YYPRINT
1199           YYPRINT (stderr, yychar, yylval);
1200 #endif
1201           fprintf (stderr, ")\n");
1202         }
1203 #endif
1204     }
1205
1206   yyn += yychar1;
1207   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
1208     goto yydefault;
1209
1210   yyn = yytable[yyn];
1211
1212   /* yyn is what to do for this token type in this state.
1213      Negative => reduce, -yyn is rule number.
1214      Positive => shift, yyn is new state.
1215        New state is final state => don't bother to shift,
1216        just return success.
1217      0, or most negative number => error.  */
1218
1219   if (yyn < 0)
1220     {
1221       if (yyn == YYFLAG)
1222         goto yyerrlab;
1223       yyn = -yyn;
1224       goto yyreduce;
1225     }
1226   else if (yyn == 0)
1227     goto yyerrlab;
1228
1229   if (yyn == YYFINAL)
1230     YYACCEPT;
1231
1232   /* Shift the lookahead token.  */
1233
1234 #if YYDEBUG != 0
1235   if (yydebug)
1236     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
1237 #endif
1238
1239   /* Discard the token being shifted unless it is eof.  */
1240   if (yychar != YYEOF)
1241     yychar = YYEMPTY;
1242
1243   *++yyvsp = yylval;
1244 #ifdef YYLSP_NEEDED
1245   *++yylsp = yylloc;
1246 #endif
1247
1248   /* count tokens shifted since error; after three, turn off error status.  */
1249   if (yyerrstatus) yyerrstatus--;
1250
1251   yystate = yyn;
1252   goto yynewstate;
1253
1254 /* Do the default action for the current state.  */
1255 yydefault:
1256
1257   yyn = yydefact[yystate];
1258   if (yyn == 0)
1259     goto yyerrlab;
1260
1261 /* Do a reduction.  yyn is the number of a rule to reduce with.  */
1262 yyreduce:
1263   yylen = yyr2[yyn];
1264   if (yylen > 0)
1265     yyval = yyvsp[1-yylen]; /* implement default value of the action */
1266
1267 #if YYDEBUG != 0
1268   if (yydebug)
1269     {
1270       int i;
1271
1272       fprintf (stderr, "Reducing via rule %d (line %d), ",
1273                yyn, yyrline[yyn]);
1274
1275       /* Print the symbols being reduced, and their result.  */
1276       for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
1277         fprintf (stderr, "%s ", yytname[yyrhs[i]]);
1278       fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
1279     }
1280 #endif
1281
1282
1283   switch (yyn) {
1284
1285 case 1:
1286 #line 151 "./awk.y"
1287 {
1288                         expression_value = yyvsp[-1].nodeval;
1289                         check_funcs();
1290                 ;
1291     break;}
1292 case 2:
1293 #line 159 "./awk.y"
1294
1295                         if (yyvsp[0].nodeval != NULL)
1296                                 yyval.nodeval = yyvsp[0].nodeval;
1297                         else
1298                                 yyval.nodeval = NULL;
1299                         yyerrok;
1300                 ;
1301     break;}
1302 case 3:
1303 #line 168 "./awk.y"
1304 {
1305                         if (yyvsp[0].nodeval == NULL)
1306                                 yyval.nodeval = yyvsp[-1].nodeval;
1307                         else if (yyvsp[-1].nodeval == NULL)
1308                                 yyval.nodeval = yyvsp[0].nodeval;
1309                         else {
1310                                 if (yyvsp[-1].nodeval->type != Node_rule_list)
1311                                         yyvsp[-1].nodeval = node(yyvsp[-1].nodeval, Node_rule_list,
1312                                                 (NODE*) NULL);
1313                                 yyval.nodeval = append_right(yyvsp[-1].nodeval,
1314                                    node(yyvsp[0].nodeval, Node_rule_list, (NODE *) NULL));
1315                         }
1316                         yyerrok;
1317                 ;
1318     break;}
1319 case 4:
1320 #line 182 "./awk.y"
1321 { yyval.nodeval = NULL; ;
1322     break;}
1323 case 5:
1324 #line 183 "./awk.y"
1325 { yyval.nodeval = NULL; ;
1326     break;}
1327 case 6:
1328 #line 184 "./awk.y"
1329 { yyval.nodeval = NULL; ;
1330     break;}
1331 case 7:
1332 #line 188 "./awk.y"
1333 { io_allowed = FALSE; ;
1334     break;}
1335 case 8:
1336 #line 190 "./awk.y"
1337 {
1338                 if (begin_block != NULL) {
1339                         if (begin_block->type != Node_rule_list)
1340                                 begin_block = node(begin_block, Node_rule_list,
1341                                         (NODE *) NULL);
1342                         (void) append_right(begin_block, node(
1343                             node((NODE *) NULL, Node_rule_node, yyvsp[0].nodeval),
1344                             Node_rule_list, (NODE *) NULL) );
1345                 } else
1346                         begin_block = node((NODE *) NULL, Node_rule_node, yyvsp[0].nodeval);
1347                 yyval.nodeval = NULL;
1348                 io_allowed = TRUE;
1349                 yyerrok;
1350           ;
1351     break;}
1352 case 9:
1353 #line 204 "./awk.y"
1354 { io_allowed = FALSE; ;
1355     break;}
1356 case 10:
1357 #line 206 "./awk.y"
1358 {
1359                 if (end_block != NULL) {
1360                         if (end_block->type != Node_rule_list)
1361                                 end_block = node(end_block, Node_rule_list,
1362                                         (NODE *) NULL);
1363                         (void) append_right (end_block, node(
1364                             node((NODE *) NULL, Node_rule_node, yyvsp[0].nodeval),
1365                             Node_rule_list, (NODE *) NULL));
1366                 } else
1367                         end_block = node((NODE *) NULL, Node_rule_node, yyvsp[0].nodeval);
1368                 yyval.nodeval = NULL;
1369                 io_allowed = TRUE;
1370                 yyerrok;
1371           ;
1372     break;}
1373 case 11:
1374 #line 221 "./awk.y"
1375 {
1376                 warning("BEGIN blocks must have an action part");
1377                 errcount++;
1378                 yyerrok;
1379           ;
1380     break;}
1381 case 12:
1382 #line 227 "./awk.y"
1383 {
1384                 warning("END blocks must have an action part");
1385                 errcount++;
1386                 yyerrok;
1387           ;
1388     break;}
1389 case 13:
1390 #line 233 "./awk.y"
1391 { yyval.nodeval = node(yyvsp[-1].nodeval, Node_rule_node, yyvsp[0].nodeval); yyerrok; ;
1392     break;}
1393 case 14:
1394 #line 235 "./awk.y"
1395 { yyval.nodeval = node((NODE *) NULL, Node_rule_node, yyvsp[0].nodeval); yyerrok; ;
1396     break;}
1397 case 15:
1398 #line 237 "./awk.y"
1399 {
1400                   yyval.nodeval = node(yyvsp[-1].nodeval,
1401                              Node_rule_node,
1402                              node(node(node(make_number(0.0),
1403                                             Node_field_spec,
1404                                             (NODE *) NULL),
1405                                         Node_expression_list,
1406                                         (NODE *) NULL),
1407                                   Node_K_print,
1408                                   (NODE *) NULL));
1409                   yyerrok;
1410                 ;
1411     break;}
1412 case 16:
1413 #line 250 "./awk.y"
1414 {
1415                         func_install(yyvsp[-1].nodeval, yyvsp[0].nodeval);
1416                         yyval.nodeval = NULL;
1417                         yyerrok;
1418                 ;
1419     break;}
1420 case 17:
1421 #line 259 "./awk.y"
1422 { yyval.sval = yyvsp[0].sval; ;
1423     break;}
1424 case 18:
1425 #line 261 "./awk.y"
1426 { yyval.sval = yyvsp[0].sval; ;
1427     break;}
1428 case 19:
1429 #line 263 "./awk.y"
1430 {
1431                 yyerror("%s() is a built-in function, it cannot be redefined",
1432                         tokstart);
1433                 errcount++;
1434                 /* yyerrok; */
1435           ;
1436     break;}
1437 case 22:
1438 #line 278 "./awk.y"
1439 {
1440                         param_counter = 0;
1441                 ;
1442     break;}
1443 case 23:
1444 #line 282 "./awk.y"
1445 {
1446                         NODE *t;
1447
1448                         t = make_param(yyvsp[-4].sval);
1449                         t->flags |= FUNC;
1450                         yyval.nodeval = append_right(t, yyvsp[-2].nodeval);
1451                         can_return = TRUE;
1452                         /* check for duplicate parameter names */
1453                         if (dup_parms(yyval.nodeval))
1454                                 errcount++;
1455                 ;
1456     break;}
1457 case 24:
1458 #line 297 "./awk.y"
1459 {
1460                 yyval.nodeval = yyvsp[-2].nodeval;
1461                 can_return = FALSE;
1462           ;
1463     break;}
1464 case 25:
1465 #line 302 "./awk.y"
1466 {
1467                 yyval.nodeval = node((NODE *) NULL, Node_K_return, (NODE *) NULL);
1468                 can_return = FALSE;
1469           ;
1470     break;}
1471 case 26:
1472 #line 311 "./awk.y"
1473 { yyval.nodeval = yyvsp[0].nodeval; ;
1474     break;}
1475 case 27:
1476 #line 313 "./awk.y"
1477 { yyval.nodeval = mkrangenode(node(yyvsp[-2].nodeval, Node_cond_pair, yyvsp[0].nodeval)); ;
1478     break;}
1479 case 28:
1480 #line 322 "./awk.y"
1481 { ++want_regexp; ;
1482     break;}
1483 case 29:
1484 #line 324 "./awk.y"
1485 {
1486                   NODE *n;
1487                   size_t len;
1488
1489                   getnode(n);
1490                   n->type = Node_regex;
1491                   len = strlen(yyvsp[-1].sval);
1492                   n->re_exp = make_string(yyvsp[-1].sval, len);
1493                   n->re_reg = make_regexp(yyvsp[-1].sval, len, FALSE, TRUE);
1494                   n->re_text = NULL;
1495                   n->re_flags = CONST;
1496                   n->re_cnt = 1;
1497                   yyval.nodeval = n;
1498                 ;
1499     break;}
1500 case 30:
1501 #line 342 "./awk.y"
1502 { yyval.nodeval = yyvsp[-3].nodeval; ;
1503     break;}
1504 case 31:
1505 #line 344 "./awk.y"
1506 { yyval.nodeval = NULL; ;
1507     break;}
1508 case 32:
1509 #line 349 "./awk.y"
1510 {
1511                         yyval.nodeval = yyvsp[0].nodeval;
1512                         if (do_lint && isnoeffect(yyval.nodeval->type))
1513                                 warning("statement may have no effect");
1514                 ;
1515     break;}
1516 case 33:
1517 #line 355 "./awk.y"
1518 {
1519                         if (yyvsp[-1].nodeval == NULL || yyvsp[-1].nodeval->type != Node_statement_list)
1520                                 yyvsp[-1].nodeval = node(yyvsp[-1].nodeval, Node_statement_list, (NODE *) NULL);
1521                         yyval.nodeval = append_right(yyvsp[-1].nodeval,
1522                                 node(yyvsp[0].nodeval, Node_statement_list, (NODE *)   NULL));
1523                         yyerrok;
1524                 ;
1525     break;}
1526 case 34:
1527 #line 363 "./awk.y"
1528 { yyval.nodeval = NULL; ;
1529     break;}
1530 case 35:
1531 #line 365 "./awk.y"
1532 { yyval.nodeval = NULL; ;
1533     break;}
1534 case 38:
1535 #line 375 "./awk.y"
1536 { yyval.nodeval = NULL; ;
1537     break;}
1538 case 39:
1539 #line 377 "./awk.y"
1540 { yyval.nodeval = NULL; ;
1541     break;}
1542 case 40:
1543 #line 379 "./awk.y"
1544 { yyval.nodeval = yyvsp[-1].nodeval; ;
1545     break;}
1546 case 41:
1547 #line 381 "./awk.y"
1548 { yyval.nodeval = yyvsp[0].nodeval; ;
1549     break;}
1550 case 42:
1551 #line 383 "./awk.y"
1552 { yyval.nodeval = node(yyvsp[-3].nodeval, Node_K_while, yyvsp[0].nodeval); ;
1553     break;}
1554 case 43:
1555 #line 385 "./awk.y"
1556 { yyval.nodeval = node(yyvsp[-2].nodeval, Node_K_do, yyvsp[-5].nodeval); ;
1557     break;}
1558 case 44:
1559 #line 387 "./awk.y"
1560 {
1561                 /*
1562                  * Efficiency hack.  Recognize the special case of
1563                  *
1564                  *      for (iggy in foo)
1565                  *              delete foo[iggy]
1566                  *
1567                  * and treat it as if it were
1568                  *
1569                  *      delete foo
1570                  *
1571                  * Check that the body is a `delete a[i]' statement,
1572                  * and that both the loop var and array names match.
1573                  */
1574                 if (yyvsp[0].nodeval->type == Node_K_delete
1575                     && yyvsp[0].nodeval->rnode != NULL
1576                     && strcmp(yyvsp[-5].sval, yyvsp[0].nodeval->rnode->var_value->vname) == 0
1577                     && strcmp(yyvsp[-3].sval, yyvsp[0].nodeval->lnode->vname) == 0) {
1578                         yyvsp[0].nodeval->type = Node_K_delete_loop;
1579                         yyval.nodeval = yyvsp[0].nodeval;
1580                 } else {
1581                         yyval.nodeval = node(yyvsp[0].nodeval, Node_K_arrayfor,
1582                                 make_for_loop(variable(yyvsp[-5].sval, CAN_FREE, Node_var),
1583                                 (NODE *) NULL, variable(yyvsp[-3].sval, CAN_FREE, Node_var_array)));
1584                 }
1585           ;
1586     break;}
1587 case 45:
1588 #line 414 "./awk.y"
1589 {
1590                 yyval.nodeval = node(yyvsp[0].nodeval, Node_K_for, (NODE *) make_for_loop(yyvsp[-7].nodeval, yyvsp[-5].nodeval, yyvsp[-3].nodeval));
1591           ;
1592     break;}
1593 case 46:
1594 #line 418 "./awk.y"
1595 {
1596                 yyval.nodeval = node(yyvsp[0].nodeval, Node_K_for,
1597                         (NODE *) make_for_loop(yyvsp[-6].nodeval, (NODE *) NULL, yyvsp[-3].nodeval));
1598           ;
1599     break;}
1600 case 47:
1601 #line 424 "./awk.y"
1602 { yyval.nodeval = node((NODE *) NULL, Node_K_break, (NODE *) NULL); ;
1603     break;}
1604 case 48:
1605 #line 427 "./awk.y"
1606 { yyval.nodeval = node((NODE *) NULL, Node_K_continue, (NODE *) NULL); ;
1607     break;}
1608 case 49:
1609 #line 429 "./awk.y"
1610 { yyval.nodeval = node(yyvsp[-3].nodeval, yyvsp[-5].nodetypeval, yyvsp[-1].nodeval); ;
1611     break;}
1612 case 50:
1613 #line 431 "./awk.y"
1614 {
1615                         if (yyvsp[-3].nodetypeval == Node_K_print && yyvsp[-2].nodeval == NULL) {
1616                                 static int warned = FALSE;
1617
1618                                 yyvsp[-2].nodeval = node(node(make_number(0.0),
1619                                                Node_field_spec,
1620                                                (NODE *) NULL),
1621                                           Node_expression_list,
1622                                           (NODE *) NULL);
1623
1624                                 if (do_lint && ! io_allowed && ! warned) {
1625                                         warned = TRUE;
1626                                         warning(
1627         "plain `print' in BEGIN or END rule should probably be `print \"\"'");
1628                                 }
1629                         }
1630
1631                         yyval.nodeval = node(yyvsp[-2].nodeval, yyvsp[-3].nodetypeval, yyvsp[-1].nodeval);
1632                 ;
1633     break;}
1634 case 51:
1635 #line 451 "./awk.y"
1636 { NODETYPE type;
1637
1638                   if (yyvsp[-1].nodeval) {
1639                         if (yyvsp[-1].nodeval == lookup("file")) {
1640                                 static int warned = FALSE;
1641
1642                                 if (! warned) {
1643                                         warned = TRUE;
1644                                         warning("`next file' is obsolete; use `nextfile'");
1645                                 }
1646                                 if (do_lint)
1647                                         warning("`next file' is a gawk extension");
1648                                 if (do_traditional) {
1649                                         /*
1650                                          * can't use yyerror, since may have overshot
1651                                          * the source line
1652                                          */
1653                                         errcount++;
1654                                         error("`next file' is a gawk extension");
1655                                 }
1656                                 if (! io_allowed) {
1657                                         /* same thing */
1658                                         errcount++;
1659                                         error("`next file' used in BEGIN or END action");
1660                                 }
1661                                 type = Node_K_nextfile;
1662                         } else {
1663                                 errcount++;
1664                                 error("illegal expression after `next'");
1665                                 type = Node_K_next;     /* sanity */
1666                         }
1667                   } else {
1668                         if (! io_allowed)
1669                                 yyerror("`next' used in BEGIN or END action");
1670                         type = Node_K_next;
1671                   }
1672                   yyval.nodeval = node((NODE *) NULL, type, (NODE *) NULL);
1673                 ;
1674     break;}
1675 case 52:
1676 #line 490 "./awk.y"
1677 {
1678                   if (do_lint)
1679                         warning("`nextfile' is a gawk extension");
1680                   if (do_traditional) {
1681                         /*
1682                          * can't use yyerror, since may have overshot
1683                          * the source line
1684                          */
1685                         errcount++;
1686                         error("`nextfile' is a gawk extension");
1687                   }
1688                   if (! io_allowed) {
1689                         /* same thing */
1690                         errcount++;
1691                         error("`nextfile' used in BEGIN or END action");
1692                   }
1693                   yyval.nodeval = node((NODE *) NULL, Node_K_nextfile, (NODE *) NULL);
1694                 ;
1695     break;}
1696 case 53:
1697 #line 509 "./awk.y"
1698 { yyval.nodeval = node(yyvsp[-1].nodeval, Node_K_exit, (NODE *) NULL); ;
1699     break;}
1700 case 54:
1701 #line 511 "./awk.y"
1702 {
1703                   if (! can_return)
1704                         yyerror("`return' used outside function context");
1705                 ;
1706     break;}
1707 case 55:
1708 #line 516 "./awk.y"
1709 { yyval.nodeval = node(yyvsp[-1].nodeval, Node_K_return, (NODE *) NULL); ;
1710     break;}
1711 case 56:
1712 #line 518 "./awk.y"
1713 { yyval.nodeval = node(variable(yyvsp[-4].sval, CAN_FREE, Node_var_array), Node_K_delete, yyvsp[-2].nodeval); ;
1714     break;}
1715 case 57:
1716 #line 520 "./awk.y"
1717 {
1718                   if (do_lint)
1719                         warning("`delete array' is a gawk extension");
1720                   if (do_traditional) {
1721                         /*
1722                          * can't use yyerror, since may have overshot
1723                          * the source line
1724                          */
1725                         errcount++;
1726                         error("`delete array' is a gawk extension");
1727                   }
1728                   yyval.nodeval = node(variable(yyvsp[-1].sval, CAN_FREE, Node_var_array), Node_K_delete, (NODE *) NULL);
1729                 ;
1730     break;}
1731 case 58:
1732 #line 534 "./awk.y"
1733 { yyval.nodeval = yyvsp[-1].nodeval; ;
1734     break;}
1735 case 59:
1736 #line 539 "./awk.y"
1737 { yyval.nodetypeval = yyvsp[0].nodetypeval; ;
1738     break;}
1739 case 60:
1740 #line 541 "./awk.y"
1741 { yyval.nodetypeval = yyvsp[0].nodetypeval; ;
1742     break;}
1743 case 61:
1744 #line 546 "./awk.y"
1745 {
1746                 yyval.nodeval = node(yyvsp[-3].nodeval, Node_K_if, 
1747                         node(yyvsp[0].nodeval, Node_if_branches, (NODE *) NULL));
1748           ;
1749     break;}
1750 case 62:
1751 #line 552 "./awk.y"
1752 { yyval.nodeval = node(yyvsp[-6].nodeval, Node_K_if,
1753                                 node(yyvsp[-3].nodeval, Node_if_branches, yyvsp[0].nodeval)); ;
1754     break;}
1755 case 63:
1756 #line 558 "./awk.y"
1757 { want_assign = FALSE; ;
1758     break;}
1759 case 67:
1760 #line 569 "./awk.y"
1761 { yyval.nodeval = NULL; ;
1762     break;}
1763 case 68:
1764 #line 571 "./awk.y"
1765 { yyval.nodeval = node(yyvsp[0].nodeval, Node_redirect_input, (NODE *) NULL); ;
1766     break;}
1767 case 69:
1768 #line 576 "./awk.y"
1769 { yyval.nodeval = NULL; ;
1770     break;}
1771 case 70:
1772 #line 578 "./awk.y"
1773 { yyval.nodeval = node(yyvsp[0].nodeval, Node_redirect_output, (NODE *) NULL); ;
1774     break;}
1775 case 71:
1776 #line 580 "./awk.y"
1777 { yyval.nodeval = node(yyvsp[0].nodeval, Node_redirect_append, (NODE *) NULL); ;
1778     break;}
1779 case 72:
1780 #line 582 "./awk.y"
1781 { yyval.nodeval = node(yyvsp[0].nodeval, Node_redirect_pipe, (NODE *) NULL); ;
1782     break;}
1783 case 73:
1784 #line 587 "./awk.y"
1785 { yyval.nodeval = NULL; ;
1786     break;}
1787 case 74:
1788 #line 589 "./awk.y"
1789 { yyval.nodeval = yyvsp[0].nodeval; ;
1790     break;}
1791 case 75:
1792 #line 594 "./awk.y"
1793 { yyval.nodeval = make_param(yyvsp[0].sval); ;
1794     break;}
1795 case 76:
1796 #line 596 "./awk.y"
1797 { yyval.nodeval = append_right(yyvsp[-2].nodeval, make_param(yyvsp[0].sval)); yyerrok; ;
1798     break;}
1799 case 77:
1800 #line 598 "./awk.y"
1801 { yyval.nodeval = NULL; ;
1802     break;}
1803 case 78:
1804 #line 600 "./awk.y"
1805 { yyval.nodeval = NULL; ;
1806     break;}
1807 case 79:
1808 #line 602 "./awk.y"
1809 { yyval.nodeval = NULL; ;
1810     break;}
1811 case 80:
1812 #line 608 "./awk.y"
1813 { yyval.nodeval = NULL; ;
1814     break;}
1815 case 81:
1816 #line 610 "./awk.y"
1817 { yyval.nodeval = yyvsp[0].nodeval; ;
1818     break;}
1819 case 82:
1820 #line 615 "./awk.y"
1821 { yyval.nodeval = NULL; ;
1822     break;}
1823 case 83:
1824 #line 617 "./awk.y"
1825 { yyval.nodeval = yyvsp[0].nodeval; ;
1826     break;}
1827 case 84:
1828 #line 622 "./awk.y"
1829 { yyval.nodeval = node(yyvsp[0].nodeval, Node_expression_list, (NODE *) NULL); ;
1830     break;}
1831 case 85:
1832 #line 624 "./awk.y"
1833 {
1834                 yyval.nodeval = append_right(yyvsp[-2].nodeval,
1835                         node(yyvsp[0].nodeval, Node_expression_list, (NODE *) NULL));
1836                 yyerrok;
1837           ;
1838     break;}
1839 case 86:
1840 #line 630 "./awk.y"
1841 { yyval.nodeval = NULL; ;
1842     break;}
1843 case 87:
1844 #line 632 "./awk.y"
1845 { yyval.nodeval = NULL; ;
1846     break;}
1847 case 88:
1848 #line 634 "./awk.y"
1849 { yyval.nodeval = NULL; ;
1850     break;}
1851 case 89:
1852 #line 636 "./awk.y"
1853 { yyval.nodeval = NULL; ;
1854     break;}
1855 case 90:
1856 #line 641 "./awk.y"
1857 { yyval.nodeval = NULL; ;
1858     break;}
1859 case 91:
1860 #line 643 "./awk.y"
1861 { yyval.nodeval = yyvsp[0].nodeval; ;
1862     break;}
1863 case 92:
1864 #line 648 "./awk.y"
1865 { yyval.nodeval = node(yyvsp[0].nodeval, Node_expression_list, (NODE *) NULL); ;
1866     break;}
1867 case 93:
1868 #line 650 "./awk.y"
1869 {
1870                         yyval.nodeval = append_right(yyvsp[-2].nodeval,
1871                                 node(yyvsp[0].nodeval, Node_expression_list, (NODE *) NULL));
1872                         yyerrok;
1873                 ;
1874     break;}
1875 case 94:
1876 #line 656 "./awk.y"
1877 { yyval.nodeval = NULL; ;
1878     break;}
1879 case 95:
1880 #line 658 "./awk.y"
1881 { yyval.nodeval = NULL; ;
1882     break;}
1883 case 96:
1884 #line 660 "./awk.y"
1885 { yyval.nodeval = NULL; ;
1886     break;}
1887 case 97:
1888 #line 662 "./awk.y"
1889 { yyval.nodeval = NULL; ;
1890     break;}
1891 case 98:
1892 #line 667 "./awk.y"
1893 { want_assign = FALSE; ;
1894     break;}
1895 case 99:
1896 #line 669 "./awk.y"
1897 {
1898                   if (do_lint && yyvsp[0].nodeval->type == Node_regex)
1899                         warning("Regular expression on left of assignment.");
1900                   yyval.nodeval = node(yyvsp[-3].nodeval, yyvsp[-2].nodetypeval, yyvsp[0].nodeval);
1901                 ;
1902     break;}
1903 case 100:
1904 #line 675 "./awk.y"
1905 { yyval.nodeval = node(variable(yyvsp[0].sval, CAN_FREE, Node_var_array), Node_in_array, yyvsp[-3].nodeval); ;
1906     break;}
1907 case 101:
1908 #line 677 "./awk.y"
1909 {
1910                   yyval.nodeval = node(yyvsp[0].nodeval, Node_K_getline,
1911                          node(yyvsp[-3].nodeval, Node_redirect_pipein, (NODE *) NULL));
1912                 ;
1913     break;}
1914 case 102:
1915 #line 682 "./awk.y"
1916 {
1917                   if (do_lint && ! io_allowed && yyvsp[0].nodeval == NULL)
1918                         warning("non-redirected getline undefined inside BEGIN or END action");
1919                   yyval.nodeval = node(yyvsp[-1].nodeval, Node_K_getline, yyvsp[0].nodeval);
1920                 ;
1921     break;}
1922 case 103:
1923 #line 688 "./awk.y"
1924 { yyval.nodeval = node(yyvsp[-2].nodeval, Node_and, yyvsp[0].nodeval); ;
1925     break;}
1926 case 104:
1927 #line 690 "./awk.y"
1928 { yyval.nodeval = node(yyvsp[-2].nodeval, Node_or, yyvsp[0].nodeval); ;
1929     break;}
1930 case 105:
1931 #line 692 "./awk.y"
1932 {
1933                   if (yyvsp[-2].nodeval->type == Node_regex)
1934                         warning("Regular expression on left of MATCH operator.");
1935                   yyval.nodeval = node(yyvsp[-2].nodeval, yyvsp[-1].nodetypeval, mk_rexp(yyvsp[0].nodeval));
1936                 ;
1937     break;}
1938 case 106:
1939 #line 698 "./awk.y"
1940 {
1941                   yyval.nodeval = yyvsp[0].nodeval;
1942                   if (do_lint && tokstart[0] == '*') {
1943                         /* possible C comment */
1944                         int n = strlen(tokstart) - 1;
1945                         if (tokstart[n] == '*')
1946                                 warning("regexp looks like a C comment, but is not");
1947                   }
1948                 ;
1949     break;}
1950 case 107:
1951 #line 708 "./awk.y"
1952 {
1953                   yyval.nodeval = node(node(make_number(0.0),
1954                                  Node_field_spec,
1955                                  (NODE *) NULL),
1956                             Node_nomatch,
1957                             yyvsp[0].nodeval);
1958                 ;
1959     break;}
1960 case 108:
1961 #line 716 "./awk.y"
1962 { yyval.nodeval = node(variable(yyvsp[0].sval, CAN_FREE, Node_var_array), Node_in_array, yyvsp[-2].nodeval); ;
1963     break;}
1964 case 109:
1965 #line 718 "./awk.y"
1966 {
1967                   if (do_lint && yyvsp[0].nodeval->type == Node_regex)
1968                         warning("Regular expression on left of comparison.");
1969                   yyval.nodeval = node(yyvsp[-2].nodeval, yyvsp[-1].nodetypeval, yyvsp[0].nodeval);
1970                 ;
1971     break;}
1972 case 110:
1973 #line 724 "./awk.y"
1974 { yyval.nodeval = node(yyvsp[-2].nodeval, Node_less, yyvsp[0].nodeval); ;
1975     break;}
1976 case 111:
1977 #line 726 "./awk.y"
1978 { yyval.nodeval = node(yyvsp[-2].nodeval, Node_greater, yyvsp[0].nodeval); ;
1979     break;}
1980 case 112:
1981 #line 728 "./awk.y"
1982 { yyval.nodeval = node(yyvsp[-4].nodeval, Node_cond_exp, node(yyvsp[-2].nodeval, Node_if_branches, yyvsp[0].nodeval));;
1983     break;}
1984 case 113:
1985 #line 730 "./awk.y"
1986 { yyval.nodeval = yyvsp[0].nodeval; ;
1987     break;}
1988 case 114:
1989 #line 732 "./awk.y"
1990 { yyval.nodeval = node(yyvsp[-1].nodeval, Node_concat, yyvsp[0].nodeval); ;
1991     break;}
1992 case 115:
1993 #line 737 "./awk.y"
1994 { want_assign = FALSE; ;
1995     break;}
1996 case 116:
1997 #line 739 "./awk.y"
1998 { yyval.nodeval = node(yyvsp[-3].nodeval, yyvsp[-2].nodetypeval, yyvsp[0].nodeval); ;
1999     break;}
2000 case 117:
2001 #line 741 "./awk.y"
2002 { yyval.nodeval = node(yyvsp[-2].nodeval, Node_and, yyvsp[0].nodeval); ;
2003     break;}
2004 case 118:
2005 #line 743 "./awk.y"
2006 { yyval.nodeval = node(yyvsp[-2].nodeval, Node_or, yyvsp[0].nodeval); ;
2007     break;}
2008 case 119:
2009 #line 745 "./awk.y"
2010 {
2011                   if (do_lint && ! io_allowed && yyvsp[0].nodeval == NULL)
2012                         warning("non-redirected getline undefined inside BEGIN or END action");
2013                   yyval.nodeval = node(yyvsp[-1].nodeval, Node_K_getline, yyvsp[0].nodeval);
2014                 ;
2015     break;}
2016 case 120:
2017 #line 751 "./awk.y"
2018 { yyval.nodeval = yyvsp[0].nodeval; ;
2019     break;}
2020 case 121:
2021 #line 753 "./awk.y"
2022 { yyval.nodeval = node((NODE *) NULL, Node_nomatch, yyvsp[0].nodeval); ;
2023     break;}
2024 case 122:
2025 #line 755 "./awk.y"
2026 { yyval.nodeval = node(yyvsp[-2].nodeval, yyvsp[-1].nodetypeval, mk_rexp(yyvsp[0].nodeval)); ;
2027     break;}
2028 case 123:
2029 #line 757 "./awk.y"
2030 { yyval.nodeval = node(variable(yyvsp[0].sval, CAN_FREE, Node_var_array), Node_in_array, yyvsp[-2].nodeval); ;
2031     break;}
2032 case 124:
2033 #line 759 "./awk.y"
2034 { yyval.nodeval = node(yyvsp[-2].nodeval, yyvsp[-1].nodetypeval, yyvsp[0].nodeval); ;
2035     break;}
2036 case 125:
2037 #line 761 "./awk.y"
2038 { yyval.nodeval = node(yyvsp[-4].nodeval, Node_cond_exp, node(yyvsp[-2].nodeval, Node_if_branches, yyvsp[0].nodeval));;
2039     break;}
2040 case 126:
2041 #line 763 "./awk.y"
2042 { yyval.nodeval = yyvsp[0].nodeval; ;
2043     break;}
2044 case 127:
2045 #line 765 "./awk.y"
2046 { yyval.nodeval = node(yyvsp[-1].nodeval, Node_concat, yyvsp[0].nodeval); ;
2047     break;}
2048 case 129:
2049 #line 772 "./awk.y"
2050 { yyval.nodeval = node(yyvsp[-2].nodeval, Node_exp, yyvsp[0].nodeval); ;
2051     break;}
2052 case 130:
2053 #line 774 "./awk.y"
2054 { yyval.nodeval = node(yyvsp[-2].nodeval, Node_times, yyvsp[0].nodeval); ;
2055     break;}
2056 case 131:
2057 #line 776 "./awk.y"
2058 { yyval.nodeval = node(yyvsp[-2].nodeval, Node_quotient, yyvsp[0].nodeval); ;
2059     break;}
2060 case 132:
2061 #line 778 "./awk.y"
2062 { yyval.nodeval = node(yyvsp[-2].nodeval, Node_mod, yyvsp[0].nodeval); ;
2063     break;}
2064 case 133:
2065 #line 780 "./awk.y"
2066 { yyval.nodeval = node(yyvsp[-2].nodeval, Node_plus, yyvsp[0].nodeval); ;
2067     break;}
2068 case 134:
2069 #line 782 "./awk.y"
2070 { yyval.nodeval = node(yyvsp[-2].nodeval, Node_minus, yyvsp[0].nodeval); ;
2071     break;}
2072 case 135:
2073 #line 784 "./awk.y"
2074 { yyval.nodeval = node(yyvsp[-1].nodeval, Node_postincrement, (NODE *) NULL); ;
2075     break;}
2076 case 136:
2077 #line 786 "./awk.y"
2078 { yyval.nodeval = node(yyvsp[-1].nodeval, Node_postdecrement, (NODE *) NULL); ;
2079     break;}
2080 case 137:
2081 #line 791 "./awk.y"
2082 { yyval.nodeval = node(yyvsp[0].nodeval, Node_not, (NODE *) NULL); ;
2083     break;}
2084 case 138:
2085 #line 793 "./awk.y"
2086 { yyval.nodeval = yyvsp[-1].nodeval; ;
2087     break;}
2088 case 139:
2089 #line 796 "./awk.y"
2090 { yyval.nodeval = snode(yyvsp[-1].nodeval, Node_builtin, (int) yyvsp[-3].lval); ;
2091     break;}
2092 case 140:
2093 #line 798 "./awk.y"
2094 { yyval.nodeval = snode(yyvsp[-1].nodeval, Node_builtin, (int) yyvsp[-3].lval); ;
2095     break;}
2096 case 141:
2097 #line 800 "./awk.y"
2098 {
2099                 if (do_lint)
2100                         warning("call of `length' without parentheses is not portable");
2101                 yyval.nodeval = snode((NODE *) NULL, Node_builtin, (int) yyvsp[0].lval);
2102                 if (do_posix)
2103                         warning("call of `length' without parentheses is deprecated by POSIX");
2104           ;
2105     break;}
2106 case 142:
2107 #line 808 "./awk.y"
2108 {
2109                 yyval.nodeval = node(yyvsp[-1].nodeval, Node_func_call, make_string(yyvsp[-3].sval, strlen(yyvsp[-3].sval)));
2110                 func_use(yyvsp[-3].sval, FUNC_USE);
2111                 param_sanity(yyvsp[-1].nodeval);
2112                 free(yyvsp[-3].sval);
2113           ;
2114     break;}
2115 case 144:
2116 #line 816 "./awk.y"
2117 { yyval.nodeval = node(yyvsp[0].nodeval, Node_preincrement, (NODE *) NULL); ;
2118     break;}
2119 case 145:
2120 #line 818 "./awk.y"
2121 { yyval.nodeval = node(yyvsp[0].nodeval, Node_predecrement, (NODE *) NULL); ;
2122     break;}
2123 case 146:
2124 #line 820 "./awk.y"
2125 { yyval.nodeval = yyvsp[0].nodeval; ;
2126     break;}
2127 case 147:
2128 #line 822 "./awk.y"
2129 { yyval.nodeval = yyvsp[0].nodeval; ;
2130     break;}
2131 case 148:
2132 #line 825 "./awk.y"
2133 {
2134                   if (yyvsp[0].nodeval->type == Node_val) {
2135                         yyvsp[0].nodeval->numbr = -(force_number(yyvsp[0].nodeval));
2136                         yyval.nodeval = yyvsp[0].nodeval;
2137                   } else
2138                         yyval.nodeval = node(yyvsp[0].nodeval, Node_unary_minus, (NODE *) NULL);
2139                 ;
2140     break;}
2141 case 149:
2142 #line 833 "./awk.y"
2143 {
2144                   /*
2145                    * was: $$ = $2
2146                    * POSIX semantics: force a conversion to numeric type
2147                    */
2148                   yyval.nodeval = node (make_number(0.0), Node_plus, yyvsp[0].nodeval);
2149                 ;
2150     break;}
2151 case 150:
2152 #line 844 "./awk.y"
2153 { yyval.nodeval = NULL; ;
2154     break;}
2155 case 151:
2156 #line 846 "./awk.y"
2157 { yyval.nodeval = yyvsp[0].nodeval; ;
2158     break;}
2159 case 152:
2160 #line 851 "./awk.y"
2161 { yyval.nodeval = variable(yyvsp[0].sval, CAN_FREE, Node_var); ;
2162     break;}
2163 case 153:
2164 #line 853 "./awk.y"
2165 {
2166                 if (yyvsp[-1].nodeval == NULL) {
2167                         fatal("invalid subscript expression");
2168                 } else if (yyvsp[-1].nodeval->rnode == NULL) {
2169                         yyval.nodeval = node(variable(yyvsp[-3].sval, CAN_FREE, Node_var_array), Node_subscript, yyvsp[-1].nodeval->lnode);
2170                         freenode(yyvsp[-1].nodeval);
2171                 } else
2172                         yyval.nodeval = node(variable(yyvsp[-3].sval, CAN_FREE, Node_var_array), Node_subscript, yyvsp[-1].nodeval);
2173                 ;
2174     break;}
2175 case 154:
2176 #line 863 "./awk.y"
2177 { yyval.nodeval = node(yyvsp[0].nodeval, Node_field_spec, (NODE *) NULL); ;
2178     break;}
2179 case 156:
2180 #line 871 "./awk.y"
2181 { yyerrok; ;
2182     break;}
2183 case 157:
2184 #line 875 "./awk.y"
2185 { yyerrok; ;
2186     break;}
2187 case 160:
2188 #line 884 "./awk.y"
2189 { yyerrok; want_assign = FALSE; ;
2190     break;}
2191 case 161:
2192 #line 887 "./awk.y"
2193 { yyerrok; ;
2194     break;}
2195 }
2196    /* the action file gets copied in in place of this dollarsign */
2197 #line 498 "/usr/share/bison.simple"
2198 \f
2199   yyvsp -= yylen;
2200   yyssp -= yylen;
2201 #ifdef YYLSP_NEEDED
2202   yylsp -= yylen;
2203 #endif
2204
2205 #if YYDEBUG != 0
2206   if (yydebug)
2207     {
2208       short *ssp1 = yyss - 1;
2209       fprintf (stderr, "state stack now");
2210       while (ssp1 != yyssp)
2211         fprintf (stderr, " %d", *++ssp1);
2212       fprintf (stderr, "\n");
2213     }
2214 #endif
2215
2216   *++yyvsp = yyval;
2217
2218 #ifdef YYLSP_NEEDED
2219   yylsp++;
2220   if (yylen == 0)
2221     {
2222       yylsp->first_line = yylloc.first_line;
2223       yylsp->first_column = yylloc.first_column;
2224       yylsp->last_line = (yylsp-1)->last_line;
2225       yylsp->last_column = (yylsp-1)->last_column;
2226       yylsp->text = 0;
2227     }
2228   else
2229     {
2230       yylsp->last_line = (yylsp+yylen-1)->last_line;
2231       yylsp->last_column = (yylsp+yylen-1)->last_column;
2232     }
2233 #endif
2234
2235   /* Now "shift" the result of the reduction.
2236      Determine what state that goes to,
2237      based on the state we popped back to
2238      and the rule number reduced by.  */
2239
2240   yyn = yyr1[yyn];
2241
2242   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
2243   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2244     yystate = yytable[yystate];
2245   else
2246     yystate = yydefgoto[yyn - YYNTBASE];
2247
2248   goto yynewstate;
2249
2250 yyerrlab:   /* here on detecting error */
2251
2252   if (! yyerrstatus)
2253     /* If not already recovering from an error, report this error.  */
2254     {
2255       ++yynerrs;
2256
2257 #ifdef YYERROR_VERBOSE
2258       yyn = yypact[yystate];
2259
2260       if (yyn > YYFLAG && yyn < YYLAST)
2261         {
2262           int size = 0;
2263           char *msg;
2264           int x, count;
2265
2266           count = 0;
2267           /* Start X at -yyn if nec to avoid negative indexes in yycheck.  */
2268           for (x = (yyn < 0 ? -yyn : 0);
2269                x < (sizeof(yytname) / sizeof(char *)); x++)
2270             if (yycheck[x + yyn] == x)
2271               size += strlen(yytname[x]) + 15, count++;
2272           msg = (char *) malloc(size + 15);
2273           if (msg != 0)
2274             {
2275               strcpy(msg, "parse error");
2276
2277               if (count < 5)
2278                 {
2279                   count = 0;
2280                   for (x = (yyn < 0 ? -yyn : 0);
2281                        x < (sizeof(yytname) / sizeof(char *)); x++)
2282                     if (yycheck[x + yyn] == x)
2283                       {
2284                         strcat(msg, count == 0 ? ", expecting `" : " or `");
2285                         strcat(msg, yytname[x]);
2286                         strcat(msg, "'");
2287                         count++;
2288                       }
2289                 }
2290               yyerror(msg);
2291               free(msg);
2292             }
2293           else
2294             yyerror ("parse error; also virtual memory exceeded");
2295         }
2296       else
2297 #endif /* YYERROR_VERBOSE */
2298         yyerror("parse error");
2299     }
2300
2301   goto yyerrlab1;
2302 yyerrlab1:   /* here on error raised explicitly by an action */
2303
2304   if (yyerrstatus == 3)
2305     {
2306       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
2307
2308       /* return failure if at end of input */
2309       if (yychar == YYEOF)
2310         YYABORT;
2311
2312 #if YYDEBUG != 0
2313       if (yydebug)
2314         fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
2315 #endif
2316
2317       yychar = YYEMPTY;
2318     }
2319
2320   /* Else will try to reuse lookahead token
2321      after shifting the error token.  */
2322
2323   yyerrstatus = 3;              /* Each real token shifted decrements this */
2324
2325   goto yyerrhandle;
2326
2327 yyerrdefault:  /* current state does not do anything special for the error token. */
2328
2329 #if 0
2330   /* This is wrong; only states that explicitly want error tokens
2331      should shift them.  */
2332   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
2333   if (yyn) goto yydefault;
2334 #endif
2335
2336 yyerrpop:   /* pop the current state because it cannot handle the error token */
2337
2338   if (yyssp == yyss) YYABORT;
2339   yyvsp--;
2340   yystate = *--yyssp;
2341 #ifdef YYLSP_NEEDED
2342   yylsp--;
2343 #endif
2344
2345 #if YYDEBUG != 0
2346   if (yydebug)
2347     {
2348       short *ssp1 = yyss - 1;
2349       fprintf (stderr, "Error: state stack now");
2350       while (ssp1 != yyssp)
2351         fprintf (stderr, " %d", *++ssp1);
2352       fprintf (stderr, "\n");
2353     }
2354 #endif
2355
2356 yyerrhandle:
2357
2358   yyn = yypact[yystate];
2359   if (yyn == YYFLAG)
2360     goto yyerrdefault;
2361
2362   yyn += YYTERROR;
2363   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
2364     goto yyerrdefault;
2365
2366   yyn = yytable[yyn];
2367   if (yyn < 0)
2368     {
2369       if (yyn == YYFLAG)
2370         goto yyerrpop;
2371       yyn = -yyn;
2372       goto yyreduce;
2373     }
2374   else if (yyn == 0)
2375     goto yyerrpop;
2376
2377   if (yyn == YYFINAL)
2378     YYACCEPT;
2379
2380 #if YYDEBUG != 0
2381   if (yydebug)
2382     fprintf(stderr, "Shifting error token, ");
2383 #endif
2384
2385   *++yyvsp = yylval;
2386 #ifdef YYLSP_NEEDED
2387   *++yylsp = yylloc;
2388 #endif
2389
2390   yystate = yyn;
2391   goto yynewstate;
2392 }
2393 #line 890 "./awk.y"
2394
2395
2396 struct token {
2397         const char *operator;           /* text to match */
2398         NODETYPE value;         /* node type */
2399         int class;              /* lexical class */
2400         unsigned flags;         /* # of args. allowed and compatability */
2401 #       define  ARGS    0xFF    /* 0, 1, 2, 3 args allowed (any combination */
2402 #       define  A(n)    (1<<(n))
2403 #       define  VERSION 0xFF00  /* old awk is zero */
2404 #       define  NOT_OLD         0x0100  /* feature not in old awk */
2405 #       define  NOT_POSIX       0x0200  /* feature not in POSIX */
2406 #       define  GAWKX           0x0400  /* gawk extension */
2407 #       define  RESX            0x0800  /* Bell Labs Research extension */
2408         NODE *(*ptr)();         /* function that implements this keyword */
2409 };
2410
2411
2412 /* Tokentab is sorted ascii ascending order, so it can be binary searched. */
2413 /* Function pointers come from declarations in awk.h. */
2414
2415 static struct token tokentab[] = {
2416 {"BEGIN",       Node_illegal,    LEX_BEGIN,     0,              0},
2417 {"END",         Node_illegal,    LEX_END,       0,              0},
2418 #ifdef ARRAYDEBUG
2419 {"adump",       Node_builtin,    LEX_BUILTIN,   GAWKX|A(1),     do_adump},
2420 #endif
2421 #ifdef BITOPS
2422 {"and",         Node_builtin,    LEX_BUILTIN,   GAWKX|A(2),     do_and},
2423 #endif /* BITOPS */
2424 {"atan2",       Node_builtin,    LEX_BUILTIN,   NOT_OLD|A(2),   do_atan2},
2425 {"break",       Node_K_break,    LEX_BREAK,     0,              0},
2426 {"close",       Node_builtin,    LEX_BUILTIN,   NOT_OLD|A(1),   do_close},
2427 #ifdef BITOPS
2428 {"compl",       Node_builtin,    LEX_BUILTIN,   GAWKX|A(1),     do_compl},
2429 #endif /* BITOPS */
2430 {"continue",    Node_K_continue, LEX_CONTINUE,  0,              0},
2431 {"cos",         Node_builtin,    LEX_BUILTIN,   NOT_OLD|A(1),   do_cos},
2432 {"delete",      Node_K_delete,   LEX_DELETE,    NOT_OLD,        0},
2433 {"do",          Node_K_do,       LEX_DO,        NOT_OLD,        0},
2434 {"else",        Node_illegal,    LEX_ELSE,      0,              0},
2435 {"exit",        Node_K_exit,     LEX_EXIT,      0,              0},
2436 {"exp",         Node_builtin,    LEX_BUILTIN,   A(1),           do_exp},
2437 {"fflush",      Node_builtin,    LEX_BUILTIN,   RESX|A(0)|A(1), do_fflush},
2438 {"for",         Node_K_for,      LEX_FOR,       0,              0},
2439 {"func",        Node_K_function, LEX_FUNCTION,  NOT_POSIX|NOT_OLD,      0},
2440 {"function",    Node_K_function, LEX_FUNCTION,  NOT_OLD,        0},
2441 {"gensub",      Node_builtin,    LEX_BUILTIN,   GAWKX|A(3)|A(4), do_gensub},
2442 {"getline",     Node_K_getline,  LEX_GETLINE,   NOT_OLD,        0},
2443 {"gsub",        Node_builtin,    LEX_BUILTIN,   NOT_OLD|A(2)|A(3), do_gsub},
2444 {"if",          Node_K_if,       LEX_IF,        0,              0},
2445 {"in",          Node_illegal,    LEX_IN,        0,              0},
2446 {"index",       Node_builtin,    LEX_BUILTIN,   A(2),           do_index},
2447 {"int",         Node_builtin,    LEX_BUILTIN,   A(1),           do_int},
2448 {"length",      Node_builtin,    LEX_LENGTH,    A(0)|A(1),      do_length},
2449 {"log",         Node_builtin,    LEX_BUILTIN,   A(1),           do_log},
2450 #ifdef BITOPS
2451 {"lshift",      Node_builtin,    LEX_BUILTIN,   GAWKX|A(2),     do_lshift},
2452 #endif /* BITOPS */
2453 {"match",       Node_builtin,    LEX_BUILTIN,   NOT_OLD|A(2),   do_match},
2454 {"next",        Node_K_next,     LEX_NEXT,      0,              0},
2455 {"nextfile",    Node_K_nextfile, LEX_NEXTFILE,  GAWKX,          0},
2456 #ifdef BITOPS
2457 {"or",          Node_builtin,    LEX_BUILTIN,   GAWKX|A(2),     do_or},
2458 #endif /* BITOPS */
2459 {"print",       Node_K_print,    LEX_PRINT,     0,              0},
2460 {"printf",      Node_K_printf,   LEX_PRINTF,    0,              0},
2461 {"rand",        Node_builtin,    LEX_BUILTIN,   NOT_OLD|A(0),   do_rand},
2462 {"return",      Node_K_return,   LEX_RETURN,    NOT_OLD,        0},
2463 #ifdef BITOPS
2464 {"rshift",      Node_builtin,    LEX_BUILTIN,   GAWKX|A(2),     do_rshift},
2465 #endif /* BITOPS */
2466 {"sin",         Node_builtin,    LEX_BUILTIN,   NOT_OLD|A(1),   do_sin},
2467 {"split",       Node_builtin,    LEX_BUILTIN,   A(2)|A(3),      do_split},
2468 {"sprintf",     Node_builtin,    LEX_BUILTIN,   0,              do_sprintf},
2469 {"sqrt",        Node_builtin,    LEX_BUILTIN,   A(1),           do_sqrt},
2470 {"srand",       Node_builtin,    LEX_BUILTIN,   NOT_OLD|A(0)|A(1), do_srand},
2471 #ifdef ARRAYDEBUG
2472 {"stopme",      Node_builtin,    LEX_BUILTIN,   GAWKX|A(0),     stopme},
2473 #endif
2474 {"strftime",    Node_builtin,    LEX_BUILTIN,   GAWKX|A(0)|A(1)|A(2), do_strftime},
2475 #ifdef BITOPS
2476 {"strtonum",    Node_builtin,    LEX_BUILTIN,   GAWKX|A(1),     do_strtonum},
2477 #endif /* BITOPS */
2478 {"sub",         Node_builtin,    LEX_BUILTIN,   NOT_OLD|A(2)|A(3), do_sub},
2479 {"substr",      Node_builtin,    LEX_BUILTIN,   A(2)|A(3),      do_substr},
2480 {"system",      Node_builtin,    LEX_BUILTIN,   NOT_OLD|A(1),   do_system},
2481 {"systime",     Node_builtin,    LEX_BUILTIN,   GAWKX|A(0),     do_systime},
2482 {"tolower",     Node_builtin,    LEX_BUILTIN,   NOT_OLD|A(1),   do_tolower},
2483 {"toupper",     Node_builtin,    LEX_BUILTIN,   NOT_OLD|A(1),   do_toupper},
2484 {"while",       Node_K_while,    LEX_WHILE,     0,              0},
2485 #ifdef BITOPS
2486 {"xor",         Node_builtin,    LEX_BUILTIN,   GAWKX|A(2),     do_xor},
2487 #endif /* BITOPS */
2488 };
2489
2490 /* yyerror --- print a syntax error message, show where */
2491
2492 #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
2493 static void
2494 yyerror(const char *m, ...)
2495 #else
2496 /* VARARGS0 */
2497 static void
2498 yyerror(va_alist)
2499 va_dcl
2500 #endif
2501 {
2502         va_list args;
2503         const char *mesg = NULL;
2504         register char *bp, *cp;
2505         char *scan;
2506         char buf[120];
2507         static char end_of_file_line[] = "(END OF FILE)";
2508
2509         errcount++;
2510         /* Find the current line in the input file */
2511         if (lexptr && lexeme) {
2512                 if (thisline == NULL) {
2513                         cp = lexeme;
2514                         if (*cp == '\n') {
2515                                 cp--;
2516                                 mesg = "unexpected newline";
2517                         }
2518                         for (; cp != lexptr_begin && *cp != '\n'; --cp)
2519                                 continue;
2520                         if (*cp == '\n')
2521                                 cp++;
2522                         thisline = cp;
2523                 }
2524                 /* NL isn't guaranteed */
2525                 bp = lexeme;
2526                 while (bp < lexend && *bp && *bp != '\n')
2527                         bp++;
2528         } else {
2529                 thisline = end_of_file_line;
2530                 bp = thisline + strlen(thisline);
2531         }
2532         msg("%.*s", (int) (bp - thisline), thisline);
2533         bp = buf;
2534         cp = buf + sizeof(buf) - 24;    /* 24 more than longest msg. input */
2535         if (lexptr != NULL) {
2536                 scan = thisline;
2537                 while (bp < cp && scan < lexeme)
2538                         if (*scan++ == '\t')
2539                                 *bp++ = '\t';
2540                         else
2541                                 *bp++ = ' ';
2542                 *bp++ = '^';
2543                 *bp++ = ' ';
2544         }
2545 #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
2546         va_start(args, m);
2547         if (mesg == NULL)
2548                 mesg = m;
2549 #else
2550         va_start(args);
2551         if (mesg == NULL)
2552                 mesg = va_arg(args, char *);
2553 #endif
2554         strcpy(bp, mesg);
2555         err("", buf, args);
2556         va_end(args);
2557 }
2558
2559 /* get_src_buf --- read the next buffer of source program */
2560
2561 static char *
2562 get_src_buf()
2563 {
2564         static int samefile = FALSE;
2565         static int nextfile = 0;
2566         static char *buf = NULL;
2567         static int fd;
2568         int n;
2569         register char *scan;
2570         static int len = 0;
2571         static int did_newline = FALSE;
2572         int newfile;
2573         struct stat sbuf;
2574
2575 #       define  SLOP    128     /* enough space to hold most source lines */
2576
2577 again:
2578         newfile = FALSE;
2579         if (nextfile > numfiles)
2580                 return NULL;
2581
2582         if (srcfiles[nextfile].stype == CMDLINE) {
2583                 if (len == 0) {
2584                         len = strlen(srcfiles[nextfile].val);
2585                         if (len == 0) {
2586                                 /*
2587                                  * Yet Another Special case:
2588                                  *      gawk '' /path/name
2589                                  * Sigh.
2590                                  */
2591                                 static int warned = FALSE;
2592
2593                                 if (do_lint && ! warned) {
2594                                         warned = TRUE;
2595                                         warning("empty program text on command line");
2596                                 }
2597                                 ++nextfile;
2598                                 goto again;
2599                         }
2600                         sourceline = 1;
2601                         lexptr = lexptr_begin = srcfiles[nextfile].val;
2602                         lexend = lexptr + len;
2603                 } else if (! did_newline && *(lexptr-1) != '\n') {
2604                         /*
2605                          * The following goop is to ensure that the source
2606                          * ends with a newline and that the entire current
2607                          * line is available for error messages.
2608                          */
2609                         int offset;
2610
2611                         did_newline = TRUE;
2612                         offset = lexptr - lexeme;
2613                         for (scan = lexeme; scan > lexptr_begin; scan--)
2614                                 if (*scan == '\n') {
2615                                         scan++;
2616                                         break;
2617                                 }
2618                         len = lexptr - scan;
2619                         emalloc(buf, char *, len+1, "get_src_buf");
2620                         memcpy(buf, scan, len);
2621                         thisline = buf;
2622                         lexptr = buf + len;
2623                         *lexptr = '\n';
2624                         lexeme = lexptr - offset;
2625                         lexptr_begin = buf;
2626                         lexend = lexptr + 1;
2627                 } else {
2628                         len = 0;
2629                         lexeme = lexptr = lexptr_begin = NULL;
2630                 }
2631                 if (lexptr == NULL && ++nextfile <= numfiles)
2632                         goto again;
2633                 return lexptr;
2634         }
2635         if (! samefile) {
2636                 source = srcfiles[nextfile].val;
2637                 if (source == NULL) {
2638                         if (buf != NULL) {
2639                                 free(buf);
2640                                 buf = NULL;
2641                         }
2642                         len = 0;
2643                         return lexeme = lexptr = lexptr_begin = NULL;
2644                 }
2645                 fd = pathopen(source);
2646                 if (fd <= INVALID_HANDLE) {
2647                         char *in;
2648
2649                         /* suppress file name and line no. in error mesg */
2650                         in = source;
2651                         source = NULL;
2652                         fatal("can't open source file \"%s\" for reading (%s)",
2653                                 in, strerror(errno));
2654                 }
2655                 len = optimal_bufsize(fd, & sbuf);
2656                 newfile = TRUE;
2657                 if (buf != NULL)
2658                         free(buf);
2659                 emalloc(buf, char *, len + SLOP, "get_src_buf");
2660                 lexptr_begin = buf + SLOP;
2661                 samefile = TRUE;
2662                 sourceline = 1;
2663         } else {
2664                 /*
2665                  * Here, we retain the current source line (up to length SLOP)
2666                  * in the beginning of the buffer that was overallocated above
2667                  */
2668                 int offset;
2669                 int linelen;
2670
2671                 offset = lexptr - lexeme;
2672                 for (scan = lexeme; scan > lexptr_begin; scan--)
2673                         if (*scan == '\n') {
2674                                 scan++;
2675                                 break;
2676                         }
2677                 linelen = lexptr - scan;
2678                 if (linelen > SLOP)
2679                         linelen = SLOP;
2680                 thisline = buf + SLOP - linelen;
2681                 memcpy(thisline, scan, linelen);
2682                 lexeme = buf + SLOP - offset;
2683                 lexptr_begin = thisline;
2684         }
2685         n = read(fd, buf + SLOP, len);
2686         if (n == -1)
2687                 fatal("can't read sourcefile \"%s\" (%s)",
2688                         source, strerror(errno));
2689         if (n == 0) {
2690                 if (newfile) {
2691                         static int warned = FALSE;
2692
2693                         if (do_lint && ! warned) {
2694                                 warned = TRUE;
2695                                 warning("source file `%s' is empty", source);
2696                         }
2697                 }
2698                 if (fileno(stdin) != fd)        /* safety */
2699                         close(fd);
2700                 samefile = FALSE;
2701                 nextfile++;
2702                 if (lexeme)
2703                         *lexeme = '\0';
2704                 len = 0;
2705                 goto again;
2706         }
2707         lexptr = buf + SLOP;
2708         lexend = lexptr + n;
2709         return buf;
2710 }
2711
2712 /* tokadd --- add a character to the token buffer */
2713
2714 #define tokadd(x) (*tok++ = (x), tok == tokend ? tokexpand() : tok)
2715
2716 /* tokexpand --- grow the token buffer */
2717
2718 char *
2719 tokexpand()
2720 {
2721         static int toksize = 60;
2722         int tokoffset;
2723
2724         tokoffset = tok - tokstart;
2725         toksize *= 2;
2726         if (tokstart != NULL)
2727                 erealloc(tokstart, char *, toksize, "tokexpand");
2728         else
2729                 emalloc(tokstart, char *, toksize, "tokexpand");
2730         tokend = tokstart + toksize;
2731         tok = tokstart + tokoffset;
2732         return tok;
2733 }
2734
2735 /* nextc --- get the next input character */
2736
2737 #if DEBUG
2738 int
2739 nextc()
2740 {
2741         int c;
2742
2743         if (lexptr && lexptr < lexend)
2744                 c = (int) (unsigned char) *lexptr++;
2745         else if (get_src_buf())
2746                 c = (int) (unsigned char) *lexptr++;
2747         else
2748                 c = EOF;
2749
2750         return c;
2751 }
2752 #else
2753 #define nextc() ((lexptr && lexptr < lexend) ? \
2754                     ((int) (unsigned char) *lexptr++) : \
2755                     (get_src_buf() ? ((int) (unsigned char) *lexptr++) : EOF) \
2756                 )
2757 #endif
2758
2759 /* pushback --- push a character back on the input */
2760
2761 #define pushback() (lexptr && lexptr > lexptr_begin ? lexptr-- : lexptr)
2762
2763 /* allow_newline --- allow newline after &&, ||, ? and : */
2764
2765 static void
2766 allow_newline()
2767 {
2768         int c;
2769
2770         for (;;) {
2771                 c = nextc();
2772                 if (c == EOF)
2773                         break;
2774                 if (c == '#') {
2775                         while ((c = nextc()) != '\n' && c != EOF)
2776                                 continue;
2777                         if (c == EOF)
2778                                 break;
2779                 }
2780                 if (c == '\n')
2781                         sourceline++;
2782                 if (! isspace(c)) {
2783                         pushback();
2784                         break;
2785                 }
2786         }
2787 }
2788
2789 /* yylex --- Read the input and turn it into tokens. */
2790
2791 static int
2792 yylex()
2793 {
2794         register int c, c1;
2795         int seen_e = FALSE;             /* These are for numbers */
2796         int seen_point = FALSE;
2797         int esc_seen;           /* for literal strings */
2798         int low, mid, high;
2799         static int did_newline = FALSE;
2800         char *tokkey;
2801         static int lasttok = 0, eof_warned = FALSE;
2802         int inhex = FALSE;
2803
2804         if (nextc() == EOF) {
2805                 if (lasttok != NEWLINE) {
2806                         lasttok = NEWLINE;
2807                         if (do_lint && ! eof_warned) {
2808                                 warning("source file does not end in newline");
2809                                 eof_warned = TRUE;
2810                         }
2811                         return NEWLINE; /* fake it */
2812                 }
2813                 return 0;
2814         }
2815         pushback();
2816 #ifdef OS2
2817         /*
2818          * added for OS/2's extproc feature of cmd.exe
2819          * (like #! in BSD sh)
2820          */
2821         if (strncasecmp(lexptr, "extproc ", 8) == 0) {
2822                 while (*lexptr && *lexptr != '\n')
2823                         lexptr++;
2824         }
2825 #endif
2826         lexeme = lexptr;
2827         thisline = NULL;
2828         if (want_regexp) {
2829                 int in_brack = 0;       /* count brackets, [[:alnum:]] allowed */
2830                 /*
2831                  * Counting brackets is non-trivial. [[] is ok,
2832                  * and so is [\]], with a point being that /[/]/ as a regexp
2833                  * constant has to work.
2834                  *
2835                  * Do not count [ or ] if either one is preceded by a \.
2836                  * A `[' should be counted if
2837                  *  a) it is the first one so far (in_brack == 0)
2838                  *  b) it is the `[' in `[:'
2839                  * A ']' should be counted if not preceded by a \, since
2840                  * it is either closing `:]' or just a plain list.
2841                  * According to POSIX, []] is how you put a ] into a set.
2842                  * Try to handle that too.
2843                  *
2844                  * The code for \ handles \[ and \].
2845                  */
2846
2847                 want_regexp = FALSE;
2848                 tok = tokstart;
2849                 for (;;) {
2850                         c = nextc();
2851                         switch (c) {
2852                         case '[':
2853                                 /* one day check for `.' and `=' too */
2854                                 if ((c1 = nextc()) == ':' || in_brack == 0)
2855                                         in_brack++;
2856                                 pushback();
2857                                 break;
2858                         case ']':
2859                                 if (tokstart[0] == '['
2860                                     && (tok == tokstart + 1
2861                                         || (tok == tokstart + 2
2862                                             && tokstart[1] == '^')))
2863                                         /* do nothing */;
2864                                 else
2865                                         in_brack--;
2866                                 break;
2867                         case '\\':
2868                                 if ((c = nextc()) == EOF) {
2869                                         yyerror("unterminated regexp ends with \\ at end of file");
2870                                         return lasttok = REGEXP; /* kludge */
2871                                 } else if (c == '\n') {
2872                                         sourceline++;
2873                                         continue;
2874                                 } else {
2875                                         tokadd('\\');
2876                                         tokadd(c);
2877                                         continue;
2878                                 }
2879                                 break;
2880                         case '/':       /* end of the regexp */
2881                                 if (in_brack > 0)
2882                                         break;
2883
2884                                 pushback();
2885                                 tokadd('\0');
2886                                 yylval.sval = tokstart;
2887                                 return lasttok = REGEXP;
2888                         case '\n':
2889                                 pushback();
2890                                 yyerror("unterminated regexp");
2891                                 return lasttok = REGEXP;        /* kludge */
2892                         case EOF:
2893                                 yyerror("unterminated regexp at end of file");
2894                                 return lasttok = REGEXP;        /* kludge */
2895                         }
2896                         tokadd(c);
2897                 }
2898         }
2899 retry:
2900         while ((c = nextc()) == ' ' || c == '\t')
2901                 continue;
2902
2903         lexeme = lexptr ? lexptr - 1 : lexptr;
2904         thisline = NULL;
2905         tok = tokstart;
2906         yylval.nodetypeval = Node_illegal;
2907
2908         switch (c) {
2909         case EOF:
2910                 if (lasttok != NEWLINE) {
2911                         lasttok = NEWLINE;
2912                         if (do_lint && ! eof_warned) {
2913                                 warning("source file does not end in newline");
2914                                 eof_warned = TRUE;
2915                         }
2916                         return NEWLINE; /* fake it */
2917                 }
2918                 return 0;
2919
2920         case '\n':
2921                 sourceline++;
2922                 return lasttok = NEWLINE;
2923
2924         case '#':               /* it's a comment */
2925                 while ((c = nextc()) != '\n') {
2926                         if (c == EOF) {
2927                                 if (lasttok != NEWLINE) {
2928                                         lasttok = NEWLINE;
2929                                         if (do_lint && ! eof_warned) {
2930                                                 warning(
2931                                 "source file does not end in newline");
2932                                                 eof_warned = TRUE;
2933                                         }
2934                                         return NEWLINE; /* fake it */
2935                                 }
2936                                 return 0;
2937                         }
2938                 }
2939                 sourceline++;
2940                 return lasttok = NEWLINE;
2941
2942         case '\\':
2943 #ifdef RELAXED_CONTINUATION
2944                 /*
2945                  * This code puports to allow comments and/or whitespace
2946                  * after the `\' at the end of a line used for continuation.
2947                  * Use it at your own risk. We think it's a bad idea, which
2948                  * is why it's not on by default.
2949                  */
2950                 if (! do_traditional) {
2951                         /* strip trailing white-space and/or comment */
2952                         while ((c = nextc()) == ' ' || c == '\t')
2953                                 continue;
2954                         if (c == '#') {
2955                                 if (do_lint)
2956                                         warning(
2957                 "use of `\\ #...' line continuation is not portable");
2958                                 while ((c = nextc()) != '\n')
2959                                         if (c == EOF)
2960                                                 break;
2961                         }
2962                         pushback();
2963                 }
2964 #endif /* RELAXED_CONTINUATION */
2965                 if (nextc() == '\n') {
2966                         sourceline++;
2967                         goto retry;
2968                 } else {
2969                         yyerror("backslash not last character on line");
2970                         exit(1);
2971                 }
2972                 break;
2973
2974         case '$':
2975                 want_assign = TRUE;
2976                 return lasttok = '$';
2977
2978         case ':':
2979         case '?':
2980                 allow_newline();
2981                 return lasttok = c;
2982
2983         case ')':
2984         case '(':       
2985         case ';':
2986         case '{':
2987         case ',':
2988                 want_assign = FALSE;
2989                 /* fall through */
2990         case '[':
2991         case ']':
2992                 return lasttok = c;
2993
2994         case '*':
2995                 if ((c = nextc()) == '=') {
2996                         yylval.nodetypeval = Node_assign_times;
2997                         return lasttok = ASSIGNOP;
2998                 } else if (do_posix) {
2999                         pushback();
3000                         return lasttok = '*';
3001                 } else if (c == '*') {
3002                         /* make ** and **= aliases for ^ and ^= */
3003                         static int did_warn_op = FALSE, did_warn_assgn = FALSE;
3004
3005                         if (nextc() == '=') {
3006                                 if (do_lint && ! did_warn_assgn) {
3007                                         did_warn_assgn = TRUE;
3008                                         warning("**= is not allowed by POSIX");
3009                                         warning("operator `**=' is not supported in old awk");
3010                                 }
3011                                 yylval.nodetypeval = Node_assign_exp;
3012                                 return ASSIGNOP;
3013                         } else {
3014                                 pushback();
3015                                 if (do_lint && ! did_warn_op) {
3016                                         did_warn_op = TRUE;
3017                                         warning("** is not allowed by POSIX");
3018                                         warning("operator `**' is not supported in old awk");
3019                                 }
3020                                 return lasttok = '^';
3021                         }
3022                 }
3023                 pushback();
3024                 return lasttok = '*';
3025
3026         case '/':
3027                 if (want_assign) {
3028                         if (nextc() == '=') {
3029                                 yylval.nodetypeval = Node_assign_quotient;
3030                                 return lasttok = ASSIGNOP;
3031                         }
3032                         pushback();
3033                 }
3034                 return lasttok = '/';
3035
3036         case '%':
3037                 if (nextc() == '=') {
3038                         yylval.nodetypeval = Node_assign_mod;
3039                         return lasttok = ASSIGNOP;
3040                 }
3041                 pushback();
3042                 return lasttok = '%';
3043
3044         case '^':
3045         {
3046                 static int did_warn_op = FALSE, did_warn_assgn = FALSE;
3047
3048                 if (nextc() == '=') {
3049                         if (do_lint && ! did_warn_assgn) {
3050                                 did_warn_assgn = TRUE;
3051                                 warning("operator `^=' is not supported in old awk");
3052                         }
3053                         yylval.nodetypeval = Node_assign_exp;
3054                         return lasttok = ASSIGNOP;
3055                 }
3056                 pushback();
3057                 if (do_lint && ! did_warn_op) {
3058                         did_warn_op = TRUE;
3059                         warning("operator `^' is not supported in old awk");
3060                 }
3061                 return lasttok = '^';
3062         }
3063
3064         case '+':
3065                 if ((c = nextc()) == '=') {
3066                         yylval.nodetypeval = Node_assign_plus;
3067                         return lasttok = ASSIGNOP;
3068                 }
3069                 if (c == '+')
3070                         return lasttok = INCREMENT;
3071                 pushback();
3072                 return lasttok = '+';
3073
3074         case '!':
3075                 if ((c = nextc()) == '=') {
3076                         yylval.nodetypeval = Node_notequal;
3077                         return lasttok = RELOP;
3078                 }
3079                 if (c == '~') {
3080                         yylval.nodetypeval = Node_nomatch;
3081                         want_assign = FALSE;
3082                         return lasttok = MATCHOP;
3083                 }
3084                 pushback();
3085                 return lasttok = '!';
3086
3087         case '<':
3088                 if (nextc() == '=') {
3089                         yylval.nodetypeval = Node_leq;
3090                         return lasttok = RELOP;
3091                 }
3092                 yylval.nodetypeval = Node_less;
3093                 pushback();
3094                 return lasttok = '<';
3095
3096         case '=':
3097                 if (nextc() == '=') {
3098                         yylval.nodetypeval = Node_equal;
3099                         return lasttok = RELOP;
3100                 }
3101                 yylval.nodetypeval = Node_assign;
3102                 pushback();
3103                 return lasttok = ASSIGNOP;
3104
3105         case '>':
3106                 if ((c = nextc()) == '=') {
3107                         yylval.nodetypeval = Node_geq;
3108                         return lasttok = RELOP;
3109                 } else if (c == '>') {
3110                         yylval.nodetypeval = Node_redirect_append;
3111                         return lasttok = APPEND_OP;
3112                 }
3113                 yylval.nodetypeval = Node_greater;
3114                 pushback();
3115                 return lasttok = '>';
3116
3117         case '~':
3118                 yylval.nodetypeval = Node_match;
3119                 want_assign = FALSE;
3120                 return lasttok = MATCHOP;
3121
3122         case '}':
3123                 /*
3124                  * Added did newline stuff.  Easier than
3125                  * hacking the grammar.
3126                  */
3127                 if (did_newline) {
3128                         did_newline = FALSE;
3129                         return lasttok = c;
3130                 }
3131                 did_newline++;
3132                 --lexptr;       /* pick up } next time */
3133                 return lasttok = NEWLINE;
3134
3135         case '"':
3136                 esc_seen = FALSE;
3137                 while ((c = nextc()) != '"') {
3138                         if (c == '\n') {
3139                                 pushback();
3140                                 yyerror("unterminated string");
3141                                 exit(1);
3142                         }
3143                         if (c == '\\') {
3144                                 c = nextc();
3145                                 if (c == '\n') {
3146                                         sourceline++;
3147                                         continue;
3148                                 }
3149                                 esc_seen = TRUE;
3150                                 tokadd('\\');
3151                         }
3152                         if (c == EOF) {
3153                                 pushback();
3154                                 yyerror("unterminated string");
3155                                 exit(1);
3156                         }
3157                         tokadd(c);
3158                 }
3159                 yylval.nodeval = make_str_node(tokstart,
3160                                         tok - tokstart, esc_seen ? SCAN : 0);
3161                 yylval.nodeval->flags |= PERM;
3162                 return lasttok = YSTRING;
3163
3164         case '-':
3165                 if ((c = nextc()) == '=') {
3166                         yylval.nodetypeval = Node_assign_minus;
3167                         return lasttok = ASSIGNOP;
3168                 }
3169                 if (c == '-')
3170                         return lasttok = DECREMENT;
3171                 pushback();
3172                 return lasttok = '-';
3173
3174         case '.':
3175                 c = nextc();
3176                 pushback();
3177                 if (! isdigit(c))
3178                         return lasttok = '.';
3179                 else
3180                         c = '.';
3181                 /* FALL THROUGH */
3182         case '0':
3183         case '1':
3184         case '2':
3185         case '3':
3186         case '4':
3187         case '5':
3188         case '6':
3189         case '7':
3190         case '8':
3191         case '9':
3192                 /* It's a number */
3193                 for (;;) {
3194                         int gotnumber = FALSE;
3195
3196                         tokadd(c);
3197                         switch (c) {
3198 #ifdef BITOPS
3199                         case 'x':
3200                         case 'X':
3201                                 if (do_traditional)
3202                                         goto done;
3203                                 if (tok == tokstart + 2)
3204                                         inhex = TRUE;
3205                                 break;
3206 #endif /* BITOTS */
3207                         case '.':
3208                                 if (seen_point) {
3209                                         gotnumber = TRUE;
3210                                         break;
3211                                 }
3212                                 seen_point = TRUE;
3213                                 break;
3214                         case 'e':
3215                         case 'E':
3216                                 if (inhex)
3217                                         break;
3218                                 if (seen_e) {
3219                                         gotnumber = TRUE;
3220                                         break;
3221                                 }
3222                                 seen_e = TRUE;
3223                                 if ((c = nextc()) == '-' || c == '+')
3224                                         tokadd(c);
3225                                 else
3226                                         pushback();
3227                                 break;
3228 #ifdef BITOPS
3229                         case 'a':
3230                         case 'A':
3231                         case 'b':
3232                         case 'B':
3233                         case 'c':
3234                         case 'C':
3235                         case 'D':
3236                         case 'd':
3237                         case 'f':
3238                         case 'F':
3239                                 if (do_traditional || ! inhex)
3240                                         goto done;
3241                                 /* fall through */
3242 #endif
3243                         case '0':
3244                         case '1':
3245                         case '2':
3246                         case '3':
3247                         case '4':
3248                         case '5':
3249                         case '6':
3250                         case '7':
3251                         case '8':
3252                         case '9':
3253                                 break;
3254                         default:
3255                         done:
3256                                 gotnumber = TRUE;
3257                         }
3258                         if (gotnumber)
3259                                 break;
3260                         c = nextc();
3261                 }
3262                 if (c != EOF)
3263                         pushback();
3264                 else if (do_lint && ! eof_warned) {
3265                         warning("source file does not end in newline");
3266                         eof_warned = TRUE;
3267                 }
3268                 tokadd('\0');
3269 #ifdef BITOPS
3270                 if (! do_traditional && isnondecimal(tokstart))
3271                         yylval.nodeval = make_number(nondec2awknum(tokstart, strlen(tokstart)));
3272                 else
3273 #endif /* BITOPS */
3274                 yylval.nodeval = make_number(atof(tokstart));
3275                 yylval.nodeval->flags |= PERM;
3276                 return lasttok = YNUMBER;
3277
3278         case '&':
3279                 if ((c = nextc()) == '&') {
3280                         yylval.nodetypeval = Node_and;
3281                         allow_newline();
3282                         want_assign = FALSE;
3283                         return lasttok = LEX_AND;
3284                 }
3285                 pushback();
3286                 return lasttok = '&';
3287
3288         case '|':
3289                 if ((c = nextc()) == '|') {
3290                         yylval.nodetypeval = Node_or;
3291                         allow_newline();
3292                         want_assign = FALSE;
3293                         return lasttok = LEX_OR;
3294                 }
3295                 pushback();
3296                 return lasttok = '|';
3297         }
3298
3299         if (c != '_' && ! isalpha(c)) {
3300                 yyerror("Invalid char '%c' in expression\n", c);
3301                 exit(1);
3302         }
3303
3304         /* it's some type of name-type-thing.  Find its length. */
3305         tok = tokstart;
3306         while (is_identchar(c)) {
3307                 tokadd(c);
3308                 c = nextc();
3309         }
3310         tokadd('\0');
3311         emalloc(tokkey, char *, tok - tokstart, "yylex");
3312         memcpy(tokkey, tokstart, tok - tokstart);
3313         if (c != EOF)
3314                 pushback();
3315         else if (do_lint && ! eof_warned) {
3316                 warning("source file does not end in newline");
3317                 eof_warned = TRUE;
3318         }
3319
3320         /* See if it is a special token. */
3321         low = 0;
3322         high = (sizeof(tokentab) / sizeof(tokentab[0])) - 1;
3323         while (low <= high) {
3324                 int i;
3325
3326                 mid = (low + high) / 2;
3327                 c = *tokstart - tokentab[mid].operator[0];
3328                 i = c ? c : strcmp(tokstart, tokentab[mid].operator);
3329
3330                 if (i < 0)              /* token < mid */
3331                         high = mid - 1;
3332                 else if (i > 0)         /* token > mid */
3333                         low = mid + 1;
3334                 else {
3335                         if (do_lint) {
3336                                 if (tokentab[mid].flags & GAWKX)
3337                                         warning("%s() is a gawk extension",
3338                                                 tokentab[mid].operator);
3339                                 if (tokentab[mid].flags & RESX)
3340                                         warning("%s() is a Bell Labs extension",
3341                                                 tokentab[mid].operator);
3342                                 if (tokentab[mid].flags & NOT_POSIX)
3343                                         warning("POSIX does not allow %s",
3344                                                 tokentab[mid].operator);
3345                         }
3346                         if (do_lint_old && (tokentab[mid].flags & NOT_OLD))
3347                                 warning("%s is not supported in old awk",
3348                                                 tokentab[mid].operator);
3349                         if ((do_traditional && (tokentab[mid].flags & GAWKX))
3350                             || (do_posix && (tokentab[mid].flags & NOT_POSIX)))
3351                                 break;
3352                         if (tokentab[mid].class == LEX_BUILTIN
3353                             || tokentab[mid].class == LEX_LENGTH
3354                            )
3355                                 yylval.lval = mid;
3356                         else
3357                                 yylval.nodetypeval = tokentab[mid].value;
3358
3359                         free(tokkey);
3360                         return lasttok = tokentab[mid].class;
3361                 }
3362         }
3363
3364         yylval.sval = tokkey;
3365         if (*lexptr == '(')
3366                 return lasttok = FUNC_CALL;
3367         else {
3368                 want_assign = TRUE;
3369                 return lasttok = NAME;
3370         }
3371 }
3372
3373 /* node_common --- common code for allocating a new node */
3374
3375 static NODE *
3376 node_common(op)
3377 NODETYPE op;
3378 {
3379         register NODE *r;
3380
3381         getnode(r);
3382         r->type = op;
3383         r->flags = MALLOC;
3384         /* if lookahead is NL, lineno is 1 too high */
3385         if (lexeme && *lexeme == '\n')
3386                 r->source_line = sourceline - 1;
3387         else
3388                 r->source_line = sourceline;
3389         r->source_file = source;
3390         return r;
3391 }
3392
3393 /* node --- allocates a node with defined lnode and rnode. */
3394
3395 NODE *
3396 node(left, op, right)
3397 NODE *left, *right;
3398 NODETYPE op;
3399 {
3400         register NODE *r;
3401
3402         r = node_common(op);
3403         r->lnode = left;
3404         r->rnode = right;
3405         return r;
3406 }
3407
3408 /* snode ---    allocate a node with defined subnode and proc for builtin
3409                 functions. Checks for arg. count and supplies defaults where
3410                 possible. */
3411
3412 static NODE *
3413 snode(subn, op, idx)
3414 NODETYPE op;
3415 int idx;
3416 NODE *subn;
3417 {
3418         register NODE *r;
3419         register NODE *n;
3420         int nexp = 0;
3421         int args_allowed;
3422
3423         r = node_common(op);
3424
3425         /* traverse expression list to see how many args. given */
3426         for (n = subn; n != NULL; n = n->rnode) {
3427                 nexp++;
3428                 if (nexp > 3)
3429                         break;
3430         }
3431
3432         /* check against how many args. are allowed for this builtin */
3433         args_allowed = tokentab[idx].flags & ARGS;
3434         if (args_allowed && (args_allowed & A(nexp)) == 0)
3435                 fatal("%s() cannot have %d argument%c",
3436                         tokentab[idx].operator, nexp, nexp == 1 ? ' ' : 's');
3437
3438         r->proc = tokentab[idx].ptr;
3439
3440         /* special case processing for a few builtins */
3441         /*
3442          * FIXME: go through these to make sure that everything done
3443          *        here is really right. Move anything that's not into
3444          *        the corresponding routine.
3445          */
3446         if (nexp == 0 && r->proc == do_length) {
3447                 subn = node(node(make_number(0.0), Node_field_spec, (NODE *) NULL),
3448                             Node_expression_list,
3449                             (NODE *) NULL);
3450         } else if (r->proc == do_match) {
3451                 if (subn->rnode->lnode->type != Node_regex)
3452                         subn->rnode->lnode = mk_rexp(subn->rnode->lnode);
3453         } else if (r->proc == do_sub || r->proc == do_gsub) {
3454                 if (subn->lnode->type != Node_regex)
3455                         subn->lnode = mk_rexp(subn->lnode);
3456                 if (nexp == 2)
3457                         append_right(subn, node(node(make_number(0.0),
3458                                                      Node_field_spec,
3459                                                      (NODE *) NULL),
3460                                                 Node_expression_list,
3461                                                 (NODE *) NULL));
3462                 else if (subn->rnode->rnode->lnode->type == Node_val) {
3463                         if (do_lint)
3464                                 warning("string literal as last arg of substitute");
3465                 } else if (! isassignable(subn->rnode->rnode->lnode))
3466                         yyerror("%s third parameter is not a changeable object",
3467                                 r->proc == do_sub ? "sub" : "gsub");
3468         } else if (r->proc == do_gensub) {
3469                 if (subn->lnode->type != Node_regex)
3470                         subn->lnode = mk_rexp(subn->lnode);
3471                 if (nexp == 3)
3472                         append_right(subn, node(node(make_number(0.0),
3473                                                      Node_field_spec,
3474                                                      (NODE *) NULL),
3475                                                 Node_expression_list,
3476                                                 (NODE *) NULL));
3477         } else if (r->proc == do_split) {
3478                 if (nexp == 2)
3479                         append_right(subn,
3480                             node(FS_node, Node_expression_list, (NODE *) NULL));
3481                 n = subn->rnode->rnode->lnode;
3482                 if (n->type != Node_regex)
3483                         subn->rnode->rnode->lnode = mk_rexp(n);
3484                 if (nexp == 2)
3485                         subn->rnode->rnode->lnode->re_flags |= FS_DFLT;
3486         }
3487
3488         r->subnode = subn;
3489         return r;
3490 }
3491
3492 /*
3493  * mkrangenode:
3494  * This allocates a Node_line_range node with defined condpair and
3495  * zeroes the trigger word to avoid the temptation of assuming that calling
3496  * 'node( foo, Node_line_range, 0)' will properly initialize 'triggered'. 
3497  * Otherwise like node().
3498  */
3499
3500 static NODE *
3501 mkrangenode(cpair)
3502 NODE *cpair;
3503 {
3504         register NODE *r;
3505
3506         getnode(r);
3507         r->type = Node_line_range;
3508         r->condpair = cpair;
3509         r->triggered = FALSE;
3510         return r;
3511 }
3512
3513 /* make_for_loop --- build a for loop */
3514
3515 static NODE *
3516 make_for_loop(init, cond, incr)
3517 NODE *init, *cond, *incr;
3518 {
3519         register FOR_LOOP_HEADER *r;
3520         NODE *n;
3521
3522         emalloc(r, FOR_LOOP_HEADER *, sizeof(FOR_LOOP_HEADER), "make_for_loop");
3523         getnode(n);
3524         n->type = Node_illegal;
3525         r->init = init;
3526         r->cond = cond;
3527         r->incr = incr;
3528         n->sub.nodep.r.hd = r;
3529         return n;
3530 }
3531
3532 /* dup_parms --- return TRUE if there are duplicate parameters */
3533
3534 static int
3535 dup_parms(func)
3536 NODE *func;
3537 {
3538         register NODE *np;
3539         char *fname, **names;
3540         int count, i, j, dups;
3541         NODE *params;
3542
3543         if (func == NULL)       /* error earlier */
3544                 return TRUE;
3545
3546         fname = func->param;
3547         count = func->param_cnt;
3548         params = func->rnode;
3549
3550         if (count == 0)         /* no args, no problem */
3551                 return FALSE;
3552
3553         if (params == NULL)     /* error earlier */
3554                 return TRUE;
3555
3556         emalloc(names, char **, count * sizeof(char *), "dup_parms");
3557
3558         i = 0;
3559         for (np = params; np != NULL; np = np->rnode) {
3560                 if (np->param == NULL) { /* error earlier, give up, go home */
3561                         free(names);
3562                         return TRUE;
3563                 }
3564                 names[i++] = np->param;
3565         }
3566
3567         dups = 0;
3568         for (i = 1; i < count; i++) {
3569                 for (j = 0; j < i; j++) {
3570                         if (strcmp(names[i], names[j]) == 0) {
3571                                 dups++;
3572                                 error(
3573         "function `%s': parameter #%d, `%s', duplicates parameter #%d",
3574                                         fname, i+1, names[j], j+1);
3575                         }
3576                 }
3577         }
3578
3579         free(names);
3580         return (dups > 0 ? TRUE : FALSE);
3581 }
3582
3583 /*
3584  * install:
3585  * Install a name in the symbol table, even if it is already there.
3586  * Caller must check against redefinition if that is desired. 
3587  */
3588
3589 NODE *
3590 install(name, value)
3591 char *name;
3592 NODE *value;
3593 {
3594         register NODE *hp;
3595         register size_t len;
3596         register int bucket;
3597
3598         len = strlen(name);
3599         bucket = hash(name, len, (unsigned long) HASHSIZE);
3600         getnode(hp);
3601         hp->type = Node_hashnode;
3602         hp->hnext = variables[bucket];
3603         variables[bucket] = hp;
3604         hp->hlength = len;
3605         hp->hvalue = value;
3606         hp->hname = name;
3607         hp->hvalue->vname = name;
3608         return hp->hvalue;
3609 }
3610
3611 /* lookup --- find the most recent hash node for name installed by install */
3612
3613 NODE *
3614 lookup(name)
3615 const char *name;
3616 {
3617         register NODE *bucket;
3618         register size_t len;
3619
3620         len = strlen(name);
3621         for (bucket = variables[hash(name, len, (unsigned long) HASHSIZE)];
3622                         bucket != NULL; bucket = bucket->hnext)
3623                 if (bucket->hlength == len && STREQN(bucket->hname, name, len))
3624                         return bucket->hvalue;
3625
3626         return NULL;
3627 }
3628
3629 /*
3630  * append_right:
3631  * Add new to the rightmost branch of LIST.  This uses n^2 time, so we make
3632  * a simple attempt at optimizing it.
3633  */
3634
3635 static NODE *
3636 append_right(list, new)
3637 NODE *list, *new;
3638 {
3639         register NODE *oldlist;
3640         static NODE *savefront = NULL, *savetail = NULL;
3641
3642         if (list == NULL || new == NULL)
3643                 return list;
3644
3645         oldlist = list;
3646         if (savefront == oldlist) {
3647                 savetail = savetail->rnode = new;
3648                 return oldlist;
3649         } else
3650                 savefront = oldlist;
3651         while (list->rnode != NULL)
3652                 list = list->rnode;
3653         savetail = list->rnode = new;
3654         return oldlist;
3655 }
3656
3657 /*
3658  * func_install:
3659  * check if name is already installed;  if so, it had better have Null value,
3660  * in which case def is added as the value. Otherwise, install name with def
3661  * as value. 
3662  */
3663
3664 static void
3665 func_install(params, def)
3666 NODE *params;
3667 NODE *def;
3668 {
3669         NODE *r;
3670         NODE *n;
3671
3672         /* check for function foo(foo) { ... }.  bleh. */
3673         for (n = params->rnode; n != NULL; n = n->rnode) {
3674                 if (strcmp(n->param, params->param) == 0)
3675                         fatal("function `%s': can't use function name as parameter name",
3676                                         params->param); 
3677         }
3678
3679         pop_params(params->rnode);
3680         pop_var(params, FALSE);
3681         r = lookup(params->param);
3682         if (r != NULL) {
3683                 fatal("function name `%s' previously defined", params->param);
3684         } else
3685                 (void) install(params->param, node(params, Node_func, def));
3686
3687         func_use(params->param, FUNC_DEFINE);
3688 }
3689
3690 /* pop_var --- remove a variable from the symbol table */
3691
3692 static void
3693 pop_var(np, freeit)
3694 NODE *np;
3695 int freeit;
3696 {
3697         register NODE *bucket, **save;
3698         register size_t len;
3699         char *name;
3700
3701         name = np->param;
3702         len = strlen(name);
3703         save = &(variables[hash(name, len, (unsigned long) HASHSIZE)]);
3704         for (bucket = *save; bucket != NULL; bucket = bucket->hnext) {
3705                 if (len == bucket->hlength && STREQN(bucket->hname, name, len)) {
3706                         *save = bucket->hnext;
3707                         freenode(bucket);
3708                         if (freeit)
3709                                 free(np->param);
3710                         return;
3711                 }
3712                 save = &(bucket->hnext);
3713         }
3714 }
3715
3716 /* pop_params --- remove list of function parameters from symbol table */
3717
3718 /*
3719  * pop parameters out of the symbol table. do this in reverse order to
3720  * avoid reading freed memory if there were duplicated parameters.
3721  */
3722 static void
3723 pop_params(params)
3724 NODE *params;
3725 {
3726         if (params == NULL)
3727                 return;
3728         pop_params(params->rnode);
3729         pop_var(params, TRUE);
3730 }
3731
3732 /* make_param --- make NAME into a function parameter */
3733
3734 static NODE *
3735 make_param(name)
3736 char *name;
3737 {
3738         NODE *r;
3739
3740         getnode(r);
3741         r->type = Node_param_list;
3742         r->rnode = NULL;
3743         r->param = name;
3744         r->param_cnt = param_counter++;
3745         return (install(name, r));
3746 }
3747
3748 static struct fdesc {
3749         char *name;
3750         short used;
3751         short defined;
3752         struct fdesc *next;
3753 } *ftable[HASHSIZE];
3754
3755 /* func_use --- track uses and definitions of functions */
3756
3757 static void
3758 func_use(name, how)
3759 char *name;
3760 enum defref how;
3761 {
3762         struct fdesc *fp;
3763         int len;
3764         int ind;
3765
3766         len = strlen(name);
3767         ind = hash(name, len, HASHSIZE);
3768
3769         for (fp = ftable[ind]; fp != NULL; fp = fp->next) {
3770                 if (strcmp(fp->name, name) == 0) {
3771                         if (how == FUNC_DEFINE)
3772                                 fp->defined++;
3773                         else
3774                                 fp->used++;
3775                         return;
3776                 }
3777         }
3778
3779         /* not in the table, fall through to allocate a new one */
3780
3781         emalloc(fp, struct fdesc *, sizeof(struct fdesc), "func_use");
3782         memset(fp, '\0', sizeof(struct fdesc));
3783         emalloc(fp->name, char *, len + 1, "func_use");
3784         strcpy(fp->name, name);
3785         if (how == FUNC_DEFINE)
3786                 fp->defined++;
3787         else
3788                 fp->used++;
3789         fp->next = ftable[ind];
3790         ftable[ind] = fp;
3791 }
3792
3793 /* check_funcs --- verify functions that are called but not defined */
3794
3795 static void
3796 check_funcs()
3797 {
3798         struct fdesc *fp, *next;
3799         int i;
3800
3801         for (i = 0; i < HASHSIZE; i++) {
3802                 for (fp = ftable[i]; fp != NULL; fp = fp->next) {
3803 #ifdef REALLYMEAN
3804                         /* making this the default breaks old code. sigh. */
3805                         if (fp->defined == 0) {
3806                                 error(
3807                 "function `%s' called but never defined", fp->name);
3808                                 errcount++;
3809                         }
3810 #else
3811                         if (do_lint && fp->defined == 0)
3812                                 warning(
3813                 "function `%s' called but never defined", fp->name);
3814 #endif
3815                         if (do_lint && fp->used == 0) {
3816                                 warning("function `%s' defined but never called",
3817                                         fp->name);
3818                         }
3819                 }
3820         }
3821
3822         /* now let's free all the memory */
3823         for (i = 0; i < HASHSIZE; i++) {
3824                 for (fp = ftable[i]; fp != NULL; fp = next) {
3825                         next = fp->next;
3826                         free(fp->name);
3827                         free(fp);
3828                 }
3829         }
3830 }
3831
3832 /* param_sanity --- look for parameters that are regexp constants */
3833
3834 static void
3835 param_sanity(arglist)
3836 NODE *arglist;
3837 {
3838         NODE *argp, *arg;
3839         int i;
3840
3841         for (i = 1, argp = arglist; argp != NULL; argp = argp->rnode, i++) {
3842                 arg = argp->lnode;
3843                 if (arg->type == Node_regex)
3844                         warning("regexp constant for parameter #%d yields boolean value", i);
3845         }
3846 }
3847
3848 /* variable --- make sure NAME is in the symbol table */
3849
3850 NODE *
3851 variable(name, can_free, type)
3852 char *name;
3853 int can_free;
3854 NODETYPE type;
3855 {
3856         register NODE *r;
3857         static int env_loaded = FALSE;
3858
3859         if (! env_loaded && STREQ(name, "ENVIRON")) {
3860                 load_environ();
3861                 env_loaded = TRUE;
3862         }
3863         if ((r = lookup(name)) == NULL)
3864                 r = install(name, node(Nnull_string, type, (NODE *) NULL));
3865         else if (can_free)
3866                 free(name);
3867         return r;
3868 }
3869
3870 /* mk_rexp --- make a regular expression constant */
3871
3872 static NODE *
3873 mk_rexp(exp)
3874 NODE *exp;
3875 {
3876         NODE *n;
3877
3878         if (exp->type == Node_regex)
3879                 return exp;
3880
3881         getnode(n);
3882         n->type = Node_regex;
3883         n->re_exp = exp;
3884         n->re_text = NULL;
3885         n->re_reg = NULL;
3886         n->re_flags = 0;
3887         n->re_cnt = 1;
3888         return n;
3889 }
3890
3891 /* isnoeffect --- when used as a statement, has no side effects */
3892
3893 /*
3894  * To be completely general, we should recursively walk the parse
3895  * tree, to make sure that all the subexpressions also have no effect.
3896  * Instead, we just weaken the actual warning that's printed, up above
3897  * in the grammar.
3898  */
3899
3900 static int
3901 isnoeffect(type)
3902 NODETYPE type;
3903 {
3904         switch (type) {
3905         case Node_times:
3906         case Node_quotient:
3907         case Node_mod:
3908         case Node_plus:
3909         case Node_minus:
3910         case Node_subscript:
3911         case Node_concat:
3912         case Node_exp:
3913         case Node_unary_minus:
3914         case Node_field_spec:
3915         case Node_and:
3916         case Node_or:
3917         case Node_equal:
3918         case Node_notequal:
3919         case Node_less:
3920         case Node_greater:
3921         case Node_leq:
3922         case Node_geq:
3923         case Node_match:
3924         case Node_nomatch:
3925         case Node_not:
3926         case Node_val:
3927         case Node_in_array:
3928         case Node_NF:
3929         case Node_NR:
3930         case Node_FNR:
3931         case Node_FS:
3932         case Node_RS:
3933         case Node_FIELDWIDTHS:
3934         case Node_IGNORECASE:
3935         case Node_OFS:
3936         case Node_ORS:
3937         case Node_OFMT:
3938         case Node_CONVFMT:
3939                 return TRUE;
3940         default:
3941                 break;  /* keeps gcc -Wall happy */
3942         }
3943
3944         return FALSE;
3945 }
3946
3947 /* isassignable --- can this node be assigned to? */
3948
3949 static int
3950 isassignable(n)
3951 register NODE *n;
3952 {
3953         switch (n->type) {
3954         case Node_var:
3955         case Node_FIELDWIDTHS:
3956         case Node_RS:
3957         case Node_FS:
3958         case Node_FNR:
3959         case Node_NR:
3960         case Node_NF:
3961         case Node_IGNORECASE:
3962         case Node_OFMT:
3963         case Node_CONVFMT:
3964         case Node_ORS:
3965         case Node_OFS:
3966         case Node_field_spec:
3967         case Node_subscript:
3968                 return TRUE;
3969         case Node_param_list:
3970                 return ((n->flags & FUNC) == 0);  /* ok if not func name */
3971         default:
3972                 break;  /* keeps gcc -Wall happy */
3973         }
3974         return FALSE;
3975 }
3976
3977 /* for debugging */
3978 NODE *
3979 stopme(tree)
3980 NODE *tree;
3981 {
3982         return tmp_number((AWKNUM) 0.0);
3983 }