1 /* A Bison parser, made by GNU Bison 3.0.2. */
3 /* Bison implementation for Yacc-like parsers in C
5 Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
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.
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.
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/>. */
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.
30 This special exception was added by the Free Software Foundation in
31 version 2.2 of Bison. */
33 /* C LALR(1) parser skeleton written by Richard Stallman, by
34 simplifying the original so-called "semantic" parser. */
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. */
43 /* Identify Bison output. */
47 #define YYBISON_VERSION "3.0.2"
50 #define YYSKELETON_NAME "yacc.c"
64 /* Copy the first part of user declarations. */
65 #line 26 "awkgram.y" /* yacc.c:339 */
73 #if defined(__STDC__) && __STDC__ < 1 /* VMS weirdness, maybe elsewhere */
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);
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);
91 static int isnoeffect(OPCODE type);
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);
102 #define instruction(t) bcalloc(t, 1, 0)
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);
122 static void process_deferred();
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);
128 static ssize_t read_one_line(int fd, void *buffer, size_t count);
129 static int one_line_close(int fd);
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 */
137 const char *const ruletab[] = {
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 */
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 */
164 #define END_FILE -1000
165 #define END_SRC -2000
167 #define YYDEBUG_LEXER_TEXT (lexeme)
168 static char *tokstart = NULL;
169 static char *tok = NULL;
171 static int errcount = 0;
174 extern int sourceline;
175 extern SRCFILE *srcfiles;
176 extern INSTRUCTION *rule_list;
178 extern NODE **args_array;
180 static INSTRUCTION *rule_block[sizeof(ruletab)];
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;
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);
194 extern double fmod(double x, double y);
196 #define YYSTYPE INSTRUCTION *
198 #define is_identchar(c) (isalnum(c) || (c) == '_')
200 #line 201 "awkgram.c" /* yacc.c:339 */
203 # if defined __cplusplus && 201103L <= __cplusplus
204 # define YY_NULLPTR nullptr
206 # define YY_NULLPTR 0
210 /* Enabling verbose error messages. */
211 #ifdef YYERROR_VERBOSE
212 # undef YYERROR_VERBOSE
213 # define YYERROR_VERBOSE 1
215 # define YYERROR_VERBOSE 0
281 SLASH_BEFORE_EQUAL = 307,
286 #define FUNC_CALL 258
298 #define CONCAT_OP 270
299 #define SUBSCRIPT 271
300 #define LEX_BEGIN 272
304 #define LEX_RETURN 276
305 #define LEX_DELETE 277
306 #define LEX_SWITCH 278
308 #define LEX_DEFAULT 280
309 #define LEX_WHILE 281
312 #define LEX_BREAK 284
313 #define LEX_CONTINUE 285
314 #define LEX_PRINT 286
315 #define LEX_PRINTF 287
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
326 #define INCREMENT 298
327 #define DECREMENT 299
328 #define LEX_BUILTIN 300
329 #define LEX_LENGTH 301
331 #define LEX_INCLUDE 303
335 #define SLASH_BEFORE_EQUAL 307
339 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
341 # define YYSTYPE_IS_TRIVIAL 1
342 # define YYSTYPE_IS_DECLARED 1
346 extern YYSTYPE yylval;
352 /* Copy the second part of user declarations. */
354 #line 355 "awkgram.c" /* yacc.c:358 */
361 typedef YYTYPE_UINT8 yytype_uint8;
363 typedef unsigned char yytype_uint8;
367 typedef YYTYPE_INT8 yytype_int8;
369 typedef signed char yytype_int8;
373 typedef YYTYPE_UINT16 yytype_uint16;
375 typedef unsigned short int yytype_uint16;
379 typedef YYTYPE_INT16 yytype_int16;
381 typedef short int yytype_int16;
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
393 # define YYSIZE_T unsigned int
397 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
400 # if defined YYENABLE_NLS && YYENABLE_NLS
402 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
403 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
407 # define YY_(Msgid) Msgid
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)
417 # define YY_ATTRIBUTE(Spec) /* empty */
421 #ifndef YY_ATTRIBUTE_PURE
422 # define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
425 #ifndef YY_ATTRIBUTE_UNUSED
426 # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
429 #if !defined _Noreturn \
430 && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
431 # if defined _MSC_VER && 1200 <= _MSC_VER
432 # define _Noreturn __declspec (noreturn)
434 # define _Noreturn YY_ATTRIBUTE ((__noreturn__))
438 /* Suppress unused-variable warnings by "using" E. */
439 #if ! defined lint || defined __GNUC__
440 # define YYUSE(E) ((void) (E))
442 # define YYUSE(E) /* empty */
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")
454 # define YY_INITIAL_VALUE(Value) Value
456 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
457 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
458 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
460 #ifndef YY_INITIAL_VALUE
461 # define YY_INITIAL_VALUE(Value) /* Nothing. */
465 #if ! defined yyoverflow || YYERROR_VERBOSE
467 /* The parser invokes alloca or malloc; define the necessary symbols. */
469 # ifdef YYSTACK_USE_ALLOCA
470 # if YYSTACK_USE_ALLOCA
472 # define YYSTACK_ALLOC __builtin_alloca
473 # elif defined __BUILTIN_VA_ARG_INCR
474 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
476 # define YYSTACK_ALLOC __alloca
477 # elif defined _MSC_VER
478 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
479 # define alloca _alloca
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
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 */
504 # define YYSTACK_ALLOC YYMALLOC
505 # define YYSTACK_FREE YYFREE
506 # ifndef YYSTACK_ALLOC_MAXIMUM
507 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
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
518 # define YYMALLOC malloc
519 # if ! defined malloc && ! defined EXIT_SUCCESS
520 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
525 # if ! defined free && ! defined EXIT_SUCCESS
526 void free (void *); /* INFRINGES ON USER NAME SPACE */
530 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
533 #if (! defined yyoverflow \
534 && (! defined __cplusplus \
535 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
537 /* A type that is properly aligned for any stack member. */
540 yytype_int16 yyss_alloc;
544 /* The size of the maximum gap between one aligned stack and the next. */
545 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
547 /* The size of an array large to enough to hold all stacks, each with
549 # define YYSTACK_BYTES(N) \
550 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
551 + YYSTACK_GAP_MAXIMUM)
553 # define YYCOPY_NEEDED 1
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
560 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
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); \
573 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
574 /* Copy COUNT objects from SRC to DST. The source and destination do
577 # if defined __GNUC__ && 1 < __GNUC__
578 # define YYCOPY(Dst, Src, Count) \
579 __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
581 # define YYCOPY(Dst, Src, Count) \
585 for (yyi = 0; yyi < (Count); yyi++) \
586 (Dst)[yyi] = (Src)[yyi]; \
591 #endif /* !YYCOPY_NEEDED */
593 /* YYFINAL -- State number of the termination state. */
595 /* YYLAST -- Last index in YYTABLE. */
598 /* YYNTOKENS -- Number of terminals. */
600 /* YYNNTS -- Number of nonterminals. */
602 /* YYNRULES -- Number of rules. */
604 /* YYNSTATES -- Number of states. */
605 #define YYNSTATES 335
607 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
608 by yylex, with out-of-bounds checking. */
610 #define YYMAXUTOK 308
612 #define YYTRANSLATE(YYX) \
613 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
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[] =
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
653 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
654 static const yytype_uint16 yyrline[] =
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
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[] =
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
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[] =
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,
727 #define YYPACT_NINF -273
729 #define yypact_value_is_default(Yystate) \
730 (!!((Yystate) == (-273)))
732 #define YYTABLE_NINF -104
734 #define yytable_value_is_error(Yytable_value) \
735 (!!((Yytable_value) == (-104)))
737 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
739 static const yytype_int16 yypact[] =
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
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[] =
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,
818 /* YYPGOTO[NTERM-NUM]. */
819 static const yytype_int16 yypgoto[] =
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
830 /* YYDEFGOTO[NTERM-NUM]. */
831 static const yytype_int16 yydefgoto[] =
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
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[] =
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
965 static const yytype_int16 yycheck[] =
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
1085 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
1086 symbol of state STATE-NUM. */
1087 static const yytype_uint8 yystos[] =
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,
1125 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1126 static const yytype_uint8 yyr1[] =
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
1149 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
1150 static const yytype_uint8 yyr2[] =
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
1174 #define yyerrok (yyerrstatus = 0)
1175 #define yyclearin (yychar = YYEMPTY)
1176 #define YYEMPTY (-2)
1179 #define YYACCEPT goto yyacceptlab
1180 #define YYABORT goto yyabortlab
1181 #define YYERROR goto yyerrorlab
1184 #define YYRECOVERING() (!!yyerrstatus)
1186 #define YYBACKUP(Token, Value) \
1188 if (yychar == YYEMPTY) \
1192 YYPOPSTACK (yylen); \
1198 yyerror (YY_("syntax error: cannot back up")); \
1203 /* Error token number */
1205 #define YYERRCODE 256
1209 /* Enable debugging if requested. */
1213 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1214 # define YYFPRINTF fprintf
1217 # define YYDPRINTF(Args) \
1223 /* This macro is provided for backward compatibility. */
1224 #ifndef YY_LOCATION_PRINT
1225 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1229 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
1233 YYFPRINTF (stderr, "%s ", Title); \
1234 yy_symbol_print (stderr, \
1236 YYFPRINTF (stderr, "\n"); \
1241 /*----------------------------------------.
1242 | Print this symbol's value on YYOUTPUT. |
1243 `----------------------------------------*/
1246 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
1248 FILE *yyo = yyoutput;
1253 if (yytype < YYNTOKENS)
1254 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1260 /*--------------------------------.
1261 | Print this symbol on YYOUTPUT. |
1262 `--------------------------------*/
1265 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
1267 YYFPRINTF (yyoutput, "%s %s (",
1268 yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
1270 yy_symbol_value_print (yyoutput, yytype, yyvaluep);
1271 YYFPRINTF (yyoutput, ")");
1274 /*------------------------------------------------------------------.
1275 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1277 `------------------------------------------------------------------*/
1280 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
1282 YYFPRINTF (stderr, "Stack now");
1283 for (; yybottom <= yytop; yybottom++)
1285 int yybot = *yybottom;
1286 YYFPRINTF (stderr, " %d", yybot);
1288 YYFPRINTF (stderr, "\n");
1291 # define YY_STACK_PRINT(Bottom, Top) \
1294 yy_stack_print ((Bottom), (Top)); \
1298 /*------------------------------------------------.
1299 | Report that the YYRULE is going to be reduced. |
1300 `------------------------------------------------*/
1303 yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
1305 unsigned long int yylno = yyrline[yyrule];
1306 int yynrhs = yyr2[yyrule];
1308 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1310 /* The symbols being reduced. */
1311 for (yyi = 0; yyi < yynrhs; yyi++)
1313 YYFPRINTF (stderr, " $%d = ", yyi + 1);
1314 yy_symbol_print (stderr,
1315 yystos[yyssp[yyi + 1 - yynrhs]],
1316 &(yyvsp[(yyi + 1) - (yynrhs)])
1318 YYFPRINTF (stderr, "\n");
1322 # define YY_REDUCE_PRINT(Rule) \
1325 yy_reduce_print (yyssp, yyvsp, Rule); \
1328 /* Nonzero means print parse trace. It is left uninitialized so that
1329 multiple parsers can coexist. */
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 */
1339 /* YYINITDEPTH -- initial size of the parser's stacks. */
1341 # define YYINITDEPTH 200
1344 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1345 if the built-in stack extension method is used).
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. */
1352 # define YYMAXDEPTH 10000
1359 # if defined __GLIBC__ && defined _STRING_H
1360 # define yystrlen strlen
1362 /* Return the length of YYSTR. */
1364 yystrlen (const char *yystr)
1367 for (yylen = 0; yystr[yylen]; yylen++)
1375 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1376 # define yystpcpy stpcpy
1378 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1381 yystpcpy (char *yydest, const char *yysrc)
1384 const char *yys = yysrc;
1386 while ((*yyd++ = *yys++) != '\0')
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
1403 yytnamerr (char *yyres, const char *yystr)
1408 char const *yyp = yystr;
1415 goto do_not_strip_quotes;
1419 goto do_not_strip_quotes;
1432 do_not_strip_quotes: ;
1436 return yystrlen (yystr);
1438 return yystpcpy (yyres, yystr) - yyres;
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
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. */
1451 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1452 yytype_int16 *yyssp, int yytoken)
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
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.
1488 if (yytoken != YYEMPTY)
1490 int yyn = yypact[*yyssp];
1491 yyarg[yycount++] = yytname[yytoken];
1492 if (!yypact_value_is_default (yyn))
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;
1503 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1504 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1505 && !yytable_value_is_error (yytable[yyx + yyn]))
1507 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1513 yyarg[yycount++] = yytname[yyx];
1515 YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
1516 if (! (yysize <= yysize1
1517 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1527 # define YYCASE_(N, S) \
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"));
1541 YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1542 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1547 if (*yymsg_alloc < yysize)
1549 *yymsg_alloc = 2 * yysize;
1550 if (! (yysize <= *yymsg_alloc
1551 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1552 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
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. */
1562 while ((*yyp = *yyformat) != '\0')
1563 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1565 yyp += yytnamerr (yyp, yyarg[yyi++]);
1576 #endif /* YYERROR_VERBOSE */
1578 /*-----------------------------------------------.
1579 | Release the memory associated to this symbol. |
1580 `-----------------------------------------------*/
1583 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1588 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1590 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1592 YY_IGNORE_MAYBE_UNINITIALIZED_END
1598 /* The lookahead symbol. */
1601 /* The semantic value of the lookahead symbol. */
1603 /* Number of syntax errors so far. */
1615 /* Number of tokens to shift before error messages enabled. */
1618 /* The stacks and their tools:
1619 'yyss': related to states.
1620 'yyvs': related to semantic values.
1622 Refer to the stacks through separate pointers, to allow yyoverflow
1623 to reallocate them elsewhere. */
1625 /* The state stack. */
1626 yytype_int16 yyssa[YYINITDEPTH];
1628 yytype_int16 *yyssp;
1630 /* The semantic value stack. */
1631 YYSTYPE yyvsa[YYINITDEPTH];
1635 YYSIZE_T yystacksize;
1639 /* Lookahead token as an internal (translated) token number. */
1641 /* The variables used to return semantic value and location from the
1646 /* Buffer for error messages, and its allocated size. */
1648 char *yymsg = yymsgbuf;
1649 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1652 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1654 /* The number of symbols on the RHS of the reduced rule.
1655 Keep to zero when no symbol should be popped. */
1658 yyssp = yyss = yyssa;
1659 yyvsp = yyvs = yyvsa;
1660 yystacksize = YYINITDEPTH;
1662 YYDPRINTF ((stderr, "Starting parse\n"));
1667 yychar = YYEMPTY; /* Cause a token to be read. */
1670 /*------------------------------------------------------------.
1671 | yynewstate -- Push a new state, which is found in yystate. |
1672 `------------------------------------------------------------*/
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. */
1681 if (yyss + yystacksize - 1 <= yyssp)
1683 /* Get the current used size of the three stacks, in elements. */
1684 YYSIZE_T yysize = yyssp - yyss + 1;
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
1691 YYSTYPE *yyvs1 = yyvs;
1692 yytype_int16 *yyss1 = yyss;
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),
1706 #else /* no yyoverflow */
1707 # ifndef YYSTACK_RELOCATE
1708 goto yyexhaustedlab;
1710 /* Extend the stack our own way. */
1711 if (YYMAXDEPTH <= yystacksize)
1712 goto yyexhaustedlab;
1714 if (YYMAXDEPTH < yystacksize)
1715 yystacksize = YYMAXDEPTH;
1718 yytype_int16 *yyss1 = yyss;
1719 union yyalloc *yyptr =
1720 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1722 goto yyexhaustedlab;
1723 YYSTACK_RELOCATE (yyss_alloc, yyss);
1724 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1725 # undef YYSTACK_RELOCATE
1727 YYSTACK_FREE (yyss1);
1730 #endif /* no yyoverflow */
1732 yyssp = yyss + yysize - 1;
1733 yyvsp = yyvs + yysize - 1;
1735 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1736 (unsigned long int) yystacksize));
1738 if (yyss + yystacksize - 1 <= yyssp)
1742 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1744 if (yystate == YYFINAL)
1754 /* Do appropriate processing given the current state. Read a
1755 lookahead token if we need one and don't already have one. */
1757 /* First try to decide what to do without reference to lookahead token. */
1758 yyn = yypact[yystate];
1759 if (yypact_value_is_default (yyn))
1762 /* Not known => get a lookahead token if don't already have one. */
1764 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1765 if (yychar == YYEMPTY)
1767 YYDPRINTF ((stderr, "Reading a token: "));
1771 if (yychar <= YYEOF)
1773 yychar = yytoken = YYEOF;
1774 YYDPRINTF ((stderr, "Now at end of input.\n"));
1778 yytoken = YYTRANSLATE (yychar);
1779 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1782 /* If the proper action on seeing token YYTOKEN is to reduce or to
1783 detect an error, take that action. */
1785 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1790 if (yytable_value_is_error (yyn))
1796 /* Count tokens shifted since error; after three, turn off error
1801 /* Shift the lookahead token. */
1802 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1804 /* Discard the shifted token. */
1808 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1810 YY_IGNORE_MAYBE_UNINITIALIZED_END
1815 /*-----------------------------------------------------------.
1816 | yydefault -- do the default action for the current state. |
1817 `-----------------------------------------------------------*/
1819 yyn = yydefact[yystate];
1825 /*-----------------------------.
1826 | yyreduce -- Do a reduction. |
1827 `-----------------------------*/
1829 /* yyn is the number of a rule to reduce with. */
1832 /* If YYLEN is nonzero, implement the default value of the action:
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];
1843 YY_REDUCE_PRINT (yyn);
1847 #line 203 "awkgram.y" /* yacc.c:1646 */
1852 #line 1853 "awkgram.c" /* yacc.c:1646 */
1856 #line 209 "awkgram.y" /* yacc.c:1646 */
1859 if (sourcefile == srcfiles)
1862 #line 1863 "awkgram.c" /* yacc.c:1646 */
1866 #line 215 "awkgram.y" /* yacc.c:1646 */
1870 * If errors, give up, don't produce an infinite
1871 * stream of syntax error messages.
1875 #line 1876 "awkgram.c" /* yacc.c:1646 */
1879 #line 227 "awkgram.y" /* yacc.c:1646 */
1881 (void) append_rule((yyvsp[-1]), (yyvsp[0]));
1883 #line 1884 "awkgram.c" /* yacc.c:1646 */
1887 #line 231 "awkgram.y" /* yacc.c:1646 */
1890 msg(_("%s blocks must have an action part"), ruletab[rule]);
1892 } else if ((yyvsp[-1]) == NULL) {
1893 msg(_("each rule must have a pattern or an action part"));
1895 } else /* pattern rule with non-empty pattern */
1896 (void) append_rule((yyvsp[-1]), NULL);
1898 #line 1899 "awkgram.c" /* yacc.c:1646 */
1902 #line 242 "awkgram.y" /* yacc.c:1646 */
1905 (void) mk_function((yyvsp[-1]), (yyvsp[0]));
1908 #line 1909 "awkgram.c" /* yacc.c:1646 */
1912 #line 248 "awkgram.y" /* yacc.c:1646 */
1914 want_source = false;
1917 #line 1918 "awkgram.c" /* yacc.c:1646 */
1921 #line 253 "awkgram.y" /* yacc.c:1646 */
1923 want_source = false;
1926 #line 1927 "awkgram.c" /* yacc.c:1646 */
1930 #line 261 "awkgram.y" /* yacc.c:1646 */
1932 if (include_source((yyvsp[0])) < 0)
1934 efree((yyvsp[0])->lextok);
1938 #line 1939 "awkgram.c" /* yacc.c:1646 */
1942 #line 269 "awkgram.y" /* yacc.c:1646 */
1944 #line 1945 "awkgram.c" /* yacc.c:1646 */
1948 #line 271 "awkgram.y" /* yacc.c:1646 */
1950 #line 1951 "awkgram.c" /* yacc.c:1646 */
1954 #line 276 "awkgram.y" /* yacc.c:1646 */
1956 if (load_library((yyvsp[0])) < 0)
1958 efree((yyvsp[0])->lextok);
1962 #line 1963 "awkgram.c" /* yacc.c:1646 */
1966 #line 284 "awkgram.y" /* yacc.c:1646 */
1968 #line 1969 "awkgram.c" /* yacc.c:1646 */
1972 #line 286 "awkgram.y" /* yacc.c:1646 */
1974 #line 1975 "awkgram.c" /* yacc.c:1646 */
1978 #line 291 "awkgram.y" /* yacc.c:1646 */
1979 { (yyval) = NULL; rule = Rule; }
1980 #line 1981 "awkgram.c" /* yacc.c:1646 */
1984 #line 293 "awkgram.y" /* yacc.c:1646 */
1985 { (yyval) = (yyvsp[0]); rule = Rule; }
1986 #line 1987 "awkgram.c" /* yacc.c:1646 */
1990 #line 295 "awkgram.y" /* yacc.c:1646 */
1994 add_lint((yyvsp[-3]), LINT_assign_in_cond);
1995 add_lint((yyvsp[0]), LINT_assign_in_cond);
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;
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;
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;
2013 (yyval) = list_append(list_merge((yyvsp[-3]), (yyvsp[0])), tp);
2016 #line 2017 "awkgram.c" /* yacc.c:1646 */
2020 #line 321 "awkgram.y" /* yacc.c:1646 */
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"));
2027 (yyvsp[0])->in_rule = rule = BEGIN;
2028 (yyvsp[0])->source_file = source;
2029 (yyval) = (yyvsp[0]);
2031 #line 2032 "awkgram.c" /* yacc.c:1646 */
2035 #line 332 "awkgram.y" /* yacc.c:1646 */
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"));
2042 (yyvsp[0])->in_rule = rule = END;
2043 (yyvsp[0])->source_file = source;
2044 (yyval) = (yyvsp[0]);
2046 #line 2047 "awkgram.c" /* yacc.c:1646 */
2050 #line 343 "awkgram.y" /* yacc.c:1646 */
2052 (yyvsp[0])->in_rule = rule = BEGINFILE;
2053 (yyvsp[0])->source_file = source;
2054 (yyval) = (yyvsp[0]);
2056 #line 2057 "awkgram.c" /* yacc.c:1646 */
2060 #line 349 "awkgram.y" /* yacc.c:1646 */
2062 (yyvsp[0])->in_rule = rule = ENDFILE;
2063 (yyvsp[0])->source_file = source;
2064 (yyval) = (yyvsp[0]);
2066 #line 2067 "awkgram.c" /* yacc.c:1646 */
2070 #line 358 "awkgram.y" /* yacc.c:1646 */
2072 if ((yyvsp[-3]) == NULL)
2073 (yyval) = list_create(instruction(Op_no_op));
2075 (yyval) = (yyvsp[-3]);
2077 #line 2078 "awkgram.c" /* yacc.c:1646 */
2081 #line 368 "awkgram.y" /* yacc.c:1646 */
2082 { (yyval) = (yyvsp[0]); }
2083 #line 2084 "awkgram.c" /* yacc.c:1646 */
2087 #line 370 "awkgram.y" /* yacc.c:1646 */
2088 { (yyval) = (yyvsp[0]); }
2089 #line 2090 "awkgram.c" /* yacc.c:1646 */
2093 #line 372 "awkgram.y" /* yacc.c:1646 */
2095 yyerror(_("`%s' is a built-in function, it cannot be redefined"),
2099 #line 2100 "awkgram.c" /* yacc.c:1646 */
2103 #line 378 "awkgram.y" /* yacc.c:1646 */
2104 { (yyval) = (yyvsp[0]); }
2105 #line 2106 "awkgram.c" /* yacc.c:1646 */
2109 #line 388 "awkgram.y" /* yacc.c:1646 */
2111 (yyvsp[-5])->source_file = source;
2112 if (install_function((yyvsp[-4])->lextok, (yyvsp[-5]), (yyvsp[-2])) < 0)
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]);
2120 #line 2121 "awkgram.c" /* yacc.c:1646 */
2124 #line 406 "awkgram.y" /* yacc.c:1646 */
2125 { want_regexp = true; }
2126 #line 2127 "awkgram.c" /* yacc.c:1646 */
2130 #line 408 "awkgram.y" /* yacc.c:1646 */
2136 re = (yyvsp[0])->lextok;
2137 (yyvsp[0])->lextok = NULL;
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);
2149 exp = make_str_node(re, len, ALREADY_MALLOCED);
2150 n = make_regnode(Node_regex, exp);
2155 (yyval) = (yyvsp[0]);
2156 (yyval)->opcode = Op_match_rec;
2157 (yyval)->memory = n;
2159 #line 2160 "awkgram.c" /* yacc.c:1646 */
2163 #line 440 "awkgram.y" /* yacc.c:1646 */
2164 { bcfree((yyvsp[0])); }
2165 #line 2166 "awkgram.c" /* yacc.c:1646 */
2169 #line 446 "awkgram.y" /* yacc.c:1646 */
2171 #line 2172 "awkgram.c" /* yacc.c:1646 */
2175 #line 448 "awkgram.y" /* yacc.c:1646 */
2177 if ((yyvsp[0]) == NULL)
2178 (yyval) = (yyvsp[-1]);
2180 add_lint((yyvsp[0]), LINT_no_effect);
2181 if ((yyvsp[-1]) == NULL)
2182 (yyval) = (yyvsp[0]);
2184 (yyval) = list_merge((yyvsp[-1]), (yyvsp[0]));
2188 #line 2189 "awkgram.c" /* yacc.c:1646 */
2192 #line 461 "awkgram.y" /* yacc.c:1646 */
2194 #line 2195 "awkgram.c" /* yacc.c:1646 */
2198 #line 471 "awkgram.y" /* yacc.c:1646 */
2200 #line 2201 "awkgram.c" /* yacc.c:1646 */
2204 #line 473 "awkgram.y" /* yacc.c:1646 */
2205 { (yyval) = (yyvsp[-1]); }
2206 #line 2207 "awkgram.c" /* yacc.c:1646 */
2210 #line 475 "awkgram.y" /* yacc.c:1646 */
2212 if (do_pretty_print)
2213 (yyval) = list_prepend((yyvsp[0]), instruction(Op_exec_count));
2215 (yyval) = (yyvsp[0]);
2217 #line 2218 "awkgram.c" /* yacc.c:1646 */
2221 #line 482 "awkgram.y" /* yacc.c:1646 */
2223 INSTRUCTION *dflt, *curr = NULL, *cexp, *cstmt;
2224 INSTRUCTION *ip, *nextc, *tbreak;
2225 const char **case_values = NULL;
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 */
2236 if ((yyvsp[-2]) != NULL) {
2237 curr = (yyvsp[-2])->nexti;
2238 bcfree((yyvsp[-2])); /* Op_list */
2242 for(; curr != NULL; curr = nextc) {
2243 INSTRUCTION *caseexp = curr->case_exp;
2244 INSTRUCTION *casestmt = curr->case_stmt;
2246 nextc = curr->nexti;
2247 if (curr->opcode == Op_K_case) {
2248 if (caseexp->opcode == Op_push_i) {
2249 /* a constant scalar */
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);
2258 if (case_values == NULL)
2259 emalloc(case_values, const char **, sizeof(char *) * maxcount, "statement");
2260 else if (case_count >= maxcount) {
2262 erealloc(case_values, const char **, sizeof(char*) * maxcount, "statement");
2264 case_values[case_count++] = caseval;
2266 /* match a constant regex against switch expression. */
2267 (curr + 1)->match_exp = true;
2269 curr->stmt_start = casestmt->nexti;
2270 curr->stmt_end = casestmt->lasti;
2271 (void) list_prepend(cexp, curr);
2272 (void) list_prepend(cexp, caseexp);
2274 if (dflt->target_jmp != tbreak)
2275 error_ln(curr->source_line,
2276 _("duplicate `default' detected in switch body"));
2278 dflt->target_jmp = casestmt->nexti;
2280 if (do_pretty_print) {
2281 curr->stmt_start = casestmt->nexti;
2282 curr->stmt_end = casestmt->lasti;
2283 (void) list_prepend(cexp, curr);
2288 cstmt = list_merge(casestmt, cstmt);
2291 if (case_values != NULL)
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;
2304 (void) list_append(cexp, dflt);
2305 (void) list_merge(ip, cexp);
2306 (yyval) = list_merge(ip, cstmt);
2309 fix_break_continue(ip, tbreak, NULL);
2311 #line 2312 "awkgram.c" /* yacc.c:1646 */
2315 #line 572 "awkgram.y" /* yacc.c:1646 */
2322 * [Op_jmp_false tb ]
2330 INSTRUCTION *ip, *tbreak, *tcont;
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;
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]));
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);
2355 fix_break_continue(ip, tbreak, tcont);
2357 #line 2358 "awkgram.c" /* yacc.c:1646 */
2361 #line 614 "awkgram.y" /* yacc.c:1646 */
2371 * [Op_jmp_true | z ]
2375 INSTRUCTION *ip, *tbreak, *tcont;
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]));
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);
2392 fix_break_continue(ip, tbreak, tcont);
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]));
2401 $1 and $4 are NULLs */
2403 #line 2404 "awkgram.c" /* yacc.c:1646 */
2407 #line 656 "awkgram.y" /* yacc.c:1646 */
2410 char *var_name = (yyvsp[-5])->lextok;
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
2420 /* Efficiency hack. Recognize the special case of
2425 * and treat it as if it were
2429 * Check that the body is a `delete a[i]' statement,
2430 * and that both the loop var and array names match.
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;
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
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]));
2449 bcfree((yyvsp[-5]));
2450 bcfree((yyvsp[-4]));
2451 bcfree((yyvsp[-3]));
2452 (yyval) = (yyvsp[0]);
2456 INSTRUCTION *tbreak, *tcont;
2458 /* [ Op_push_array a ]
2459 * [ Op_arrayfor_init | ib ]
2460 * ic:[ Op_arrayfor_incr | ib ]
2461 * [ Op_var_assign if any ]
2466 * ib:[Op_arrayfor_final ]
2470 ip->nexti->opcode = Op_push_array;
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]));
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]));
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;
2494 (void) list_append(ip, (yyvsp[-4]));
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;
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;
2508 if ((yyvsp[0]) != NULL)
2509 (void) list_merge(ip, (yyvsp[0]));
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);
2520 #line 2521 "awkgram.c" /* yacc.c:1646 */
2524 #line 769 "awkgram.y" /* yacc.c:1646 */
2526 (yyval) = mk_for_loop((yyvsp[-11]), (yyvsp[-9]), (yyvsp[-6]), (yyvsp[-3]), (yyvsp[0]));
2531 #line 2532 "awkgram.c" /* yacc.c:1646 */
2535 #line 776 "awkgram.y" /* yacc.c:1646 */
2537 (yyval) = mk_for_loop((yyvsp[-10]), (yyvsp[-8]), (INSTRUCTION *) NULL, (yyvsp[-3]), (yyvsp[0]));
2542 #line 2543 "awkgram.c" /* yacc.c:1646 */
2546 #line 783 "awkgram.y" /* yacc.c:1646 */
2548 if (do_pretty_print)
2549 (yyval) = list_prepend((yyvsp[0]), instruction(Op_exec_count));
2551 (yyval) = (yyvsp[0]);
2553 #line 2554 "awkgram.c" /* yacc.c:1646 */
2557 #line 793 "awkgram.y" /* yacc.c:1646 */
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]));
2566 #line 2567 "awkgram.c" /* yacc.c:1646 */
2570 #line 802 "awkgram.y" /* yacc.c:1646 */
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]));
2579 #line 2580 "awkgram.c" /* yacc.c:1646 */
2583 #line 811 "awkgram.y" /* yacc.c:1646 */
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]));
2592 #line 2593 "awkgram.c" /* yacc.c:1646 */
2596 #line 820 "awkgram.y" /* yacc.c:1646 */
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]);
2603 (yyvsp[-1])->target_newfile = ip_newfile;
2604 (yyvsp[-1])->target_endfile = ip_endfile;
2605 (yyval) = list_create((yyvsp[-1]));
2607 #line 2608 "awkgram.c" /* yacc.c:1646 */
2611 #line 831 "awkgram.y" /* yacc.c:1646 */
2613 /* Initialize the two possible jump targets, the actual target
2614 * is resolved at run-time.
2616 (yyvsp[-2])->target_end = ip_end; /* first instruction in end_block */
2617 (yyvsp[-2])->target_atexit = ip_atexit; /* cleanup and go home */
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);
2624 (yyval) = list_append((yyvsp[-1]), (yyvsp[-2]));
2626 #line 2627 "awkgram.c" /* yacc.c:1646 */
2630 #line 846 "awkgram.y" /* yacc.c:1646 */
2633 yyerror(_("`return' used outside function context"));
2635 #line 2636 "awkgram.c" /* yacc.c:1646 */
2639 #line 849 "awkgram.y" /* yacc.c:1646 */
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);
2647 && (yyvsp[-1])->lasti->opcode == Op_func_call
2648 && strcmp((yyvsp[-1])->lasti->func_name, in_function) == 0
2650 /* Do tail recursion optimization. Tail
2651 * call without a return value is recognized
2654 ((yyvsp[-1])->lasti + 1)->tail_call = true;
2657 (yyval) = list_append((yyvsp[-1]), (yyvsp[-3]));
2660 #line 2661 "awkgram.c" /* yacc.c:1646 */
2664 #line 881 "awkgram.y" /* yacc.c:1646 */
2665 { in_print = true; in_parens = 0; }
2666 #line 2667 "awkgram.c" /* yacc.c:1646 */
2670 #line 882 "awkgram.y" /* yacc.c:1646 */
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.
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)
2686 static bool warned = false;
2687 /* -----------------
2692 * ------------------
2693 * [Op_K_print_rec | NULL | redir_type | expr_count]
2696 if ((yyvsp[-1]) != NULL) {
2697 NODE *n = (yyvsp[-1])->nexti->nexti->memory;
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 */
2708 if (do_lint && (rule == BEGIN || rule == END) && ! warned) {
2710 lintwarn_ln((yyvsp[-3])->source_line,
2711 _("plain `print' in BEGIN or END rule should probably be `print \"\"'"));
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]));
2722 ip = (yyvsp[0])->nexti;
2723 (yyvsp[-3])->redir_type = ip->redir_type;
2724 (yyvsp[0])->nexti = ip->nexti;
2726 (yyval) = list_append((yyvsp[0]), (yyvsp[-3]));
2729 /* -----------------
2733 * [ expression_list ]
2734 * ------------------
2735 * [$1 | NULL | redir_type | expr_count]
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]));
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]));
2752 ip = (yyvsp[0])->nexti;
2753 (yyvsp[-3])->redir_type = ip->redir_type;
2754 (yyvsp[0])->nexti = ip->nexti;
2756 if ((yyvsp[-1]) == NULL) {
2757 (yyvsp[-3])->expr_count = 0;
2758 (yyval) = list_append((yyvsp[0]), (yyvsp[-3]));
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]));
2767 #line 2768 "awkgram.c" /* yacc.c:1646 */
2771 #line 979 "awkgram.y" /* yacc.c:1646 */
2772 { sub_counter = 0; }
2773 #line 2774 "awkgram.c" /* yacc.c:1646 */
2777 #line 980 "awkgram.y" /* yacc.c:1646 */
2779 char *arr = (yyvsp[-2])->lextok;
2781 (yyvsp[-2])->opcode = Op_push_array;
2782 (yyvsp[-2])->memory = variable((yyvsp[-2])->source_line, arr, Node_var_new);
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"));
2791 if ((yyvsp[0]) == NULL) {
2793 * As of September 2012, POSIX has added support
2794 * for `delete array'. See:
2795 * http://austingroupbugs.net/view.php?id=544
2797 * Thanks to Nathan Weeks for the initiative.
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.
2803 (yyvsp[-3])->expr_count = 0;
2804 (yyval) = list_append(list_create((yyvsp[-2])), (yyvsp[-3]));
2806 (yyvsp[-3])->expr_count = sub_counter;
2807 (yyval) = list_append(list_append((yyvsp[0]), (yyvsp[-2])), (yyvsp[-3]));
2810 #line 2811 "awkgram.c" /* yacc.c:1646 */
2814 #line 1017 "awkgram.y" /* yacc.c:1646 */
2816 static bool warned = false;
2817 char *arr = (yyvsp[-1])->lextok;
2819 if (do_lint && ! warned) {
2821 lintwarn_ln((yyvsp[-3])->source_line,
2822 _("`delete(array)' is a non-portable tawk extension"));
2824 if (do_traditional) {
2825 error_ln((yyvsp[-3])->source_line,
2826 _("`delete(array)' is a non-portable tawk extension"));
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]));
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"));
2840 #line 2841 "awkgram.c" /* yacc.c:1646 */
2844 #line 1043 "awkgram.y" /* yacc.c:1646 */
2845 { (yyval) = optimize_assignment((yyvsp[0])); }
2846 #line 2847 "awkgram.c" /* yacc.c:1646 */
2850 #line 1048 "awkgram.y" /* yacc.c:1646 */
2852 #line 2853 "awkgram.c" /* yacc.c:1646 */
2856 #line 1050 "awkgram.y" /* yacc.c:1646 */
2857 { (yyval) = (yyvsp[0]); }
2858 #line 2859 "awkgram.c" /* yacc.c:1646 */
2862 #line 1055 "awkgram.y" /* yacc.c:1646 */
2864 #line 2865 "awkgram.c" /* yacc.c:1646 */
2868 #line 1057 "awkgram.y" /* yacc.c:1646 */
2870 if ((yyvsp[-1]) == NULL)
2871 (yyval) = list_create((yyvsp[0]));
2873 (yyval) = list_prepend((yyvsp[-1]), (yyvsp[0]));
2875 #line 2876 "awkgram.c" /* yacc.c:1646 */
2879 #line 1064 "awkgram.y" /* yacc.c:1646 */
2881 #line 2882 "awkgram.c" /* yacc.c:1646 */
2885 #line 1069 "awkgram.y" /* yacc.c:1646 */
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]);
2897 #line 2898 "awkgram.c" /* yacc.c:1646 */
2901 #line 1081 "awkgram.y" /* yacc.c:1646 */
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]);
2912 #line 2913 "awkgram.c" /* yacc.c:1646 */
2916 #line 1095 "awkgram.y" /* yacc.c:1646 */
2917 { (yyval) = (yyvsp[0]); }
2918 #line 2919 "awkgram.c" /* yacc.c:1646 */
2922 #line 1097 "awkgram.y" /* yacc.c:1646 */
2924 NODE *n = (yyvsp[0])->memory;
2925 (void) force_number(n);
2927 bcfree((yyvsp[-1]));
2928 (yyval) = (yyvsp[0]);
2930 #line 2931 "awkgram.c" /* yacc.c:1646 */
2934 #line 1105 "awkgram.y" /* yacc.c:1646 */
2936 bcfree((yyvsp[-1]));
2937 (yyval) = (yyvsp[0]);
2939 #line 2940 "awkgram.c" /* yacc.c:1646 */
2943 #line 1110 "awkgram.y" /* yacc.c:1646 */
2944 { (yyval) = (yyvsp[0]); }
2945 #line 2946 "awkgram.c" /* yacc.c:1646 */
2949 #line 1112 "awkgram.y" /* yacc.c:1646 */
2951 (yyvsp[0])->opcode = Op_push_re;
2952 (yyval) = (yyvsp[0]);
2954 #line 2955 "awkgram.c" /* yacc.c:1646 */
2958 #line 1120 "awkgram.y" /* yacc.c:1646 */
2959 { (yyval) = (yyvsp[0]); }
2960 #line 2961 "awkgram.c" /* yacc.c:1646 */
2964 #line 1122 "awkgram.y" /* yacc.c:1646 */
2965 { (yyval) = (yyvsp[0]); }
2966 #line 2967 "awkgram.c" /* yacc.c:1646 */
2970 #line 1132 "awkgram.y" /* yacc.c:1646 */
2972 (yyval) = (yyvsp[-1]);
2974 #line 2975 "awkgram.c" /* yacc.c:1646 */
2978 #line 1139 "awkgram.y" /* yacc.c:1646 */
2984 #line 2985 "awkgram.c" /* yacc.c:1646 */
2988 #line 1144 "awkgram.y" /* yacc.c:1646 */
2989 { in_print = false; in_parens = 0; }
2990 #line 2991 "awkgram.c" /* yacc.c:1646 */
2994 #line 1145 "awkgram.y" /* yacc.c:1646 */
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]));
3002 #line 3003 "awkgram.c" /* yacc.c:1646 */
3006 #line 1156 "awkgram.y" /* yacc.c:1646 */
3008 (yyval) = mk_condition((yyvsp[-3]), (yyvsp[-5]), (yyvsp[0]), NULL, NULL);
3010 #line 3011 "awkgram.c" /* yacc.c:1646 */
3014 #line 1161 "awkgram.y" /* yacc.c:1646 */
3016 (yyval) = mk_condition((yyvsp[-6]), (yyvsp[-8]), (yyvsp[-3]), (yyvsp[-2]), (yyvsp[0]));
3018 #line 3019 "awkgram.c" /* yacc.c:1646 */
3022 #line 1178 "awkgram.y" /* yacc.c:1646 */
3024 #line 3025 "awkgram.c" /* yacc.c:1646 */
3028 #line 1180 "awkgram.y" /* yacc.c:1646 */
3030 bcfree((yyvsp[-1]));
3031 (yyval) = (yyvsp[0]);
3033 #line 3034 "awkgram.c" /* yacc.c:1646 */
3037 #line 1188 "awkgram.y" /* yacc.c:1646 */
3039 #line 3040 "awkgram.c" /* yacc.c:1646 */
3043 #line 1190 "awkgram.y" /* yacc.c:1646 */
3044 { (yyval) = (yyvsp[0]) ; }
3045 #line 3046 "awkgram.c" /* yacc.c:1646 */
3049 #line 1195 "awkgram.y" /* yacc.c:1646 */
3051 (yyvsp[0])->param_count = 0;
3052 (yyval) = list_create((yyvsp[0]));
3054 #line 3055 "awkgram.c" /* yacc.c:1646 */
3058 #line 1200 "awkgram.y" /* yacc.c:1646 */
3060 (yyvsp[0])->param_count = (yyvsp[-2])->lasti->param_count + 1;
3061 (yyval) = list_append((yyvsp[-2]), (yyvsp[0]));
3064 #line 3065 "awkgram.c" /* yacc.c:1646 */
3068 #line 1206 "awkgram.y" /* yacc.c:1646 */
3070 #line 3071 "awkgram.c" /* yacc.c:1646 */
3074 #line 1208 "awkgram.y" /* yacc.c:1646 */
3075 { (yyval) = (yyvsp[-1]); }
3076 #line 3077 "awkgram.c" /* yacc.c:1646 */
3080 #line 1210 "awkgram.y" /* yacc.c:1646 */
3081 { (yyval) = (yyvsp[-2]); }
3082 #line 3083 "awkgram.c" /* yacc.c:1646 */
3086 #line 1216 "awkgram.y" /* yacc.c:1646 */
3088 #line 3089 "awkgram.c" /* yacc.c:1646 */
3092 #line 1218 "awkgram.y" /* yacc.c:1646 */
3093 { (yyval) = (yyvsp[0]); }
3094 #line 3095 "awkgram.c" /* yacc.c:1646 */
3098 #line 1223 "awkgram.y" /* yacc.c:1646 */
3100 #line 3101 "awkgram.c" /* yacc.c:1646 */
3104 #line 1225 "awkgram.y" /* yacc.c:1646 */
3105 { (yyval) = (yyvsp[0]); }
3106 #line 3107 "awkgram.c" /* yacc.c:1646 */
3110 #line 1230 "awkgram.y" /* yacc.c:1646 */
3111 { (yyval) = mk_expression_list(NULL, (yyvsp[0])); }
3112 #line 3113 "awkgram.c" /* yacc.c:1646 */
3116 #line 1232 "awkgram.y" /* yacc.c:1646 */
3118 (yyval) = mk_expression_list((yyvsp[-2]), (yyvsp[0]));
3121 #line 3122 "awkgram.c" /* yacc.c:1646 */
3125 #line 1237 "awkgram.y" /* yacc.c:1646 */
3127 #line 3128 "awkgram.c" /* yacc.c:1646 */
3131 #line 1239 "awkgram.y" /* yacc.c:1646 */
3134 * Returning the expression list instead of NULL lets
3135 * snode get a list of arguments that it can count.
3137 (yyval) = (yyvsp[-1]);
3139 #line 3140 "awkgram.c" /* yacc.c:1646 */
3143 #line 1247 "awkgram.y" /* yacc.c:1646 */
3146 (yyval) = mk_expression_list((yyvsp[-2]), (yyvsp[0]));
3148 #line 3149 "awkgram.c" /* yacc.c:1646 */
3152 #line 1252 "awkgram.y" /* yacc.c:1646 */
3155 (yyval) = (yyvsp[-2]);
3157 #line 3158 "awkgram.c" /* yacc.c:1646 */
3161 #line 1261 "awkgram.y" /* yacc.c:1646 */
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]));
3168 #line 3169 "awkgram.c" /* yacc.c:1646 */
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 */
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 */
3184 #line 1272 "awkgram.y" /* yacc.c:1646 */
3186 if ((yyvsp[-2])->lasti->opcode == Op_match_rec)
3187 warning_ln((yyvsp[-1])->source_line,
3188 _("regular expression on left of `~' or `!~' operator"));
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]));
3196 (yyvsp[-1])->memory = make_regnode(Node_dynregex, NULL);
3197 (yyval) = list_append(list_merge((yyvsp[-2]), (yyvsp[0])), (yyvsp[-1]));
3200 #line 3201 "awkgram.c" /* yacc.c:1646 */
3204 #line 1288 "awkgram.y" /* yacc.c:1646 */
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]));
3214 #line 3215 "awkgram.c" /* yacc.c:1646 */
3218 #line 1298 "awkgram.y" /* yacc.c:1646 */
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]));
3225 #line 3226 "awkgram.c" /* yacc.c:1646 */
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 */
3235 #line 1307 "awkgram.y" /* yacc.c:1646 */
3236 { (yyval) = (yyvsp[0]); }
3237 #line 3238 "awkgram.c" /* yacc.c:1646 */
3241 #line 1312 "awkgram.y" /* yacc.c:1646 */
3242 { (yyval) = (yyvsp[0]); }
3243 #line 3244 "awkgram.c" /* yacc.c:1646 */
3247 #line 1314 "awkgram.y" /* yacc.c:1646 */
3248 { (yyval) = (yyvsp[0]); }
3249 #line 3250 "awkgram.c" /* yacc.c:1646 */
3253 #line 1316 "awkgram.y" /* yacc.c:1646 */
3255 (yyvsp[0])->opcode = Op_assign_quotient;
3256 (yyval) = (yyvsp[0]);
3258 #line 3259 "awkgram.c" /* yacc.c:1646 */
3262 #line 1324 "awkgram.y" /* yacc.c:1646 */
3263 { (yyval) = (yyvsp[0]); }
3264 #line 3265 "awkgram.c" /* yacc.c:1646 */
3268 #line 1326 "awkgram.y" /* yacc.c:1646 */
3269 { (yyval) = (yyvsp[0]); }
3270 #line 3271 "awkgram.c" /* yacc.c:1646 */
3274 #line 1331 "awkgram.y" /* yacc.c:1646 */
3275 { (yyval) = (yyvsp[0]); }
3276 #line 3277 "awkgram.c" /* yacc.c:1646 */
3280 #line 1333 "awkgram.y" /* yacc.c:1646 */
3281 { (yyval) = (yyvsp[0]); }
3282 #line 3283 "awkgram.c" /* yacc.c:1646 */
3286 #line 1338 "awkgram.y" /* yacc.c:1646 */
3287 { (yyval) = (yyvsp[0]); }
3288 #line 3289 "awkgram.c" /* yacc.c:1646 */
3292 #line 1340 "awkgram.y" /* yacc.c:1646 */
3293 { (yyval) = (yyvsp[0]); }
3294 #line 3295 "awkgram.c" /* yacc.c:1646 */
3298 #line 1342 "awkgram.y" /* yacc.c:1646 */
3301 bool is_simple_var = false;
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;
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.
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
3320 NODE *n1 = (yyvsp[-1])->nexti->memory;
3321 NODE *n2 = (yyvsp[0])->nexti->memory;
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);
3330 n1->stptr[nlen] = '\0';
3331 n1->flags &= ~(NUMCUR|NUMBER|NUMINT);
3332 n1->flags |= (STRING|STRCUR);
3334 bcfree((yyvsp[0])->nexti);
3336 (yyval) = (yyvsp[-1]);
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)
3345 #line 3346 "awkgram.c" /* yacc.c:1646 */
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 */
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 */
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 */
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 */
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 */
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 */
3385 #line 1406 "awkgram.y" /* yacc.c:1646 */
3388 * In BEGINFILE/ENDFILE, allow `getline var < file'
3391 if (rule == BEGINFILE || rule == ENDFILE) {
3392 if ((yyvsp[-1]) != NULL && (yyvsp[0]) != NULL)
3395 if ((yyvsp[-1]) != NULL)
3396 error_ln((yyvsp[-2])->source_line,
3397 _("`getline var' invalid inside `%s' rule"), ruletab[rule]);
3399 error_ln((yyvsp[-2])->source_line,
3400 _("`getline' invalid inside `%s' rule"), ruletab[rule]);
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);
3408 #line 3409 "awkgram.c" /* yacc.c:1646 */
3412 #line 1429 "awkgram.y" /* yacc.c:1646 */
3414 (yyvsp[0])->opcode = Op_postincrement;
3415 (yyval) = mk_assignment((yyvsp[-1]), NULL, (yyvsp[0]));
3417 #line 3418 "awkgram.c" /* yacc.c:1646 */
3421 #line 1434 "awkgram.y" /* yacc.c:1646 */
3423 (yyvsp[0])->opcode = Op_postdecrement;
3424 (yyval) = mk_assignment((yyvsp[-1]), NULL, (yyvsp[0]));
3426 #line 3427 "awkgram.c" /* yacc.c:1646 */
3430 #line 1439 "awkgram.y" /* yacc.c:1646 */
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"));
3438 (yyvsp[0])->nexti->opcode = Op_push_array;
3439 (yyvsp[-1])->opcode = Op_in_array;
3440 if ((yyvsp[-3]) == NULL) { /* error */
3442 (yyvsp[-1])->expr_count = 0;
3443 (yyval) = list_merge((yyvsp[0]), (yyvsp[-1]));
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]));
3450 #line 3451 "awkgram.c" /* yacc.c:1646 */
3454 #line 1464 "awkgram.y" /* yacc.c:1646 */
3456 (yyval) = mk_getline((yyvsp[-1]), (yyvsp[0]), (yyvsp[-3]), (yyvsp[-2])->redir_type);
3457 bcfree((yyvsp[-2]));
3459 #line 3460 "awkgram.c" /* yacc.c:1646 */
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 */
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 */
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 */
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 */
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 */
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 */
3499 #line 1485 "awkgram.y" /* yacc.c:1646 */
3501 (yyval) = list_create((yyvsp[0]));
3503 #line 3504 "awkgram.c" /* yacc.c:1646 */
3507 #line 1489 "awkgram.y" /* yacc.c:1646 */
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]));
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
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);
3529 n->numbr = (AWKNUM) (n->numbr == 0.0);
3530 bcfree((yyvsp[-1]));
3531 (yyval) = (yyvsp[0]);
3533 (yyvsp[-1])->opcode = Op_not;
3534 add_lint((yyvsp[0]), LINT_assign_in_cond);
3535 (yyval) = list_append((yyvsp[0]), (yyvsp[-1]));
3539 #line 3540 "awkgram.c" /* yacc.c:1646 */
3543 #line 1521 "awkgram.y" /* yacc.c:1646 */
3544 { (yyval) = (yyvsp[-1]); }
3545 #line 3546 "awkgram.c" /* yacc.c:1646 */
3549 #line 1523 "awkgram.y" /* yacc.c:1646 */
3551 (yyval) = snode((yyvsp[-1]), (yyvsp[-3]));
3552 if ((yyval) == NULL)
3555 #line 3556 "awkgram.c" /* yacc.c:1646 */
3559 #line 1529 "awkgram.y" /* yacc.c:1646 */
3561 (yyval) = snode((yyvsp[-1]), (yyvsp[-3]));
3562 if ((yyval) == NULL)
3565 #line 3566 "awkgram.c" /* yacc.c:1646 */
3569 #line 1535 "awkgram.y" /* yacc.c:1646 */
3571 static bool warned = false;
3573 if (do_lint && ! warned) {
3575 lintwarn_ln((yyvsp[0])->source_line,
3576 _("call of `length' without parentheses is not portable"));
3578 (yyval) = snode(NULL, (yyvsp[0]));
3579 if ((yyval) == NULL)
3582 #line 3583 "awkgram.c" /* yacc.c:1646 */
3586 #line 1550 "awkgram.y" /* yacc.c:1646 */
3588 (yyvsp[-1])->opcode = Op_preincrement;
3589 (yyval) = mk_assignment((yyvsp[0]), NULL, (yyvsp[-1]));
3591 #line 3592 "awkgram.c" /* yacc.c:1646 */
3595 #line 1555 "awkgram.y" /* yacc.c:1646 */
3597 (yyvsp[-1])->opcode = Op_predecrement;
3598 (yyval) = mk_assignment((yyvsp[0]), NULL, (yyvsp[-1]));
3600 #line 3601 "awkgram.c" /* yacc.c:1646 */
3604 #line 1560 "awkgram.y" /* yacc.c:1646 */
3606 (yyval) = list_create((yyvsp[0]));
3608 #line 3609 "awkgram.c" /* yacc.c:1646 */
3612 #line 1564 "awkgram.y" /* yacc.c:1646 */
3614 (yyval) = list_create((yyvsp[0]));
3616 #line 3617 "awkgram.c" /* yacc.c:1646 */
3620 #line 1568 "awkgram.y" /* yacc.c:1646 */
3622 if ((yyvsp[0])->lasti->opcode == Op_push_i
3623 && ((yyvsp[0])->lasti->memory->flags & (STRCUR|STRING)) == 0
3625 NODE *n = (yyvsp[0])->lasti->memory;
3626 (void) force_number(n);
3628 (yyval) = (yyvsp[0]);
3629 bcfree((yyvsp[-1]));
3631 (yyvsp[-1])->opcode = Op_unary_minus;
3632 (yyval) = list_append((yyvsp[0]), (yyvsp[-1]));
3635 #line 3636 "awkgram.c" /* yacc.c:1646 */
3639 #line 1583 "awkgram.y" /* yacc.c:1646 */
3643 * POSIX semantics: force a conversion to numeric type
3645 (yyvsp[-1])->opcode = Op_plus_i;
3646 (yyvsp[-1])->memory = make_number(0.0);
3647 (yyval) = list_append((yyvsp[0]), (yyvsp[-1]));
3649 #line 3650 "awkgram.c" /* yacc.c:1646 */
3653 #line 1596 "awkgram.y" /* yacc.c:1646 */
3655 func_use((yyvsp[0])->lasti->func_name, FUNC_USE);
3656 (yyval) = (yyvsp[0]);
3658 #line 3659 "awkgram.c" /* yacc.c:1646 */
3662 #line 1601 "awkgram.y" /* yacc.c:1646 */
3664 /* indirect function call */
3668 static bool warned = false;
3669 const char *msg = _("indirect function calls are a gawk extension");
3671 if (do_traditional || do_posix)
3673 else if (do_lint && ! warned) {
3675 lintwarn("%s", msg);
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;
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:
3693 (yyval) = list_prepend((yyvsp[0]), t);
3695 #line 3696 "awkgram.c" /* yacc.c:1646 */
3699 #line 1637 "awkgram.y" /* yacc.c:1646 */
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]));
3708 INSTRUCTION *t = (yyvsp[-1]);
3709 ((yyvsp[-3]) + 1)->expr_count = count_expressions(&t, true);
3710 (yyval) = list_append(t, (yyvsp[-3]));
3713 #line 3714 "awkgram.c" /* yacc.c:1646 */
3717 #line 1654 "awkgram.y" /* yacc.c:1646 */
3719 #line 3720 "awkgram.c" /* yacc.c:1646 */
3723 #line 1656 "awkgram.y" /* yacc.c:1646 */
3724 { (yyval) = (yyvsp[0]); }
3725 #line 3726 "awkgram.c" /* yacc.c:1646 */
3729 #line 1661 "awkgram.y" /* yacc.c:1646 */
3731 #line 3732 "awkgram.c" /* yacc.c:1646 */
3735 #line 1663 "awkgram.y" /* yacc.c:1646 */
3736 { (yyval) = (yyvsp[-1]); }
3737 #line 3738 "awkgram.c" /* yacc.c:1646 */
3741 #line 1668 "awkgram.y" /* yacc.c:1646 */
3742 { (yyval) = (yyvsp[0]); }
3743 #line 3744 "awkgram.c" /* yacc.c:1646 */
3747 #line 1670 "awkgram.y" /* yacc.c:1646 */
3749 (yyval) = list_merge((yyvsp[-1]), (yyvsp[0]));
3751 #line 3752 "awkgram.c" /* yacc.c:1646 */
3755 #line 1677 "awkgram.y" /* yacc.c:1646 */
3757 INSTRUCTION *ip = (yyvsp[0])->lasti;
3758 int count = ip->sub_count; /* # of SUBSEP-seperated expressions */
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;
3765 ip->opcode = Op_no_op;
3766 sub_counter++; /* count # of dimensions */
3767 (yyval) = (yyvsp[0]);
3769 #line 3770 "awkgram.c" /* yacc.c:1646 */
3773 #line 1694 "awkgram.y" /* yacc.c:1646 */
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;
3784 (yyvsp[0])->sub_count = count_expressions(&t, false);
3785 (yyval) = list_append(t, (yyvsp[0]));
3787 #line 3788 "awkgram.c" /* yacc.c:1646 */
3791 #line 1711 "awkgram.y" /* yacc.c:1646 */
3792 { (yyval) = (yyvsp[0]); }
3793 #line 3794 "awkgram.c" /* yacc.c:1646 */
3797 #line 1713 "awkgram.y" /* yacc.c:1646 */
3799 (yyval) = list_merge((yyvsp[-1]), (yyvsp[0]));
3801 #line 3802 "awkgram.c" /* yacc.c:1646 */
3805 #line 1720 "awkgram.y" /* yacc.c:1646 */
3806 { (yyval) = (yyvsp[-1]); }
3807 #line 3808 "awkgram.c" /* yacc.c:1646 */
3811 #line 1725 "awkgram.y" /* yacc.c:1646 */
3813 char *var_name = (yyvsp[0])->lextok;
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]));
3819 #line 3820 "awkgram.c" /* yacc.c:1646 */
3823 #line 1733 "awkgram.y" /* yacc.c:1646 */
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]));
3830 #line 3831 "awkgram.c" /* yacc.c:1646 */
3834 #line 1743 "awkgram.y" /* yacc.c:1646 */
3836 INSTRUCTION *ip = (yyvsp[0])->nexti;
3837 if (ip->opcode == Op_push
3838 && ip->memory->type == Node_var
3839 && ip->memory->var_update
3841 (yyval) = list_prepend((yyvsp[0]), instruction(Op_var_update));
3842 (yyval)->nexti->update_var = ip->memory->var_update;
3844 (yyval) = (yyvsp[0]);
3846 #line 3847 "awkgram.c" /* yacc.c:1646 */
3850 #line 1755 "awkgram.y" /* yacc.c:1646 */
3852 (yyval) = list_append((yyvsp[-1]), (yyvsp[-2]));
3853 if ((yyvsp[0]) != NULL)
3854 mk_assignment((yyvsp[-1]), NULL, (yyvsp[0]));
3856 #line 3857 "awkgram.c" /* yacc.c:1646 */
3860 #line 1764 "awkgram.y" /* yacc.c:1646 */
3862 (yyvsp[0])->opcode = Op_postincrement;
3864 #line 3865 "awkgram.c" /* yacc.c:1646 */
3868 #line 1768 "awkgram.y" /* yacc.c:1646 */
3870 (yyvsp[0])->opcode = Op_postdecrement;
3872 #line 3873 "awkgram.c" /* yacc.c:1646 */
3876 #line 1771 "awkgram.y" /* yacc.c:1646 */
3878 #line 3879 "awkgram.c" /* yacc.c:1646 */
3882 #line 1779 "awkgram.y" /* yacc.c:1646 */
3884 #line 3885 "awkgram.c" /* yacc.c:1646 */
3888 #line 1783 "awkgram.y" /* yacc.c:1646 */
3890 #line 3891 "awkgram.c" /* yacc.c:1646 */
3894 #line 1792 "awkgram.y" /* yacc.c:1646 */
3896 #line 3897 "awkgram.c" /* yacc.c:1646 */
3900 #line 1796 "awkgram.y" /* yacc.c:1646 */
3901 { (yyval) = (yyvsp[0]); yyerrok; }
3902 #line 3903 "awkgram.c" /* yacc.c:1646 */
3906 #line 1800 "awkgram.y" /* yacc.c:1646 */
3908 #line 3909 "awkgram.c" /* yacc.c:1646 */
3912 #line 3913 "awkgram.c" /* yacc.c:1646 */
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);
3930 YY_STACK_PRINT (yyss, yyssp);
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. */
3940 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
3941 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
3942 yystate = yytable[yystate];
3944 yystate = yydefgoto[yyn - YYNTOKENS];
3949 /*--------------------------------------.
3950 | yyerrlab -- here on detecting error. |
3951 `--------------------------------------*/
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);
3957 /* If not already recovering from an error, report this error. */
3961 #if ! YYERROR_VERBOSE
3962 yyerror (YY_("syntax error"));
3964 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
3967 char const *yymsgp = YY_("syntax error");
3968 int yysyntax_error_status;
3969 yysyntax_error_status = YYSYNTAX_ERROR;
3970 if (yysyntax_error_status == 0)
3972 else if (yysyntax_error_status == 1)
3974 if (yymsg != yymsgbuf)
3975 YYSTACK_FREE (yymsg);
3976 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
3980 yymsg_alloc = sizeof yymsgbuf;
3981 yysyntax_error_status = 2;
3985 yysyntax_error_status = YYSYNTAX_ERROR;
3990 if (yysyntax_error_status == 2)
3991 goto yyexhaustedlab;
3993 # undef YYSYNTAX_ERROR
3999 if (yyerrstatus == 3)
4001 /* If just tried and failed to reuse lookahead token after an
4002 error, discard it. */
4004 if (yychar <= YYEOF)
4006 /* Return failure if at end of input. */
4007 if (yychar == YYEOF)
4012 yydestruct ("Error: discarding",
4018 /* Else will try to reuse lookahead token after shifting the error
4023 /*---------------------------------------------------.
4024 | yyerrorlab -- error raised explicitly by YYERROR. |
4025 `---------------------------------------------------*/
4028 /* Pacify compilers like GCC when the user code never invokes
4029 YYERROR and the label yyerrorlab therefore never appears in user
4031 if (/*CONSTCOND*/ 0)
4034 /* Do not reclaim the symbols of the rule whose action triggered
4038 YY_STACK_PRINT (yyss, yyssp);
4043 /*-------------------------------------------------------------.
4044 | yyerrlab1 -- common code for both syntax error and YYERROR. |
4045 `-------------------------------------------------------------*/
4047 yyerrstatus = 3; /* Each real token shifted decrements this. */
4051 yyn = yypact[yystate];
4052 if (!yypact_value_is_default (yyn))
4055 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
4063 /* Pop the current state because it cannot handle the error token. */
4068 yydestruct ("Error: popping",
4069 yystos[yystate], yyvsp);
4072 YY_STACK_PRINT (yyss, yyssp);
4075 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
4077 YY_IGNORE_MAYBE_UNINITIALIZED_END
4080 /* Shift the error token. */
4081 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
4087 /*-------------------------------------.
4088 | yyacceptlab -- YYACCEPT comes here. |
4089 `-------------------------------------*/
4094 /*-----------------------------------.
4095 | yyabortlab -- YYABORT comes here. |
4096 `-----------------------------------*/
4101 #if !defined yyoverflow || YYERROR_VERBOSE
4102 /*-------------------------------------------------.
4103 | yyexhaustedlab -- memory exhaustion comes here. |
4104 `-------------------------------------------------*/
4106 yyerror (YY_("memory exhausted"));
4112 if (yychar != YYEMPTY)
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",
4120 /* Do not reclaim the symbols of the rule whose action triggered
4121 this YYABORT or YYACCEPT. */
4123 YY_STACK_PRINT (yyss, yyssp);
4124 while (yyssp != yyss)
4126 yydestruct ("Cleanup: popping",
4127 yystos[*yyssp], yyvsp);
4132 YYSTACK_FREE (yyss);
4135 if (yymsg != yymsgbuf)
4136 YYSTACK_FREE (yymsg);
4140 #line 1802 "awkgram.y" /* yacc.c:1906 */
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 */
4157 NODE *(*ptr)(int); /* function that implements this keyword */
4158 NODE *(*ptr2)(int); /* alternate arbitrary-precision function */
4161 #if 'a' == 0x81 /* it's EBCDIC */
4162 /* tokcompare --- lexicographically compare token names for sorting */
4165 tokcompare(const void *l, const void *r)
4167 struct token *lhs, *rhs;
4169 lhs = (struct token *) l;
4170 rhs = (struct token *) r;
4172 return strcmp(lhs->operator, rhs->operator);
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.
4183 #define MPF(F) do_mpfr_##F
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},
4194 {"adump", Op_builtin, LEX_BUILTIN, GAWKX|A(1)|A(2), do_adump, 0},
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)},
4217 {"extension", Op_builtin, LEX_BUILTIN, GAWKX|A(1)|A(2)|A(3), do_ext, 0},
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},
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)},
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 */
4282 #define nextc_is_1stbyte 1
4283 #endif /* MBS_SUPPORT */
4285 /* getfname --- return name of a builtin function (for pretty printing) */
4288 getfname(NODE *(*fptr)(int))
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;
4301 /* negate_num --- negate a number in NODE */
4310 if (! is_mpg_number(n)) {
4311 n->numbr = -n->numbr;
4316 if (is_mpg_integer(n)) {
4318 mpz_neg(n->mpg_i, n->mpg_i);
4323 * 0 --> -0 conversion. Requires turning the MPG integer
4324 * into an MPFR float.
4327 mpz_clear(n->mpg_i); /* release the integer storage */
4329 /* Convert and fall through. */
4330 tval = mpfr_set_d(n->mpg_numbr, 0.0, ROUND_MODE);
4331 IEEE_FMT(n->mpg_numbr, tval);
4336 /* mpfr float case */
4337 tval = mpfr_neg(n->mpg_numbr, n->mpg_numbr, ROUND_MODE);
4338 IEEE_FMT(n->mpg_numbr, tval);
4342 /* print_included_from --- print `Included from ..' file names and locations */
4345 print_included_from()
4350 /* suppress current file name, line # from `.. included from ..' msgs */
4351 saveline = sourceline;
4354 for (s = sourcefile; s != NULL && s->stype == SRC_INC; ) {
4356 if (s == NULL || s->fd <= INVALID_HANDLE)
4360 /* if last token is NEWLINE, line number is off by 1. */
4361 if (s->lasttok == NEWLINE)
4364 s->prev == sourcefile ? "In file included from"
4366 (s->stype == SRC_INC ||
4367 s->stype == SRC_FILE) ? s->src : "cmd. line",
4369 s->stype == SRC_INC ? ',' : ':'
4372 sourceline = saveline;
4375 /* warning_ln --- print a warning message with location */
4378 warning_ln(int line, const char *mesg, ...)
4383 saveline = sourceline;
4385 print_included_from();
4386 va_start(args, mesg);
4387 err(false, _("warning: "), mesg, args);
4389 sourceline = saveline;
4392 /* lintwarn_ln --- print a lint warning and location */
4395 lintwarn_ln(int line, const char *mesg, ...)
4400 saveline = sourceline;
4402 print_included_from();
4403 va_start(args, mesg);
4404 if (lintfunc == r_fatal)
4405 err(true, _("fatal: "), mesg, args);
4407 err(false, _("warning: "), mesg, args);
4409 sourceline = saveline;
4410 if (lintfunc == r_fatal)
4411 gawk_exit(EXIT_FATAL);
4414 /* error_ln --- print an error message and location */
4417 error_ln(int line, const char *m, ...)
4422 saveline = sourceline;
4424 print_included_from();
4427 err(false, "error: ", m, args);
4429 sourceline = saveline;
4432 /* yyerror --- print a syntax error message, show where */
4435 yyerror(const char *m, ...)
4438 const char *mesg = NULL;
4443 static char end_of_file_line[] = "(END OF FILE)";
4446 print_included_from();
4449 /* Find the current line in the input file */
4450 if (lexptr && lexeme) {
4451 if (thisline == NULL) {
4455 mesg = _("unexpected newline or end of string");
4457 for (; cp != lexptr_begin && *cp != '\n'; --cp)
4463 /* NL isn't guaranteed */
4465 while (bp < lexend && *bp && *bp != '\n')
4468 thisline = end_of_file_line;
4469 bp = thisline + strlen(thisline);
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.
4477 * 8/2003: We may not need this anymore.
4482 msg("%.*s", (int) (bp - thisline), thisline);
4489 count = (bp - thisline) + strlen(mesg) + 2 + 1;
4490 emalloc(buf, char *, count, "yyerror");
4494 if (lexptr != NULL) {
4496 while (scan < lexeme)
4497 if (*scan++ == '\t')
4505 err(false, "", buf, args);
4510 /* mk_program --- create a single list of instructions */
4512 static INSTRUCTION *
4515 INSTRUCTION *cp, *tmp;
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]
4523 if (end_block == NULL)
4524 end_block = list_create(ip_end);
4526 (void) list_prepend(end_block, ip_end);
4528 if (! in_main_context()) {
4529 if (begin_block != NULL && prog_block != NULL)
4530 cp = list_merge(begin_block, prog_block);
4532 cp = (begin_block != NULL) ? begin_block : prog_block;
4535 (void) list_merge(cp, end_block);
4539 (void) list_append(cp, instruction(Op_stop));
4543 if (endfile_block == NULL)
4544 endfile_block = list_create(ip_endfile);
4546 ip_rec->has_endfile = true;
4547 (void) list_prepend(endfile_block, ip_endfile);
4550 if (beginfile_block == NULL)
4551 beginfile_block = list_create(ip_beginfile);
4553 (void) list_prepend(beginfile_block, ip_beginfile);
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
4560 /* no pattern-action and (real) end, beginfile or endfile blocks */
4563 ip_rec = ip_newfile = NULL;
4565 list_append(beginfile_block, instruction(Op_after_beginfile));
4566 (void) list_append(endfile_block, instruction(Op_after_endfile));
4568 if (begin_block == NULL) /* no program at all */
4571 cp = list_merge(begin_block, end_block);
4572 (void) list_append(cp, ip_atexit);
4573 (void) list_append(cp, instruction(Op_stop));
4575 /* append beginfile_block and endfile_block for sole use
4576 * in getline without redirection (Op_K_getline).
4579 (void) list_merge(cp, beginfile_block);
4580 (void) list_merge(cp, endfile_block);
4585 /* install a do-nothing prog block */
4586 prog_block = list_create(instruction(Op_no_op));
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;
4595 list_append(beginfile_block, instruction(Op_after_beginfile));
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);
4604 (void) list_append(cp, ip_atexit);
4605 (void) list_append(cp, instruction(Op_stop));
4608 /* delete the Op_list, not needed */
4616 #undef beginfile_block
4617 #undef endfile_block
4620 /* parse_program --- read in the program and convert into a list of instructions */
4623 parse_program(INSTRUCTION **pcode)
4627 /* pre-create non-local jump targets
4628 * ip_end (Op_no_op) -- used as jump target for `exit'
4629 * outside an END block.
4631 ip_end = instruction(Op_no_op);
4633 if (! in_main_context())
4634 ip_newfile = ip_rec = ip_atexit = ip_beginfile = ip_endfile = NULL;
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 */
4647 for (sourcefile = srcfiles->next; sourcefile->stype == SRC_EXTLIB;
4648 sourcefile = sourcefile->next)
4654 memset(rule_block, 0, sizeof(ruletab) * sizeof(INSTRUCTION *));
4656 tok = tokstart != NULL ? tokstart : tokexpand();
4659 *pcode = mk_program();
4661 /* avoid false source indications */
4664 if (ret == 0) /* avoid spurious warning if parser aborted with YYABORT */
4667 if (args_array == NULL)
4668 emalloc(args_array, NODE **, (max_args + 2) * sizeof(NODE *), "parse_program");
4670 erealloc(args_array, NODE **, (max_args + 2) * sizeof(NODE *), "parse_program");
4672 return (ret || errcount);
4675 /* do_add_srcfile --- add one item to srcfiles */
4678 do_add_srcfile(enum srctype stype, char *src, char *path, SRCFILE *thisfile)
4682 emalloc(s, SRCFILE *, sizeof(SRCFILE), "do_add_srcfile");
4683 memset(s, 0, sizeof(SRCFILE));
4684 s->src = estrdup(src, strlen(src));
4687 s->fd = INVALID_HANDLE;
4689 s->prev = thisfile->prev;
4690 thisfile->prev->next = s;
4695 /* add_srcfile --- add one item to srcfiles after checking if
4696 * a source file exists and not already in list.
4700 add_srcfile(enum srctype stype, char *src, SRCFILE *thisfile, bool *already_included, int *errcode)
4707 if (already_included)
4708 *already_included = false;
4711 if (stype == SRC_CMDLINE || stype == SRC_STDIN)
4712 return do_add_srcfile(stype, src, NULL, thisfile);
4714 path = find_source(src, & sbuf, &errno_val, stype == SRC_EXTLIB);
4717 *errcode = errno_val;
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)"),
4725 errno_val ? strerror(errno_val) : _("reason unknown"));
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);
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
4743 if (sourceline > 1 && lasttok == NEWLINE)
4747 ? _("already included source file `%s'")
4748 : _("already loaded shared library `%s'"),
4752 if (already_included)
4753 *already_included = true;
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 */
4766 s = do_add_srcfile(stype, src, path, thisfile);
4768 s->mtime = sbuf.st_mtime;
4772 /* include_source --- read program from source included using `@include' */
4775 include_source(INSTRUCTION *file)
4778 char *src = file->lextok;
4780 bool already_included;
4782 if (do_traditional || do_posix) {
4783 error_ln(file->source_line, _("@include is a gawk extension"));
4787 if (strlen(src) == 0) {
4789 lintwarn_ln(file->source_line, _("empty filename after @include"));
4793 s = add_srcfile(SRC_INC, src, sourcefile, &already_included, &errcode);
4795 if (already_included)
4797 error_ln(file->source_line,
4798 _("can't open source file `%s' for reading (%s)"),
4799 src, errcode ? strerror(errcode) : _("reason unknown"));
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;
4811 /* included file becomes the current source */
4822 /* load_library --- load a shared library */
4825 load_library(INSTRUCTION *file)
4828 char *src = file->lextok;
4830 bool already_included;
4832 if (do_traditional || do_posix) {
4833 error_ln(file->source_line, _("@load is a gawk extension"));
4837 if (strlen(src) == 0) {
4839 lintwarn_ln(file->source_line, _("empty filename after @load"));
4843 s = add_srcfile(SRC_EXTLIB, src, sourcefile, &already_included, &errcode);
4845 if (already_included)
4847 error_ln(file->source_line,
4848 _("can't open shared library `%s' for reading (%s)"),
4849 src, errcode ? strerror(errcode) : _("reason unknown"));
4853 load_ext(s->fullpath);
4857 /* next_sourcefile --- read program from the next source in srcfiles */
4862 static int (*closefunc)(int fd) = NULL;
4864 if (closefunc == NULL) {
4865 char *cp = getenv("AWKREADFUNC");
4867 /* If necessary, one day, test value for different functions. */
4871 closefunc = one_line_close;
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
4880 * assert(lexeof == true);
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;
4891 if (sourcefile->buf != NULL) {
4892 efree(sourcefile->buf);
4893 sourcefile->buf = NULL;
4894 sourcefile->lexptr_begin = NULL;
4897 while ((sourcefile = sourcefile->next) != NULL) {
4898 if (sourcefile == srcfiles)
4900 if (sourcefile->stype != SRC_EXTLIB)
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;
4921 /* get_src_buf --- read the next buffer of source program */
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.
4937 static ssize_t (*readfunc)() = 0;
4939 if (readfunc == NULL) {
4940 char *cp = getenv("AWKREADFUNC");
4942 /* If necessary, one day, test value for different functions. */
4945 * cast is to remove warnings on systems with
4946 * different return types for read.
4948 readfunc = ( ssize_t(*)() ) read;
4950 readfunc = read_one_line;
4954 if (sourcefile == srcfiles)
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;
4963 if (sourcefile->bufsize == 0) {
4965 * Yet Another Special case:
4966 * gawk '' /path/name
4969 static bool warned = false;
4971 if (do_lint && ! warned) {
4973 lintwarn(_("empty program text on command line"));
4977 } else if (sourcefile->buf == NULL && *(lexptr-1) != '\n') {
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.
4986 offset = lexptr - lexeme;
4987 for (scan = lexeme; scan > lexptr_begin; scan--)
4988 if (*scan == '\n') {
4992 savelen = lexptr - scan;
4993 emalloc(buf, char *, savelen + 1, "get_src_buf");
4994 memcpy(buf, scan, savelen);
4996 lexptr = buf + savelen;
4998 lexeme = lexptr - offset;
5000 lexend = lexptr + 1;
5001 sourcefile->buf = buf;
5007 if (sourcefile->fd <= INVALID_HANDLE) {
5011 source = sourcefile->src;
5014 fd = srcopen(sourcefile);
5015 if (fd <= INVALID_HANDLE) {
5018 /* suppress file name and line no. in error mesg */
5021 error(_("can't open source file `%s' for reading (%s)"),
5022 in, strerror(errno));
5025 return sourcefile->src;
5028 sourcefile->fd = fd;
5029 l = optimal_bufsize(fd, &sbuf);
5031 * Make sure that something silly like
5032 * AWKBUFSIZE=8 make check
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;
5041 emalloc(sourcefile->buf, char *, sourcefile->bufsize, "get_src_buf");
5042 lexptr = lexptr_begin = lexeme = sourcefile->buf;
5048 * Here, we retain the current source line in the beginning of the buffer.
5051 for (scan = lexeme; scan > lexptr_begin; scan--)
5052 if (*scan == '\n') {
5057 savelen = lexptr - scan;
5058 offset = lexptr - lexeme;
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.
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;
5075 thisline = lexptr_begin;
5076 memmove(thisline, scan, savelen);
5077 lexptr = thisline + savelen;
5078 lexeme = lexptr - offset;
5081 lexptr = lexeme = lexptr_begin;
5086 n = (*readfunc)(sourcefile->fd, lexptr, sourcefile->bufsize - savelen);
5088 error(_("can't read sourcefile `%s' (%s)"),
5089 source, strerror(errno));
5093 lexend = lexptr + n;
5095 static bool warned = false;
5096 if (do_lint && newfile && ! warned){
5099 lintwarn(_("source file `%s' is empty"), source);
5104 return sourcefile->buf;
5107 /* tokadd --- add a character to the token buffer */
5109 #define tokadd(x) (*tok++ = (x), tok == tokend ? tokexpand() : tok)
5111 /* tokexpand --- grow the token buffer */
5119 if (tokstart != NULL) {
5120 tokoffset = tok - tokstart;
5122 erealloc(tokstart, char *, toksize, "tokexpand");
5123 tok = tokstart + tokoffset;
5126 emalloc(tokstart, char *, toksize, "tokexpand");
5129 tokend = tokstart + toksize;
5133 /* nextc --- get the next input character */
5140 if (gawk_mb_cur_max > 1) {
5144 if (lexptr == NULL || lexptr >= lexend) {
5150 /* Update the buffer index. */
5151 cur_ring_idx = (cur_ring_idx == RING_BUFFER_SIZE - 1)? 0 :
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;
5161 for (idx = 0 ; lexptr + idx < lexend ; idx++) {
5162 tmp_state = cur_mbstate;
5163 mbclen = mbrlen(lexptr, idx + 1, &tmp_state);
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
5169 cur_char_ring[work_ring_idx] = 1;
5171 } else if (mbclen == (size_t)-2) {
5172 /* It is not a complete multibyte character. */
5173 cur_char_ring[work_ring_idx] = idx + 1;
5176 cur_char_ring[work_ring_idx] = mbclen;
5179 work_ring_idx = (work_ring_idx == RING_BUFFER_SIZE - 1)?
5180 0 : work_ring_idx + 1;
5182 cur_mbstate = tmp_state;
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;
5190 return (int) (unsigned char) *lexptr++;
5195 if (lexptr && lexptr < lexend)
5196 return ((int) (unsigned char) *lexptr++);
5197 } while (get_src_buf());
5202 #else /* MBS_SUPPORT */
5210 if (lexptr && lexptr < lexend)
5211 return ((int) (unsigned char) *lexptr++);
5212 } while (get_src_buf());
5216 #endif /* MBS_SUPPORT */
5218 /* pushback --- push a character back on the input */
5224 if (gawk_mb_cur_max > 1)
5225 cur_ring_idx = (cur_ring_idx == 0)? RING_BUFFER_SIZE - 1 :
5228 (! lexeof && lexptr && lexptr > lexptr_begin ? lexptr-- : lexptr);
5232 /* allow_newline --- allow newline after &&, ||, ? and : */
5241 if (c == END_FILE) {
5246 while ((c = nextc()) != '\n' && c != END_FILE)
5248 if (c == END_FILE) {
5262 /* newline_eof --- return newline or EOF as needed and adjust variables */
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.
5270 static int newline_eof()
5272 /* NB: a newline at end does not start a source line. */
5273 if (lasttok != NEWLINE) {
5275 if (do_lint && ! eof_warned) {
5276 lintwarn(_("source file does not end in newline"));
5288 /* yylex --- Read the input and turn it into tokens. */
5294 bool seen_e = false; /* These are for numbers */
5295 bool seen_point = false;
5296 bool esc_seen; /* for literal strings */
5299 static bool did_newline = false;
5302 bool intlstr = false;
5305 #define GET_INSTRUCTION(op) bcalloc(op, 1, sourceline)
5307 #define NEWLINE_EOF newline_eof()
5309 yylval = (INSTRUCTION *) NULL;
5310 if (lasttok == SUBSCRIPT) {
5315 if (lasttok == LEX_EOF) /* error earlier in current source, must give up !! */
5322 return lasttok = NEWLINE_EOF;
5327 * added for OS/2's extproc feature of cmd.exe
5328 * (like #! in BSD sh)
5330 if (strncasecmp(lexptr, "extproc ", 8) == 0) {
5331 while (*lexptr && *lexptr != '\n')
5339 int in_brack = 0; /* count brackets, [[:alnum:]] allowed */
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.
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.
5354 * The code for \ handles \[ and \].
5357 want_regexp = false;
5362 if (gawk_mb_cur_max == 1 || nextc_is_1stbyte) switch (c) {
5364 /* one day check for `.' and `=' too */
5365 if (nextc() == ':' || in_brack == 0)
5370 if (tokstart[0] == '['
5371 && (tok == tokstart + 1
5372 || (tok == tokstart + 2
5373 && tokstart[1] == '^')))
5379 if ((c = nextc()) == END_FILE) {
5381 yyerror(_("unterminated regexp ends with `\\' at end of file"));
5382 goto end_regexp; /* kludge */
5383 } else if (c == '\n') {
5392 case '/': /* end of the regexp */
5396 yylval = GET_INSTRUCTION(Op_token);
5397 yylval->lextok = estrdup(tokstart, tok - tokstart);
5402 if (peek == 'i' || peek == 's') {
5405 _("%s: %d: tawk regex modifier `/.../%c' doesn't work in gawk"),
5406 source, sourceline, peek);
5409 _("tawk regex modifier `/.../%c' doesn't work in gawk"),
5413 return lasttok = REGEXP;
5416 yyerror(_("unterminated regexp"));
5417 goto end_regexp; /* kludge */
5420 yyerror(_("unterminated regexp at end of file"));
5421 goto end_regexp; /* kludge */
5428 /* skipping \r is a hack, but windows is just too pervasive. sigh. */
5429 while ((c = nextc()) == ' ' || c == '\t' || c == '\r')
5432 lexeme = lexptr ? lexptr - 1 : lexptr;
5437 if (gawk_mb_cur_max == 1 || nextc_is_1stbyte)
5444 return lasttok = NEWLINE_EOF;
5448 return lasttok = NEWLINE;
5450 case '#': /* it's a comment */
5451 while ((c = nextc()) != '\n') {
5453 return lasttok = NEWLINE_EOF;
5456 return lasttok = NEWLINE;
5459 return lasttok = '@';
5462 #ifdef RELAXED_CONTINUATION
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.
5469 if (! do_traditional) {
5470 /* strip trailing white-space and/or comment */
5471 while ((c = nextc()) == ' ' || c == '\t' || c == '\r')
5474 static bool warned = false;
5476 if (do_lint && ! warned) {
5479 _("use of `\\ #...' line continuation is not portable"));
5481 while ((c = nextc()) != '\n')
5487 #endif /* RELAXED_CONTINUATION */
5489 if (c == '\r') /* allow MS-DOS files. bleah */
5495 yyerror(_("backslash not last character on line"));
5496 return lasttok = LEX_EOF;
5502 yylval = GET_INSTRUCTION(Op_cond_exp);
5508 * in_parens is undefined unless we are parsing a print
5509 * statement (in_print), but why bother with a check?
5519 yylval = GET_INSTRUCTION(Op_field_spec);
5522 if (++in_braces == 1)
5523 firstline = sourceline;
5532 yylval = GET_INSTRUCTION(Op_sub_array);
5535 yylval = GET_INSTRUCTION(Op_subscript);
5536 lasttok = SUBSCRIPT; /* end of subscripts */
5541 if ((c = nextc()) == '=') {
5542 yylval = GET_INSTRUCTION(Op_assign_times);
5543 return lasttok = ASSIGNOP;
5544 } else if (do_posix) {
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;
5552 if (nextc() == '=') {
5553 if (! did_warn_assgn) {
5554 did_warn_assgn = true;
5556 lintwarn(_("POSIX does not allow operator `**='"));
5558 warning(_("old awk does not support operator `**='"));
5560 yylval = GET_INSTRUCTION(Op_assign_exp);
5564 if (! did_warn_op) {
5567 lintwarn(_("POSIX does not allow operator `**'"));
5569 warning(_("old awk does not support operator `**'"));
5571 yylval = GET_INSTRUCTION(Op_exp);
5572 return lasttok = '^';
5576 yylval = GET_INSTRUCTION(Op_times);
5577 return lasttok = '*';
5580 if (nextc() == '=') {
5582 return lasttok = SLASH_BEFORE_EQUAL;
5585 yylval = GET_INSTRUCTION(Op_quotient);
5586 return lasttok = '/';
5589 if (nextc() == '=') {
5590 yylval = GET_INSTRUCTION(Op_assign_mod);
5591 return lasttok = ASSIGNOP;
5594 yylval = GET_INSTRUCTION(Op_mod);
5595 return lasttok = '%';
5599 static bool did_warn_op = false, did_warn_assgn = false;
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"));
5606 yylval = GET_INSTRUCTION(Op_assign_exp);
5607 return lasttok = ASSIGNOP;
5610 if (do_lint_old && ! did_warn_op) {
5612 warning(_("operator `^' is not supported in old awk"));
5614 yylval = GET_INSTRUCTION(Op_exp);
5615 return lasttok = '^';
5619 if ((c = nextc()) == '=') {
5620 yylval = GET_INSTRUCTION(Op_assign_plus);
5621 return lasttok = ASSIGNOP;
5624 yylval = GET_INSTRUCTION(Op_symbol);
5625 return lasttok = INCREMENT;
5628 yylval = GET_INSTRUCTION(Op_plus);
5629 return lasttok = '+';
5632 if ((c = nextc()) == '=') {
5633 yylval = GET_INSTRUCTION(Op_notequal);
5634 return lasttok = RELOP;
5637 yylval = GET_INSTRUCTION(Op_nomatch);
5638 return lasttok = MATCHOP;
5641 yylval = GET_INSTRUCTION(Op_symbol);
5642 return lasttok = '!';
5645 if (nextc() == '=') {
5646 yylval = GET_INSTRUCTION(Op_leq);
5647 return lasttok = RELOP;
5649 yylval = GET_INSTRUCTION(Op_less);
5651 return lasttok = '<';
5654 if (nextc() == '=') {
5655 yylval = GET_INSTRUCTION(Op_equal);
5656 return lasttok = RELOP;
5658 yylval = GET_INSTRUCTION(Op_assign);
5660 return lasttok = ASSIGN;
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;
5672 if (in_print && in_parens == 0) {
5673 yylval = GET_INSTRUCTION(Op_symbol);
5674 yylval->redir_type = redirect_output;
5675 return lasttok = IO_OUT;
5677 yylval = GET_INSTRUCTION(Op_greater);
5678 return lasttok = '>';
5681 yylval = GET_INSTRUCTION(Op_match);
5682 return lasttok = MATCHOP;
5686 * Added did newline stuff. Easier than
5687 * hacking the grammar.
5690 did_newline = false;
5691 if (--in_braces == 0)
5692 lastline = sourceline;
5696 --lexptr; /* pick up } next time */
5697 return lasttok = NEWLINE;
5702 while ((c = nextc()) != '"') {
5705 yyerror(_("unterminated string"));
5706 return lasttok = LEX_EOF;
5708 if ((gawk_mb_cur_max == 1 || nextc_is_1stbyte) &&
5716 if (! want_source || c != '"')
5719 if (c == END_FILE) {
5721 yyerror(_("unterminated string"));
5722 return lasttok = LEX_EOF;
5726 yylval = GET_INSTRUCTION(Op_token);
5728 yylval->lextok = estrdup(tokstart, tok - tokstart);
5729 return lasttok = FILENAME;
5732 yylval->opcode = Op_push_i;
5733 yylval->memory = make_str_node(tokstart,
5734 tok - tokstart, esc_seen ? SCAN : 0);
5736 yylval->memory->flags |= INTLSTR;
5739 dumpintlstr(yylval->memory->stptr, yylval->memory->stlen);
5741 return lasttok = YSTRING;
5744 if ((c = nextc()) == '=') {
5745 yylval = GET_INSTRUCTION(Op_assign_minus);
5746 return lasttok = ASSIGNOP;
5749 yylval = GET_INSTRUCTION(Op_symbol);
5750 return lasttok = DECREMENT;
5753 yylval = GET_INSTRUCTION(Op_minus);
5754 return lasttok = '-';
5760 return lasttok = '.';
5776 bool gotnumber = false;
5784 if (tok == tokstart + 2) {
5787 if (isxdigit(peek)) {
5789 pushback(); /* following digit */
5791 pushback(); /* x or X */
5797 /* period ends exponent part of floating point number */
5798 if (seen_point || seen_e) {
5813 if ((c = nextc()) == '-' || c == '+') {
5820 pushback(); /* non-digit after + or - */
5821 pushback(); /* + or - */
5822 pushback(); /* e or E */
5824 } else if (! isdigit(c)) {
5825 pushback(); /* character after e or E */
5826 pushback(); /* e or E */
5828 pushback(); /* digit */
5841 if (do_traditional || ! inhex)
5866 yylval = GET_INSTRUCTION(Op_push_i);
5869 if (! do_traditional) {
5870 base = get_numbase(tokstart, false);
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);
5885 if (! seen_point && ! seen_e) {
5887 mpg_strtoui(r->mpg_i, tokstart, strlen(tokstart), NULL, base);
5892 tval = mpfr_strtofr(r->mpg_numbr, tokstart, NULL, base, ROUND_MODE);
5894 IEEE_FMT(r->mpg_numbr, tval);
5897 return lasttok = YNUMBER;
5901 d = nondec2awknum(tokstart, strlen(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;
5910 if ((c = nextc()) == '&') {
5911 yylval = GET_INSTRUCTION(Op_and);
5913 return lasttok = LEX_AND;
5916 yylval = GET_INSTRUCTION(Op_symbol);
5917 return lasttok = '&';
5920 if ((c = nextc()) == '|') {
5921 yylval = GET_INSTRUCTION(Op_or);
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);
5930 if (in_print && in_parens == 0) {
5931 yylval = GET_INSTRUCTION(Op_symbol);
5932 yylval->redir_type = redirect_pipe;
5933 return lasttok = IO_OUT;
5935 yylval = GET_INSTRUCTION(Op_symbol);
5936 yylval->redir_type = redirect_pipein;
5937 return lasttok = IO_IN;
5941 if (c != '_' && ! isalpha(c)) {
5942 yyerror(_("invalid char '%c' in expression"), c);
5943 return lasttok = LEX_EOF;
5947 * Lots of fog here. Consider:
5949 * print "xyzzy"$_"foo"
5951 * Without the check for ` lasttok != '$' ', this is parsed as
5953 * print "xxyzz" $(_"foo")
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.
5960 if (! do_traditional && c == '_' && lasttok != '$') {
5961 if ((c = nextc()) == '"') {
5969 /* it's some type of name-type-thing. Find its length. */
5971 while (c != END_FILE && is_identchar(c)) {
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;
5983 if ((class == LEX_INCLUDE || class == LEX_LOAD || class == LEX_EVAL)
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;
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;
5999 if (do_lint_old && (tokentab[mid].flags & NOT_OLD) != 0
6000 && (warntab[mid] & NOT_OLD) == 0
6002 warning(_("`%s' is not supported in old awk"),
6003 tokentab[mid].operator);
6004 warntab[mid] |= NOT_OLD;
6007 if ((tokentab[mid].flags & BREAK) != 0)
6009 if ((tokentab[mid].flags & CONTINUE) != 0)
6018 if (in_main_context())
6020 emalloc(tokkey, char *, tok - tokstart + 1, "yylex");
6022 memcpy(tokkey + 1, tokstart, tok - tokstart);
6023 yylval = GET_INSTRUCTION(Op_token);
6024 yylval->lextok = tokkey;
6032 yylval = bcalloc(tokentab[mid].value, 3, sourceline);
6039 if (! do_pretty_print)
6040 return lasttok = class;
6043 yylval = bcalloc(tokentab[mid].value, 2, sourceline);
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.
6052 if (! continue_allowed) {
6053 error_ln(sourceline,
6054 _("`continue' is not allowed outside a loop"));
6057 goto make_instruction;
6060 if (! break_allowed) {
6061 error_ln(sourceline,
6062 _("`break' is not allowed outside a loop or switch"));
6065 goto make_instruction;
6069 yylval = GET_INSTRUCTION(tokentab[mid].value);
6070 if (class == LEX_BUILTIN || class == LEX_LENGTH)
6071 yylval->builtin_idx = mid;
6074 return lasttok = class;
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;
6083 static bool goto_warned = false;
6085 yylval = GET_INSTRUCTION(Op_token);
6086 yylval->lextok = tokkey;
6088 #define SMART_ALECK 1
6089 if (SMART_ALECK && do_lint
6090 && ! goto_warned && strcasecmp(tokkey, "goto") == 0) {
6092 lintwarn(_("`goto' considered harmful!\n"));
6094 return lasttok = NAME;
6097 #undef GET_INSTRUCTION
6101 /* snode --- instructions for builtin functions. Checks for arg. count
6102 and supplies defaults where possible. */
6104 static INSTRUCTION *
6105 snode(INSTRUCTION *subn, INSTRUCTION *r)
6112 int idx = r->builtin_idx;
6116 for (tp = subn->nexti; tp; tp = tp->nexti) {
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);
6131 /* special processing for sub, gsub and gensub */
6133 if (tokentab[idx].value == Op_sub_builtin) {
6134 const char *operator = tokentab[idx].operator;
6138 arg = subn->nexti; /* first arg list */
6139 (void) mk_rexp(arg);
6141 if (strcmp(operator, "gensub") != 0) {
6144 if (strcmp(operator, "gsub") == 0)
6145 r->sub_flags |= GSUB;
6147 arg = arg->lasti->nexti; /* 2nd arg list */
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)));
6157 arg = arg->lasti->nexti; /* third arg list */
6159 if (ip->opcode == Op_push_i) {
6161 lintwarn(_("%s: string literal as last arg of substitute has no effect"),
6163 r->sub_flags |= LITERAL;
6165 if (make_assignable(ip) == NULL)
6166 yyerror(_("%s third parameter is not a changeable object"),
6169 ip->do_reference = true;
6172 r->expr_count = count_expressions(&subn, false);
6175 (void) list_append(subn, r);
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;
6197 r->sub_flags |= GENSUB;
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)));
6205 r->expr_count = count_expressions(&subn, false);
6206 return list_append(subn, r);
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;
6216 r->builtin = tokentab[idx].ptr;
6218 /* special case processing for a few builtins */
6220 if (r->builtin == do_length) {
6222 /* no args. Use $0 */
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);
6233 if (arg->nexti == arg->lasti && arg->nexti->opcode == Op_push)
6234 arg->nexti->opcode = Op_push_arg; /* argument may be array */
6236 } else if (r->builtin == do_isarray) {
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;
6243 arg = subn->nexti->lasti->nexti; /* 2nd arg list */
6244 (void) mk_rexp(arg);
6246 if (nexp == 3) { /* 3rd argument there */
6247 if (do_lint && ! warned) {
6249 lintwarn(_("match: third argument is a gawk extension"));
6251 if (do_traditional) {
6252 yyerror(_("match: third argument is a gawk extension"));
6256 arg = arg->lasti->nexti; /* third arg list */
6258 if (/*ip == arg->nexti && */ ip->opcode == Op_push)
6259 ip->opcode = Op_push_array;
6261 } else if (r->builtin == do_split) {
6262 arg = subn->nexti->lasti->nexti; /* 2nd arg list */
6264 if (ip->opcode == Op_push)
6265 ip->opcode = Op_push_array;
6268 expr = list_create(instruction(Op_push));
6269 expr->nexti->memory = FS_node;
6270 (void) mk_expression_list(subn, expr);
6272 arg = arg->lasti->nexti;
6275 n->re_flags |= FS_DFLT;
6277 arg = arg->lasti->nexti;
6279 if (ip->opcode == Op_push)
6280 ip->opcode = Op_push_array;
6282 } else if (r->builtin == do_patsplit) {
6283 arg = subn->nexti->lasti->nexti; /* 2nd arg list */
6285 if (ip->opcode == Op_push)
6286 ip->opcode = Op_push_array;
6289 expr = list_create(instruction(Op_push));
6290 expr->nexti->memory = FPAT_node;
6291 (void) mk_expression_list(subn, expr);
6293 arg = arg->lasti->nexti;
6296 arg = arg->lasti->nexti;
6298 if (ip->opcode == Op_push)
6299 ip->opcode = Op_push_array;
6301 } else if (r->builtin == do_close) {
6302 static bool warned = false;
6304 if (do_lint && ! warned) {
6306 lintwarn(_("close: second argument is a gawk extension"));
6308 if (do_traditional) {
6309 yyerror(_("close: second argument is a gawk extension"));
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;
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 */
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;
6335 if (((str1->flags | str2->flags) & INTLSTR) != 0)
6336 warning(_("use of dcngettext(_\"...\") is incorrect: remove leading underscore"));
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 */
6342 if (ip->opcode == Op_push)
6343 ip->opcode = Op_push_array;
6347 if (ip->opcode == Op_push)
6348 ip->opcode = Op_push_array;
6351 else if (r->builtin == do_index) {
6352 arg = subn->nexti->lasti->nexti; /* 2nd arg list */
6354 if (ip->opcode == Op_match_rec)
6355 fatal(_("index: regexp constant as second argument is not allowed"));
6358 else if (r->builtin == do_adump) {
6359 ip = subn->nexti->lasti;
6360 if (ip->opcode == Op_push)
6361 ip->opcode = Op_push_array;
6366 r->expr_count = count_expressions(&subn, false);
6367 return list_append(subn, r);
6371 return list_create(r);
6375 /* parms_shadow --- check if parameters shadow globals */
6378 parms_shadow(INSTRUCTION *pc, bool *shadow)
6385 func = pc->func_body;
6386 fname = func->vname;
6389 #if 0 /* can't happen, already exited if error ? */
6390 if (fname == NULL || func == NULL) /* error earlier */
6394 pcount = func->param_cnt;
6396 if (pcount == 0) /* no args, no problem */
6399 source = pc->source_file;
6400 sourceline = pc->source_line;
6402 * Use warning() and not lintwarn() so that can warn
6403 * about all shadowed parameters.
6405 for (i = 0; i < pcount; i++) {
6406 if (lookup(fp[i].param) != NULL) {
6408 _("function `%s': parameter `%s' shadows global variable"),
6409 fname, fp[i].param);
6418 /* valinfo --- dump var info */
6421 valinfo(NODE *n, Func_print print_func, FILE *fp)
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) {
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));
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) {
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));
6448 print_func(fp, "%.17g\n", n->numbr);
6450 print_func(fp, "?? flags %s\n", flags2str(n->flags));
6454 /* dump_vars --- dump the symbol table */
6457 dump_vars(const char *fname)
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"));
6470 vars = variable_list();
6471 print_vars(vars, fprintf, fp);
6473 if (fp != stderr && fclose(fp) != 0)
6474 warning(_("%s: close failed (%s)"), fname, strerror(errno));
6477 /* dump_funcs --- print all functions */
6483 funcs = function_list(true);
6484 (void) foreach_func(funcs, (int (*)(INSTRUCTION *, void *)) pp_func, (void *) 0);
6489 /* shadow_funcs --- check all functions for parameters that shadow globals */
6494 static int calls = 0;
6495 bool shadow = false;
6499 fatal(_("shadow_funcs() called twice!"));
6501 funcs = function_list(true);
6502 (void) foreach_func(funcs, (int (*)(INSTRUCTION *, void *)) parms_shadow, & shadow);
6505 /* End with fatal if the user requested it. */
6506 if (shadow && lintfunc != warning)
6507 lintwarn(_("there were shadowed variables."));
6511 /* mk_function --- finalize function definition node; remove parameters
6512 * out of the symbol table.
6515 static INSTRUCTION *
6516 mk_function(INSTRUCTION *fi, INSTRUCTION *def)
6520 thisfunc = fi->func_body;
6521 assert(thisfunc != NULL);
6523 if (do_optimize && def->lasti->opcode == Op_pop) {
6524 /* tail call which does not return any value. */
6528 for (t = def->nexti; t->nexti != def->lasti; t = t->nexti)
6530 if (t->opcode == Op_func_call
6531 && strcmp(t->func_name, thisfunc->vname) == 0)
6532 (t + 1)->tail_call = true;
6535 /* add an implicit return at end;
6536 * also used by 'return' command in debugger
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));
6543 if (do_pretty_print)
6544 (void) list_prepend(def, instruction(Op_exec_count));
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;
6554 (void) list_append(rule_list, fi + 1); /* debugging */
6556 /* update lint table info */
6557 func_use(thisfunc->vname, FUNC_DEFINE);
6559 /* remove params from symbol table */
6560 remove_params(thisfunc);
6566 * install function name in the symbol table.
6567 * Extra work, build up and install a list of the parameter names.
6571 install_function(char *fname, INSTRUCTION *fi, INSTRUCTION *plist)
6577 if (r != NULL || is_deferred_variable(fname)) {
6578 error_ln(fi->source_line, _("function name `%s' previously defined"), fname);
6583 pcount = plist->lasti->param_count + 1;
6584 f = install_symbol(fname, Node_func);
6586 f->param_cnt = pcount;
6591 pnames = check_params(fname, pcount, plist); /* frees plist */
6592 f->fparms = make_params(pnames, pcount);
6600 /* check_params --- build a list of function parameter names after
6601 * making sure that the names are valid and there are no duplicates.
6605 check_params(char *fname, int pcount, INSTRUCTION *list)
6607 INSTRUCTION *p, *np;
6614 emalloc(pnames, char **, pcount * sizeof(char *), "check_params");
6616 for (i = 0, p = list->nexti; p != NULL; i++, p = np) {
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"),
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);
6652 #define HASHSIZE 1021
6654 static struct fdesc {
6660 } *ftable[HASHSIZE];
6662 /* func_use --- track uses and definitions of functions */
6665 func_use(const char *name, enum defref how)
6672 ind = hash(name, len, HASHSIZE, NULL);
6674 for (fp = ftable[ind]; fp != NULL; fp = fp->next)
6675 if (strcmp(fp->name, name) == 0)
6678 /* not in the table, fall through to allocate a new one */
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];
6688 if (how == FUNC_DEFINE)
6690 else if (how == FUNC_EXT) {
6697 /* track_ext_func --- add an extension function to the table */
6700 track_ext_func(const char *name)
6702 func_use(name, FUNC_EXT);
6705 /* check_funcs --- verify functions that are called but not defined */
6710 struct fdesc *fp, *next;
6713 if (! in_main_context())
6716 for (i = 0; i < HASHSIZE; i++) {
6717 for (fp = ftable[i]; fp != NULL; fp = fp->next) {
6719 /* making this the default breaks old code. sigh. */
6720 if (fp->defined == 0 && ! fp->extension) {
6722 _("function `%s' called but never defined"), fp->name);
6726 if (do_lint && fp->defined == 0 && ! fp->extension)
6728 _("function `%s' called but never defined"), fp->name);
6731 if (do_lint && fp->used == 0 && ! fp->extension) {
6732 lintwarn(_("function `%s' defined but never called directly"),
6739 /* now let's free all the memory */
6740 for (i = 0; i < HASHSIZE; i++) {
6741 for (fp = ftable[i]; fp != NULL; fp = next) {
6750 /* param_sanity --- look for parameters that are regexp constants */
6753 param_sanity(INSTRUCTION *arglist)
6755 INSTRUCTION *argl, *arg;
6758 if (arglist == NULL)
6760 for (argl = arglist->nexti; argl; ) {
6762 if (arg->opcode == Op_match_rec)
6763 warning_ln(arg->source_line,
6764 _("regexp constant for parameter #%d yields boolean value"), i);
6770 /* deferred variables --- those that are only defined if needed. */
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.
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;
6785 /* register_deferred_variable --- add a var name and loading function to the list */
6788 register_deferred_variable(const char *name, NODE *(*load_func)(void))
6790 struct deferred_variable *dv;
6791 size_t sl = strlen(name);
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;
6801 /* is_deferred_variable --- check if NAME is a deferred variable */
6804 is_deferred_variable(const char *name)
6806 struct deferred_variable *dv;
6807 for (dv = deferred_variables; dv != NULL; dv = dv->next)
6808 if (strcmp(name, dv->name) == 0)
6814 /* variable --- make sure NAME is in the symbol table */
6817 variable(int location, char *name, NODETYPE type)
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"),
6825 if (r == symbol_table)
6829 struct deferred_variable *dv;
6831 for (dv = deferred_variables; true; dv = dv->next) {
6834 * This is the only case in which we may not free the string.
6836 return install_symbol(name, type);
6838 if (strcmp(name, dv->name) == 0) {
6839 r = (*dv->load_func)();
6848 /* process_deferred --- if the program uses SYMTAB, load deferred variables */
6853 struct deferred_variable *dv;
6858 for (dv = deferred_variables; dv != NULL; dv = dv->next) {
6859 (void) dv->load_func();
6863 /* make_regnode --- make a regular expression node */
6866 make_regnode(int type, NODE *exp)
6871 memset(n, 0, sizeof(NODE));
6875 if (type == Node_regex) {
6876 n->re_reg = make_regexp(exp->stptr, exp->stlen, false, true, false);
6877 if (n->re_reg == NULL) {
6882 n->re_flags = CONSTANT;
6888 /* mk_rexp --- make a regular expression constant */
6891 mk_rexp(INSTRUCTION *list)
6896 if (ip == list->lasti && ip->opcode == Op_match_rec)
6897 ip->opcode = Op_push_re;
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;
6909 /* isnoeffect --- when used as a statement, has no side effects */
6912 isnoeffect(OPCODE type)
6929 case Op_unary_minus:
6946 break; /* keeps gcc -Wall happy */
6951 #endif /* NO_LINT */
6954 /* make_assignable --- make this operand an assignable one if posiible */
6956 static INSTRUCTION *
6957 make_assignable(INSTRUCTION *ip)
6959 switch (ip->opcode) {
6961 ip->opcode = Op_push_lhs;
6964 ip->opcode = Op_field_spec_lhs;
6967 ip->opcode = Op_subscript_lhs;
6970 break; /* keeps gcc -Wall happy */
6975 /* stopme --- for debugging */
6978 stopme(int nargs ATTRIBUTE_UNUSED)
6980 return make_number(0.0);
6983 /* dumpintlstr --- write out an initial .po file entry for the string */
6986 dumpintlstr(const char *str, size_t len)
6990 /* See the GNU gettext distribution for details on the file format */
6992 if (source != NULL) {
6993 /* ala the gettext sources, remove leading `./'s */
6994 for (cp = source; cp[0] == '.' && cp[1] == '/'; cp += 2)
6996 printf("#: %s:%d\n", cp, sourceline);
7000 pp_string_fp(fprintf, stdout, str, len, '"', true);
7002 printf("msgstr \"\"\n\n");
7006 /* dumpintlstr2 --- write out an initial .po file entry for the string and its plural */
7009 dumpintlstr2(const char *str1, size_t len1, const char *str2, size_t len2)
7013 /* See the GNU gettext distribution for details on the file format */
7015 if (source != NULL) {
7016 /* ala the gettext sources, remove leading `./'s */
7017 for (cp = source; cp[0] == '.' && cp[1] == '/'; cp += 2)
7019 printf("#: %s:%d\n", cp, sourceline);
7023 pp_string_fp(fprintf, stdout, str1, len1, '"', true);
7025 printf("msgid_plural ");
7026 pp_string_fp(fprintf, stdout, str2, len2, '"', true);
7028 printf("msgstr[0] \"\"\nmsgstr[1] \"\"\n\n");
7032 /* mk_binary --- instructions for binary operators */
7034 static INSTRUCTION *
7035 mk_binary(INSTRUCTION *s1, INSTRUCTION *s2, INSTRUCTION *op)
7037 INSTRUCTION *ip1,*ip2;
7041 if (s2->lasti == ip2 && ip2->opcode == Op_push_i) {
7042 /* do any numeric constant folding */
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
7049 NODE *n1 = ip1->memory, *n2 = ip2->memory;
7050 res = force_number(n1)->numbr;
7051 (void) force_number(n2);
7052 switch (op->opcode) {
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"));
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 `%%'"));
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 */
7085 res = calc_exp(res, n2->numbr);
7091 op->opcode = Op_push_i;
7092 op->memory = make_number(res);
7099 return list_create(op);
7101 /* do basic arithmetic optimisation */
7102 /* convert (Op_push_i Node_val) + (Op_plus) to (Op_plus_i Node_val) */
7103 switch (op->opcode) {
7105 op->opcode = Op_times_i;
7108 op->opcode = Op_quotient_i;
7111 op->opcode = Op_mod_i;
7114 op->opcode = Op_plus_i;
7117 op->opcode = Op_minus_i;
7120 op->opcode = Op_exp_i;
7126 op->memory = ip2->memory;
7128 bcfree(s2); /* Op_list */
7129 return list_append(s1, op);
7134 /* append lists s1, s2 and add `op' bytecode */
7135 (void) list_merge(s1, s2);
7136 return list_append(s1, op);
7139 /* mk_boolean --- instructions for boolean and, or */
7141 static INSTRUCTION *
7142 mk_boolean(INSTRUCTION *left, INSTRUCTION *right, INSTRUCTION *op)
7145 OPCODE opc, final_opc;
7147 opc = op->opcode; /* Op_and or Op_or */
7148 final_opc = (opc == Op_or) ? Op_or_final : Op_and_final;
7150 add_lint(right, LINT_assign_in_cond);
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;
7160 /* NB: target_stmt points to previous Op_and(Op_or) in a chain;
7161 * target_stmt only used in the parser (see below).
7164 left->lasti->target_stmt = left->lasti;
7165 right->lasti->target_stmt = left->lasti;
7166 } else { /* optimization for x || y || z || ... */
7169 op->opcode = final_opc;
7170 (void) list_append(right, op);
7171 op->target_stmt = tp;
7173 tp->target_jmp = op;
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)
7186 return list_merge(left, right);
7189 /* mk_condition --- if-else and conditional */
7191 static INSTRUCTION *
7192 mk_condition(INSTRUCTION *cond, INSTRUCTION *ifp, INSTRUCTION *true_branch,
7193 INSTRUCTION *elsep, INSTRUCTION *false_branch)
7199 * t: [Op_jmp_false f ]
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);
7224 /* assert(elsep != NULL); */
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));
7237 (void) list_prepend(false_branch, instruction(Op_jmp));
7238 false_branch->nexti->target_jmp = false_branch->lasti;
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;
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;
7252 if (true_branch != NULL)
7253 list_merge(ip, true_branch);
7254 return list_merge(ip, false_branch);
7257 enum defline { FIRST_LINE, LAST_LINE };
7259 /* find_line -- find the first(last) line in a list of (pattern) instructions */
7262 find_line(INSTRUCTION *pattern, enum defline what)
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;
7276 if (ip == pattern->lasti)
7283 /* append_rule --- pattern-action instructions */
7285 static INSTRUCTION *
7286 append_rule(INSTRUCTION *pattern, INSTRUCTION *action)
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);
7315 rp = bcalloc(Op_rule, 3, 0);
7317 rp->source_file = source;
7318 tp = instruction(Op_no_op);
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);
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));
7341 (rp + 2)->last_line = lastline;
7343 if (do_pretty_print) {
7344 (void) list_prepend(pattern, instruction(Op_exec_count));
7345 (void) list_prepend(action, instruction(Op_exec_count));
7347 (rp + 1)->firsti = action->nexti;
7348 (rp + 1)->lasti = tp;
7350 list_merge(list_prepend(pattern, rp),
7357 list_append(rule_list, rp + 1);
7359 if (rule_block[rule] == NULL)
7360 rule_block[rule] = ip;
7362 (void) list_merge(rule_block[rule], ip);
7364 return rule_block[rule];
7367 /* mk_assignment --- assignment bytecodes */
7369 static INSTRUCTION *
7370 mk_assignment(INSTRUCTION *lhs, INSTRUCTION *rhs, INSTRUCTION *op)
7376 switch (tp->opcode) {
7378 tp->opcode = Op_field_spec_lhs;
7381 tp->opcode = Op_subscript_lhs;
7385 tp->opcode = Op_push_lhs;
7387 case Op_field_assign:
7388 yyerror(_("cannot assign a value to the result of a field post-increment expression"));
7391 yyerror(_("invalid target of assignment (opcode %s)"),
7392 opcode2str(tp->opcode));
7396 tp->do_reference = (op->opcode != Op_assign); /* check for uninitialized reference */
7399 ip = list_merge(rhs, lhs);
7403 (void) list_append(ip, op);
7405 if (tp->opcode == Op_push_lhs
7406 && tp->memory->type == Node_var
7407 && tp->memory->var_assign
7409 tp->do_reference = false; /* no uninitialized reference checking
7410 * for a special variable.
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));
7425 /* optimize_assignment --- peephole optimization for assignment */
7427 static INSTRUCTION *
7428 optimize_assignment(INSTRUCTION *exp)
7430 INSTRUCTION *i1, *i2, *i3;
7433 * Optimize assignment statements array[subs] = x; var = x; $n = x;
7434 * string concatenation of the form s = s t.
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.
7441 * 2) Simple variable assignment var = x:
7442 * Replaces Op_push_lhs + Op_assign + Op_pop with Op_store_var.
7444 * 3) Field assignment $n = x:
7445 * Replaces Op_field_spec_lhs + Op_assign + Op_field_assign + Op_pop
7446 * with Op_store_field.
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.
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.
7463 if ( i1->opcode != Op_assign
7464 && i1->opcode != Op_field_assign)
7465 return list_append(exp, instruction(Op_pop));
7467 for (i2 = exp->nexti; i2 != i1; i2 = i2->nexti) {
7468 switch (i2->opcode) {
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.
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
7478 /* s = s ... optimization */
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.
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 */
7492 /* remove the variable from r.h.s */
7494 exp->nexti = i3->nexti;
7497 if (--i2->expr_count == 1) /* one less expression in Op_concat */
7498 i2->opcode = Op_no_op;
7501 assert(i3->opcode == Op_push_lhs);
7502 i3->opcode = Op_assign_concat; /* change Op_push_lhs to Op_assign_concat */
7504 bcfree(i1); /* Op_assign */
7505 exp->lasti = i3; /* update Op_list */
7510 case Op_field_spec_lhs:
7511 if (i2->nexti->opcode == Op_assign
7512 && i2->nexti->nexti == i1
7513 && i1->opcode == Op_field_assign
7516 i2->opcode = Op_store_field;
7517 bcfree(i2->nexti); /* Op_assign */
7519 bcfree(i1); /* Op_field_assign */
7520 exp->lasti = i2; /* update Op_list */
7526 if (i2->nexti->nexti->opcode == Op_subscript_lhs) {
7527 i3 = i2->nexti->nexti;
7528 if (i3->sub_count == 1
7530 && i1->opcode == Op_assign
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.
7539 i2->opcode = Op_no_op;
7540 bcfree(i1); /* Op_assign */
7541 exp->lasti = i3; /* update Op_list */
7549 && i1->opcode == Op_assign
7552 i2->opcode = Op_store_var;
7554 bcfree(i1); /* Op_assign */
7555 exp->lasti = i2; /* update Op_list */
7558 if (i3->opcode == Op_push_i
7559 && (i3->memory->flags & INTLSTR) == 0
7562 /* constant initializer */
7563 i2->initval = i3->memory;
7578 /* no optimization */
7579 return list_append(exp, instruction(Op_pop));
7583 /* mk_getline --- make instructions for getline */
7585 static INSTRUCTION *
7586 mk_getline(INSTRUCTION *op, INSTRUCTION *var, INSTRUCTION *redir, int redirtype)
7590 INSTRUCTION *asgn = NULL;
7593 * getline [var] < [file]
7595 * [ file (simp_exp)]
7597 * [ Op_K_getline_redir|NULL|redir_type|into_var]
7602 if (redir == NULL) {
7603 int sline = op->source_line;
7605 op = bcalloc(Op_K_getline, 2, sline);
7606 (op + 1)->target_endfile = ip_endfile;
7607 (op + 1)->target_beginfile = ip_beginfile;
7611 tp = make_assignable(var->lasti);
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
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;
7632 if (redir != NULL) {
7633 ip = list_merge(redir, var);
7634 (void) list_append(ip, op);
7636 ip = list_append(var, op);
7637 } else if (redir != NULL)
7638 ip = list_append(redir, op);
7640 ip = list_create(op);
7641 op->into_var = (var != NULL);
7642 op->redir_type = (redir != NULL) ? redirtype : redirect_none;
7644 return (asgn == NULL ? ip : list_append(ip, asgn));
7648 /* mk_for_loop --- for loop bytecodes */
7650 static INSTRUCTION *
7651 mk_for_loop(INSTRUCTION *forp, INSTRUCTION *init, INSTRUCTION *cond,
7652 INSTRUCTION *incr, INSTRUCTION *body)
7655 * ------------------------
7656 * init (may be NULL)
7657 * ------------------------
7659 * cond (Op_no_op if NULL)
7660 * ------------------------
7661 * [ Op_jmp_false tb ]
7662 * ------------------------
7663 * body (may be NULL)
7664 * ------------------------
7666 * incr (may be NULL)
7668 * ------------------------
7672 INSTRUCTION *ip, *tbreak, *tcont;
7674 INSTRUCTION *pp_cond;
7677 tbreak = instruction(Op_no_op);
7680 add_lint(cond, LINT_assign_in_cond);
7681 pp_cond = cond->nexti;
7683 (void) list_append(ip, instruction(Op_jmp_false));
7684 ip->lasti->target_jmp = tbreak;
7686 pp_cond = instruction(Op_no_op);
7687 ip = list_create(pp_cond);
7691 ip = list_merge(init, ip);
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;
7700 (void) list_merge(ip, body);
7702 jmp = instruction(Op_jmp);
7703 jmp->target_jmp = pp_cond;
7707 tcont = incr->nexti;
7708 (void) list_merge(ip, incr);
7711 (void) list_append(ip, jmp);
7712 ret = list_append(ip, tbreak);
7713 fix_break_continue(ret, tbreak, tcont);
7715 if (do_pretty_print) {
7716 forp->target_break = tbreak;
7717 forp->target_continue = tcont;
7718 ret = list_prepend(ret, forp);
7725 /* add_lint --- add lint warning bytecode if needed */
7728 add_lint(INSTRUCTION *list, LINTTYPE linttype)
7734 case LINT_assign_in_cond:
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)
7742 if (ip->opcode == Op_assign || ip->opcode == Op_assign_concat) {
7743 list_append(list, instruction(Op_lint));
7744 list->lasti->lint_type = linttype;
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)
7753 if (do_lint) { /* compile-time warning */
7754 if (isnoeffect(ip->opcode))
7755 lintwarn_ln(ip->source_line, ("statement may have no effect"));
7758 if (ip->opcode == Op_push) { /* run-time warning */
7759 list_append(list, instruction(Op_lint));
7760 list->lasti->lint_type = linttype;
7771 /* mk_expression_list --- list of bytecode lists */
7773 static INSTRUCTION *
7774 mk_expression_list(INSTRUCTION *list, INSTRUCTION *s1)
7778 /* we can't just combine all bytecodes, since we need to
7779 * process individual expressions for a few builtins in snode() (-:
7782 /* -- list of lists */
7783 /* [Op_list| ... ]------
7785 * [Op_list| ... ] -- |
7788 * [Op_list| ... ] -- |
7794 assert(s1 != NULL && s1->opcode == Op_list);
7796 list = instruction(Op_list);
7798 list->lasti = s1->lasti;
7802 /* append expression to the end of the list */
7806 list->lasti = s1->lasti;
7810 /* count_expressions --- fixup expression_list from mk_expression_list.
7811 * returns no of expressions in list. isarg is true
7812 * for function arguments.
7816 count_expressions(INSTRUCTION **list, bool isarg)
7819 INSTRUCTION *r = NULL;
7822 if (*list == NULL) /* error earlier */
7825 for (expr = (*list)->nexti; expr; ) {
7826 INSTRUCTION *t1, *t2;
7829 if (isarg && t1 == t2 && t1->opcode == Op_push)
7830 t1->opcode = Op_push_param;
7834 (void) list_merge(r, expr);
7839 if (! isarg && count > max_args)
7846 /* fix_break_continue --- fix up break & continue codes in loop bodies */
7849 fix_break_continue(INSTRUCTION *list, INSTRUCTION *b_target, INSTRUCTION *c_target)
7853 list->lasti->nexti = NULL; /* just to make sure */
7855 for (ip = list->nexti; ip != NULL; ip = ip->nexti) {
7856 switch (ip->opcode) {
7858 if (ip->target_jmp == NULL)
7859 ip->target_jmp = b_target;
7863 if (ip->target_jmp == NULL)
7864 ip->target_jmp = c_target;
7868 /* this is to keep the compiler happy. sheesh. */
7874 static inline INSTRUCTION *
7875 list_create(INSTRUCTION *x)
7879 l = instruction(Op_list);
7885 static inline INSTRUCTION *
7886 list_append(INSTRUCTION *l, INSTRUCTION *x)
7889 if (l->opcode != Op_list)
7892 l->lasti->nexti = x;
7897 static inline INSTRUCTION *
7898 list_prepend(INSTRUCTION *l, INSTRUCTION *x)
7901 if (l->opcode != Op_list)
7904 x->nexti = l->nexti;
7909 static inline INSTRUCTION *
7910 list_merge(INSTRUCTION *l1, INSTRUCTION *l2)
7913 if (l1->opcode != Op_list)
7915 if (l2->opcode != Op_list)
7918 l1->lasti->nexti = l2->nexti;
7919 l1->lasti = l2->lasti;
7924 /* See if name is a special token. */
7927 check_special(const char *name)
7931 #if 'a' == 0x81 /* it's EBCDIC */
7932 static bool did_sort = false;
7935 qsort((void *) tokentab,
7936 sizeof(tokentab) / sizeof(tokentab[0]),
7937 sizeof(tokentab[0]), tokcompare);
7943 high = (sizeof(tokentab) / sizeof(tokentab[0])) - 1;
7944 while (low <= high) {
7945 mid = (low + high) / 2;
7946 i = *name - tokentab[mid].operator[0];
7948 i = strcmp(name, tokentab[mid].operator);
7950 if (i < 0) /* token < mid */
7952 else if (i > 0) /* token > mid */
7955 if ((do_traditional && (tokentab[mid].flags & GAWKX))
7956 || (do_posix && (tokentab[mid].flags & NOT_POSIX)))
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.
7970 static FILE *fp = NULL;
7972 /* read_one_line --- return one input line at a time. mainly for debugging. */
7975 read_one_line(int fd, void *buffer, size_t count)
7979 /* Minor potential memory leak here. Too bad. */
7981 fp = fdopen(fd, "r");
7983 fprintf(stderr, "ugh. fdopen: %s\n", strerror(errno));
7984 gawk_exit(EXIT_FAILURE);
7988 if (fgets(buf, sizeof buf, fp) == NULL)
7991 memcpy(buffer, buf, strlen(buf));
7995 /* one_line_close --- close the open file being read with read_one_line() */
7998 one_line_close(int fd)
8002 if (fp == NULL || fd != fileno(fp))
8003 fatal("debugging read/close screwed up!");