do not delete regex.c
[platform/upstream/gawk.git] / awkgram.c
1 /* A Bison parser, made by GNU Bison 3.0.2.  */
2
3 /* Bison implementation for Yacc-like parsers in C
4
5    Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
6
7    This program is free software: you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation, either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 /* As a special exception, you may create a larger work that contains
21    part or all of the Bison parser skeleton and distribute that work
22    under terms of your choice, so long as that work isn't itself a
23    parser generator using the skeleton or a modified version thereof
24    as a parser skeleton.  Alternatively, if you modify or redistribute
25    the parser skeleton itself, you may (at your option) remove this
26    special exception, which will cause the skeleton and the resulting
27    Bison output files to be licensed under the GNU General Public
28    License without this special exception.
29
30    This special exception was added by the Free Software Foundation in
31    version 2.2 of Bison.  */
32
33 /* C LALR(1) parser skeleton written by Richard Stallman, by
34    simplifying the original so-called "semantic" parser.  */
35
36 /* All symbols defined below should begin with yy or YY, to avoid
37    infringing on user name space.  This should be done even for local
38    variables, as they might otherwise be expanded by user macros.
39    There are some unavoidable exceptions within include files to
40    define necessary library symbols; they are noted "INFRINGES ON
41    USER NAME SPACE" below.  */
42
43 /* Identify Bison output.  */
44 #define YYBISON 1
45
46 /* Bison version.  */
47 #define YYBISON_VERSION "3.0.2"
48
49 /* Skeleton name.  */
50 #define YYSKELETON_NAME "yacc.c"
51
52 /* Pure parsers.  */
53 #define YYPURE 0
54
55 /* Push parsers.  */
56 #define YYPUSH 0
57
58 /* Pull parsers.  */
59 #define YYPULL 1
60
61
62
63
64 /* Copy the first part of user declarations.  */
65 #line 26 "awkgram.y" /* yacc.c:339  */
66
67 #ifdef GAWKDEBUG
68 #define YYDEBUG 12
69 #endif
70
71 #include "awk.h"
72
73 #if defined(__STDC__) && __STDC__ < 1   /* VMS weirdness, maybe elsewhere */
74 #define signed /**/
75 #endif
76
77 static void yyerror(const char *m, ...) ATTRIBUTE_PRINTF_1;
78 static void error_ln(int line, const char *m, ...) ATTRIBUTE_PRINTF_2;
79 static void lintwarn_ln(int line, const char *m, ...) ATTRIBUTE_PRINTF_2;
80 static void warning_ln(int line, const char *m, ...) ATTRIBUTE_PRINTF_2;
81 static char *get_src_buf(void);
82 static int yylex(void);
83 int     yyparse(void); 
84 static INSTRUCTION *snode(INSTRUCTION *subn, INSTRUCTION *op);
85 static char **check_params(char *fname, int pcount, INSTRUCTION *list);
86 static int install_function(char *fname, INSTRUCTION *fi, INSTRUCTION *plist);
87 static NODE *mk_rexp(INSTRUCTION *exp);
88 static void param_sanity(INSTRUCTION *arglist);
89 static int parms_shadow(INSTRUCTION *pc, bool *shadow);
90 #ifndef NO_LINT
91 static int isnoeffect(OPCODE type);
92 #endif
93 static INSTRUCTION *make_assignable(INSTRUCTION *ip);
94 static void dumpintlstr(const char *str, size_t len);
95 static void dumpintlstr2(const char *str1, size_t len1, const char *str2, size_t len2);
96 static int include_source(INSTRUCTION *file);
97 static int load_library(INSTRUCTION *file);
98 static void next_sourcefile(void);
99 static char *tokexpand(void);
100 static bool is_deferred_variable(const char *name);
101
102 #define instruction(t)  bcalloc(t, 1, 0)
103
104 static INSTRUCTION *mk_program(void);
105 static INSTRUCTION *append_rule(INSTRUCTION *pattern, INSTRUCTION *action);
106 static INSTRUCTION *mk_function(INSTRUCTION *fi, INSTRUCTION *def);
107 static INSTRUCTION *mk_condition(INSTRUCTION *cond, INSTRUCTION *ifp, INSTRUCTION *true_branch,
108                 INSTRUCTION *elsep,     INSTRUCTION *false_branch);
109 static INSTRUCTION *mk_expression_list(INSTRUCTION *list, INSTRUCTION *s1);
110 static INSTRUCTION *mk_for_loop(INSTRUCTION *forp, INSTRUCTION *init, INSTRUCTION *cond,
111                 INSTRUCTION *incr, INSTRUCTION *body);
112 static void fix_break_continue(INSTRUCTION *list, INSTRUCTION *b_target, INSTRUCTION *c_target);
113 static INSTRUCTION *mk_binary(INSTRUCTION *s1, INSTRUCTION *s2, INSTRUCTION *op);
114 static INSTRUCTION *mk_boolean(INSTRUCTION *left, INSTRUCTION *right, INSTRUCTION *op);
115 static INSTRUCTION *mk_assignment(INSTRUCTION *lhs, INSTRUCTION *rhs, INSTRUCTION *op);
116 static INSTRUCTION *mk_getline(INSTRUCTION *op, INSTRUCTION *opt_var, INSTRUCTION *redir, int redirtype);
117 static NODE *make_regnode(int type, NODE *exp);
118 static int count_expressions(INSTRUCTION **list, bool isarg);
119 static INSTRUCTION *optimize_assignment(INSTRUCTION *exp);
120 static void add_lint(INSTRUCTION *list, LINTTYPE linttype);
121
122 static void process_deferred();
123
124 enum defref { FUNC_DEFINE, FUNC_USE, FUNC_EXT };
125 static void func_use(const char *name, enum defref how);
126 static void check_funcs(void);
127
128 static ssize_t read_one_line(int fd, void *buffer, size_t count);
129 static int one_line_close(int fd);
130
131 static bool want_source = false;
132 static bool want_regexp = false;        /* lexical scanning kludge */
133 static char *in_function;               /* parsing kludge */
134 static bool symtab_used = false;        /* program used SYMTAB */
135 static int rule = 0;
136
137 const char *const ruletab[] = {
138         "?",
139         "BEGIN",
140         "Rule",
141         "END",
142         "BEGINFILE",
143         "ENDFILE",
144 };
145
146 static bool in_print = false;   /* lexical scanning kludge for print */
147 static int in_parens = 0;       /* lexical scanning kludge for print */
148 static int sub_counter = 0;     /* array dimension counter for use in delete */
149 static char *lexptr = NULL;             /* pointer to next char during parsing */
150 static char *lexend;
151 static char *lexptr_begin;      /* keep track of where we were for error msgs */
152 static char *lexeme;            /* beginning of lexeme for debugging */
153 static bool lexeof;             /* seen EOF for current source? */  
154 static char *thisline = NULL;
155 static int in_braces = 0;       /* count braces for firstline, lastline in an 'action' */
156 static int lastline = 0;
157 static int firstline = 0;
158 static SRCFILE *sourcefile = NULL;      /* current program source */
159 static int lasttok = 0;
160 static bool eof_warned = false; /* GLOBAL: want warning for each file */
161 static int break_allowed;       /* kludge for break */
162 static int continue_allowed;    /* kludge for continue */
163
164 #define END_FILE        -1000
165 #define END_SRC         -2000
166
167 #define YYDEBUG_LEXER_TEXT (lexeme)
168 static char *tokstart = NULL;
169 static char *tok = NULL;
170 static char *tokend;
171 static int errcount = 0;
172
173 extern char *source;
174 extern int sourceline;
175 extern SRCFILE *srcfiles;
176 extern INSTRUCTION *rule_list;
177 extern int max_args;
178 extern NODE **args_array;
179
180 static INSTRUCTION *rule_block[sizeof(ruletab)];
181
182 static INSTRUCTION *ip_rec;
183 static INSTRUCTION *ip_newfile;
184 static INSTRUCTION *ip_atexit = NULL;
185 static INSTRUCTION *ip_end;
186 static INSTRUCTION *ip_endfile;
187 static INSTRUCTION *ip_beginfile;
188
189 static inline INSTRUCTION *list_create(INSTRUCTION *x);
190 static inline INSTRUCTION *list_append(INSTRUCTION *l, INSTRUCTION *x);
191 static inline INSTRUCTION *list_prepend(INSTRUCTION *l, INSTRUCTION *x);
192 static inline INSTRUCTION *list_merge(INSTRUCTION *l1, INSTRUCTION *l2);
193
194 extern double fmod(double x, double y);
195
196 #define YYSTYPE INSTRUCTION *
197
198 #define is_identchar(c)         (isalnum(c) || (c) == '_')
199
200 #line 201 "awkgram.c" /* yacc.c:339  */
201
202 # ifndef YY_NULLPTR
203 #  if defined __cplusplus && 201103L <= __cplusplus
204 #   define YY_NULLPTR nullptr
205 #  else
206 #   define YY_NULLPTR 0
207 #  endif
208 # endif
209
210 /* Enabling verbose error messages.  */
211 #ifdef YYERROR_VERBOSE
212 # undef YYERROR_VERBOSE
213 # define YYERROR_VERBOSE 1
214 #else
215 # define YYERROR_VERBOSE 0
216 #endif
217
218
219 /* Debug traces.  */
220 #ifndef YYDEBUG
221 # define YYDEBUG 0
222 #endif
223 #if YYDEBUG
224 extern int yydebug;
225 #endif
226
227 /* Token type.  */
228 #ifndef YYTOKENTYPE
229 # define YYTOKENTYPE
230   enum yytokentype
231   {
232     FUNC_CALL = 258,
233     NAME = 259,
234     REGEXP = 260,
235     FILENAME = 261,
236     YNUMBER = 262,
237     YSTRING = 263,
238     RELOP = 264,
239     IO_OUT = 265,
240     IO_IN = 266,
241     ASSIGNOP = 267,
242     ASSIGN = 268,
243     MATCHOP = 269,
244     CONCAT_OP = 270,
245     SUBSCRIPT = 271,
246     LEX_BEGIN = 272,
247     LEX_END = 273,
248     LEX_IF = 274,
249     LEX_ELSE = 275,
250     LEX_RETURN = 276,
251     LEX_DELETE = 277,
252     LEX_SWITCH = 278,
253     LEX_CASE = 279,
254     LEX_DEFAULT = 280,
255     LEX_WHILE = 281,
256     LEX_DO = 282,
257     LEX_FOR = 283,
258     LEX_BREAK = 284,
259     LEX_CONTINUE = 285,
260     LEX_PRINT = 286,
261     LEX_PRINTF = 287,
262     LEX_NEXT = 288,
263     LEX_EXIT = 289,
264     LEX_FUNCTION = 290,
265     LEX_BEGINFILE = 291,
266     LEX_ENDFILE = 292,
267     LEX_GETLINE = 293,
268     LEX_NEXTFILE = 294,
269     LEX_IN = 295,
270     LEX_AND = 296,
271     LEX_OR = 297,
272     INCREMENT = 298,
273     DECREMENT = 299,
274     LEX_BUILTIN = 300,
275     LEX_LENGTH = 301,
276     LEX_EOF = 302,
277     LEX_INCLUDE = 303,
278     LEX_EVAL = 304,
279     LEX_LOAD = 305,
280     NEWLINE = 306,
281     SLASH_BEFORE_EQUAL = 307,
282     UNARY = 308
283   };
284 #endif
285 /* Tokens.  */
286 #define FUNC_CALL 258
287 #define NAME 259
288 #define REGEXP 260
289 #define FILENAME 261
290 #define YNUMBER 262
291 #define YSTRING 263
292 #define RELOP 264
293 #define IO_OUT 265
294 #define IO_IN 266
295 #define ASSIGNOP 267
296 #define ASSIGN 268
297 #define MATCHOP 269
298 #define CONCAT_OP 270
299 #define SUBSCRIPT 271
300 #define LEX_BEGIN 272
301 #define LEX_END 273
302 #define LEX_IF 274
303 #define LEX_ELSE 275
304 #define LEX_RETURN 276
305 #define LEX_DELETE 277
306 #define LEX_SWITCH 278
307 #define LEX_CASE 279
308 #define LEX_DEFAULT 280
309 #define LEX_WHILE 281
310 #define LEX_DO 282
311 #define LEX_FOR 283
312 #define LEX_BREAK 284
313 #define LEX_CONTINUE 285
314 #define LEX_PRINT 286
315 #define LEX_PRINTF 287
316 #define LEX_NEXT 288
317 #define LEX_EXIT 289
318 #define LEX_FUNCTION 290
319 #define LEX_BEGINFILE 291
320 #define LEX_ENDFILE 292
321 #define LEX_GETLINE 293
322 #define LEX_NEXTFILE 294
323 #define LEX_IN 295
324 #define LEX_AND 296
325 #define LEX_OR 297
326 #define INCREMENT 298
327 #define DECREMENT 299
328 #define LEX_BUILTIN 300
329 #define LEX_LENGTH 301
330 #define LEX_EOF 302
331 #define LEX_INCLUDE 303
332 #define LEX_EVAL 304
333 #define LEX_LOAD 305
334 #define NEWLINE 306
335 #define SLASH_BEFORE_EQUAL 307
336 #define UNARY 308
337
338 /* Value type.  */
339 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
340 typedef int YYSTYPE;
341 # define YYSTYPE_IS_TRIVIAL 1
342 # define YYSTYPE_IS_DECLARED 1
343 #endif
344
345
346 extern YYSTYPE yylval;
347
348 int yyparse (void);
349
350
351
352 /* Copy the second part of user declarations.  */
353
354 #line 355 "awkgram.c" /* yacc.c:358  */
355
356 #ifdef short
357 # undef short
358 #endif
359
360 #ifdef YYTYPE_UINT8
361 typedef YYTYPE_UINT8 yytype_uint8;
362 #else
363 typedef unsigned char yytype_uint8;
364 #endif
365
366 #ifdef YYTYPE_INT8
367 typedef YYTYPE_INT8 yytype_int8;
368 #else
369 typedef signed char yytype_int8;
370 #endif
371
372 #ifdef YYTYPE_UINT16
373 typedef YYTYPE_UINT16 yytype_uint16;
374 #else
375 typedef unsigned short int yytype_uint16;
376 #endif
377
378 #ifdef YYTYPE_INT16
379 typedef YYTYPE_INT16 yytype_int16;
380 #else
381 typedef short int yytype_int16;
382 #endif
383
384 #ifndef YYSIZE_T
385 # ifdef __SIZE_TYPE__
386 #  define YYSIZE_T __SIZE_TYPE__
387 # elif defined size_t
388 #  define YYSIZE_T size_t
389 # elif ! defined YYSIZE_T
390 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
391 #  define YYSIZE_T size_t
392 # else
393 #  define YYSIZE_T unsigned int
394 # endif
395 #endif
396
397 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
398
399 #ifndef YY_
400 # if defined YYENABLE_NLS && YYENABLE_NLS
401 #  if ENABLE_NLS
402 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
403 #   define YY_(Msgid) dgettext ("bison-runtime", Msgid)
404 #  endif
405 # endif
406 # ifndef YY_
407 #  define YY_(Msgid) Msgid
408 # endif
409 #endif
410
411 #ifndef YY_ATTRIBUTE
412 # if (defined __GNUC__                                               \
413       && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__)))  \
414      || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
415 #  define YY_ATTRIBUTE(Spec) __attribute__(Spec)
416 # else
417 #  define YY_ATTRIBUTE(Spec) /* empty */
418 # endif
419 #endif
420
421 #ifndef YY_ATTRIBUTE_PURE
422 # define YY_ATTRIBUTE_PURE   YY_ATTRIBUTE ((__pure__))
423 #endif
424
425 #ifndef YY_ATTRIBUTE_UNUSED
426 # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
427 #endif
428
429 #if !defined _Noreturn \
430      && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
431 # if defined _MSC_VER && 1200 <= _MSC_VER
432 #  define _Noreturn __declspec (noreturn)
433 # else
434 #  define _Noreturn YY_ATTRIBUTE ((__noreturn__))
435 # endif
436 #endif
437
438 /* Suppress unused-variable warnings by "using" E.  */
439 #if ! defined lint || defined __GNUC__
440 # define YYUSE(E) ((void) (E))
441 #else
442 # define YYUSE(E) /* empty */
443 #endif
444
445 #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
446 /* Suppress an incorrect diagnostic about yylval being uninitialized.  */
447 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
448     _Pragma ("GCC diagnostic push") \
449     _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
450     _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
451 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
452     _Pragma ("GCC diagnostic pop")
453 #else
454 # define YY_INITIAL_VALUE(Value) Value
455 #endif
456 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
457 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
458 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
459 #endif
460 #ifndef YY_INITIAL_VALUE
461 # define YY_INITIAL_VALUE(Value) /* Nothing. */
462 #endif
463
464
465 #if ! defined yyoverflow || YYERROR_VERBOSE
466
467 /* The parser invokes alloca or malloc; define the necessary symbols.  */
468
469 # ifdef YYSTACK_USE_ALLOCA
470 #  if YYSTACK_USE_ALLOCA
471 #   ifdef __GNUC__
472 #    define YYSTACK_ALLOC __builtin_alloca
473 #   elif defined __BUILTIN_VA_ARG_INCR
474 #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
475 #   elif defined _AIX
476 #    define YYSTACK_ALLOC __alloca
477 #   elif defined _MSC_VER
478 #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
479 #    define alloca _alloca
480 #   else
481 #    define YYSTACK_ALLOC alloca
482 #    if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
483 #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
484       /* Use EXIT_SUCCESS as a witness for stdlib.h.  */
485 #     ifndef EXIT_SUCCESS
486 #      define EXIT_SUCCESS 0
487 #     endif
488 #    endif
489 #   endif
490 #  endif
491 # endif
492
493 # ifdef YYSTACK_ALLOC
494    /* Pacify GCC's 'empty if-body' warning.  */
495 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
496 #  ifndef YYSTACK_ALLOC_MAXIMUM
497     /* The OS might guarantee only one guard page at the bottom of the stack,
498        and a page size can be as small as 4096 bytes.  So we cannot safely
499        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
500        to allow for a few compiler-allocated temporary stack slots.  */
501 #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
502 #  endif
503 # else
504 #  define YYSTACK_ALLOC YYMALLOC
505 #  define YYSTACK_FREE YYFREE
506 #  ifndef YYSTACK_ALLOC_MAXIMUM
507 #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
508 #  endif
509 #  if (defined __cplusplus && ! defined EXIT_SUCCESS \
510        && ! ((defined YYMALLOC || defined malloc) \
511              && (defined YYFREE || defined free)))
512 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
513 #   ifndef EXIT_SUCCESS
514 #    define EXIT_SUCCESS 0
515 #   endif
516 #  endif
517 #  ifndef YYMALLOC
518 #   define YYMALLOC malloc
519 #   if ! defined malloc && ! defined EXIT_SUCCESS
520 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
521 #   endif
522 #  endif
523 #  ifndef YYFREE
524 #   define YYFREE free
525 #   if ! defined free && ! defined EXIT_SUCCESS
526 void free (void *); /* INFRINGES ON USER NAME SPACE */
527 #   endif
528 #  endif
529 # endif
530 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
531
532
533 #if (! defined yyoverflow \
534      && (! defined __cplusplus \
535          || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
536
537 /* A type that is properly aligned for any stack member.  */
538 union yyalloc
539 {
540   yytype_int16 yyss_alloc;
541   YYSTYPE yyvs_alloc;
542 };
543
544 /* The size of the maximum gap between one aligned stack and the next.  */
545 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
546
547 /* The size of an array large to enough to hold all stacks, each with
548    N elements.  */
549 # define YYSTACK_BYTES(N) \
550      ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
551       + YYSTACK_GAP_MAXIMUM)
552
553 # define YYCOPY_NEEDED 1
554
555 /* Relocate STACK from its old location to the new one.  The
556    local variables YYSIZE and YYSTACKSIZE give the old and new number of
557    elements in the stack, and YYPTR gives the new location of the
558    stack.  Advance YYPTR to a properly aligned location for the next
559    stack.  */
560 # define YYSTACK_RELOCATE(Stack_alloc, Stack)                           \
561     do                                                                  \
562       {                                                                 \
563         YYSIZE_T yynewbytes;                                            \
564         YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
565         Stack = &yyptr->Stack_alloc;                                    \
566         yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
567         yyptr += yynewbytes / sizeof (*yyptr);                          \
568       }                                                                 \
569     while (0)
570
571 #endif
572
573 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
574 /* Copy COUNT objects from SRC to DST.  The source and destination do
575    not overlap.  */
576 # ifndef YYCOPY
577 #  if defined __GNUC__ && 1 < __GNUC__
578 #   define YYCOPY(Dst, Src, Count) \
579       __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
580 #  else
581 #   define YYCOPY(Dst, Src, Count)              \
582       do                                        \
583         {                                       \
584           YYSIZE_T yyi;                         \
585           for (yyi = 0; yyi < (Count); yyi++)   \
586             (Dst)[yyi] = (Src)[yyi];            \
587         }                                       \
588       while (0)
589 #  endif
590 # endif
591 #endif /* !YYCOPY_NEEDED */
592
593 /* YYFINAL -- State number of the termination state.  */
594 #define YYFINAL  2
595 /* YYLAST -- Last index in YYTABLE.  */
596 #define YYLAST   1155
597
598 /* YYNTOKENS -- Number of terminals.  */
599 #define YYNTOKENS  75
600 /* YYNNTS -- Number of nonterminals.  */
601 #define YYNNTS  65
602 /* YYNRULES -- Number of rules.  */
603 #define YYNRULES  188
604 /* YYNSTATES -- Number of states.  */
605 #define YYNSTATES  335
606
607 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
608    by yylex, with out-of-bounds checking.  */
609 #define YYUNDEFTOK  2
610 #define YYMAXUTOK   308
611
612 #define YYTRANSLATE(YYX)                                                \
613   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
614
615 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
616    as returned by yylex, without out-of-bounds checking.  */
617 static const yytype_uint8 yytranslate[] =
618 {
619        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
620        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
621        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
622        2,     2,     2,    63,     2,     2,    66,    62,     2,     2,
623       67,    68,    60,    58,    55,    59,     2,    61,     2,     2,
624        2,     2,     2,     2,     2,     2,     2,     2,    54,    74,
625       56,     2,    57,    53,    69,     2,     2,     2,     2,     2,
626        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
627        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
628        2,    70,     2,    71,    65,     2,     2,     2,     2,     2,
629        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
630        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
631        2,     2,     2,    72,     2,    73,     2,     2,     2,     2,
632        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
633        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
634        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
635        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
636        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
637        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
638        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
639        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
640        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
641        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
642        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
643        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
644        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
645        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
646       15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
647       25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
648       35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
649       45,    46,    47,    48,    49,    50,    51,    52,    64
650 };
651
652 #if YYDEBUG
653   /* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
654 static const yytype_uint16 yyrline[] =
655 {
656        0,   200,   200,   202,   207,   208,   214,   226,   230,   241,
657      247,   252,   260,   268,   270,   275,   283,   285,   291,   292,
658      294,   320,   331,   342,   348,   357,   367,   369,   371,   377,
659      382,   383,   387,   406,   405,   439,   441,   446,   447,   460,
660      465,   466,   470,   472,   474,   481,   571,   613,   655,   768,
661      775,   782,   792,   801,   810,   819,   830,   846,   845,   869,
662      881,   881,   979,   979,  1012,  1042,  1048,  1049,  1055,  1056,
663     1063,  1068,  1080,  1094,  1096,  1104,  1109,  1111,  1119,  1121,
664     1130,  1131,  1139,  1144,  1144,  1155,  1159,  1167,  1168,  1171,
665     1173,  1178,  1179,  1188,  1189,  1194,  1199,  1205,  1207,  1209,
666     1216,  1217,  1223,  1224,  1229,  1231,  1236,  1238,  1246,  1251,
667     1260,  1267,  1269,  1271,  1287,  1297,  1304,  1306,  1311,  1313,
668     1315,  1323,  1325,  1330,  1332,  1337,  1339,  1341,  1391,  1393,
669     1395,  1397,  1399,  1401,  1403,  1405,  1428,  1433,  1438,  1463,
670     1469,  1471,  1473,  1475,  1477,  1479,  1484,  1488,  1520,  1522,
671     1528,  1534,  1547,  1548,  1549,  1554,  1559,  1563,  1567,  1582,
672     1595,  1600,  1636,  1654,  1655,  1661,  1662,  1667,  1669,  1676,
673     1693,  1710,  1712,  1719,  1724,  1732,  1742,  1754,  1763,  1767,
674     1771,  1775,  1779,  1783,  1786,  1788,  1792,  1796,  1800
675 };
676 #endif
677
678 #if YYDEBUG || YYERROR_VERBOSE || 0
679 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
680    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
681 static const char *const yytname[] =
682 {
683   "$end", "error", "$undefined", "FUNC_CALL", "NAME", "REGEXP",
684   "FILENAME", "YNUMBER", "YSTRING", "RELOP", "IO_OUT", "IO_IN", "ASSIGNOP",
685   "ASSIGN", "MATCHOP", "CONCAT_OP", "SUBSCRIPT", "LEX_BEGIN", "LEX_END",
686   "LEX_IF", "LEX_ELSE", "LEX_RETURN", "LEX_DELETE", "LEX_SWITCH",
687   "LEX_CASE", "LEX_DEFAULT", "LEX_WHILE", "LEX_DO", "LEX_FOR", "LEX_BREAK",
688   "LEX_CONTINUE", "LEX_PRINT", "LEX_PRINTF", "LEX_NEXT", "LEX_EXIT",
689   "LEX_FUNCTION", "LEX_BEGINFILE", "LEX_ENDFILE", "LEX_GETLINE",
690   "LEX_NEXTFILE", "LEX_IN", "LEX_AND", "LEX_OR", "INCREMENT", "DECREMENT",
691   "LEX_BUILTIN", "LEX_LENGTH", "LEX_EOF", "LEX_INCLUDE", "LEX_EVAL",
692   "LEX_LOAD", "NEWLINE", "SLASH_BEFORE_EQUAL", "'?'", "':'", "','", "'<'",
693   "'>'", "'+'", "'-'", "'*'", "'/'", "'%'", "'!'", "UNARY", "'^'", "'$'",
694   "'('", "')'", "'@'", "'['", "']'", "'{'", "'}'", "';'", "$accept",
695   "program", "rule", "source", "library", "pattern", "action", "func_name",
696   "lex_builtin", "function_prologue", "regexp", "$@1", "a_slash",
697   "statements", "statement_term", "statement", "non_compound_stmt", "$@2",
698   "simple_stmt", "$@3", "$@4", "opt_simple_stmt", "case_statements",
699   "case_statement", "case_value", "print", "print_expression_list",
700   "output_redir", "$@5", "if_statement", "nls", "opt_nls", "input_redir",
701   "opt_param_list", "param_list", "opt_exp", "opt_expression_list",
702   "expression_list", "exp", "assign_operator", "relop_or_less", "a_relop",
703   "common_exp", "simp_exp", "simp_exp_nc", "non_post_simp_exp",
704   "func_call", "direct_func_call", "opt_variable", "delete_subscript_list",
705   "delete_subscript", "delete_exp_list", "bracketed_exp_list", "subscript",
706   "subscript_list", "simple_variable", "variable", "opt_incdec", "l_brace",
707   "r_brace", "r_paren", "opt_semi", "semi", "colon", "comma", YY_NULLPTR
708 };
709 #endif
710
711 # ifdef YYPRINT
712 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
713    (internal) symbol number NUM (which must be that of a token).  */
714 static const yytype_uint16 yytoknum[] =
715 {
716        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
717      265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
718      275,   276,   277,   278,   279,   280,   281,   282,   283,   284,
719      285,   286,   287,   288,   289,   290,   291,   292,   293,   294,
720      295,   296,   297,   298,   299,   300,   301,   302,   303,   304,
721      305,   306,   307,    63,    58,    44,    60,    62,    43,    45,
722       42,    47,    37,    33,   308,    94,    36,    40,    41,    64,
723       91,    93,   123,   125,    59
724 };
725 # endif
726
727 #define YYPACT_NINF -273
728
729 #define yypact_value_is_default(Yystate) \
730   (!!((Yystate) == (-273)))
731
732 #define YYTABLE_NINF -104
733
734 #define yytable_value_is_error(Yytable_value) \
735   (!!((Yytable_value) == (-104)))
736
737   /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
738      STATE-NUM.  */
739 static const yytype_int16 yypact[] =
740 {
741     -273,   376,  -273,  -273,   -27,   -21,  -273,  -273,  -273,  -273,
742      157,  -273,  -273,    11,    11,    11,    -5,    -3,  -273,  -273,
743     -273,  1019,  1019,  -273,  1019,  1065,   821,   116,  -273,   -20,
744        1,  -273,  -273,    35,   758,   992,   252,   296,  -273,  -273,
745     -273,  -273,   233,   789,   821,  -273,     2,  -273,  -273,  -273,
746     -273,  -273,    63,    54,  -273,    69,  -273,  -273,  -273,   789,
747      789,   127,    87,   115,    87,    87,  1019,   131,  -273,  -273,
748       55,   295,    40,    47,  -273,    83,  -273,  -273,  -273,    35,
749     -273,    83,  -273,   151,  -273,  -273,  1019,   132,  1019,  1019,
750     1019,    83,  -273,  -273,  -273,  1019,   124,   252,  1019,  1019,
751     1019,  1019,  1019,  1019,  1019,  1019,  1019,  1019,  1019,  1019,
752     -273,  -273,  -273,  -273,   152,  1019,   100,    16,  1034,    37,
753     -273,  -273,  -273,    43,  1019,  -273,   100,   100,   295,  -273,
754     -273,  -273,  1019,    83,  -273,   137,   867,  -273,  -273,    75,
755      -19,  -273,    77,   -19,    35,  -273,   596,  -273,  -273,   123,
756     -273,   141,   175,  1098,  1019,   161,    11,   -26,   -26,    87,
757       87,    87,    87,   -26,   -26,    87,    87,    87,    87,  -273,
758     1034,  -273,  -273,  -273,  -273,   100,    65,   252,  -273,  -273,
759     1034,  -273,   132,  -273,  1034,  -273,  -273,  -273,  -273,  -273,
760      104,  -273,    26,   118,   119,    83,   121,   -19,   -19,  -273,
761     -273,   -19,  1019,   -19,    83,  -273,  -273,   -19,  -273,  -273,
762     1034,  -273,   117,    83,  1019,  1034,  -273,    83,  -273,   112,
763     -273,  1019,  1019,  -273,   188,  1019,  1019,   710,   900,  -273,
764     -273,  -273,   -19,  1034,  -273,  -273,  -273,   642,   596,    83,
765     -273,  -273,  1034,  -273,  -273,  -273,   295,   -19,   -21,   126,
766      295,   295,   169,   -13,  -273,   117,  -273,   821,   186,  -273,
767     -273,  -273,    83,  -273,  -273,    13,  -273,  -273,  -273,    83,
768       83,   139,   132,    83,    55,  -273,  -273,   710,  -273,  -273,
769        1,   710,  1019,   100,   743,   137,  1019,   192,  -273,  -273,
770      295,    83,   286,    83,   992,    83,    44,    83,   710,    83,
771      946,   710,  -273,   247,   154,  -273,   156,  -273,  -273,   946,
772      100,  -273,  -273,  -273,   226,   228,  -273,   154,  -273,    83,
773     -273,   100,    83,  -273,  -273,    83,  -273,    83,   710,  -273,
774      448,   710,  -273,   522,  -273
775 };
776
777   /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
778      Performed when YYTABLE does not specify something else to do.  Zero
779      means the default is an error.  */
780 static const yytype_uint8 yydefact[] =
781 {
782        2,     0,     1,     6,     0,   174,   156,   157,    21,    22,
783        0,    23,    24,   163,     0,     0,     0,   151,     5,    87,
784       36,     0,     0,    35,     0,     0,     0,     0,     3,     0,
785        0,   146,    33,     4,    19,   117,   125,   126,   128,   152,
786      160,   176,   153,     0,     0,   171,     0,   175,    27,    26,
787       30,    31,     0,     0,    28,    91,   164,   154,   155,     0,
788        0,     0,   159,   153,   158,   147,     0,   180,   153,   106,
789        0,   104,     0,     0,   161,    89,   186,     7,     8,    40,
790       37,    89,     9,     0,    88,   121,     0,     0,     0,     0,
791        0,    89,   122,   124,   123,     0,     0,   127,     0,     0,
792        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
793      119,   118,   136,   137,     0,     0,     0,     0,   104,     0,
794      173,   172,    29,     0,     0,   135,     0,     0,     0,   178,
795      179,   177,   107,    89,   183,     0,     0,   148,    14,     0,
796        0,    17,     0,     0,    90,   181,     0,    41,    34,   113,
797      114,   111,   112,     0,     0,   115,   163,   133,   134,   130,
798      131,   132,   129,   144,   145,   141,   142,   143,   140,   120,
799      110,   162,   170,    97,    95,     0,     0,    92,   149,   150,
800      108,   188,     0,   109,   105,    13,    10,    16,    11,    39,
801        0,    57,     0,     0,     0,    89,     0,     0,     0,    78,
802       79,     0,   100,     0,    89,    38,    51,     0,    60,    44,
803       65,    37,   184,    89,     0,    20,   139,    89,    98,     0,
804      138,     0,   100,    62,     0,     0,     0,     0,    66,    52,
805       53,    54,     0,   101,    55,   182,    59,     0,     0,    89,
806      185,    42,   116,    32,    99,    96,     0,     0,   165,     0,
807        0,     0,     0,   174,    67,     0,    56,     0,    82,    80,
808       43,    25,    89,    58,    63,     0,   167,   169,    64,    89,
809       89,     0,     0,    89,     0,    83,    61,     0,   166,   168,
810        0,     0,     0,     0,     0,    81,     0,    85,    68,    46,
811        0,    89,     0,    89,    84,    89,     0,    89,     0,    89,
812       66,     0,    70,     0,     0,    69,     0,    47,    48,    66,
813        0,    86,    73,    76,     0,     0,    77,     0,   187,    89,
814       45,     0,    89,    75,    74,    89,    37,    89,     0,    37,
815        0,     0,    50,     0,    49
816 };
817
818   /* YYPGOTO[NTERM-NUM].  */
819 static const yytype_int16 yypgoto[] =
820 {
821     -273,  -273,  -273,  -273,  -273,  -273,   208,  -273,  -273,  -273,
822      -64,  -273,  -273,  -202,    71,   -58,  -273,  -273,  -218,  -273,
823     -273,  -272,  -273,  -273,  -273,  -273,  -273,  -273,  -273,  -273,
824       50,    76,  -273,  -273,  -273,    19,   -54,   -23,    -1,  -273,
825     -273,  -273,   -44,    39,  -273,   224,  -273,   -11,    94,  -273,
826     -273,    -7,   -38,  -273,  -273,   -73,    -2,  -273,   -28,  -231,
827      -46,  -273,   -25,   -57,    85
828 };
829
830   /* YYDEFGOTO[NTERM-NUM].  */
831 static const yytype_int16 yydefgoto[] =
832 {
833       -1,     1,    28,   140,   143,    29,    77,    53,    54,    30,
834       31,    83,    32,   146,    78,   205,   206,   222,   207,   237,
835      248,   255,   296,   305,   317,   208,   258,   276,   286,   209,
836      144,   145,   125,   175,   176,   232,   116,   117,   210,   115,
837       94,    95,    35,    36,    37,    38,    39,    40,    55,   264,
838      265,   266,    45,    46,    47,    41,    42,   131,   211,   212,
839      137,   239,   213,   319,   136
840 };
841
842   /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
843      positive, shift that token.  If negative, reduce the rule whose
844      number is the opposite.  If YYTABLE_NINF, syntax error.  */
845 static const yytype_int16 yytable[] =
846 {
847       34,    80,    80,    70,    81,   126,   127,   260,   121,   238,
848      254,    56,    57,    58,   150,     5,    74,   132,   120,    63,
849       63,   119,    63,    68,   135,    71,  -103,   272,   310,   278,
850      223,    19,    19,    63,   100,   101,   102,   321,   132,   103,
851       43,   138,   118,   118,   173,   302,   139,   174,   141,    44,
852       74,    33,    75,   142,    76,    76,   132,    44,   118,   118,
853       62,    64,    59,    65,    60,   128,   218,  -103,   303,   304,
854      171,   133,    44,    75,    97,   320,   185,    25,   187,    79,
855      178,   179,   254,    44,  -103,   149,    84,   151,   152,   153,
856     -103,   254,   133,   224,   155,    19,    63,    63,    63,    63,
857       63,    63,    63,    63,    63,    63,    63,    63,   172,   220,
858      133,   -93,   122,   244,   170,    81,   245,   -89,    81,     4,
859      133,   123,    63,   134,   330,   124,   -12,   333,   -15,   217,
860        4,   180,    85,   -94,    19,   184,     5,   157,   158,   159,
861      160,   161,   162,   163,   164,   165,   166,   167,   168,   -12,
862       85,   -15,   103,   215,    56,    86,   148,   147,   112,   113,
863       48,    49,   156,   177,    72,   169,    73,   154,   134,   252,
864     -104,   221,    81,    81,   129,   130,    81,   182,    81,    92,
865       93,    87,    81,   259,    85,   225,   226,   240,   228,    86,
866       79,    76,   249,    79,   268,   271,   275,    92,    93,   283,
867      262,   233,    50,    51,   269,   270,   282,    81,   318,   181,
868      267,   186,   295,   242,   188,    87,    88,  -104,  -104,   287,
869      246,   233,    81,   289,   250,   251,    52,   267,   285,   204,
870      273,    92,    93,   323,   274,   324,   118,   291,    82,   316,
871      308,   247,   294,   311,   297,   110,   111,    79,    79,    67,
872      216,    79,   288,    79,   312,   313,    71,    79,   279,   293,
873      325,   219,     0,     0,   322,     0,     0,   299,   229,   230,
874      332,   227,   231,   334,   234,   327,   112,   113,   236,     0,
875      235,   290,    79,   292,    63,   114,     0,     0,     0,   241,
876        0,     0,    63,   243,     0,    85,     0,    79,     0,    20,
877       86,     0,     0,   256,    85,   314,   315,     0,    23,    86,
878       98,    99,   100,   101,   102,   261,     0,   103,   263,     0,
879        0,     0,     0,     0,     0,     0,    87,    88,    89,     0,
880        0,     0,     0,    97,     0,    87,    88,    89,   277,    90,
881        0,     0,    92,    93,     0,   280,   281,     0,    90,   284,
882        0,    92,    93,     0,   104,   105,   106,   107,   108,     0,
883       76,   109,     0,   134,     0,     0,     0,   298,     0,   300,
884        0,   301,   306,   307,     0,   309,     2,     3,     0,     4,
885        5,     0,     0,     6,     7,     0,     0,     0,     0,     0,
886        0,     0,     0,     8,     9,   326,     0,     0,   328,     0,
887        0,   329,     0,   331,     0,     0,     0,     0,     0,     0,
888        0,    10,    11,    12,    13,     0,     0,     0,     0,    14,
889       15,    16,    17,    18,     0,     0,     0,    19,    20,     0,
890        0,     0,     0,     0,    21,    22,     0,    23,     0,    24,
891        0,     0,    25,    26,     0,    27,     0,     0,   -18,   189,
892      -18,     4,     5,     0,     0,     6,     7,     0,     0,     0,
893        0,     0,     0,     0,     0,     0,     0,   190,     0,   191,
894      192,   193,   -72,   -72,   194,   195,   196,   197,   198,   199,
895      200,   201,   202,     0,     0,     0,    13,   203,     0,     0,
896        0,    14,    15,    16,    17,     0,     0,     0,     0,   -72,
897       20,     0,     0,     0,     0,     0,    21,    22,     0,    23,
898        0,    24,     0,     0,    25,    26,     0,    61,     0,     0,
899       75,   -72,    76,   189,     0,     4,     5,     0,     0,     6,
900        7,     0,     0,     0,     0,     0,     0,     0,     0,     0,
901        0,   190,     0,   191,   192,   193,   -71,   -71,   194,   195,
902      196,   197,   198,   199,   200,   201,   202,     0,     0,     0,
903       13,   203,     0,     0,     0,    14,    15,    16,    17,     0,
904        0,     0,     0,   -71,    20,     0,     0,     0,     0,     0,
905       21,    22,     0,    23,     0,    24,     0,     0,    25,    26,
906        0,    61,     0,     0,    75,   -71,    76,   189,     0,     4,
907        5,     0,     0,     6,     7,     0,     0,     0,     0,     0,
908        0,     0,     0,     0,     0,   190,     0,   191,   192,   193,
909        0,     0,   194,   195,   196,   197,   198,   199,   200,   201,
910      202,     0,     0,     0,    13,   203,     0,     0,     0,    14,
911       15,    16,    17,    69,     0,     4,     5,     0,    20,     6,
912        7,     0,  -102,     0,    21,    22,     0,    23,     0,    24,
913        0,     0,    25,    26,     0,    61,     0,     0,    75,   204,
914       76,     0,     0,     0,     0,     0,     0,     0,     0,     0,
915       13,     0,     0,     0,     0,    14,    15,    16,    17,     0,
916        0,     0,     0,  -102,    20,     0,     0,     0,     0,     0,
917       21,    22,     0,    23,     0,    24,     0,     0,    25,   257,
918     -102,    61,     0,     4,     5,     0,  -102,     6,     7,     0,
919        0,     0,     0,     0,     0,     0,     0,     0,     0,   190,
920        0,   191,   192,   193,     0,     0,   194,   195,   196,   197,
921      198,   199,   200,   201,   202,     0,     4,     5,    13,   203,
922        6,     7,     0,    14,    15,    16,    17,     0,     0,     0,
923        0,     0,    20,     0,     0,     0,     0,    85,    21,    22,
924        0,    23,    86,    24,     0,     0,    25,    26,     0,    61,
925        0,    13,    75,     0,    76,     0,    14,    15,    16,    17,
926       69,     0,     4,     5,     0,    20,     6,     7,    87,    88,
927       89,    21,    22,     0,    23,     0,    24,     0,     0,    25,
928       26,    90,    61,    91,    92,    93,     0,    76,     0,     0,
929        0,     0,    69,     0,     4,     5,     0,    13,     6,     7,
930        0,     0,    14,    15,    16,    17,     0,     0,     0,     0,
931        0,    20,     0,     0,     0,     0,     0,    21,    22,     0,
932       23,     0,    24,     0,     0,    25,    26,  -102,    61,    13,
933        0,     0,     0,     0,    14,    15,    16,    17,   183,     0,
934        4,     5,     0,    20,     6,     7,     0,     0,     0,    21,
935       22,     0,    23,     0,    24,     0,     0,    25,    26,     0,
936       61,     0,     0,     0,     0,     0,     0,     0,     0,     0,
937        0,     0,     0,     4,   253,    13,     0,     6,     7,     0,
938       14,    15,    16,    17,     0,     0,     0,     0,     0,    20,
939        0,     0,   192,     0,     0,    21,    22,     0,    23,     0,
940       24,   199,   200,    25,    26,     0,    61,     0,    13,     0,
941        0,     0,     0,    14,    15,    16,    17,     0,     0,     4,
942        5,     0,    20,     6,     7,     0,     0,     0,    21,    22,
943        0,    23,     0,    24,     0,     0,    25,    26,   192,    61,
944        0,     0,     0,     0,     0,     0,     0,   199,   200,     0,
945        0,     0,     0,     0,    13,     0,     0,     0,     0,    14,
946       15,    16,    17,     0,     0,     4,     5,     0,    20,     6,
947        7,     0,     0,    96,    21,    22,     0,    23,     0,    24,
948        0,     0,    25,    26,     0,    61,     0,     0,     0,     0,
949        0,     0,     4,     5,     0,     0,     6,     7,     0,     0,
950       13,     0,     0,     0,     0,    14,    15,    16,    17,     0,
951        0,     0,     0,    85,    20,     0,     0,     0,    86,     0,
952       21,    22,     0,    23,     0,    24,     0,    13,    25,    26,
953        0,    61,    14,    15,    16,    17,     0,     0,     4,     5,
954        0,    20,     6,     7,    87,    88,    89,    21,    22,     0,
955       23,     0,    24,     0,     0,    25,    26,    90,    61,     0,
956       92,    93,     0,     0,     0,     0,     0,     0,     0,     0,
957        0,     0,     0,     0,     0,     0,     0,    85,    14,    15,
958       16,    17,    86,     0,     0,     0,     0,    20,     0,     0,
959        0,     0,     0,    21,    22,     0,    23,     0,    24,     0,
960        0,    25,    66,     0,    61,     0,     0,     0,    87,    88,
961       89,     0,     0,     0,     0,     0,     0,     0,     0,     0,
962        0,    90,   214,     0,    92,    93
963 };
964
965 static const yytype_int16 yycheck[] =
966 {
967        1,    29,    30,    26,    29,    59,    60,   238,    46,   211,
968      228,    13,    14,    15,    87,     4,    27,     1,    16,    21,
969       22,    44,    24,    25,    70,    26,    10,    40,   300,    16,
970        4,    51,    51,    35,    60,    61,    62,   309,     1,    65,
971       67,     1,    43,    44,     1,     1,     6,     4,     1,    70,
972       61,     1,    72,     6,    74,    74,     1,    70,    59,    60,
973       21,    22,    67,    24,    67,    66,     1,    51,    24,    25,
974      116,    55,    70,    72,    35,   306,     1,    66,     1,    29,
975      126,   127,   300,    70,    68,    86,    51,    88,    89,    90,
976       74,   309,    55,    67,    95,    51,    98,    99,   100,   101,
977      102,   103,   104,   105,   106,   107,   108,   109,    71,   182,
978       55,    68,    49,     1,   115,   140,     4,    73,   143,     3,
979       55,    67,   124,    68,   326,    56,    51,   329,    51,   175,
980        3,   132,     9,    68,    51,   136,     4,    98,    99,   100,
981      101,   102,   103,   104,   105,   106,   107,   108,   109,    74,
982        9,    74,    65,   154,   156,    14,     5,    81,    43,    44,
983        3,     4,    38,   124,    48,    13,    50,    91,    68,   227,
984        9,    67,   197,   198,    43,    44,   201,    40,   203,    56,
985       57,    40,   207,   237,     9,    67,    67,   212,    67,    14,
986      140,    74,     4,   143,    68,    26,    10,    56,    57,   272,
987      246,   202,    45,    46,   250,   251,    67,   232,    54,   133,
988      248,   140,    20,   214,   143,    40,    41,    56,    57,   277,
989      221,   222,   247,   281,   225,   226,    69,   265,   274,    73,
990      255,    56,    57,     7,   257,     7,   237,   283,    30,   303,
991      298,   222,   286,   301,   290,    12,    13,   197,   198,    25,
992      156,   201,   280,   203,     7,     8,   257,   207,   265,   284,
993      317,   176,    -1,    -1,   310,    -1,    -1,   292,   197,   198,
994      328,   195,   201,   331,   203,   321,    43,    44,   207,    -1,
995      204,   282,   232,   284,   286,    52,    -1,    -1,    -1,   213,
996       -1,    -1,   294,   217,    -1,     9,    -1,   247,    -1,    52,
997       14,    -1,    -1,   232,     9,    58,    59,    -1,    61,    14,
998       58,    59,    60,    61,    62,   239,    -1,    65,   247,    -1,
999       -1,    -1,    -1,    -1,    -1,    -1,    40,    41,    42,    -1,
1000       -1,    -1,    -1,   294,    -1,    40,    41,    42,   262,    53,
1001       -1,    -1,    56,    57,    -1,   269,   270,    -1,    53,   273,
1002       -1,    56,    57,    -1,    58,    59,    60,    61,    62,    -1,
1003       74,    65,    -1,    68,    -1,    -1,    -1,   291,    -1,   293,
1004       -1,   295,   296,   297,    -1,   299,     0,     1,    -1,     3,
1005        4,    -1,    -1,     7,     8,    -1,    -1,    -1,    -1,    -1,
1006       -1,    -1,    -1,    17,    18,   319,    -1,    -1,   322,    -1,
1007       -1,   325,    -1,   327,    -1,    -1,    -1,    -1,    -1,    -1,
1008       -1,    35,    36,    37,    38,    -1,    -1,    -1,    -1,    43,
1009       44,    45,    46,    47,    -1,    -1,    -1,    51,    52,    -1,
1010       -1,    -1,    -1,    -1,    58,    59,    -1,    61,    -1,    63,
1011       -1,    -1,    66,    67,    -1,    69,    -1,    -1,    72,     1,
1012       74,     3,     4,    -1,    -1,     7,     8,    -1,    -1,    -1,
1013       -1,    -1,    -1,    -1,    -1,    -1,    -1,    19,    -1,    21,
1014       22,    23,    24,    25,    26,    27,    28,    29,    30,    31,
1015       32,    33,    34,    -1,    -1,    -1,    38,    39,    -1,    -1,
1016       -1,    43,    44,    45,    46,    -1,    -1,    -1,    -1,    51,
1017       52,    -1,    -1,    -1,    -1,    -1,    58,    59,    -1,    61,
1018       -1,    63,    -1,    -1,    66,    67,    -1,    69,    -1,    -1,
1019       72,    73,    74,     1,    -1,     3,     4,    -1,    -1,     7,
1020        8,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
1021       -1,    19,    -1,    21,    22,    23,    24,    25,    26,    27,
1022       28,    29,    30,    31,    32,    33,    34,    -1,    -1,    -1,
1023       38,    39,    -1,    -1,    -1,    43,    44,    45,    46,    -1,
1024       -1,    -1,    -1,    51,    52,    -1,    -1,    -1,    -1,    -1,
1025       58,    59,    -1,    61,    -1,    63,    -1,    -1,    66,    67,
1026       -1,    69,    -1,    -1,    72,    73,    74,     1,    -1,     3,
1027        4,    -1,    -1,     7,     8,    -1,    -1,    -1,    -1,    -1,
1028       -1,    -1,    -1,    -1,    -1,    19,    -1,    21,    22,    23,
1029       -1,    -1,    26,    27,    28,    29,    30,    31,    32,    33,
1030       34,    -1,    -1,    -1,    38,    39,    -1,    -1,    -1,    43,
1031       44,    45,    46,     1,    -1,     3,     4,    -1,    52,     7,
1032        8,    -1,    10,    -1,    58,    59,    -1,    61,    -1,    63,
1033       -1,    -1,    66,    67,    -1,    69,    -1,    -1,    72,    73,
1034       74,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
1035       38,    -1,    -1,    -1,    -1,    43,    44,    45,    46,    -1,
1036       -1,    -1,    -1,    51,    52,    -1,    -1,    -1,    -1,    -1,
1037       58,    59,    -1,    61,    -1,    63,    -1,    -1,    66,    67,
1038       68,    69,    -1,     3,     4,    -1,    74,     7,     8,    -1,
1039       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    19,
1040       -1,    21,    22,    23,    -1,    -1,    26,    27,    28,    29,
1041       30,    31,    32,    33,    34,    -1,     3,     4,    38,    39,
1042        7,     8,    -1,    43,    44,    45,    46,    -1,    -1,    -1,
1043       -1,    -1,    52,    -1,    -1,    -1,    -1,     9,    58,    59,
1044       -1,    61,    14,    63,    -1,    -1,    66,    67,    -1,    69,
1045       -1,    38,    72,    -1,    74,    -1,    43,    44,    45,    46,
1046        1,    -1,     3,     4,    -1,    52,     7,     8,    40,    41,
1047       42,    58,    59,    -1,    61,    -1,    63,    -1,    -1,    66,
1048       67,    53,    69,    55,    56,    57,    -1,    74,    -1,    -1,
1049       -1,    -1,     1,    -1,     3,     4,    -1,    38,     7,     8,
1050       -1,    -1,    43,    44,    45,    46,    -1,    -1,    -1,    -1,
1051       -1,    52,    -1,    -1,    -1,    -1,    -1,    58,    59,    -1,
1052       61,    -1,    63,    -1,    -1,    66,    67,    68,    69,    38,
1053       -1,    -1,    -1,    -1,    43,    44,    45,    46,     1,    -1,
1054        3,     4,    -1,    52,     7,     8,    -1,    -1,    -1,    58,
1055       59,    -1,    61,    -1,    63,    -1,    -1,    66,    67,    -1,
1056       69,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
1057       -1,    -1,    -1,     3,     4,    38,    -1,     7,     8,    -1,
1058       43,    44,    45,    46,    -1,    -1,    -1,    -1,    -1,    52,
1059       -1,    -1,    22,    -1,    -1,    58,    59,    -1,    61,    -1,
1060       63,    31,    32,    66,    67,    -1,    69,    -1,    38,    -1,
1061       -1,    -1,    -1,    43,    44,    45,    46,    -1,    -1,     3,
1062        4,    -1,    52,     7,     8,    -1,    -1,    -1,    58,    59,
1063       -1,    61,    -1,    63,    -1,    -1,    66,    67,    22,    69,
1064       -1,    -1,    -1,    -1,    -1,    -1,    -1,    31,    32,    -1,
1065       -1,    -1,    -1,    -1,    38,    -1,    -1,    -1,    -1,    43,
1066       44,    45,    46,    -1,    -1,     3,     4,    -1,    52,     7,
1067        8,    -1,    -1,    11,    58,    59,    -1,    61,    -1,    63,
1068       -1,    -1,    66,    67,    -1,    69,    -1,    -1,    -1,    -1,
1069       -1,    -1,     3,     4,    -1,    -1,     7,     8,    -1,    -1,
1070       38,    -1,    -1,    -1,    -1,    43,    44,    45,    46,    -1,
1071       -1,    -1,    -1,     9,    52,    -1,    -1,    -1,    14,    -1,
1072       58,    59,    -1,    61,    -1,    63,    -1,    38,    66,    67,
1073       -1,    69,    43,    44,    45,    46,    -1,    -1,     3,     4,
1074       -1,    52,     7,     8,    40,    41,    42,    58,    59,    -1,
1075       61,    -1,    63,    -1,    -1,    66,    67,    53,    69,    -1,
1076       56,    57,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
1077       -1,    -1,    -1,    -1,    -1,    -1,    -1,     9,    43,    44,
1078       45,    46,    14,    -1,    -1,    -1,    -1,    52,    -1,    -1,
1079       -1,    -1,    -1,    58,    59,    -1,    61,    -1,    63,    -1,
1080       -1,    66,    67,    -1,    69,    -1,    -1,    -1,    40,    41,
1081       42,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
1082       -1,    53,    54,    -1,    56,    57
1083 };
1084
1085   /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
1086      symbol of state STATE-NUM.  */
1087 static const yytype_uint8 yystos[] =
1088 {
1089        0,    76,     0,     1,     3,     4,     7,     8,    17,    18,
1090       35,    36,    37,    38,    43,    44,    45,    46,    47,    51,
1091       52,    58,    59,    61,    63,    66,    67,    69,    77,    80,
1092       84,    85,    87,   105,   113,   117,   118,   119,   120,   121,
1093      122,   130,   131,    67,    70,   127,   128,   129,     3,     4,
1094       45,    46,    69,    82,    83,   123,   131,   131,   131,    67,
1095       67,    69,   118,   131,   118,   118,    67,   120,   131,     1,
1096      112,   113,    48,    50,   122,    72,    74,    81,    89,   105,
1097      133,   137,    81,    86,    51,     9,    14,    40,    41,    42,
1098       53,    55,    56,    57,   115,   116,    11,   118,    58,    59,
1099       60,    61,    62,    65,    58,    59,    60,    61,    62,    65,
1100       12,    13,    43,    44,    52,   114,   111,   112,   113,   112,
1101       16,   127,    49,    67,    56,   107,   111,   111,   113,    43,
1102       44,   132,     1,    55,    68,   135,   139,   135,     1,     6,
1103       78,     1,     6,    79,   105,   106,    88,   106,     5,   113,
1104      130,   113,   113,   113,   106,   113,    38,   118,   118,   118,
1105      118,   118,   118,   118,   118,   118,   118,   118,   118,    13,
1106      113,   135,    71,     1,     4,   108,   109,   118,   135,   135,
1107      113,   106,    40,     1,   113,     1,    89,     1,    89,     1,
1108       19,    21,    22,    23,    26,    27,    28,    29,    30,    31,
1109       32,    33,    34,    39,    73,    90,    91,    93,   100,   104,
1110      113,   133,   134,   137,    54,   113,   123,   135,     1,   139,
1111      130,    67,    92,     4,    67,    67,    67,   106,    67,    89,
1112       89,    89,   110,   113,    89,   106,    89,    94,    88,   136,
1113      137,   106,   113,   106,     1,     4,   113,   110,    95,     4,
1114      113,   113,    90,     4,    93,    96,    89,    67,   101,   111,
1115      134,   106,   135,    89,   124,   125,   126,   127,    68,   135,
1116      135,    26,    40,   137,   112,    10,   102,   106,    16,   126,
1117      106,   106,    67,   130,   106,   135,   103,    90,   133,    90,
1118      113,   135,   113,   137,   117,    20,    97,   135,   106,   137,
1119      106,   106,     1,    24,    25,    98,   106,   106,    90,   106,
1120       96,    90,     7,     8,    58,    59,    85,    99,    54,   138,
1121      134,    96,   135,     7,     7,   138,   106,   135,   106,   106,
1122       88,   106,    90,    88,    90
1123 };
1124
1125   /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
1126 static const yytype_uint8 yyr1[] =
1127 {
1128        0,    75,    76,    76,    76,    76,    76,    77,    77,    77,
1129       77,    77,    78,    78,    78,    79,    79,    79,    80,    80,
1130       80,    80,    80,    80,    80,    81,    82,    82,    82,    82,
1131       83,    83,    84,    86,    85,    87,    87,    88,    88,    88,
1132       89,    89,    90,    90,    90,    90,    90,    90,    90,    90,
1133       90,    90,    91,    91,    91,    91,    91,    92,    91,    91,
1134       94,    93,    95,    93,    93,    93,    96,    96,    97,    97,
1135       97,    98,    98,    99,    99,    99,    99,    99,   100,   100,
1136      101,   101,   102,   103,   102,   104,   104,   105,   105,   106,
1137      106,   107,   107,   108,   108,   109,   109,   109,   109,   109,
1138      110,   110,   111,   111,   112,   112,   112,   112,   112,   112,
1139      113,   113,   113,   113,   113,   113,   113,   113,   114,   114,
1140      114,   115,   115,   116,   116,   117,   117,   117,   118,   118,
1141      118,   118,   118,   118,   118,   118,   118,   118,   118,   119,
1142      119,   119,   119,   119,   119,   119,   120,   120,   120,   120,
1143      120,   120,   120,   120,   120,   120,   120,   120,   120,   120,
1144      121,   121,   122,   123,   123,   124,   124,   125,   125,   126,
1145      127,   128,   128,   129,   130,   130,   131,   131,   132,   132,
1146      132,   133,   134,   135,   136,   136,   137,   138,   139
1147 };
1148
1149   /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.  */
1150 static const yytype_uint8 yyr2[] =
1151 {
1152        0,     2,     0,     2,     2,     2,     2,     2,     2,     2,
1153        4,     4,     1,     2,     1,     1,     2,     1,     0,     1,
1154        4,     1,     1,     1,     1,     5,     1,     1,     1,     2,
1155        1,     1,     6,     0,     3,     1,     1,     0,     2,     2,
1156        1,     2,     2,     3,     1,     9,     6,     8,     8,    12,
1157       11,     1,     2,     2,     2,     2,     3,     0,     4,     2,
1158        0,     4,     0,     4,     4,     1,     0,     1,     0,     2,
1159        2,     5,     4,     1,     2,     2,     1,     1,     1,     1,
1160        1,     3,     0,     0,     3,     6,     9,     1,     2,     0,
1161        1,     0,     2,     0,     1,     1,     3,     1,     2,     3,
1162        0,     1,     0,     1,     1,     3,     1,     2,     3,     3,
1163        3,     3,     3,     3,     3,     3,     5,     1,     1,     1,
1164        2,     1,     1,     1,     1,     1,     1,     2,     1,     3,
1165        3,     3,     3,     3,     3,     3,     2,     2,     5,     4,
1166        3,     3,     3,     3,     3,     3,     1,     2,     3,     4,
1167        4,     1,     1,     1,     2,     2,     1,     1,     2,     2,
1168        1,     2,     4,     0,     1,     0,     2,     1,     2,     1,
1169        3,     1,     2,     2,     1,     2,     1,     3,     1,     1,
1170        0,     2,     2,     1,     0,     1,     1,     1,     2
1171 };
1172
1173
1174 #define yyerrok         (yyerrstatus = 0)
1175 #define yyclearin       (yychar = YYEMPTY)
1176 #define YYEMPTY         (-2)
1177 #define YYEOF           0
1178
1179 #define YYACCEPT        goto yyacceptlab
1180 #define YYABORT         goto yyabortlab
1181 #define YYERROR         goto yyerrorlab
1182
1183
1184 #define YYRECOVERING()  (!!yyerrstatus)
1185
1186 #define YYBACKUP(Token, Value)                                  \
1187 do                                                              \
1188   if (yychar == YYEMPTY)                                        \
1189     {                                                           \
1190       yychar = (Token);                                         \
1191       yylval = (Value);                                         \
1192       YYPOPSTACK (yylen);                                       \
1193       yystate = *yyssp;                                         \
1194       goto yybackup;                                            \
1195     }                                                           \
1196   else                                                          \
1197     {                                                           \
1198       yyerror (YY_("syntax error: cannot back up")); \
1199       YYERROR;                                                  \
1200     }                                                           \
1201 while (0)
1202
1203 /* Error token number */
1204 #define YYTERROR        1
1205 #define YYERRCODE       256
1206
1207
1208
1209 /* Enable debugging if requested.  */
1210 #if YYDEBUG
1211
1212 # ifndef YYFPRINTF
1213 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1214 #  define YYFPRINTF fprintf
1215 # endif
1216
1217 # define YYDPRINTF(Args)                        \
1218 do {                                            \
1219   if (yydebug)                                  \
1220     YYFPRINTF Args;                             \
1221 } while (0)
1222
1223 /* This macro is provided for backward compatibility. */
1224 #ifndef YY_LOCATION_PRINT
1225 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1226 #endif
1227
1228
1229 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)                    \
1230 do {                                                                      \
1231   if (yydebug)                                                            \
1232     {                                                                     \
1233       YYFPRINTF (stderr, "%s ", Title);                                   \
1234       yy_symbol_print (stderr,                                            \
1235                   Type, Value); \
1236       YYFPRINTF (stderr, "\n");                                           \
1237     }                                                                     \
1238 } while (0)
1239
1240
1241 /*----------------------------------------.
1242 | Print this symbol's value on YYOUTPUT.  |
1243 `----------------------------------------*/
1244
1245 static void
1246 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
1247 {
1248   FILE *yyo = yyoutput;
1249   YYUSE (yyo);
1250   if (!yyvaluep)
1251     return;
1252 # ifdef YYPRINT
1253   if (yytype < YYNTOKENS)
1254     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1255 # endif
1256   YYUSE (yytype);
1257 }
1258
1259
1260 /*--------------------------------.
1261 | Print this symbol on YYOUTPUT.  |
1262 `--------------------------------*/
1263
1264 static void
1265 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
1266 {
1267   YYFPRINTF (yyoutput, "%s %s (",
1268              yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
1269
1270   yy_symbol_value_print (yyoutput, yytype, yyvaluep);
1271   YYFPRINTF (yyoutput, ")");
1272 }
1273
1274 /*------------------------------------------------------------------.
1275 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1276 | TOP (included).                                                   |
1277 `------------------------------------------------------------------*/
1278
1279 static void
1280 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
1281 {
1282   YYFPRINTF (stderr, "Stack now");
1283   for (; yybottom <= yytop; yybottom++)
1284     {
1285       int yybot = *yybottom;
1286       YYFPRINTF (stderr, " %d", yybot);
1287     }
1288   YYFPRINTF (stderr, "\n");
1289 }
1290
1291 # define YY_STACK_PRINT(Bottom, Top)                            \
1292 do {                                                            \
1293   if (yydebug)                                                  \
1294     yy_stack_print ((Bottom), (Top));                           \
1295 } while (0)
1296
1297
1298 /*------------------------------------------------.
1299 | Report that the YYRULE is going to be reduced.  |
1300 `------------------------------------------------*/
1301
1302 static void
1303 yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
1304 {
1305   unsigned long int yylno = yyrline[yyrule];
1306   int yynrhs = yyr2[yyrule];
1307   int yyi;
1308   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1309              yyrule - 1, yylno);
1310   /* The symbols being reduced.  */
1311   for (yyi = 0; yyi < yynrhs; yyi++)
1312     {
1313       YYFPRINTF (stderr, "   $%d = ", yyi + 1);
1314       yy_symbol_print (stderr,
1315                        yystos[yyssp[yyi + 1 - yynrhs]],
1316                        &(yyvsp[(yyi + 1) - (yynrhs)])
1317                                               );
1318       YYFPRINTF (stderr, "\n");
1319     }
1320 }
1321
1322 # define YY_REDUCE_PRINT(Rule)          \
1323 do {                                    \
1324   if (yydebug)                          \
1325     yy_reduce_print (yyssp, yyvsp, Rule); \
1326 } while (0)
1327
1328 /* Nonzero means print parse trace.  It is left uninitialized so that
1329    multiple parsers can coexist.  */
1330 int yydebug;
1331 #else /* !YYDEBUG */
1332 # define YYDPRINTF(Args)
1333 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1334 # define YY_STACK_PRINT(Bottom, Top)
1335 # define YY_REDUCE_PRINT(Rule)
1336 #endif /* !YYDEBUG */
1337
1338
1339 /* YYINITDEPTH -- initial size of the parser's stacks.  */
1340 #ifndef YYINITDEPTH
1341 # define YYINITDEPTH 200
1342 #endif
1343
1344 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1345    if the built-in stack extension method is used).
1346
1347    Do not make this value too large; the results are undefined if
1348    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1349    evaluated with infinite-precision integer arithmetic.  */
1350
1351 #ifndef YYMAXDEPTH
1352 # define YYMAXDEPTH 10000
1353 #endif
1354
1355
1356 #if YYERROR_VERBOSE
1357
1358 # ifndef yystrlen
1359 #  if defined __GLIBC__ && defined _STRING_H
1360 #   define yystrlen strlen
1361 #  else
1362 /* Return the length of YYSTR.  */
1363 static YYSIZE_T
1364 yystrlen (const char *yystr)
1365 {
1366   YYSIZE_T yylen;
1367   for (yylen = 0; yystr[yylen]; yylen++)
1368     continue;
1369   return yylen;
1370 }
1371 #  endif
1372 # endif
1373
1374 # ifndef yystpcpy
1375 #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1376 #   define yystpcpy stpcpy
1377 #  else
1378 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1379    YYDEST.  */
1380 static char *
1381 yystpcpy (char *yydest, const char *yysrc)
1382 {
1383   char *yyd = yydest;
1384   const char *yys = yysrc;
1385
1386   while ((*yyd++ = *yys++) != '\0')
1387     continue;
1388
1389   return yyd - 1;
1390 }
1391 #  endif
1392 # endif
1393
1394 # ifndef yytnamerr
1395 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1396    quotes and backslashes, so that it's suitable for yyerror.  The
1397    heuristic is that double-quoting is unnecessary unless the string
1398    contains an apostrophe, a comma, or backslash (other than
1399    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
1400    null, do not copy; instead, return the length of what the result
1401    would have been.  */
1402 static YYSIZE_T
1403 yytnamerr (char *yyres, const char *yystr)
1404 {
1405   if (*yystr == '"')
1406     {
1407       YYSIZE_T yyn = 0;
1408       char const *yyp = yystr;
1409
1410       for (;;)
1411         switch (*++yyp)
1412           {
1413           case '\'':
1414           case ',':
1415             goto do_not_strip_quotes;
1416
1417           case '\\':
1418             if (*++yyp != '\\')
1419               goto do_not_strip_quotes;
1420             /* Fall through.  */
1421           default:
1422             if (yyres)
1423               yyres[yyn] = *yyp;
1424             yyn++;
1425             break;
1426
1427           case '"':
1428             if (yyres)
1429               yyres[yyn] = '\0';
1430             return yyn;
1431           }
1432     do_not_strip_quotes: ;
1433     }
1434
1435   if (! yyres)
1436     return yystrlen (yystr);
1437
1438   return yystpcpy (yyres, yystr) - yyres;
1439 }
1440 # endif
1441
1442 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1443    about the unexpected token YYTOKEN for the state stack whose top is
1444    YYSSP.
1445
1446    Return 0 if *YYMSG was successfully written.  Return 1 if *YYMSG is
1447    not large enough to hold the message.  In that case, also set
1448    *YYMSG_ALLOC to the required number of bytes.  Return 2 if the
1449    required number of bytes is too large to store.  */
1450 static int
1451 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1452                 yytype_int16 *yyssp, int yytoken)
1453 {
1454   YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
1455   YYSIZE_T yysize = yysize0;
1456   enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1457   /* Internationalized format string. */
1458   const char *yyformat = YY_NULLPTR;
1459   /* Arguments of yyformat. */
1460   char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1461   /* Number of reported tokens (one for the "unexpected", one per
1462      "expected"). */
1463   int yycount = 0;
1464
1465   /* There are many possibilities here to consider:
1466      - If this state is a consistent state with a default action, then
1467        the only way this function was invoked is if the default action
1468        is an error action.  In that case, don't check for expected
1469        tokens because there are none.
1470      - The only way there can be no lookahead present (in yychar) is if
1471        this state is a consistent state with a default action.  Thus,
1472        detecting the absence of a lookahead is sufficient to determine
1473        that there is no unexpected or expected token to report.  In that
1474        case, just report a simple "syntax error".
1475      - Don't assume there isn't a lookahead just because this state is a
1476        consistent state with a default action.  There might have been a
1477        previous inconsistent state, consistent state with a non-default
1478        action, or user semantic action that manipulated yychar.
1479      - Of course, the expected token list depends on states to have
1480        correct lookahead information, and it depends on the parser not
1481        to perform extra reductions after fetching a lookahead from the
1482        scanner and before detecting a syntax error.  Thus, state merging
1483        (from LALR or IELR) and default reductions corrupt the expected
1484        token list.  However, the list is correct for canonical LR with
1485        one exception: it will still contain any token that will not be
1486        accepted due to an error action in a later state.
1487   */
1488   if (yytoken != YYEMPTY)
1489     {
1490       int yyn = yypact[*yyssp];
1491       yyarg[yycount++] = yytname[yytoken];
1492       if (!yypact_value_is_default (yyn))
1493         {
1494           /* Start YYX at -YYN if negative to avoid negative indexes in
1495              YYCHECK.  In other words, skip the first -YYN actions for
1496              this state because they are default actions.  */
1497           int yyxbegin = yyn < 0 ? -yyn : 0;
1498           /* Stay within bounds of both yycheck and yytname.  */
1499           int yychecklim = YYLAST - yyn + 1;
1500           int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1501           int yyx;
1502
1503           for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1504             if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1505                 && !yytable_value_is_error (yytable[yyx + yyn]))
1506               {
1507                 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1508                   {
1509                     yycount = 1;
1510                     yysize = yysize0;
1511                     break;
1512                   }
1513                 yyarg[yycount++] = yytname[yyx];
1514                 {
1515                   YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
1516                   if (! (yysize <= yysize1
1517                          && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1518                     return 2;
1519                   yysize = yysize1;
1520                 }
1521               }
1522         }
1523     }
1524
1525   switch (yycount)
1526     {
1527 # define YYCASE_(N, S)                      \
1528       case N:                               \
1529         yyformat = S;                       \
1530       break
1531       YYCASE_(0, YY_("syntax error"));
1532       YYCASE_(1, YY_("syntax error, unexpected %s"));
1533       YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1534       YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1535       YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1536       YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1537 # undef YYCASE_
1538     }
1539
1540   {
1541     YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1542     if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1543       return 2;
1544     yysize = yysize1;
1545   }
1546
1547   if (*yymsg_alloc < yysize)
1548     {
1549       *yymsg_alloc = 2 * yysize;
1550       if (! (yysize <= *yymsg_alloc
1551              && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1552         *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1553       return 1;
1554     }
1555
1556   /* Avoid sprintf, as that infringes on the user's name space.
1557      Don't have undefined behavior even if the translation
1558      produced a string with the wrong number of "%s"s.  */
1559   {
1560     char *yyp = *yymsg;
1561     int yyi = 0;
1562     while ((*yyp = *yyformat) != '\0')
1563       if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1564         {
1565           yyp += yytnamerr (yyp, yyarg[yyi++]);
1566           yyformat += 2;
1567         }
1568       else
1569         {
1570           yyp++;
1571           yyformat++;
1572         }
1573   }
1574   return 0;
1575 }
1576 #endif /* YYERROR_VERBOSE */
1577
1578 /*-----------------------------------------------.
1579 | Release the memory associated to this symbol.  |
1580 `-----------------------------------------------*/
1581
1582 static void
1583 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1584 {
1585   YYUSE (yyvaluep);
1586   if (!yymsg)
1587     yymsg = "Deleting";
1588   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1589
1590   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1591   YYUSE (yytype);
1592   YY_IGNORE_MAYBE_UNINITIALIZED_END
1593 }
1594
1595
1596
1597
1598 /* The lookahead symbol.  */
1599 int yychar;
1600
1601 /* The semantic value of the lookahead symbol.  */
1602 YYSTYPE yylval;
1603 /* Number of syntax errors so far.  */
1604 int yynerrs;
1605
1606
1607 /*----------.
1608 | yyparse.  |
1609 `----------*/
1610
1611 int
1612 yyparse (void)
1613 {
1614     int yystate;
1615     /* Number of tokens to shift before error messages enabled.  */
1616     int yyerrstatus;
1617
1618     /* The stacks and their tools:
1619        'yyss': related to states.
1620        'yyvs': related to semantic values.
1621
1622        Refer to the stacks through separate pointers, to allow yyoverflow
1623        to reallocate them elsewhere.  */
1624
1625     /* The state stack.  */
1626     yytype_int16 yyssa[YYINITDEPTH];
1627     yytype_int16 *yyss;
1628     yytype_int16 *yyssp;
1629
1630     /* The semantic value stack.  */
1631     YYSTYPE yyvsa[YYINITDEPTH];
1632     YYSTYPE *yyvs;
1633     YYSTYPE *yyvsp;
1634
1635     YYSIZE_T yystacksize;
1636
1637   int yyn;
1638   int yyresult;
1639   /* Lookahead token as an internal (translated) token number.  */
1640   int yytoken = 0;
1641   /* The variables used to return semantic value and location from the
1642      action routines.  */
1643   YYSTYPE yyval;
1644
1645 #if YYERROR_VERBOSE
1646   /* Buffer for error messages, and its allocated size.  */
1647   char yymsgbuf[128];
1648   char *yymsg = yymsgbuf;
1649   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1650 #endif
1651
1652 #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
1653
1654   /* The number of symbols on the RHS of the reduced rule.
1655      Keep to zero when no symbol should be popped.  */
1656   int yylen = 0;
1657
1658   yyssp = yyss = yyssa;
1659   yyvsp = yyvs = yyvsa;
1660   yystacksize = YYINITDEPTH;
1661
1662   YYDPRINTF ((stderr, "Starting parse\n"));
1663
1664   yystate = 0;
1665   yyerrstatus = 0;
1666   yynerrs = 0;
1667   yychar = YYEMPTY; /* Cause a token to be read.  */
1668   goto yysetstate;
1669
1670 /*------------------------------------------------------------.
1671 | yynewstate -- Push a new state, which is found in yystate.  |
1672 `------------------------------------------------------------*/
1673  yynewstate:
1674   /* In all cases, when you get here, the value and location stacks
1675      have just been pushed.  So pushing a state here evens the stacks.  */
1676   yyssp++;
1677
1678  yysetstate:
1679   *yyssp = yystate;
1680
1681   if (yyss + yystacksize - 1 <= yyssp)
1682     {
1683       /* Get the current used size of the three stacks, in elements.  */
1684       YYSIZE_T yysize = yyssp - yyss + 1;
1685
1686 #ifdef yyoverflow
1687       {
1688         /* Give user a chance to reallocate the stack.  Use copies of
1689            these so that the &'s don't force the real ones into
1690            memory.  */
1691         YYSTYPE *yyvs1 = yyvs;
1692         yytype_int16 *yyss1 = yyss;
1693
1694         /* Each stack pointer address is followed by the size of the
1695            data in use in that stack, in bytes.  This used to be a
1696            conditional around just the two extra args, but that might
1697            be undefined if yyoverflow is a macro.  */
1698         yyoverflow (YY_("memory exhausted"),
1699                     &yyss1, yysize * sizeof (*yyssp),
1700                     &yyvs1, yysize * sizeof (*yyvsp),
1701                     &yystacksize);
1702
1703         yyss = yyss1;
1704         yyvs = yyvs1;
1705       }
1706 #else /* no yyoverflow */
1707 # ifndef YYSTACK_RELOCATE
1708       goto yyexhaustedlab;
1709 # else
1710       /* Extend the stack our own way.  */
1711       if (YYMAXDEPTH <= yystacksize)
1712         goto yyexhaustedlab;
1713       yystacksize *= 2;
1714       if (YYMAXDEPTH < yystacksize)
1715         yystacksize = YYMAXDEPTH;
1716
1717       {
1718         yytype_int16 *yyss1 = yyss;
1719         union yyalloc *yyptr =
1720           (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1721         if (! yyptr)
1722           goto yyexhaustedlab;
1723         YYSTACK_RELOCATE (yyss_alloc, yyss);
1724         YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1725 #  undef YYSTACK_RELOCATE
1726         if (yyss1 != yyssa)
1727           YYSTACK_FREE (yyss1);
1728       }
1729 # endif
1730 #endif /* no yyoverflow */
1731
1732       yyssp = yyss + yysize - 1;
1733       yyvsp = yyvs + yysize - 1;
1734
1735       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1736                   (unsigned long int) yystacksize));
1737
1738       if (yyss + yystacksize - 1 <= yyssp)
1739         YYABORT;
1740     }
1741
1742   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1743
1744   if (yystate == YYFINAL)
1745     YYACCEPT;
1746
1747   goto yybackup;
1748
1749 /*-----------.
1750 | yybackup.  |
1751 `-----------*/
1752 yybackup:
1753
1754   /* Do appropriate processing given the current state.  Read a
1755      lookahead token if we need one and don't already have one.  */
1756
1757   /* First try to decide what to do without reference to lookahead token.  */
1758   yyn = yypact[yystate];
1759   if (yypact_value_is_default (yyn))
1760     goto yydefault;
1761
1762   /* Not known => get a lookahead token if don't already have one.  */
1763
1764   /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
1765   if (yychar == YYEMPTY)
1766     {
1767       YYDPRINTF ((stderr, "Reading a token: "));
1768       yychar = yylex ();
1769     }
1770
1771   if (yychar <= YYEOF)
1772     {
1773       yychar = yytoken = YYEOF;
1774       YYDPRINTF ((stderr, "Now at end of input.\n"));
1775     }
1776   else
1777     {
1778       yytoken = YYTRANSLATE (yychar);
1779       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1780     }
1781
1782   /* If the proper action on seeing token YYTOKEN is to reduce or to
1783      detect an error, take that action.  */
1784   yyn += yytoken;
1785   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1786     goto yydefault;
1787   yyn = yytable[yyn];
1788   if (yyn <= 0)
1789     {
1790       if (yytable_value_is_error (yyn))
1791         goto yyerrlab;
1792       yyn = -yyn;
1793       goto yyreduce;
1794     }
1795
1796   /* Count tokens shifted since error; after three, turn off error
1797      status.  */
1798   if (yyerrstatus)
1799     yyerrstatus--;
1800
1801   /* Shift the lookahead token.  */
1802   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1803
1804   /* Discard the shifted token.  */
1805   yychar = YYEMPTY;
1806
1807   yystate = yyn;
1808   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1809   *++yyvsp = yylval;
1810   YY_IGNORE_MAYBE_UNINITIALIZED_END
1811
1812   goto yynewstate;
1813
1814
1815 /*-----------------------------------------------------------.
1816 | yydefault -- do the default action for the current state.  |
1817 `-----------------------------------------------------------*/
1818 yydefault:
1819   yyn = yydefact[yystate];
1820   if (yyn == 0)
1821     goto yyerrlab;
1822   goto yyreduce;
1823
1824
1825 /*-----------------------------.
1826 | yyreduce -- Do a reduction.  |
1827 `-----------------------------*/
1828 yyreduce:
1829   /* yyn is the number of a rule to reduce with.  */
1830   yylen = yyr2[yyn];
1831
1832   /* If YYLEN is nonzero, implement the default value of the action:
1833      '$$ = $1'.
1834
1835      Otherwise, the following line sets YYVAL to garbage.
1836      This behavior is undocumented and Bison
1837      users should not rely upon it.  Assigning to YYVAL
1838      unconditionally makes the parser a bit smaller, and it avoids a
1839      GCC warning that YYVAL may be used uninitialized.  */
1840   yyval = yyvsp[1-yylen];
1841
1842
1843   YY_REDUCE_PRINT (yyn);
1844   switch (yyn)
1845     {
1846         case 3:
1847 #line 203 "awkgram.y" /* yacc.c:1646  */
1848     {
1849                 rule = 0;
1850                 yyerrok;
1851           }
1852 #line 1853 "awkgram.c" /* yacc.c:1646  */
1853     break;
1854
1855   case 5:
1856 #line 209 "awkgram.y" /* yacc.c:1646  */
1857     {
1858                 next_sourcefile();
1859                 if (sourcefile == srcfiles)
1860                         process_deferred();
1861           }
1862 #line 1863 "awkgram.c" /* yacc.c:1646  */
1863     break;
1864
1865   case 6:
1866 #line 215 "awkgram.y" /* yacc.c:1646  */
1867     {
1868                 rule = 0;
1869                 /*
1870                  * If errors, give up, don't produce an infinite
1871                  * stream of syntax error messages.
1872                  */
1873                 /* yyerrok; */
1874           }
1875 #line 1876 "awkgram.c" /* yacc.c:1646  */
1876     break;
1877
1878   case 7:
1879 #line 227 "awkgram.y" /* yacc.c:1646  */
1880     {
1881                 (void) append_rule((yyvsp[-1]), (yyvsp[0]));
1882           }
1883 #line 1884 "awkgram.c" /* yacc.c:1646  */
1884     break;
1885
1886   case 8:
1887 #line 231 "awkgram.y" /* yacc.c:1646  */
1888     {
1889                 if (rule != Rule) {
1890                         msg(_("%s blocks must have an action part"), ruletab[rule]);
1891                         errcount++;
1892                 } else if ((yyvsp[-1]) == NULL) {
1893                         msg(_("each rule must have a pattern or an action part"));
1894                         errcount++;
1895                 } else          /* pattern rule with non-empty pattern */
1896                         (void) append_rule((yyvsp[-1]), NULL);
1897           }
1898 #line 1899 "awkgram.c" /* yacc.c:1646  */
1899     break;
1900
1901   case 9:
1902 #line 242 "awkgram.y" /* yacc.c:1646  */
1903     {
1904                 in_function = NULL;
1905                 (void) mk_function((yyvsp[-1]), (yyvsp[0]));
1906                 yyerrok;
1907           }
1908 #line 1909 "awkgram.c" /* yacc.c:1646  */
1909     break;
1910
1911   case 10:
1912 #line 248 "awkgram.y" /* yacc.c:1646  */
1913     {
1914                 want_source = false;
1915                 yyerrok;
1916           }
1917 #line 1918 "awkgram.c" /* yacc.c:1646  */
1918     break;
1919
1920   case 11:
1921 #line 253 "awkgram.y" /* yacc.c:1646  */
1922     {
1923                 want_source = false;
1924                 yyerrok;
1925           }
1926 #line 1927 "awkgram.c" /* yacc.c:1646  */
1927     break;
1928
1929   case 12:
1930 #line 261 "awkgram.y" /* yacc.c:1646  */
1931     {
1932                 if (include_source((yyvsp[0])) < 0)
1933                         YYABORT;
1934                 efree((yyvsp[0])->lextok);
1935                 bcfree((yyvsp[0]));
1936                 (yyval) = NULL;
1937           }
1938 #line 1939 "awkgram.c" /* yacc.c:1646  */
1939     break;
1940
1941   case 13:
1942 #line 269 "awkgram.y" /* yacc.c:1646  */
1943     { (yyval) = NULL; }
1944 #line 1945 "awkgram.c" /* yacc.c:1646  */
1945     break;
1946
1947   case 14:
1948 #line 271 "awkgram.y" /* yacc.c:1646  */
1949     { (yyval) = NULL; }
1950 #line 1951 "awkgram.c" /* yacc.c:1646  */
1951     break;
1952
1953   case 15:
1954 #line 276 "awkgram.y" /* yacc.c:1646  */
1955     {
1956                 if (load_library((yyvsp[0])) < 0)
1957                         YYABORT;
1958                 efree((yyvsp[0])->lextok);
1959                 bcfree((yyvsp[0]));
1960                 (yyval) = NULL;
1961           }
1962 #line 1963 "awkgram.c" /* yacc.c:1646  */
1963     break;
1964
1965   case 16:
1966 #line 284 "awkgram.y" /* yacc.c:1646  */
1967     { (yyval) = NULL; }
1968 #line 1969 "awkgram.c" /* yacc.c:1646  */
1969     break;
1970
1971   case 17:
1972 #line 286 "awkgram.y" /* yacc.c:1646  */
1973     { (yyval) = NULL; }
1974 #line 1975 "awkgram.c" /* yacc.c:1646  */
1975     break;
1976
1977   case 18:
1978 #line 291 "awkgram.y" /* yacc.c:1646  */
1979     {   (yyval) = NULL; rule = Rule; }
1980 #line 1981 "awkgram.c" /* yacc.c:1646  */
1981     break;
1982
1983   case 19:
1984 #line 293 "awkgram.y" /* yacc.c:1646  */
1985     {   (yyval) = (yyvsp[0]); rule = Rule; }
1986 #line 1987 "awkgram.c" /* yacc.c:1646  */
1987     break;
1988
1989   case 20:
1990 #line 295 "awkgram.y" /* yacc.c:1646  */
1991     {
1992                 INSTRUCTION *tp;
1993
1994                 add_lint((yyvsp[-3]), LINT_assign_in_cond);
1995                 add_lint((yyvsp[0]), LINT_assign_in_cond);
1996
1997                 tp = instruction(Op_no_op);
1998                 list_prepend((yyvsp[-3]), bcalloc(Op_line_range, !!do_pretty_print + 1, 0));
1999                 (yyvsp[-3])->nexti->triggered = false;
2000                 (yyvsp[-3])->nexti->target_jmp = (yyvsp[0])->nexti;
2001
2002                 list_append((yyvsp[-3]), instruction(Op_cond_pair));
2003                 (yyvsp[-3])->lasti->line_range = (yyvsp[-3])->nexti;
2004                 (yyvsp[-3])->lasti->target_jmp = tp;
2005
2006                 list_append((yyvsp[0]), instruction(Op_cond_pair));
2007                 (yyvsp[0])->lasti->line_range = (yyvsp[-3])->nexti;
2008                 (yyvsp[0])->lasti->target_jmp = tp;
2009                 if (do_pretty_print) {
2010                         ((yyvsp[-3])->nexti + 1)->condpair_left = (yyvsp[-3])->lasti;
2011                         ((yyvsp[-3])->nexti + 1)->condpair_right = (yyvsp[0])->lasti;
2012                 }
2013                 (yyval) = list_append(list_merge((yyvsp[-3]), (yyvsp[0])), tp);
2014                 rule = Rule;
2015           }
2016 #line 2017 "awkgram.c" /* yacc.c:1646  */
2017     break;
2018
2019   case 21:
2020 #line 321 "awkgram.y" /* yacc.c:1646  */
2021     {
2022                 static int begin_seen = 0;
2023                 if (do_lint_old && ++begin_seen == 2)
2024                         warning_ln((yyvsp[0])->source_line,
2025                                 _("old awk does not support multiple `BEGIN' or `END' rules"));
2026
2027                 (yyvsp[0])->in_rule = rule = BEGIN;
2028                 (yyvsp[0])->source_file = source;
2029                 (yyval) = (yyvsp[0]);
2030           }
2031 #line 2032 "awkgram.c" /* yacc.c:1646  */
2032     break;
2033
2034   case 22:
2035 #line 332 "awkgram.y" /* yacc.c:1646  */
2036     {
2037                 static int end_seen = 0;
2038                 if (do_lint_old && ++end_seen == 2)
2039                         warning_ln((yyvsp[0])->source_line,
2040                                 _("old awk does not support multiple `BEGIN' or `END' rules"));
2041
2042                 (yyvsp[0])->in_rule = rule = END;
2043                 (yyvsp[0])->source_file = source;
2044                 (yyval) = (yyvsp[0]);
2045           }
2046 #line 2047 "awkgram.c" /* yacc.c:1646  */
2047     break;
2048
2049   case 23:
2050 #line 343 "awkgram.y" /* yacc.c:1646  */
2051     {
2052                 (yyvsp[0])->in_rule = rule = BEGINFILE;
2053                 (yyvsp[0])->source_file = source;
2054                 (yyval) = (yyvsp[0]);
2055           }
2056 #line 2057 "awkgram.c" /* yacc.c:1646  */
2057     break;
2058
2059   case 24:
2060 #line 349 "awkgram.y" /* yacc.c:1646  */
2061     {
2062                 (yyvsp[0])->in_rule = rule = ENDFILE;
2063                 (yyvsp[0])->source_file = source;
2064                 (yyval) = (yyvsp[0]);
2065           }
2066 #line 2067 "awkgram.c" /* yacc.c:1646  */
2067     break;
2068
2069   case 25:
2070 #line 358 "awkgram.y" /* yacc.c:1646  */
2071     {
2072                 if ((yyvsp[-3]) == NULL)
2073                         (yyval) = list_create(instruction(Op_no_op));
2074                 else
2075                         (yyval) = (yyvsp[-3]);
2076           }
2077 #line 2078 "awkgram.c" /* yacc.c:1646  */
2078     break;
2079
2080   case 26:
2081 #line 368 "awkgram.y" /* yacc.c:1646  */
2082     { (yyval) = (yyvsp[0]); }
2083 #line 2084 "awkgram.c" /* yacc.c:1646  */
2084     break;
2085
2086   case 27:
2087 #line 370 "awkgram.y" /* yacc.c:1646  */
2088     { (yyval) = (yyvsp[0]); }
2089 #line 2090 "awkgram.c" /* yacc.c:1646  */
2090     break;
2091
2092   case 28:
2093 #line 372 "awkgram.y" /* yacc.c:1646  */
2094     {
2095                 yyerror(_("`%s' is a built-in function, it cannot be redefined"),
2096                                         tokstart);
2097                 YYABORT;
2098           }
2099 #line 2100 "awkgram.c" /* yacc.c:1646  */
2100     break;
2101
2102   case 29:
2103 #line 378 "awkgram.y" /* yacc.c:1646  */
2104     { (yyval) = (yyvsp[0]); }
2105 #line 2106 "awkgram.c" /* yacc.c:1646  */
2106     break;
2107
2108   case 32:
2109 #line 388 "awkgram.y" /* yacc.c:1646  */
2110     {
2111                 (yyvsp[-5])->source_file = source;
2112                 if (install_function((yyvsp[-4])->lextok, (yyvsp[-5]), (yyvsp[-2])) < 0)
2113                         YYABORT;
2114                 in_function = (yyvsp[-4])->lextok;
2115                 (yyvsp[-4])->lextok = NULL;
2116                 bcfree((yyvsp[-4]));
2117                 /* $4 already free'd in install_function */
2118                 (yyval) = (yyvsp[-5]);
2119           }
2120 #line 2121 "awkgram.c" /* yacc.c:1646  */
2121     break;
2122
2123   case 33:
2124 #line 406 "awkgram.y" /* yacc.c:1646  */
2125     { want_regexp = true; }
2126 #line 2127 "awkgram.c" /* yacc.c:1646  */
2127     break;
2128
2129   case 34:
2130 #line 408 "awkgram.y" /* yacc.c:1646  */
2131     {
2132                   NODE *n, *exp;
2133                   char *re;
2134                   size_t len;
2135
2136                   re = (yyvsp[0])->lextok;
2137                   (yyvsp[0])->lextok = NULL;
2138                   len = strlen(re);
2139                   if (do_lint) {
2140                         if (len == 0)
2141                                 lintwarn_ln((yyvsp[0])->source_line,
2142                                         _("regexp constant `//' looks like a C++ comment, but is not"));
2143                         else if (re[0] == '*' && re[len-1] == '*')
2144                                 /* possible C comment */
2145                                 lintwarn_ln((yyvsp[0])->source_line,
2146                                         _("regexp constant `/%s/' looks like a C comment, but is not"), re);
2147                   }
2148
2149                   exp = make_str_node(re, len, ALREADY_MALLOCED);
2150                   n = make_regnode(Node_regex, exp);
2151                   if (n == NULL) {
2152                         unref(exp);
2153                         YYABORT;
2154                   }
2155                   (yyval) = (yyvsp[0]);
2156                   (yyval)->opcode = Op_match_rec;
2157                   (yyval)->memory = n;
2158                 }
2159 #line 2160 "awkgram.c" /* yacc.c:1646  */
2160     break;
2161
2162   case 35:
2163 #line 440 "awkgram.y" /* yacc.c:1646  */
2164     { bcfree((yyvsp[0])); }
2165 #line 2166 "awkgram.c" /* yacc.c:1646  */
2166     break;
2167
2168   case 37:
2169 #line 446 "awkgram.y" /* yacc.c:1646  */
2170     {   (yyval) = NULL; }
2171 #line 2172 "awkgram.c" /* yacc.c:1646  */
2172     break;
2173
2174   case 38:
2175 #line 448 "awkgram.y" /* yacc.c:1646  */
2176     {
2177                 if ((yyvsp[0]) == NULL)
2178                         (yyval) = (yyvsp[-1]);
2179                 else {
2180                         add_lint((yyvsp[0]), LINT_no_effect);
2181                         if ((yyvsp[-1]) == NULL)
2182                                 (yyval) = (yyvsp[0]);
2183                         else
2184                                 (yyval) = list_merge((yyvsp[-1]), (yyvsp[0]));
2185                 }
2186             yyerrok;
2187           }
2188 #line 2189 "awkgram.c" /* yacc.c:1646  */
2189     break;
2190
2191   case 39:
2192 #line 461 "awkgram.y" /* yacc.c:1646  */
2193     {   (yyval) = NULL; }
2194 #line 2195 "awkgram.c" /* yacc.c:1646  */
2195     break;
2196
2197   case 42:
2198 #line 471 "awkgram.y" /* yacc.c:1646  */
2199     { (yyval) = NULL; }
2200 #line 2201 "awkgram.c" /* yacc.c:1646  */
2201     break;
2202
2203   case 43:
2204 #line 473 "awkgram.y" /* yacc.c:1646  */
2205     { (yyval) = (yyvsp[-1]); }
2206 #line 2207 "awkgram.c" /* yacc.c:1646  */
2207     break;
2208
2209   case 44:
2210 #line 475 "awkgram.y" /* yacc.c:1646  */
2211     {
2212                 if (do_pretty_print)
2213                         (yyval) = list_prepend((yyvsp[0]), instruction(Op_exec_count));
2214                 else
2215                         (yyval) = (yyvsp[0]);
2216           }
2217 #line 2218 "awkgram.c" /* yacc.c:1646  */
2218     break;
2219
2220   case 45:
2221 #line 482 "awkgram.y" /* yacc.c:1646  */
2222     {
2223                 INSTRUCTION *dflt, *curr = NULL, *cexp, *cstmt;
2224                 INSTRUCTION *ip, *nextc, *tbreak;
2225                 const char **case_values = NULL;
2226                 int maxcount = 128;
2227                 int case_count = 0;
2228                 int i;
2229
2230                 tbreak = instruction(Op_no_op); 
2231                 cstmt = list_create(tbreak);
2232                 cexp = list_create(instruction(Op_pop));
2233                 dflt = instruction(Op_jmp);
2234                 dflt->target_jmp = tbreak;      /* if no case match and no explicit default */
2235
2236                 if ((yyvsp[-2]) != NULL) {
2237                         curr = (yyvsp[-2])->nexti;
2238                         bcfree((yyvsp[-2]));    /* Op_list */
2239                 } /*  else
2240                                 curr = NULL; */
2241
2242                 for(; curr != NULL; curr = nextc) {
2243                         INSTRUCTION *caseexp = curr->case_exp;
2244                         INSTRUCTION *casestmt = curr->case_stmt;
2245
2246                         nextc = curr->nexti;
2247                         if (curr->opcode == Op_K_case) {
2248                                 if (caseexp->opcode == Op_push_i) {
2249                                         /* a constant scalar */
2250                                         char *caseval;
2251                                         caseval = force_string(caseexp->memory)->stptr;
2252                                         for (i = 0; i < case_count; i++) {
2253                                                 if (strcmp(caseval, case_values[i]) == 0)
2254                                                         error_ln(curr->source_line,
2255                                                                 _("duplicate case values in switch body: %s"), caseval);
2256                                         }
2257  
2258                                         if (case_values == NULL)
2259                                                 emalloc(case_values, const char **, sizeof(char *) * maxcount, "statement");
2260                                         else if (case_count >= maxcount) {
2261                                                 maxcount += 128;
2262                                                 erealloc(case_values, const char **, sizeof(char*) * maxcount, "statement");
2263                                         }
2264                                         case_values[case_count++] = caseval;
2265                                 } else {
2266                                         /* match a constant regex against switch expression. */
2267                                         (curr + 1)->match_exp = true;
2268                                 }
2269                                 curr->stmt_start = casestmt->nexti;
2270                                 curr->stmt_end  = casestmt->lasti;
2271                                 (void) list_prepend(cexp, curr);
2272                                 (void) list_prepend(cexp, caseexp);
2273                         } else {
2274                                 if (dflt->target_jmp != tbreak)
2275                                         error_ln(curr->source_line,
2276                                                 _("duplicate `default' detected in switch body"));
2277                                 else
2278                                         dflt->target_jmp = casestmt->nexti;
2279
2280                                 if (do_pretty_print) {
2281                                         curr->stmt_start = casestmt->nexti;
2282                                         curr->stmt_end = casestmt->lasti;
2283                                         (void) list_prepend(cexp, curr);
2284                                 } else
2285                                         bcfree(curr);
2286                         }
2287
2288                         cstmt = list_merge(casestmt, cstmt);
2289                 }
2290
2291                 if (case_values != NULL)
2292                         efree(case_values);
2293
2294                 ip = (yyvsp[-6]);
2295                 if (do_pretty_print) {
2296                         (void) list_prepend(ip, (yyvsp[-8]));
2297                         (void) list_prepend(ip, instruction(Op_exec_count));
2298                         (yyvsp[-8])->target_break = tbreak;
2299                         ((yyvsp[-8]) + 1)->switch_start = cexp->nexti;
2300                         ((yyvsp[-8]) + 1)->switch_end = cexp->lasti;
2301                 }/* else
2302                                 $1 is NULL */
2303
2304                 (void) list_append(cexp, dflt);
2305                 (void) list_merge(ip, cexp);
2306                 (yyval) = list_merge(ip, cstmt);
2307
2308                 break_allowed--;                        
2309                 fix_break_continue(ip, tbreak, NULL);
2310           }
2311 #line 2312 "awkgram.c" /* yacc.c:1646  */
2312     break;
2313
2314   case 46:
2315 #line 572 "awkgram.y" /* yacc.c:1646  */
2316     { 
2317                 /*
2318                  *    -----------------
2319                  * tc:
2320                  *         cond
2321                  *    -----------------
2322                  *    [Op_jmp_false tb   ]
2323                  *    -----------------   
2324                  *         body
2325                  *    -----------------
2326                  *    [Op_jmp      tc    ]
2327                  * tb:[Op_no_op          ]
2328                  */
2329
2330                 INSTRUCTION *ip, *tbreak, *tcont;
2331
2332                 tbreak = instruction(Op_no_op);
2333                 add_lint((yyvsp[-3]), LINT_assign_in_cond);
2334                 tcont = (yyvsp[-3])->nexti;
2335                 ip = list_append((yyvsp[-3]), instruction(Op_jmp_false));
2336                 ip->lasti->target_jmp = tbreak;
2337
2338                 if (do_pretty_print) {
2339                         (void) list_append(ip, instruction(Op_exec_count));
2340                         (yyvsp[-5])->target_break = tbreak;
2341                         (yyvsp[-5])->target_continue = tcont;
2342                         ((yyvsp[-5]) + 1)->while_body = ip->lasti;
2343                         (void) list_prepend(ip, (yyvsp[-5]));
2344                 }/* else
2345                                 $1 is NULL */
2346
2347                 if ((yyvsp[0]) != NULL)
2348                         (void) list_merge(ip, (yyvsp[0]));
2349                 (void) list_append(ip, instruction(Op_jmp));
2350                 ip->lasti->target_jmp = tcont;
2351                 (yyval) = list_append(ip, tbreak);
2352
2353                 break_allowed--;
2354                 continue_allowed--;
2355                 fix_break_continue(ip, tbreak, tcont);
2356           }
2357 #line 2358 "awkgram.c" /* yacc.c:1646  */
2358     break;
2359
2360   case 47:
2361 #line 614 "awkgram.y" /* yacc.c:1646  */
2362     {
2363                 /*
2364                  *    -----------------
2365                  * z:
2366                  *         body
2367                  *    -----------------
2368                  * tc: 
2369                  *         cond
2370                  *    -----------------
2371                  *    [Op_jmp_true | z  ]
2372                  * tb:[Op_no_op         ]
2373                  */
2374
2375                 INSTRUCTION *ip, *tbreak, *tcont;
2376
2377                 tbreak = instruction(Op_no_op);
2378                 tcont = (yyvsp[-2])->nexti;
2379                 add_lint((yyvsp[-2]), LINT_assign_in_cond);
2380                 if ((yyvsp[-5]) != NULL)
2381                         ip = list_merge((yyvsp[-5]), (yyvsp[-2]));
2382                 else
2383                         ip = list_prepend((yyvsp[-2]), instruction(Op_no_op));
2384                 if (do_pretty_print)
2385                         (void) list_prepend(ip, instruction(Op_exec_count));
2386                 (void) list_append(ip, instruction(Op_jmp_true));
2387                 ip->lasti->target_jmp = ip->nexti;
2388                 (yyval) = list_append(ip, tbreak);
2389
2390                 break_allowed--;
2391                 continue_allowed--;
2392                 fix_break_continue(ip, tbreak, tcont);
2393
2394                 if (do_pretty_print) {
2395                         (yyvsp[-7])->target_break = tbreak;
2396                         (yyvsp[-7])->target_continue = tcont;
2397                         ((yyvsp[-7]) + 1)->doloop_cond = tcont;
2398                         (yyval) = list_prepend(ip, (yyvsp[-7]));
2399                         bcfree((yyvsp[-4]));
2400                 } /* else
2401                         $1 and $4 are NULLs */
2402           }
2403 #line 2404 "awkgram.c" /* yacc.c:1646  */
2404     break;
2405
2406   case 48:
2407 #line 656 "awkgram.y" /* yacc.c:1646  */
2408     {
2409                 INSTRUCTION *ip;
2410                 char *var_name = (yyvsp[-5])->lextok;
2411
2412                 if ((yyvsp[0]) != NULL
2413                                 && (yyvsp[0])->lasti->opcode == Op_K_delete
2414                                 && (yyvsp[0])->lasti->expr_count == 1
2415                                 && (yyvsp[0])->nexti->opcode == Op_push
2416                                 && ((yyvsp[0])->nexti->memory->type != Node_var || !((yyvsp[0])->nexti->memory->var_update))
2417                                 && strcmp((yyvsp[0])->nexti->memory->vname, var_name) == 0
2418                 ) {
2419                 
2420                 /* Efficiency hack.  Recognize the special case of
2421                  *
2422                  *      for (iggy in foo)
2423                  *              delete foo[iggy]
2424                  *
2425                  * and treat it as if it were
2426                  *
2427                  *      delete foo
2428                  *
2429                  * Check that the body is a `delete a[i]' statement,
2430                  * and that both the loop var and array names match.
2431                  */              
2432                         NODE *arr = NULL;
2433
2434                         ip = (yyvsp[0])->nexti->nexti; 
2435                         if ((yyvsp[-3])->nexti->opcode == Op_push && (yyvsp[-3])->lasti == (yyvsp[-3])->nexti)
2436                                 arr = (yyvsp[-3])->nexti->memory;
2437                         if (arr != NULL
2438                                         && ip->opcode == Op_no_op
2439                                         && ip->nexti->opcode == Op_push_array
2440                                         && strcmp(ip->nexti->memory->vname, arr->vname) == 0
2441                                         && ip->nexti->nexti == (yyvsp[0])->lasti
2442                         ) {
2443                                 (void) make_assignable((yyvsp[0])->nexti);
2444                                 (yyvsp[0])->lasti->opcode = Op_K_delete_loop;
2445                                 (yyvsp[0])->lasti->expr_count = 0;
2446                                 if ((yyvsp[-7]) != NULL)
2447                                         bcfree((yyvsp[-7]));
2448                                 efree(var_name);
2449                                 bcfree((yyvsp[-5]));
2450                                 bcfree((yyvsp[-4]));
2451                                 bcfree((yyvsp[-3]));
2452                                 (yyval) = (yyvsp[0]);
2453                         } else
2454                                 goto regular_loop;
2455                 } else {
2456                         INSTRUCTION *tbreak, *tcont;
2457
2458                         /*    [ Op_push_array a       ]
2459                          *    [ Op_arrayfor_init | ib ]
2460                          * ic:[ Op_arrayfor_incr | ib ] 
2461                          *    [ Op_var_assign if any  ]
2462                          *
2463                          *              body
2464                          *
2465                          *    [Op_jmp | ic            ]
2466                          * ib:[Op_arrayfor_final      ]
2467                          */
2468 regular_loop:
2469                         ip = (yyvsp[-3]);
2470                         ip->nexti->opcode = Op_push_array;
2471
2472                         tbreak = instruction(Op_arrayfor_final);
2473                         (yyvsp[-4])->opcode = Op_arrayfor_incr;
2474                         (yyvsp[-4])->array_var = variable((yyvsp[-5])->source_line, var_name, Node_var);
2475                         (yyvsp[-4])->target_jmp = tbreak;
2476                         tcont = (yyvsp[-4]);
2477                         (yyvsp[-5])->opcode = Op_arrayfor_init;
2478                         (yyvsp[-5])->target_jmp = tbreak;
2479                         (void) list_append(ip, (yyvsp[-5]));
2480
2481                         if (do_pretty_print) {
2482                                 (yyvsp[-7])->opcode = Op_K_arrayfor;
2483                                 (yyvsp[-7])->target_continue = tcont;
2484                                 (yyvsp[-7])->target_break = tbreak;
2485                                 (void) list_append(ip, (yyvsp[-7]));
2486                         } /* else
2487                                         $1 is NULL */
2488
2489                         /* add update_FOO instruction if necessary */ 
2490                         if ((yyvsp[-4])->array_var->type == Node_var && (yyvsp[-4])->array_var->var_update) {
2491                                 (void) list_append(ip, instruction(Op_var_update));
2492                                 ip->lasti->update_var = (yyvsp[-4])->array_var->var_update;
2493                         }
2494                         (void) list_append(ip, (yyvsp[-4]));
2495
2496                         /* add set_FOO instruction if necessary */
2497                         if ((yyvsp[-4])->array_var->type == Node_var && (yyvsp[-4])->array_var->var_assign) {
2498                                 (void) list_append(ip, instruction(Op_var_assign));
2499                                 ip->lasti->assign_var = (yyvsp[-4])->array_var->var_assign;
2500                         }
2501
2502                         if (do_pretty_print) {
2503                                 (void) list_append(ip, instruction(Op_exec_count));
2504                                 ((yyvsp[-7]) + 1)->forloop_cond = (yyvsp[-4]);
2505                                 ((yyvsp[-7]) + 1)->forloop_body = ip->lasti; 
2506                         }
2507
2508                         if ((yyvsp[0]) != NULL)
2509                                 (void) list_merge(ip, (yyvsp[0]));
2510
2511                         (void) list_append(ip, instruction(Op_jmp));
2512                         ip->lasti->target_jmp = (yyvsp[-4]);
2513                         (yyval) = list_append(ip, tbreak);
2514                         fix_break_continue(ip, tbreak, tcont);
2515                 } 
2516
2517                 break_allowed--;
2518                 continue_allowed--;
2519           }
2520 #line 2521 "awkgram.c" /* yacc.c:1646  */
2521     break;
2522
2523   case 49:
2524 #line 769 "awkgram.y" /* yacc.c:1646  */
2525     {
2526                 (yyval) = mk_for_loop((yyvsp[-11]), (yyvsp[-9]), (yyvsp[-6]), (yyvsp[-3]), (yyvsp[0]));
2527
2528                 break_allowed--;
2529                 continue_allowed--;
2530           }
2531 #line 2532 "awkgram.c" /* yacc.c:1646  */
2532     break;
2533
2534   case 50:
2535 #line 776 "awkgram.y" /* yacc.c:1646  */
2536     {
2537                 (yyval) = mk_for_loop((yyvsp[-10]), (yyvsp[-8]), (INSTRUCTION *) NULL, (yyvsp[-3]), (yyvsp[0]));
2538
2539                 break_allowed--;
2540                 continue_allowed--;
2541           }
2542 #line 2543 "awkgram.c" /* yacc.c:1646  */
2543     break;
2544
2545   case 51:
2546 #line 783 "awkgram.y" /* yacc.c:1646  */
2547     {
2548                 if (do_pretty_print)
2549                         (yyval) = list_prepend((yyvsp[0]), instruction(Op_exec_count));
2550                 else
2551                         (yyval) = (yyvsp[0]);
2552           }
2553 #line 2554 "awkgram.c" /* yacc.c:1646  */
2554     break;
2555
2556   case 52:
2557 #line 793 "awkgram.y" /* yacc.c:1646  */
2558     { 
2559                 if (! break_allowed)
2560                         error_ln((yyvsp[-1])->source_line,
2561                                 _("`break' is not allowed outside a loop or switch"));
2562                 (yyvsp[-1])->target_jmp = NULL;
2563                 (yyval) = list_create((yyvsp[-1]));
2564
2565           }
2566 #line 2567 "awkgram.c" /* yacc.c:1646  */
2567     break;
2568
2569   case 53:
2570 #line 802 "awkgram.y" /* yacc.c:1646  */
2571     {
2572                 if (! continue_allowed)
2573                         error_ln((yyvsp[-1])->source_line,
2574                                 _("`continue' is not allowed outside a loop"));
2575                 (yyvsp[-1])->target_jmp = NULL;
2576                 (yyval) = list_create((yyvsp[-1]));
2577
2578           }
2579 #line 2580 "awkgram.c" /* yacc.c:1646  */
2580     break;
2581
2582   case 54:
2583 #line 811 "awkgram.y" /* yacc.c:1646  */
2584     {
2585                 /* if inside function (rule = 0), resolve context at run-time */
2586                 if (rule && rule != Rule)
2587                         error_ln((yyvsp[-1])->source_line,
2588                                 _("`next' used in %s action"), ruletab[rule]);
2589                 (yyvsp[-1])->target_jmp = ip_rec;
2590                 (yyval) = list_create((yyvsp[-1]));
2591           }
2592 #line 2593 "awkgram.c" /* yacc.c:1646  */
2593     break;
2594
2595   case 55:
2596 #line 820 "awkgram.y" /* yacc.c:1646  */
2597     {
2598                 /* if inside function (rule = 0), resolve context at run-time */
2599                 if (rule == BEGIN || rule == END || rule == ENDFILE)
2600                         error_ln((yyvsp[-1])->source_line,
2601                                 _("`nextfile' used in %s action"), ruletab[rule]);
2602
2603                 (yyvsp[-1])->target_newfile = ip_newfile;
2604                 (yyvsp[-1])->target_endfile = ip_endfile;
2605                 (yyval) = list_create((yyvsp[-1]));
2606           }
2607 #line 2608 "awkgram.c" /* yacc.c:1646  */
2608     break;
2609
2610   case 56:
2611 #line 831 "awkgram.y" /* yacc.c:1646  */
2612     {
2613                 /* Initialize the two possible jump targets, the actual target
2614                  * is resolved at run-time. 
2615                  */
2616                 (yyvsp[-2])->target_end = ip_end;       /* first instruction in end_block */
2617                 (yyvsp[-2])->target_atexit = ip_atexit; /* cleanup and go home */
2618
2619                 if ((yyvsp[-1]) == NULL) {
2620                         (yyval) = list_create((yyvsp[-2]));
2621                         (void) list_prepend((yyval), instruction(Op_push_i));
2622                         (yyval)->nexti->memory = dupnode(Nnull_string);
2623                 } else
2624                         (yyval) = list_append((yyvsp[-1]), (yyvsp[-2]));
2625           }
2626 #line 2627 "awkgram.c" /* yacc.c:1646  */
2627     break;
2628
2629   case 57:
2630 #line 846 "awkgram.y" /* yacc.c:1646  */
2631     {
2632                 if (! in_function)
2633                         yyerror(_("`return' used outside function context"));
2634           }
2635 #line 2636 "awkgram.c" /* yacc.c:1646  */
2636     break;
2637
2638   case 58:
2639 #line 849 "awkgram.y" /* yacc.c:1646  */
2640     {
2641                 if ((yyvsp[-1]) == NULL) {
2642                         (yyval) = list_create((yyvsp[-3]));
2643                         (void) list_prepend((yyval), instruction(Op_push_i));
2644                         (yyval)->nexti->memory = dupnode(Nnull_string);
2645                 } else {
2646                         if (do_optimize
2647                                 && (yyvsp[-1])->lasti->opcode == Op_func_call
2648                                 && strcmp((yyvsp[-1])->lasti->func_name, in_function) == 0
2649                         ) {
2650                                 /* Do tail recursion optimization. Tail
2651                                  * call without a return value is recognized
2652                                  * in mk_function().
2653                                  */
2654                                 ((yyvsp[-1])->lasti + 1)->tail_call = true;
2655                         }
2656
2657                         (yyval) = list_append((yyvsp[-1]), (yyvsp[-3]));
2658                 }
2659           }
2660 #line 2661 "awkgram.c" /* yacc.c:1646  */
2661     break;
2662
2663   case 60:
2664 #line 881 "awkgram.y" /* yacc.c:1646  */
2665     { in_print = true; in_parens = 0; }
2666 #line 2667 "awkgram.c" /* yacc.c:1646  */
2667     break;
2668
2669   case 61:
2670 #line 882 "awkgram.y" /* yacc.c:1646  */
2671     {
2672                 /*
2673                  * Optimization: plain `print' has no expression list, so $3 is null.
2674                  * If $3 is NULL or is a bytecode list for $0 use Op_K_print_rec,
2675                  * which is faster for these two cases.
2676                  */
2677
2678                 if ((yyvsp[-3])->opcode == Op_K_print &&
2679                         ((yyvsp[-1]) == NULL
2680                                 || ((yyvsp[-1])->lasti->opcode == Op_field_spec
2681                                         && (yyvsp[-1])->nexti->nexti->nexti == (yyvsp[-1])->lasti
2682                                         && (yyvsp[-1])->nexti->nexti->opcode == Op_push_i
2683                                         && (yyvsp[-1])->nexti->nexti->memory->type == Node_val)
2684                         )
2685                 ) {
2686                         static bool warned = false;
2687                         /*   -----------------
2688                          *      output_redir
2689                          *    [ redirect exp ]
2690                          *   -----------------
2691                          *     expression_list
2692                          *   ------------------
2693                          *    [Op_K_print_rec | NULL | redir_type | expr_count]
2694                          */
2695
2696                         if ((yyvsp[-1]) != NULL) {
2697                                 NODE *n = (yyvsp[-1])->nexti->nexti->memory;
2698
2699                                 if (! iszero(n))
2700                                         goto regular_print;
2701
2702                                 bcfree((yyvsp[-1])->lasti);                     /* Op_field_spec */
2703                                 unref(n);                               /* Node_val */
2704                                 bcfree((yyvsp[-1])->nexti->nexti);              /* Op_push_i */
2705                                 bcfree((yyvsp[-1])->nexti);                     /* Op_list */
2706                                 bcfree((yyvsp[-1]));                            /* Op_list */
2707                         } else {
2708                                 if (do_lint && (rule == BEGIN || rule == END) && ! warned) {
2709                                         warned = true;
2710                                         lintwarn_ln((yyvsp[-3])->source_line,
2711                 _("plain `print' in BEGIN or END rule should probably be `print \"\"'"));
2712                                 }
2713                         }
2714
2715                         (yyvsp[-3])->expr_count = 0;
2716                         (yyvsp[-3])->opcode = Op_K_print_rec;
2717                         if ((yyvsp[0]) == NULL) {    /* no redircetion */
2718                                 (yyvsp[-3])->redir_type = redirect_none;
2719                                 (yyval) = list_create((yyvsp[-3]));
2720                         } else {
2721                                 INSTRUCTION *ip;
2722                                 ip = (yyvsp[0])->nexti;
2723                                 (yyvsp[-3])->redir_type = ip->redir_type;
2724                                 (yyvsp[0])->nexti = ip->nexti;
2725                                 bcfree(ip);
2726                                 (yyval) = list_append((yyvsp[0]), (yyvsp[-3]));
2727                         }
2728                 } else {
2729                         /*   -----------------
2730                          *    [ output_redir    ]
2731                          *    [ redirect exp    ]
2732                          *   -----------------
2733                          *    [ expression_list ]
2734                          *   ------------------
2735                          *    [$1 | NULL | redir_type | expr_count]
2736                          *
2737                          */
2738 regular_print:   
2739                         if ((yyvsp[0]) == NULL) {               /* no redirection */
2740                                 if ((yyvsp[-1]) == NULL)        {       /* printf without arg */
2741                                         (yyvsp[-3])->expr_count = 0;
2742                                         (yyvsp[-3])->redir_type = redirect_none;
2743                                         (yyval) = list_create((yyvsp[-3]));
2744                                 } else {
2745                                         INSTRUCTION *t = (yyvsp[-1]);
2746                                         (yyvsp[-3])->expr_count = count_expressions(&t, false);
2747                                         (yyvsp[-3])->redir_type = redirect_none;
2748                                         (yyval) = list_append(t, (yyvsp[-3]));
2749                                 }
2750                         } else {
2751                                 INSTRUCTION *ip;
2752                                 ip = (yyvsp[0])->nexti;
2753                                 (yyvsp[-3])->redir_type = ip->redir_type;
2754                                 (yyvsp[0])->nexti = ip->nexti;
2755                                 bcfree(ip);
2756                                 if ((yyvsp[-1]) == NULL) {
2757                                         (yyvsp[-3])->expr_count = 0;
2758                                         (yyval) = list_append((yyvsp[0]), (yyvsp[-3]));
2759                                 } else {
2760                                         INSTRUCTION *t = (yyvsp[-1]);
2761                                         (yyvsp[-3])->expr_count = count_expressions(&t, false);
2762                                         (yyval) = list_append(list_merge((yyvsp[0]), t), (yyvsp[-3]));
2763                                 }
2764                         }
2765                 }
2766           }
2767 #line 2768 "awkgram.c" /* yacc.c:1646  */
2768     break;
2769
2770   case 62:
2771 #line 979 "awkgram.y" /* yacc.c:1646  */
2772     { sub_counter = 0; }
2773 #line 2774 "awkgram.c" /* yacc.c:1646  */
2774     break;
2775
2776   case 63:
2777 #line 980 "awkgram.y" /* yacc.c:1646  */
2778     {
2779                 char *arr = (yyvsp[-2])->lextok;
2780
2781                 (yyvsp[-2])->opcode = Op_push_array;
2782                 (yyvsp[-2])->memory = variable((yyvsp[-2])->source_line, arr, Node_var_new);
2783
2784                 if (! do_posix && ! do_traditional) {
2785                         if ((yyvsp[-2])->memory == symbol_table)
2786                                 fatal(_("`delete' is not allowed with SYMTAB"));
2787                         else if ((yyvsp[-2])->memory == func_table)
2788                                 fatal(_("`delete' is not allowed with FUNCTAB"));
2789                 }
2790
2791                 if ((yyvsp[0]) == NULL) {
2792                         /*
2793                          * As of September 2012, POSIX has added support
2794                          * for `delete array'. See:
2795                          * http://austingroupbugs.net/view.php?id=544
2796                          *
2797                          * Thanks to Nathan Weeks for the initiative.
2798                          *
2799                          * Thus we no longer warn or check do_posix.
2800                          * Also, since BWK awk supports it, we don't have to
2801                          * check do_traditional either.
2802                          */
2803                         (yyvsp[-3])->expr_count = 0;
2804                         (yyval) = list_append(list_create((yyvsp[-2])), (yyvsp[-3]));
2805                 } else {
2806                         (yyvsp[-3])->expr_count = sub_counter;
2807                         (yyval) = list_append(list_append((yyvsp[0]), (yyvsp[-2])), (yyvsp[-3]));
2808                 }
2809           }
2810 #line 2811 "awkgram.c" /* yacc.c:1646  */
2811     break;
2812
2813   case 64:
2814 #line 1017 "awkgram.y" /* yacc.c:1646  */
2815     {
2816                 static bool warned = false;
2817                 char *arr = (yyvsp[-1])->lextok;
2818
2819                 if (do_lint && ! warned) {
2820                         warned = true;
2821                         lintwarn_ln((yyvsp[-3])->source_line,
2822                                 _("`delete(array)' is a non-portable tawk extension"));
2823                 }
2824                 if (do_traditional) {
2825                         error_ln((yyvsp[-3])->source_line,
2826                                 _("`delete(array)' is a non-portable tawk extension"));
2827                 }
2828                 (yyvsp[-1])->memory = variable((yyvsp[-1])->source_line, arr, Node_var_new);
2829                 (yyvsp[-1])->opcode = Op_push_array;
2830                 (yyvsp[-3])->expr_count = 0;
2831                 (yyval) = list_append(list_create((yyvsp[-1])), (yyvsp[-3]));
2832
2833                 if (! do_posix && ! do_traditional) {
2834                         if ((yyvsp[-1])->memory == symbol_table)
2835                                 fatal(_("`delete' is not allowed with SYMTAB"));
2836                         else if ((yyvsp[-1])->memory == func_table)
2837                                 fatal(_("`delete' is not allowed with FUNCTAB"));
2838                 }
2839           }
2840 #line 2841 "awkgram.c" /* yacc.c:1646  */
2841     break;
2842
2843   case 65:
2844 #line 1043 "awkgram.y" /* yacc.c:1646  */
2845     {   (yyval) = optimize_assignment((yyvsp[0])); }
2846 #line 2847 "awkgram.c" /* yacc.c:1646  */
2847     break;
2848
2849   case 66:
2850 #line 1048 "awkgram.y" /* yacc.c:1646  */
2851     { (yyval) = NULL; }
2852 #line 2853 "awkgram.c" /* yacc.c:1646  */
2853     break;
2854
2855   case 67:
2856 #line 1050 "awkgram.y" /* yacc.c:1646  */
2857     { (yyval) = (yyvsp[0]); }
2858 #line 2859 "awkgram.c" /* yacc.c:1646  */
2859     break;
2860
2861   case 68:
2862 #line 1055 "awkgram.y" /* yacc.c:1646  */
2863     { (yyval) = NULL; }
2864 #line 2865 "awkgram.c" /* yacc.c:1646  */
2865     break;
2866
2867   case 69:
2868 #line 1057 "awkgram.y" /* yacc.c:1646  */
2869     {
2870                 if ((yyvsp[-1]) == NULL)
2871                         (yyval) = list_create((yyvsp[0]));
2872                 else
2873                         (yyval) = list_prepend((yyvsp[-1]), (yyvsp[0]));
2874           }
2875 #line 2876 "awkgram.c" /* yacc.c:1646  */
2876     break;
2877
2878   case 70:
2879 #line 1064 "awkgram.y" /* yacc.c:1646  */
2880     { (yyval) = NULL; }
2881 #line 2882 "awkgram.c" /* yacc.c:1646  */
2882     break;
2883
2884   case 71:
2885 #line 1069 "awkgram.y" /* yacc.c:1646  */
2886     {
2887                 INSTRUCTION *casestmt = (yyvsp[0]);
2888                 if ((yyvsp[0]) == NULL)
2889                         casestmt = list_create(instruction(Op_no_op));  
2890                 if (do_pretty_print)
2891                         (void) list_prepend(casestmt, instruction(Op_exec_count));
2892                 (yyvsp[-4])->case_exp = (yyvsp[-3]);
2893                 (yyvsp[-4])->case_stmt = casestmt;
2894                 bcfree((yyvsp[-2]));
2895                 (yyval) = (yyvsp[-4]);
2896           }
2897 #line 2898 "awkgram.c" /* yacc.c:1646  */
2898     break;
2899
2900   case 72:
2901 #line 1081 "awkgram.y" /* yacc.c:1646  */
2902     {
2903                 INSTRUCTION *casestmt = (yyvsp[0]);
2904                 if ((yyvsp[0]) == NULL)
2905                         casestmt = list_create(instruction(Op_no_op));
2906                 if (do_pretty_print)
2907                         (void) list_prepend(casestmt, instruction(Op_exec_count));
2908                 bcfree((yyvsp[-2]));
2909                 (yyvsp[-3])->case_stmt = casestmt;
2910                 (yyval) = (yyvsp[-3]);
2911           }
2912 #line 2913 "awkgram.c" /* yacc.c:1646  */
2913     break;
2914
2915   case 73:
2916 #line 1095 "awkgram.y" /* yacc.c:1646  */
2917     {   (yyval) = (yyvsp[0]); }
2918 #line 2919 "awkgram.c" /* yacc.c:1646  */
2919     break;
2920
2921   case 74:
2922 #line 1097 "awkgram.y" /* yacc.c:1646  */
2923     { 
2924                 NODE *n = (yyvsp[0])->memory;
2925                 (void) force_number(n);
2926                 negate_num(n);
2927                 bcfree((yyvsp[-1]));
2928                 (yyval) = (yyvsp[0]);
2929           }
2930 #line 2931 "awkgram.c" /* yacc.c:1646  */
2931     break;
2932
2933   case 75:
2934 #line 1105 "awkgram.y" /* yacc.c:1646  */
2935     {
2936                 bcfree((yyvsp[-1]));
2937                 (yyval) = (yyvsp[0]);
2938           }
2939 #line 2940 "awkgram.c" /* yacc.c:1646  */
2940     break;
2941
2942   case 76:
2943 #line 1110 "awkgram.y" /* yacc.c:1646  */
2944     {   (yyval) = (yyvsp[0]); }
2945 #line 2946 "awkgram.c" /* yacc.c:1646  */
2946     break;
2947
2948   case 77:
2949 #line 1112 "awkgram.y" /* yacc.c:1646  */
2950     {
2951                 (yyvsp[0])->opcode = Op_push_re;
2952                 (yyval) = (yyvsp[0]);
2953           }
2954 #line 2955 "awkgram.c" /* yacc.c:1646  */
2955     break;
2956
2957   case 78:
2958 #line 1120 "awkgram.y" /* yacc.c:1646  */
2959     { (yyval) = (yyvsp[0]); }
2960 #line 2961 "awkgram.c" /* yacc.c:1646  */
2961     break;
2962
2963   case 79:
2964 #line 1122 "awkgram.y" /* yacc.c:1646  */
2965     { (yyval) = (yyvsp[0]); }
2966 #line 2967 "awkgram.c" /* yacc.c:1646  */
2967     break;
2968
2969   case 81:
2970 #line 1132 "awkgram.y" /* yacc.c:1646  */
2971     {
2972                 (yyval) = (yyvsp[-1]);
2973           }
2974 #line 2975 "awkgram.c" /* yacc.c:1646  */
2975     break;
2976
2977   case 82:
2978 #line 1139 "awkgram.y" /* yacc.c:1646  */
2979     {
2980                 in_print = false;
2981                 in_parens = 0;
2982                 (yyval) = NULL;
2983           }
2984 #line 2985 "awkgram.c" /* yacc.c:1646  */
2985     break;
2986
2987   case 83:
2988 #line 1144 "awkgram.y" /* yacc.c:1646  */
2989     { in_print = false; in_parens = 0; }
2990 #line 2991 "awkgram.c" /* yacc.c:1646  */
2991     break;
2992
2993   case 84:
2994 #line 1145 "awkgram.y" /* yacc.c:1646  */
2995     {
2996                 if ((yyvsp[-2])->redir_type == redirect_twoway
2997                         && (yyvsp[0])->lasti->opcode == Op_K_getline_redir
2998                                 && (yyvsp[0])->lasti->redir_type == redirect_twoway)
2999                         yyerror(_("multistage two-way pipelines don't work"));
3000                 (yyval) = list_prepend((yyvsp[0]), (yyvsp[-2]));
3001           }
3002 #line 3003 "awkgram.c" /* yacc.c:1646  */
3003     break;
3004
3005   case 85:
3006 #line 1156 "awkgram.y" /* yacc.c:1646  */
3007     {
3008                 (yyval) = mk_condition((yyvsp[-3]), (yyvsp[-5]), (yyvsp[0]), NULL, NULL);
3009           }
3010 #line 3011 "awkgram.c" /* yacc.c:1646  */
3011     break;
3012
3013   case 86:
3014 #line 1161 "awkgram.y" /* yacc.c:1646  */
3015     {
3016                 (yyval) = mk_condition((yyvsp[-6]), (yyvsp[-8]), (yyvsp[-3]), (yyvsp[-2]), (yyvsp[0]));
3017           }
3018 #line 3019 "awkgram.c" /* yacc.c:1646  */
3019     break;
3020
3021   case 91:
3022 #line 1178 "awkgram.y" /* yacc.c:1646  */
3023     { (yyval) = NULL; }
3024 #line 3025 "awkgram.c" /* yacc.c:1646  */
3025     break;
3026
3027   case 92:
3028 #line 1180 "awkgram.y" /* yacc.c:1646  */
3029     {
3030                 bcfree((yyvsp[-1]));
3031                 (yyval) = (yyvsp[0]);
3032           }
3033 #line 3034 "awkgram.c" /* yacc.c:1646  */
3034     break;
3035
3036   case 93:
3037 #line 1188 "awkgram.y" /* yacc.c:1646  */
3038     { (yyval) = NULL; }
3039 #line 3040 "awkgram.c" /* yacc.c:1646  */
3040     break;
3041
3042   case 94:
3043 #line 1190 "awkgram.y" /* yacc.c:1646  */
3044     { (yyval) = (yyvsp[0]) ; }
3045 #line 3046 "awkgram.c" /* yacc.c:1646  */
3046     break;
3047
3048   case 95:
3049 #line 1195 "awkgram.y" /* yacc.c:1646  */
3050     {
3051                 (yyvsp[0])->param_count = 0;
3052                 (yyval) = list_create((yyvsp[0]));
3053           }
3054 #line 3055 "awkgram.c" /* yacc.c:1646  */
3055     break;
3056
3057   case 96:
3058 #line 1200 "awkgram.y" /* yacc.c:1646  */
3059     {
3060                 (yyvsp[0])->param_count =  (yyvsp[-2])->lasti->param_count + 1;
3061                 (yyval) = list_append((yyvsp[-2]), (yyvsp[0]));
3062                 yyerrok;
3063           }
3064 #line 3065 "awkgram.c" /* yacc.c:1646  */
3065     break;
3066
3067   case 97:
3068 #line 1206 "awkgram.y" /* yacc.c:1646  */
3069     { (yyval) = NULL; }
3070 #line 3071 "awkgram.c" /* yacc.c:1646  */
3071     break;
3072
3073   case 98:
3074 #line 1208 "awkgram.y" /* yacc.c:1646  */
3075     { (yyval) = (yyvsp[-1]); }
3076 #line 3077 "awkgram.c" /* yacc.c:1646  */
3077     break;
3078
3079   case 99:
3080 #line 1210 "awkgram.y" /* yacc.c:1646  */
3081     { (yyval) = (yyvsp[-2]); }
3082 #line 3083 "awkgram.c" /* yacc.c:1646  */
3083     break;
3084
3085   case 100:
3086 #line 1216 "awkgram.y" /* yacc.c:1646  */
3087     { (yyval) = NULL; }
3088 #line 3089 "awkgram.c" /* yacc.c:1646  */
3089     break;
3090
3091   case 101:
3092 #line 1218 "awkgram.y" /* yacc.c:1646  */
3093     { (yyval) = (yyvsp[0]); }
3094 #line 3095 "awkgram.c" /* yacc.c:1646  */
3095     break;
3096
3097   case 102:
3098 #line 1223 "awkgram.y" /* yacc.c:1646  */
3099     { (yyval) = NULL; }
3100 #line 3101 "awkgram.c" /* yacc.c:1646  */
3101     break;
3102
3103   case 103:
3104 #line 1225 "awkgram.y" /* yacc.c:1646  */
3105     { (yyval) = (yyvsp[0]); }
3106 #line 3107 "awkgram.c" /* yacc.c:1646  */
3107     break;
3108
3109   case 104:
3110 #line 1230 "awkgram.y" /* yacc.c:1646  */
3111     {   (yyval) = mk_expression_list(NULL, (yyvsp[0])); }
3112 #line 3113 "awkgram.c" /* yacc.c:1646  */
3113     break;
3114
3115   case 105:
3116 #line 1232 "awkgram.y" /* yacc.c:1646  */
3117     {
3118                 (yyval) = mk_expression_list((yyvsp[-2]), (yyvsp[0]));
3119                 yyerrok;
3120           }
3121 #line 3122 "awkgram.c" /* yacc.c:1646  */
3122     break;
3123
3124   case 106:
3125 #line 1237 "awkgram.y" /* yacc.c:1646  */
3126     { (yyval) = NULL; }
3127 #line 3128 "awkgram.c" /* yacc.c:1646  */
3128     break;
3129
3130   case 107:
3131 #line 1239 "awkgram.y" /* yacc.c:1646  */
3132     {
3133                 /*
3134                  * Returning the expression list instead of NULL lets
3135                  * snode get a list of arguments that it can count.
3136                  */
3137                 (yyval) = (yyvsp[-1]);
3138           }
3139 #line 3140 "awkgram.c" /* yacc.c:1646  */
3140     break;
3141
3142   case 108:
3143 #line 1247 "awkgram.y" /* yacc.c:1646  */
3144     {
3145                 /* Ditto */
3146                 (yyval) = mk_expression_list((yyvsp[-2]), (yyvsp[0]));
3147           }
3148 #line 3149 "awkgram.c" /* yacc.c:1646  */
3149     break;
3150
3151   case 109:
3152 #line 1252 "awkgram.y" /* yacc.c:1646  */
3153     {
3154                 /* Ditto */
3155                 (yyval) = (yyvsp[-2]);
3156           }
3157 #line 3158 "awkgram.c" /* yacc.c:1646  */
3158     break;
3159
3160   case 110:
3161 #line 1261 "awkgram.y" /* yacc.c:1646  */
3162     {
3163                 if (do_lint && (yyvsp[0])->lasti->opcode == Op_match_rec)
3164                         lintwarn_ln((yyvsp[-1])->source_line,
3165                                 _("regular expression on right of assignment"));
3166                 (yyval) = mk_assignment((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1]));
3167           }
3168 #line 3169 "awkgram.c" /* yacc.c:1646  */
3169     break;
3170
3171   case 111:
3172 #line 1268 "awkgram.y" /* yacc.c:1646  */
3173     {   (yyval) = mk_boolean((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
3174 #line 3175 "awkgram.c" /* yacc.c:1646  */
3175     break;
3176
3177   case 112:
3178 #line 1270 "awkgram.y" /* yacc.c:1646  */
3179     {   (yyval) = mk_boolean((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
3180 #line 3181 "awkgram.c" /* yacc.c:1646  */
3181     break;
3182
3183   case 113:
3184 #line 1272 "awkgram.y" /* yacc.c:1646  */
3185     {
3186                 if ((yyvsp[-2])->lasti->opcode == Op_match_rec)
3187                         warning_ln((yyvsp[-1])->source_line,
3188                                 _("regular expression on left of `~' or `!~' operator"));
3189
3190                 if ((yyvsp[0])->lasti == (yyvsp[0])->nexti && (yyvsp[0])->nexti->opcode == Op_match_rec) {
3191                         (yyvsp[-1])->memory = (yyvsp[0])->nexti->memory;
3192                         bcfree((yyvsp[0])->nexti);      /* Op_match_rec */
3193                         bcfree((yyvsp[0]));                     /* Op_list */
3194                         (yyval) = list_append((yyvsp[-2]), (yyvsp[-1]));
3195                 } else {
3196                         (yyvsp[-1])->memory = make_regnode(Node_dynregex, NULL);
3197                         (yyval) = list_append(list_merge((yyvsp[-2]), (yyvsp[0])), (yyvsp[-1]));
3198                 }
3199           }
3200 #line 3201 "awkgram.c" /* yacc.c:1646  */
3201     break;
3202
3203   case 114:
3204 #line 1288 "awkgram.y" /* yacc.c:1646  */
3205     {
3206                 if (do_lint_old)
3207                         warning_ln((yyvsp[-1])->source_line,
3208                                 _("old awk does not support the keyword `in' except after `for'"));
3209                 (yyvsp[0])->nexti->opcode = Op_push_array;
3210                 (yyvsp[-1])->opcode = Op_in_array;
3211                 (yyvsp[-1])->expr_count = 1;
3212                 (yyval) = list_append(list_merge((yyvsp[-2]), (yyvsp[0])), (yyvsp[-1]));
3213           }
3214 #line 3215 "awkgram.c" /* yacc.c:1646  */
3215     break;
3216
3217   case 115:
3218 #line 1298 "awkgram.y" /* yacc.c:1646  */
3219     {
3220                 if (do_lint && (yyvsp[0])->lasti->opcode == Op_match_rec)
3221                         lintwarn_ln((yyvsp[-1])->source_line,
3222                                 _("regular expression on right of comparison"));
3223                 (yyval) = list_append(list_merge((yyvsp[-2]), (yyvsp[0])), (yyvsp[-1]));
3224           }
3225 #line 3226 "awkgram.c" /* yacc.c:1646  */
3226     break;
3227
3228   case 116:
3229 #line 1305 "awkgram.y" /* yacc.c:1646  */
3230     { (yyval) = mk_condition((yyvsp[-4]), (yyvsp[-3]), (yyvsp[-2]), (yyvsp[-1]), (yyvsp[0])); }
3231 #line 3232 "awkgram.c" /* yacc.c:1646  */
3232     break;
3233
3234   case 117:
3235 #line 1307 "awkgram.y" /* yacc.c:1646  */
3236     { (yyval) = (yyvsp[0]); }
3237 #line 3238 "awkgram.c" /* yacc.c:1646  */
3238     break;
3239
3240   case 118:
3241 #line 1312 "awkgram.y" /* yacc.c:1646  */
3242     { (yyval) = (yyvsp[0]); }
3243 #line 3244 "awkgram.c" /* yacc.c:1646  */
3244     break;
3245
3246   case 119:
3247 #line 1314 "awkgram.y" /* yacc.c:1646  */
3248     { (yyval) = (yyvsp[0]); }
3249 #line 3250 "awkgram.c" /* yacc.c:1646  */
3250     break;
3251
3252   case 120:
3253 #line 1316 "awkgram.y" /* yacc.c:1646  */
3254     {   
3255                 (yyvsp[0])->opcode = Op_assign_quotient;
3256                 (yyval) = (yyvsp[0]);
3257           }
3258 #line 3259 "awkgram.c" /* yacc.c:1646  */
3259     break;
3260
3261   case 121:
3262 #line 1324 "awkgram.y" /* yacc.c:1646  */
3263     { (yyval) = (yyvsp[0]); }
3264 #line 3265 "awkgram.c" /* yacc.c:1646  */
3265     break;
3266
3267   case 122:
3268 #line 1326 "awkgram.y" /* yacc.c:1646  */
3269     { (yyval) = (yyvsp[0]); }
3270 #line 3271 "awkgram.c" /* yacc.c:1646  */
3271     break;
3272
3273   case 123:
3274 #line 1331 "awkgram.y" /* yacc.c:1646  */
3275     { (yyval) = (yyvsp[0]); }
3276 #line 3277 "awkgram.c" /* yacc.c:1646  */
3277     break;
3278
3279   case 124:
3280 #line 1333 "awkgram.y" /* yacc.c:1646  */
3281     { (yyval) = (yyvsp[0]); }
3282 #line 3283 "awkgram.c" /* yacc.c:1646  */
3283     break;
3284
3285   case 125:
3286 #line 1338 "awkgram.y" /* yacc.c:1646  */
3287     { (yyval) = (yyvsp[0]); }
3288 #line 3289 "awkgram.c" /* yacc.c:1646  */
3289     break;
3290
3291   case 126:
3292 #line 1340 "awkgram.y" /* yacc.c:1646  */
3293     { (yyval) = (yyvsp[0]); }
3294 #line 3295 "awkgram.c" /* yacc.c:1646  */
3295     break;
3296
3297   case 127:
3298 #line 1342 "awkgram.y" /* yacc.c:1646  */
3299     {
3300                 int count = 2;
3301                 bool is_simple_var = false;
3302
3303                 if ((yyvsp[-1])->lasti->opcode == Op_concat) {
3304                         /* multiple (> 2) adjacent strings optimization */
3305                         is_simple_var = ((yyvsp[-1])->lasti->concat_flag & CSVAR);
3306                         count = (yyvsp[-1])->lasti->expr_count + 1;
3307                         (yyvsp[-1])->lasti->opcode = Op_no_op;
3308                 } else {
3309                         is_simple_var = ((yyvsp[-1])->nexti->opcode == Op_push
3310                                         && (yyvsp[-1])->lasti == (yyvsp[-1])->nexti); /* first exp. is a simple
3311                                                                      * variable?; kludge for use
3312                                                                      * in Op_assign_concat.
3313                                                                      */
3314                 }
3315
3316                 if (do_optimize
3317                         && (yyvsp[-1])->nexti == (yyvsp[-1])->lasti && (yyvsp[-1])->nexti->opcode == Op_push_i
3318                         && (yyvsp[0])->nexti == (yyvsp[0])->lasti && (yyvsp[0])->nexti->opcode == Op_push_i
3319                 ) {
3320                         NODE *n1 = (yyvsp[-1])->nexti->memory;
3321                         NODE *n2 = (yyvsp[0])->nexti->memory;
3322                         size_t nlen;
3323
3324                         n1 = force_string(n1);
3325                         n2 = force_string(n2);
3326                         nlen = n1->stlen + n2->stlen;
3327                         erealloc(n1->stptr, char *, nlen + 2, "constant fold");
3328                         memcpy(n1->stptr + n1->stlen, n2->stptr, n2->stlen);
3329                         n1->stlen = nlen;
3330                         n1->stptr[nlen] = '\0';
3331                         n1->flags &= ~(NUMCUR|NUMBER|NUMINT);
3332                         n1->flags |= (STRING|STRCUR);
3333                         unref(n2);
3334                         bcfree((yyvsp[0])->nexti);
3335                         bcfree((yyvsp[0]));
3336                         (yyval) = (yyvsp[-1]);
3337                 } else {
3338                         (yyval) = list_append(list_merge((yyvsp[-1]), (yyvsp[0])), instruction(Op_concat));
3339                         (yyval)->lasti->concat_flag = (is_simple_var ? CSVAR : 0);
3340                         (yyval)->lasti->expr_count = count;
3341                         if (count > max_args)
3342                                 max_args = count;
3343                 }
3344           }
3345 #line 3346 "awkgram.c" /* yacc.c:1646  */
3346     break;
3347
3348   case 129:
3349 #line 1394 "awkgram.y" /* yacc.c:1646  */
3350     { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
3351 #line 3352 "awkgram.c" /* yacc.c:1646  */
3352     break;
3353
3354   case 130:
3355 #line 1396 "awkgram.y" /* yacc.c:1646  */
3356     { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
3357 #line 3358 "awkgram.c" /* yacc.c:1646  */
3358     break;
3359
3360   case 131:
3361 #line 1398 "awkgram.y" /* yacc.c:1646  */
3362     { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
3363 #line 3364 "awkgram.c" /* yacc.c:1646  */
3364     break;
3365
3366   case 132:
3367 #line 1400 "awkgram.y" /* yacc.c:1646  */
3368     { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
3369 #line 3370 "awkgram.c" /* yacc.c:1646  */
3370     break;
3371
3372   case 133:
3373 #line 1402 "awkgram.y" /* yacc.c:1646  */
3374     { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
3375 #line 3376 "awkgram.c" /* yacc.c:1646  */
3376     break;
3377
3378   case 134:
3379 #line 1404 "awkgram.y" /* yacc.c:1646  */
3380     { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
3381 #line 3382 "awkgram.c" /* yacc.c:1646  */
3382     break;
3383
3384   case 135:
3385 #line 1406 "awkgram.y" /* yacc.c:1646  */
3386     {
3387                 /*
3388                  * In BEGINFILE/ENDFILE, allow `getline var < file'
3389                  */
3390
3391                 if (rule == BEGINFILE || rule == ENDFILE) {
3392                         if ((yyvsp[-1]) != NULL && (yyvsp[0]) != NULL)
3393                                 ;        /* all  ok */
3394                         else {
3395                                 if ((yyvsp[-1]) != NULL)
3396                                         error_ln((yyvsp[-2])->source_line,
3397                                                 _("`getline var' invalid inside `%s' rule"), ruletab[rule]);
3398                                 else
3399                                         error_ln((yyvsp[-2])->source_line,
3400                                                 _("`getline' invalid inside `%s' rule"), ruletab[rule]);
3401                         }
3402                 }
3403                 if (do_lint && rule == END && (yyvsp[0]) == NULL)
3404                         lintwarn_ln((yyvsp[-2])->source_line,
3405                                 _("non-redirected `getline' undefined inside END action"));
3406                 (yyval) = mk_getline((yyvsp[-2]), (yyvsp[-1]), (yyvsp[0]), redirect_input);
3407           }
3408 #line 3409 "awkgram.c" /* yacc.c:1646  */
3409     break;
3410
3411   case 136:
3412 #line 1429 "awkgram.y" /* yacc.c:1646  */
3413     {
3414                 (yyvsp[0])->opcode = Op_postincrement;
3415                 (yyval) = mk_assignment((yyvsp[-1]), NULL, (yyvsp[0]));
3416           }
3417 #line 3418 "awkgram.c" /* yacc.c:1646  */
3418     break;
3419
3420   case 137:
3421 #line 1434 "awkgram.y" /* yacc.c:1646  */
3422     {
3423                 (yyvsp[0])->opcode = Op_postdecrement;
3424                 (yyval) = mk_assignment((yyvsp[-1]), NULL, (yyvsp[0]));
3425           }
3426 #line 3427 "awkgram.c" /* yacc.c:1646  */
3427     break;
3428
3429   case 138:
3430 #line 1439 "awkgram.y" /* yacc.c:1646  */
3431     {
3432                 if (do_lint_old) {
3433                     warning_ln((yyvsp[-1])->source_line,
3434                                 _("old awk does not support the keyword `in' except after `for'"));
3435                     warning_ln((yyvsp[-1])->source_line,
3436                                 _("old awk does not support multidimensional arrays"));
3437                 }
3438                 (yyvsp[0])->nexti->opcode = Op_push_array;
3439                 (yyvsp[-1])->opcode = Op_in_array;
3440                 if ((yyvsp[-3]) == NULL) {      /* error */
3441                         errcount++;
3442                         (yyvsp[-1])->expr_count = 0;
3443                         (yyval) = list_merge((yyvsp[0]), (yyvsp[-1]));
3444                 } else {
3445                         INSTRUCTION *t = (yyvsp[-3]);
3446                         (yyvsp[-1])->expr_count = count_expressions(&t, false);
3447                         (yyval) = list_append(list_merge(t, (yyvsp[0])), (yyvsp[-1]));
3448                 }
3449           }
3450 #line 3451 "awkgram.c" /* yacc.c:1646  */
3451     break;
3452
3453   case 139:
3454 #line 1464 "awkgram.y" /* yacc.c:1646  */
3455     {
3456                   (yyval) = mk_getline((yyvsp[-1]), (yyvsp[0]), (yyvsp[-3]), (yyvsp[-2])->redir_type);
3457                   bcfree((yyvsp[-2]));
3458                 }
3459 #line 3460 "awkgram.c" /* yacc.c:1646  */
3460     break;
3461
3462   case 140:
3463 #line 1470 "awkgram.y" /* yacc.c:1646  */
3464     { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
3465 #line 3466 "awkgram.c" /* yacc.c:1646  */
3466     break;
3467
3468   case 141:
3469 #line 1472 "awkgram.y" /* yacc.c:1646  */
3470     { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
3471 #line 3472 "awkgram.c" /* yacc.c:1646  */
3472     break;
3473
3474   case 142:
3475 #line 1474 "awkgram.y" /* yacc.c:1646  */
3476     { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
3477 #line 3478 "awkgram.c" /* yacc.c:1646  */
3478     break;
3479
3480   case 143:
3481 #line 1476 "awkgram.y" /* yacc.c:1646  */
3482     { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
3483 #line 3484 "awkgram.c" /* yacc.c:1646  */
3484     break;
3485
3486   case 144:
3487 #line 1478 "awkgram.y" /* yacc.c:1646  */
3488     { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
3489 #line 3490 "awkgram.c" /* yacc.c:1646  */
3490     break;
3491
3492   case 145:
3493 #line 1480 "awkgram.y" /* yacc.c:1646  */
3494     { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
3495 #line 3496 "awkgram.c" /* yacc.c:1646  */
3496     break;
3497
3498   case 146:
3499 #line 1485 "awkgram.y" /* yacc.c:1646  */
3500     {
3501                 (yyval) = list_create((yyvsp[0]));
3502           }
3503 #line 3504 "awkgram.c" /* yacc.c:1646  */
3504     break;
3505
3506   case 147:
3507 #line 1489 "awkgram.y" /* yacc.c:1646  */
3508     {
3509                 if ((yyvsp[0])->opcode == Op_match_rec) {
3510                         (yyvsp[0])->opcode = Op_nomatch;
3511                         (yyvsp[-1])->opcode = Op_push_i;
3512                         (yyvsp[-1])->memory = make_number(0.0); 
3513                         (yyval) = list_append(list_append(list_create((yyvsp[-1])),
3514                                                 instruction(Op_field_spec)), (yyvsp[0]));
3515                 } else {
3516                         if (do_optimize && (yyvsp[0])->nexti == (yyvsp[0])->lasti
3517                                         && (yyvsp[0])->nexti->opcode == Op_push_i
3518                                         && ((yyvsp[0])->nexti->memory->flags & (MPFN|MPZN)) == 0
3519                         ) {
3520                                 NODE *n = (yyvsp[0])->nexti->memory;
3521                                 if ((n->flags & (STRCUR|STRING)) != 0) {
3522                                         n->numbr = (AWKNUM) (n->stlen == 0);
3523                                         n->flags &= ~(STRCUR|STRING);
3524                                         n->flags |= (NUMCUR|NUMBER);
3525                                         efree(n->stptr);
3526                                         n->stptr = NULL;
3527                                         n->stlen = 0;
3528                                 } else
3529                                         n->numbr = (AWKNUM) (n->numbr == 0.0);
3530                                 bcfree((yyvsp[-1]));
3531                                 (yyval) = (yyvsp[0]);
3532                         } else {
3533                                 (yyvsp[-1])->opcode = Op_not;
3534                                 add_lint((yyvsp[0]), LINT_assign_in_cond);
3535                                 (yyval) = list_append((yyvsp[0]), (yyvsp[-1]));
3536                         }
3537                 }
3538            }
3539 #line 3540 "awkgram.c" /* yacc.c:1646  */
3540     break;
3541
3542   case 148:
3543 #line 1521 "awkgram.y" /* yacc.c:1646  */
3544     { (yyval) = (yyvsp[-1]); }
3545 #line 3546 "awkgram.c" /* yacc.c:1646  */
3546     break;
3547
3548   case 149:
3549 #line 1523 "awkgram.y" /* yacc.c:1646  */
3550     {
3551                 (yyval) = snode((yyvsp[-1]), (yyvsp[-3]));
3552                 if ((yyval) == NULL)
3553                         YYABORT;
3554           }
3555 #line 3556 "awkgram.c" /* yacc.c:1646  */
3556     break;
3557
3558   case 150:
3559 #line 1529 "awkgram.y" /* yacc.c:1646  */
3560     {
3561                 (yyval) = snode((yyvsp[-1]), (yyvsp[-3]));
3562                 if ((yyval) == NULL)
3563                         YYABORT;
3564           }
3565 #line 3566 "awkgram.c" /* yacc.c:1646  */
3566     break;
3567
3568   case 151:
3569 #line 1535 "awkgram.y" /* yacc.c:1646  */
3570     {
3571                 static bool warned = false;
3572
3573                 if (do_lint && ! warned) {
3574                         warned = true;
3575                         lintwarn_ln((yyvsp[0])->source_line,
3576                                 _("call of `length' without parentheses is not portable"));
3577                 }
3578                 (yyval) = snode(NULL, (yyvsp[0]));
3579                 if ((yyval) == NULL)
3580                         YYABORT;
3581           }
3582 #line 3583 "awkgram.c" /* yacc.c:1646  */
3583     break;
3584
3585   case 154:
3586 #line 1550 "awkgram.y" /* yacc.c:1646  */
3587     {
3588                 (yyvsp[-1])->opcode = Op_preincrement;
3589                 (yyval) = mk_assignment((yyvsp[0]), NULL, (yyvsp[-1]));
3590           }
3591 #line 3592 "awkgram.c" /* yacc.c:1646  */
3592     break;
3593
3594   case 155:
3595 #line 1555 "awkgram.y" /* yacc.c:1646  */
3596     {
3597                 (yyvsp[-1])->opcode = Op_predecrement;
3598                 (yyval) = mk_assignment((yyvsp[0]), NULL, (yyvsp[-1]));
3599           }
3600 #line 3601 "awkgram.c" /* yacc.c:1646  */
3601     break;
3602
3603   case 156:
3604 #line 1560 "awkgram.y" /* yacc.c:1646  */
3605     {
3606                 (yyval) = list_create((yyvsp[0]));
3607           }
3608 #line 3609 "awkgram.c" /* yacc.c:1646  */
3609     break;
3610
3611   case 157:
3612 #line 1564 "awkgram.y" /* yacc.c:1646  */
3613     {
3614                 (yyval) = list_create((yyvsp[0]));
3615           }
3616 #line 3617 "awkgram.c" /* yacc.c:1646  */
3617     break;
3618
3619   case 158:
3620 #line 1568 "awkgram.y" /* yacc.c:1646  */
3621     {
3622                 if ((yyvsp[0])->lasti->opcode == Op_push_i
3623                         && ((yyvsp[0])->lasti->memory->flags & (STRCUR|STRING)) == 0
3624                 ) {
3625                         NODE *n = (yyvsp[0])->lasti->memory;
3626                         (void) force_number(n);
3627                         negate_num(n);                  
3628                         (yyval) = (yyvsp[0]);
3629                         bcfree((yyvsp[-1]));
3630                 } else {
3631                         (yyvsp[-1])->opcode = Op_unary_minus;
3632                         (yyval) = list_append((yyvsp[0]), (yyvsp[-1]));
3633                 }
3634           }
3635 #line 3636 "awkgram.c" /* yacc.c:1646  */
3636     break;
3637
3638   case 159:
3639 #line 1583 "awkgram.y" /* yacc.c:1646  */
3640     {
3641             /*
3642              * was: $$ = $2
3643              * POSIX semantics: force a conversion to numeric type
3644              */
3645                 (yyvsp[-1])->opcode = Op_plus_i;
3646                 (yyvsp[-1])->memory = make_number(0.0);
3647                 (yyval) = list_append((yyvsp[0]), (yyvsp[-1]));
3648           }
3649 #line 3650 "awkgram.c" /* yacc.c:1646  */
3650     break;
3651
3652   case 160:
3653 #line 1596 "awkgram.y" /* yacc.c:1646  */
3654     {
3655                 func_use((yyvsp[0])->lasti->func_name, FUNC_USE);
3656                 (yyval) = (yyvsp[0]);
3657           }
3658 #line 3659 "awkgram.c" /* yacc.c:1646  */
3659     break;
3660
3661   case 161:
3662 #line 1601 "awkgram.y" /* yacc.c:1646  */
3663     {
3664                 /* indirect function call */
3665                 INSTRUCTION *f, *t;
3666                 char *name;
3667                 NODE *indirect_var;
3668                 static bool warned = false;
3669                 const char *msg = _("indirect function calls are a gawk extension");
3670
3671                 if (do_traditional || do_posix)
3672                         yyerror("%s", msg);
3673                 else if (do_lint && ! warned) {
3674                         warned = true;
3675                         lintwarn("%s", msg);
3676                 }
3677                 
3678                 f = (yyvsp[0])->lasti;
3679                 f->opcode = Op_indirect_func_call;
3680                 name = estrdup(f->func_name, strlen(f->func_name));
3681                 if (is_std_var(name))
3682                         yyerror(_("can not use special variable `%s' for indirect function call"), name);
3683                 indirect_var = variable(f->source_line, name, Node_var_new);
3684                 t = instruction(Op_push);
3685                 t->memory = indirect_var;
3686
3687                 /* prepend indirect var instead of appending to arguments (opt_expression_list),
3688                  * and pop it off in setup_frame (eval.c) (left to right evaluation order); Test case:
3689                  *              f = "fun"
3690                  *              @f(f="real_fun")
3691                  */
3692
3693                 (yyval) = list_prepend((yyvsp[0]), t);
3694           }
3695 #line 3696 "awkgram.c" /* yacc.c:1646  */
3696     break;
3697
3698   case 162:
3699 #line 1637 "awkgram.y" /* yacc.c:1646  */
3700     {
3701                 param_sanity((yyvsp[-1]));
3702                 (yyvsp[-3])->opcode = Op_func_call;
3703                 (yyvsp[-3])->func_body = NULL;
3704                 if ((yyvsp[-1]) == NULL) {      /* no argument or error */
3705                         ((yyvsp[-3]) + 1)->expr_count = 0;
3706                         (yyval) = list_create((yyvsp[-3]));
3707                 } else {
3708                         INSTRUCTION *t = (yyvsp[-1]);
3709                         ((yyvsp[-3]) + 1)->expr_count = count_expressions(&t, true); 
3710                         (yyval) = list_append(t, (yyvsp[-3]));
3711                 }
3712           }
3713 #line 3714 "awkgram.c" /* yacc.c:1646  */
3714     break;
3715
3716   case 163:
3717 #line 1654 "awkgram.y" /* yacc.c:1646  */
3718     { (yyval) = NULL; }
3719 #line 3720 "awkgram.c" /* yacc.c:1646  */
3720     break;
3721
3722   case 164:
3723 #line 1656 "awkgram.y" /* yacc.c:1646  */
3724     { (yyval) = (yyvsp[0]); }
3725 #line 3726 "awkgram.c" /* yacc.c:1646  */
3726     break;
3727
3728   case 165:
3729 #line 1661 "awkgram.y" /* yacc.c:1646  */
3730     { (yyval) = NULL; }
3731 #line 3732 "awkgram.c" /* yacc.c:1646  */
3732     break;
3733
3734   case 166:
3735 #line 1663 "awkgram.y" /* yacc.c:1646  */
3736     { (yyval) = (yyvsp[-1]); }
3737 #line 3738 "awkgram.c" /* yacc.c:1646  */
3738     break;
3739
3740   case 167:
3741 #line 1668 "awkgram.y" /* yacc.c:1646  */
3742     {   (yyval) = (yyvsp[0]); }
3743 #line 3744 "awkgram.c" /* yacc.c:1646  */
3744     break;
3745
3746   case 168:
3747 #line 1670 "awkgram.y" /* yacc.c:1646  */
3748     {
3749                 (yyval) = list_merge((yyvsp[-1]), (yyvsp[0]));
3750           }
3751 #line 3752 "awkgram.c" /* yacc.c:1646  */
3752     break;
3753
3754   case 169:
3755 #line 1677 "awkgram.y" /* yacc.c:1646  */
3756     {
3757                 INSTRUCTION *ip = (yyvsp[0])->lasti; 
3758                 int count = ip->sub_count;      /* # of SUBSEP-seperated expressions */
3759                 if (count > 1) {
3760                         /* change Op_subscript or Op_sub_array to Op_concat */
3761                         ip->opcode = Op_concat;
3762                         ip->concat_flag = CSUBSEP;
3763                         ip->expr_count = count;
3764                 } else
3765                         ip->opcode = Op_no_op;
3766                 sub_counter++;  /* count # of dimensions */
3767                 (yyval) = (yyvsp[0]);
3768           }
3769 #line 3770 "awkgram.c" /* yacc.c:1646  */
3770     break;
3771
3772   case 170:
3773 #line 1694 "awkgram.y" /* yacc.c:1646  */
3774     {
3775                 INSTRUCTION *t = (yyvsp[-1]);
3776                 if ((yyvsp[-1]) == NULL) {
3777                         error_ln((yyvsp[0])->source_line,
3778                                 _("invalid subscript expression"));
3779                         /* install Null string as subscript. */
3780                         t = list_create(instruction(Op_push_i));
3781                         t->nexti->memory = dupnode(Nnull_string);
3782                         (yyvsp[0])->sub_count = 1;                      
3783                 } else
3784                         (yyvsp[0])->sub_count = count_expressions(&t, false);
3785                 (yyval) = list_append(t, (yyvsp[0]));
3786           }
3787 #line 3788 "awkgram.c" /* yacc.c:1646  */
3788     break;
3789
3790   case 171:
3791 #line 1711 "awkgram.y" /* yacc.c:1646  */
3792     {   (yyval) = (yyvsp[0]); }
3793 #line 3794 "awkgram.c" /* yacc.c:1646  */
3794     break;
3795
3796   case 172:
3797 #line 1713 "awkgram.y" /* yacc.c:1646  */
3798     {
3799                 (yyval) = list_merge((yyvsp[-1]), (yyvsp[0]));
3800           }
3801 #line 3802 "awkgram.c" /* yacc.c:1646  */
3802     break;
3803
3804   case 173:
3805 #line 1720 "awkgram.y" /* yacc.c:1646  */
3806     { (yyval) = (yyvsp[-1]); }
3807 #line 3808 "awkgram.c" /* yacc.c:1646  */
3808     break;
3809
3810   case 174:
3811 #line 1725 "awkgram.y" /* yacc.c:1646  */
3812     {
3813                 char *var_name = (yyvsp[0])->lextok;
3814
3815                 (yyvsp[0])->opcode = Op_push;
3816                 (yyvsp[0])->memory = variable((yyvsp[0])->source_line, var_name, Node_var_new);
3817                 (yyval) = list_create((yyvsp[0]));
3818           }
3819 #line 3820 "awkgram.c" /* yacc.c:1646  */
3820     break;
3821
3822   case 175:
3823 #line 1733 "awkgram.y" /* yacc.c:1646  */
3824     {
3825                 char *arr = (yyvsp[-1])->lextok;
3826                 (yyvsp[-1])->memory = variable((yyvsp[-1])->source_line, arr, Node_var_new);
3827                 (yyvsp[-1])->opcode = Op_push_array;
3828                 (yyval) = list_prepend((yyvsp[0]), (yyvsp[-1]));
3829           }
3830 #line 3831 "awkgram.c" /* yacc.c:1646  */
3831     break;
3832
3833   case 176:
3834 #line 1743 "awkgram.y" /* yacc.c:1646  */
3835     {
3836                 INSTRUCTION *ip = (yyvsp[0])->nexti;
3837                 if (ip->opcode == Op_push
3838                         && ip->memory->type == Node_var
3839                         && ip->memory->var_update
3840                 ) {
3841                         (yyval) = list_prepend((yyvsp[0]), instruction(Op_var_update));
3842                         (yyval)->nexti->update_var = ip->memory->var_update;
3843                 } else
3844                         (yyval) = (yyvsp[0]);
3845           }
3846 #line 3847 "awkgram.c" /* yacc.c:1646  */
3847     break;
3848
3849   case 177:
3850 #line 1755 "awkgram.y" /* yacc.c:1646  */
3851     {
3852                 (yyval) = list_append((yyvsp[-1]), (yyvsp[-2]));
3853                 if ((yyvsp[0]) != NULL)
3854                         mk_assignment((yyvsp[-1]), NULL, (yyvsp[0]));
3855           }
3856 #line 3857 "awkgram.c" /* yacc.c:1646  */
3857     break;
3858
3859   case 178:
3860 #line 1764 "awkgram.y" /* yacc.c:1646  */
3861     {
3862                 (yyvsp[0])->opcode = Op_postincrement;
3863           }
3864 #line 3865 "awkgram.c" /* yacc.c:1646  */
3865     break;
3866
3867   case 179:
3868 #line 1768 "awkgram.y" /* yacc.c:1646  */
3869     {
3870                 (yyvsp[0])->opcode = Op_postdecrement;
3871           }
3872 #line 3873 "awkgram.c" /* yacc.c:1646  */
3873     break;
3874
3875   case 180:
3876 #line 1771 "awkgram.y" /* yacc.c:1646  */
3877     { (yyval) = NULL; }
3878 #line 3879 "awkgram.c" /* yacc.c:1646  */
3879     break;
3880
3881   case 182:
3882 #line 1779 "awkgram.y" /* yacc.c:1646  */
3883     { yyerrok; }
3884 #line 3885 "awkgram.c" /* yacc.c:1646  */
3885     break;
3886
3887   case 183:
3888 #line 1783 "awkgram.y" /* yacc.c:1646  */
3889     { yyerrok; }
3890 #line 3891 "awkgram.c" /* yacc.c:1646  */
3891     break;
3892
3893   case 186:
3894 #line 1792 "awkgram.y" /* yacc.c:1646  */
3895     { yyerrok; }
3896 #line 3897 "awkgram.c" /* yacc.c:1646  */
3897     break;
3898
3899   case 187:
3900 #line 1796 "awkgram.y" /* yacc.c:1646  */
3901     { (yyval) = (yyvsp[0]); yyerrok; }
3902 #line 3903 "awkgram.c" /* yacc.c:1646  */
3903     break;
3904
3905   case 188:
3906 #line 1800 "awkgram.y" /* yacc.c:1646  */
3907     { yyerrok; }
3908 #line 3909 "awkgram.c" /* yacc.c:1646  */
3909     break;
3910
3911
3912 #line 3913 "awkgram.c" /* yacc.c:1646  */
3913       default: break;
3914     }
3915   /* User semantic actions sometimes alter yychar, and that requires
3916      that yytoken be updated with the new translation.  We take the
3917      approach of translating immediately before every use of yytoken.
3918      One alternative is translating here after every semantic action,
3919      but that translation would be missed if the semantic action invokes
3920      YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
3921      if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
3922      incorrect destructor might then be invoked immediately.  In the
3923      case of YYERROR or YYBACKUP, subsequent parser actions might lead
3924      to an incorrect destructor call or verbose syntax error message
3925      before the lookahead is translated.  */
3926   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
3927
3928   YYPOPSTACK (yylen);
3929   yylen = 0;
3930   YY_STACK_PRINT (yyss, yyssp);
3931
3932   *++yyvsp = yyval;
3933
3934   /* Now 'shift' the result of the reduction.  Determine what state
3935      that goes to, based on the state we popped back to and the rule
3936      number reduced by.  */
3937
3938   yyn = yyr1[yyn];
3939
3940   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
3941   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
3942     yystate = yytable[yystate];
3943   else
3944     yystate = yydefgoto[yyn - YYNTOKENS];
3945
3946   goto yynewstate;
3947
3948
3949 /*--------------------------------------.
3950 | yyerrlab -- here on detecting error.  |
3951 `--------------------------------------*/
3952 yyerrlab:
3953   /* Make sure we have latest lookahead translation.  See comments at
3954      user semantic actions for why this is necessary.  */
3955   yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
3956
3957   /* If not already recovering from an error, report this error.  */
3958   if (!yyerrstatus)
3959     {
3960       ++yynerrs;
3961 #if ! YYERROR_VERBOSE
3962       yyerror (YY_("syntax error"));
3963 #else
3964 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
3965                                         yyssp, yytoken)
3966       {
3967         char const *yymsgp = YY_("syntax error");
3968         int yysyntax_error_status;
3969         yysyntax_error_status = YYSYNTAX_ERROR;
3970         if (yysyntax_error_status == 0)
3971           yymsgp = yymsg;
3972         else if (yysyntax_error_status == 1)
3973           {
3974             if (yymsg != yymsgbuf)
3975               YYSTACK_FREE (yymsg);
3976             yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
3977             if (!yymsg)
3978               {
3979                 yymsg = yymsgbuf;
3980                 yymsg_alloc = sizeof yymsgbuf;
3981                 yysyntax_error_status = 2;
3982               }
3983             else
3984               {
3985                 yysyntax_error_status = YYSYNTAX_ERROR;
3986                 yymsgp = yymsg;
3987               }
3988           }
3989         yyerror (yymsgp);
3990         if (yysyntax_error_status == 2)
3991           goto yyexhaustedlab;
3992       }
3993 # undef YYSYNTAX_ERROR
3994 #endif
3995     }
3996
3997
3998
3999   if (yyerrstatus == 3)
4000     {
4001       /* If just tried and failed to reuse lookahead token after an
4002          error, discard it.  */
4003
4004       if (yychar <= YYEOF)
4005         {
4006           /* Return failure if at end of input.  */
4007           if (yychar == YYEOF)
4008             YYABORT;
4009         }
4010       else
4011         {
4012           yydestruct ("Error: discarding",
4013                       yytoken, &yylval);
4014           yychar = YYEMPTY;
4015         }
4016     }
4017
4018   /* Else will try to reuse lookahead token after shifting the error
4019      token.  */
4020   goto yyerrlab1;
4021
4022
4023 /*---------------------------------------------------.
4024 | yyerrorlab -- error raised explicitly by YYERROR.  |
4025 `---------------------------------------------------*/
4026 yyerrorlab:
4027
4028   /* Pacify compilers like GCC when the user code never invokes
4029      YYERROR and the label yyerrorlab therefore never appears in user
4030      code.  */
4031   if (/*CONSTCOND*/ 0)
4032      goto yyerrorlab;
4033
4034   /* Do not reclaim the symbols of the rule whose action triggered
4035      this YYERROR.  */
4036   YYPOPSTACK (yylen);
4037   yylen = 0;
4038   YY_STACK_PRINT (yyss, yyssp);
4039   yystate = *yyssp;
4040   goto yyerrlab1;
4041
4042
4043 /*-------------------------------------------------------------.
4044 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
4045 `-------------------------------------------------------------*/
4046 yyerrlab1:
4047   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
4048
4049   for (;;)
4050     {
4051       yyn = yypact[yystate];
4052       if (!yypact_value_is_default (yyn))
4053         {
4054           yyn += YYTERROR;
4055           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
4056             {
4057               yyn = yytable[yyn];
4058               if (0 < yyn)
4059                 break;
4060             }
4061         }
4062
4063       /* Pop the current state because it cannot handle the error token.  */
4064       if (yyssp == yyss)
4065         YYABORT;
4066
4067
4068       yydestruct ("Error: popping",
4069                   yystos[yystate], yyvsp);
4070       YYPOPSTACK (1);
4071       yystate = *yyssp;
4072       YY_STACK_PRINT (yyss, yyssp);
4073     }
4074
4075   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
4076   *++yyvsp = yylval;
4077   YY_IGNORE_MAYBE_UNINITIALIZED_END
4078
4079
4080   /* Shift the error token.  */
4081   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
4082
4083   yystate = yyn;
4084   goto yynewstate;
4085
4086
4087 /*-------------------------------------.
4088 | yyacceptlab -- YYACCEPT comes here.  |
4089 `-------------------------------------*/
4090 yyacceptlab:
4091   yyresult = 0;
4092   goto yyreturn;
4093
4094 /*-----------------------------------.
4095 | yyabortlab -- YYABORT comes here.  |
4096 `-----------------------------------*/
4097 yyabortlab:
4098   yyresult = 1;
4099   goto yyreturn;
4100
4101 #if !defined yyoverflow || YYERROR_VERBOSE
4102 /*-------------------------------------------------.
4103 | yyexhaustedlab -- memory exhaustion comes here.  |
4104 `-------------------------------------------------*/
4105 yyexhaustedlab:
4106   yyerror (YY_("memory exhausted"));
4107   yyresult = 2;
4108   /* Fall through.  */
4109 #endif
4110
4111 yyreturn:
4112   if (yychar != YYEMPTY)
4113     {
4114       /* Make sure we have latest lookahead translation.  See comments at
4115          user semantic actions for why this is necessary.  */
4116       yytoken = YYTRANSLATE (yychar);
4117       yydestruct ("Cleanup: discarding lookahead",
4118                   yytoken, &yylval);
4119     }
4120   /* Do not reclaim the symbols of the rule whose action triggered
4121      this YYABORT or YYACCEPT.  */
4122   YYPOPSTACK (yylen);
4123   YY_STACK_PRINT (yyss, yyssp);
4124   while (yyssp != yyss)
4125     {
4126       yydestruct ("Cleanup: popping",
4127                   yystos[*yyssp], yyvsp);
4128       YYPOPSTACK (1);
4129     }
4130 #ifndef yyoverflow
4131   if (yyss != yyssa)
4132     YYSTACK_FREE (yyss);
4133 #endif
4134 #if YYERROR_VERBOSE
4135   if (yymsg != yymsgbuf)
4136     YYSTACK_FREE (yymsg);
4137 #endif
4138   return yyresult;
4139 }
4140 #line 1802 "awkgram.y" /* yacc.c:1906  */
4141
4142
4143 struct token {
4144         const char *operator;   /* text to match */
4145         OPCODE value;                   /*  type */
4146         int class;                              /* lexical class */
4147         unsigned flags;                 /* # of args. allowed and compatability */
4148 #       define  ARGS    0xFF    /* 0, 1, 2, 3 args allowed (any combination */
4149 #       define  A(n)    (1<<(n))
4150 #       define  VERSION_MASK    0xFF00  /* old awk is zero */
4151 #       define  NOT_OLD         0x0100  /* feature not in old awk */
4152 #       define  NOT_POSIX       0x0200  /* feature not in POSIX */
4153 #       define  GAWKX           0x0400  /* gawk extension */
4154 #       define  BREAK           0x0800  /* break allowed inside */
4155 #       define  CONTINUE        0x1000  /* continue allowed inside */
4156         
4157         NODE *(*ptr)(int);      /* function that implements this keyword */
4158         NODE *(*ptr2)(int);     /* alternate arbitrary-precision function */
4159 };
4160
4161 #if 'a' == 0x81 /* it's EBCDIC */
4162 /* tokcompare --- lexicographically compare token names for sorting */
4163
4164 static int
4165 tokcompare(const void *l, const void *r)
4166 {
4167         struct token *lhs, *rhs;
4168
4169         lhs = (struct token *) l;
4170         rhs = (struct token *) r;
4171
4172         return strcmp(lhs->operator, rhs->operator);
4173 }
4174 #endif
4175
4176 /*
4177  * Tokentab is sorted ASCII ascending order, so it can be binary searched.
4178  * See check_special(), which sorts the table on EBCDIC systems.
4179  * Function pointers come from declarations in awk.h.
4180  */
4181
4182 #ifdef HAVE_MPFR
4183 #define MPF(F) do_mpfr_##F
4184 #else
4185 #define MPF(F) 0
4186 #endif
4187
4188 static const struct token tokentab[] = {
4189 {"BEGIN",       Op_rule,         LEX_BEGIN,     0,              0,      0},
4190 {"BEGINFILE",   Op_rule,         LEX_BEGINFILE, GAWKX,          0,      0},
4191 {"END",         Op_rule,         LEX_END,       0,              0,      0},
4192 {"ENDFILE",             Op_rule,         LEX_ENDFILE,   GAWKX,          0,      0},
4193 #ifdef ARRAYDEBUG
4194 {"adump",       Op_builtin,    LEX_BUILTIN,     GAWKX|A(1)|A(2),        do_adump,       0},
4195 #endif
4196 {"and",         Op_builtin,    LEX_BUILTIN,     GAWKX,          do_and, MPF(and)},
4197 {"asort",       Op_builtin,      LEX_BUILTIN,   GAWKX|A(1)|A(2)|A(3),   do_asort,       0},
4198 {"asorti",      Op_builtin,      LEX_BUILTIN,   GAWKX|A(1)|A(2)|A(3),   do_asorti,      0},
4199 {"atan2",       Op_builtin,      LEX_BUILTIN,   NOT_OLD|A(2),   do_atan2,       MPF(atan2)},
4200 {"bindtextdomain",      Op_builtin,      LEX_BUILTIN,   GAWKX|A(1)|A(2),        do_bindtextdomain,      0},
4201 {"break",       Op_K_break,      LEX_BREAK,     0,              0,      0},
4202 {"case",        Op_K_case,       LEX_CASE,      GAWKX,          0,      0},
4203 {"close",       Op_builtin,      LEX_BUILTIN,   NOT_OLD|A(1)|A(2),      do_close,       0},
4204 {"compl",       Op_builtin,    LEX_BUILTIN,     GAWKX|A(1),     do_compl,       MPF(compl)},
4205 {"continue",    Op_K_continue, LEX_CONTINUE,    0,              0,      0},
4206 {"cos",         Op_builtin,      LEX_BUILTIN,   NOT_OLD|A(1),   do_cos, MPF(cos)},
4207 {"dcgettext",   Op_builtin,      LEX_BUILTIN,   GAWKX|A(1)|A(2)|A(3),   do_dcgettext,   0},
4208 {"dcngettext",  Op_builtin,      LEX_BUILTIN,   GAWKX|A(1)|A(2)|A(3)|A(4)|A(5), do_dcngettext,  0},
4209 {"default",     Op_K_default,    LEX_DEFAULT,   GAWKX,          0,      0},
4210 {"delete",      Op_K_delete,     LEX_DELETE,    NOT_OLD,        0,      0},
4211 {"do",          Op_K_do,         LEX_DO,        NOT_OLD|BREAK|CONTINUE, 0,      0},
4212 {"else",        Op_K_else,       LEX_ELSE,      0,              0,      0},
4213 {"eval",        Op_symbol,       LEX_EVAL,      0,              0,      0},
4214 {"exit",        Op_K_exit,       LEX_EXIT,      0,              0,      0},
4215 {"exp",         Op_builtin,      LEX_BUILTIN,   A(1),           do_exp, MPF(exp)},
4216 #ifdef DYNAMIC
4217 {"extension",   Op_builtin,      LEX_BUILTIN,   GAWKX|A(1)|A(2)|A(3),   do_ext, 0},
4218 #endif
4219 {"fflush",      Op_builtin,      LEX_BUILTIN,   A(0)|A(1), do_fflush,   0},
4220 {"for",         Op_K_for,        LEX_FOR,       BREAK|CONTINUE, 0,      0},
4221 {"func",        Op_func, LEX_FUNCTION,  NOT_POSIX|NOT_OLD,      0,      0},
4222 {"function",Op_func, LEX_FUNCTION,      NOT_OLD,        0,      0},
4223 {"gensub",      Op_sub_builtin,  LEX_BUILTIN,   GAWKX|A(3)|A(4), 0,     0},
4224 {"getline",     Op_K_getline_redir,      LEX_GETLINE,   NOT_OLD,        0,      0},
4225 {"gsub",        Op_sub_builtin,  LEX_BUILTIN,   NOT_OLD|A(2)|A(3), 0,   0},
4226 {"if",          Op_K_if,         LEX_IF,        0,              0,      0},
4227 {"in",          Op_symbol,       LEX_IN,        0,              0,      0},
4228 {"include",     Op_symbol,       LEX_INCLUDE,   GAWKX,  0,      0},
4229 {"index",       Op_builtin,      LEX_BUILTIN,   A(2),           do_index,       0},
4230 {"int",         Op_builtin,      LEX_BUILTIN,   A(1),           do_int, MPF(int)},
4231 {"isarray",     Op_builtin,      LEX_BUILTIN,   GAWKX|A(1),     do_isarray,     0},
4232 {"length",      Op_builtin,      LEX_LENGTH,    A(0)|A(1),      do_length,      0},
4233 {"load",        Op_symbol,       LEX_LOAD,      GAWKX,          0,      0},
4234 {"log",         Op_builtin,      LEX_BUILTIN,   A(1),           do_log, MPF(log)},
4235 {"lshift",      Op_builtin,    LEX_BUILTIN,     GAWKX|A(2),     do_lshift,      MPF(lshift)},
4236 {"match",       Op_builtin,      LEX_BUILTIN,   NOT_OLD|A(2)|A(3), do_match,    0},
4237 {"mktime",      Op_builtin,      LEX_BUILTIN,   GAWKX|A(1),     do_mktime,      0},
4238 {"next",        Op_K_next,       LEX_NEXT,      0,              0,      0},
4239 {"nextfile",    Op_K_nextfile, LEX_NEXTFILE,    0,              0,      0},
4240 {"or",          Op_builtin,    LEX_BUILTIN,     GAWKX,          do_or,  MPF(or)},
4241 {"patsplit",    Op_builtin,    LEX_BUILTIN,     GAWKX|A(2)|A(3)|A(4), do_patsplit,      0},
4242 {"print",       Op_K_print,      LEX_PRINT,     0,              0,      0},
4243 {"printf",      Op_K_printf,     LEX_PRINTF,    0,              0,      0},
4244 {"rand",        Op_builtin,      LEX_BUILTIN,   NOT_OLD|A(0),   do_rand,        MPF(rand)},
4245 {"return",      Op_K_return,     LEX_RETURN,    NOT_OLD,        0,      0},
4246 {"rshift",      Op_builtin,    LEX_BUILTIN,     GAWKX|A(2),     do_rshift,      MPF(rshift)},
4247 {"sin",         Op_builtin,      LEX_BUILTIN,   NOT_OLD|A(1),   do_sin, MPF(sin)},
4248 {"split",       Op_builtin,      LEX_BUILTIN,   A(2)|A(3)|A(4), do_split,       0},
4249 {"sprintf",     Op_builtin,      LEX_BUILTIN,   0,              do_sprintf,     0},
4250 {"sqrt",        Op_builtin,      LEX_BUILTIN,   A(1),           do_sqrt,        MPF(sqrt)},
4251 {"srand",       Op_builtin,      LEX_BUILTIN,   NOT_OLD|A(0)|A(1), do_srand,    MPF(srand)},
4252 #if defined(GAWKDEBUG) || defined(ARRAYDEBUG) /* || ... */
4253 {"stopme",      Op_builtin,     LEX_BUILTIN,    GAWKX|A(0),     stopme,         0},
4254 #endif
4255 {"strftime",    Op_builtin,      LEX_BUILTIN,   GAWKX|A(0)|A(1)|A(2)|A(3), do_strftime, 0},
4256 {"strtonum",    Op_builtin,    LEX_BUILTIN,     GAWKX|A(1),     do_strtonum, MPF(strtonum)},
4257 {"sub",         Op_sub_builtin,  LEX_BUILTIN,   NOT_OLD|A(2)|A(3), 0,   0},
4258 {"substr",      Op_builtin,      LEX_BUILTIN,   A(2)|A(3),      do_substr,      0},
4259 {"switch",      Op_K_switch,     LEX_SWITCH,    GAWKX|BREAK,    0,      0},
4260 {"system",      Op_builtin,      LEX_BUILTIN,   NOT_OLD|A(1),   do_system,      0},
4261 {"systime",     Op_builtin,      LEX_BUILTIN,   GAWKX|A(0),     do_systime,     0},
4262 {"tolower",     Op_builtin,      LEX_BUILTIN,   NOT_OLD|A(1),   do_tolower,     0},
4263 {"toupper",     Op_builtin,      LEX_BUILTIN,   NOT_OLD|A(1),   do_toupper,     0},
4264 {"while",       Op_K_while,      LEX_WHILE,     BREAK|CONTINUE, 0,      0},
4265 {"xor",         Op_builtin,    LEX_BUILTIN,     GAWKX,          do_xor, MPF(xor)},
4266 };
4267
4268 #if MBS_SUPPORT
4269 /* Variable containing the current shift state.  */
4270 static mbstate_t cur_mbstate;
4271 /* Ring buffer containing current characters.  */
4272 #define MAX_CHAR_IN_RING_BUFFER 8
4273 #define RING_BUFFER_SIZE (MAX_CHAR_IN_RING_BUFFER * MB_LEN_MAX)
4274 static char cur_char_ring[RING_BUFFER_SIZE];
4275 /* Index for ring buffers.  */
4276 static int cur_ring_idx;
4277 /* This macro means that last nextc() return a singlebyte character
4278    or 1st byte of a multibyte character.  */
4279 #define nextc_is_1stbyte (cur_char_ring[cur_ring_idx] == 1)
4280 #else /* MBS_SUPPORT */
4281 /* a dummy */
4282 #define nextc_is_1stbyte 1
4283 #endif /* MBS_SUPPORT */
4284
4285 /* getfname --- return name of a builtin function (for pretty printing) */
4286
4287 const char *
4288 getfname(NODE *(*fptr)(int))
4289 {
4290         int i, j;
4291
4292         j = sizeof(tokentab) / sizeof(tokentab[0]);
4293         /* linear search, no other way to do it */
4294         for (i = 0; i < j; i++) 
4295                 if (tokentab[i].ptr == fptr)
4296                         return tokentab[i].operator;
4297
4298         return NULL;
4299 }
4300
4301 /* negate_num --- negate a number in NODE */
4302
4303 void
4304 negate_num(NODE *n)
4305 {
4306 #ifdef HAVE_MPFR
4307         int tval = 0;
4308 #endif
4309
4310         if (! is_mpg_number(n)) {
4311                 n->numbr = -n->numbr;
4312                 return;
4313         }
4314
4315 #ifdef HAVE_MPFR
4316         if (is_mpg_integer(n)) {
4317                 if (! iszero(n)) {
4318                         mpz_neg(n->mpg_i, n->mpg_i);
4319                         return;
4320                 }
4321
4322                 /*
4323                  * 0 --> -0 conversion. Requires turning the MPG integer
4324                  * into an MPFR float.
4325                  */
4326
4327                 mpz_clear(n->mpg_i);    /* release the integer storage */
4328
4329                 /* Convert and fall through. */
4330                 tval = mpfr_set_d(n->mpg_numbr, 0.0, ROUND_MODE);
4331                 IEEE_FMT(n->mpg_numbr, tval);
4332                 n->flags &= ~MPZN;
4333                 n->flags |= MPFN;
4334         }
4335
4336         /* mpfr float case */
4337         tval = mpfr_neg(n->mpg_numbr, n->mpg_numbr, ROUND_MODE);
4338         IEEE_FMT(n->mpg_numbr, tval);
4339 #endif
4340 }
4341
4342 /* print_included_from --- print `Included from ..' file names and locations */
4343
4344 static void
4345 print_included_from()
4346 {
4347         int saveline, line;
4348         SRCFILE *s;
4349
4350         /* suppress current file name, line # from `.. included from ..' msgs */ 
4351         saveline = sourceline;
4352         sourceline = 0;
4353
4354         for (s = sourcefile; s != NULL && s->stype == SRC_INC; ) {
4355                 s = s->next;
4356                 if (s == NULL || s->fd <= INVALID_HANDLE)
4357                         continue;
4358                 line = s->srclines;
4359
4360                 /* if last token is NEWLINE, line number is off by 1. */
4361                 if (s->lasttok == NEWLINE)
4362                         line--;
4363                 msg("%s %s:%d%c",
4364                         s->prev == sourcefile ? "In file included from"
4365                                           : "                 from",
4366                         (s->stype == SRC_INC ||
4367                                  s->stype == SRC_FILE) ? s->src : "cmd. line",
4368                         line,
4369                         s->stype == SRC_INC ? ',' : ':'
4370                 );
4371         }
4372         sourceline = saveline;
4373 }
4374
4375 /* warning_ln --- print a warning message with location */
4376
4377 static void
4378 warning_ln(int line, const char *mesg, ...)
4379 {
4380         va_list args;
4381         int saveline;
4382
4383         saveline = sourceline;
4384         sourceline = line;
4385         print_included_from();
4386         va_start(args, mesg);
4387         err(false, _("warning: "), mesg, args);
4388         va_end(args);
4389         sourceline = saveline;
4390 }
4391
4392 /* lintwarn_ln --- print a lint warning and location */
4393
4394 static void
4395 lintwarn_ln(int line, const char *mesg, ...)
4396 {
4397         va_list args;
4398         int saveline;
4399
4400         saveline = sourceline;
4401         sourceline = line;
4402         print_included_from();
4403         va_start(args, mesg);
4404         if (lintfunc == r_fatal)
4405                 err(true, _("fatal: "), mesg, args);
4406         else
4407                 err(false, _("warning: "), mesg, args);
4408         va_end(args);
4409         sourceline = saveline;
4410         if (lintfunc == r_fatal)
4411                 gawk_exit(EXIT_FATAL);
4412 }
4413
4414 /* error_ln --- print an error message and location */
4415
4416 static void
4417 error_ln(int line, const char *m, ...)
4418 {
4419         va_list args;
4420         int saveline;
4421
4422         saveline = sourceline;
4423         sourceline = line;
4424         print_included_from();
4425         errcount++;
4426         va_start(args, m);
4427         err(false, "error: ", m, args);
4428         va_end(args);
4429         sourceline = saveline;
4430 }
4431
4432 /* yyerror --- print a syntax error message, show where */
4433
4434 static void
4435 yyerror(const char *m, ...)
4436 {
4437         va_list args;
4438         const char *mesg = NULL;
4439         char *bp, *cp;
4440         char *scan;
4441         char *buf;
4442         int count;
4443         static char end_of_file_line[] = "(END OF FILE)";
4444         char save;
4445
4446         print_included_from();
4447
4448         errcount++;
4449         /* Find the current line in the input file */
4450         if (lexptr && lexeme) {
4451                 if (thisline == NULL) {
4452                         cp = lexeme;
4453                         if (*cp == '\n') {
4454                                 cp--;
4455                                 mesg = _("unexpected newline or end of string");
4456                         }
4457                         for (; cp != lexptr_begin && *cp != '\n'; --cp)
4458                                 continue;
4459                         if (*cp == '\n')
4460                                 cp++;
4461                         thisline = cp;
4462                 }
4463                 /* NL isn't guaranteed */
4464                 bp = lexeme;
4465                 while (bp < lexend && *bp && *bp != '\n')
4466                         bp++;
4467         } else {
4468                 thisline = end_of_file_line;
4469                 bp = thisline + strlen(thisline);
4470         }
4471
4472         /*
4473          * Saving and restoring *bp keeps valgrind happy,
4474          * since the guts of glibc uses strlen, even though
4475          * we're passing an explict precision. Sigh.
4476          *
4477          * 8/2003: We may not need this anymore.
4478          */
4479         save = *bp;
4480         *bp = '\0';
4481
4482         msg("%.*s", (int) (bp - thisline), thisline);
4483
4484         *bp = save;
4485         va_start(args, m);
4486         if (mesg == NULL)
4487                 mesg = m;
4488
4489         count = (bp - thisline) + strlen(mesg) + 2 + 1;
4490         emalloc(buf, char *, count, "yyerror");
4491
4492         bp = buf;
4493
4494         if (lexptr != NULL) {
4495                 scan = thisline;
4496                 while (scan < lexeme)
4497                         if (*scan++ == '\t')
4498                                 *bp++ = '\t';
4499                         else
4500                                 *bp++ = ' ';
4501                 *bp++ = '^';
4502                 *bp++ = ' ';
4503         }
4504         strcpy(bp, mesg);
4505         err(false, "", buf, args);
4506         va_end(args);
4507         efree(buf);
4508 }
4509
4510 /* mk_program --- create a single list of instructions */
4511
4512 static INSTRUCTION *
4513 mk_program()
4514 {
4515         INSTRUCTION *cp, *tmp;
4516
4517 #define begin_block         rule_block[BEGIN]
4518 #define end_block           rule_block[END]
4519 #define prog_block          rule_block[Rule]
4520 #define beginfile_block     rule_block[BEGINFILE]
4521 #define endfile_block       rule_block[ENDFILE]
4522
4523         if (end_block == NULL)
4524                 end_block = list_create(ip_end);
4525         else
4526                 (void) list_prepend(end_block, ip_end);
4527
4528         if (! in_main_context()) {
4529                 if (begin_block != NULL && prog_block != NULL)
4530                         cp = list_merge(begin_block, prog_block);
4531                 else
4532                         cp = (begin_block != NULL) ? begin_block : prog_block;
4533
4534                 if (cp != NULL)
4535                         (void) list_merge(cp, end_block);
4536                 else
4537                         cp = end_block;
4538
4539                 (void) list_append(cp, instruction(Op_stop));
4540                 goto out;
4541         }
4542
4543         if (endfile_block == NULL)
4544                 endfile_block = list_create(ip_endfile);
4545         else {
4546                 ip_rec->has_endfile = true;
4547                 (void) list_prepend(endfile_block, ip_endfile);
4548         }
4549
4550         if (beginfile_block == NULL)
4551                 beginfile_block = list_create(ip_beginfile);
4552         else
4553                 (void) list_prepend(beginfile_block, ip_beginfile);
4554
4555         if (prog_block == NULL) {
4556                 if (end_block->nexti == end_block->lasti
4557                                 && beginfile_block->nexti == beginfile_block->lasti 
4558                                 && endfile_block->nexti == endfile_block->lasti
4559                 ) {
4560                         /* no pattern-action and (real) end, beginfile or endfile blocks */
4561                         bcfree(ip_rec);
4562                         bcfree(ip_newfile);
4563                         ip_rec = ip_newfile = NULL;
4564
4565                         list_append(beginfile_block, instruction(Op_after_beginfile));
4566                         (void) list_append(endfile_block, instruction(Op_after_endfile));
4567
4568                         if (begin_block == NULL)     /* no program at all */
4569                                 cp = end_block;
4570                         else
4571                                 cp = list_merge(begin_block, end_block);
4572                         (void) list_append(cp, ip_atexit);
4573                         (void) list_append(cp, instruction(Op_stop));
4574
4575                         /* append beginfile_block and endfile_block for sole use
4576                          * in getline without redirection (Op_K_getline).
4577                          */
4578
4579                         (void) list_merge(cp, beginfile_block);
4580                         (void) list_merge(cp, endfile_block);
4581
4582                         goto out;
4583
4584                 } else {
4585                         /* install a do-nothing prog block */
4586                         prog_block = list_create(instruction(Op_no_op));
4587                 }
4588         }
4589
4590         (void) list_append(endfile_block, instruction(Op_after_endfile));
4591         (void) list_prepend(prog_block, ip_rec);
4592         (void) list_append(prog_block, instruction(Op_jmp));
4593         prog_block->lasti->target_jmp = ip_rec;
4594                 
4595         list_append(beginfile_block, instruction(Op_after_beginfile));
4596
4597         cp = list_merge(beginfile_block, prog_block);
4598         (void) list_prepend(cp, ip_newfile);
4599         (void) list_merge(cp, endfile_block);
4600         (void) list_merge(cp, end_block);
4601         if (begin_block != NULL)
4602                 cp = list_merge(begin_block, cp);
4603
4604         (void) list_append(cp, ip_atexit);
4605         (void) list_append(cp, instruction(Op_stop));
4606
4607 out:
4608         /* delete the Op_list, not needed */
4609         tmp = cp->nexti;
4610         bcfree(cp);
4611         return tmp;
4612
4613 #undef begin_block
4614 #undef end_block
4615 #undef prog_block
4616 #undef beginfile_block
4617 #undef endfile_block 
4618 }
4619
4620 /* parse_program --- read in the program and convert into a list of instructions */
4621
4622 int
4623 parse_program(INSTRUCTION **pcode)
4624 {
4625         int ret;
4626
4627         /* pre-create non-local jump targets
4628          * ip_end (Op_no_op) -- used as jump target for `exit'
4629          * outside an END block.
4630          */
4631         ip_end = instruction(Op_no_op);
4632
4633         if (! in_main_context())
4634                 ip_newfile = ip_rec = ip_atexit = ip_beginfile = ip_endfile = NULL;
4635         else {
4636                 ip_endfile = instruction(Op_no_op);
4637                 ip_beginfile = instruction(Op_no_op);
4638                 ip_rec = instruction(Op_get_record); /* target for `next', also ip_newfile */
4639                 ip_newfile = bcalloc(Op_newfile, 2, 0); /* target for `nextfile' */
4640                 ip_newfile->target_jmp = ip_end;
4641                 ip_newfile->target_endfile = ip_endfile;
4642                 (ip_newfile + 1)->target_get_record = ip_rec;
4643                 ip_rec->target_newfile = ip_newfile;
4644                 ip_atexit = instruction(Op_atexit);     /* target for `exit' in END block */
4645         }
4646
4647         for (sourcefile = srcfiles->next; sourcefile->stype == SRC_EXTLIB;
4648                         sourcefile = sourcefile->next)
4649                 ;
4650
4651         lexeof = false;
4652         lexptr = NULL;
4653         lasttok = 0;
4654         memset(rule_block, 0, sizeof(ruletab) * sizeof(INSTRUCTION *));
4655         errcount = 0;
4656         tok = tokstart != NULL ? tokstart : tokexpand();
4657
4658         ret = yyparse();
4659         *pcode = mk_program();
4660
4661         /* avoid false source indications */
4662         source = NULL;
4663         sourceline = 0;
4664         if (ret == 0)   /* avoid spurious warning if parser aborted with YYABORT */
4665                 check_funcs();
4666
4667         if (args_array == NULL)
4668                 emalloc(args_array, NODE **, (max_args + 2) * sizeof(NODE *), "parse_program");
4669         else
4670                 erealloc(args_array, NODE **, (max_args + 2) * sizeof(NODE *), "parse_program");
4671
4672         return (ret || errcount);
4673 }
4674
4675 /* do_add_srcfile --- add one item to srcfiles */
4676
4677 static SRCFILE *
4678 do_add_srcfile(enum srctype stype, char *src, char *path, SRCFILE *thisfile)
4679 {
4680         SRCFILE *s;
4681
4682         emalloc(s, SRCFILE *, sizeof(SRCFILE), "do_add_srcfile");
4683         memset(s, 0, sizeof(SRCFILE));
4684         s->src = estrdup(src, strlen(src));
4685         s->fullpath = path;
4686         s->stype = stype;
4687         s->fd = INVALID_HANDLE;
4688         s->next = thisfile;
4689         s->prev = thisfile->prev;
4690         thisfile->prev->next = s;
4691         thisfile->prev = s;
4692         return s;
4693 }
4694
4695 /* add_srcfile --- add one item to srcfiles after checking if
4696  *                              a source file exists and not already in list.
4697  */
4698
4699 SRCFILE *
4700 add_srcfile(enum srctype stype, char *src, SRCFILE *thisfile, bool *already_included, int *errcode)
4701 {
4702         SRCFILE *s;
4703         struct stat sbuf;
4704         char *path;
4705         int errno_val = 0;
4706
4707         if (already_included)
4708                 *already_included = false;
4709         if (errcode)
4710                 *errcode = 0;
4711         if (stype == SRC_CMDLINE || stype == SRC_STDIN)
4712                 return do_add_srcfile(stype, src, NULL, thisfile);
4713
4714         path = find_source(src, & sbuf, &errno_val, stype == SRC_EXTLIB);
4715         if (path == NULL) {
4716                 if (errcode) {
4717                         *errcode = errno_val;
4718                         return NULL;
4719                 }
4720                 /* use full messages to ease translation */
4721                 fatal(stype != SRC_EXTLIB
4722                         ? _("can't open source file `%s' for reading (%s)")
4723                         : _("can't open shared library `%s' for reading (%s)"),
4724                                 src,
4725                                 errno_val ? strerror(errno_val) : _("reason unknown"));
4726         }
4727
4728         /* N.B. We do not eliminate duplicate SRC_FILE (-f) programs. */
4729         for (s = srcfiles->next; s != srcfiles; s = s->next) {
4730                 if ((s->stype == SRC_FILE || s->stype == SRC_INC || s->stype == SRC_EXTLIB) && files_are_same(path, s)) {
4731                         if (stype == SRC_INC || stype == SRC_EXTLIB) {
4732                                 /* eliminate duplicates */
4733                                 if ((stype == SRC_INC) && (s->stype == SRC_FILE))
4734                                         fatal(_("can't include `%s' and use it as a program file"), src);
4735
4736                                 if (do_lint) {
4737                                         int line = sourceline;
4738                                         /* Kludge: the line number may be off for `@include file'.
4739                                          * Since, this function is also used for '-f file' in main.c,
4740                                          * sourceline > 1 check ensures that the call is at
4741                                          * parse time.
4742                                          */
4743                                         if (sourceline > 1 && lasttok == NEWLINE)
4744                                                 line--;
4745                                         lintwarn_ln(line,
4746                                                     stype != SRC_EXTLIB
4747                                                       ? _("already included source file `%s'")
4748                                                       : _("already loaded shared library `%s'"),
4749                                                     src);
4750                                 }
4751                                 efree(path);
4752                                 if (already_included)
4753                                         *already_included = true;
4754                                 return NULL;
4755                         } else {
4756                                 /* duplicates are allowed for -f */ 
4757                                 if (s->stype == SRC_INC)
4758                                         fatal(_("can't include `%s' and use it as a program file"), src);
4759                                 /* no need to scan for further matches, since
4760                                  * they must be of homogeneous type */
4761                                 break;
4762                         }
4763                 }
4764         }
4765
4766         s = do_add_srcfile(stype, src, path, thisfile);
4767         s->sbuf = sbuf;
4768         s->mtime = sbuf.st_mtime;
4769         return s;
4770 }
4771
4772 /* include_source --- read program from source included using `@include' */
4773
4774 static int
4775 include_source(INSTRUCTION *file)
4776 {
4777         SRCFILE *s;
4778         char *src = file->lextok;
4779         int errcode;
4780         bool already_included;
4781
4782         if (do_traditional || do_posix) {
4783                 error_ln(file->source_line, _("@include is a gawk extension"));
4784                 return -1;
4785         }
4786
4787         if (strlen(src) == 0) {
4788                 if (do_lint)
4789                         lintwarn_ln(file->source_line, _("empty filename after @include"));
4790                 return 0;
4791         }
4792
4793         s = add_srcfile(SRC_INC, src, sourcefile, &already_included, &errcode);
4794         if (s == NULL) {
4795                 if (already_included)
4796                         return 0;
4797                 error_ln(file->source_line,
4798                         _("can't open source file `%s' for reading (%s)"),
4799                         src, errcode ? strerror(errcode) : _("reason unknown"));
4800                 return -1;
4801         }
4802
4803         /* save scanner state for the current sourcefile */
4804         sourcefile->srclines = sourceline;
4805         sourcefile->lexptr = lexptr;
4806         sourcefile->lexend = lexend;
4807         sourcefile->lexptr_begin = lexptr_begin;        
4808         sourcefile->lexeme = lexeme;
4809         sourcefile->lasttok = lasttok;
4810
4811         /* included file becomes the current source */ 
4812         sourcefile = s;
4813         lexptr = NULL;
4814         sourceline = 0;
4815         source = NULL;
4816         lasttok = 0;
4817         lexeof = false;
4818         eof_warned = false;
4819         return 0;
4820 }
4821
4822 /* load_library --- load a shared library */
4823
4824 static int
4825 load_library(INSTRUCTION *file)
4826 {
4827         SRCFILE *s;
4828         char *src = file->lextok;
4829         int errcode;
4830         bool already_included;
4831
4832         if (do_traditional || do_posix) {
4833                 error_ln(file->source_line, _("@load is a gawk extension"));
4834                 return -1;
4835         }
4836
4837         if (strlen(src) == 0) {
4838                 if (do_lint)
4839                         lintwarn_ln(file->source_line, _("empty filename after @load"));
4840                 return 0;
4841         }
4842
4843         s = add_srcfile(SRC_EXTLIB, src, sourcefile, &already_included, &errcode);
4844         if (s == NULL) {
4845                 if (already_included)
4846                         return 0;
4847                 error_ln(file->source_line,
4848                         _("can't open shared library `%s' for reading (%s)"),
4849                         src, errcode ? strerror(errcode) : _("reason unknown"));
4850                 return -1;
4851         }
4852
4853         load_ext(s->fullpath);
4854         return 0;
4855 }
4856
4857 /* next_sourcefile --- read program from the next source in srcfiles */
4858
4859 static void
4860 next_sourcefile()
4861 {
4862         static int (*closefunc)(int fd) = NULL;
4863
4864         if (closefunc == NULL) {
4865                 char *cp = getenv("AWKREADFUNC");
4866
4867                 /* If necessary, one day, test value for different functions.  */
4868                 if (cp == NULL)
4869                         closefunc = close;
4870                 else
4871                         closefunc = one_line_close;
4872         }
4873
4874         /*
4875          * This won't be true if there's an invalid character in
4876          * the source file or source string (e.g., user typo).
4877          * Previous versions of gawk did not core dump in such a
4878          * case.
4879          *
4880          * assert(lexeof == true);
4881          */
4882
4883         lexeof = false;
4884         eof_warned = false;
4885         sourcefile->srclines = sourceline;      /* total no of lines in current file */
4886         if (sourcefile->fd > INVALID_HANDLE) {
4887                 if (sourcefile->fd != fileno(stdin))  /* safety */
4888                         (*closefunc)(sourcefile->fd);
4889                 sourcefile->fd = INVALID_HANDLE;
4890         }
4891         if (sourcefile->buf != NULL) {
4892                 efree(sourcefile->buf);
4893                 sourcefile->buf = NULL;
4894                 sourcefile->lexptr_begin = NULL;
4895         }
4896
4897         while ((sourcefile = sourcefile->next) != NULL) {
4898                 if (sourcefile == srcfiles)
4899                         return;
4900                 if (sourcefile->stype != SRC_EXTLIB)
4901                         break;
4902         }
4903
4904         if (sourcefile->lexptr_begin != NULL) {
4905                 /* resume reading from already opened file (postponed to process '@include') */
4906                 lexptr = sourcefile->lexptr;
4907                 lexend = sourcefile->lexend;
4908                 lasttok = sourcefile->lasttok;
4909                 lexptr_begin = sourcefile->lexptr_begin;
4910                 lexeme = sourcefile->lexeme;
4911                 sourceline = sourcefile->srclines;
4912                 source = sourcefile->src;
4913         } else {
4914                 lexptr = NULL;
4915                 sourceline = 0;
4916                 source = NULL;
4917                 lasttok = 0;
4918         }
4919 }
4920
4921 /* get_src_buf --- read the next buffer of source program */
4922
4923 static char *
4924 get_src_buf()
4925 {
4926         int n;
4927         char *scan;
4928         bool newfile;
4929         int savelen;
4930         struct stat sbuf;
4931
4932         /*
4933          * No argument prototype on readfunc on purpose,
4934          * avoids problems with some ancient systems where
4935          * the types of arguments to read() aren't up to date.
4936          */
4937         static ssize_t (*readfunc)() = 0;
4938
4939         if (readfunc == NULL) {
4940                 char *cp = getenv("AWKREADFUNC");
4941
4942                 /* If necessary, one day, test value for different functions.  */
4943                 if (cp == NULL)
4944                         /*
4945                          * cast is to remove warnings on systems with
4946                          * different return types for read.
4947                          */
4948                         readfunc = ( ssize_t(*)() ) read;
4949                 else
4950                         readfunc = read_one_line;
4951         }
4952
4953         newfile = false;
4954         if (sourcefile == srcfiles)
4955                 return NULL;
4956
4957         if (sourcefile->stype == SRC_CMDLINE) {
4958                 if (sourcefile->bufsize == 0) {
4959                         sourcefile->bufsize = strlen(sourcefile->src);
4960                         lexptr = lexptr_begin = lexeme = sourcefile->src;
4961                         lexend = lexptr + sourcefile->bufsize;
4962                         sourceline = 1;
4963                         if (sourcefile->bufsize == 0) {
4964                                 /*
4965                                  * Yet Another Special case:
4966                                  *      gawk '' /path/name
4967                                  * Sigh.
4968                                  */
4969                                 static bool warned = false;
4970
4971                                 if (do_lint && ! warned) {
4972                                         warned = true;
4973                                         lintwarn(_("empty program text on command line"));
4974                                 }
4975                                 lexeof = true;
4976                         }
4977                 } else if (sourcefile->buf == NULL  && *(lexptr-1) != '\n') {
4978                         /*
4979                          * The following goop is to ensure that the source
4980                          * ends with a newline and that the entire current
4981                          * line is available for error messages.
4982                          */
4983                         int offset;
4984                         char *buf;
4985
4986                         offset = lexptr - lexeme;
4987                         for (scan = lexeme; scan > lexptr_begin; scan--)
4988                                 if (*scan == '\n') {
4989                                         scan++;
4990                                         break;
4991                                 }
4992                         savelen = lexptr - scan;
4993                         emalloc(buf, char *, savelen + 1, "get_src_buf");
4994                         memcpy(buf, scan, savelen);
4995                         thisline = buf;
4996                         lexptr = buf + savelen;
4997                         *lexptr = '\n';
4998                         lexeme = lexptr - offset;
4999                         lexptr_begin = buf;
5000                         lexend = lexptr + 1;
5001                         sourcefile->buf = buf;
5002                 } else
5003                         lexeof = true;
5004                 return lexptr;
5005         }
5006
5007         if (sourcefile->fd <= INVALID_HANDLE) {
5008                 int fd;
5009                 int l;
5010
5011                 source = sourcefile->src;
5012                 if (source == NULL)
5013                         return NULL;
5014                 fd = srcopen(sourcefile);
5015                 if (fd <= INVALID_HANDLE) {
5016                         char *in;
5017
5018                         /* suppress file name and line no. in error mesg */
5019                         in = source;
5020                         source = NULL;
5021                         error(_("can't open source file `%s' for reading (%s)"),
5022                                 in, strerror(errno));
5023                         errcount++;
5024                         lexeof = true;
5025                         return sourcefile->src;
5026                 }
5027
5028                 sourcefile->fd = fd;
5029                 l = optimal_bufsize(fd, &sbuf);
5030                 /*
5031                  * Make sure that something silly like
5032                  *      AWKBUFSIZE=8 make check
5033                  * works ok.
5034                  */
5035 #define A_DECENT_BUFFER_SIZE    128
5036                 if (l < A_DECENT_BUFFER_SIZE)
5037                         l = A_DECENT_BUFFER_SIZE;
5038 #undef A_DECENT_BUFFER_SIZE
5039                 sourcefile->bufsize = l;
5040                 newfile = true;
5041                 emalloc(sourcefile->buf, char *, sourcefile->bufsize, "get_src_buf");
5042                 lexptr = lexptr_begin = lexeme = sourcefile->buf;
5043                 savelen = 0;
5044                 sourceline = 1;
5045                 thisline = NULL;
5046         } else {
5047                 /*
5048                  * Here, we retain the current source line in the beginning of the buffer.
5049                  */
5050                 int offset;
5051                 for (scan = lexeme; scan > lexptr_begin; scan--)
5052                         if (*scan == '\n') {
5053                                 scan++;
5054                                 break;
5055                         }
5056
5057                 savelen = lexptr - scan;
5058                 offset = lexptr - lexeme;
5059
5060                 if (savelen > 0) {
5061                         /*
5062                          * Need to make sure we have room left for reading new text;
5063                          * grow the buffer (by doubling, an arbitrary choice), if the retained line
5064                          * takes up more than a certain percentage (50%, again an arbitrary figure)
5065                          * of the available space.
5066                          */
5067
5068                         if (savelen > sourcefile->bufsize / 2) { /* long line or token  */
5069                                 sourcefile->bufsize *= 2;
5070                                 erealloc(sourcefile->buf, char *, sourcefile->bufsize, "get_src_buf");
5071                                 scan = sourcefile->buf + (scan - lexptr_begin);
5072                                 lexptr_begin = sourcefile->buf;
5073                         }
5074
5075                         thisline = lexptr_begin;
5076                         memmove(thisline, scan, savelen);
5077                         lexptr = thisline + savelen;
5078                         lexeme = lexptr - offset;
5079                 } else {
5080                         savelen = 0;
5081                         lexptr = lexeme = lexptr_begin;
5082                         thisline = NULL;
5083                 }
5084         }
5085
5086         n = (*readfunc)(sourcefile->fd, lexptr, sourcefile->bufsize - savelen);
5087         if (n == -1) {
5088                 error(_("can't read sourcefile `%s' (%s)"),
5089                                 source, strerror(errno));
5090                 errcount++;
5091                 lexeof = true;
5092         } else {
5093                 lexend = lexptr + n;
5094                 if (n == 0) {
5095                         static bool warned = false;
5096                         if (do_lint && newfile && ! warned){
5097                                 warned = true;
5098                                 sourceline = 0;
5099                                 lintwarn(_("source file `%s' is empty"), source);
5100                         }
5101                         lexeof = true;
5102                 }
5103         }
5104         return sourcefile->buf;
5105 }
5106
5107 /* tokadd --- add a character to the token buffer */
5108
5109 #define tokadd(x) (*tok++ = (x), tok == tokend ? tokexpand() : tok)
5110
5111 /* tokexpand --- grow the token buffer */
5112
5113 static char *
5114 tokexpand()
5115 {
5116         static int toksize;
5117         int tokoffset;
5118                         
5119         if (tokstart != NULL) {
5120                 tokoffset = tok - tokstart;
5121                 toksize *= 2;
5122                 erealloc(tokstart, char *, toksize, "tokexpand");
5123                 tok = tokstart + tokoffset;
5124         } else {
5125                 toksize = 60;
5126                 emalloc(tokstart, char *, toksize, "tokexpand");
5127                 tok = tokstart;
5128         }
5129         tokend = tokstart + toksize;
5130         return tok;
5131 }
5132
5133 /* nextc --- get the next input character */
5134
5135 #if MBS_SUPPORT
5136
5137 static int
5138 nextc(void)
5139 {
5140         if (gawk_mb_cur_max > 1) {
5141 again:
5142                 if (lexeof)
5143                         return END_FILE;
5144                 if (lexptr == NULL || lexptr >= lexend) {
5145                         if (get_src_buf())
5146                                 goto again;
5147                         return END_SRC;
5148                 }
5149
5150                 /* Update the buffer index.  */
5151                 cur_ring_idx = (cur_ring_idx == RING_BUFFER_SIZE - 1)? 0 :
5152                         cur_ring_idx + 1;
5153
5154                 /* Did we already check the current character?  */
5155                 if (cur_char_ring[cur_ring_idx] == 0) {
5156                         /* No, we need to check the next character on the buffer.  */
5157                         int idx, work_ring_idx = cur_ring_idx;
5158                         mbstate_t tmp_state;
5159                         size_t mbclen;
5160         
5161                         for (idx = 0 ; lexptr + idx < lexend ; idx++) {
5162                                 tmp_state = cur_mbstate;
5163                                 mbclen = mbrlen(lexptr, idx + 1, &tmp_state);
5164
5165                                 if (mbclen == 1 || mbclen == (size_t)-1 || mbclen == 0) {
5166                                         /* It is a singlebyte character, non-complete multibyte
5167                                            character or EOF.  We treat it as a singlebyte
5168                                            character.  */
5169                                         cur_char_ring[work_ring_idx] = 1;
5170                                         break;
5171                                 } else if (mbclen == (size_t)-2) {
5172                                         /* It is not a complete multibyte character.  */
5173                                         cur_char_ring[work_ring_idx] = idx + 1;
5174                                 } else {
5175                                         /* mbclen > 1 */
5176                                         cur_char_ring[work_ring_idx] = mbclen;
5177                                         break;
5178                                 }
5179                                 work_ring_idx = (work_ring_idx == RING_BUFFER_SIZE - 1)?
5180                                         0 : work_ring_idx + 1;
5181                         }
5182                         cur_mbstate = tmp_state;
5183
5184                         /* Put a mark on the position on which we write next character.  */
5185                         work_ring_idx = (work_ring_idx == RING_BUFFER_SIZE - 1)?
5186                                 0 : work_ring_idx + 1;
5187                         cur_char_ring[work_ring_idx] = 0;
5188                 }
5189
5190                 return (int) (unsigned char) *lexptr++;
5191         } else {
5192                 do {
5193                         if (lexeof)
5194                                 return END_FILE;
5195                         if (lexptr && lexptr < lexend)
5196                                         return ((int) (unsigned char) *lexptr++);
5197                 } while (get_src_buf());
5198                 return END_SRC;
5199         }
5200 }
5201
5202 #else /* MBS_SUPPORT */
5203
5204 int
5205 nextc()
5206 {
5207         do {
5208                 if (lexeof)
5209                         return END_FILE;
5210                 if (lexptr && lexptr < lexend)
5211                         return ((int) (unsigned char) *lexptr++);
5212         } while (get_src_buf());
5213         return END_SRC;
5214 }
5215
5216 #endif /* MBS_SUPPORT */
5217
5218 /* pushback --- push a character back on the input */
5219
5220 static inline void
5221 pushback(void)
5222 {
5223 #if MBS_SUPPORT
5224         if (gawk_mb_cur_max > 1)
5225                 cur_ring_idx = (cur_ring_idx == 0)? RING_BUFFER_SIZE - 1 :
5226                         cur_ring_idx - 1;
5227 #endif
5228         (! lexeof && lexptr && lexptr > lexptr_begin ? lexptr-- : lexptr);
5229 }
5230
5231
5232 /* allow_newline --- allow newline after &&, ||, ? and : */
5233
5234 static void
5235 allow_newline(void)
5236 {
5237         int c;
5238
5239         for (;;) {
5240                 c = nextc();
5241                 if (c == END_FILE) {
5242                         pushback();
5243                         break;
5244                 }
5245                 if (c == '#') {
5246                         while ((c = nextc()) != '\n' && c != END_FILE)
5247                                 continue;
5248                         if (c == END_FILE) {
5249                                 pushback();
5250                                 break;
5251                         }
5252                 }
5253                 if (c == '\n')
5254                         sourceline++;
5255                 if (! isspace(c)) {
5256                         pushback();
5257                         break;
5258                 }
5259         }
5260 }
5261
5262 /* newline_eof --- return newline or EOF as needed and adjust variables */
5263
5264 /*
5265  * This routine used to be a macro, however GCC 4.6.2 warned about
5266  * the result of a computation not being used.  Converting to a function
5267  * removes the warnings.
5268  */
5269
5270 static int newline_eof()
5271 {
5272         /* NB: a newline at end does not start a source line. */
5273         if (lasttok != NEWLINE) {
5274                 pushback();
5275                 if (do_lint && ! eof_warned) {
5276                         lintwarn(_("source file does not end in newline"));
5277                         eof_warned = true;
5278                 }
5279                 sourceline++;
5280                 return NEWLINE;
5281         }
5282
5283         sourceline--;
5284         eof_warned = false;
5285         return LEX_EOF;
5286 }
5287
5288 /* yylex --- Read the input and turn it into tokens. */
5289
5290 static int
5291 yylex(void)
5292 {
5293         int c;
5294         bool seen_e = false;            /* These are for numbers */
5295         bool seen_point = false;
5296         bool esc_seen;          /* for literal strings */
5297         int mid;
5298         int base;
5299         static bool did_newline = false;
5300         char *tokkey;
5301         bool inhex = false;
5302         bool intlstr = false;
5303         AWKNUM d;
5304
5305 #define GET_INSTRUCTION(op) bcalloc(op, 1, sourceline)
5306
5307 #define NEWLINE_EOF newline_eof()
5308
5309         yylval = (INSTRUCTION *) NULL;
5310         if (lasttok == SUBSCRIPT) {
5311                 lasttok = 0;
5312                 return SUBSCRIPT;
5313         }
5314  
5315         if (lasttok == LEX_EOF)         /* error earlier in current source, must give up !! */
5316                 return 0;
5317
5318         c = nextc();
5319         if (c == END_SRC)
5320                 return 0;
5321         if (c == END_FILE)
5322                 return lasttok = NEWLINE_EOF;
5323         pushback();
5324
5325 #if defined __EMX__
5326         /*
5327          * added for OS/2's extproc feature of cmd.exe
5328          * (like #! in BSD sh)
5329          */
5330         if (strncasecmp(lexptr, "extproc ", 8) == 0) {
5331                 while (*lexptr && *lexptr != '\n')
5332                         lexptr++;
5333         }
5334 #endif
5335
5336         lexeme = lexptr;
5337         thisline = NULL;
5338         if (want_regexp) {
5339                 int in_brack = 0;       /* count brackets, [[:alnum:]] allowed */
5340                 /*
5341                  * Counting brackets is non-trivial. [[] is ok,
5342                  * and so is [\]], with a point being that /[/]/ as a regexp
5343                  * constant has to work.
5344                  *
5345                  * Do not count [ or ] if either one is preceded by a \.
5346                  * A `[' should be counted if
5347                  *  a) it is the first one so far (in_brack == 0)
5348                  *  b) it is the `[' in `[:'
5349                  * A ']' should be counted if not preceded by a \, since
5350                  * it is either closing `:]' or just a plain list.
5351                  * According to POSIX, []] is how you put a ] into a set.
5352                  * Try to handle that too.
5353                  *
5354                  * The code for \ handles \[ and \].
5355                  */
5356
5357                 want_regexp = false;
5358                 tok = tokstart;
5359                 for (;;) {
5360                         c = nextc();
5361
5362                         if (gawk_mb_cur_max == 1 || nextc_is_1stbyte) switch (c) {
5363                         case '[':
5364                                 /* one day check for `.' and `=' too */
5365                                 if (nextc() == ':' || in_brack == 0)
5366                                         in_brack++;
5367                                 pushback();
5368                                 break;
5369                         case ']':
5370                                 if (tokstart[0] == '['
5371                                     && (tok == tokstart + 1
5372                                         || (tok == tokstart + 2
5373                                             && tokstart[1] == '^')))
5374                                         /* do nothing */;
5375                                 else
5376                                         in_brack--;
5377                                 break;
5378                         case '\\':
5379                                 if ((c = nextc()) == END_FILE) {
5380                                         pushback();
5381                                         yyerror(_("unterminated regexp ends with `\\' at end of file"));
5382                                         goto end_regexp; /* kludge */
5383                                 } else if (c == '\n') {
5384                                         sourceline++;
5385                                         continue;
5386                                 } else {
5387                                         tokadd('\\');
5388                                         tokadd(c);
5389                                         continue;
5390                                 }
5391                                 break;
5392                         case '/':       /* end of the regexp */
5393                                 if (in_brack > 0)
5394                                         break;
5395 end_regexp:
5396                                 yylval = GET_INSTRUCTION(Op_token);
5397                                 yylval->lextok = estrdup(tokstart, tok - tokstart);
5398                                 if (do_lint) {
5399                                         int peek = nextc();
5400
5401                                         pushback();
5402                                         if (peek == 'i' || peek == 's') {
5403                                                 if (source)
5404                                                         lintwarn(
5405                                                 _("%s: %d: tawk regex modifier `/.../%c' doesn't work in gawk"),
5406                                                                 source, sourceline, peek);
5407                                                 else
5408                                                         lintwarn(
5409                                                 _("tawk regex modifier `/.../%c' doesn't work in gawk"),
5410                                                                 peek);
5411                                         }
5412                                 }
5413                                 return lasttok = REGEXP;
5414                         case '\n':
5415                                 pushback();
5416                                 yyerror(_("unterminated regexp"));
5417                                 goto end_regexp;        /* kludge */
5418                         case END_FILE:
5419                                 pushback();
5420                                 yyerror(_("unterminated regexp at end of file"));
5421                                 goto end_regexp;        /* kludge */
5422                         }
5423                         tokadd(c);
5424                 }
5425         }
5426 retry:
5427
5428         /* skipping \r is a hack, but windows is just too pervasive. sigh. */
5429         while ((c = nextc()) == ' ' || c == '\t' || c == '\r')
5430                 continue;
5431
5432         lexeme = lexptr ? lexptr - 1 : lexptr;
5433         thisline = NULL;
5434         tok = tokstart;
5435
5436 #if MBS_SUPPORT
5437         if (gawk_mb_cur_max == 1 || nextc_is_1stbyte)
5438 #endif
5439         switch (c) {
5440         case END_SRC:
5441                 return 0;
5442
5443         case END_FILE:
5444                 return lasttok = NEWLINE_EOF;
5445
5446         case '\n':
5447                 sourceline++;
5448                 return lasttok = NEWLINE;
5449
5450         case '#':               /* it's a comment */
5451                 while ((c = nextc()) != '\n') {
5452                         if (c == END_FILE)
5453                                 return lasttok = NEWLINE_EOF;
5454                 }
5455                 sourceline++;
5456                 return lasttok = NEWLINE;
5457
5458         case '@':
5459                 return lasttok = '@';
5460
5461         case '\\':
5462 #ifdef RELAXED_CONTINUATION
5463                 /*
5464                  * This code puports to allow comments and/or whitespace
5465                  * after the `\' at the end of a line used for continuation.
5466                  * Use it at your own risk. We think it's a bad idea, which
5467                  * is why it's not on by default.
5468                  */
5469                 if (! do_traditional) {
5470                         /* strip trailing white-space and/or comment */
5471                         while ((c = nextc()) == ' ' || c == '\t' || c == '\r')
5472                                 continue;
5473                         if (c == '#') {
5474                                 static bool warned = false;
5475
5476                                 if (do_lint && ! warned) {
5477                                         warned = true;
5478                                         lintwarn(
5479                 _("use of `\\ #...' line continuation is not portable"));
5480                                 }
5481                                 while ((c = nextc()) != '\n')
5482                                         if (c == END_FILE)
5483                                                 break;
5484                         }
5485                         pushback();
5486                 }
5487 #endif /* RELAXED_CONTINUATION */
5488                 c = nextc();
5489                 if (c == '\r')  /* allow MS-DOS files. bleah */
5490                         c = nextc();
5491                 if (c == '\n') {
5492                         sourceline++;
5493                         goto retry;
5494                 } else {
5495                         yyerror(_("backslash not last character on line"));
5496                         return lasttok = LEX_EOF;
5497                 }
5498                 break;
5499
5500         case ':':
5501         case '?':
5502                 yylval = GET_INSTRUCTION(Op_cond_exp);
5503                 if (! do_posix)
5504                         allow_newline();
5505                 return lasttok = c;
5506
5507                 /*
5508                  * in_parens is undefined unless we are parsing a print
5509                  * statement (in_print), but why bother with a check?
5510                  */
5511         case ')':
5512                 in_parens--;
5513                 return lasttok = c;
5514
5515         case '(':       
5516                 in_parens++;
5517                 return lasttok = c;
5518         case '$':
5519                 yylval = GET_INSTRUCTION(Op_field_spec);
5520                 return lasttok = c;
5521         case '{':
5522                 if (++in_braces == 1)
5523                         firstline = sourceline;
5524         case ';':
5525         case ',':
5526         case '[':
5527                         return lasttok = c;
5528         case ']':
5529                 c = nextc();
5530                 pushback();
5531                 if (c == '[') {
5532                         yylval = GET_INSTRUCTION(Op_sub_array);
5533                         lasttok = ']';
5534                 } else {
5535                         yylval = GET_INSTRUCTION(Op_subscript);
5536                         lasttok = SUBSCRIPT;    /* end of subscripts */
5537                 }
5538                 return ']';
5539
5540         case '*':
5541                 if ((c = nextc()) == '=') {
5542                         yylval = GET_INSTRUCTION(Op_assign_times);
5543                         return lasttok = ASSIGNOP;
5544                 } else if (do_posix) {
5545                         pushback();
5546                         yylval = GET_INSTRUCTION(Op_times);
5547                         return lasttok = '*';
5548                 } else if (c == '*') {
5549                         /* make ** and **= aliases for ^ and ^= */
5550                         static bool did_warn_op = false, did_warn_assgn = false;
5551
5552                         if (nextc() == '=') {
5553                                 if (! did_warn_assgn) {
5554                                         did_warn_assgn = true;
5555                                         if (do_lint)
5556                                                 lintwarn(_("POSIX does not allow operator `**='"));
5557                                         if (do_lint_old)
5558                                                 warning(_("old awk does not support operator `**='"));
5559                                 }
5560                                 yylval = GET_INSTRUCTION(Op_assign_exp);
5561                                 return ASSIGNOP;
5562                         } else {
5563                                 pushback();
5564                                 if (! did_warn_op) {
5565                                         did_warn_op = true;
5566                                         if (do_lint)
5567                                                 lintwarn(_("POSIX does not allow operator `**'"));
5568                                         if (do_lint_old)
5569                                                 warning(_("old awk does not support operator `**'"));
5570                                 }
5571                                 yylval = GET_INSTRUCTION(Op_exp);
5572                                 return lasttok = '^';
5573                         }
5574                 }
5575                 pushback();
5576                 yylval = GET_INSTRUCTION(Op_times);
5577                 return lasttok = '*';
5578
5579         case '/':
5580                 if (nextc() == '=') {
5581                         pushback();
5582                         return lasttok = SLASH_BEFORE_EQUAL;
5583                 }
5584                 pushback();
5585                 yylval = GET_INSTRUCTION(Op_quotient);
5586                 return lasttok = '/';
5587
5588         case '%':
5589                 if (nextc() == '=') {
5590                         yylval = GET_INSTRUCTION(Op_assign_mod);
5591                         return lasttok = ASSIGNOP;
5592                 }
5593                 pushback();
5594                 yylval = GET_INSTRUCTION(Op_mod);
5595                 return lasttok = '%';
5596
5597         case '^':
5598         {
5599                 static bool did_warn_op = false, did_warn_assgn = false;
5600
5601                 if (nextc() == '=') {
5602                         if (do_lint_old && ! did_warn_assgn) {
5603                                 did_warn_assgn = true;
5604                                 warning(_("operator `^=' is not supported in old awk"));
5605                         }
5606                         yylval = GET_INSTRUCTION(Op_assign_exp);
5607                         return lasttok = ASSIGNOP;
5608                 }
5609                 pushback();
5610                 if (do_lint_old && ! did_warn_op) {
5611                         did_warn_op = true;
5612                         warning(_("operator `^' is not supported in old awk"));
5613                 }
5614                 yylval = GET_INSTRUCTION(Op_exp);       
5615                 return lasttok = '^';
5616         }
5617
5618         case '+':
5619                 if ((c = nextc()) == '=') {
5620                         yylval = GET_INSTRUCTION(Op_assign_plus);
5621                         return lasttok = ASSIGNOP;
5622                 }
5623                 if (c == '+') {
5624                         yylval = GET_INSTRUCTION(Op_symbol);
5625                         return lasttok = INCREMENT;
5626                 }
5627                 pushback();
5628                 yylval = GET_INSTRUCTION(Op_plus);
5629                 return lasttok = '+';
5630
5631         case '!':
5632                 if ((c = nextc()) == '=') {
5633                         yylval = GET_INSTRUCTION(Op_notequal);
5634                         return lasttok = RELOP;
5635                 }
5636                 if (c == '~') {
5637                         yylval = GET_INSTRUCTION(Op_nomatch);
5638                         return lasttok = MATCHOP;
5639                 }
5640                 pushback();
5641                 yylval = GET_INSTRUCTION(Op_symbol);
5642                 return lasttok = '!';
5643
5644         case '<':
5645                 if (nextc() == '=') {
5646                         yylval = GET_INSTRUCTION(Op_leq);
5647                         return lasttok = RELOP;
5648                 }
5649                 yylval = GET_INSTRUCTION(Op_less);
5650                 pushback();
5651                 return lasttok = '<';
5652
5653         case '=':
5654                 if (nextc() == '=') {
5655                         yylval = GET_INSTRUCTION(Op_equal);
5656                         return lasttok = RELOP;
5657                 }
5658                 yylval = GET_INSTRUCTION(Op_assign);
5659                 pushback();
5660                 return lasttok = ASSIGN;
5661
5662         case '>':
5663                 if ((c = nextc()) == '=') {
5664                         yylval = GET_INSTRUCTION(Op_geq);
5665                         return lasttok = RELOP;
5666                 } else if (c == '>') {
5667                         yylval = GET_INSTRUCTION(Op_symbol);
5668                         yylval->redir_type = redirect_append;
5669                         return lasttok = IO_OUT;
5670                 }
5671                 pushback();
5672                 if (in_print && in_parens == 0) {
5673                         yylval = GET_INSTRUCTION(Op_symbol);
5674                         yylval->redir_type = redirect_output;
5675                         return lasttok = IO_OUT;
5676                 }
5677                 yylval = GET_INSTRUCTION(Op_greater);
5678                 return lasttok = '>';
5679
5680         case '~':
5681                 yylval = GET_INSTRUCTION(Op_match);
5682                 return lasttok = MATCHOP;
5683
5684         case '}':
5685                 /*
5686                  * Added did newline stuff.  Easier than
5687                  * hacking the grammar.
5688                  */
5689                 if (did_newline) {
5690                         did_newline = false;
5691                         if (--in_braces == 0)
5692                                 lastline = sourceline;
5693                         return lasttok = c;
5694                 }
5695                 did_newline++;
5696                 --lexptr;       /* pick up } next time */
5697                 return lasttok = NEWLINE;
5698
5699         case '"':
5700         string:
5701                 esc_seen = false;
5702                 while ((c = nextc()) != '"') {
5703                         if (c == '\n') {
5704                                 pushback();
5705                                 yyerror(_("unterminated string"));
5706                                 return lasttok = LEX_EOF;
5707                         }
5708                         if ((gawk_mb_cur_max == 1 || nextc_is_1stbyte) &&
5709                             c == '\\') {
5710                                 c = nextc();
5711                                 if (c == '\n') {
5712                                         sourceline++;
5713                                         continue;
5714                                 }
5715                                 esc_seen = true;
5716                                 if (! want_source || c != '"')
5717                                         tokadd('\\');
5718                         }
5719                         if (c == END_FILE) {
5720                                 pushback();
5721                                 yyerror(_("unterminated string"));
5722                                 return lasttok = LEX_EOF;
5723                         }
5724                         tokadd(c);
5725                 }
5726                 yylval = GET_INSTRUCTION(Op_token);
5727                 if (want_source) {
5728                         yylval->lextok = estrdup(tokstart, tok - tokstart);
5729                         return lasttok = FILENAME;
5730                 }
5731                 
5732                 yylval->opcode = Op_push_i;
5733                 yylval->memory = make_str_node(tokstart,
5734                                         tok - tokstart, esc_seen ? SCAN : 0);
5735                 if (intlstr) {
5736                         yylval->memory->flags |= INTLSTR;
5737                         intlstr = false;
5738                         if (do_intl)
5739                                 dumpintlstr(yylval->memory->stptr, yylval->memory->stlen);
5740                 }
5741                 return lasttok = YSTRING;
5742
5743         case '-':
5744                 if ((c = nextc()) == '=') {
5745                         yylval = GET_INSTRUCTION(Op_assign_minus);
5746                         return lasttok = ASSIGNOP;
5747                 }
5748                 if (c == '-') {
5749                         yylval = GET_INSTRUCTION(Op_symbol);
5750                         return lasttok = DECREMENT;
5751                 }
5752                 pushback();
5753                 yylval = GET_INSTRUCTION(Op_minus);
5754                 return lasttok = '-';
5755
5756         case '.':
5757                 c = nextc();
5758                 pushback();
5759                 if (! isdigit(c))
5760                         return lasttok = '.';
5761                 else
5762                         c = '.';
5763                 /* FALL THROUGH */
5764         case '0':
5765         case '1':
5766         case '2':
5767         case '3':
5768         case '4':
5769         case '5':
5770         case '6':
5771         case '7':
5772         case '8':
5773         case '9':
5774                 /* It's a number */
5775                 for (;;) {
5776                         bool gotnumber = false;
5777
5778                         tokadd(c);
5779                         switch (c) {
5780                         case 'x':
5781                         case 'X':
5782                                 if (do_traditional)
5783                                         goto done;
5784                                 if (tok == tokstart + 2) {
5785                                         int peek = nextc();
5786
5787                                         if (isxdigit(peek)) {
5788                                                 inhex = true;
5789                                                 pushback();     /* following digit */
5790                                         } else {
5791                                                 pushback();     /* x or X */
5792                                                 goto done;
5793                                         }
5794                                 }
5795                                 break;
5796                         case '.':
5797                                 /* period ends exponent part of floating point number */
5798                                 if (seen_point || seen_e) {
5799                                         gotnumber = true;
5800                                         break;
5801                                 }
5802                                 seen_point = true;
5803                                 break;
5804                         case 'e':
5805                         case 'E':
5806                                 if (inhex)
5807                                         break;
5808                                 if (seen_e) {
5809                                         gotnumber = true;
5810                                         break;
5811                                 }
5812                                 seen_e = true;
5813                                 if ((c = nextc()) == '-' || c == '+') {
5814                                         int c2 = nextc();
5815
5816                                         if (isdigit(c2)) {
5817                                                 tokadd(c);
5818                                                 tokadd(c2);
5819                                         } else {
5820                                                 pushback();     /* non-digit after + or - */
5821                                                 pushback();     /* + or - */
5822                                                 pushback();     /* e or E */
5823                                         }
5824                                 } else if (! isdigit(c)) {
5825                                         pushback();     /* character after e or E */
5826                                         pushback();     /* e or E */
5827                                 } else {
5828                                         pushback();     /* digit */
5829                                 }
5830                                 break;
5831                         case 'a':
5832                         case 'A':
5833                         case 'b':
5834                         case 'B':
5835                         case 'c':
5836                         case 'C':
5837                         case 'D':
5838                         case 'd':
5839                         case 'f':
5840                         case 'F':
5841                                 if (do_traditional || ! inhex)
5842                                         goto done;
5843                                 /* fall through */
5844                         case '0':
5845                         case '1':
5846                         case '2':
5847                         case '3':
5848                         case '4':
5849                         case '5':
5850                         case '6':
5851                         case '7':
5852                         case '8':
5853                         case '9':
5854                                 break;
5855                         default:
5856                         done:
5857                                 gotnumber = true;
5858                         }
5859                         if (gotnumber)
5860                                 break;
5861                         c = nextc();
5862                 }
5863                 pushback();
5864
5865                 tokadd('\0');
5866                 yylval = GET_INSTRUCTION(Op_push_i);
5867
5868                 base = 10;
5869                 if (! do_traditional) {
5870                         base = get_numbase(tokstart, false);
5871                         if (do_lint) {
5872                                 if (base == 8)
5873                                         lintwarn("numeric constant `%.*s' treated as octal",
5874                                                 (int) strlen(tokstart)-1, tokstart);
5875                                 else if (base == 16)
5876                                         lintwarn("numeric constant `%.*s' treated as hexadecimal",
5877                                                 (int) strlen(tokstart)-1, tokstart);
5878                         }
5879                 }
5880
5881 #ifdef HAVE_MPFR
5882                 if (do_mpfr) {
5883                         NODE *r;
5884
5885                         if (! seen_point && ! seen_e) {
5886                                 r = mpg_integer();
5887                                 mpg_strtoui(r->mpg_i, tokstart, strlen(tokstart), NULL, base);
5888                                 errno = 0;
5889                         } else {
5890                                 int tval;
5891                                 r = mpg_float();
5892                                 tval = mpfr_strtofr(r->mpg_numbr, tokstart, NULL, base, ROUND_MODE);
5893                                 errno = 0;
5894                                 IEEE_FMT(r->mpg_numbr, tval);
5895                         }
5896                         yylval->memory = r;
5897                         return lasttok = YNUMBER;
5898                 }
5899 #endif
5900                 if (base != 10)
5901                         d = nondec2awknum(tokstart, strlen(tokstart));
5902                 else
5903                         d = atof(tokstart);
5904                 yylval->memory = make_number(d);
5905                 if (d <= INT32_MAX && d >= INT32_MIN && d == (int32_t) d)
5906                         yylval->memory->flags |= NUMINT;
5907                 return lasttok = YNUMBER;
5908
5909         case '&':
5910                 if ((c = nextc()) == '&') {
5911                         yylval = GET_INSTRUCTION(Op_and);
5912                         allow_newline();
5913                         return lasttok = LEX_AND;
5914                 }
5915                 pushback();
5916                 yylval = GET_INSTRUCTION(Op_symbol);
5917                 return lasttok = '&';
5918
5919         case '|':
5920                 if ((c = nextc()) == '|') {
5921                         yylval = GET_INSTRUCTION(Op_or);
5922                         allow_newline();
5923                         return lasttok = LEX_OR;
5924                 } else if (! do_traditional && c == '&') {
5925                         yylval = GET_INSTRUCTION(Op_symbol);
5926                         yylval->redir_type = redirect_twoway;
5927                         return lasttok = (in_print && in_parens == 0 ? IO_OUT : IO_IN);
5928                 }
5929                 pushback();
5930                 if (in_print && in_parens == 0) {
5931                         yylval = GET_INSTRUCTION(Op_symbol);
5932                         yylval->redir_type = redirect_pipe;
5933                         return lasttok = IO_OUT;
5934                 } else {
5935                         yylval = GET_INSTRUCTION(Op_symbol);
5936                         yylval->redir_type = redirect_pipein;
5937                         return lasttok = IO_IN;
5938                 }
5939         }
5940
5941         if (c != '_' && ! isalpha(c)) {
5942                 yyerror(_("invalid char '%c' in expression"), c);
5943                 return lasttok = LEX_EOF;
5944         }
5945
5946         /*
5947          * Lots of fog here.  Consider:
5948          *
5949          * print "xyzzy"$_"foo"
5950          *
5951          * Without the check for ` lasttok != '$' ', this is parsed as
5952          *
5953          * print "xxyzz" $(_"foo")
5954          *
5955          * With the check, it is "correctly" parsed as three
5956          * string concatenations.  Sigh.  This seems to be
5957          * "more correct", but this is definitely one of those
5958          * occasions where the interactions are funny.
5959          */
5960         if (! do_traditional && c == '_' && lasttok != '$') {
5961                 if ((c = nextc()) == '"') {
5962                         intlstr = true;
5963                         goto string;
5964                 }
5965                 pushback();
5966                 c = '_';
5967         }
5968
5969         /* it's some type of name-type-thing.  Find its length. */
5970         tok = tokstart;
5971         while (c != END_FILE && is_identchar(c)) {
5972                 tokadd(c);
5973                 c = nextc();
5974         }
5975         tokadd('\0');
5976         pushback();
5977
5978         /* See if it is a special token. */
5979         if ((mid = check_special(tokstart)) >= 0) {
5980                 static int warntab[sizeof(tokentab) / sizeof(tokentab[0])];
5981                 int class = tokentab[mid].class;
5982
5983                 if ((class == LEX_INCLUDE || class == LEX_LOAD || class == LEX_EVAL)
5984                                 && lasttok != '@')
5985                         goto out;
5986
5987                 if (do_lint) {
5988                         if ((tokentab[mid].flags & GAWKX) != 0 && (warntab[mid] & GAWKX) == 0) {
5989                                 lintwarn(_("`%s' is a gawk extension"),
5990                                         tokentab[mid].operator);
5991                                 warntab[mid] |= GAWKX;
5992                         }
5993                         if ((tokentab[mid].flags & NOT_POSIX) != 0 && (warntab[mid] & NOT_POSIX) == 0) {
5994                                 lintwarn(_("POSIX does not allow `%s'"),
5995                                         tokentab[mid].operator);
5996                                 warntab[mid] |= NOT_POSIX;
5997                         }
5998                 }
5999                 if (do_lint_old && (tokentab[mid].flags & NOT_OLD) != 0
6000                                  && (warntab[mid] & NOT_OLD) == 0
6001                 ) {
6002                         warning(_("`%s' is not supported in old awk"),
6003                                         tokentab[mid].operator);
6004                         warntab[mid] |= NOT_OLD;
6005                 }
6006
6007                 if ((tokentab[mid].flags & BREAK) != 0)
6008                         break_allowed++;
6009                 if ((tokentab[mid].flags & CONTINUE) != 0)
6010                         continue_allowed++;
6011
6012                 switch (class) {
6013                 case LEX_INCLUDE:
6014                 case LEX_LOAD:
6015                         want_source = true;
6016                         break;
6017                 case LEX_EVAL:
6018                         if (in_main_context())
6019                                 goto out;
6020                         emalloc(tokkey, char *, tok - tokstart + 1, "yylex");
6021                         tokkey[0] = '@';
6022                         memcpy(tokkey + 1, tokstart, tok - tokstart);
6023                         yylval = GET_INSTRUCTION(Op_token);
6024                         yylval->lextok = tokkey;
6025                         break;
6026
6027                 case LEX_FUNCTION:
6028                 case LEX_BEGIN:
6029                 case LEX_END:
6030                 case LEX_BEGINFILE:
6031                 case LEX_ENDFILE:               
6032                         yylval = bcalloc(tokentab[mid].value, 3, sourceline);
6033                         break;
6034
6035                 case LEX_FOR:
6036                 case LEX_WHILE:
6037                 case LEX_DO:
6038                 case LEX_SWITCH:
6039                         if (! do_pretty_print)
6040                                 return lasttok = class;
6041                         /* fall through */
6042                 case LEX_CASE:
6043                         yylval = bcalloc(tokentab[mid].value, 2, sourceline);
6044                         break;
6045
6046                 /*
6047                  * These must be checked here, due to the LALR nature of the parser,
6048                  * the rules for continue and break may not be reduced until after
6049                  * a token that increments the xxx_allowed varibles is seen. Bleah.
6050                  */
6051                 case LEX_CONTINUE:
6052                         if (! continue_allowed) {
6053                                 error_ln(sourceline,
6054                                         _("`continue' is not allowed outside a loop"));
6055                                 errcount++;
6056                         }
6057                         goto make_instruction;
6058
6059                 case LEX_BREAK:
6060                         if (! break_allowed) {
6061                                 error_ln(sourceline,
6062                                         _("`break' is not allowed outside a loop or switch"));
6063                                 errcount++;
6064                         }
6065                         goto make_instruction;
6066
6067                 default:
6068 make_instruction:
6069                         yylval = GET_INSTRUCTION(tokentab[mid].value);
6070                         if (class == LEX_BUILTIN || class == LEX_LENGTH)
6071                                 yylval->builtin_idx = mid;
6072                         break;
6073                 }
6074                 return lasttok = class;
6075         }
6076 out:
6077         tokkey = estrdup(tokstart, tok - tokstart);
6078         if (*lexptr == '(') {
6079                 yylval = bcalloc(Op_token, 2, sourceline);
6080                 yylval->lextok = tokkey;        
6081                 return lasttok = FUNC_CALL;
6082         } else {
6083                 static bool goto_warned = false;
6084
6085                 yylval = GET_INSTRUCTION(Op_token);
6086                 yylval->lextok = tokkey;
6087
6088 #define SMART_ALECK     1
6089                 if (SMART_ALECK && do_lint
6090                     && ! goto_warned && strcasecmp(tokkey, "goto") == 0) {
6091                         goto_warned = true;
6092                         lintwarn(_("`goto' considered harmful!\n"));
6093                 }
6094                 return lasttok = NAME;
6095         }
6096
6097 #undef GET_INSTRUCTION
6098 #undef NEWLINE_EOF
6099 }
6100
6101 /* snode --- instructions for builtin functions. Checks for arg. count
6102              and supplies defaults where possible. */
6103
6104 static INSTRUCTION *
6105 snode(INSTRUCTION *subn, INSTRUCTION *r)
6106 {
6107         INSTRUCTION *arg;
6108         INSTRUCTION *ip;
6109         NODE *n;
6110         int nexp = 0;
6111         int args_allowed;
6112         int idx = r->builtin_idx;
6113
6114         if (subn != NULL) {
6115                 INSTRUCTION *tp;
6116                 for (tp = subn->nexti; tp; tp = tp->nexti) {
6117                         tp = tp->lasti;
6118                         nexp++;
6119                 }
6120                 assert(nexp > 0);
6121         }               
6122
6123         /* check against how many args. are allowed for this builtin */
6124         args_allowed = tokentab[idx].flags & ARGS;
6125         if (args_allowed && (args_allowed & A(nexp)) == 0) {
6126                 yyerror(_("%d is invalid as number of arguments for %s"),
6127                                 nexp, tokentab[idx].operator);
6128                 return NULL;
6129         }
6130
6131         /* special processing for sub, gsub and gensub */
6132
6133         if (tokentab[idx].value == Op_sub_builtin) {
6134                 const char *operator = tokentab[idx].operator;
6135
6136                 r->sub_flags = 0;
6137
6138                 arg = subn->nexti;              /* first arg list */
6139                 (void) mk_rexp(arg);
6140
6141                 if (strcmp(operator, "gensub") != 0) {
6142                         /* sub and gsub */
6143
6144                         if (strcmp(operator, "gsub") == 0)
6145                                 r->sub_flags |= GSUB;
6146
6147                         arg = arg->lasti->nexti;        /* 2nd arg list */
6148                         if (nexp == 2) {
6149                                 INSTRUCTION *expr;
6150
6151                                 expr = list_create(instruction(Op_push_i));
6152                                 expr->nexti->memory = make_number(0.0);
6153                                 (void) mk_expression_list(subn,
6154                                                 list_append(expr, instruction(Op_field_spec)));
6155                         }
6156
6157                         arg = arg->lasti->nexti;        /* third arg list */
6158                         ip = arg->lasti;
6159                         if (ip->opcode == Op_push_i) {
6160                                 if (do_lint)
6161                                         lintwarn(_("%s: string literal as last arg of substitute has no effect"),
6162                                                 operator);
6163                                 r->sub_flags |= LITERAL;
6164                         } else {
6165                                 if (make_assignable(ip) == NULL)
6166                                         yyerror(_("%s third parameter is not a changeable object"),
6167                                                 operator);
6168                                 else
6169                                         ip->do_reference = true;
6170                         }
6171
6172                         r->expr_count = count_expressions(&subn, false);
6173                         ip = subn->lasti;
6174
6175                         (void) list_append(subn, r);
6176
6177                         /* add after_assign code */
6178                         if (ip->opcode == Op_push_lhs && ip->memory->type == Node_var && ip->memory->var_assign) {
6179                                 (void) list_append(subn, instruction(Op_var_assign));
6180                                 subn->lasti->assign_ctxt = Op_sub_builtin;
6181                                 subn->lasti->assign_var = ip->memory->var_assign;
6182                         } else if (ip->opcode == Op_field_spec_lhs) {
6183                                 (void) list_append(subn, instruction(Op_field_assign));
6184                                 subn->lasti->assign_ctxt = Op_sub_builtin;
6185                                 subn->lasti->field_assign = (Func_ptr) 0;
6186                                 ip->target_assign = subn->lasti;
6187                         } else if (ip->opcode == Op_subscript_lhs) {
6188                                 (void) list_append(subn, instruction(Op_subscript_assign));
6189                                 subn->lasti->assign_ctxt = Op_sub_builtin;
6190                         }
6191
6192                         return subn;    
6193
6194                 } else {
6195                         /* gensub */
6196
6197                         r->sub_flags |= GENSUB;
6198                         if (nexp == 3) {
6199                                 ip = instruction(Op_push_i);
6200                                 ip->memory = make_number(0.0);
6201                                 (void) mk_expression_list(subn,
6202                                                 list_append(list_create(ip), instruction(Op_field_spec)));
6203                         }
6204
6205                         r->expr_count = count_expressions(&subn, false);
6206                         return list_append(subn, r);
6207                 }
6208         }
6209
6210 #ifdef HAVE_MPFR
6211         /* N.B.: There isn't any special processing for an alternate function below */
6212         if (do_mpfr && tokentab[idx].ptr2)
6213                 r->builtin =  tokentab[idx].ptr2;
6214         else
6215 #endif
6216                 r->builtin = tokentab[idx].ptr;
6217
6218         /* special case processing for a few builtins */
6219
6220         if (r->builtin == do_length) {
6221                 if (nexp == 0) {                
6222                     /* no args. Use $0 */
6223
6224                         INSTRUCTION *list;
6225                         r->expr_count = 1;                      
6226                         list = list_create(r);
6227                         (void) list_prepend(list, instruction(Op_field_spec));
6228                         (void) list_prepend(list, instruction(Op_push_i));
6229                         list->nexti->memory = make_number(0.0);
6230                         return list; 
6231                 } else {
6232                         arg = subn->nexti;
6233                         if (arg->nexti == arg->lasti && arg->nexti->opcode == Op_push)
6234                                 arg->nexti->opcode = Op_push_arg;       /* argument may be array */
6235                 }
6236         } else if (r->builtin == do_isarray) {
6237                 arg = subn->nexti;
6238                 if (arg->nexti == arg->lasti && arg->nexti->opcode == Op_push)
6239                         arg->nexti->opcode = Op_push_arg;       /* argument may be array */
6240         } else if (r->builtin == do_match) {
6241                 static bool warned = false;
6242
6243                 arg = subn->nexti->lasti->nexti;        /* 2nd arg list */
6244                 (void) mk_rexp(arg);
6245
6246                 if (nexp == 3) {        /* 3rd argument there */
6247                         if (do_lint && ! warned) {
6248                                 warned = true;
6249                                 lintwarn(_("match: third argument is a gawk extension"));
6250                         }
6251                         if (do_traditional) {
6252                                 yyerror(_("match: third argument is a gawk extension"));
6253                                 return NULL;
6254                         }
6255
6256                         arg = arg->lasti->nexti;        /* third arg list */
6257                         ip = arg->lasti;
6258                         if (/*ip == arg->nexti  && */ ip->opcode == Op_push)
6259                                 ip->opcode = Op_push_array;
6260                 }
6261         } else if (r->builtin == do_split) {
6262                 arg = subn->nexti->lasti->nexti;        /* 2nd arg list */
6263                 ip = arg->lasti;
6264                 if (ip->opcode == Op_push)
6265                         ip->opcode = Op_push_array;
6266                 if (nexp == 2) {
6267                         INSTRUCTION *expr;
6268                         expr = list_create(instruction(Op_push));
6269                         expr->nexti->memory = FS_node;
6270                         (void) mk_expression_list(subn, expr);
6271                 }
6272                 arg = arg->lasti->nexti;
6273                 n = mk_rexp(arg);
6274                 if (nexp == 2)
6275                         n->re_flags |= FS_DFLT;
6276                 if (nexp == 4) {
6277                         arg = arg->lasti->nexti;
6278                         ip = arg->lasti;
6279                         if (ip->opcode == Op_push)
6280                                 ip->opcode = Op_push_array;
6281                 }
6282         } else if (r->builtin == do_patsplit) {
6283                 arg = subn->nexti->lasti->nexti;        /* 2nd arg list */
6284                 ip = arg->lasti;
6285                 if (ip->opcode == Op_push)
6286                         ip->opcode = Op_push_array;
6287                 if (nexp == 2) {
6288                         INSTRUCTION *expr;
6289                         expr = list_create(instruction(Op_push));
6290                         expr->nexti->memory = FPAT_node;
6291                         (void) mk_expression_list(subn, expr);
6292                 }
6293                 arg = arg->lasti->nexti;
6294                 n = mk_rexp(arg);
6295                 if (nexp == 4) {
6296                         arg = arg->lasti->nexti;
6297                         ip = arg->lasti;
6298                         if (ip->opcode == Op_push)
6299                                 ip->opcode = Op_push_array;
6300                 }
6301         } else if (r->builtin == do_close) {
6302                 static bool warned = false;
6303                 if (nexp == 2) {
6304                         if (do_lint && ! warned) {
6305                                 warned = true;
6306                                 lintwarn(_("close: second argument is a gawk extension"));
6307                         }
6308                         if (do_traditional) {
6309                                 yyerror(_("close: second argument is a gawk extension"));
6310                                 return NULL;
6311                         }
6312                 }
6313         } else if (do_intl                                      /* --gen-po */
6314                         && r->builtin == do_dcgettext           /* dcgettext(...) */
6315                         && subn->nexti->lasti->opcode == Op_push_i      /* 1st arg is constant */
6316                         && (subn->nexti->lasti->memory->flags & STRCUR) != 0) { /* it's a string constant */
6317                 /* ala xgettext, dcgettext("some string" ...) dumps the string */
6318                 NODE *str = subn->nexti->lasti->memory;
6319
6320                 if ((str->flags & INTLSTR) != 0)
6321                         warning(_("use of dcgettext(_\"...\") is incorrect: remove leading underscore"));
6322                         /* don't dump it, the lexer already did */
6323                 else
6324                         dumpintlstr(str->stptr, str->stlen);
6325         } else if (do_intl                                      /* --gen-po */
6326                         && r->builtin == do_dcngettext          /* dcngettext(...) */
6327                         && subn->nexti->lasti->opcode == Op_push_i      /* 1st arg is constant */
6328                         && (subn->nexti->lasti->memory->flags & STRCUR) != 0    /* it's a string constant */
6329                         && subn->nexti->lasti->nexti->lasti->opcode == Op_push_i        /* 2nd arg is constant too */
6330                         && (subn->nexti->lasti->nexti->lasti->memory->flags & STRCUR) != 0) {   /* it's a string constant */
6331                 /* ala xgettext, dcngettext("some string", "some plural" ...) dumps the string */
6332                 NODE *str1 = subn->nexti->lasti->memory;
6333                 NODE *str2 = subn->nexti->lasti->nexti->lasti->memory;
6334
6335                 if (((str1->flags | str2->flags) & INTLSTR) != 0)
6336                         warning(_("use of dcngettext(_\"...\") is incorrect: remove leading underscore"));
6337                 else
6338                         dumpintlstr2(str1->stptr, str1->stlen, str2->stptr, str2->stlen);
6339         } else if (r->builtin == do_asort || r->builtin == do_asorti) {
6340                 arg = subn->nexti;      /* 1st arg list */
6341                 ip = arg->lasti;
6342                 if (ip->opcode == Op_push)
6343                         ip->opcode = Op_push_array;
6344                 if (nexp >= 2) {
6345                         arg = ip->nexti;
6346                         ip = arg->lasti;
6347                         if (ip->opcode == Op_push)
6348                                 ip->opcode = Op_push_array;
6349                 }
6350         }
6351         else if (r->builtin == do_index) {
6352                 arg = subn->nexti->lasti->nexti;        /* 2nd arg list */
6353                 ip = arg->lasti;
6354                 if (ip->opcode == Op_match_rec)
6355                         fatal(_("index: regexp constant as second argument is not allowed"));
6356         }
6357 #ifdef ARRAYDEBUG
6358         else if (r->builtin == do_adump) {
6359                 ip = subn->nexti->lasti;
6360                 if (ip->opcode == Op_push)
6361                         ip->opcode = Op_push_array;
6362         }
6363 #endif
6364
6365         if (subn != NULL) {
6366                 r->expr_count = count_expressions(&subn, false);
6367                 return list_append(subn, r);
6368         }
6369
6370         r->expr_count = 0;
6371         return list_create(r);
6372 }
6373
6374
6375 /* parms_shadow --- check if parameters shadow globals */
6376
6377 static int
6378 parms_shadow(INSTRUCTION *pc, bool *shadow)
6379 {
6380         int pcount, i;
6381         bool ret = false;
6382         NODE *func, *fp;
6383         char *fname;
6384
6385         func = pc->func_body;
6386         fname = func->vname;
6387         fp = func->fparms;
6388
6389 #if 0   /* can't happen, already exited if error ? */
6390         if (fname == NULL || func == NULL)      /* error earlier */
6391                 return false;
6392 #endif
6393
6394         pcount = func->param_cnt;
6395
6396         if (pcount == 0)                /* no args, no problem */
6397                 return 0;
6398
6399         source = pc->source_file;
6400         sourceline = pc->source_line;
6401         /*
6402          * Use warning() and not lintwarn() so that can warn
6403          * about all shadowed parameters.
6404          */
6405         for (i = 0; i < pcount; i++) {
6406                 if (lookup(fp[i].param) != NULL) {
6407                         warning(
6408         _("function `%s': parameter `%s' shadows global variable"),
6409                                         fname, fp[i].param);
6410                         ret = true;
6411                 }
6412         }
6413
6414         *shadow |= ret;
6415         return 0;
6416 }
6417
6418 /* valinfo --- dump var info */
6419
6420 void
6421 valinfo(NODE *n, Func_print print_func, FILE *fp)
6422 {
6423         if (n == Nnull_string)
6424                 print_func(fp, "uninitialized scalar\n");
6425         else if (n->flags & STRING) {
6426                 pp_string_fp(print_func, fp, n->stptr, n->stlen, '"', false);
6427                 print_func(fp, "\n");
6428         } else if (n->flags & NUMBER) {
6429 #ifdef HAVE_MPFR
6430                 if (is_mpg_float(n))
6431                         print_func(fp, "%s\n", mpg_fmt("%.17R*g", ROUND_MODE, n->mpg_numbr));
6432                 else if (is_mpg_integer(n))
6433                         print_func(fp, "%s\n", mpg_fmt("%Zd", n->mpg_i));
6434                 else
6435 #endif
6436                 print_func(fp, "%.17g\n", n->numbr);
6437         } else if (n->flags & STRCUR) {
6438                 pp_string_fp(print_func, fp, n->stptr, n->stlen, '"', false);
6439                 print_func(fp, "\n");
6440         } else if (n->flags & NUMCUR) {
6441 #ifdef HAVE_MPFR
6442                 if (is_mpg_float(n))
6443                         print_func(fp, "%s\n", mpg_fmt("%.17R*g", ROUND_MODE, n->mpg_numbr));
6444                 else if (is_mpg_integer(n))
6445                         print_func(fp, "%s\n", mpg_fmt("%Zd", n->mpg_i));
6446                 else
6447 #endif
6448                 print_func(fp, "%.17g\n", n->numbr);
6449         } else
6450                 print_func(fp, "?? flags %s\n", flags2str(n->flags));
6451 }
6452
6453
6454 /* dump_vars --- dump the symbol table */
6455
6456 void
6457 dump_vars(const char *fname)
6458 {
6459         FILE *fp;
6460         NODE **vars;
6461
6462         if (fname == NULL)
6463                 fp = stderr;
6464         else if ((fp = fopen(fname, "w")) == NULL) {
6465                 warning(_("could not open `%s' for writing (%s)"), fname, strerror(errno));
6466                 warning(_("sending variable list to standard error"));
6467                 fp = stderr;
6468         }
6469
6470         vars = variable_list();
6471         print_vars(vars, fprintf, fp);
6472         efree(vars);
6473         if (fp != stderr && fclose(fp) != 0)
6474                 warning(_("%s: close failed (%s)"), fname, strerror(errno));
6475 }
6476
6477 /* dump_funcs --- print all functions */
6478
6479 void
6480 dump_funcs()
6481 {
6482         NODE **funcs;
6483         funcs = function_list(true);
6484         (void) foreach_func(funcs, (int (*)(INSTRUCTION *, void *)) pp_func, (void *) 0);
6485         efree(funcs);
6486 }
6487
6488
6489 /* shadow_funcs --- check all functions for parameters that shadow globals */
6490
6491 void
6492 shadow_funcs()
6493 {
6494         static int calls = 0;
6495         bool shadow = false;
6496         NODE **funcs;
6497
6498         if (calls++ != 0)
6499                 fatal(_("shadow_funcs() called twice!"));
6500
6501         funcs = function_list(true);
6502         (void) foreach_func(funcs, (int (*)(INSTRUCTION *, void *)) parms_shadow, & shadow);
6503         efree(funcs);
6504
6505         /* End with fatal if the user requested it.  */
6506         if (shadow && lintfunc != warning)
6507                 lintwarn(_("there were shadowed variables."));
6508 }
6509
6510
6511 /* mk_function --- finalize function definition node; remove parameters
6512  *      out of the symbol table.
6513  */
6514
6515 static INSTRUCTION *
6516 mk_function(INSTRUCTION *fi, INSTRUCTION *def)
6517 {
6518         NODE *thisfunc;
6519
6520         thisfunc = fi->func_body;
6521         assert(thisfunc != NULL);
6522
6523         if (do_optimize && def->lasti->opcode == Op_pop) {
6524                 /* tail call which does not return any value. */
6525
6526                 INSTRUCTION *t;
6527
6528                 for (t = def->nexti; t->nexti != def->lasti; t = t->nexti)
6529                         ;
6530                 if (t->opcode == Op_func_call
6531                     && strcmp(t->func_name, thisfunc->vname) == 0)
6532                         (t + 1)->tail_call = true;
6533         }
6534
6535         /* add an implicit return at end;
6536          * also used by 'return' command in debugger
6537          */
6538
6539         (void) list_append(def, instruction(Op_push_i));
6540         def->lasti->memory = dupnode(Nnull_string);
6541         (void) list_append(def, instruction(Op_K_return));
6542
6543         if (do_pretty_print)
6544                 (void) list_prepend(def, instruction(Op_exec_count));
6545
6546         /* fi->opcode = Op_func */
6547         (fi + 1)->firsti = def->nexti;
6548         (fi + 1)->lasti = def->lasti;
6549         (fi + 2)->first_line = fi->source_line;
6550         (fi + 2)->last_line = lastline;
6551         fi->nexti = def->nexti;
6552         bcfree(def);
6553
6554         (void) list_append(rule_list, fi + 1);  /* debugging */
6555
6556         /* update lint table info */
6557         func_use(thisfunc->vname, FUNC_DEFINE);
6558
6559         /* remove params from symbol table */
6560         remove_params(thisfunc);
6561         return fi;
6562 }
6563
6564 /* 
6565  * install_function:
6566  * install function name in the symbol table.
6567  * Extra work, build up and install a list of the parameter names.
6568  */
6569
6570 static int
6571 install_function(char *fname, INSTRUCTION *fi, INSTRUCTION *plist)
6572 {
6573         NODE *r, *f;
6574         int pcount = 0;
6575
6576         r = lookup(fname);
6577         if (r != NULL || is_deferred_variable(fname)) {
6578                 error_ln(fi->source_line, _("function name `%s' previously defined"), fname);
6579                 return -1;
6580         }
6581
6582         if (plist != NULL)
6583                 pcount = plist->lasti->param_count + 1;
6584         f = install_symbol(fname, Node_func);
6585         fi->func_body = f;
6586         f->param_cnt = pcount;
6587         f->code_ptr = fi;
6588         f->fparms = NULL; 
6589         if (pcount > 0) {
6590                 char **pnames;
6591                 pnames = check_params(fname, pcount, plist);    /* frees plist */
6592                 f->fparms = make_params(pnames, pcount);
6593                 efree(pnames);
6594                 install_params(f);
6595         }
6596         return 0;
6597 }
6598
6599
6600 /* check_params --- build a list of function parameter names after
6601  *      making sure that the names are valid and there are no duplicates.
6602  */
6603
6604 static char **
6605 check_params(char *fname, int pcount, INSTRUCTION *list)
6606 {
6607         INSTRUCTION *p, *np;
6608         int i, j;
6609         char *name;
6610         char **pnames;
6611
6612         assert(pcount > 0);
6613
6614         emalloc(pnames, char **, pcount * sizeof(char *), "check_params");
6615
6616         for (i = 0, p = list->nexti; p != NULL; i++, p = np) {
6617                 np = p->nexti;
6618                 name = p->lextok;
6619                 p->lextok = NULL;
6620
6621                 if (strcmp(name, fname) == 0) {
6622                         /* check for function foo(foo) { ... }.  bleah. */
6623                         error_ln(p->source_line,
6624                                 _("function `%s': can't use function name as parameter name"), fname);
6625                 } else if (is_std_var(name)) {
6626                         error_ln(p->source_line,
6627                                 _("function `%s': can't use special variable `%s' as a function parameter"),
6628                                         fname, name);
6629                 }
6630
6631                 /* check for duplicate parameters */
6632                 for (j = 0; j < i; j++) {
6633                         if (strcmp(name, pnames[j]) == 0) {
6634                                 error_ln(p->source_line,
6635                                         _("function `%s': parameter #%d, `%s', duplicates parameter #%d"),
6636                                         fname, i + 1, name, j + 1);
6637                         }
6638                 }
6639
6640                 pnames[i] = name;
6641                 bcfree(p);
6642         }
6643         bcfree(list);
6644
6645         return pnames; 
6646 }
6647
6648
6649 #ifdef HASHSIZE
6650 undef HASHSIZE
6651 #endif
6652 #define HASHSIZE 1021
6653  
6654 static struct fdesc {
6655         char *name;
6656         short used;
6657         short defined;
6658         short extension;
6659         struct fdesc *next;
6660 } *ftable[HASHSIZE];
6661
6662 /* func_use --- track uses and definitions of functions */
6663
6664 static void
6665 func_use(const char *name, enum defref how)
6666 {
6667         struct fdesc *fp;
6668         int len;
6669         int ind;
6670
6671         len = strlen(name);
6672         ind = hash(name, len, HASHSIZE, NULL);
6673
6674         for (fp = ftable[ind]; fp != NULL; fp = fp->next)
6675                 if (strcmp(fp->name, name) == 0)
6676                         goto update_value;
6677
6678         /* not in the table, fall through to allocate a new one */
6679
6680         emalloc(fp, struct fdesc *, sizeof(struct fdesc), "func_use");
6681         memset(fp, '\0', sizeof(struct fdesc));
6682         emalloc(fp->name, char *, len + 1, "func_use");
6683         strcpy(fp->name, name);
6684         fp->next = ftable[ind];
6685         ftable[ind] = fp;
6686
6687 update_value:
6688         if (how == FUNC_DEFINE)
6689                 fp->defined++;
6690         else if (how == FUNC_EXT) {
6691                 fp->defined++;
6692                 fp->extension++;
6693         } else
6694                 fp->used++;
6695 }
6696
6697 /* track_ext_func --- add an extension function to the table */
6698
6699 void
6700 track_ext_func(const char *name)
6701 {
6702         func_use(name, FUNC_EXT);
6703 }
6704
6705 /* check_funcs --- verify functions that are called but not defined */
6706
6707 static void
6708 check_funcs()
6709 {
6710         struct fdesc *fp, *next;
6711         int i;
6712
6713         if (! in_main_context())
6714                 goto free_mem;
6715  
6716         for (i = 0; i < HASHSIZE; i++) {
6717                 for (fp = ftable[i]; fp != NULL; fp = fp->next) {
6718 #ifdef REALLYMEAN
6719                         /* making this the default breaks old code. sigh. */
6720                         if (fp->defined == 0 && ! fp->extension) {
6721                                 error(
6722                 _("function `%s' called but never defined"), fp->name);
6723                                 errcount++;
6724                         }
6725 #else
6726                         if (do_lint && fp->defined == 0 && ! fp->extension)
6727                                 lintwarn(
6728                 _("function `%s' called but never defined"), fp->name);
6729 #endif
6730
6731                         if (do_lint && fp->used == 0 && ! fp->extension) {
6732                                 lintwarn(_("function `%s' defined but never called directly"),
6733                                         fp->name);
6734                         }
6735                 }
6736         }
6737
6738 free_mem:
6739         /* now let's free all the memory */
6740         for (i = 0; i < HASHSIZE; i++) {
6741                 for (fp = ftable[i]; fp != NULL; fp = next) {
6742                         next = fp->next;
6743                         efree(fp->name);
6744                         efree(fp);
6745                 }
6746                 ftable[i] = NULL;
6747         }
6748 }
6749
6750 /* param_sanity --- look for parameters that are regexp constants */
6751
6752 static void
6753 param_sanity(INSTRUCTION *arglist)
6754 {
6755         INSTRUCTION *argl, *arg;
6756         int i = 1;
6757
6758         if (arglist == NULL)
6759                 return;
6760         for (argl = arglist->nexti; argl; ) {
6761                 arg = argl->lasti;
6762                 if (arg->opcode == Op_match_rec)
6763                         warning_ln(arg->source_line,
6764                                 _("regexp constant for parameter #%d yields boolean value"), i);
6765                 argl = arg->nexti;
6766                 i++;
6767         }
6768 }
6769
6770 /* deferred variables --- those that are only defined if needed. */
6771
6772 /*
6773  * Is there any reason to use a hash table for deferred variables?  At the
6774  * moment, there are only 1 to 3 such variables, so it may not be worth
6775  * the overhead.  If more modules start using this facility, it should
6776  * probably be converted into a hash table.
6777  */
6778
6779 static struct deferred_variable {
6780         NODE *(*load_func)(void);
6781         struct deferred_variable *next;
6782         char name[1];   /* variable-length array */
6783 } *deferred_variables;
6784
6785 /* register_deferred_variable --- add a var name and loading function to the list */
6786
6787 void
6788 register_deferred_variable(const char *name, NODE *(*load_func)(void))
6789 {
6790         struct deferred_variable *dv;
6791         size_t sl = strlen(name);
6792
6793         emalloc(dv, struct deferred_variable *, sizeof(*dv)+sl,
6794                 "register_deferred_variable");
6795         dv->load_func = load_func;
6796         dv->next = deferred_variables;
6797         memcpy(dv->name, name, sl+1);
6798         deferred_variables = dv;
6799 }
6800
6801 /* is_deferred_variable --- check if NAME is a deferred variable */
6802
6803 static bool
6804 is_deferred_variable(const char *name)
6805 {
6806         struct deferred_variable *dv;
6807         for (dv = deferred_variables; dv != NULL; dv = dv->next)
6808                 if (strcmp(name, dv->name) == 0)
6809                         return true;
6810         return false;
6811 }
6812
6813
6814 /* variable --- make sure NAME is in the symbol table */
6815
6816 NODE *
6817 variable(int location, char *name, NODETYPE type)
6818 {
6819         NODE *r;
6820
6821         if ((r = lookup(name)) != NULL) {
6822                 if (r->type == Node_func || r->type == Node_ext_func )
6823                         error_ln(location, _("function `%s' called with space between name and `(',\nor used as a variable or an array"),
6824                                 r->vname);
6825                 if (r == symbol_table)
6826                         symtab_used = true;
6827         } else {
6828                 /* not found */
6829                 struct deferred_variable *dv;
6830
6831                 for (dv = deferred_variables; true; dv = dv->next) {
6832                         if (dv == NULL) {
6833                                 /*
6834                                  * This is the only case in which we may not free the string.
6835                                  */
6836                                 return install_symbol(name, type);
6837                         }
6838                         if (strcmp(name, dv->name) == 0) {
6839                                 r = (*dv->load_func)();
6840                                 break;
6841                         }
6842                 }
6843         }
6844         efree(name);
6845         return r;
6846 }
6847
6848 /* process_deferred --- if the program uses SYMTAB, load deferred variables */
6849
6850 static void
6851 process_deferred()
6852 {
6853         struct deferred_variable *dv;
6854
6855         if (! symtab_used)
6856                 return;
6857
6858         for (dv = deferred_variables; dv != NULL; dv = dv->next) {
6859                 (void) dv->load_func();
6860         }
6861 }
6862
6863 /* make_regnode --- make a regular expression node */
6864
6865 static NODE *
6866 make_regnode(int type, NODE *exp)
6867 {
6868         NODE *n;
6869
6870         getnode(n);
6871         memset(n, 0, sizeof(NODE));
6872         n->type = type;
6873         n->re_cnt = 1;
6874
6875         if (type == Node_regex) {
6876                 n->re_reg = make_regexp(exp->stptr, exp->stlen, false, true, false);
6877                 if (n->re_reg == NULL) {
6878                         freenode(n);
6879                         return NULL;
6880                 }
6881                 n->re_exp = exp;
6882                 n->re_flags = CONSTANT;
6883         }
6884         return n;
6885 }
6886
6887
6888 /* mk_rexp --- make a regular expression constant */
6889
6890 static NODE *
6891 mk_rexp(INSTRUCTION *list)
6892 {
6893         INSTRUCTION *ip;
6894
6895         ip = list->nexti;
6896         if (ip == list->lasti && ip->opcode == Op_match_rec)
6897                 ip->opcode = Op_push_re;
6898         else {
6899                 ip = instruction(Op_push_re);
6900                 ip->memory = make_regnode(Node_dynregex, NULL);
6901                 ip->nexti = list->lasti->nexti;
6902                 list->lasti->nexti = ip;
6903                 list->lasti = ip;
6904         }
6905         return ip->memory;
6906 }
6907
6908 #ifndef NO_LINT
6909 /* isnoeffect --- when used as a statement, has no side effects */
6910
6911 static int
6912 isnoeffect(OPCODE type)
6913 {
6914         switch (type) {
6915         case Op_times:
6916         case Op_times_i:
6917         case Op_quotient:
6918         case Op_quotient_i:
6919         case Op_mod:
6920         case Op_mod_i:
6921         case Op_plus:
6922         case Op_plus_i:
6923         case Op_minus:
6924         case Op_minus_i:
6925         case Op_subscript:
6926         case Op_concat:
6927         case Op_exp:
6928         case Op_exp_i:
6929         case Op_unary_minus:
6930         case Op_field_spec:
6931         case Op_and_final:
6932         case Op_or_final:
6933         case Op_equal:
6934         case Op_notequal:
6935         case Op_less:
6936         case Op_greater:
6937         case Op_leq:
6938         case Op_geq:
6939         case Op_match:
6940         case Op_nomatch:
6941         case Op_match_rec:
6942         case Op_not:
6943         case Op_in_array:
6944                 return true;
6945         default:
6946                 break;  /* keeps gcc -Wall happy */
6947         }
6948
6949         return false;
6950 }
6951 #endif /* NO_LINT */
6952
6953
6954 /* make_assignable --- make this operand an assignable one if posiible */
6955
6956 static INSTRUCTION *
6957 make_assignable(INSTRUCTION *ip)
6958 {
6959         switch (ip->opcode) {
6960         case Op_push:
6961                 ip->opcode = Op_push_lhs;
6962                 return ip;
6963         case Op_field_spec:
6964                 ip->opcode = Op_field_spec_lhs;
6965                 return ip;
6966         case Op_subscript:
6967                 ip->opcode = Op_subscript_lhs;
6968                 return ip;
6969         default:
6970                 break;  /* keeps gcc -Wall happy */
6971         }
6972         return NULL;
6973 }
6974
6975 /* stopme --- for debugging */
6976
6977 NODE *
6978 stopme(int nargs ATTRIBUTE_UNUSED)
6979 {
6980         return make_number(0.0);
6981 }
6982
6983 /* dumpintlstr --- write out an initial .po file entry for the string */
6984
6985 static void
6986 dumpintlstr(const char *str, size_t len)
6987 {
6988         char *cp;
6989
6990         /* See the GNU gettext distribution for details on the file format */
6991
6992         if (source != NULL) {
6993                 /* ala the gettext sources, remove leading `./'s */
6994                 for (cp = source; cp[0] == '.' && cp[1] == '/'; cp += 2)
6995                         continue;
6996                 printf("#: %s:%d\n", cp, sourceline);
6997         }
6998
6999         printf("msgid ");
7000         pp_string_fp(fprintf, stdout, str, len, '"', true);
7001         putchar('\n');
7002         printf("msgstr \"\"\n\n");
7003         fflush(stdout);
7004 }
7005
7006 /* dumpintlstr2 --- write out an initial .po file entry for the string and its plural */
7007
7008 static void
7009 dumpintlstr2(const char *str1, size_t len1, const char *str2, size_t len2)
7010 {
7011         char *cp;
7012
7013         /* See the GNU gettext distribution for details on the file format */
7014
7015         if (source != NULL) {
7016                 /* ala the gettext sources, remove leading `./'s */
7017                 for (cp = source; cp[0] == '.' && cp[1] == '/'; cp += 2)
7018                         continue;
7019                 printf("#: %s:%d\n", cp, sourceline);
7020         }
7021
7022         printf("msgid ");
7023         pp_string_fp(fprintf, stdout, str1, len1, '"', true);
7024         putchar('\n');
7025         printf("msgid_plural ");
7026         pp_string_fp(fprintf, stdout, str2, len2, '"', true);
7027         putchar('\n');
7028         printf("msgstr[0] \"\"\nmsgstr[1] \"\"\n\n");
7029         fflush(stdout);
7030 }
7031
7032 /* mk_binary --- instructions for binary operators */
7033
7034 static INSTRUCTION *
7035 mk_binary(INSTRUCTION *s1, INSTRUCTION *s2, INSTRUCTION *op)
7036 {
7037         INSTRUCTION *ip1,*ip2;
7038         AWKNUM res;
7039
7040         ip2 = s2->nexti;
7041         if (s2->lasti == ip2 && ip2->opcode == Op_push_i) {
7042         /* do any numeric constant folding */
7043                 ip1 = s1->nexti;
7044                 if (do_optimize
7045                                 && ip1 == s1->lasti && ip1->opcode == Op_push_i
7046                                 && (ip1->memory->flags & (MPFN|MPZN|STRCUR|STRING)) == 0
7047                                 && (ip2->memory->flags & (MPFN|MPZN|STRCUR|STRING)) == 0
7048                 ) {
7049                         NODE *n1 = ip1->memory, *n2 = ip2->memory;
7050                         res = force_number(n1)->numbr;
7051                         (void) force_number(n2);
7052                         switch (op->opcode) {
7053                         case Op_times:
7054                                 res *= n2->numbr;
7055                                 break;
7056                         case Op_quotient:
7057                                 if (n2->numbr == 0.0) {
7058                                         /* don't fatalize, allow parsing rest of the input */
7059                                         error_ln(op->source_line, _("division by zero attempted"));
7060                                         goto regular;
7061                                 }
7062
7063                                 res /= n2->numbr;
7064                                 break;
7065                         case Op_mod:
7066                                 if (n2->numbr == 0.0) {
7067                                         /* don't fatalize, allow parsing rest of the input */
7068                                         error_ln(op->source_line, _("division by zero attempted in `%%'"));
7069                                         goto regular;
7070                                 }
7071 #ifdef HAVE_FMOD
7072                                 res = fmod(res, n2->numbr);
7073 #else   /* ! HAVE_FMOD */
7074                                 (void) modf(res / n2->numbr, &res);
7075                                 res = n1->numbr - res * n2->numbr;
7076 #endif  /* ! HAVE_FMOD */
7077                                 break;
7078                         case Op_plus:
7079                                 res += n2->numbr;
7080                                 break;
7081                         case Op_minus:
7082                                 res -= n2->numbr;
7083                                 break;
7084                         case Op_exp:
7085                                 res = calc_exp(res, n2->numbr);
7086                                 break;
7087                         default:
7088                                 goto regular;
7089                         }
7090
7091                         op->opcode = Op_push_i;
7092                         op->memory = make_number(res);
7093                         unref(n1);
7094                         unref(n2);
7095                         bcfree(ip1);
7096                         bcfree(ip2);
7097                         bcfree(s1);
7098                         bcfree(s2);
7099                         return list_create(op);
7100                 } else {
7101                 /* do basic arithmetic optimisation */
7102                 /* convert (Op_push_i Node_val) + (Op_plus) to (Op_plus_i Node_val) */
7103                         switch (op->opcode) {
7104                         case Op_times:
7105                                 op->opcode = Op_times_i;
7106                                 break;
7107                         case Op_quotient:
7108                                 op->opcode = Op_quotient_i;
7109                                 break;
7110                         case Op_mod:
7111                                 op->opcode = Op_mod_i;
7112                                 break;
7113                         case Op_plus:
7114                                 op->opcode = Op_plus_i;
7115                                 break;
7116                         case Op_minus:
7117                                 op->opcode = Op_minus_i;
7118                                 break;
7119                         case Op_exp:
7120                                 op->opcode = Op_exp_i;
7121                                 break;
7122                         default:
7123                                 goto regular;
7124                         }       
7125
7126                         op->memory = ip2->memory;
7127                         bcfree(ip2);
7128                         bcfree(s2);     /* Op_list */
7129                         return list_append(s1, op);
7130                 }
7131         }
7132
7133 regular:
7134         /* append lists s1, s2 and add `op' bytecode */
7135         (void) list_merge(s1, s2);
7136         return list_append(s1, op);
7137 }
7138
7139 /* mk_boolean --- instructions for boolean and, or */
7140  
7141 static INSTRUCTION *
7142 mk_boolean(INSTRUCTION *left, INSTRUCTION *right, INSTRUCTION *op)
7143 {
7144         INSTRUCTION *tp;
7145         OPCODE opc, final_opc;
7146
7147         opc = op->opcode;               /* Op_and or Op_or */
7148         final_opc = (opc == Op_or) ? Op_or_final : Op_and_final;
7149
7150         add_lint(right, LINT_assign_in_cond);
7151
7152         tp = left->lasti;
7153
7154         if (tp->opcode != final_opc) {  /* x || y */
7155                 list_append(right, instruction(final_opc));
7156                 add_lint(left, LINT_assign_in_cond);
7157                 (void) list_append(left, op);
7158                 left->lasti->target_jmp = right->lasti;
7159
7160                 /* NB: target_stmt points to previous Op_and(Op_or) in a chain;
7161                  *     target_stmt only used in the parser (see below).
7162                  */
7163
7164                 left->lasti->target_stmt = left->lasti;
7165                 right->lasti->target_stmt = left->lasti;
7166         } else {                /* optimization for x || y || z || ... */
7167                 INSTRUCTION *ip;
7168                 
7169                 op->opcode = final_opc;
7170                 (void) list_append(right, op);
7171                 op->target_stmt = tp;
7172                 tp->opcode = opc;
7173                 tp->target_jmp = op;
7174
7175                 /* update jump targets */
7176                 for (ip = tp->target_stmt; ; ip = ip->target_stmt) {
7177                         assert(ip->opcode == opc);
7178                         assert(ip->target_jmp == tp);
7179                         /* if (ip->opcode == opc &&  ip->target_jmp == tp) */
7180                         ip->target_jmp = op;
7181                         if (ip->target_stmt == ip)
7182                                 break;
7183                 }
7184         }
7185
7186         return list_merge(left, right);
7187 }
7188
7189 /* mk_condition --- if-else and conditional */
7190
7191 static INSTRUCTION *
7192 mk_condition(INSTRUCTION *cond, INSTRUCTION *ifp, INSTRUCTION *true_branch,
7193                 INSTRUCTION *elsep, INSTRUCTION *false_branch)
7194 {
7195         /*
7196          *    ----------------
7197          *       cond
7198          *    ----------------
7199          * t: [Op_jmp_false f ]
7200          *    ----------------
7201          *       true_branch
7202          *
7203          *    ----------------
7204          *    [Op_jmp y]
7205          *    ---------------- 
7206          * f:
7207          *      false_branch
7208          *    ----------------
7209          * y: [Op_no_op]
7210          *    ----------------
7211          */
7212
7213         INSTRUCTION *ip;
7214
7215         if (false_branch == NULL) {
7216                 false_branch = list_create(instruction(Op_no_op));
7217                 if (elsep != NULL) {            /* else { } */
7218                         if (do_pretty_print)
7219                                 (void) list_prepend(false_branch, elsep);
7220                         else
7221                                 bcfree(elsep);
7222                 }
7223         } else {
7224                 /* assert(elsep != NULL); */
7225
7226                 /* avoid a series of no_op's: if .. else if .. else if .. */
7227                 if (false_branch->lasti->opcode != Op_no_op)
7228                         (void) list_append(false_branch, instruction(Op_no_op));
7229                 if (do_pretty_print) {
7230                         (void) list_prepend(false_branch, elsep);
7231                         false_branch->nexti->branch_end = false_branch->lasti;
7232                         (void) list_prepend(false_branch, instruction(Op_exec_count));
7233                 } else
7234                         bcfree(elsep);
7235         }
7236
7237         (void) list_prepend(false_branch, instruction(Op_jmp));
7238         false_branch->nexti->target_jmp = false_branch->lasti;
7239
7240         add_lint(cond, LINT_assign_in_cond);
7241         ip = list_append(cond, instruction(Op_jmp_false));
7242         ip->lasti->target_jmp = false_branch->nexti->nexti;
7243
7244         if (do_pretty_print) {
7245                 (void) list_prepend(ip, ifp);
7246                 (void) list_append(ip, instruction(Op_exec_count));
7247                 ip->nexti->branch_if = ip->lasti;
7248                 ip->nexti->branch_else = false_branch->nexti;
7249         } else
7250                 bcfree(ifp);
7251
7252         if (true_branch != NULL)
7253                 list_merge(ip, true_branch);
7254         return list_merge(ip, false_branch);
7255 }
7256
7257 enum defline { FIRST_LINE, LAST_LINE };
7258
7259 /* find_line -- find the first(last) line in a list of (pattern) instructions */
7260
7261 static int
7262 find_line(INSTRUCTION *pattern, enum defline what)
7263 {
7264         INSTRUCTION *ip;
7265         int lineno = 0;
7266
7267         for (ip = pattern->nexti; ip; ip = ip->nexti) {
7268                 if (what == LAST_LINE) {
7269                         if (ip->source_line > lineno)
7270                                 lineno = ip->source_line;
7271                 } else {        /* FIRST_LINE */
7272                         if (ip->source_line > 0
7273                                         && (lineno == 0 || ip->source_line < lineno))
7274                                 lineno = ip->source_line;
7275                 }
7276                 if (ip == pattern->lasti)
7277                         break;
7278         }
7279         assert(lineno > 0);
7280         return lineno;
7281 }
7282
7283 /* append_rule --- pattern-action instructions */
7284
7285 static INSTRUCTION *
7286 append_rule(INSTRUCTION *pattern, INSTRUCTION *action)
7287 {
7288         /*
7289          *    ----------------
7290          *       pattern
7291          *    ----------------
7292          *    [Op_jmp_false f ]
7293          *    ----------------
7294          *       action
7295          *    ----------------
7296          * f: [Op_no_op       ]
7297          *    ----------------
7298          */
7299
7300         INSTRUCTION *rp;
7301         INSTRUCTION *tp;
7302         INSTRUCTION *ip;
7303
7304         if (rule != Rule) {
7305                 rp = pattern;
7306                 if (do_pretty_print)
7307                         (void) list_append(action, instruction(Op_no_op));
7308                 (rp + 1)->firsti = action->nexti;
7309                 (rp + 1)->lasti = action->lasti;
7310                 (rp + 2)->first_line = pattern->source_line;
7311                 (rp + 2)->last_line = lastline;
7312                 ip = list_prepend(action, rp);
7313
7314         } else {
7315                 rp = bcalloc(Op_rule, 3, 0);
7316                 rp->in_rule = Rule;
7317                 rp->source_file = source;
7318                 tp = instruction(Op_no_op);
7319
7320                 if (pattern == NULL) {
7321                         /* assert(action != NULL); */
7322                         if (do_pretty_print)
7323                                 (void) list_prepend(action, instruction(Op_exec_count));
7324                         (rp + 1)->firsti = action->nexti;
7325                         (rp + 1)->lasti = tp;
7326                         (rp + 2)->first_line = firstline;
7327                         (rp + 2)->last_line = lastline;
7328                         rp->source_line = firstline;
7329                         ip = list_prepend(list_append(action, tp), rp);
7330                 } else {
7331                         (void) list_append(pattern, instruction(Op_jmp_false));
7332                         pattern->lasti->target_jmp = tp;
7333                         (rp + 2)->first_line = find_line(pattern, FIRST_LINE);
7334                         rp->source_line = (rp + 2)->first_line;
7335                         if (action == NULL) {
7336                                 (rp + 2)->last_line = find_line(pattern, LAST_LINE);
7337                                 action = list_create(instruction(Op_K_print_rec));
7338                                 if (do_pretty_print)
7339                                         (void) list_prepend(action, instruction(Op_exec_count));
7340                         } else
7341                                 (rp + 2)->last_line = lastline;
7342
7343                         if (do_pretty_print) {
7344                                 (void) list_prepend(pattern, instruction(Op_exec_count));
7345                                 (void) list_prepend(action, instruction(Op_exec_count));
7346                         }
7347                         (rp + 1)->firsti = action->nexti;
7348                         (rp + 1)->lasti = tp;
7349                         ip = list_append(
7350                                         list_merge(list_prepend(pattern, rp),
7351                                                 action),
7352                                         tp);
7353                 }
7354
7355         }
7356
7357         list_append(rule_list, rp + 1);
7358
7359         if (rule_block[rule] == NULL)
7360                 rule_block[rule] = ip;
7361         else
7362                 (void) list_merge(rule_block[rule], ip);
7363         
7364         return rule_block[rule];
7365 }
7366
7367 /* mk_assignment --- assignment bytecodes */
7368
7369 static INSTRUCTION *
7370 mk_assignment(INSTRUCTION *lhs, INSTRUCTION *rhs, INSTRUCTION *op)
7371 {
7372         INSTRUCTION *tp;
7373         INSTRUCTION *ip;
7374
7375         tp = lhs->lasti;
7376         switch (tp->opcode) {
7377         case Op_field_spec:
7378                 tp->opcode = Op_field_spec_lhs;
7379                 break;
7380         case Op_subscript:
7381                 tp->opcode = Op_subscript_lhs;
7382                 break;
7383         case Op_push:
7384         case Op_push_array:
7385                 tp->opcode = Op_push_lhs; 
7386                 break;
7387         case Op_field_assign:
7388                 yyerror(_("cannot assign a value to the result of a field post-increment expression"));
7389                 break;
7390         default:
7391                 yyerror(_("invalid target of assignment (opcode %s)"),
7392                                 opcode2str(tp->opcode));
7393                 break;
7394         }
7395
7396         tp->do_reference = (op->opcode != Op_assign);   /* check for uninitialized reference */
7397
7398         if (rhs != NULL)
7399                 ip = list_merge(rhs, lhs);
7400         else
7401                 ip = lhs;
7402
7403         (void) list_append(ip, op);
7404
7405         if (tp->opcode == Op_push_lhs
7406                         && tp->memory->type == Node_var
7407                         && tp->memory->var_assign
7408         ) {
7409                 tp->do_reference = false; /* no uninitialized reference checking
7410                                            * for a special variable.
7411                                            */
7412                 (void) list_append(ip, instruction(Op_var_assign));
7413                 ip->lasti->assign_var = tp->memory->var_assign;
7414         } else if (tp->opcode == Op_field_spec_lhs) {
7415                 (void) list_append(ip, instruction(Op_field_assign));
7416                 ip->lasti->field_assign = (Func_ptr) 0;
7417                 tp->target_assign = ip->lasti;
7418         } else if (tp->opcode == Op_subscript_lhs) {
7419                 (void) list_append(ip, instruction(Op_subscript_assign));
7420         }
7421
7422         return ip;
7423 }
7424
7425 /* optimize_assignment --- peephole optimization for assignment */
7426
7427 static INSTRUCTION *
7428 optimize_assignment(INSTRUCTION *exp)
7429 {
7430         INSTRUCTION *i1, *i2, *i3;
7431
7432         /*
7433          * Optimize assignment statements array[subs] = x; var = x; $n = x;
7434          * string concatenation of the form s = s t.
7435          *
7436          * 1) Array element assignment array[subs] = x:
7437          *   Replaces Op_push_array + Op_subscript_lhs + Op_assign + Op_pop
7438          *   with single instruction Op_store_sub.
7439          *       Limitation: 1 dimension and sub is simple var/value.
7440          * 
7441          * 2) Simple variable assignment var = x:
7442          *   Replaces Op_push_lhs + Op_assign + Op_pop with Op_store_var.
7443          *
7444          * 3) Field assignment $n = x:
7445          *   Replaces Op_field_spec_lhs + Op_assign + Op_field_assign + Op_pop
7446          *   with Op_store_field.
7447          *
7448          * 4) Optimization for string concatenation:
7449          *   For cases like x = x y, uses realloc to include y in x;
7450          *   also eliminates instructions Op_push_lhs and Op_pop.
7451          */
7452
7453         /*
7454          * N.B.: do not append Op_pop instruction to the returned
7455          * instruction list if optimized. None of these
7456          * optimized instructions pushes the r-value of assignment
7457          * onto the runtime stack.
7458          */
7459
7460         i2 = NULL;
7461         i1 = exp->lasti;
7462
7463         if (   i1->opcode != Op_assign
7464             && i1->opcode != Op_field_assign) 
7465                 return list_append(exp, instruction(Op_pop));
7466
7467         for (i2 = exp->nexti; i2 != i1; i2 = i2->nexti) {
7468                 switch (i2->opcode) {
7469                 case Op_concat:
7470                         if (i2->nexti->opcode == Op_push_lhs    /* l.h.s is a simple variable */
7471                                 && (i2->concat_flag & CSVAR)        /* 1st exp in r.h.s is a simple variable;
7472                                                                      * see Op_concat in the grammer above.
7473                                                                      */
7474                                 && i2->nexti->memory == exp->nexti->memory       /* and the same as in l.h.s */
7475                                 && i2->nexti->nexti == i1
7476                                 && i1->opcode == Op_assign
7477                         ) {
7478                                 /* s = s ... optimization */
7479
7480                                 /* avoid stuff like x = x (x = y) or x = x gsub(/./, "b", x);
7481                                  * check for l-value reference to this variable in the r.h.s.
7482                                  * Also, avoid function calls in general to guard against
7483                                  * global variable assignment.
7484                                  */
7485
7486                                 for (i3 = exp->nexti->nexti; i3 != i2; i3 = i3->nexti) {
7487                                         if ((i3->opcode == Op_push_lhs && i3->memory == i2->nexti->memory)
7488                                                         || i3->opcode == Op_func_call)
7489                                                 return list_append(exp, instruction(Op_pop)); /* no optimization */
7490                                 }
7491
7492                                 /* remove the variable from r.h.s */
7493                                 i3 = exp->nexti;
7494                                 exp->nexti = i3->nexti;
7495                                 bcfree(i3);
7496
7497                                 if (--i2->expr_count == 1)      /* one less expression in Op_concat */
7498                                         i2->opcode = Op_no_op;
7499
7500                                 i3 = i2->nexti;
7501                                 assert(i3->opcode == Op_push_lhs);
7502                                 i3->opcode = Op_assign_concat;  /* change Op_push_lhs to Op_assign_concat */
7503                                 i3->nexti = NULL;
7504                                 bcfree(i1);          /* Op_assign */
7505                                 exp->lasti = i3;     /* update Op_list */
7506                                 return exp;
7507                         }
7508                         break;
7509
7510                 case Op_field_spec_lhs:
7511                         if (i2->nexti->opcode == Op_assign
7512                                         && i2->nexti->nexti == i1
7513                                         && i1->opcode == Op_field_assign
7514                         ) {
7515                                 /* $n = .. */
7516                                 i2->opcode = Op_store_field;
7517                                 bcfree(i2->nexti);  /* Op_assign */
7518                                 i2->nexti = NULL;
7519                                 bcfree(i1);          /* Op_field_assign */
7520                                 exp->lasti = i2;    /* update Op_list */
7521                                 return exp;
7522                         }
7523                         break;
7524
7525                 case Op_push_array:
7526                         if (i2->nexti->nexti->opcode == Op_subscript_lhs) {
7527                                 i3 = i2->nexti->nexti;
7528                                 if (i3->sub_count == 1
7529                                                 && i3->nexti == i1
7530                                                 && i1->opcode == Op_assign
7531                                 ) {
7532                                         /* array[sub] = .. */
7533                                         i3->opcode = Op_store_sub;
7534                                         i3->memory = i2->memory;
7535                                         i3->expr_count = 1;  /* sub_count shadows memory,
7536                                           * so use expr_count instead.
7537                                                           */
7538                                         i3->nexti = NULL;
7539                                         i2->opcode = Op_no_op;                                  
7540                                         bcfree(i1);          /* Op_assign */
7541                                         exp->lasti = i3;     /* update Op_list */
7542                                         return exp;
7543                                 }
7544                         }
7545                         break;
7546
7547                 case Op_push_lhs:
7548                         if (i2->nexti == i1
7549                                         && i1->opcode == Op_assign
7550                         ) {
7551                                 /* var = .. */
7552                                 i2->opcode = Op_store_var;
7553                                 i2->nexti = NULL;
7554                                 bcfree(i1);          /* Op_assign */
7555                                 exp->lasti = i2;     /* update Op_list */
7556
7557                                 i3 = exp->nexti;
7558                                 if (i3->opcode == Op_push_i
7559                                         && (i3->memory->flags & INTLSTR) == 0
7560                                         && i3->nexti == i2
7561                                 ) {
7562                                         /* constant initializer */ 
7563                                         i2->initval = i3->memory;
7564                                         bcfree(i3);
7565                                         exp->nexti = i2;
7566                                 } else
7567                                         i2->initval = NULL;
7568
7569                                 return exp;
7570                         }
7571                         break;
7572
7573                 default:
7574                         break;
7575                 }
7576         }
7577
7578         /* no optimization  */
7579         return list_append(exp, instruction(Op_pop));
7580 }
7581
7582
7583 /* mk_getline --- make instructions for getline */
7584
7585 static INSTRUCTION *
7586 mk_getline(INSTRUCTION *op, INSTRUCTION *var, INSTRUCTION *redir, int redirtype)
7587 {
7588         INSTRUCTION *ip;
7589         INSTRUCTION *tp;
7590         INSTRUCTION *asgn = NULL;
7591
7592         /*
7593          *  getline [var] < [file]
7594          *
7595          *  [ file (simp_exp)]
7596          *  [ [ var ] ]
7597          *  [ Op_K_getline_redir|NULL|redir_type|into_var]
7598          *  [ [var_assign] ] 
7599          *
7600          */
7601
7602         if (redir == NULL) {
7603                 int sline = op->source_line;
7604                 bcfree(op);
7605                 op = bcalloc(Op_K_getline, 2, sline);
7606                 (op + 1)->target_endfile = ip_endfile;
7607                 (op + 1)->target_beginfile = ip_beginfile;      
7608         }
7609
7610         if (var != NULL) {
7611                 tp = make_assignable(var->lasti);
7612                 assert(tp != NULL);
7613
7614                 /* check if we need after_assign bytecode */
7615                 if (tp->opcode == Op_push_lhs
7616                                 && tp->memory->type == Node_var
7617                                 && tp->memory->var_assign
7618                 ) {
7619                         asgn = instruction(Op_var_assign);
7620                         asgn->assign_ctxt = op->opcode;
7621                         asgn->assign_var = tp->memory->var_assign;
7622                 } else if (tp->opcode == Op_field_spec_lhs) {
7623                         asgn = instruction(Op_field_assign);
7624                         asgn->assign_ctxt = op->opcode;
7625                         asgn->field_assign = (Func_ptr) 0;   /* determined at run time */
7626                         tp->target_assign = asgn;
7627                 } else if (tp->opcode == Op_subscript_lhs) {
7628                         asgn = instruction(Op_subscript_assign);
7629                         asgn->assign_ctxt = op->opcode;
7630                 }
7631
7632                 if (redir != NULL) {
7633                         ip = list_merge(redir, var);
7634                         (void) list_append(ip, op);
7635                 } else
7636                         ip = list_append(var, op);
7637         } else if (redir != NULL)
7638                 ip = list_append(redir, op);
7639         else
7640                 ip = list_create(op);
7641         op->into_var = (var != NULL);
7642         op->redir_type = (redir != NULL) ? redirtype : redirect_none;
7643
7644         return (asgn == NULL ? ip : list_append(ip, asgn));
7645 }
7646
7647
7648 /* mk_for_loop --- for loop bytecodes */
7649
7650 static INSTRUCTION *
7651 mk_for_loop(INSTRUCTION *forp, INSTRUCTION *init, INSTRUCTION *cond,
7652                                 INSTRUCTION *incr, INSTRUCTION *body)
7653 {
7654         /*
7655          *   ------------------------
7656          *        init                 (may be NULL)
7657          *   ------------------------
7658          * x:
7659          *        cond                 (Op_no_op if NULL)
7660          *   ------------------------
7661          *    [ Op_jmp_false tb      ]
7662          *   ------------------------
7663          *        body                 (may be NULL)
7664          *   ------------------------
7665          * tc: 
7666          *    incr                      (may be NULL)
7667          *    [ Op_jmp x             ] 
7668          *   ------------------------
7669          * tb:[ Op_no_op             ] 
7670          */
7671
7672         INSTRUCTION *ip, *tbreak, *tcont;
7673         INSTRUCTION *jmp;
7674         INSTRUCTION *pp_cond;
7675         INSTRUCTION *ret;
7676
7677         tbreak = instruction(Op_no_op);
7678
7679         if (cond != NULL) {
7680                 add_lint(cond, LINT_assign_in_cond);
7681                 pp_cond = cond->nexti;
7682                 ip = cond;
7683                 (void) list_append(ip, instruction(Op_jmp_false));
7684                 ip->lasti->target_jmp = tbreak;
7685         } else {
7686                 pp_cond = instruction(Op_no_op);
7687                 ip = list_create(pp_cond);
7688         }
7689
7690         if (init != NULL)
7691                 ip = list_merge(init, ip);
7692
7693         if (do_pretty_print) {
7694                 (void) list_append(ip, instruction(Op_exec_count));
7695                 (forp + 1)->forloop_cond = pp_cond;
7696                 (forp + 1)->forloop_body = ip->lasti;
7697         }
7698
7699         if (body != NULL)
7700                 (void) list_merge(ip, body);
7701
7702         jmp = instruction(Op_jmp);
7703         jmp->target_jmp = pp_cond;
7704         if (incr == NULL)
7705                 tcont = jmp;
7706         else {
7707                 tcont = incr->nexti;
7708                 (void) list_merge(ip, incr);
7709         }
7710
7711         (void) list_append(ip, jmp);
7712         ret = list_append(ip, tbreak);
7713         fix_break_continue(ret, tbreak, tcont);
7714
7715         if (do_pretty_print) {
7716                 forp->target_break = tbreak;
7717                 forp->target_continue = tcont;
7718                 ret = list_prepend(ret, forp);
7719         } /* else
7720                         forp is NULL */
7721
7722         return ret;
7723 }
7724
7725 /* add_lint --- add lint warning bytecode if needed */
7726
7727 static void
7728 add_lint(INSTRUCTION *list, LINTTYPE linttype)
7729 {
7730 #ifndef NO_LINT
7731         INSTRUCTION *ip;
7732
7733         switch (linttype) {
7734         case LINT_assign_in_cond:
7735                 ip = list->lasti;
7736                 if (ip->opcode == Op_var_assign || ip->opcode == Op_field_assign) {
7737                         assert(ip != list->nexti);
7738                         for (ip = list->nexti; ip->nexti != list->lasti; ip = ip->nexti)
7739                                 ;
7740                 }
7741
7742                 if (ip->opcode == Op_assign || ip->opcode == Op_assign_concat) {
7743                         list_append(list, instruction(Op_lint));
7744                         list->lasti->lint_type = linttype;
7745                 }
7746                 break;
7747
7748         case LINT_no_effect:
7749                 if (list->lasti->opcode == Op_pop && list->nexti != list->lasti) {
7750                         for (ip = list->nexti; ip->nexti != list->lasti; ip = ip->nexti)
7751                                 ;
7752
7753                         if (do_lint) {          /* compile-time warning */
7754                                 if (isnoeffect(ip->opcode))
7755                                         lintwarn_ln(ip->source_line, ("statement may have no effect"));
7756                         }
7757
7758                         if (ip->opcode == Op_push) {            /* run-time warning */
7759                                 list_append(list, instruction(Op_lint));
7760                                 list->lasti->lint_type = linttype;
7761                         }
7762                 }
7763                 break;
7764
7765         default:
7766                 break;
7767         }
7768 #endif
7769 }
7770
7771 /* mk_expression_list --- list of bytecode lists */
7772
7773 static INSTRUCTION *
7774 mk_expression_list(INSTRUCTION *list, INSTRUCTION *s1)
7775 {
7776         INSTRUCTION *r;
7777
7778         /* we can't just combine all bytecodes, since we need to
7779          * process individual expressions for a few builtins in snode() (-:
7780          */
7781         
7782         /* -- list of lists     */
7783         /* [Op_list| ... ]------
7784          *                       |
7785          * [Op_list| ... ]   --  |
7786          *  ...               |  |
7787          *  ...       <-------   |
7788          * [Op_list| ... ]   --  |
7789          *  ...               |  |
7790          *  ...               |  |
7791          *  ...       <------- --
7792          */
7793
7794         assert(s1 != NULL && s1->opcode == Op_list);
7795         if (list == NULL) {
7796                 list = instruction(Op_list);
7797                 list->nexti = s1;
7798                 list->lasti = s1->lasti;
7799                 return list;
7800         }
7801
7802         /* append expression to the end of the list */
7803
7804         r = list->lasti;
7805         r->nexti = s1;
7806         list->lasti = s1->lasti;
7807         return list;
7808 }
7809
7810 /* count_expressions --- fixup expression_list from mk_expression_list.
7811  *                       returns no of expressions in list. isarg is true
7812  *                       for function arguments.
7813  */
7814
7815 static int
7816 count_expressions(INSTRUCTION **list, bool isarg)
7817 {
7818         INSTRUCTION *expr;
7819         INSTRUCTION *r = NULL;
7820         int count = 0;
7821
7822         if (*list == NULL)      /* error earlier */
7823                 return 0;
7824
7825         for (expr = (*list)->nexti; expr; ) {
7826                 INSTRUCTION *t1, *t2;
7827                 t1 = expr->nexti;
7828                 t2 = expr->lasti;
7829                 if (isarg && t1 == t2 && t1->opcode == Op_push)
7830                         t1->opcode = Op_push_param;
7831                 if (++count == 1)
7832                         r = expr;
7833                 else
7834                         (void) list_merge(r, expr);
7835                 expr = t2->nexti;
7836         }
7837  
7838         assert(count > 0);
7839         if (! isarg && count > max_args)
7840                 max_args = count;
7841         bcfree(*list);
7842         *list = r;
7843         return count;
7844 }
7845
7846 /* fix_break_continue --- fix up break & continue codes in loop bodies */
7847
7848 static void
7849 fix_break_continue(INSTRUCTION *list, INSTRUCTION *b_target, INSTRUCTION *c_target)
7850 {
7851         INSTRUCTION *ip;
7852
7853         list->lasti->nexti = NULL;      /* just to make sure */
7854
7855         for (ip = list->nexti; ip != NULL; ip = ip->nexti) {
7856                 switch (ip->opcode) {
7857                 case Op_K_break:
7858                         if (ip->target_jmp == NULL)
7859                                 ip->target_jmp = b_target;
7860                         break;
7861
7862                 case Op_K_continue:
7863                         if (ip->target_jmp == NULL)
7864                                 ip->target_jmp = c_target;
7865                         break;
7866
7867                 default:
7868                         /* this is to keep the compiler happy. sheesh. */
7869                         break;
7870                 }
7871         }
7872 }
7873
7874 static inline INSTRUCTION *
7875 list_create(INSTRUCTION *x)
7876 {
7877         INSTRUCTION *l;
7878
7879         l = instruction(Op_list);
7880         l->nexti = x;
7881         l->lasti = x;
7882         return l;
7883 }
7884
7885 static inline INSTRUCTION *
7886 list_append(INSTRUCTION *l, INSTRUCTION *x)
7887 {
7888 #ifdef GAWKDEBUG
7889         if (l->opcode != Op_list)
7890                 cant_happen();
7891 #endif
7892         l->lasti->nexti = x;
7893         l->lasti = x;
7894         return l;
7895 }
7896
7897 static inline INSTRUCTION *
7898 list_prepend(INSTRUCTION *l, INSTRUCTION *x)
7899 {
7900 #ifdef GAWKDEBUG
7901         if (l->opcode != Op_list)
7902                 cant_happen();
7903 #endif
7904         x->nexti = l->nexti;
7905         l->nexti = x;
7906         return l;
7907 }
7908
7909 static inline INSTRUCTION *
7910 list_merge(INSTRUCTION *l1, INSTRUCTION *l2)
7911 {
7912 #ifdef GAWKDEBUG
7913         if (l1->opcode != Op_list)
7914                 cant_happen();
7915         if (l2->opcode != Op_list)
7916                 cant_happen();
7917 #endif
7918         l1->lasti->nexti = l2->nexti;
7919         l1->lasti = l2->lasti;
7920         bcfree(l2);
7921         return l1;
7922 }
7923
7924 /* See if name is a special token. */
7925
7926 int
7927 check_special(const char *name)
7928 {
7929         int low, high, mid;
7930         int i;
7931 #if 'a' == 0x81 /* it's EBCDIC */
7932         static bool did_sort = false;
7933
7934         if (! did_sort) {
7935                 qsort((void *) tokentab,
7936                                 sizeof(tokentab) / sizeof(tokentab[0]),
7937                                 sizeof(tokentab[0]), tokcompare);
7938                 did_sort = true;
7939         }
7940 #endif
7941
7942         low = 0;
7943         high = (sizeof(tokentab) / sizeof(tokentab[0])) - 1;
7944         while (low <= high) {
7945                 mid = (low + high) / 2;
7946                 i = *name - tokentab[mid].operator[0];
7947                 if (i == 0)
7948                         i = strcmp(name, tokentab[mid].operator);
7949
7950                 if (i < 0)              /* token < mid */
7951                         high = mid - 1;
7952                 else if (i > 0)         /* token > mid */
7953                         low = mid + 1;
7954                 else {
7955                         if ((do_traditional && (tokentab[mid].flags & GAWKX))
7956                                         || (do_posix && (tokentab[mid].flags & NOT_POSIX)))
7957                                 return -1;
7958                         return mid;
7959                 }
7960         }
7961         return -1;
7962 }
7963
7964 /*
7965  * This provides a private version of functions that act like VMS's
7966  * variable-length record filesystem, where there was a bug on
7967  * certain source files.
7968  */
7969
7970 static FILE *fp = NULL;
7971
7972 /* read_one_line --- return one input line at a time. mainly for debugging. */
7973
7974 static ssize_t
7975 read_one_line(int fd, void *buffer, size_t count)
7976 {
7977         char buf[BUFSIZ];
7978
7979         /* Minor potential memory leak here. Too bad. */
7980         if (fp == NULL) {
7981                 fp = fdopen(fd, "r");
7982                 if (fp == NULL) {
7983                         fprintf(stderr, "ugh. fdopen: %s\n", strerror(errno));
7984                         gawk_exit(EXIT_FAILURE);
7985                 }
7986         }
7987
7988         if (fgets(buf, sizeof buf, fp) == NULL)
7989                 return 0;
7990
7991         memcpy(buffer, buf, strlen(buf));
7992         return strlen(buf);
7993 }
7994
7995 /* one_line_close --- close the open file being read with read_one_line() */
7996
7997 static int
7998 one_line_close(int fd)
7999 {
8000         int ret;
8001
8002         if (fp == NULL || fd != fileno(fp))
8003                 fatal("debugging read/close screwed up!");
8004
8005         ret = fclose(fp);
8006         fp = NULL;
8007         return ret;
8008 }
8009
8010