~vcs-imports/gawk/master

408.13.50 by Arnold D. Robbins
Move to Bison 3.0.4.
1
/* A Bison parser, made by GNU Bison 3.0.4.  */
35 by Arnold D. Robbins
Move to gawk-3.1.7.
2
228 by Arnold D. Robbins
Update to bison 2.5.
3
/* Bison implementation for Yacc-like parsers in C
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
4
408.13.40 by Arnold D. Robbins
Update to bison 3.0.3.
5
   Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
6
35 by Arnold D. Robbins
Move to gawk-3.1.7.
7
   This program is free software: you can redistribute it and/or modify
30 by Arnold D. Robbins
Move to gawk-3.1.2.
8
   it under the terms of the GNU General Public License as published by
35 by Arnold D. Robbins
Move to gawk-3.1.7.
9
   the Free Software Foundation, either version 3 of the License, or
10
   (at your option) any later version.
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
11
30 by Arnold D. Robbins
Move to gawk-3.1.2.
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.
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
16
30 by Arnold D. Robbins
Move to gawk-3.1.2.
17
   You should have received a copy of the GNU General Public License
35 by Arnold D. Robbins
Move to gawk-3.1.7.
18
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20
/* As a special exception, you may create a larger work that contains
21
   part or all of the Bison parser skeleton and distribute that work
22
   under terms of your choice, so long as that work isn't itself a
23
   parser generator using the skeleton or a modified version thereof
24
   as a parser skeleton.  Alternatively, if you modify or redistribute
25
   the parser skeleton itself, you may (at your option) remove this
26
   special exception, which will cause the skeleton and the resulting
27
   Bison output files to be licensed under the GNU General Public
28
   License without this special exception.
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
29
35 by Arnold D. Robbins
Move to gawk-3.1.7.
30
   This special exception was added by the Free Software Foundation in
31
   version 2.2 of Bison.  */
32
33
/* C LALR(1) parser skeleton written by Richard Stallman, by
34
   simplifying the original so-called "semantic" parser.  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
35
36
/* All symbols defined below should begin with yy or YY, to avoid
37
   infringing on user name space.  This should be done even for local
38
   variables, as they might otherwise be expanded by user macros.
39
   There are some unavoidable exceptions within include files to
40
   define necessary library symbols; they are noted "INFRINGES ON
41
   USER NAME SPACE" below.  */
42
43
/* Identify Bison output.  */
44
#define YYBISON 1
45
35 by Arnold D. Robbins
Move to gawk-3.1.7.
46
/* Bison version.  */
408.13.50 by Arnold D. Robbins
Move to Bison 3.0.4.
47
#define YYBISON_VERSION "3.0.4"
35 by Arnold D. Robbins
Move to gawk-3.1.7.
48
30 by Arnold D. Robbins
Move to gawk-3.1.2.
49
/* Skeleton name.  */
50
#define YYSKELETON_NAME "yacc.c"
51
52
/* Pure parsers.  */
53
#define YYPURE 0
54
35 by Arnold D. Robbins
Move to gawk-3.1.7.
55
/* Push parsers.  */
56
#define YYPUSH 0
57
58
/* Pull parsers.  */
59
#define YYPULL 1
60
30 by Arnold D. Robbins
Move to gawk-3.1.2.
61
62
63
35 by Arnold D. Robbins
Move to gawk-3.1.7.
64
/* Copy the first part of user declarations.  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
65
#line 26 "awkgram.y" /* yacc.c:339  */
35 by Arnold D. Robbins
Move to gawk-3.1.7.
66
67
#ifdef GAWKDEBUG
68
#define YYDEBUG 12
69
#endif
70
71
#include "awk.h"
72
73
#if defined(__STDC__) && __STDC__ < 1	/* VMS weirdness, maybe elsewhere */
74
#define signed /**/
75
#endif
76
77
static void yyerror(const char *m, ...) ATTRIBUTE_PRINTF_1;
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
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;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
81
static char *get_src_buf(void);
82
static int yylex(void);
83
int	yyparse(void); 
84
static INSTRUCTION *snode(INSTRUCTION *subn, INSTRUCTION *op);
281.1.1 by john haque
Speed/memory performance improvements.
85
static char **check_params(char *fname, int pcount, INSTRUCTION *list);
86
static int install_function(char *fname, INSTRUCTION *fi, INSTRUCTION *plist);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
87
static NODE *mk_rexp(INSTRUCTION *exp);
88
static void param_sanity(INSTRUCTION *arglist);
387 by Arnold D. Robbins
Considerable additional portability fixes.
89
static int parms_shadow(INSTRUCTION *pc, bool *shadow);
348 by Arnold D. Robbins
Fix --disable-lint.
90
#ifndef NO_LINT
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
91
static int isnoeffect(OPCODE type);
348 by Arnold D. Robbins
Fix --disable-lint.
92
#endif
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
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);
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
96
static int include_source(INSTRUCTION *file);
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
97
static int load_library(INSTRUCTION *file);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
98
static void next_sourcefile(void);
99
static char *tokexpand(void);
100
101
#define instruction(t)	bcalloc(t, 1, 0)
102
103
static INSTRUCTION *mk_program(void);
104
static INSTRUCTION *append_rule(INSTRUCTION *pattern, INSTRUCTION *action);
281.1.1 by john haque
Speed/memory performance improvements.
105
static INSTRUCTION *mk_function(INSTRUCTION *fi, INSTRUCTION *def);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
106
static INSTRUCTION *mk_condition(INSTRUCTION *cond, INSTRUCTION *ifp, INSTRUCTION *true_branch,
107
		INSTRUCTION *elsep,	INSTRUCTION *false_branch);
108
static INSTRUCTION *mk_expression_list(INSTRUCTION *list, INSTRUCTION *s1);
109
static INSTRUCTION *mk_for_loop(INSTRUCTION *forp, INSTRUCTION *init, INSTRUCTION *cond,
110
		INSTRUCTION *incr, INSTRUCTION *body);
116 by Arnold D. Robbins
Fix switch debugging.
111
static void fix_break_continue(INSTRUCTION *list, INSTRUCTION *b_target, INSTRUCTION *c_target);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
112
static INSTRUCTION *mk_binary(INSTRUCTION *s1, INSTRUCTION *s2, INSTRUCTION *op);
113
static INSTRUCTION *mk_boolean(INSTRUCTION *left, INSTRUCTION *right, INSTRUCTION *op);
114
static INSTRUCTION *mk_assignment(INSTRUCTION *lhs, INSTRUCTION *rhs, INSTRUCTION *op);
116 by Arnold D. Robbins
Fix switch debugging.
115
static INSTRUCTION *mk_getline(INSTRUCTION *op, INSTRUCTION *opt_var, INSTRUCTION *redir, int redirtype);
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
116
static int count_expressions(INSTRUCTION **list, bool isarg);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
117
static INSTRUCTION *optimize_assignment(INSTRUCTION *exp);
118
static void add_lint(INSTRUCTION *list, LINTTYPE linttype);
35 by Arnold D. Robbins
Move to gawk-3.1.7.
119
319.2.43 by Arnold D. Robbins
Fix lint checking for extension functions.
120
enum defref { FUNC_DEFINE, FUNC_USE, FUNC_EXT };
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
121
static void func_use(const char *name, enum defref how);
122
static void check_funcs(void);
123
124
static ssize_t read_one_line(int fd, void *buffer, size_t count);
125
static int one_line_close(int fd);
126
408.13.59 by Arnold D. Robbins
Disallow calling a function parameter. Check params are not function names.
127
static bool at_seen = false;
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
128
static bool want_source = false;
319.1.80 by Arnold D. Robbins
Some minor fixes. See ChangeLog.
129
static bool want_regexp = false;	/* lexical scanning kludge */
281.1.4 by john haque
Optimize tail-recursive calls.
130
static char *in_function;		/* parsing kludge */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
131
static int rule = 0;
132
133
const char *const ruletab[] = {
134
	"?",
135
	"BEGIN",
136
	"Rule",
137
	"END",
138
	"BEGINFILE",
139
	"ENDFILE",
140
};
141
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
142
static bool in_print = false;	/* lexical scanning kludge for print */
35 by Arnold D. Robbins
Move to gawk-3.1.7.
143
static int in_parens = 0;	/* lexical scanning kludge for print */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
144
static int sub_counter = 0;	/* array dimension counter for use in delete */
408.19.48 by Arnold D. Robbins
Bug fix, invalid read in yylex.
145
static char *lexptr;		/* pointer to next char during parsing */
146
static char *lexend;		/* end of buffer */
35 by Arnold D. Robbins
Move to gawk-3.1.7.
147
static char *lexptr_begin;	/* keep track of where we were for error msgs */
148
static char *lexeme;		/* beginning of lexeme for debugging */
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
149
static bool lexeof;		/* seen EOF for current source? */  
35 by Arnold D. Robbins
Move to gawk-3.1.7.
150
static char *thisline = NULL;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
151
static int in_braces = 0;	/* count braces for firstline, lastline in an 'action' */
152
static int lastline = 0;
153
static int firstline = 0;
154
static SRCFILE *sourcefile = NULL;	/* current program source */
155
static int lasttok = 0;
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
156
static bool eof_warned = false;	/* GLOBAL: want warning for each file */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
157
static int break_allowed;	/* kludge for break */
158
static int continue_allowed;	/* kludge for continue */
159
160
#define END_FILE	-1000
161
#define END_SRC  	-2000
162
35 by Arnold D. Robbins
Move to gawk-3.1.7.
163
#define YYDEBUG_LEXER_TEXT (lexeme)
164
static char *tokstart = NULL;
165
static char *tok = NULL;
166
static char *tokend;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
167
static int errcount = 0;
168
35 by Arnold D. Robbins
Move to gawk-3.1.7.
169
extern char *source;
170
extern int sourceline;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
171
extern SRCFILE *srcfiles;
172
extern INSTRUCTION *rule_list;
173
extern int max_args;
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
174
extern NODE **args_array;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
175
176
static INSTRUCTION *rule_block[sizeof(ruletab)];
177
178
static INSTRUCTION *ip_rec;
179
static INSTRUCTION *ip_newfile;
180
static INSTRUCTION *ip_atexit = NULL;
181
static INSTRUCTION *ip_end;
182
static INSTRUCTION *ip_endfile;
183
static INSTRUCTION *ip_beginfile;
184
185
static inline INSTRUCTION *list_create(INSTRUCTION *x);
186
static inline INSTRUCTION *list_append(INSTRUCTION *l, INSTRUCTION *x);
187
static inline INSTRUCTION *list_prepend(INSTRUCTION *l, INSTRUCTION *x);
188
static inline INSTRUCTION *list_merge(INSTRUCTION *l1, INSTRUCTION *l2);
189
190
extern double fmod(double x, double y);
35 by Arnold D. Robbins
Move to gawk-3.1.7.
191
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
192
#define YYSTYPE INSTRUCTION *
193
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
194
#line 195 "awkgram.c" /* yacc.c:339  */
319.1.18 by Arnold D. Robbins
Update infrastructure.
195
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
196
# ifndef YY_NULLPTR
319.1.18 by Arnold D. Robbins
Update infrastructure.
197
#  if defined __cplusplus && 201103L <= __cplusplus
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
198
#   define YY_NULLPTR nullptr
319.1.18 by Arnold D. Robbins
Update infrastructure.
199
#  else
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
200
#   define YY_NULLPTR 0
319.1.18 by Arnold D. Robbins
Update infrastructure.
201
#  endif
202
# endif
35 by Arnold D. Robbins
Move to gawk-3.1.7.
203
204
/* Enabling verbose error messages.  */
205
#ifdef YYERROR_VERBOSE
206
# undef YYERROR_VERBOSE
207
# define YYERROR_VERBOSE 1
208
#else
209
# define YYERROR_VERBOSE 0
210
#endif
211
277.1.174 by Arnold D. Robbins
Update to bison 2.6.4.
212
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
213
/* Debug traces.  */
319.1.18 by Arnold D. Robbins
Update infrastructure.
214
#ifndef YYDEBUG
215
# define YYDEBUG 0
216
#endif
217
#if YYDEBUG
218
extern int yydebug;
219
#endif
35 by Arnold D. Robbins
Move to gawk-3.1.7.
220
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
221
/* Token type.  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
222
#ifndef YYTOKENTYPE
223
# define YYTOKENTYPE
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
224
  enum yytokentype
225
  {
226
    FUNC_CALL = 258,
227
    NAME = 259,
228
    REGEXP = 260,
229
    FILENAME = 261,
230
    YNUMBER = 262,
231
    YSTRING = 263,
232
    RELOP = 264,
233
    IO_OUT = 265,
234
    IO_IN = 266,
235
    ASSIGNOP = 267,
236
    ASSIGN = 268,
237
    MATCHOP = 269,
238
    CONCAT_OP = 270,
239
    SUBSCRIPT = 271,
240
    LEX_BEGIN = 272,
241
    LEX_END = 273,
242
    LEX_IF = 274,
243
    LEX_ELSE = 275,
244
    LEX_RETURN = 276,
245
    LEX_DELETE = 277,
246
    LEX_SWITCH = 278,
247
    LEX_CASE = 279,
248
    LEX_DEFAULT = 280,
249
    LEX_WHILE = 281,
250
    LEX_DO = 282,
251
    LEX_FOR = 283,
252
    LEX_BREAK = 284,
253
    LEX_CONTINUE = 285,
254
    LEX_PRINT = 286,
255
    LEX_PRINTF = 287,
256
    LEX_NEXT = 288,
257
    LEX_EXIT = 289,
258
    LEX_FUNCTION = 290,
259
    LEX_BEGINFILE = 291,
260
    LEX_ENDFILE = 292,
261
    LEX_GETLINE = 293,
262
    LEX_NEXTFILE = 294,
263
    LEX_IN = 295,
264
    LEX_AND = 296,
265
    LEX_OR = 297,
266
    INCREMENT = 298,
267
    DECREMENT = 299,
268
    LEX_BUILTIN = 300,
269
    LEX_LENGTH = 301,
270
    LEX_EOF = 302,
271
    LEX_INCLUDE = 303,
272
    LEX_EVAL = 304,
273
    LEX_LOAD = 305,
274
    NEWLINE = 306,
275
    SLASH_BEFORE_EQUAL = 307,
276
    UNARY = 308
277
  };
30 by Arnold D. Robbins
Move to gawk-3.1.2.
278
#endif
35 by Arnold D. Robbins
Move to gawk-3.1.7.
279
/* Tokens.  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
280
#define FUNC_CALL 258
281
#define NAME 259
282
#define REGEXP 260
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
283
#define FILENAME 261
30 by Arnold D. Robbins
Move to gawk-3.1.2.
284
#define YNUMBER 262
285
#define YSTRING 263
286
#define RELOP 264
287
#define IO_OUT 265
288
#define IO_IN 266
289
#define ASSIGNOP 267
290
#define ASSIGN 268
291
#define MATCHOP 269
292
#define CONCAT_OP 270
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
293
#define SUBSCRIPT 271
294
#define LEX_BEGIN 272
295
#define LEX_END 273
296
#define LEX_IF 274
297
#define LEX_ELSE 275
298
#define LEX_RETURN 276
299
#define LEX_DELETE 277
300
#define LEX_SWITCH 278
301
#define LEX_CASE 279
302
#define LEX_DEFAULT 280
303
#define LEX_WHILE 281
304
#define LEX_DO 282
305
#define LEX_FOR 283
306
#define LEX_BREAK 284
307
#define LEX_CONTINUE 285
308
#define LEX_PRINT 286
309
#define LEX_PRINTF 287
310
#define LEX_NEXT 288
311
#define LEX_EXIT 289
312
#define LEX_FUNCTION 290
313
#define LEX_BEGINFILE 291
314
#define LEX_ENDFILE 292
315
#define LEX_GETLINE 293
316
#define LEX_NEXTFILE 294
317
#define LEX_IN 295
318
#define LEX_AND 296
319
#define LEX_OR 297
320
#define INCREMENT 298
321
#define DECREMENT 299
322
#define LEX_BUILTIN 300
323
#define LEX_LENGTH 301
324
#define LEX_EOF 302
325
#define LEX_INCLUDE 303
326
#define LEX_EVAL 304
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
327
#define LEX_LOAD 305
328
#define NEWLINE 306
329
#define SLASH_BEFORE_EQUAL 307
330
#define UNARY 308
30 by Arnold D. Robbins
Move to gawk-3.1.2.
331
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
332
/* Value type.  */
35 by Arnold D. Robbins
Move to gawk-3.1.7.
333
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
334
typedef int YYSTYPE;
35 by Arnold D. Robbins
Move to gawk-3.1.7.
335
# define YYSTYPE_IS_TRIVIAL 1
30 by Arnold D. Robbins
Move to gawk-3.1.2.
336
# define YYSTYPE_IS_DECLARED 1
337
#endif
338
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
339
319.1.18 by Arnold D. Robbins
Update infrastructure.
340
extern YYSTYPE yylval;
341
342
int yyparse (void);
343
277.1.174 by Arnold D. Robbins
Update to bison 2.6.4.
344
30 by Arnold D. Robbins
Move to gawk-3.1.2.
345
346
/* Copy the second part of user declarations.  */
347
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
348
#line 349 "awkgram.c" /* yacc.c:358  */
35 by Arnold D. Robbins
Move to gawk-3.1.7.
349
350
#ifdef short
351
# undef short
352
#endif
353
354
#ifdef YYTYPE_UINT8
355
typedef YYTYPE_UINT8 yytype_uint8;
356
#else
357
typedef unsigned char yytype_uint8;
358
#endif
359
360
#ifdef YYTYPE_INT8
361
typedef YYTYPE_INT8 yytype_int8;
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
362
#else
35 by Arnold D. Robbins
Move to gawk-3.1.7.
363
typedef signed char yytype_int8;
364
#endif
365
366
#ifdef YYTYPE_UINT16
367
typedef YYTYPE_UINT16 yytype_uint16;
368
#else
369
typedef unsigned short int yytype_uint16;
370
#endif
371
372
#ifdef YYTYPE_INT16
373
typedef YYTYPE_INT16 yytype_int16;
374
#else
375
typedef short int yytype_int16;
376
#endif
377
378
#ifndef YYSIZE_T
379
# ifdef __SIZE_TYPE__
380
#  define YYSIZE_T __SIZE_TYPE__
381
# elif defined size_t
382
#  define YYSIZE_T size_t
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
383
# elif ! defined YYSIZE_T
35 by Arnold D. Robbins
Move to gawk-3.1.7.
384
#  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
385
#  define YYSIZE_T size_t
386
# else
387
#  define YYSIZE_T unsigned int
388
# endif
389
#endif
390
391
#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
392
393
#ifndef YY_
80 by Arnold D. Robbins
Upgrade to Autoconf 3.68 and Bison 2.4.3. Make a dist.
394
# if defined YYENABLE_NLS && YYENABLE_NLS
35 by Arnold D. Robbins
Move to gawk-3.1.7.
395
#  if ENABLE_NLS
396
#   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
277.1.174 by Arnold D. Robbins
Update to bison 2.6.4.
397
#   define YY_(Msgid) dgettext ("bison-runtime", Msgid)
35 by Arnold D. Robbins
Move to gawk-3.1.7.
398
#  endif
399
# endif
400
# ifndef YY_
277.1.174 by Arnold D. Robbins
Update to bison 2.6.4.
401
#  define YY_(Msgid) Msgid
35 by Arnold D. Robbins
Move to gawk-3.1.7.
402
# endif
403
#endif
404
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
405
#ifndef YY_ATTRIBUTE
406
# if (defined __GNUC__                                               \
407
      && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__)))  \
408
     || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
409
#  define YY_ATTRIBUTE(Spec) __attribute__(Spec)
410
# else
411
#  define YY_ATTRIBUTE(Spec) /* empty */
412
# endif
413
#endif
414
415
#ifndef YY_ATTRIBUTE_PURE
416
# define YY_ATTRIBUTE_PURE   YY_ATTRIBUTE ((__pure__))
417
#endif
418
419
#ifndef YY_ATTRIBUTE_UNUSED
420
# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
421
#endif
422
423
#if !defined _Noreturn \
424
     && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
425
# if defined _MSC_VER && 1200 <= _MSC_VER
426
#  define _Noreturn __declspec (noreturn)
427
# else
428
#  define _Noreturn YY_ATTRIBUTE ((__noreturn__))
408.2.32 by Arnold D. Robbins
Regenerate awkgram.c with latest bison.
429
# endif
430
#endif
431
35 by Arnold D. Robbins
Move to gawk-3.1.7.
432
/* Suppress unused-variable warnings by "using" E.  */
433
#if ! defined lint || defined __GNUC__
277.1.174 by Arnold D. Robbins
Update to bison 2.6.4.
434
# define YYUSE(E) ((void) (E))
35 by Arnold D. Robbins
Move to gawk-3.1.7.
435
#else
277.1.174 by Arnold D. Robbins
Update to bison 2.6.4.
436
# define YYUSE(E) /* empty */
35 by Arnold D. Robbins
Move to gawk-3.1.7.
437
#endif
438
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
439
#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
440
/* Suppress an incorrect diagnostic about yylval being uninitialized.  */
441
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
442
    _Pragma ("GCC diagnostic push") \
443
    _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
444
    _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
445
# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
446
    _Pragma ("GCC diagnostic pop")
447
#else
448
# define YY_INITIAL_VALUE(Value) Value
449
#endif
450
#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
451
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
452
# define YY_IGNORE_MAYBE_UNINITIALIZED_END
453
#endif
454
#ifndef YY_INITIAL_VALUE
455
# define YY_INITIAL_VALUE(Value) /* Nothing. */
456
#endif
408.2.32 by Arnold D. Robbins
Regenerate awkgram.c with latest bison.
457
35 by Arnold D. Robbins
Move to gawk-3.1.7.
458
459
#if ! defined yyoverflow || YYERROR_VERBOSE
33 by Arnold D. Robbins
Move to gawk 3.1.5.
460
30 by Arnold D. Robbins
Move to gawk-3.1.2.
461
/* The parser invokes alloca or malloc; define the necessary symbols.  */
28 by Arnold D. Robbins
Move to gawk-3.1.0.
462
33 by Arnold D. Robbins
Move to gawk 3.1.5.
463
# ifdef YYSTACK_USE_ALLOCA
464
#  if YYSTACK_USE_ALLOCA
465
#   ifdef __GNUC__
466
#    define YYSTACK_ALLOC __builtin_alloca
35 by Arnold D. Robbins
Move to gawk-3.1.7.
467
#   elif defined __BUILTIN_VA_ARG_INCR
468
#    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
469
#   elif defined _AIX
470
#    define YYSTACK_ALLOC __alloca
471
#   elif defined _MSC_VER
472
#    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
473
#    define alloca _alloca
33 by Arnold D. Robbins
Move to gawk 3.1.5.
474
#   else
30 by Arnold D. Robbins
Move to gawk-3.1.2.
475
#    define YYSTACK_ALLOC alloca
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
476
#    if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
35 by Arnold D. Robbins
Move to gawk-3.1.7.
477
#     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
319.1.18 by Arnold D. Robbins
Update infrastructure.
478
      /* Use EXIT_SUCCESS as a witness for stdlib.h.  */
228 by Arnold D. Robbins
Update to bison 2.5.
479
#     ifndef EXIT_SUCCESS
480
#      define EXIT_SUCCESS 0
35 by Arnold D. Robbins
Move to gawk-3.1.7.
481
#     endif
482
#    endif
30 by Arnold D. Robbins
Move to gawk-3.1.2.
483
#   endif
484
#  endif
485
# endif
486
487
# ifdef YYSTACK_ALLOC
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
488
   /* Pacify GCC's 'empty if-body' warning.  */
489
#  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
35 by Arnold D. Robbins
Move to gawk-3.1.7.
490
#  ifndef YYSTACK_ALLOC_MAXIMUM
491
    /* The OS might guarantee only one guard page at the bottom of the stack,
492
       and a page size can be as small as 4096 bytes.  So we cannot safely
493
       invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
494
       to allow for a few compiler-allocated temporary stack slots.  */
495
#   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
496
#  endif
30 by Arnold D. Robbins
Move to gawk-3.1.2.
497
# else
33 by Arnold D. Robbins
Move to gawk 3.1.5.
498
#  define YYSTACK_ALLOC YYMALLOC
499
#  define YYSTACK_FREE YYFREE
35 by Arnold D. Robbins
Move to gawk-3.1.7.
500
#  ifndef YYSTACK_ALLOC_MAXIMUM
501
#   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
502
#  endif
228 by Arnold D. Robbins
Update to bison 2.5.
503
#  if (defined __cplusplus && ! defined EXIT_SUCCESS \
35 by Arnold D. Robbins
Move to gawk-3.1.7.
504
       && ! ((defined YYMALLOC || defined malloc) \
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
505
             && (defined YYFREE || defined free)))
35 by Arnold D. Robbins
Move to gawk-3.1.7.
506
#   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
228 by Arnold D. Robbins
Update to bison 2.5.
507
#   ifndef EXIT_SUCCESS
508
#    define EXIT_SUCCESS 0
35 by Arnold D. Robbins
Move to gawk-3.1.7.
509
#   endif
510
#  endif
511
#  ifndef YYMALLOC
512
#   define YYMALLOC malloc
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
513
#   if ! defined malloc && ! defined EXIT_SUCCESS
35 by Arnold D. Robbins
Move to gawk-3.1.7.
514
void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
515
#   endif
516
#  endif
517
#  ifndef YYFREE
518
#   define YYFREE free
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
519
#   if ! defined free && ! defined EXIT_SUCCESS
35 by Arnold D. Robbins
Move to gawk-3.1.7.
520
void free (void *); /* INFRINGES ON USER NAME SPACE */
521
#   endif
522
#  endif
30 by Arnold D. Robbins
Move to gawk-3.1.2.
523
# endif
35 by Arnold D. Robbins
Move to gawk-3.1.7.
524
#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
525
526
408.1.12 by Arnold D. Robbins
Merge branch 'gawk-4.0-stable'
527
#if (! defined yyoverflow \
528
     && (! defined __cplusplus \
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
529
         || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
30 by Arnold D. Robbins
Move to gawk-3.1.2.
530
531
/* A type that is properly aligned for any stack member.  */
532
union yyalloc
533
{
35 by Arnold D. Robbins
Move to gawk-3.1.7.
534
  yytype_int16 yyss_alloc;
535
  YYSTYPE yyvs_alloc;
536
};
30 by Arnold D. Robbins
Move to gawk-3.1.2.
537
538
/* The size of the maximum gap between one aligned stack and the next.  */
539
# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
540
541
/* The size of an array large to enough to hold all stacks, each with
542
   N elements.  */
543
# define YYSTACK_BYTES(N) \
35 by Arnold D. Robbins
Move to gawk-3.1.7.
544
     ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
30 by Arnold D. Robbins
Move to gawk-3.1.2.
545
      + YYSTACK_GAP_MAXIMUM)
546
228 by Arnold D. Robbins
Update to bison 2.5.
547
# define YYCOPY_NEEDED 1
548
549
/* Relocate STACK from its old location to the new one.  The
550
   local variables YYSIZE and YYSTACKSIZE give the old and new number of
551
   elements in the stack, and YYPTR gives the new location of the
552
   stack.  Advance YYPTR to a properly aligned location for the next
553
   stack.  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
554
# define YYSTACK_RELOCATE(Stack_alloc, Stack)                           \
555
    do                                                                  \
556
      {                                                                 \
557
        YYSIZE_T yynewbytes;                                            \
558
        YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
559
        Stack = &yyptr->Stack_alloc;                                    \
560
        yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
561
        yyptr += yynewbytes / sizeof (*yyptr);                          \
562
      }                                                                 \
563
    while (0)
228 by Arnold D. Robbins
Update to bison 2.5.
564
565
#endif
566
567
#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
319.1.18 by Arnold D. Robbins
Update infrastructure.
568
/* Copy COUNT objects from SRC to DST.  The source and destination do
30 by Arnold D. Robbins
Move to gawk-3.1.2.
569
   not overlap.  */
570
# ifndef YYCOPY
35 by Arnold D. Robbins
Move to gawk-3.1.7.
571
#  if defined __GNUC__ && 1 < __GNUC__
319.1.18 by Arnold D. Robbins
Update infrastructure.
572
#   define YYCOPY(Dst, Src, Count) \
573
      __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
30 by Arnold D. Robbins
Move to gawk-3.1.2.
574
#  else
319.1.18 by Arnold D. Robbins
Update infrastructure.
575
#   define YYCOPY(Dst, Src, Count)              \
576
      do                                        \
577
        {                                       \
578
          YYSIZE_T yyi;                         \
579
          for (yyi = 0; yyi < (Count); yyi++)   \
580
            (Dst)[yyi] = (Src)[yyi];            \
581
        }                                       \
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
582
      while (0)
30 by Arnold D. Robbins
Move to gawk-3.1.2.
583
#  endif
584
# endif
228 by Arnold D. Robbins
Update to bison 2.5.
585
#endif /* !YYCOPY_NEEDED */
35 by Arnold D. Robbins
Move to gawk-3.1.7.
586
587
/* YYFINAL -- State number of the termination state.  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
588
#define YYFINAL  2
30 by Arnold D. Robbins
Move to gawk-3.1.2.
589
/* YYLAST -- Last index in YYTABLE.  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
590
#define YYLAST   1155
30 by Arnold D. Robbins
Move to gawk-3.1.2.
591
35 by Arnold D. Robbins
Move to gawk-3.1.7.
592
/* YYNTOKENS -- Number of terminals.  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
593
#define YYNTOKENS  75
35 by Arnold D. Robbins
Move to gawk-3.1.7.
594
/* YYNNTS -- Number of nonterminals.  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
595
#define YYNNTS  65
35 by Arnold D. Robbins
Move to gawk-3.1.7.
596
/* YYNRULES -- Number of rules.  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
597
#define YYNRULES  188
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
598
/* YYNSTATES -- Number of states.  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
599
#define YYNSTATES  335
30 by Arnold D. Robbins
Move to gawk-3.1.2.
600
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
601
/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
602
   by yylex, with out-of-bounds checking.  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
603
#define YYUNDEFTOK  2
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
604
#define YYMAXUTOK   308
30 by Arnold D. Robbins
Move to gawk-3.1.2.
605
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
606
#define YYTRANSLATE(YYX)                                                \
30 by Arnold D. Robbins
Move to gawk-3.1.2.
607
  ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
608
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
609
/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
610
   as returned by yylex, without out-of-bounds checking.  */
35 by Arnold D. Robbins
Move to gawk-3.1.7.
611
static const yytype_uint8 yytranslate[] =
30 by Arnold D. Robbins
Move to gawk-3.1.2.
612
{
613
       0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
614
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
615
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
616
       2,     2,     2,    63,     2,     2,    66,    62,     2,     2,
617
      67,    68,    60,    58,    55,    59,     2,    61,     2,     2,
618
       2,     2,     2,     2,     2,     2,     2,     2,    54,    74,
619
      56,     2,    57,    53,    69,     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,    70,     2,    71,    65,     2,     2,     2,     2,     2,
623
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
624
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
625
       2,     2,     2,    72,     2,    73,     2,     2,     2,     2,
30 by Arnold D. Robbins
Move to gawk-3.1.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,     2,     2,     2,     2,     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,     2,     2,     2,     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,     1,     2,     3,     4,
639
       5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
640
      15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
641
      25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
31 by Arnold D. Robbins
Move to gawk-3.1.3.
642
      35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
643
      45,    46,    47,    48,    49,    50,    51,    52,    64
30 by Arnold D. Robbins
Move to gawk-3.1.2.
644
};
645
646
#if YYDEBUG
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
647
  /* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
35 by Arnold D. Robbins
Move to gawk-3.1.7.
648
static const yytype_uint16 yyrline[] =
30 by Arnold D. Robbins
Move to gawk-3.1.2.
649
{
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
650
       0,   194,   194,   196,   201,   202,   206,   218,   222,   233,
651
     239,   245,   254,   262,   264,   269,   277,   279,   285,   286,
652
     288,   314,   325,   336,   342,   351,   361,   363,   365,   371,
653
     379,   380,   384,   403,   402,   436,   438,   443,   444,   457,
654
     462,   463,   467,   469,   471,   478,   568,   610,   652,   765,
655
     772,   779,   789,   798,   807,   816,   827,   843,   842,   866,
656
     878,   878,   976,   976,  1009,  1039,  1045,  1046,  1052,  1053,
657
    1060,  1065,  1077,  1091,  1093,  1101,  1106,  1108,  1116,  1118,
658
    1127,  1128,  1136,  1141,  1141,  1152,  1156,  1164,  1165,  1168,
408.13.164 by Arnold D. Robbins
Fix minor coredump.
659
    1170,  1175,  1176,  1185,  1186,  1191,  1196,  1205,  1207,  1209,
660
    1216,  1217,  1223,  1224,  1229,  1231,  1236,  1238,  1246,  1251,
661
    1260,  1267,  1269,  1271,  1287,  1297,  1304,  1306,  1311,  1313,
662
    1315,  1323,  1325,  1330,  1332,  1337,  1339,  1341,  1391,  1393,
663
    1395,  1397,  1399,  1401,  1403,  1405,  1419,  1424,  1429,  1454,
664
    1460,  1462,  1464,  1466,  1468,  1470,  1475,  1479,  1511,  1513,
665
    1519,  1525,  1538,  1539,  1540,  1545,  1550,  1554,  1558,  1573,
666
    1586,  1591,  1628,  1657,  1658,  1664,  1665,  1670,  1672,  1679,
667
    1696,  1713,  1715,  1722,  1727,  1735,  1745,  1757,  1766,  1770,
668
    1774,  1778,  1782,  1786,  1789,  1791,  1795,  1799,  1803
30 by Arnold D. Robbins
Move to gawk-3.1.2.
669
};
670
#endif
671
319.1.18 by Arnold D. Robbins
Update infrastructure.
672
#if YYDEBUG || YYERROR_VERBOSE || 0
35 by Arnold D. Robbins
Move to gawk-3.1.7.
673
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
674
   First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
675
static const char *const yytname[] =
676
{
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
677
  "$end", "error", "$undefined", "FUNC_CALL", "NAME", "REGEXP",
678
  "FILENAME", "YNUMBER", "YSTRING", "RELOP", "IO_OUT", "IO_IN", "ASSIGNOP",
679
  "ASSIGN", "MATCHOP", "CONCAT_OP", "SUBSCRIPT", "LEX_BEGIN", "LEX_END",
680
  "LEX_IF", "LEX_ELSE", "LEX_RETURN", "LEX_DELETE", "LEX_SWITCH",
37 by Arnold D. Robbins
Bring in development gawk changes.
681
  "LEX_CASE", "LEX_DEFAULT", "LEX_WHILE", "LEX_DO", "LEX_FOR", "LEX_BREAK",
682
  "LEX_CONTINUE", "LEX_PRINT", "LEX_PRINTF", "LEX_NEXT", "LEX_EXIT",
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
683
  "LEX_FUNCTION", "LEX_BEGINFILE", "LEX_ENDFILE", "LEX_GETLINE",
684
  "LEX_NEXTFILE", "LEX_IN", "LEX_AND", "LEX_OR", "INCREMENT", "DECREMENT",
685
  "LEX_BUILTIN", "LEX_LENGTH", "LEX_EOF", "LEX_INCLUDE", "LEX_EVAL",
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
686
  "LEX_LOAD", "NEWLINE", "SLASH_BEFORE_EQUAL", "'?'", "':'", "','", "'<'",
687
  "'>'", "'+'", "'-'", "'*'", "'/'", "'%'", "'!'", "UNARY", "'^'", "'$'",
688
  "'('", "')'", "'@'", "'['", "']'", "'{'", "'}'", "';'", "$accept",
689
  "program", "rule", "source", "library", "pattern", "action", "func_name",
690
  "lex_builtin", "function_prologue", "regexp", "$@1", "a_slash",
691
  "statements", "statement_term", "statement", "non_compound_stmt", "$@2",
692
  "simple_stmt", "$@3", "$@4", "opt_simple_stmt", "case_statements",
693
  "case_statement", "case_value", "print", "print_expression_list",
694
  "output_redir", "$@5", "if_statement", "nls", "opt_nls", "input_redir",
695
  "opt_param_list", "param_list", "opt_exp", "opt_expression_list",
696
  "expression_list", "exp", "assign_operator", "relop_or_less", "a_relop",
697
  "common_exp", "simp_exp", "simp_exp_nc", "non_post_simp_exp",
698
  "func_call", "direct_func_call", "opt_variable", "delete_subscript_list",
699
  "delete_subscript", "delete_exp_list", "bracketed_exp_list", "subscript",
700
  "subscript_list", "simple_variable", "variable", "opt_incdec", "l_brace",
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
701
  "r_brace", "r_paren", "opt_semi", "semi", "colon", "comma", YY_NULLPTR
30 by Arnold D. Robbins
Move to gawk-3.1.2.
702
};
703
#endif
704
705
# ifdef YYPRINT
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
706
/* YYTOKNUM[NUM] -- (External) token number corresponding to the
707
   (internal) symbol number NUM (which must be that of a token).  */
35 by Arnold D. Robbins
Move to gawk-3.1.7.
708
static const yytype_uint16 yytoknum[] =
30 by Arnold D. Robbins
Move to gawk-3.1.2.
709
{
710
       0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
711
     265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
712
     275,   276,   277,   278,   279,   280,   281,   282,   283,   284,
713
     285,   286,   287,   288,   289,   290,   291,   292,   293,   294,
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
714
     295,   296,   297,   298,   299,   300,   301,   302,   303,   304,
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
715
     305,   306,   307,    63,    58,    44,    60,    62,    43,    45,
716
      42,    47,    37,    33,   308,    94,    36,    40,    41,    64,
717
      91,    93,   123,   125,    59
30 by Arnold D. Robbins
Move to gawk-3.1.2.
718
};
719
# endif
720
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
721
#define YYPACT_NINF -273
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
722
723
#define yypact_value_is_default(Yystate) \
724
  (!!((Yystate) == (-273)))
725
726
#define YYTABLE_NINF -104
727
728
#define yytable_value_is_error(Yytable_value) \
729
  (!!((Yytable_value) == (-104)))
730
731
  /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
732
     STATE-NUM.  */
35 by Arnold D. Robbins
Move to gawk-3.1.7.
733
static const yytype_int16 yypact[] =
30 by Arnold D. Robbins
Move to gawk-3.1.2.
734
{
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
735
    -273,   376,  -273,  -273,   -27,   -21,  -273,  -273,  -273,  -273,
736
     157,  -273,  -273,    11,    11,    11,    -5,    -3,  -273,  -273,
737
    -273,  1019,  1019,  -273,  1019,  1065,   821,   116,  -273,   -20,
738
       1,  -273,  -273,    35,   758,   992,   252,   296,  -273,  -273,
739
    -273,  -273,   233,   789,   821,  -273,     2,  -273,  -273,  -273,
740
    -273,  -273,    63,    54,  -273,    69,  -273,  -273,  -273,   789,
741
     789,   127,    87,   115,    87,    87,  1019,   131,  -273,  -273,
742
      55,   295,    40,    47,  -273,    83,  -273,  -273,  -273,    35,
743
    -273,    83,  -273,   151,  -273,  -273,  1019,   132,  1019,  1019,
744
    1019,    83,  -273,  -273,  -273,  1019,   124,   252,  1019,  1019,
745
    1019,  1019,  1019,  1019,  1019,  1019,  1019,  1019,  1019,  1019,
746
    -273,  -273,  -273,  -273,   152,  1019,   100,    16,  1034,    37,
747
    -273,  -273,  -273,    43,  1019,  -273,   100,   100,   295,  -273,
748
    -273,  -273,  1019,    83,  -273,   137,   867,  -273,  -273,    75,
749
     -19,  -273,    77,   -19,    35,  -273,   596,  -273,  -273,   123,
750
    -273,   141,   175,  1098,  1019,   161,    11,   -26,   -26,    87,
751
      87,    87,    87,   -26,   -26,    87,    87,    87,    87,  -273,
752
    1034,  -273,  -273,  -273,  -273,   100,    65,   252,  -273,  -273,
753
    1034,  -273,   132,  -273,  1034,  -273,  -273,  -273,  -273,  -273,
754
     104,  -273,    26,   118,   119,    83,   121,   -19,   -19,  -273,
755
    -273,   -19,  1019,   -19,    83,  -273,  -273,   -19,  -273,  -273,
756
    1034,  -273,   117,    83,  1019,  1034,  -273,    83,  -273,   112,
757
    -273,  1019,  1019,  -273,   188,  1019,  1019,   710,   900,  -273,
758
    -273,  -273,   -19,  1034,  -273,  -273,  -273,   642,   596,    83,
759
    -273,  -273,  1034,  -273,  -273,  -273,   295,   -19,   -21,   126,
760
     295,   295,   169,   -13,  -273,   117,  -273,   821,   186,  -273,
761
    -273,  -273,    83,  -273,  -273,    13,  -273,  -273,  -273,    83,
762
      83,   139,   132,    83,    55,  -273,  -273,   710,  -273,  -273,
763
       1,   710,  1019,   100,   743,   137,  1019,   192,  -273,  -273,
764
     295,    83,   286,    83,   992,    83,    44,    83,   710,    83,
765
     946,   710,  -273,   247,   154,  -273,   156,  -273,  -273,   946,
766
     100,  -273,  -273,  -273,   226,   228,  -273,   154,  -273,    83,
767
    -273,   100,    83,  -273,  -273,    83,  -273,    83,   710,  -273,
768
     448,   710,  -273,   522,  -273
30 by Arnold D. Robbins
Move to gawk-3.1.2.
769
};
770
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
771
  /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
772
     Performed when YYTABLE does not specify something else to do.  Zero
773
     means the default is an error.  */
774
static const yytype_uint8 yydefact[] =
775
{
776
       2,     0,     1,     6,     0,   174,   156,   157,    21,    22,
777
       0,    23,    24,   163,     0,     0,     0,   151,     5,    87,
778
      36,     0,     0,    35,     0,     0,     0,     0,     3,     0,
779
       0,   146,    33,     4,    19,   117,   125,   126,   128,   152,
780
     160,   176,   153,     0,     0,   171,     0,   175,    27,    26,
781
      30,    31,     0,     0,    28,    91,   164,   154,   155,     0,
782
       0,     0,   159,   153,   158,   147,     0,   180,   153,   106,
783
       0,   104,     0,     0,   161,    89,   186,     7,     8,    40,
784
      37,    89,     9,     0,    88,   121,     0,     0,     0,     0,
785
       0,    89,   122,   124,   123,     0,     0,   127,     0,     0,
786
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
787
     119,   118,   136,   137,     0,     0,     0,     0,   104,     0,
788
     173,   172,    29,     0,     0,   135,     0,     0,     0,   178,
789
     179,   177,   107,    89,   183,     0,     0,   148,    14,     0,
790
       0,    17,     0,     0,    90,   181,     0,    41,    34,   113,
791
     114,   111,   112,     0,     0,   115,   163,   133,   134,   130,
792
     131,   132,   129,   144,   145,   141,   142,   143,   140,   120,
793
     110,   162,   170,    97,    95,     0,     0,    92,   149,   150,
794
     108,   188,     0,   109,   105,    13,    10,    16,    11,    39,
795
       0,    57,     0,     0,     0,    89,     0,     0,     0,    78,
796
      79,     0,   100,     0,    89,    38,    51,     0,    60,    44,
797
      65,    37,   184,    89,     0,    20,   139,    89,    98,     0,
798
     138,     0,   100,    62,     0,     0,     0,     0,    66,    52,
799
      53,    54,     0,   101,    55,   182,    59,     0,     0,    89,
800
     185,    42,   116,    32,    99,    96,     0,     0,   165,     0,
801
       0,     0,     0,   174,    67,     0,    56,     0,    82,    80,
802
      43,    25,    89,    58,    63,     0,   167,   169,    64,    89,
803
      89,     0,     0,    89,     0,    83,    61,     0,   166,   168,
804
       0,     0,     0,     0,     0,    81,     0,    85,    68,    46,
805
       0,    89,     0,    89,    84,    89,     0,    89,     0,    89,
806
      66,     0,    70,     0,     0,    69,     0,    47,    48,    66,
807
       0,    86,    73,    76,     0,     0,    77,     0,   187,    89,
808
      45,     0,    89,    75,    74,    89,    37,    89,     0,    37,
809
       0,     0,    50,     0,    49
810
};
811
812
  /* YYPGOTO[NTERM-NUM].  */
35 by Arnold D. Robbins
Move to gawk-3.1.7.
813
static const yytype_int16 yypgoto[] =
30 by Arnold D. Robbins
Move to gawk-3.1.2.
814
{
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
815
    -273,  -273,  -273,  -273,  -273,  -273,   208,  -273,  -273,  -273,
816
     -64,  -273,  -273,  -202,    71,   -58,  -273,  -273,  -218,  -273,
817
    -273,  -272,  -273,  -273,  -273,  -273,  -273,  -273,  -273,  -273,
818
      50,    76,  -273,  -273,  -273,    19,   -54,   -23,    -1,  -273,
819
    -273,  -273,   -44,    39,  -273,   224,  -273,   -11,    94,  -273,
820
    -273,    -7,   -38,  -273,  -273,   -73,    -2,  -273,   -28,  -231,
821
     -46,  -273,   -25,   -57,    85
30 by Arnold D. Robbins
Move to gawk-3.1.2.
822
};
823
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
824
  /* YYDEFGOTO[NTERM-NUM].  */
825
static const yytype_int16 yydefgoto[] =
826
{
827
      -1,     1,    28,   140,   143,    29,    77,    53,    54,    30,
828
      31,    83,    32,   146,    78,   205,   206,   222,   207,   237,
829
     248,   255,   296,   305,   317,   208,   258,   276,   286,   209,
830
     144,   145,   125,   175,   176,   232,   116,   117,   210,   115,
831
      94,    95,    35,    36,    37,    38,    39,    40,    55,   264,
832
     265,   266,    45,    46,    47,    41,    42,   131,   211,   212,
833
     137,   239,   213,   319,   136
834
};
835
836
  /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
837
     positive, shift that token.  If negative, reduce the rule whose
838
     number is the opposite.  If YYTABLE_NINF, syntax error.  */
35 by Arnold D. Robbins
Move to gawk-3.1.7.
839
static const yytype_int16 yytable[] =
30 by Arnold D. Robbins
Move to gawk-3.1.2.
840
{
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
841
      34,    80,    80,    70,    81,   126,   127,   260,   121,   238,
842
     254,    56,    57,    58,   150,     5,    74,   132,   120,    63,
843
      63,   119,    63,    68,   135,    71,  -103,   272,   310,   278,
844
     223,    19,    19,    63,   100,   101,   102,   321,   132,   103,
845
      43,   138,   118,   118,   173,   302,   139,   174,   141,    44,
846
      74,    33,    75,   142,    76,    76,   132,    44,   118,   118,
847
      62,    64,    59,    65,    60,   128,   218,  -103,   303,   304,
848
     171,   133,    44,    75,    97,   320,   185,    25,   187,    79,
849
     178,   179,   254,    44,  -103,   149,    84,   151,   152,   153,
850
    -103,   254,   133,   224,   155,    19,    63,    63,    63,    63,
851
      63,    63,    63,    63,    63,    63,    63,    63,   172,   220,
852
     133,   -93,   122,   244,   170,    81,   245,   -89,    81,     4,
853
     133,   123,    63,   134,   330,   124,   -12,   333,   -15,   217,
854
       4,   180,    85,   -94,    19,   184,     5,   157,   158,   159,
855
     160,   161,   162,   163,   164,   165,   166,   167,   168,   -12,
856
      85,   -15,   103,   215,    56,    86,   148,   147,   112,   113,
857
      48,    49,   156,   177,    72,   169,    73,   154,   134,   252,
858
    -104,   221,    81,    81,   129,   130,    81,   182,    81,    92,
859
      93,    87,    81,   259,    85,   225,   226,   240,   228,    86,
860
      79,    76,   249,    79,   268,   271,   275,    92,    93,   283,
861
     262,   233,    50,    51,   269,   270,   282,    81,   318,   181,
862
     267,   186,   295,   242,   188,    87,    88,  -104,  -104,   287,
863
     246,   233,    81,   289,   250,   251,    52,   267,   285,   204,
864
     273,    92,    93,   323,   274,   324,   118,   291,    82,   316,
865
     308,   247,   294,   311,   297,   110,   111,    79,    79,    67,
866
     216,    79,   288,    79,   312,   313,    71,    79,   279,   293,
867
     325,   219,     0,     0,   322,     0,     0,   299,   229,   230,
868
     332,   227,   231,   334,   234,   327,   112,   113,   236,     0,
869
     235,   290,    79,   292,    63,   114,     0,     0,     0,   241,
870
       0,     0,    63,   243,     0,    85,     0,    79,     0,    20,
871
      86,     0,     0,   256,    85,   314,   315,     0,    23,    86,
872
      98,    99,   100,   101,   102,   261,     0,   103,   263,     0,
873
       0,     0,     0,     0,     0,     0,    87,    88,    89,     0,
874
       0,     0,     0,    97,     0,    87,    88,    89,   277,    90,
875
       0,     0,    92,    93,     0,   280,   281,     0,    90,   284,
876
       0,    92,    93,     0,   104,   105,   106,   107,   108,     0,
877
      76,   109,     0,   134,     0,     0,     0,   298,     0,   300,
878
       0,   301,   306,   307,     0,   309,     2,     3,     0,     4,
879
       5,     0,     0,     6,     7,     0,     0,     0,     0,     0,
880
       0,     0,     0,     8,     9,   326,     0,     0,   328,     0,
881
       0,   329,     0,   331,     0,     0,     0,     0,     0,     0,
882
       0,    10,    11,    12,    13,     0,     0,     0,     0,    14,
883
      15,    16,    17,    18,     0,     0,     0,    19,    20,     0,
884
       0,     0,     0,     0,    21,    22,     0,    23,     0,    24,
885
       0,     0,    25,    26,     0,    27,     0,     0,   -18,   189,
886
     -18,     4,     5,     0,     0,     6,     7,     0,     0,     0,
887
       0,     0,     0,     0,     0,     0,     0,   190,     0,   191,
888
     192,   193,   -72,   -72,   194,   195,   196,   197,   198,   199,
889
     200,   201,   202,     0,     0,     0,    13,   203,     0,     0,
890
       0,    14,    15,    16,    17,     0,     0,     0,     0,   -72,
891
      20,     0,     0,     0,     0,     0,    21,    22,     0,    23,
892
       0,    24,     0,     0,    25,    26,     0,    61,     0,     0,
893
      75,   -72,    76,   189,     0,     4,     5,     0,     0,     6,
894
       7,     0,     0,     0,     0,     0,     0,     0,     0,     0,
895
       0,   190,     0,   191,   192,   193,   -71,   -71,   194,   195,
896
     196,   197,   198,   199,   200,   201,   202,     0,     0,     0,
897
      13,   203,     0,     0,     0,    14,    15,    16,    17,     0,
898
       0,     0,     0,   -71,    20,     0,     0,     0,     0,     0,
899
      21,    22,     0,    23,     0,    24,     0,     0,    25,    26,
900
       0,    61,     0,     0,    75,   -71,    76,   189,     0,     4,
901
       5,     0,     0,     6,     7,     0,     0,     0,     0,     0,
902
       0,     0,     0,     0,     0,   190,     0,   191,   192,   193,
903
       0,     0,   194,   195,   196,   197,   198,   199,   200,   201,
904
     202,     0,     0,     0,    13,   203,     0,     0,     0,    14,
905
      15,    16,    17,    69,     0,     4,     5,     0,    20,     6,
906
       7,     0,  -102,     0,    21,    22,     0,    23,     0,    24,
907
       0,     0,    25,    26,     0,    61,     0,     0,    75,   204,
908
      76,     0,     0,     0,     0,     0,     0,     0,     0,     0,
909
      13,     0,     0,     0,     0,    14,    15,    16,    17,     0,
910
       0,     0,     0,  -102,    20,     0,     0,     0,     0,     0,
911
      21,    22,     0,    23,     0,    24,     0,     0,    25,   257,
912
    -102,    61,     0,     4,     5,     0,  -102,     6,     7,     0,
913
       0,     0,     0,     0,     0,     0,     0,     0,     0,   190,
914
       0,   191,   192,   193,     0,     0,   194,   195,   196,   197,
915
     198,   199,   200,   201,   202,     0,     4,     5,    13,   203,
916
       6,     7,     0,    14,    15,    16,    17,     0,     0,     0,
917
       0,     0,    20,     0,     0,     0,     0,    85,    21,    22,
918
       0,    23,    86,    24,     0,     0,    25,    26,     0,    61,
919
       0,    13,    75,     0,    76,     0,    14,    15,    16,    17,
920
      69,     0,     4,     5,     0,    20,     6,     7,    87,    88,
921
      89,    21,    22,     0,    23,     0,    24,     0,     0,    25,
922
      26,    90,    61,    91,    92,    93,     0,    76,     0,     0,
923
       0,     0,    69,     0,     4,     5,     0,    13,     6,     7,
924
       0,     0,    14,    15,    16,    17,     0,     0,     0,     0,
925
       0,    20,     0,     0,     0,     0,     0,    21,    22,     0,
926
      23,     0,    24,     0,     0,    25,    26,  -102,    61,    13,
927
       0,     0,     0,     0,    14,    15,    16,    17,   183,     0,
928
       4,     5,     0,    20,     6,     7,     0,     0,     0,    21,
929
      22,     0,    23,     0,    24,     0,     0,    25,    26,     0,
930
      61,     0,     0,     0,     0,     0,     0,     0,     0,     0,
931
       0,     0,     0,     4,   253,    13,     0,     6,     7,     0,
932
      14,    15,    16,    17,     0,     0,     0,     0,     0,    20,
933
       0,     0,   192,     0,     0,    21,    22,     0,    23,     0,
934
      24,   199,   200,    25,    26,     0,    61,     0,    13,     0,
935
       0,     0,     0,    14,    15,    16,    17,     0,     0,     4,
936
       5,     0,    20,     6,     7,     0,     0,     0,    21,    22,
937
       0,    23,     0,    24,     0,     0,    25,    26,   192,    61,
938
       0,     0,     0,     0,     0,     0,     0,   199,   200,     0,
939
       0,     0,     0,     0,    13,     0,     0,     0,     0,    14,
940
      15,    16,    17,     0,     0,     4,     5,     0,    20,     6,
941
       7,     0,     0,    96,    21,    22,     0,    23,     0,    24,
942
       0,     0,    25,    26,     0,    61,     0,     0,     0,     0,
943
       0,     0,     4,     5,     0,     0,     6,     7,     0,     0,
944
      13,     0,     0,     0,     0,    14,    15,    16,    17,     0,
945
       0,     0,     0,    85,    20,     0,     0,     0,    86,     0,
946
      21,    22,     0,    23,     0,    24,     0,    13,    25,    26,
947
       0,    61,    14,    15,    16,    17,     0,     0,     4,     5,
948
       0,    20,     6,     7,    87,    88,    89,    21,    22,     0,
949
      23,     0,    24,     0,     0,    25,    26,    90,    61,     0,
950
      92,    93,     0,     0,     0,     0,     0,     0,     0,     0,
951
       0,     0,     0,     0,     0,     0,     0,    85,    14,    15,
952
      16,    17,    86,     0,     0,     0,     0,    20,     0,     0,
281.1.1 by john haque
Speed/memory performance improvements.
953
       0,     0,     0,    21,    22,     0,    23,     0,    24,     0,
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
954
       0,    25,    66,     0,    61,     0,     0,     0,    87,    88,
955
      89,     0,     0,     0,     0,     0,     0,     0,     0,     0,
956
       0,    90,   214,     0,    92,    93
30 by Arnold D. Robbins
Move to gawk-3.1.2.
957
};
958
35 by Arnold D. Robbins
Move to gawk-3.1.7.
959
static const yytype_int16 yycheck[] =
30 by Arnold D. Robbins
Move to gawk-3.1.2.
960
{
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
961
       1,    29,    30,    26,    29,    59,    60,   238,    46,   211,
962
     228,    13,    14,    15,    87,     4,    27,     1,    16,    21,
963
      22,    44,    24,    25,    70,    26,    10,    40,   300,    16,
964
       4,    51,    51,    35,    60,    61,    62,   309,     1,    65,
965
      67,     1,    43,    44,     1,     1,     6,     4,     1,    70,
966
      61,     1,    72,     6,    74,    74,     1,    70,    59,    60,
967
      21,    22,    67,    24,    67,    66,     1,    51,    24,    25,
968
     116,    55,    70,    72,    35,   306,     1,    66,     1,    29,
969
     126,   127,   300,    70,    68,    86,    51,    88,    89,    90,
970
      74,   309,    55,    67,    95,    51,    98,    99,   100,   101,
971
     102,   103,   104,   105,   106,   107,   108,   109,    71,   182,
972
      55,    68,    49,     1,   115,   140,     4,    73,   143,     3,
973
      55,    67,   124,    68,   326,    56,    51,   329,    51,   175,
974
       3,   132,     9,    68,    51,   136,     4,    98,    99,   100,
975
     101,   102,   103,   104,   105,   106,   107,   108,   109,    74,
976
       9,    74,    65,   154,   156,    14,     5,    81,    43,    44,
977
       3,     4,    38,   124,    48,    13,    50,    91,    68,   227,
978
       9,    67,   197,   198,    43,    44,   201,    40,   203,    56,
979
      57,    40,   207,   237,     9,    67,    67,   212,    67,    14,
980
     140,    74,     4,   143,    68,    26,    10,    56,    57,   272,
981
     246,   202,    45,    46,   250,   251,    67,   232,    54,   133,
982
     248,   140,    20,   214,   143,    40,    41,    56,    57,   277,
983
     221,   222,   247,   281,   225,   226,    69,   265,   274,    73,
984
     255,    56,    57,     7,   257,     7,   237,   283,    30,   303,
985
     298,   222,   286,   301,   290,    12,    13,   197,   198,    25,
986
     156,   201,   280,   203,     7,     8,   257,   207,   265,   284,
987
     317,   176,    -1,    -1,   310,    -1,    -1,   292,   197,   198,
988
     328,   195,   201,   331,   203,   321,    43,    44,   207,    -1,
989
     204,   282,   232,   284,   286,    52,    -1,    -1,    -1,   213,
990
      -1,    -1,   294,   217,    -1,     9,    -1,   247,    -1,    52,
991
      14,    -1,    -1,   232,     9,    58,    59,    -1,    61,    14,
992
      58,    59,    60,    61,    62,   239,    -1,    65,   247,    -1,
993
      -1,    -1,    -1,    -1,    -1,    -1,    40,    41,    42,    -1,
994
      -1,    -1,    -1,   294,    -1,    40,    41,    42,   262,    53,
995
      -1,    -1,    56,    57,    -1,   269,   270,    -1,    53,   273,
996
      -1,    56,    57,    -1,    58,    59,    60,    61,    62,    -1,
997
      74,    65,    -1,    68,    -1,    -1,    -1,   291,    -1,   293,
998
      -1,   295,   296,   297,    -1,   299,     0,     1,    -1,     3,
999
       4,    -1,    -1,     7,     8,    -1,    -1,    -1,    -1,    -1,
1000
      -1,    -1,    -1,    17,    18,   319,    -1,    -1,   322,    -1,
1001
      -1,   325,    -1,   327,    -1,    -1,    -1,    -1,    -1,    -1,
1002
      -1,    35,    36,    37,    38,    -1,    -1,    -1,    -1,    43,
1003
      44,    45,    46,    47,    -1,    -1,    -1,    51,    52,    -1,
1004
      -1,    -1,    -1,    -1,    58,    59,    -1,    61,    -1,    63,
1005
      -1,    -1,    66,    67,    -1,    69,    -1,    -1,    72,     1,
1006
      74,     3,     4,    -1,    -1,     7,     8,    -1,    -1,    -1,
281.1.1 by john haque
Speed/memory performance improvements.
1007
      -1,    -1,    -1,    -1,    -1,    -1,    -1,    19,    -1,    21,
1008
      22,    23,    24,    25,    26,    27,    28,    29,    30,    31,
1009
      32,    33,    34,    -1,    -1,    -1,    38,    39,    -1,    -1,
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
1010
      -1,    43,    44,    45,    46,    -1,    -1,    -1,    -1,    51,
1011
      52,    -1,    -1,    -1,    -1,    -1,    58,    59,    -1,    61,
1012
      -1,    63,    -1,    -1,    66,    67,    -1,    69,    -1,    -1,
1013
      72,    73,    74,     1,    -1,     3,     4,    -1,    -1,     7,
1014
       8,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
1015
      -1,    19,    -1,    21,    22,    23,    24,    25,    26,    27,
1016
      28,    29,    30,    31,    32,    33,    34,    -1,    -1,    -1,
1017
      38,    39,    -1,    -1,    -1,    43,    44,    45,    46,    -1,
1018
      -1,    -1,    -1,    51,    52,    -1,    -1,    -1,    -1,    -1,
1019
      58,    59,    -1,    61,    -1,    63,    -1,    -1,    66,    67,
1020
      -1,    69,    -1,    -1,    72,    73,    74,     1,    -1,     3,
116 by Arnold D. Robbins
Fix switch debugging.
1021
       4,    -1,    -1,     7,     8,    -1,    -1,    -1,    -1,    -1,
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
1022
      -1,    -1,    -1,    -1,    -1,    19,    -1,    21,    22,    23,
1023
      -1,    -1,    26,    27,    28,    29,    30,    31,    32,    33,
1024
      34,    -1,    -1,    -1,    38,    39,    -1,    -1,    -1,    43,
1025
      44,    45,    46,     1,    -1,     3,     4,    -1,    52,     7,
1026
       8,    -1,    10,    -1,    58,    59,    -1,    61,    -1,    63,
1027
      -1,    -1,    66,    67,    -1,    69,    -1,    -1,    72,    73,
1028
      74,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
1029
      38,    -1,    -1,    -1,    -1,    43,    44,    45,    46,    -1,
1030
      -1,    -1,    -1,    51,    52,    -1,    -1,    -1,    -1,    -1,
1031
      58,    59,    -1,    61,    -1,    63,    -1,    -1,    66,    67,
1032
      68,    69,    -1,     3,     4,    -1,    74,     7,     8,    -1,
1033
      -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    19,
1034
      -1,    21,    22,    23,    -1,    -1,    26,    27,    28,    29,
1035
      30,    31,    32,    33,    34,    -1,     3,     4,    38,    39,
1036
       7,     8,    -1,    43,    44,    45,    46,    -1,    -1,    -1,
1037
      -1,    -1,    52,    -1,    -1,    -1,    -1,     9,    58,    59,
1038
      -1,    61,    14,    63,    -1,    -1,    66,    67,    -1,    69,
1039
      -1,    38,    72,    -1,    74,    -1,    43,    44,    45,    46,
1040
       1,    -1,     3,     4,    -1,    52,     7,     8,    40,    41,
1041
      42,    58,    59,    -1,    61,    -1,    63,    -1,    -1,    66,
1042
      67,    53,    69,    55,    56,    57,    -1,    74,    -1,    -1,
1043
      -1,    -1,     1,    -1,     3,     4,    -1,    38,     7,     8,
1044
      -1,    -1,    43,    44,    45,    46,    -1,    -1,    -1,    -1,
1045
      -1,    52,    -1,    -1,    -1,    -1,    -1,    58,    59,    -1,
1046
      61,    -1,    63,    -1,    -1,    66,    67,    68,    69,    38,
1047
      -1,    -1,    -1,    -1,    43,    44,    45,    46,     1,    -1,
1048
       3,     4,    -1,    52,     7,     8,    -1,    -1,    -1,    58,
1049
      59,    -1,    61,    -1,    63,    -1,    -1,    66,    67,    -1,
1050
      69,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
1051
      -1,    -1,    -1,     3,     4,    38,    -1,     7,     8,    -1,
1052
      43,    44,    45,    46,    -1,    -1,    -1,    -1,    -1,    52,
1053
      -1,    -1,    22,    -1,    -1,    58,    59,    -1,    61,    -1,
1054
      63,    31,    32,    66,    67,    -1,    69,    -1,    38,    -1,
1055
      -1,    -1,    -1,    43,    44,    45,    46,    -1,    -1,     3,
1056
       4,    -1,    52,     7,     8,    -1,    -1,    -1,    58,    59,
1057
      -1,    61,    -1,    63,    -1,    -1,    66,    67,    22,    69,
1058
      -1,    -1,    -1,    -1,    -1,    -1,    -1,    31,    32,    -1,
1059
      -1,    -1,    -1,    -1,    38,    -1,    -1,    -1,    -1,    43,
1060
      44,    45,    46,    -1,    -1,     3,     4,    -1,    52,     7,
1061
       8,    -1,    -1,    11,    58,    59,    -1,    61,    -1,    63,
1062
      -1,    -1,    66,    67,    -1,    69,    -1,    -1,    -1,    -1,
1063
      -1,    -1,     3,     4,    -1,    -1,     7,     8,    -1,    -1,
1064
      38,    -1,    -1,    -1,    -1,    43,    44,    45,    46,    -1,
1065
      -1,    -1,    -1,     9,    52,    -1,    -1,    -1,    14,    -1,
1066
      58,    59,    -1,    61,    -1,    63,    -1,    38,    66,    67,
1067
      -1,    69,    43,    44,    45,    46,    -1,    -1,     3,     4,
1068
      -1,    52,     7,     8,    40,    41,    42,    58,    59,    -1,
1069
      61,    -1,    63,    -1,    -1,    66,    67,    53,    69,    -1,
1070
      56,    57,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
281.1.1 by john haque
Speed/memory performance improvements.
1071
      -1,    -1,    -1,    -1,    -1,    -1,    -1,     9,    43,    44,
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
1072
      45,    46,    14,    -1,    -1,    -1,    -1,    52,    -1,    -1,
1073
      -1,    -1,    -1,    58,    59,    -1,    61,    -1,    63,    -1,
1074
      -1,    66,    67,    -1,    69,    -1,    -1,    -1,    40,    41,
1075
      42,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
1076
      -1,    53,    54,    -1,    56,    57
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1077
};
1078
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1079
  /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
1080
     symbol of state STATE-NUM.  */
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1081
static const yytype_uint8 yystos[] =
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1082
{
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
1083
       0,    76,     0,     1,     3,     4,     7,     8,    17,    18,
1084
      35,    36,    37,    38,    43,    44,    45,    46,    47,    51,
1085
      52,    58,    59,    61,    63,    66,    67,    69,    77,    80,
1086
      84,    85,    87,   105,   113,   117,   118,   119,   120,   121,
1087
     122,   130,   131,    67,    70,   127,   128,   129,     3,     4,
1088
      45,    46,    69,    82,    83,   123,   131,   131,   131,    67,
1089
      67,    69,   118,   131,   118,   118,    67,   120,   131,     1,
1090
     112,   113,    48,    50,   122,    72,    74,    81,    89,   105,
1091
     133,   137,    81,    86,    51,     9,    14,    40,    41,    42,
1092
      53,    55,    56,    57,   115,   116,    11,   118,    58,    59,
1093
      60,    61,    62,    65,    58,    59,    60,    61,    62,    65,
1094
      12,    13,    43,    44,    52,   114,   111,   112,   113,   112,
1095
      16,   127,    49,    67,    56,   107,   111,   111,   113,    43,
1096
      44,   132,     1,    55,    68,   135,   139,   135,     1,     6,
1097
      78,     1,     6,    79,   105,   106,    88,   106,     5,   113,
1098
     130,   113,   113,   113,   106,   113,    38,   118,   118,   118,
1099
     118,   118,   118,   118,   118,   118,   118,   118,   118,    13,
1100
     113,   135,    71,     1,     4,   108,   109,   118,   135,   135,
1101
     113,   106,    40,     1,   113,     1,    89,     1,    89,     1,
1102
      19,    21,    22,    23,    26,    27,    28,    29,    30,    31,
1103
      32,    33,    34,    39,    73,    90,    91,    93,   100,   104,
1104
     113,   133,   134,   137,    54,   113,   123,   135,     1,   139,
1105
     130,    67,    92,     4,    67,    67,    67,   106,    67,    89,
1106
      89,    89,   110,   113,    89,   106,    89,    94,    88,   136,
1107
     137,   106,   113,   106,     1,     4,   113,   110,    95,     4,
1108
     113,   113,    90,     4,    93,    96,    89,    67,   101,   111,
1109
     134,   106,   135,    89,   124,   125,   126,   127,    68,   135,
1110
     135,    26,    40,   137,   112,    10,   102,   106,    16,   126,
1111
     106,   106,    67,   130,   106,   135,   103,    90,   133,    90,
1112
     113,   135,   113,   137,   117,    20,    97,   135,   106,   137,
1113
     106,   106,     1,    24,    25,    98,   106,   106,    90,   106,
1114
      96,    90,     7,     8,    58,    59,    85,    99,    54,   138,
1115
     134,    96,   135,     7,     7,   138,   106,   135,   106,   106,
1116
      88,   106,    90,    88,    90
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1117
};
1118
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1119
  /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
1120
static const yytype_uint8 yyr1[] =
1121
{
1122
       0,    75,    76,    76,    76,    76,    76,    77,    77,    77,
1123
      77,    77,    78,    78,    78,    79,    79,    79,    80,    80,
1124
      80,    80,    80,    80,    80,    81,    82,    82,    82,    82,
1125
      83,    83,    84,    86,    85,    87,    87,    88,    88,    88,
1126
      89,    89,    90,    90,    90,    90,    90,    90,    90,    90,
1127
      90,    90,    91,    91,    91,    91,    91,    92,    91,    91,
1128
      94,    93,    95,    93,    93,    93,    96,    96,    97,    97,
1129
      97,    98,    98,    99,    99,    99,    99,    99,   100,   100,
1130
     101,   101,   102,   103,   102,   104,   104,   105,   105,   106,
1131
     106,   107,   107,   108,   108,   109,   109,   109,   109,   109,
1132
     110,   110,   111,   111,   112,   112,   112,   112,   112,   112,
1133
     113,   113,   113,   113,   113,   113,   113,   113,   114,   114,
1134
     114,   115,   115,   116,   116,   117,   117,   117,   118,   118,
1135
     118,   118,   118,   118,   118,   118,   118,   118,   118,   119,
1136
     119,   119,   119,   119,   119,   119,   120,   120,   120,   120,
1137
     120,   120,   120,   120,   120,   120,   120,   120,   120,   120,
1138
     121,   121,   122,   123,   123,   124,   124,   125,   125,   126,
1139
     127,   128,   128,   129,   130,   130,   131,   131,   132,   132,
1140
     132,   133,   134,   135,   136,   136,   137,   138,   139
1141
};
1142
1143
  /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.  */
1144
static const yytype_uint8 yyr2[] =
1145
{
1146
       0,     2,     0,     2,     2,     2,     2,     2,     2,     2,
1147
       4,     4,     1,     2,     1,     1,     2,     1,     0,     1,
1148
       4,     1,     1,     1,     1,     5,     1,     1,     1,     2,
1149
       1,     1,     6,     0,     3,     1,     1,     0,     2,     2,
1150
       1,     2,     2,     3,     1,     9,     6,     8,     8,    12,
1151
      11,     1,     2,     2,     2,     2,     3,     0,     4,     2,
1152
       0,     4,     0,     4,     4,     1,     0,     1,     0,     2,
1153
       2,     5,     4,     1,     2,     2,     1,     1,     1,     1,
1154
       1,     3,     0,     0,     3,     6,     9,     1,     2,     0,
1155
       1,     0,     2,     0,     1,     1,     3,     1,     2,     3,
1156
       0,     1,     0,     1,     1,     3,     1,     2,     3,     3,
1157
       3,     3,     3,     3,     3,     3,     5,     1,     1,     1,
1158
       2,     1,     1,     1,     1,     1,     1,     2,     1,     3,
1159
       3,     3,     3,     3,     3,     3,     2,     2,     5,     4,
1160
       3,     3,     3,     3,     3,     3,     1,     2,     3,     4,
1161
       4,     1,     1,     1,     2,     2,     1,     1,     2,     2,
1162
       1,     2,     4,     0,     1,     0,     2,     1,     2,     1,
1163
       3,     1,     2,     2,     1,     2,     1,     3,     1,     1,
1164
       0,     2,     2,     1,     0,     1,     1,     1,     2
1165
};
1166
1167
1168
#define yyerrok         (yyerrstatus = 0)
1169
#define yyclearin       (yychar = YYEMPTY)
1170
#define YYEMPTY         (-2)
1171
#define YYEOF           0
1172
1173
#define YYACCEPT        goto yyacceptlab
1174
#define YYABORT         goto yyabortlab
1175
#define YYERROR         goto yyerrorlab
1176
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1177
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1178
#define YYRECOVERING()  (!!yyerrstatus)
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1179
319.1.18 by Arnold D. Robbins
Update infrastructure.
1180
#define YYBACKUP(Token, Value)                                  \
1181
do                                                              \
1182
  if (yychar == YYEMPTY)                                        \
1183
    {                                                           \
1184
      yychar = (Token);                                         \
1185
      yylval = (Value);                                         \
1186
      YYPOPSTACK (yylen);                                       \
1187
      yystate = *yyssp;                                         \
1188
      goto yybackup;                                            \
1189
    }                                                           \
1190
  else                                                          \
1191
    {                                                           \
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1192
      yyerror (YY_("syntax error: cannot back up")); \
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1193
      YYERROR;                                                  \
1194
    }                                                           \
1195
while (0)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1196
277.1.176 by Arnold D. Robbins
Update to bison 2.6.5.
1197
/* Error token number */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1198
#define YYTERROR        1
1199
#define YYERRCODE       256
1200
1201
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1202
1203
/* Enable debugging if requested.  */
1204
#if YYDEBUG
1205
1206
# ifndef YYFPRINTF
1207
#  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1208
#  define YYFPRINTF fprintf
1209
# endif
1210
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1211
# define YYDPRINTF(Args)                        \
1212
do {                                            \
1213
  if (yydebug)                                  \
1214
    YYFPRINTF Args;                             \
1215
} while (0)
1216
1217
/* This macro is provided for backward compatibility. */
1218
#ifndef YY_LOCATION_PRINT
1219
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1220
#endif
1221
1222
1223
# define YY_SYMBOL_PRINT(Title, Type, Value, Location)                    \
1224
do {                                                                      \
1225
  if (yydebug)                                                            \
1226
    {                                                                     \
1227
      YYFPRINTF (stderr, "%s ", Title);                                   \
1228
      yy_symbol_print (stderr,                                            \
1229
                  Type, Value); \
1230
      YYFPRINTF (stderr, "\n");                                           \
1231
    }                                                                     \
1232
} while (0)
1233
1234
1235
/*----------------------------------------.
1236
| Print this symbol's value on YYOUTPUT.  |
1237
`----------------------------------------*/
1238
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1239
static void
1240
yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
1241
{
319.1.18 by Arnold D. Robbins
Update infrastructure.
1242
  FILE *yyo = yyoutput;
1243
  YYUSE (yyo);
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1244
  if (!yyvaluep)
1245
    return;
1246
# ifdef YYPRINT
1247
  if (yytype < YYNTOKENS)
1248
    YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1249
# endif
408.2.32 by Arnold D. Robbins
Regenerate awkgram.c with latest bison.
1250
  YYUSE (yytype);
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1251
}
1252
1253
1254
/*--------------------------------.
1255
| Print this symbol on YYOUTPUT.  |
1256
`--------------------------------*/
1257
1258
static void
1259
yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
1260
{
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1261
  YYFPRINTF (yyoutput, "%s %s (",
1262
             yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1263
1264
  yy_symbol_value_print (yyoutput, yytype, yyvaluep);
1265
  YYFPRINTF (yyoutput, ")");
1266
}
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1267
1268
/*------------------------------------------------------------------.
1269
| yy_stack_print -- Print the state stack from its BOTTOM up to its |
33 by Arnold D. Robbins
Move to gawk 3.1.5.
1270
| TOP (included).                                                   |
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1271
`------------------------------------------------------------------*/
1272
1273
static void
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1274
yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1275
{
1276
  YYFPRINTF (stderr, "Stack now");
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1277
  for (; yybottom <= yytop; yybottom++)
1278
    {
1279
      int yybot = *yybottom;
1280
      YYFPRINTF (stderr, " %d", yybot);
1281
    }
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1282
  YYFPRINTF (stderr, "\n");
1283
}
1284
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1285
# define YY_STACK_PRINT(Bottom, Top)                            \
1286
do {                                                            \
1287
  if (yydebug)                                                  \
1288
    yy_stack_print ((Bottom), (Top));                           \
1289
} while (0)
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1290
1291
1292
/*------------------------------------------------.
1293
| Report that the YYRULE is going to be reduced.  |
1294
`------------------------------------------------*/
1295
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1296
static void
1297
yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1298
{
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1299
  unsigned long int yylno = yyrline[yyrule];
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1300
  int yynrhs = yyr2[yyrule];
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1301
  int yyi;
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1302
  YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1303
             yyrule - 1, yylno);
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1304
  /* The symbols being reduced.  */
1305
  for (yyi = 0; yyi < yynrhs; yyi++)
1306
    {
1307
      YYFPRINTF (stderr, "   $%d = ", yyi + 1);
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1308
      yy_symbol_print (stderr,
1309
                       yystos[yyssp[yyi + 1 - yynrhs]],
1310
                       &(yyvsp[(yyi + 1) - (yynrhs)])
1311
                                              );
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1312
      YYFPRINTF (stderr, "\n");
1313
    }
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1314
}
1315
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1316
# define YY_REDUCE_PRINT(Rule)          \
1317
do {                                    \
1318
  if (yydebug)                          \
1319
    yy_reduce_print (yyssp, yyvsp, Rule); \
1320
} while (0)
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1321
1322
/* Nonzero means print parse trace.  It is left uninitialized so that
1323
   multiple parsers can coexist.  */
1324
int yydebug;
1325
#else /* !YYDEBUG */
1326
# define YYDPRINTF(Args)
33 by Arnold D. Robbins
Move to gawk 3.1.5.
1327
# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1328
# define YY_STACK_PRINT(Bottom, Top)
1329
# define YY_REDUCE_PRINT(Rule)
1330
#endif /* !YYDEBUG */
1331
1332
1333
/* YYINITDEPTH -- initial size of the parser's stacks.  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1334
#ifndef YYINITDEPTH
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1335
# define YYINITDEPTH 200
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1336
#endif
1337
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1338
/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1339
   if the built-in stack extension method is used).
1340
1341
   Do not make this value too large; the results are undefined if
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1342
   YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1343
   evaluated with infinite-precision integer arithmetic.  */
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1344
1345
#ifndef YYMAXDEPTH
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1346
# define YYMAXDEPTH 10000
1347
#endif
1348
1349
1350
#if YYERROR_VERBOSE
1351
1352
# ifndef yystrlen
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1353
#  if defined __GLIBC__ && defined _STRING_H
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1354
#   define yystrlen strlen
1355
#  else
1356
/* Return the length of YYSTR.  */
1357
static YYSIZE_T
1358
yystrlen (const char *yystr)
1359
{
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1360
  YYSIZE_T yylen;
1361
  for (yylen = 0; yystr[yylen]; yylen++)
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1362
    continue;
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1363
  return yylen;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1364
}
1365
#  endif
1366
# endif
1367
1368
# ifndef yystpcpy
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1369
#  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1370
#   define yystpcpy stpcpy
1371
#  else
1372
/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1373
   YYDEST.  */
1374
static char *
1375
yystpcpy (char *yydest, const char *yysrc)
1376
{
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1377
  char *yyd = yydest;
1378
  const char *yys = yysrc;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1379
1380
  while ((*yyd++ = *yys++) != '\0')
1381
    continue;
1382
1383
  return yyd - 1;
1384
}
1385
#  endif
1386
# endif
1387
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1388
# ifndef yytnamerr
1389
/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1390
   quotes and backslashes, so that it's suitable for yyerror.  The
1391
   heuristic is that double-quoting is unnecessary unless the string
1392
   contains an apostrophe, a comma, or backslash (other than
1393
   backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
1394
   null, do not copy; instead, return the length of what the result
1395
   would have been.  */
1396
static YYSIZE_T
1397
yytnamerr (char *yyres, const char *yystr)
1398
{
1399
  if (*yystr == '"')
1400
    {
1401
      YYSIZE_T yyn = 0;
1402
      char const *yyp = yystr;
1403
1404
      for (;;)
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1405
        switch (*++yyp)
1406
          {
1407
          case '\'':
1408
          case ',':
1409
            goto do_not_strip_quotes;
1410
1411
          case '\\':
1412
            if (*++yyp != '\\')
1413
              goto do_not_strip_quotes;
1414
            /* Fall through.  */
1415
          default:
1416
            if (yyres)
1417
              yyres[yyn] = *yyp;
1418
            yyn++;
1419
            break;
1420
1421
          case '"':
1422
            if (yyres)
1423
              yyres[yyn] = '\0';
1424
            return yyn;
1425
          }
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1426
    do_not_strip_quotes: ;
1427
    }
1428
1429
  if (! yyres)
1430
    return yystrlen (yystr);
1431
1432
  return yystpcpy (yyres, yystr) - yyres;
1433
}
1434
# endif
1435
228 by Arnold D. Robbins
Update to bison 2.5.
1436
/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1437
   about the unexpected token YYTOKEN for the state stack whose top is
1438
   YYSSP.
1439
1440
   Return 0 if *YYMSG was successfully written.  Return 1 if *YYMSG is
1441
   not large enough to hold the message.  In that case, also set
1442
   *YYMSG_ALLOC to the required number of bytes.  Return 2 if the
1443
   required number of bytes is too large to store.  */
1444
static int
1445
yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1446
                yytype_int16 *yyssp, int yytoken)
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1447
{
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1448
  YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
228 by Arnold D. Robbins
Update to bison 2.5.
1449
  YYSIZE_T yysize = yysize0;
1450
  enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1451
  /* Internationalized format string. */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1452
  const char *yyformat = YY_NULLPTR;
228 by Arnold D. Robbins
Update to bison 2.5.
1453
  /* Arguments of yyformat. */
1454
  char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1455
  /* Number of reported tokens (one for the "unexpected", one per
1456
     "expected"). */
1457
  int yycount = 0;
1458
1459
  /* There are many possibilities here to consider:
1460
     - If this state is a consistent state with a default action, then
1461
       the only way this function was invoked is if the default action
1462
       is an error action.  In that case, don't check for expected
1463
       tokens because there are none.
1464
     - The only way there can be no lookahead present (in yychar) is if
1465
       this state is a consistent state with a default action.  Thus,
1466
       detecting the absence of a lookahead is sufficient to determine
1467
       that there is no unexpected or expected token to report.  In that
1468
       case, just report a simple "syntax error".
1469
     - Don't assume there isn't a lookahead just because this state is a
1470
       consistent state with a default action.  There might have been a
1471
       previous inconsistent state, consistent state with a non-default
1472
       action, or user semantic action that manipulated yychar.
1473
     - Of course, the expected token list depends on states to have
1474
       correct lookahead information, and it depends on the parser not
1475
       to perform extra reductions after fetching a lookahead from the
1476
       scanner and before detecting a syntax error.  Thus, state merging
1477
       (from LALR or IELR) and default reductions corrupt the expected
1478
       token list.  However, the list is correct for canonical LR with
1479
       one exception: it will still contain any token that will not be
1480
       accepted due to an error action in a later state.
1481
  */
1482
  if (yytoken != YYEMPTY)
1483
    {
1484
      int yyn = yypact[*yyssp];
1485
      yyarg[yycount++] = yytname[yytoken];
1486
      if (!yypact_value_is_default (yyn))
1487
        {
1488
          /* Start YYX at -YYN if negative to avoid negative indexes in
1489
             YYCHECK.  In other words, skip the first -YYN actions for
1490
             this state because they are default actions.  */
1491
          int yyxbegin = yyn < 0 ? -yyn : 0;
1492
          /* Stay within bounds of both yycheck and yytname.  */
1493
          int yychecklim = YYLAST - yyn + 1;
1494
          int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1495
          int yyx;
1496
1497
          for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1498
            if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1499
                && !yytable_value_is_error (yytable[yyx + yyn]))
1500
              {
1501
                if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1502
                  {
1503
                    yycount = 1;
1504
                    yysize = yysize0;
1505
                    break;
1506
                  }
1507
                yyarg[yycount++] = yytname[yyx];
277.1.189 by Arnold D. Robbins
Move to bison 2.7.
1508
                {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1509
                  YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
277.1.189 by Arnold D. Robbins
Move to bison 2.7.
1510
                  if (! (yysize <= yysize1
1511
                         && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1512
                    return 2;
1513
                  yysize = yysize1;
1514
                }
228 by Arnold D. Robbins
Update to bison 2.5.
1515
              }
1516
        }
1517
    }
1518
1519
  switch (yycount)
1520
    {
1521
# define YYCASE_(N, S)                      \
1522
      case N:                               \
1523
        yyformat = S;                       \
1524
      break
1525
      YYCASE_(0, YY_("syntax error"));
1526
      YYCASE_(1, YY_("syntax error, unexpected %s"));
1527
      YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1528
      YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1529
      YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1530
      YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1531
# undef YYCASE_
1532
    }
1533
277.1.189 by Arnold D. Robbins
Move to bison 2.7.
1534
  {
1535
    YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1536
    if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1537
      return 2;
1538
    yysize = yysize1;
1539
  }
228 by Arnold D. Robbins
Update to bison 2.5.
1540
1541
  if (*yymsg_alloc < yysize)
1542
    {
1543
      *yymsg_alloc = 2 * yysize;
1544
      if (! (yysize <= *yymsg_alloc
1545
             && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1546
        *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1547
      return 1;
1548
    }
1549
1550
  /* Avoid sprintf, as that infringes on the user's name space.
1551
     Don't have undefined behavior even if the translation
1552
     produced a string with the wrong number of "%s"s.  */
1553
  {
1554
    char *yyp = *yymsg;
1555
    int yyi = 0;
1556
    while ((*yyp = *yyformat) != '\0')
1557
      if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1558
        {
1559
          yyp += yytnamerr (yyp, yyarg[yyi++]);
1560
          yyformat += 2;
1561
        }
1562
      else
1563
        {
1564
          yyp++;
1565
          yyformat++;
1566
        }
1567
  }
1568
  return 0;
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1569
}
1570
#endif /* YYERROR_VERBOSE */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1571
1572
/*-----------------------------------------------.
1573
| Release the memory associated to this symbol.  |
1574
`-----------------------------------------------*/
1575
1576
static void
33 by Arnold D. Robbins
Move to gawk 3.1.5.
1577
yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1578
{
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1579
  YYUSE (yyvaluep);
33 by Arnold D. Robbins
Move to gawk 3.1.5.
1580
  if (!yymsg)
1581
    yymsg = "Deleting";
1582
  YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1583
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1584
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
408.2.32 by Arnold D. Robbins
Regenerate awkgram.c with latest bison.
1585
  YYUSE (yytype);
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1586
  YY_IGNORE_MAYBE_UNINITIALIZED_END
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1587
}
1588
228 by Arnold D. Robbins
Update to bison 2.5.
1589
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1590
1591
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1592
/* The lookahead symbol.  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1593
int yychar;
1594
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1595
/* The semantic value of the lookahead symbol.  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1596
YYSTYPE yylval;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1597
/* Number of syntax errors so far.  */
1598
int yynerrs;
1599
1600
228 by Arnold D. Robbins
Update to bison 2.5.
1601
/*----------.
1602
| yyparse.  |
1603
`----------*/
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1604
1605
int
1606
yyparse (void)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1607
{
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1608
    int yystate;
1609
    /* Number of tokens to shift before error messages enabled.  */
1610
    int yyerrstatus;
1611
1612
    /* The stacks and their tools:
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1613
       'yyss': related to states.
1614
       'yyvs': related to semantic values.
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1615
319.1.18 by Arnold D. Robbins
Update infrastructure.
1616
       Refer to the stacks through separate pointers, to allow yyoverflow
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1617
       to reallocate them elsewhere.  */
1618
1619
    /* The state stack.  */
1620
    yytype_int16 yyssa[YYINITDEPTH];
1621
    yytype_int16 *yyss;
1622
    yytype_int16 *yyssp;
1623
1624
    /* The semantic value stack.  */
1625
    YYSTYPE yyvsa[YYINITDEPTH];
1626
    YYSTYPE *yyvs;
1627
    YYSTYPE *yyvsp;
1628
1629
    YYSIZE_T yystacksize;
1630
1631
  int yyn;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1632
  int yyresult;
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1633
  /* Lookahead token as an internal (translated) token number.  */
277.1.174 by Arnold D. Robbins
Update to bison 2.6.4.
1634
  int yytoken = 0;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1635
  /* The variables used to return semantic value and location from the
1636
     action routines.  */
1637
  YYSTYPE yyval;
1638
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1639
#if YYERROR_VERBOSE
1640
  /* Buffer for error messages, and its allocated size.  */
1641
  char yymsgbuf[128];
1642
  char *yymsg = yymsgbuf;
1643
  YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1644
#endif
1645
1646
#define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
1647
1648
  /* The number of symbols on the RHS of the reduced rule.
1649
     Keep to zero when no symbol should be popped.  */
1650
  int yylen = 0;
1651
277.1.176 by Arnold D. Robbins
Update to bison 2.6.5.
1652
  yyssp = yyss = yyssa;
1653
  yyvsp = yyvs = yyvsa;
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1654
  yystacksize = YYINITDEPTH;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1655
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1656
  YYDPRINTF ((stderr, "Starting parse\n"));
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1657
1658
  yystate = 0;
1659
  yyerrstatus = 0;
1660
  yynerrs = 0;
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1661
  yychar = YYEMPTY; /* Cause a token to be read.  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1662
  goto yysetstate;
1663
1664
/*------------------------------------------------------------.
1665
| yynewstate -- Push a new state, which is found in yystate.  |
1666
`------------------------------------------------------------*/
1667
 yynewstate:
1668
  /* In all cases, when you get here, the value and location stacks
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1669
     have just been pushed.  So pushing a state here evens the stacks.  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1670
  yyssp++;
1671
1672
 yysetstate:
1673
  *yyssp = yystate;
1674
1675
  if (yyss + yystacksize - 1 <= yyssp)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1676
    {
1677
      /* Get the current used size of the three stacks, in elements.  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1678
      YYSIZE_T yysize = yyssp - yyss + 1;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1679
1680
#ifdef yyoverflow
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1681
      {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1682
        /* Give user a chance to reallocate the stack.  Use copies of
1683
           these so that the &'s don't force the real ones into
1684
           memory.  */
1685
        YYSTYPE *yyvs1 = yyvs;
1686
        yytype_int16 *yyss1 = yyss;
1687
1688
        /* Each stack pointer address is followed by the size of the
1689
           data in use in that stack, in bytes.  This used to be a
1690
           conditional around just the two extra args, but that might
1691
           be undefined if yyoverflow is a macro.  */
1692
        yyoverflow (YY_("memory exhausted"),
1693
                    &yyss1, yysize * sizeof (*yyssp),
1694
                    &yyvs1, yysize * sizeof (*yyvsp),
1695
                    &yystacksize);
1696
1697
        yyss = yyss1;
1698
        yyvs = yyvs1;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1699
      }
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1700
#else /* no yyoverflow */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1701
# ifndef YYSTACK_RELOCATE
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1702
      goto yyexhaustedlab;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1703
# else
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1704
      /* Extend the stack our own way.  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1705
      if (YYMAXDEPTH <= yystacksize)
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1706
        goto yyexhaustedlab;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1707
      yystacksize *= 2;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1708
      if (YYMAXDEPTH < yystacksize)
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1709
        yystacksize = YYMAXDEPTH;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1710
1711
      {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1712
        yytype_int16 *yyss1 = yyss;
1713
        union yyalloc *yyptr =
1714
          (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1715
        if (! yyptr)
1716
          goto yyexhaustedlab;
1717
        YYSTACK_RELOCATE (yyss_alloc, yyss);
1718
        YYSTACK_RELOCATE (yyvs_alloc, yyvs);
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1719
#  undef YYSTACK_RELOCATE
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1720
        if (yyss1 != yyssa)
1721
          YYSTACK_FREE (yyss1);
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1722
      }
1723
# endif
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1724
#endif /* no yyoverflow */
1725
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1726
      yyssp = yyss + yysize - 1;
1727
      yyvsp = yyvs + yysize - 1;
1728
1729
      YYDPRINTF ((stderr, "Stack size increased to %lu\n",
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1730
                  (unsigned long int) yystacksize));
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1731
1732
      if (yyss + yystacksize - 1 <= yyssp)
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1733
        YYABORT;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1734
    }
1735
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1736
  YYDPRINTF ((stderr, "Entering state %d\n", yystate));
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1737
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1738
  if (yystate == YYFINAL)
1739
    YYACCEPT;
1740
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1741
  goto yybackup;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1742
1743
/*-----------.
1744
| yybackup.  |
1745
`-----------*/
1746
yybackup:
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1747
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1748
  /* Do appropriate processing given the current state.  Read a
1749
     lookahead token if we need one and don't already have one.  */
1750
1751
  /* First try to decide what to do without reference to lookahead token.  */
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1752
  yyn = yypact[yystate];
228 by Arnold D. Robbins
Update to bison 2.5.
1753
  if (yypact_value_is_default (yyn))
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1754
    goto yydefault;
1755
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1756
  /* Not known => get a lookahead token if don't already have one.  */
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1757
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1758
  /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1759
  if (yychar == YYEMPTY)
1760
    {
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1761
      YYDPRINTF ((stderr, "Reading a token: "));
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1762
      yychar = yylex ();
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1763
    }
1764
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1765
  if (yychar <= YYEOF)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1766
    {
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1767
      yychar = yytoken = YYEOF;
1768
      YYDPRINTF ((stderr, "Now at end of input.\n"));
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1769
    }
1770
  else
1771
    {
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1772
      yytoken = YYTRANSLATE (yychar);
33 by Arnold D. Robbins
Move to gawk 3.1.5.
1773
      YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1774
    }
1775
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1776
  /* If the proper action on seeing token YYTOKEN is to reduce or to
1777
     detect an error, take that action.  */
1778
  yyn += yytoken;
1779
  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1780
    goto yydefault;
1781
  yyn = yytable[yyn];
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1782
  if (yyn <= 0)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1783
    {
228 by Arnold D. Robbins
Update to bison 2.5.
1784
      if (yytable_value_is_error (yyn))
1785
        goto yyerrlab;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1786
      yyn = -yyn;
1787
      goto yyreduce;
1788
    }
1789
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1790
  /* Count tokens shifted since error; after three, turn off error
1791
     status.  */
1792
  if (yyerrstatus)
1793
    yyerrstatus--;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1794
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1795
  /* Shift the lookahead token.  */
1796
  YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1797
1798
  /* Discard the shifted token.  */
1799
  yychar = YYEMPTY;
1800
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1801
  yystate = yyn;
277.1.174 by Arnold D. Robbins
Update to bison 2.6.4.
1802
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1803
  *++yyvsp = yylval;
277.1.174 by Arnold D. Robbins
Update to bison 2.6.4.
1804
  YY_IGNORE_MAYBE_UNINITIALIZED_END
35 by Arnold D. Robbins
Move to gawk-3.1.7.
1805
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1806
  goto yynewstate;
1807
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1808
1809
/*-----------------------------------------------------------.
1810
| yydefault -- do the default action for the current state.  |
1811
`-----------------------------------------------------------*/
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1812
yydefault:
1813
  yyn = yydefact[yystate];
1814
  if (yyn == 0)
1815
    goto yyerrlab;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1816
  goto yyreduce;
1817
1818
1819
/*-----------------------------.
1820
| yyreduce -- Do a reduction.  |
1821
`-----------------------------*/
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1822
yyreduce:
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1823
  /* yyn is the number of a rule to reduce with.  */
28 by Arnold D. Robbins
Move to gawk-3.1.0.
1824
  yylen = yyr2[yyn];
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1825
1826
  /* If YYLEN is nonzero, implement the default value of the action:
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1827
     '$$ = $1'.
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1828
1829
     Otherwise, the following line sets YYVAL to garbage.
1830
     This behavior is undocumented and Bison
1831
     users should not rely upon it.  Assigning to YYVAL
1832
     unconditionally makes the parser a bit smaller, and it avoids a
1833
     GCC warning that YYVAL may be used uninitialized.  */
1834
  yyval = yyvsp[1-yylen];
1835
1836
1837
  YY_REDUCE_PRINT (yyn);
1838
  switch (yyn)
1839
    {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
1840
        case 3:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1841
#line 197 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
1842
    {
1843
		rule = 0;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1844
		yyerrok;
1845
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1846
#line 1847 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1847
    break;
1848
1849
  case 5:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1850
#line 203 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
1851
    {
1852
		next_sourcefile();
1853
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1854
#line 1855 "awkgram.c" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
1855
    break;
1856
1857
  case 6:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1858
#line 207 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
1859
    {
1860
		rule = 0;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1861
		/*
1862
		 * If errors, give up, don't produce an infinite
31 by Arnold D. Robbins
Move to gawk-3.1.3.
1863
		 * stream of syntax error messages.
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1864
		 */
31 by Arnold D. Robbins
Move to gawk-3.1.3.
1865
  		/* yyerrok; */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1866
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1867
#line 1868 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1868
    break;
1869
1870
  case 7:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1871
#line 219 "awkgram.y" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1872
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1873
		(void) append_rule((yyvsp[-1]), (yyvsp[0]));
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1874
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1875
#line 1876 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1876
    break;
1877
1878
  case 8:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1879
#line 223 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
1880
    {
1881
		if (rule != Rule) {
1882
			msg(_("%s blocks must have an action part"), ruletab[rule]);
1883
			errcount++;
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1884
		} else if ((yyvsp[-1]) == NULL) {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
1885
			msg(_("each rule must have a pattern or an action part"));
1886
			errcount++;
1887
		} else		/* pattern rule with non-empty pattern */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1888
			(void) append_rule((yyvsp[-1]), NULL);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
1889
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1890
#line 1891 "awkgram.c" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
1891
    break;
1892
1893
  case 9:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1894
#line 234 "awkgram.y" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1895
    {
281.1.4 by john haque
Optimize tail-recursive calls.
1896
		in_function = NULL;
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1897
		(void) mk_function((yyvsp[-1]), (yyvsp[0]));
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1898
		yyerrok;
1899
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1900
#line 1901 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1901
    break;
1902
1903
  case 10:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1904
#line 240 "awkgram.y" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1905
    {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
1906
		want_source = false;
408.13.59 by Arnold D. Robbins
Disallow calling a function parameter. Check params are not function names.
1907
		at_seen = false;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
1908
		yyerrok;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1909
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1910
#line 1911 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1911
    break;
1912
1913
  case 11:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1914
#line 246 "awkgram.y" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
1915
    {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
1916
		want_source = false;
408.13.59 by Arnold D. Robbins
Disallow calling a function parameter. Check params are not function names.
1917
		at_seen = false;
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
1918
		yyerrok;
1919
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1920
#line 1921 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
1921
    break;
1922
1923
  case 12:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1924
#line 255 "awkgram.y" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1925
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1926
		if (include_source((yyvsp[0])) < 0)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
1927
			YYABORT;
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1928
		efree((yyvsp[0])->lextok);
1929
		bcfree((yyvsp[0]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
1930
		(yyval) = NULL;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1931
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1932
#line 1933 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1933
    break;
1934
1935
  case 13:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1936
#line 263 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
1937
    { (yyval) = NULL; }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1938
#line 1939 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
1939
    break;
1940
1941
  case 14:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1942
#line 265 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
1943
    { (yyval) = NULL; }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1944
#line 1945 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
1945
    break;
1946
1947
  case 15:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1948
#line 270 "awkgram.y" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
1949
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1950
		if (load_library((yyvsp[0])) < 0)
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
1951
			YYABORT;
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1952
		efree((yyvsp[0])->lextok);
1953
		bcfree((yyvsp[0]));
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
1954
		(yyval) = NULL;
1955
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1956
#line 1957 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
1957
    break;
1958
1959
  case 16:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1960
#line 278 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
1961
    { (yyval) = NULL; }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1962
#line 1963 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
1963
    break;
1964
1965
  case 17:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1966
#line 280 "awkgram.y" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
1967
    { (yyval) = NULL; }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1968
#line 1969 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
1969
    break;
1970
1971
  case 18:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1972
#line 285 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
1973
    {	(yyval) = NULL; rule = Rule; }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1974
#line 1975 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1975
    break;
1976
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
1977
  case 19:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1978
#line 287 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1979
    {	(yyval) = (yyvsp[0]); rule = Rule; }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1980
#line 1981 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
1981
    break;
1982
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
1983
  case 20:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
1984
#line 289 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
1985
    {
1986
		INSTRUCTION *tp;
1987
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1988
		add_lint((yyvsp[-3]), LINT_assign_in_cond);
1989
		add_lint((yyvsp[0]), LINT_assign_in_cond);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
1990
1991
		tp = instruction(Op_no_op);
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
1992
		list_prepend((yyvsp[-3]), bcalloc(Op_line_range, !!do_pretty_print + 1, 0));
1993
		(yyvsp[-3])->nexti->triggered = false;
1994
		(yyvsp[-3])->nexti->target_jmp = (yyvsp[0])->nexti;
1995
1996
		list_append((yyvsp[-3]), instruction(Op_cond_pair));
1997
		(yyvsp[-3])->lasti->line_range = (yyvsp[-3])->nexti;
1998
		(yyvsp[-3])->lasti->target_jmp = tp;
1999
2000
		list_append((yyvsp[0]), instruction(Op_cond_pair));
2001
		(yyvsp[0])->lasti->line_range = (yyvsp[-3])->nexti;
2002
		(yyvsp[0])->lasti->target_jmp = tp;
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
2003
		if (do_pretty_print) {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2004
			((yyvsp[-3])->nexti + 1)->condpair_left = (yyvsp[-3])->lasti;
2005
			((yyvsp[-3])->nexti + 1)->condpair_right = (yyvsp[0])->lasti;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2006
		}
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2007
		(yyval) = list_append(list_merge((yyvsp[-3]), (yyvsp[0])), tp);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2008
		rule = Rule;
2009
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2010
#line 2011 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
2011
    break;
2012
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2013
  case 21:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2014
#line 315 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2015
    {
2016
		static int begin_seen = 0;
2017
		if (do_lint_old && ++begin_seen == 2)
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2018
			warning_ln((yyvsp[0])->source_line,
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
2019
				_("old awk does not support multiple `BEGIN' or `END' rules"));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2020
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2021
		(yyvsp[0])->in_rule = rule = BEGIN;
2022
		(yyvsp[0])->source_file = source;
2023
		(yyval) = (yyvsp[0]);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2024
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2025
#line 2026 "awkgram.c" /* yacc.c:1646  */
37 by Arnold D. Robbins
Bring in development gawk changes.
2026
    break;
2027
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2028
  case 22:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2029
#line 326 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2030
    {
2031
		static int end_seen = 0;
2032
		if (do_lint_old && ++end_seen == 2)
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2033
			warning_ln((yyvsp[0])->source_line,
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
2034
				_("old awk does not support multiple `BEGIN' or `END' rules"));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2035
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2036
		(yyvsp[0])->in_rule = rule = END;
2037
		(yyvsp[0])->source_file = source;
2038
		(yyval) = (yyvsp[0]);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2039
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2040
#line 2041 "awkgram.c" /* yacc.c:1646  */
37 by Arnold D. Robbins
Bring in development gawk changes.
2041
    break;
2042
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2043
  case 23:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2044
#line 337 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2045
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2046
		(yyvsp[0])->in_rule = rule = BEGINFILE;
2047
		(yyvsp[0])->source_file = source;
2048
		(yyval) = (yyvsp[0]);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2049
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2050
#line 2051 "awkgram.c" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2051
    break;
2052
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2053
  case 24:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2054
#line 343 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2055
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2056
		(yyvsp[0])->in_rule = rule = ENDFILE;
2057
		(yyvsp[0])->source_file = source;
2058
		(yyval) = (yyvsp[0]);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2059
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2060
#line 2061 "awkgram.c" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2061
    break;
2062
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2063
  case 25:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2064
#line 352 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2065
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2066
		if ((yyvsp[-3]) == NULL)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2067
			(yyval) = list_create(instruction(Op_no_op));
2068
		else
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2069
			(yyval) = (yyvsp[-3]);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2070
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2071
#line 2072 "awkgram.c" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2072
    break;
2073
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2074
  case 26:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2075
#line 362 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
2076
    { (yyval) = (yyvsp[0]); }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2077
#line 2078 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
2078
    break;
2079
2080
  case 27:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2081
#line 364 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2082
    { (yyval) = (yyvsp[0]); }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2083
#line 2084 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2084
    break;
2085
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
2086
  case 28:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2087
#line 366 "awkgram.y" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
2088
    {
28 by Arnold D. Robbins
Move to gawk-3.1.0.
2089
		yyerror(_("`%s' is a built-in function, it cannot be redefined"),
281.1.1 by john haque
Speed/memory performance improvements.
2090
					tokstart);
2091
		YYABORT;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
2092
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2093
#line 2094 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
2094
    break;
2095
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2096
  case 29:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2097
#line 372 "awkgram.y" /* yacc.c:1646  */
408.13.59 by Arnold D. Robbins
Disallow calling a function parameter. Check params are not function names.
2098
    {
2099
		(yyval) = (yyvsp[0]);
2100
		at_seen = false;
2101
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2102
#line 2103 "awkgram.c" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2103
    break;
2104
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2105
  case 32:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2106
#line 385 "awkgram.y" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
2107
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2108
		(yyvsp[-5])->source_file = source;
2109
		if (install_function((yyvsp[-4])->lextok, (yyvsp[-5]), (yyvsp[-2])) < 0)
281.1.1 by john haque
Speed/memory performance improvements.
2110
			YYABORT;
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2111
		in_function = (yyvsp[-4])->lextok;
2112
		(yyvsp[-4])->lextok = NULL;
2113
		bcfree((yyvsp[-4]));
281.1.1 by john haque
Speed/memory performance improvements.
2114
		/* $4 already free'd in install_function */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2115
		(yyval) = (yyvsp[-5]);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2116
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2117
#line 2118 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
2118
    break;
2119
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2120
  case 33:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2121
#line 403 "awkgram.y" /* yacc.c:1646  */
319.1.80 by Arnold D. Robbins
Some minor fixes. See ChangeLog.
2122
    { want_regexp = true; }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2123
#line 2124 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
2124
    break;
2125
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2126
  case 34:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2127
#line 405 "awkgram.y" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
2128
    {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2129
		  NODE *n, *exp;
2130
		  char *re;
2131
		  size_t len;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
2132
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2133
		  re = (yyvsp[0])->lextok;
2134
		  (yyvsp[0])->lextok = NULL;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2135
		  len = strlen(re);
33 by Arnold D. Robbins
Move to gawk 3.1.5.
2136
		  if (do_lint) {
2137
			if (len == 0)
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2138
				lintwarn_ln((yyvsp[0])->source_line,
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
2139
					_("regexp constant `//' looks like a C++ comment, but is not"));
319.2.38 by Arnold D. Robbins
Further API code and test code.
2140
			else if (re[0] == '*' && re[len-1] == '*')
33 by Arnold D. Robbins
Move to gawk 3.1.5.
2141
				/* possible C comment */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2142
				lintwarn_ln((yyvsp[0])->source_line,
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
2143
					_("regexp constant `/%s/' looks like a C comment, but is not"), re);
30 by Arnold D. Robbins
Move to gawk-3.1.2.
2144
		  }
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2145
281.1.2 by john haque
Add a test file, cleanup code and update doc.
2146
		  exp = make_str_node(re, len, ALREADY_MALLOCED);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2147
		  n = make_regnode(Node_regex, exp);
2148
		  if (n == NULL) {
2149
			unref(exp);
2150
			YYABORT;
2151
		  }
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2152
		  (yyval) = (yyvsp[0]);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2153
		  (yyval)->opcode = Op_match_rec;
2154
		  (yyval)->memory = n;
2155
		}
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2156
#line 2157 "awkgram.c" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2157
    break;
2158
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2159
  case 35:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2160
#line 437 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2161
    { bcfree((yyvsp[0])); }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2162
#line 2163 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
2163
    break;
2164
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2165
  case 37:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2166
#line 443 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
2167
    {	(yyval) = NULL; }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2168
#line 2169 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
2169
    break;
2170
2171
  case 38:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2172
#line 445 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2173
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2174
		if ((yyvsp[0]) == NULL)
2175
			(yyval) = (yyvsp[-1]);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2176
		else {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2177
			add_lint((yyvsp[0]), LINT_no_effect);
2178
			if ((yyvsp[-1]) == NULL)
2179
				(yyval) = (yyvsp[0]);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2180
			else
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2181
				(yyval) = list_merge((yyvsp[-1]), (yyvsp[0]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2182
		}
2183
	    yyerrok;
2184
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2185
#line 2186 "awkgram.c" /* yacc.c:1646  */
37 by Arnold D. Robbins
Bring in development gawk changes.
2186
    break;
2187
2188
  case 39:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2189
#line 458 "awkgram.y" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2190
    {	(yyval) = NULL; }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2191
#line 2192 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2192
    break;
2193
2194
  case 42:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2195
#line 468 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
2196
    { (yyval) = NULL; }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2197
#line 2198 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
2198
    break;
2199
2200
  case 43:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2201
#line 470 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
2202
    { (yyval) = (yyvsp[-1]); }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2203
#line 2204 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2204
    break;
2205
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
2206
  case 44:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2207
#line 472 "awkgram.y" /* yacc.c:1646  */
281.1.1 by john haque
Speed/memory performance improvements.
2208
    {
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
2209
		if (do_pretty_print)
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2210
			(yyval) = list_prepend((yyvsp[0]), instruction(Op_exec_count));
281.1.1 by john haque
Speed/memory performance improvements.
2211
		else
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2212
			(yyval) = (yyvsp[0]);
281.1.1 by john haque
Speed/memory performance improvements.
2213
 	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2214
#line 2215 "awkgram.c" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2215
    break;
2216
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2217
  case 45:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2218
#line 479 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2219
    {
116 by Arnold D. Robbins
Fix switch debugging.
2220
		INSTRUCTION *dflt, *curr = NULL, *cexp, *cstmt;
2221
		INSTRUCTION *ip, *nextc, *tbreak;
2222
		const char **case_values = NULL;
2223
		int maxcount = 128;
2224
		int case_count = 0;
2225
		int i;
2226
2227
		tbreak = instruction(Op_no_op);	
2228
		cstmt = list_create(tbreak);
2229
		cexp = list_create(instruction(Op_pop));
2230
		dflt = instruction(Op_jmp);
2231
		dflt->target_jmp = tbreak;	/* if no case match and no explicit default */
2232
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2233
		if ((yyvsp[-2]) != NULL) {
2234
			curr = (yyvsp[-2])->nexti;
2235
			bcfree((yyvsp[-2]));	/* Op_list */
116 by Arnold D. Robbins
Fix switch debugging.
2236
		} /*  else
2237
				curr = NULL; */
2238
2239
		for(; curr != NULL; curr = nextc) {
2240
			INSTRUCTION *caseexp = curr->case_exp;
2241
			INSTRUCTION *casestmt = curr->case_stmt;
2242
2243
			nextc = curr->nexti;
2244
			if (curr->opcode == Op_K_case) {
2245
				if (caseexp->opcode == Op_push_i) {
2246
					/* a constant scalar */
2247
					char *caseval;
2248
					caseval = force_string(caseexp->memory)->stptr;
2249
					for (i = 0; i < case_count; i++) {
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
2250
						if (strcmp(caseval, case_values[i]) == 0)
2251
							error_ln(curr->source_line,
2252
								_("duplicate case values in switch body: %s"), caseval);
116 by Arnold D. Robbins
Fix switch debugging.
2253
					}
2254
 
2255
					if (case_values == NULL)
2256
						emalloc(case_values, const char **, sizeof(char *) * maxcount, "statement");
2257
					else if (case_count >= maxcount) {
2258
						maxcount += 128;
2259
						erealloc(case_values, const char **, sizeof(char*) * maxcount, "statement");
2260
					}
2261
					case_values[case_count++] = caseval;
2262
				} else {
2263
					/* match a constant regex against switch expression. */
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
2264
					(curr + 1)->match_exp = true;
116 by Arnold D. Robbins
Fix switch debugging.
2265
				}
2266
				curr->stmt_start = casestmt->nexti;
2267
				curr->stmt_end	= casestmt->lasti;
2268
				(void) list_prepend(cexp, curr);
2269
				(void) list_prepend(cexp, caseexp);
2270
			} else {
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
2271
				if (dflt->target_jmp != tbreak)
2272
					error_ln(curr->source_line,
2273
						_("duplicate `default' detected in switch body"));
2274
				else
116 by Arnold D. Robbins
Fix switch debugging.
2275
					dflt->target_jmp = casestmt->nexti;
2276
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
2277
				if (do_pretty_print) {
116 by Arnold D. Robbins
Fix switch debugging.
2278
					curr->stmt_start = casestmt->nexti;
2279
					curr->stmt_end = casestmt->lasti;
2280
					(void) list_prepend(cexp, curr);
2281
				} else
2282
					bcfree(curr);
2283
			}
2284
2285
			cstmt = list_merge(casestmt, cstmt);
2286
		}
2287
2288
		if (case_values != NULL)
2289
			efree(case_values);
2290
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2291
		ip = (yyvsp[-6]);
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
2292
		if (do_pretty_print) {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2293
			(void) list_prepend(ip, (yyvsp[-8]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2294
			(void) list_prepend(ip, instruction(Op_exec_count));
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2295
			(yyvsp[-8])->target_break = tbreak;
2296
			((yyvsp[-8]) + 1)->switch_start = cexp->nexti;
2297
			((yyvsp[-8]) + 1)->switch_end = cexp->lasti;
116 by Arnold D. Robbins
Fix switch debugging.
2298
		}/* else
2299
				$1 is NULL */
2300
2301
		(void) list_append(cexp, dflt);
2302
		(void) list_merge(ip, cexp);
2303
		(yyval) = list_merge(ip, cstmt);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2304
2305
		break_allowed--;			
116 by Arnold D. Robbins
Fix switch debugging.
2306
		fix_break_continue(ip, tbreak, NULL);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2307
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2308
#line 2309 "awkgram.c" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2309
    break;
2310
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2311
  case 46:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2312
#line 569 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2313
    { 
116 by Arnold D. Robbins
Fix switch debugging.
2314
		/*
2315
		 *    -----------------
2316
		 * tc:
2317
		 *         cond
2318
		 *    -----------------
2319
		 *    [Op_jmp_false tb   ]
2320
		 *    -----------------   
2321
		 *         body
2322
		 *    -----------------
2323
		 *    [Op_jmp      tc    ]
2324
		 * tb:[Op_no_op          ]
2325
		 */
2326
2327
		INSTRUCTION *ip, *tbreak, *tcont;
2328
2329
		tbreak = instruction(Op_no_op);
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2330
		add_lint((yyvsp[-3]), LINT_assign_in_cond);
2331
		tcont = (yyvsp[-3])->nexti;
2332
		ip = list_append((yyvsp[-3]), instruction(Op_jmp_false));
116 by Arnold D. Robbins
Fix switch debugging.
2333
		ip->lasti->target_jmp = tbreak;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2334
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
2335
		if (do_pretty_print) {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2336
			(void) list_append(ip, instruction(Op_exec_count));
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2337
			(yyvsp[-5])->target_break = tbreak;
2338
			(yyvsp[-5])->target_continue = tcont;
2339
			((yyvsp[-5]) + 1)->while_body = ip->lasti;
2340
			(void) list_prepend(ip, (yyvsp[-5]));
116 by Arnold D. Robbins
Fix switch debugging.
2341
		}/* else
2342
				$1 is NULL */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2343
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2344
		if ((yyvsp[0]) != NULL)
2345
			(void) list_merge(ip, (yyvsp[0]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2346
		(void) list_append(ip, instruction(Op_jmp));
116 by Arnold D. Robbins
Fix switch debugging.
2347
		ip->lasti->target_jmp = tcont;
2348
		(yyval) = list_append(ip, tbreak);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2349
2350
		break_allowed--;
2351
		continue_allowed--;
116 by Arnold D. Robbins
Fix switch debugging.
2352
		fix_break_continue(ip, tbreak, tcont);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2353
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2354
#line 2355 "awkgram.c" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2355
    break;
2356
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2357
  case 47:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2358
#line 611 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2359
    {
116 by Arnold D. Robbins
Fix switch debugging.
2360
		/*
2361
		 *    -----------------
2362
		 * z:
2363
		 *         body
2364
		 *    -----------------
2365
		 * tc: 
2366
		 *         cond
2367
		 *    -----------------
2368
		 *    [Op_jmp_true | z  ]
2369
		 * tb:[Op_no_op         ]
2370
		 */
2371
2372
		INSTRUCTION *ip, *tbreak, *tcont;
2373
2374
		tbreak = instruction(Op_no_op);
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2375
		tcont = (yyvsp[-2])->nexti;
2376
		add_lint((yyvsp[-2]), LINT_assign_in_cond);
2377
		if ((yyvsp[-5]) != NULL)
2378
			ip = list_merge((yyvsp[-5]), (yyvsp[-2]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2379
		else
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2380
			ip = list_prepend((yyvsp[-2]), instruction(Op_no_op));
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
2381
		if (do_pretty_print)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2382
			(void) list_prepend(ip, instruction(Op_exec_count));
2383
		(void) list_append(ip, instruction(Op_jmp_true));
2384
		ip->lasti->target_jmp = ip->nexti;
116 by Arnold D. Robbins
Fix switch debugging.
2385
		(yyval) = list_append(ip, tbreak);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2386
2387
		break_allowed--;
2388
		continue_allowed--;
116 by Arnold D. Robbins
Fix switch debugging.
2389
		fix_break_continue(ip, tbreak, tcont);
2390
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
2391
		if (do_pretty_print) {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2392
			(yyvsp[-7])->target_break = tbreak;
2393
			(yyvsp[-7])->target_continue = tcont;
2394
			((yyvsp[-7]) + 1)->doloop_cond = tcont;
2395
			(yyval) = list_prepend(ip, (yyvsp[-7]));
2396
			bcfree((yyvsp[-4]));
116 by Arnold D. Robbins
Fix switch debugging.
2397
		} /* else
408.4.8 by Arnold D. Robbins
Minor cleanup in awkgram.y.
2398
			$1 and $4 are NULLs */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2399
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2400
#line 2401 "awkgram.c" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2401
    break;
2402
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2403
  case 48:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2404
#line 653 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2405
    {
49 by Arnold D. Robbins
Fix memory leaks - patch from John.
2406
		INSTRUCTION *ip;
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2407
		char *var_name = (yyvsp[-5])->lextok;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2408
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2409
		if ((yyvsp[0]) != NULL
2410
				&& (yyvsp[0])->lasti->opcode == Op_K_delete
2411
				&& (yyvsp[0])->lasti->expr_count == 1
2412
				&& (yyvsp[0])->nexti->opcode == Op_push
2413
				&& ((yyvsp[0])->nexti->memory->type != Node_var || !((yyvsp[0])->nexti->memory->var_update))
2414
				&& strcmp((yyvsp[0])->nexti->memory->vname, var_name) == 0
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2415
		) {
2416
		
2417
		/* Efficiency hack.  Recognize the special case of
28 by Arnold D. Robbins
Move to gawk-3.1.0.
2418
		 *
2419
		 * 	for (iggy in foo)
2420
		 * 		delete foo[iggy]
2421
		 *
2422
		 * and treat it as if it were
2423
		 *
2424
		 * 	delete foo
2425
		 *
2426
		 * Check that the body is a `delete a[i]' statement,
2427
		 * and that both the loop var and array names match.
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2428
		 */		 
2429
			NODE *arr = NULL;
2430
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2431
			ip = (yyvsp[0])->nexti->nexti; 
2432
			if ((yyvsp[-3])->nexti->opcode == Op_push && (yyvsp[-3])->lasti == (yyvsp[-3])->nexti)
2433
				arr = (yyvsp[-3])->nexti->memory;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2434
			if (arr != NULL
2435
					&& ip->opcode == Op_no_op
2436
					&& ip->nexti->opcode == Op_push_array
2437
					&& strcmp(ip->nexti->memory->vname, arr->vname) == 0
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2438
					&& ip->nexti->nexti == (yyvsp[0])->lasti
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2439
			) {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2440
				(void) make_assignable((yyvsp[0])->nexti);
2441
				(yyvsp[0])->lasti->opcode = Op_K_delete_loop;
2442
				(yyvsp[0])->lasti->expr_count = 0;
2443
				if ((yyvsp[-7]) != NULL)
2444
					bcfree((yyvsp[-7]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2445
				efree(var_name);
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2446
				bcfree((yyvsp[-5]));
2447
				bcfree((yyvsp[-4]));
2448
				bcfree((yyvsp[-3]));
2449
				(yyval) = (yyvsp[0]);
49 by Arnold D. Robbins
Fix memory leaks - patch from John.
2450
			} else
2451
				goto regular_loop;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
2452
		} else {
116 by Arnold D. Robbins
Fix switch debugging.
2453
			INSTRUCTION *tbreak, *tcont;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2454
306 by john haque
Add arbitrary-precision arithmetic on integers.
2455
			/*    [ Op_push_array a       ]
2456
			 *    [ Op_arrayfor_init | ib ]
2457
			 * ic:[ Op_arrayfor_incr | ib ] 
2458
			 *    [ Op_var_assign if any  ]
2459
			 *
2460
			 *              body
2461
			 *
2462
			 *    [Op_jmp | ic            ]
2463
			 * ib:[Op_arrayfor_final      ]
2464
			 */
49 by Arnold D. Robbins
Fix memory leaks - patch from John.
2465
regular_loop:
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2466
			ip = (yyvsp[-3]);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2467
			ip->nexti->opcode = Op_push_array;
116 by Arnold D. Robbins
Fix switch debugging.
2468
2469
			tbreak = instruction(Op_arrayfor_final);
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2470
			(yyvsp[-4])->opcode = Op_arrayfor_incr;
2471
			(yyvsp[-4])->array_var = variable((yyvsp[-5])->source_line, var_name, Node_var);
2472
			(yyvsp[-4])->target_jmp = tbreak;
2473
			tcont = (yyvsp[-4]);
2474
			(yyvsp[-5])->opcode = Op_arrayfor_init;
2475
			(yyvsp[-5])->target_jmp = tbreak;
2476
			(void) list_append(ip, (yyvsp[-5]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2477
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
2478
			if (do_pretty_print) {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2479
				(yyvsp[-7])->opcode = Op_K_arrayfor;
2480
				(yyvsp[-7])->target_continue = tcont;
2481
				(yyvsp[-7])->target_break = tbreak;
2482
				(void) list_append(ip, (yyvsp[-7]));
116 by Arnold D. Robbins
Fix switch debugging.
2483
			} /* else
2484
					$1 is NULL */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2485
2486
			/* add update_FOO instruction if necessary */ 
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2487
			if ((yyvsp[-4])->array_var->type == Node_var && (yyvsp[-4])->array_var->var_update) {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2488
				(void) list_append(ip, instruction(Op_var_update));
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2489
				ip->lasti->update_var = (yyvsp[-4])->array_var->var_update;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2490
			}
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2491
			(void) list_append(ip, (yyvsp[-4]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2492
2493
			/* add set_FOO instruction if necessary */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2494
			if ((yyvsp[-4])->array_var->type == Node_var && (yyvsp[-4])->array_var->var_assign) {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2495
				(void) list_append(ip, instruction(Op_var_assign));
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2496
				ip->lasti->assign_var = (yyvsp[-4])->array_var->var_assign;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2497
			}
2498
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
2499
			if (do_pretty_print) {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2500
				(void) list_append(ip, instruction(Op_exec_count));
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2501
				((yyvsp[-7]) + 1)->forloop_cond = (yyvsp[-4]);
2502
				((yyvsp[-7]) + 1)->forloop_body = ip->lasti; 
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2503
			}
2504
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2505
			if ((yyvsp[0]) != NULL)
2506
				(void) list_merge(ip, (yyvsp[0]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2507
2508
			(void) list_append(ip, instruction(Op_jmp));
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2509
			ip->lasti->target_jmp = (yyvsp[-4]);
116 by Arnold D. Robbins
Fix switch debugging.
2510
			(yyval) = list_append(ip, tbreak);
2511
			fix_break_continue(ip, tbreak, tcont);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2512
		} 
2513
2514
		break_allowed--;
2515
		continue_allowed--;
2516
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2517
#line 2518 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
2518
    break;
2519
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2520
  case 49:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2521
#line 766 "awkgram.y" /* yacc.c:1646  */
281.1.1 by john haque
Speed/memory performance improvements.
2522
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2523
		(yyval) = mk_for_loop((yyvsp[-11]), (yyvsp[-9]), (yyvsp[-6]), (yyvsp[-3]), (yyvsp[0]));
281.1.1 by john haque
Speed/memory performance improvements.
2524
2525
		break_allowed--;
2526
		continue_allowed--;
2527
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2528
#line 2529 "awkgram.c" /* yacc.c:1646  */
281.1.1 by john haque
Speed/memory performance improvements.
2529
    break;
2530
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2531
  case 50:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2532
#line 773 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2533
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2534
		(yyval) = mk_for_loop((yyvsp[-10]), (yyvsp[-8]), (INSTRUCTION *) NULL, (yyvsp[-3]), (yyvsp[0]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2535
2536
		break_allowed--;
2537
		continue_allowed--;
2538
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2539
#line 2540 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
2540
    break;
2541
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2542
  case 51:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2543
#line 780 "awkgram.y" /* yacc.c:1646  */
32 by Arnold D. Robbins
Move to gawk-3.1.4.
2544
    {
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
2545
		if (do_pretty_print)
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2546
			(yyval) = list_prepend((yyvsp[0]), instruction(Op_exec_count));
281.1.1 by john haque
Speed/memory performance improvements.
2547
		else
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2548
			(yyval) = (yyvsp[0]);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2549
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2550
#line 2551 "awkgram.c" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2551
    break;
2552
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2553
  case 52:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2554
#line 790 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2555
    { 
2556
		if (! break_allowed)
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2557
			error_ln((yyvsp[-1])->source_line,
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
2558
				_("`break' is not allowed outside a loop or switch"));
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2559
		(yyvsp[-1])->target_jmp = NULL;
2560
		(yyval) = list_create((yyvsp[-1]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2561
2562
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2563
#line 2564 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
2564
    break;
2565
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2566
  case 53:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2567
#line 799 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2568
    {
2569
		if (! continue_allowed)
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2570
			error_ln((yyvsp[-1])->source_line,
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
2571
				_("`continue' is not allowed outside a loop"));
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2572
		(yyvsp[-1])->target_jmp = NULL;
2573
		(yyval) = list_create((yyvsp[-1]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2574
2575
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2576
#line 2577 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
2577
    break;
2578
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2579
  case 54:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2580
#line 808 "awkgram.y" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
2581
    {
167 by Arnold D. Robbins
Fix next and exit from functions.
2582
		/* if inside function (rule = 0), resolve context at run-time */
2583
		if (rule && rule != Rule)
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2584
			error_ln((yyvsp[-1])->source_line,
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
2585
				_("`next' used in %s action"), ruletab[rule]);
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2586
		(yyvsp[-1])->target_jmp = ip_rec;
2587
		(yyval) = list_create((yyvsp[-1]));
30 by Arnold D. Robbins
Move to gawk-3.1.2.
2588
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2589
#line 2590 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
2590
    break;
2591
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2592
  case 55:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2593
#line 817 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2594
    {
167 by Arnold D. Robbins
Fix next and exit from functions.
2595
		/* if inside function (rule = 0), resolve context at run-time */
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
2596
		if (rule == BEGIN || rule == END || rule == ENDFILE)
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2597
			error_ln((yyvsp[-1])->source_line,
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
2598
				_("`nextfile' used in %s action"), ruletab[rule]);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2599
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2600
		(yyvsp[-1])->target_newfile = ip_newfile;
2601
		(yyvsp[-1])->target_endfile = ip_endfile;
2602
		(yyval) = list_create((yyvsp[-1]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2603
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2604
#line 2605 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
2605
    break;
2606
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2607
  case 56:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2608
#line 828 "awkgram.y" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
2609
    {
167 by Arnold D. Robbins
Fix next and exit from functions.
2610
		/* Initialize the two possible jump targets, the actual target
2611
		 * is resolved at run-time. 
2612
		 */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2613
		(yyvsp[-2])->target_end = ip_end;	/* first instruction in end_block */
2614
		(yyvsp[-2])->target_atexit = ip_atexit;	/* cleanup and go home */
34 by Arnold D. Robbins
Move to gawk-3.1.6.
2615
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2616
		if ((yyvsp[-1]) == NULL) {
2617
			(yyval) = list_create((yyvsp[-2]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2618
			(void) list_prepend((yyval), instruction(Op_push_i));
281.1.1 by john haque
Speed/memory performance improvements.
2619
			(yyval)->nexti->memory = dupnode(Nnull_string);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2620
		} else
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2621
			(yyval) = list_append((yyvsp[-1]), (yyvsp[-2]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2622
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2623
#line 2624 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
2624
    break;
2625
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2626
  case 57:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2627
#line 843 "awkgram.y" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
2628
    {
281.1.4 by john haque
Optimize tail-recursive calls.
2629
		if (! in_function)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2630
			yyerror(_("`return' used outside function context"));
2631
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2632
#line 2633 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
2633
    break;
2634
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2635
  case 58:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2636
#line 846 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2637
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2638
		if ((yyvsp[-1]) == NULL) {
2639
			(yyval) = list_create((yyvsp[-3]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2640
			(void) list_prepend((yyval), instruction(Op_push_i));
281.1.1 by john haque
Speed/memory performance improvements.
2641
			(yyval)->nexti->memory = dupnode(Nnull_string);
281.1.4 by john haque
Optimize tail-recursive calls.
2642
		} else {
408.4.50 by Arnold D. Robbins
Fix -O option.
2643
			if (do_optimize
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2644
				&& (yyvsp[-1])->lasti->opcode == Op_func_call
2645
				&& strcmp((yyvsp[-1])->lasti->func_name, in_function) == 0
281.1.4 by john haque
Optimize tail-recursive calls.
2646
			) {
2647
				/* Do tail recursion optimization. Tail
2648
				 * call without a return value is recognized
2649
				 * in mk_function().
2650
				 */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2651
				((yyvsp[-1])->lasti + 1)->tail_call = true;
281.1.4 by john haque
Optimize tail-recursive calls.
2652
			}
2653
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2654
			(yyval) = list_append((yyvsp[-1]), (yyvsp[-3]));
281.1.4 by john haque
Optimize tail-recursive calls.
2655
		}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2656
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2657
#line 2658 "awkgram.c" /* yacc.c:1646  */
37 by Arnold D. Robbins
Bring in development gawk changes.
2658
    break;
2659
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2660
  case 60:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2661
#line 878 "awkgram.y" /* yacc.c:1646  */
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
2662
    { in_print = true; in_parens = 0; }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2663
#line 2664 "awkgram.c" /* yacc.c:1646  */
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
2664
    break;
2665
2666
  case 61:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2667
#line 879 "awkgram.y" /* yacc.c:1646  */
31 by Arnold D. Robbins
Move to gawk-3.1.3.
2668
    {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2669
		/*
2670
		 * Optimization: plain `print' has no expression list, so $3 is null.
2671
		 * If $3 is NULL or is a bytecode list for $0 use Op_K_print_rec,
2672
		 * which is faster for these two cases.
2673
		 */
2674
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2675
		if ((yyvsp[-3])->opcode == Op_K_print &&
2676
			((yyvsp[-1]) == NULL
2677
				|| ((yyvsp[-1])->lasti->opcode == Op_field_spec
2678
					&& (yyvsp[-1])->nexti->nexti->nexti == (yyvsp[-1])->lasti
2679
					&& (yyvsp[-1])->nexti->nexti->opcode == Op_push_i
2680
					&& (yyvsp[-1])->nexti->nexti->memory->type == Node_val)
281.1.1 by john haque
Speed/memory performance improvements.
2681
			)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2682
		) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
2683
			static bool warned = false;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2684
			/*   -----------------
2685
			 *      output_redir
2686
			 *    [ redirect exp ]
2687
			 *   -----------------
2688
			 *     expression_list
2689
			 *   ------------------
2690
			 *    [Op_K_print_rec | NULL | redir_type | expr_count]
2691
			 */
2692
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2693
			if ((yyvsp[-1]) != NULL) {
2694
				NODE *n = (yyvsp[-1])->nexti->nexti->memory;
306 by john haque
Add arbitrary-precision arithmetic on integers.
2695
2696
				if (! iszero(n))
2697
					goto regular_print;
2698
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2699
				bcfree((yyvsp[-1])->lasti);			/* Op_field_spec */
306 by john haque
Add arbitrary-precision arithmetic on integers.
2700
				unref(n);				/* Node_val */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2701
				bcfree((yyvsp[-1])->nexti->nexti);		/* Op_push_i */
2702
				bcfree((yyvsp[-1])->nexti);			/* Op_list */
2703
				bcfree((yyvsp[-1]));				/* Op_list */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2704
			} else {
2705
				if (do_lint && (rule == BEGIN || rule == END) && ! warned) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
2706
					warned = true;
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2707
					lintwarn_ln((yyvsp[-3])->source_line,
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2708
		_("plain `print' in BEGIN or END rule should probably be `print \"\"'"));
2709
				}
2710
			}
2711
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2712
			(yyvsp[-3])->expr_count = 0;
2713
			(yyvsp[-3])->opcode = Op_K_print_rec;
2714
			if ((yyvsp[0]) == NULL) {    /* no redircetion */
2715
				(yyvsp[-3])->redir_type = redirect_none;
2716
				(yyval) = list_create((yyvsp[-3]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2717
			} else {
2718
				INSTRUCTION *ip;
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2719
				ip = (yyvsp[0])->nexti;
2720
				(yyvsp[-3])->redir_type = ip->redir_type;
2721
				(yyvsp[0])->nexti = ip->nexti;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2722
				bcfree(ip);
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2723
				(yyval) = list_append((yyvsp[0]), (yyvsp[-3]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2724
			}
31 by Arnold D. Robbins
Move to gawk-3.1.3.
2725
		} else {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2726
			/*   -----------------
2727
			 *    [ output_redir    ]
2728
			 *    [ redirect exp    ]
2729
			 *   -----------------
2730
			 *    [ expression_list ]
2731
			 *   ------------------
2732
			 *    [$1 | NULL | redir_type | expr_count]
2733
			 *
2734
			 */
306 by john haque
Add arbitrary-precision arithmetic on integers.
2735
regular_print:	 
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2736
			if ((yyvsp[0]) == NULL) {		/* no redirection */
2737
				if ((yyvsp[-1]) == NULL)	{	/* printf without arg */
2738
					(yyvsp[-3])->expr_count = 0;
2739
					(yyvsp[-3])->redir_type = redirect_none;
2740
					(yyval) = list_create((yyvsp[-3]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2741
				} else {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2742
					INSTRUCTION *t = (yyvsp[-1]);
2743
					(yyvsp[-3])->expr_count = count_expressions(&t, false);
2744
					(yyvsp[-3])->redir_type = redirect_none;
2745
					(yyval) = list_append(t, (yyvsp[-3]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2746
				}
2747
			} else {
2748
				INSTRUCTION *ip;
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2749
				ip = (yyvsp[0])->nexti;
2750
				(yyvsp[-3])->redir_type = ip->redir_type;
2751
				(yyvsp[0])->nexti = ip->nexti;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2752
				bcfree(ip);
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2753
				if ((yyvsp[-1]) == NULL) {
2754
					(yyvsp[-3])->expr_count = 0;
2755
					(yyval) = list_append((yyvsp[0]), (yyvsp[-3]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2756
				} else {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2757
					INSTRUCTION *t = (yyvsp[-1]);
2758
					(yyvsp[-3])->expr_count = count_expressions(&t, false);
2759
					(yyval) = list_append(list_merge((yyvsp[0]), t), (yyvsp[-3]));
31 by Arnold D. Robbins
Move to gawk-3.1.3.
2760
				}
2761
			}
2762
		}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2763
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2764
#line 2765 "awkgram.c" /* yacc.c:1646  */
31 by Arnold D. Robbins
Move to gawk-3.1.3.
2765
    break;
2766
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2767
  case 62:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2768
#line 976 "awkgram.y" /* yacc.c:1646  */
281.1.1 by john haque
Speed/memory performance improvements.
2769
    { sub_counter = 0; }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2770
#line 2771 "awkgram.c" /* yacc.c:1646  */
281.1.1 by john haque
Speed/memory performance improvements.
2771
    break;
2772
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2773
  case 63:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2774
#line 977 "awkgram.y" /* yacc.c:1646  */
31 by Arnold D. Robbins
Move to gawk-3.1.3.
2775
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2776
		char *arr = (yyvsp[-2])->lextok;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2777
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2778
		(yyvsp[-2])->opcode = Op_push_array;
2779
		(yyvsp[-2])->memory = variable((yyvsp[-2])->source_line, arr, Node_var_new);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2780
319.9.3 by Arnold D. Robbins
More SYMTAB and FUNCTAB improvements.
2781
		if (! do_posix && ! do_traditional) {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2782
			if ((yyvsp[-2])->memory == symbol_table)
319.9.3 by Arnold D. Robbins
More SYMTAB and FUNCTAB improvements.
2783
				fatal(_("`delete' is not allowed with SYMTAB"));
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2784
			else if ((yyvsp[-2])->memory == func_table)
319.9.3 by Arnold D. Robbins
More SYMTAB and FUNCTAB improvements.
2785
				fatal(_("`delete' is not allowed with FUNCTAB"));
2786
		}
319.9.1 by Arnold D. Robbins
First cut at SYMTAB and FUNCTAB.
2787
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2788
		if ((yyvsp[0]) == NULL) {
277.1.168 by Arnold D. Robbins
Update some things that are now POSIX.
2789
			/*
2790
			 * As of September 2012, POSIX has added support
2791
			 * for `delete array'. See:
2792
			 * http://austingroupbugs.net/view.php?id=544
2793
			 *
2794
			 * Thanks to Nathan Weeks for the initiative.
2795
			 *
2796
			 * Thus we no longer warn or check do_posix.
2797
			 * Also, since BWK awk supports it, we don't have to
2798
			 * check do_traditional either.
2799
			 */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2800
			(yyvsp[-3])->expr_count = 0;
2801
			(yyval) = list_append(list_create((yyvsp[-2])), (yyvsp[-3]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2802
		} else {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2803
			(yyvsp[-3])->expr_count = sub_counter;
2804
			(yyval) = list_append(list_append((yyvsp[0]), (yyvsp[-2])), (yyvsp[-3]));
31 by Arnold D. Robbins
Move to gawk-3.1.3.
2805
		}
2806
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2807
#line 2808 "awkgram.c" /* yacc.c:1646  */
31 by Arnold D. Robbins
Move to gawk-3.1.3.
2808
    break;
2809
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2810
  case 64:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2811
#line 1014 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2812
    {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
2813
		static bool warned = false;
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2814
		char *arr = (yyvsp[-1])->lextok;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2815
2816
		if (do_lint && ! warned) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
2817
			warned = true;
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2818
			lintwarn_ln((yyvsp[-3])->source_line,
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
2819
				_("`delete(array)' is a non-portable tawk extension"));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2820
		}
2821
		if (do_traditional) {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2822
			error_ln((yyvsp[-3])->source_line,
277.1.168 by Arnold D. Robbins
Update some things that are now POSIX.
2823
				_("`delete(array)' is a non-portable tawk extension"));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2824
		}
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2825
		(yyvsp[-1])->memory = variable((yyvsp[-1])->source_line, arr, Node_var_new);
2826
		(yyvsp[-1])->opcode = Op_push_array;
2827
		(yyvsp[-3])->expr_count = 0;
2828
		(yyval) = list_append(list_create((yyvsp[-1])), (yyvsp[-3]));
319.9.1 by Arnold D. Robbins
First cut at SYMTAB and FUNCTAB.
2829
319.9.3 by Arnold D. Robbins
More SYMTAB and FUNCTAB improvements.
2830
		if (! do_posix && ! do_traditional) {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2831
			if ((yyvsp[-1])->memory == symbol_table)
319.9.3 by Arnold D. Robbins
More SYMTAB and FUNCTAB improvements.
2832
				fatal(_("`delete' is not allowed with SYMTAB"));
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2833
			else if ((yyvsp[-1])->memory == func_table)
319.9.3 by Arnold D. Robbins
More SYMTAB and FUNCTAB improvements.
2834
				fatal(_("`delete' is not allowed with FUNCTAB"));
2835
		}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2836
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2837
#line 2838 "awkgram.c" /* yacc.c:1646  */
31 by Arnold D. Robbins
Move to gawk-3.1.3.
2838
    break;
2839
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2840
  case 65:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2841
#line 1040 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2842
    {	(yyval) = optimize_assignment((yyvsp[0])); }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2843
#line 2844 "awkgram.c" /* yacc.c:1646  */
281.1.1 by john haque
Speed/memory performance improvements.
2844
    break;
2845
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2846
  case 66:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2847
#line 1045 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
2848
    { (yyval) = NULL; }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2849
#line 2850 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
2850
    break;
2851
2852
  case 67:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2853
#line 1047 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2854
    { (yyval) = (yyvsp[0]); }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2855
#line 2856 "awkgram.c" /* yacc.c:1646  */
277.1.11 by Arnold D. Robbins
Fix gsub and getline pass by reference. Add tests.
2856
    break;
2857
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2858
  case 68:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2859
#line 1052 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
2860
    { (yyval) = NULL; }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2861
#line 2862 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
2862
    break;
2863
2864
  case 69:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2865
#line 1054 "awkgram.y" /* yacc.c:1646  */
116 by Arnold D. Robbins
Fix switch debugging.
2866
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2867
		if ((yyvsp[-1]) == NULL)
2868
			(yyval) = list_create((yyvsp[0]));
116 by Arnold D. Robbins
Fix switch debugging.
2869
		else
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2870
			(yyval) = list_prepend((yyvsp[-1]), (yyvsp[0]));
116 by Arnold D. Robbins
Fix switch debugging.
2871
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2872
#line 2873 "awkgram.c" /* yacc.c:1646  */
37 by Arnold D. Robbins
Bring in development gawk changes.
2873
    break;
2874
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2875
  case 70:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2876
#line 1061 "awkgram.y" /* yacc.c:1646  */
281.1.1 by john haque
Speed/memory performance improvements.
2877
    { (yyval) = NULL; }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2878
#line 2879 "awkgram.c" /* yacc.c:1646  */
281.1.1 by john haque
Speed/memory performance improvements.
2879
    break;
2880
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2881
  case 71:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2882
#line 1066 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2883
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2884
		INSTRUCTION *casestmt = (yyvsp[0]);
2885
		if ((yyvsp[0]) == NULL)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2886
			casestmt = list_create(instruction(Op_no_op));	
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
2887
		if (do_pretty_print)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2888
			(void) list_prepend(casestmt, instruction(Op_exec_count));
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2889
		(yyvsp[-4])->case_exp = (yyvsp[-3]);
2890
		(yyvsp[-4])->case_stmt = casestmt;
2891
		bcfree((yyvsp[-2]));
2892
		(yyval) = (yyvsp[-4]);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2893
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2894
#line 2895 "awkgram.c" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2895
    break;
2896
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2897
  case 72:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2898
#line 1078 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2899
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2900
		INSTRUCTION *casestmt = (yyvsp[0]);
2901
		if ((yyvsp[0]) == NULL)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2902
			casestmt = list_create(instruction(Op_no_op));
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
2903
		if (do_pretty_print)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2904
			(void) list_prepend(casestmt, instruction(Op_exec_count));
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2905
		bcfree((yyvsp[-2]));
2906
		(yyvsp[-3])->case_stmt = casestmt;
2907
		(yyval) = (yyvsp[-3]);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2908
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2909
#line 2910 "awkgram.c" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2910
    break;
2911
37 by Arnold D. Robbins
Bring in development gawk changes.
2912
  case 73:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2913
#line 1092 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
2914
    {	(yyval) = (yyvsp[0]); }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2915
#line 2916 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
2916
    break;
2917
2918
  case 74:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2919
#line 1094 "awkgram.y" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2920
    { 
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2921
		NODE *n = (yyvsp[0])->memory;
300 by john haque
Add infrastructure for MPFR/GMP support.
2922
		(void) force_number(n);
302.1.1 by john haque
Finish MPFR changes and clean up code.
2923
		negate_num(n);
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2924
		bcfree((yyvsp[-1]));
2925
		(yyval) = (yyvsp[0]);
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2926
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2927
#line 2928 "awkgram.c" /* yacc.c:1646  */
277.1.11 by Arnold D. Robbins
Fix gsub and getline pass by reference. Add tests.
2928
    break;
2929
37 by Arnold D. Robbins
Bring in development gawk changes.
2930
  case 75:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2931
#line 1102 "awkgram.y" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2932
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2933
		bcfree((yyvsp[-1]));
2934
		(yyval) = (yyvsp[0]);
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2935
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2936
#line 2937 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2937
    break;
2938
2939
  case 76:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2940
#line 1107 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
2941
    {	(yyval) = (yyvsp[0]); }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2942
#line 2943 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
2943
    break;
2944
2945
  case 77:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2946
#line 1109 "awkgram.y" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2947
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2948
		(yyvsp[0])->opcode = Op_push_re;
2949
		(yyval) = (yyvsp[0]);
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2950
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2951
#line 2952 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2952
    break;
2953
2954
  case 78:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2955
#line 1117 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
2956
    { (yyval) = (yyvsp[0]); }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2957
#line 2958 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
2958
    break;
2959
2960
  case 79:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2961
#line 1119 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2962
    { (yyval) = (yyvsp[0]); }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2963
#line 2964 "awkgram.c" /* yacc.c:1646  */
408.13.37 by Arnold D. Robbins
Remove deferred variables.
2964
    break;
2965
2966
  case 81:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2967
#line 1129 "awkgram.y" /* yacc.c:1646  */
408.13.37 by Arnold D. Robbins
Remove deferred variables.
2968
    {
2969
		(yyval) = (yyvsp[-1]);
2970
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2971
#line 2972 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2972
    break;
2973
2974
  case 82:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2975
#line 1136 "awkgram.y" /* yacc.c:1646  */
116 by Arnold D. Robbins
Fix switch debugging.
2976
    {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
2977
		in_print = false;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2978
		in_parens = 0;
2979
		(yyval) = NULL;
2980
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2981
#line 2982 "awkgram.c" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2982
    break;
2983
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
2984
  case 83:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2985
#line 1141 "awkgram.y" /* yacc.c:1646  */
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
2986
    { in_print = false; in_parens = 0; }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2987
#line 2988 "awkgram.c" /* yacc.c:1646  */
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
2988
    break;
2989
2990
  case 84:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2991
#line 1142 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2992
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2993
		if ((yyvsp[-2])->redir_type == redirect_twoway
2994
		    	&& (yyvsp[0])->lasti->opcode == Op_K_getline_redir
2995
		   	 	&& (yyvsp[0])->lasti->redir_type == redirect_twoway)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2996
			yyerror(_("multistage two-way pipelines don't work"));
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
2997
		(yyval) = list_prepend((yyvsp[0]), (yyvsp[-2]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
2998
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
2999
#line 3000 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
3000
    break;
3001
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3002
  case 85:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
3003
#line 1153 "awkgram.y" /* yacc.c:1646  */
281.1.1 by john haque
Speed/memory performance improvements.
3004
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3005
		(yyval) = mk_condition((yyvsp[-3]), (yyvsp[-5]), (yyvsp[0]), NULL, NULL);
281.1.1 by john haque
Speed/memory performance improvements.
3006
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
3007
#line 3008 "awkgram.c" /* yacc.c:1646  */
281.1.1 by john haque
Speed/memory performance improvements.
3008
    break;
3009
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3010
  case 86:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
3011
#line 1158 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3012
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3013
		(yyval) = mk_condition((yyvsp[-6]), (yyvsp[-8]), (yyvsp[-3]), (yyvsp[-2]), (yyvsp[0]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3014
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
3015
#line 3016 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
3016
    break;
3017
281.1.1 by john haque
Speed/memory performance improvements.
3018
  case 91:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
3019
#line 1175 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3020
    { (yyval) = NULL; }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
3021
#line 3022 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3022
    break;
3023
3024
  case 92:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
3025
#line 1177 "awkgram.y" /* yacc.c:1646  */
408.13.37 by Arnold D. Robbins
Remove deferred variables.
3026
    {
3027
		bcfree((yyvsp[-1]));
3028
		(yyval) = (yyvsp[0]);
3029
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
3030
#line 3031 "awkgram.c" /* yacc.c:1646  */
408.13.37 by Arnold D. Robbins
Remove deferred variables.
3031
    break;
3032
3033
  case 93:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
3034
#line 1185 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3035
    { (yyval) = NULL; }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
3036
#line 3037 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3037
    break;
3038
3039
  case 94:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
3040
#line 1187 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3041
    { (yyval) = (yyvsp[0]) ; }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
3042
#line 3043 "awkgram.c" /* yacc.c:1646  */
277.1.11 by Arnold D. Robbins
Fix gsub and getline pass by reference. Add tests.
3043
    break;
3044
3045
  case 95:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
3046
#line 1192 "awkgram.y" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3047
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3048
		(yyvsp[0])->param_count = 0;
3049
		(yyval) = list_create((yyvsp[0]));
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3050
	  }
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
3051
#line 3052 "awkgram.c" /* yacc.c:1646  */
116 by Arnold D. Robbins
Fix switch debugging.
3052
    break;
3053
277.1.11 by Arnold D. Robbins
Fix gsub and getline pass by reference. Add tests.
3054
  case 96:
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
3055
#line 1197 "awkgram.y" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3056
    {
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3057
		if ((yyvsp[-2]) != NULL && (yyvsp[0]) != NULL) {
3058
			(yyvsp[0])->param_count =  (yyvsp[-2])->lasti->param_count + 1;
3059
			(yyval) = list_append((yyvsp[-2]), (yyvsp[0]));
3060
			yyerrok;
3061
		} else
3062
			(yyval) = NULL;
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3063
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3064
#line 3065 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
3065
    break;
3066
3067
  case 97:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3068
#line 1206 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3069
    { (yyval) = NULL; }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3070
#line 3071 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3071
    break;
3072
3073
  case 98:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3074
#line 1208 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3075
    { (yyval) = (yyvsp[-1]); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3076
#line 3077 "awkgram.c" /* yacc.c:1646  */
277.1.11 by Arnold D. Robbins
Fix gsub and getline pass by reference. Add tests.
3077
    break;
3078
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3079
  case 99:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3080
#line 1210 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3081
    { (yyval) = (yyvsp[-2]); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3082
#line 3083 "awkgram.c" /* yacc.c:1646  */
277.1.11 by Arnold D. Robbins
Fix gsub and getline pass by reference. Add tests.
3083
    break;
3084
3085
  case 100:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3086
#line 1216 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3087
    { (yyval) = NULL; }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3088
#line 3089 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3089
    break;
3090
3091
  case 101:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3092
#line 1218 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3093
    { (yyval) = (yyvsp[0]); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3094
#line 3095 "awkgram.c" /* yacc.c:1646  */
31 by Arnold D. Robbins
Move to gawk-3.1.3.
3095
    break;
3096
37 by Arnold D. Robbins
Bring in development gawk changes.
3097
  case 102:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3098
#line 1223 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3099
    { (yyval) = NULL; }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3100
#line 3101 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3101
    break;
3102
3103
  case 103:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3104
#line 1225 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3105
    { (yyval) = (yyvsp[0]); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3106
#line 3107 "awkgram.c" /* yacc.c:1646  */
277.1.11 by Arnold D. Robbins
Fix gsub and getline pass by reference. Add tests.
3107
    break;
3108
3109
  case 104:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3110
#line 1230 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3111
    {	(yyval) = mk_expression_list(NULL, (yyvsp[0])); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3112
#line 3113 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
3113
    break;
3114
277.1.11 by Arnold D. Robbins
Fix gsub and getline pass by reference. Add tests.
3115
  case 105:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3116
#line 1232 "awkgram.y" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3117
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3118
		(yyval) = mk_expression_list((yyvsp[-2]), (yyvsp[0]));
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3119
		yyerrok;
3120
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3121
#line 3122 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
3122
    break;
3123
277.1.11 by Arnold D. Robbins
Fix gsub and getline pass by reference. Add tests.
3124
  case 106:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3125
#line 1237 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3126
    { (yyval) = NULL; }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3127
#line 3128 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3128
    break;
3129
3130
  case 107:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3131
#line 1239 "awkgram.y" /* yacc.c:1646  */
277.1.214 by Arnold D. Robbins
Bug fix for expression list error.
3132
    {
3133
		/*
3134
		 * Returning the expression list instead of NULL lets
3135
		 * snode get a list of arguments that it can count.
3136
		 */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3137
		(yyval) = (yyvsp[-1]);
277.1.214 by Arnold D. Robbins
Bug fix for expression list error.
3138
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3139
#line 3140 "awkgram.c" /* yacc.c:1646  */
281.1.1 by john haque
Speed/memory performance improvements.
3140
    break;
3141
31 by Arnold D. Robbins
Move to gawk-3.1.3.
3142
  case 108:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3143
#line 1247 "awkgram.y" /* yacc.c:1646  */
277.1.214 by Arnold D. Robbins
Bug fix for expression list error.
3144
    {
3145
		/* Ditto */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3146
		(yyval) = mk_expression_list((yyvsp[-2]), (yyvsp[0]));
277.1.214 by Arnold D. Robbins
Bug fix for expression list error.
3147
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3148
#line 3149 "awkgram.c" /* yacc.c:1646  */
277.1.11 by Arnold D. Robbins
Fix gsub and getline pass by reference. Add tests.
3149
    break;
3150
3151
  case 109:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3152
#line 1252 "awkgram.y" /* yacc.c:1646  */
277.1.214 by Arnold D. Robbins
Bug fix for expression list error.
3153
    {
3154
		/* Ditto */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3155
		(yyval) = (yyvsp[-2]);
277.1.214 by Arnold D. Robbins
Bug fix for expression list error.
3156
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3157
#line 3158 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3158
    break;
3159
3160
  case 110:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3161
#line 1261 "awkgram.y" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3162
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3163
		if (do_lint && (yyvsp[0])->lasti->opcode == Op_match_rec)
3164
			lintwarn_ln((yyvsp[-1])->source_line,
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3165
				_("regular expression on right of assignment"));
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3166
		(yyval) = mk_assignment((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1]));
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3167
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3168
#line 3169 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3169
    break;
3170
3171
  case 111:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3172
#line 1268 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3173
    {	(yyval) = mk_boolean((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3174
#line 3175 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3175
    break;
3176
3177
  case 112:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3178
#line 1270 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3179
    {	(yyval) = mk_boolean((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3180
#line 3181 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3181
    break;
3182
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3183
  case 113:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3184
#line 1272 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3185
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3186
		if ((yyvsp[-2])->lasti->opcode == Op_match_rec)
3187
			warning_ln((yyvsp[-1])->source_line,
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
3188
				_("regular expression on left of `~' or `!~' operator"));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3189
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
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]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3195
		} else {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3196
			(yyvsp[-1])->memory = make_regnode(Node_dynregex, NULL);
3197
			(yyval) = list_append(list_merge((yyvsp[-2]), (yyvsp[0])), (yyvsp[-1]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3198
		}
3199
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3200
#line 3201 "awkgram.c" /* yacc.c:1646  */
37 by Arnold D. Robbins
Bring in development gawk changes.
3201
    break;
3202
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3203
  case 114:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3204
#line 1288 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3205
    {
3206
		if (do_lint_old)
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3207
			warning_ln((yyvsp[-1])->source_line,
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
3208
				_("old awk does not support the keyword `in' except after `for'"));
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
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]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3213
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3214
#line 3215 "awkgram.c" /* yacc.c:1646  */
37 by Arnold D. Robbins
Bring in development gawk changes.
3215
    break;
3216
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3217
  case 115:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3218
#line 1298 "awkgram.y" /* yacc.c:1646  */
281.1.1 by john haque
Speed/memory performance improvements.
3219
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3220
		if (do_lint && (yyvsp[0])->lasti->opcode == Op_match_rec)
3221
			lintwarn_ln((yyvsp[-1])->source_line,
281.1.1 by john haque
Speed/memory performance improvements.
3222
				_("regular expression on right of comparison"));
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3223
		(yyval) = list_append(list_merge((yyvsp[-2]), (yyvsp[0])), (yyvsp[-1]));
281.1.1 by john haque
Speed/memory performance improvements.
3224
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3225
#line 3226 "awkgram.c" /* yacc.c:1646  */
281.1.1 by john haque
Speed/memory performance improvements.
3226
    break;
3227
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3228
  case 116:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3229
#line 1305 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3230
    { (yyval) = mk_condition((yyvsp[-4]), (yyvsp[-3]), (yyvsp[-2]), (yyvsp[-1]), (yyvsp[0])); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3231
#line 3232 "awkgram.c" /* yacc.c:1646  */
116 by Arnold D. Robbins
Fix switch debugging.
3232
    break;
3233
281.1.1 by john haque
Speed/memory performance improvements.
3234
  case 117:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3235
#line 1307 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3236
    { (yyval) = (yyvsp[0]); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3237
#line 3238 "awkgram.c" /* yacc.c:1646  */
281.1.1 by john haque
Speed/memory performance improvements.
3238
    break;
3239
116 by Arnold D. Robbins
Fix switch debugging.
3240
  case 118:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3241
#line 1312 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3242
    { (yyval) = (yyvsp[0]); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3243
#line 3244 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3244
    break;
3245
3246
  case 119:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3247
#line 1314 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3248
    { (yyval) = (yyvsp[0]); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3249
#line 3250 "awkgram.c" /* yacc.c:1646  */
277.1.11 by Arnold D. Robbins
Fix gsub and getline pass by reference. Add tests.
3250
    break;
3251
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3252
  case 120:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3253
#line 1316 "awkgram.y" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3254
    {	
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3255
		(yyvsp[0])->opcode = Op_assign_quotient;
3256
		(yyval) = (yyvsp[0]);
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3257
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3258
#line 3259 "awkgram.c" /* yacc.c:1646  */
277.1.11 by Arnold D. Robbins
Fix gsub and getline pass by reference. Add tests.
3259
    break;
3260
3261
  case 121:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3262
#line 1324 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3263
    { (yyval) = (yyvsp[0]); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3264
#line 3265 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3265
    break;
3266
3267
  case 122:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3268
#line 1326 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3269
    { (yyval) = (yyvsp[0]); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3270
#line 3271 "awkgram.c" /* yacc.c:1646  */
277.1.11 by Arnold D. Robbins
Fix gsub and getline pass by reference. Add tests.
3271
    break;
3272
3273
  case 123:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3274
#line 1331 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3275
    { (yyval) = (yyvsp[0]); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3276
#line 3277 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3277
    break;
3278
3279
  case 124:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3280
#line 1333 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3281
    { (yyval) = (yyvsp[0]); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3282
#line 3283 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3283
    break;
3284
3285
  case 125:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3286
#line 1338 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3287
    { (yyval) = (yyvsp[0]); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3288
#line 3289 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3289
    break;
3290
3291
  case 126:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3292
#line 1340 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3293
    { (yyval) = (yyvsp[0]); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3294
#line 3295 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3295
    break;
3296
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3297
  case 127:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3298
#line 1342 "awkgram.y" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
3299
    {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3300
		int count = 2;
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
3301
		bool is_simple_var = false;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3302
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3303
		if ((yyvsp[-1])->lasti->opcode == Op_concat) {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3304
			/* multiple (> 2) adjacent strings optimization */
408.13.111 by Arnold D. Robbins
Minor code cleanups.
3305
			is_simple_var = ((yyvsp[-1])->lasti->concat_flag & CSVAR) != 0;
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3306
			count = (yyvsp[-1])->lasti->expr_count + 1;
3307
			(yyvsp[-1])->lasti->opcode = Op_no_op;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3308
		} else {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3309
			is_simple_var = ((yyvsp[-1])->nexti->opcode == Op_push
3310
					&& (yyvsp[-1])->lasti == (yyvsp[-1])->nexti); /* first exp. is a simple
281.1.1 by john haque
Speed/memory performance improvements.
3311
					                             * variable?; kludge for use
3312
					                             * in Op_assign_concat.
3313
		 			                             */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3314
		}
109 by Arnold D. Robbins
Bug fixes and cleanup.
3315
408.4.50 by Arnold D. Robbins
Fix -O option.
3316
		if (do_optimize
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
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
109 by Arnold D. Robbins
Bug fixes and cleanup.
3319
		) {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3320
			NODE *n1 = (yyvsp[-1])->nexti->memory;
3321
			NODE *n2 = (yyvsp[0])->nexti->memory;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3322
			size_t nlen;
3323
281.1.1 by john haque
Speed/memory performance improvements.
3324
			n1 = force_string(n1);
3325
			n2 = force_string(n2);
109 by Arnold D. Robbins
Bug fixes and cleanup.
3326
			nlen = n1->stlen + n2->stlen;
3327
			erealloc(n1->stptr, char *, nlen + 2, "constant fold");
3328
			memcpy(n1->stptr + n1->stlen, n2->stptr, n2->stlen);
3329
			n1->stlen = nlen;
3330
			n1->stptr[nlen] = '\0';
281.1.1 by john haque
Speed/memory performance improvements.
3331
			n1->flags &= ~(NUMCUR|NUMBER|NUMINT);
109 by Arnold D. Robbins
Bug fixes and cleanup.
3332
			n1->flags |= (STRING|STRCUR);
3333
			unref(n2);
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3334
			bcfree((yyvsp[0])->nexti);
3335
			bcfree((yyvsp[0]));
3336
			(yyval) = (yyvsp[-1]);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3337
		} else {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3338
			(yyval) = list_append(list_merge((yyvsp[-1]), (yyvsp[0])), instruction(Op_concat));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3339
			(yyval)->lasti->concat_flag = (is_simple_var ? CSVAR : 0);
3340
			(yyval)->lasti->expr_count = count;
3341
			if (count > max_args)
3342
				max_args = count;
3343
		}
3344
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3345
#line 3346 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
3346
    break;
3347
277.1.11 by Arnold D. Robbins
Fix gsub and getline pass by reference. Add tests.
3348
  case 129:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3349
#line 1394 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3350
    { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3351
#line 3352 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3352
    break;
3353
3354
  case 130:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3355
#line 1396 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3356
    { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3357
#line 3358 "awkgram.c" /* yacc.c:1646  */
34 by Arnold D. Robbins
Move to gawk-3.1.6.
3358
    break;
3359
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3360
  case 131:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3361
#line 1398 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3362
    { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3363
#line 3364 "awkgram.c" /* yacc.c:1646  */
34 by Arnold D. Robbins
Move to gawk-3.1.6.
3364
    break;
3365
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3366
  case 132:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3367
#line 1400 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3368
    { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3369
#line 3370 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3370
    break;
3371
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3372
  case 133:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3373
#line 1402 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3374
    { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3375
#line 3376 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3376
    break;
3377
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3378
  case 134:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3379
#line 1404 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3380
    { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3381
#line 3382 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3382
    break;
3383
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3384
  case 135:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3385
#line 1406 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3386
    {
3387
		/*
408.5.182 by Arnold D. Robbins
Allow any redirected getline inside BEGINFILE/ENDFILE.
3388
		 * In BEGINFILE/ENDFILE, allow `getline [var] < file'
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3389
		 */
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
3390
408.5.182 by Arnold D. Robbins
Allow any redirected getline inside BEGINFILE/ENDFILE.
3391
		if ((rule == BEGINFILE || rule == ENDFILE) && (yyvsp[0]) == NULL)
3392
			error_ln((yyvsp[-2])->source_line,
3393
				 _("non-redirected `getline' invalid inside `%s' rule"), ruletab[rule]);
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3394
		if (do_lint && rule == END && (yyvsp[0]) == NULL)
3395
			lintwarn_ln((yyvsp[-2])->source_line,
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
3396
				_("non-redirected `getline' undefined inside END action"));
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3397
		(yyval) = mk_getline((yyvsp[-2]), (yyvsp[-1]), (yyvsp[0]), redirect_input);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3398
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3399
#line 3400 "awkgram.c" /* yacc.c:1646  */
408.5.182 by Arnold D. Robbins
Allow any redirected getline inside BEGINFILE/ENDFILE.
3400
    break;
3401
3402
  case 136:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3403
#line 1420 "awkgram.y" /* yacc.c:1646  */
408.5.182 by Arnold D. Robbins
Allow any redirected getline inside BEGINFILE/ENDFILE.
3404
    {
3405
		(yyvsp[0])->opcode = Op_postincrement;
3406
		(yyval) = mk_assignment((yyvsp[-1]), NULL, (yyvsp[0]));
3407
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3408
#line 3409 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
3409
    break;
3410
408.5.182 by Arnold D. Robbins
Allow any redirected getline inside BEGINFILE/ENDFILE.
3411
  case 137:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3412
#line 1425 "awkgram.y" /* yacc.c:1646  */
281.1.1 by john haque
Speed/memory performance improvements.
3413
    {
408.5.182 by Arnold D. Robbins
Allow any redirected getline inside BEGINFILE/ENDFILE.
3414
		(yyvsp[0])->opcode = Op_postdecrement;
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3415
		(yyval) = mk_assignment((yyvsp[-1]), NULL, (yyvsp[0]));
281.1.1 by john haque
Speed/memory performance improvements.
3416
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3417
#line 3418 "awkgram.c" /* yacc.c:1646  */
281.1.1 by john haque
Speed/memory performance improvements.
3418
    break;
3419
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3420
  case 138:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3421
#line 1430 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3422
    {
3423
		if (do_lint_old) {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3424
		    warning_ln((yyvsp[-1])->source_line,
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
3425
				_("old awk does not support the keyword `in' except after `for'"));
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3426
		    warning_ln((yyvsp[-1])->source_line,
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
3427
				_("old awk does not support multidimensional arrays"));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3428
		}
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3429
		(yyvsp[0])->nexti->opcode = Op_push_array;
3430
		(yyvsp[-1])->opcode = Op_in_array;
3431
		if ((yyvsp[-3]) == NULL) {	/* error */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3432
			errcount++;
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3433
			(yyvsp[-1])->expr_count = 0;
3434
			(yyval) = list_merge((yyvsp[0]), (yyvsp[-1]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3435
		} else {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3436
			INSTRUCTION *t = (yyvsp[-3]);
3437
			(yyvsp[-1])->expr_count = count_expressions(&t, false);
3438
			(yyval) = list_append(list_merge(t, (yyvsp[0])), (yyvsp[-1]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3439
		}
3440
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3441
#line 3442 "awkgram.c" /* yacc.c:1646  */
34 by Arnold D. Robbins
Move to gawk-3.1.6.
3442
    break;
3443
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3444
  case 139:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3445
#line 1455 "awkgram.y" /* yacc.c:1646  */
116 by Arnold D. Robbins
Fix switch debugging.
3446
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3447
		  (yyval) = mk_getline((yyvsp[-1]), (yyvsp[0]), (yyvsp[-3]), (yyvsp[-2])->redir_type);
3448
		  bcfree((yyvsp[-2]));
116 by Arnold D. Robbins
Fix switch debugging.
3449
		}
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3450
#line 3451 "awkgram.c" /* yacc.c:1646  */
116 by Arnold D. Robbins
Fix switch debugging.
3451
    break;
3452
277.1.11 by Arnold D. Robbins
Fix gsub and getline pass by reference. Add tests.
3453
  case 140:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3454
#line 1461 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3455
    { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3456
#line 3457 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3457
    break;
3458
3459
  case 141:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3460
#line 1463 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3461
    { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3462
#line 3463 "awkgram.c" /* yacc.c:1646  */
34 by Arnold D. Robbins
Move to gawk-3.1.6.
3463
    break;
3464
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3465
  case 142:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3466
#line 1465 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3467
    { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3468
#line 3469 "awkgram.c" /* yacc.c:1646  */
37 by Arnold D. Robbins
Bring in development gawk changes.
3469
    break;
3470
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3471
  case 143:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3472
#line 1467 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3473
    { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3474
#line 3475 "awkgram.c" /* yacc.c:1646  */
37 by Arnold D. Robbins
Bring in development gawk changes.
3475
    break;
3476
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3477
  case 144:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3478
#line 1469 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3479
    { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3480
#line 3481 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3481
    break;
3482
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3483
  case 145:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3484
#line 1471 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3485
    { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3486
#line 3487 "awkgram.c" /* yacc.c:1646  */
408.13.37 by Arnold D. Robbins
Remove deferred variables.
3487
    break;
3488
3489
  case 146:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3490
#line 1476 "awkgram.y" /* yacc.c:1646  */
408.13.37 by Arnold D. Robbins
Remove deferred variables.
3491
    {
3492
		(yyval) = list_create((yyvsp[0]));
3493
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3494
#line 3495 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3495
    break;
3496
3497
  case 147:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3498
#line 1480 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3499
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3500
		if ((yyvsp[0])->opcode == Op_match_rec) {
3501
			(yyvsp[0])->opcode = Op_nomatch;
3502
			(yyvsp[-1])->opcode = Op_push_i;
3503
			(yyvsp[-1])->memory = make_number(0.0);	
3504
			(yyval) = list_append(list_append(list_create((yyvsp[-1])),
3505
						instruction(Op_field_spec)), (yyvsp[0]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3506
		} else {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3507
			if (do_optimize && (yyvsp[0])->nexti == (yyvsp[0])->lasti
3508
					&& (yyvsp[0])->nexti->opcode == Op_push_i
3509
					&& ((yyvsp[0])->nexti->memory->flags & (MPFN|MPZN)) == 0
109 by Arnold D. Robbins
Bug fixes and cleanup.
3510
			) {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3511
				NODE *n = (yyvsp[0])->nexti->memory;
109 by Arnold D. Robbins
Bug fixes and cleanup.
3512
				if ((n->flags & (STRCUR|STRING)) != 0) {
3513
					n->numbr = (AWKNUM) (n->stlen == 0);
3514
					n->flags &= ~(STRCUR|STRING);
3515
					n->flags |= (NUMCUR|NUMBER);
3516
					efree(n->stptr);
3517
					n->stptr = NULL;
3518
					n->stlen = 0;
3519
				} else
3520
					n->numbr = (AWKNUM) (n->numbr == 0.0);
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3521
				bcfree((yyvsp[-1]));
3522
				(yyval) = (yyvsp[0]);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3523
			} else {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3524
				(yyvsp[-1])->opcode = Op_not;
3525
				add_lint((yyvsp[0]), LINT_assign_in_cond);
3526
				(yyval) = list_append((yyvsp[0]), (yyvsp[-1]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3527
			}
3528
		}
3529
	   }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3530
#line 3531 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
3531
    break;
3532
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3533
  case 148:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3534
#line 1512 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3535
    { (yyval) = (yyvsp[-1]); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3536
#line 3537 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3537
    break;
3538
3539
  case 149:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3540
#line 1514 "awkgram.y" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3541
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3542
		(yyval) = snode((yyvsp[-1]), (yyvsp[-3]));
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3543
		if ((yyval) == NULL)
3544
			YYABORT;
3545
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3546
#line 3547 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3547
    break;
3548
3549
  case 150:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3550
#line 1520 "awkgram.y" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3551
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3552
		(yyval) = snode((yyvsp[-1]), (yyvsp[-3]));
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3553
		if ((yyval) == NULL)
3554
			YYABORT;
3555
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3556
#line 3557 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3557
    break;
3558
3559
  case 151:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3560
#line 1526 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3561
    {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
3562
		static bool warned = false;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3563
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
3564
		if (do_lint && ! warned) {
3565
			warned = true;
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3566
			lintwarn_ln((yyvsp[0])->source_line,
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
3567
				_("call of `length' without parentheses is not portable"));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3568
		}
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3569
		(yyval) = snode(NULL, (yyvsp[0]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3570
		if ((yyval) == NULL)
3571
			YYABORT;
37 by Arnold D. Robbins
Bring in development gawk changes.
3572
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3573
#line 3574 "awkgram.c" /* yacc.c:1646  */
37 by Arnold D. Robbins
Bring in development gawk changes.
3574
    break;
3575
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3576
  case 154:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3577
#line 1541 "awkgram.y" /* yacc.c:1646  */
281.1.1 by john haque
Speed/memory performance improvements.
3578
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3579
		(yyvsp[-1])->opcode = Op_preincrement;
3580
		(yyval) = mk_assignment((yyvsp[0]), NULL, (yyvsp[-1]));
281.1.1 by john haque
Speed/memory performance improvements.
3581
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3582
#line 3583 "awkgram.c" /* yacc.c:1646  */
281.1.1 by john haque
Speed/memory performance improvements.
3583
    break;
3584
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3585
  case 155:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3586
#line 1546 "awkgram.y" /* yacc.c:1646  */
116 by Arnold D. Robbins
Fix switch debugging.
3587
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3588
		(yyvsp[-1])->opcode = Op_predecrement;
3589
		(yyval) = mk_assignment((yyvsp[0]), NULL, (yyvsp[-1]));
116 by Arnold D. Robbins
Fix switch debugging.
3590
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3591
#line 3592 "awkgram.c" /* yacc.c:1646  */
408.13.37 by Arnold D. Robbins
Remove deferred variables.
3592
    break;
3593
3594
  case 156:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3595
#line 1551 "awkgram.y" /* yacc.c:1646  */
408.13.37 by Arnold D. Robbins
Remove deferred variables.
3596
    {
3597
		(yyval) = list_create((yyvsp[0]));
3598
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3599
#line 3600 "awkgram.c" /* yacc.c:1646  */
116 by Arnold D. Robbins
Fix switch debugging.
3600
    break;
3601
408.13.37 by Arnold D. Robbins
Remove deferred variables.
3602
  case 157:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3603
#line 1555 "awkgram.y" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3604
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3605
		(yyval) = list_create((yyvsp[0]));
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3606
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3607
#line 3608 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3608
    break;
3609
3610
  case 158:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3611
#line 1559 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3612
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3613
		if ((yyvsp[0])->lasti->opcode == Op_push_i
3614
			&& ((yyvsp[0])->lasti->memory->flags & (STRCUR|STRING)) == 0
281.1.1 by john haque
Speed/memory performance improvements.
3615
		) {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3616
			NODE *n = (yyvsp[0])->lasti->memory;
300 by john haque
Add infrastructure for MPFR/GMP support.
3617
			(void) force_number(n);
302.1.1 by john haque
Finish MPFR changes and clean up code.
3618
			negate_num(n);			
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3619
			(yyval) = (yyvsp[0]);
3620
			bcfree((yyvsp[-1]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3621
		} else {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3622
			(yyvsp[-1])->opcode = Op_unary_minus;
3623
			(yyval) = list_append((yyvsp[0]), (yyvsp[-1]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3624
		}
3625
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3626
#line 3627 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
3627
    break;
3628
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3629
  case 159:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3630
#line 1574 "awkgram.y" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
3631
    {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3632
	    /*
3633
	     * was: $$ = $2
3634
	     * POSIX semantics: force a conversion to numeric type
3635
	     */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3636
		(yyvsp[-1])->opcode = Op_plus_i;
3637
		(yyvsp[-1])->memory = make_number(0.0);
3638
		(yyval) = list_append((yyvsp[0]), (yyvsp[-1]));
31 by Arnold D. Robbins
Move to gawk-3.1.3.
3639
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3640
#line 3641 "awkgram.c" /* yacc.c:1646  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
3641
    break;
3642
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3643
  case 160:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3644
#line 1587 "awkgram.y" /* yacc.c:1646  */
281.1.1 by john haque
Speed/memory performance improvements.
3645
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3646
		func_use((yyvsp[0])->lasti->func_name, FUNC_USE);
3647
		(yyval) = (yyvsp[0]);
281.1.1 by john haque
Speed/memory performance improvements.
3648
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3649
#line 3650 "awkgram.c" /* yacc.c:1646  */
281.1.1 by john haque
Speed/memory performance improvements.
3650
    break;
3651
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3652
  case 161:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3653
#line 1592 "awkgram.y" /* yacc.c:1646  */
34 by Arnold D. Robbins
Move to gawk-3.1.6.
3654
    {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3655
		/* indirect function call */
3656
		INSTRUCTION *f, *t;
3657
		char *name;
3658
		NODE *indirect_var;
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
3659
		static bool warned = false;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3660
		const char *msg = _("indirect function calls are a gawk extension");
3661
3662
		if (do_traditional || do_posix)
3663
			yyerror("%s", msg);
3664
		else if (do_lint && ! warned) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
3665
			warned = true;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3666
			lintwarn("%s", msg);
34 by Arnold D. Robbins
Move to gawk-3.1.6.
3667
		}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3668
		
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3669
		f = (yyvsp[0])->lasti;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3670
		f->opcode = Op_indirect_func_call;
3671
		name = estrdup(f->func_name, strlen(f->func_name));
3672
		if (is_std_var(name))
3673
			yyerror(_("can not use special variable `%s' for indirect function call"), name);
281.1.1 by john haque
Speed/memory performance improvements.
3674
		indirect_var = variable(f->source_line, name, Node_var_new);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3675
		t = instruction(Op_push);
3676
		t->memory = indirect_var;
3677
3678
		/* prepend indirect var instead of appending to arguments (opt_expression_list),
3679
		 * and pop it off in setup_frame (eval.c) (left to right evaluation order); Test case:
3680
		 *		f = "fun"
3681
		 *		@f(f="real_fun")
3682
		 */
3683
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3684
		(yyval) = list_prepend((yyvsp[0]), t);
408.13.59 by Arnold D. Robbins
Disallow calling a function parameter. Check params are not function names.
3685
		at_seen = false;
34 by Arnold D. Robbins
Move to gawk-3.1.6.
3686
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3687
#line 3688 "awkgram.c" /* yacc.c:1646  */
31 by Arnold D. Robbins
Move to gawk-3.1.3.
3688
    break;
3689
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3690
  case 162:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3691
#line 1629 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3692
    {
408.13.59 by Arnold D. Robbins
Disallow calling a function parameter. Check params are not function names.
3693
		NODE *n;
3694
3695
		if (! at_seen) {
3696
			n = lookup((yyvsp[-3])->func_name);
3697
			if (n != NULL && n->type != Node_func
3698
			    && n->type != Node_ext_func && n->type != Node_old_ext_func) {
3699
				error_ln((yyvsp[-3])->source_line,
3700
					_("attempt to use non-function `%s' in function call"),
3701
						(yyvsp[-3])->func_name);
3702
			}
3703
		}
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3704
		param_sanity((yyvsp[-1]));
3705
		(yyvsp[-3])->opcode = Op_func_call;
3706
		(yyvsp[-3])->func_body = NULL;
3707
		if ((yyvsp[-1]) == NULL) {	/* no argument or error */
3708
			((yyvsp[-3]) + 1)->expr_count = 0;
3709
			(yyval) = list_create((yyvsp[-3]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3710
		} else {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3711
			INSTRUCTION *t = (yyvsp[-1]);
3712
			((yyvsp[-3]) + 1)->expr_count = count_expressions(&t, true); 
3713
			(yyval) = list_append(t, (yyvsp[-3]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3714
		}
3715
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3716
#line 3717 "awkgram.c" /* yacc.c:1646  */
34 by Arnold D. Robbins
Move to gawk-3.1.6.
3717
    break;
3718
277.1.11 by Arnold D. Robbins
Fix gsub and getline pass by reference. Add tests.
3719
  case 163:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3720
#line 1657 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3721
    { (yyval) = NULL; }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3722
#line 3723 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3723
    break;
3724
3725
  case 164:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3726
#line 1659 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3727
    { (yyval) = (yyvsp[0]); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3728
#line 3729 "awkgram.c" /* yacc.c:1646  */
277.1.11 by Arnold D. Robbins
Fix gsub and getline pass by reference. Add tests.
3729
    break;
3730
3731
  case 165:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3732
#line 1664 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3733
    { (yyval) = NULL; }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3734
#line 3735 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3735
    break;
3736
3737
  case 166:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3738
#line 1666 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3739
    { (yyval) = (yyvsp[-1]); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3740
#line 3741 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3741
    break;
3742
3743
  case 167:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3744
#line 1671 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3745
    {	(yyval) = (yyvsp[0]); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3746
#line 3747 "awkgram.c" /* yacc.c:1646  */
408.13.37 by Arnold D. Robbins
Remove deferred variables.
3747
    break;
3748
3749
  case 168:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3750
#line 1673 "awkgram.y" /* yacc.c:1646  */
408.13.37 by Arnold D. Robbins
Remove deferred variables.
3751
    {
3752
		(yyval) = list_merge((yyvsp[-1]), (yyvsp[0]));
3753
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3754
#line 3755 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3755
    break;
3756
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3757
  case 169:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3758
#line 1680 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3759
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3760
		INSTRUCTION *ip = (yyvsp[0])->lasti; 
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3761
		int count = ip->sub_count;	/* # of SUBSEP-seperated expressions */
3762
		if (count > 1) {
3763
			/* change Op_subscript or Op_sub_array to Op_concat */
3764
			ip->opcode = Op_concat;
3765
			ip->concat_flag = CSUBSEP;
3766
			ip->expr_count = count;
3767
		} else
3768
			ip->opcode = Op_no_op;
3769
		sub_counter++;	/* count # of dimensions */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3770
		(yyval) = (yyvsp[0]);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3771
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3772
#line 3773 "awkgram.c" /* yacc.c:1646  */
37 by Arnold D. Robbins
Bring in development gawk changes.
3773
    break;
3774
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3775
  case 170:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3776
#line 1697 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3777
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3778
		INSTRUCTION *t = (yyvsp[-1]);
3779
		if ((yyvsp[-1]) == NULL) {
3780
			error_ln((yyvsp[0])->source_line,
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
3781
				_("invalid subscript expression"));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3782
			/* install Null string as subscript. */
3783
			t = list_create(instruction(Op_push_i));
281.1.1 by john haque
Speed/memory performance improvements.
3784
			t->nexti->memory = dupnode(Nnull_string);
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3785
			(yyvsp[0])->sub_count = 1;			
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3786
		} else
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3787
			(yyvsp[0])->sub_count = count_expressions(&t, false);
3788
		(yyval) = list_append(t, (yyvsp[0]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3789
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3790
#line 3791 "awkgram.c" /* yacc.c:1646  */
37 by Arnold D. Robbins
Bring in development gawk changes.
3791
    break;
3792
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3793
  case 171:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3794
#line 1714 "awkgram.y" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3795
    {	(yyval) = (yyvsp[0]); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3796
#line 3797 "awkgram.c" /* yacc.c:1646  */
408.13.37 by Arnold D. Robbins
Remove deferred variables.
3797
    break;
3798
3799
  case 172:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3800
#line 1716 "awkgram.y" /* yacc.c:1646  */
408.13.37 by Arnold D. Robbins
Remove deferred variables.
3801
    {
3802
		(yyval) = list_merge((yyvsp[-1]), (yyvsp[0]));
3803
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3804
#line 3805 "awkgram.c" /* yacc.c:1646  */
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
3805
    break;
3806
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3807
  case 173:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3808
#line 1723 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3809
    { (yyval) = (yyvsp[-1]); }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3810
#line 3811 "awkgram.c" /* yacc.c:1646  */
37 by Arnold D. Robbins
Bring in development gawk changes.
3811
    break;
3812
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3813
  case 174:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3814
#line 1728 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3815
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3816
		char *var_name = (yyvsp[0])->lextok;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3817
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3818
		(yyvsp[0])->opcode = Op_push;
3819
		(yyvsp[0])->memory = variable((yyvsp[0])->source_line, var_name, Node_var_new);
3820
		(yyval) = list_create((yyvsp[0]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3821
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3822
#line 3823 "awkgram.c" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3823
    break;
3824
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3825
  case 175:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3826
#line 1736 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3827
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3828
		char *arr = (yyvsp[-1])->lextok;
3829
		(yyvsp[-1])->memory = variable((yyvsp[-1])->source_line, arr, Node_var_new);
3830
		(yyvsp[-1])->opcode = Op_push_array;
3831
		(yyval) = list_prepend((yyvsp[0]), (yyvsp[-1]));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3832
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3833
#line 3834 "awkgram.c" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3834
    break;
3835
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3836
  case 176:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3837
#line 1746 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3838
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3839
		INSTRUCTION *ip = (yyvsp[0])->nexti;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3840
		if (ip->opcode == Op_push
281.1.1 by john haque
Speed/memory performance improvements.
3841
			&& ip->memory->type == Node_var
3842
			&& ip->memory->var_update
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3843
		) {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3844
			(yyval) = list_prepend((yyvsp[0]), instruction(Op_var_update));
146 by Arnold D. Robbins
Bug fixes in scanning, updating variables.
3845
			(yyval)->nexti->update_var = ip->memory->var_update;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3846
		} else
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3847
			(yyval) = (yyvsp[0]);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3848
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3849
#line 3850 "awkgram.c" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3850
    break;
3851
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3852
  case 177:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3853
#line 1758 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3854
    {
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3855
		(yyval) = list_append((yyvsp[-1]), (yyvsp[-2]));
3856
		if ((yyvsp[0]) != NULL)
3857
			mk_assignment((yyvsp[-1]), NULL, (yyvsp[0]));
281.1.1 by john haque
Speed/memory performance improvements.
3858
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3859
#line 3860 "awkgram.c" /* yacc.c:1646  */
408.13.37 by Arnold D. Robbins
Remove deferred variables.
3860
    break;
3861
3862
  case 178:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3863
#line 1767 "awkgram.y" /* yacc.c:1646  */
408.13.37 by Arnold D. Robbins
Remove deferred variables.
3864
    {
3865
		(yyvsp[0])->opcode = Op_postincrement;
3866
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3867
#line 3868 "awkgram.c" /* yacc.c:1646  */
281.1.1 by john haque
Speed/memory performance improvements.
3868
    break;
3869
408.13.37 by Arnold D. Robbins
Remove deferred variables.
3870
  case 179:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3871
#line 1771 "awkgram.y" /* yacc.c:1646  */
281.1.1 by john haque
Speed/memory performance improvements.
3872
    {
408.13.37 by Arnold D. Robbins
Remove deferred variables.
3873
		(yyvsp[0])->opcode = Op_postdecrement;
116 by Arnold D. Robbins
Fix switch debugging.
3874
	  }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3875
#line 3876 "awkgram.c" /* yacc.c:1646  */
116 by Arnold D. Robbins
Fix switch debugging.
3876
    break;
3877
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3878
  case 180:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3879
#line 1774 "awkgram.y" /* yacc.c:1646  */
408.13.37 by Arnold D. Robbins
Remove deferred variables.
3880
    { (yyval) = NULL; }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3881
#line 3882 "awkgram.c" /* yacc.c:1646  */
408.13.37 by Arnold D. Robbins
Remove deferred variables.
3882
    break;
3883
3884
  case 182:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3885
#line 1782 "awkgram.y" /* yacc.c:1646  */
109 by Arnold D. Robbins
Bug fixes and cleanup.
3886
    { yyerrok; }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3887
#line 3888 "awkgram.c" /* yacc.c:1646  */
109 by Arnold D. Robbins
Bug fixes and cleanup.
3888
    break;
3889
116 by Arnold D. Robbins
Fix switch debugging.
3890
  case 183:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3891
#line 1786 "awkgram.y" /* yacc.c:1646  */
408.5.182 by Arnold D. Robbins
Allow any redirected getline inside BEGINFILE/ENDFILE.
3892
    { yyerrok; }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3893
#line 3894 "awkgram.c" /* yacc.c:1646  */
408.5.182 by Arnold D. Robbins
Allow any redirected getline inside BEGINFILE/ENDFILE.
3894
    break;
3895
3896
  case 186:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3897
#line 1795 "awkgram.y" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3898
    { yyerrok; }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3899
#line 3900 "awkgram.c" /* yacc.c:1646  */
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3900
    break;
3901
3902
  case 187:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3903
#line 1799 "awkgram.y" /* yacc.c:1646  */
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3904
    { (yyval) = (yyvsp[0]); yyerrok; }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3905
#line 3906 "awkgram.c" /* yacc.c:1646  */
109 by Arnold D. Robbins
Bug fixes and cleanup.
3906
    break;
3907
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
3908
  case 188:
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3909
#line 1803 "awkgram.y" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3910
    { yyerrok; }
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3911
#line 3912 "awkgram.c" /* yacc.c:1646  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
3912
    break;
3913
3914
408.13.164 by Arnold D. Robbins
Fix minor coredump.
3915
#line 3916 "awkgram.c" /* yacc.c:1646  */
35 by Arnold D. Robbins
Move to gawk-3.1.7.
3916
      default: break;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
3917
    }
228 by Arnold D. Robbins
Update to bison 2.5.
3918
  /* User semantic actions sometimes alter yychar, and that requires
3919
     that yytoken be updated with the new translation.  We take the
3920
     approach of translating immediately before every use of yytoken.
3921
     One alternative is translating here after every semantic action,
3922
     but that translation would be missed if the semantic action invokes
3923
     YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
3924
     if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
3925
     incorrect destructor might then be invoked immediately.  In the
3926
     case of YYERROR or YYBACKUP, subsequent parser actions might lead
3927
     to an incorrect destructor call or verbose syntax error message
3928
     before the lookahead is translated.  */
35 by Arnold D. Robbins
Move to gawk-3.1.7.
3929
  YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
3930
3931
  YYPOPSTACK (yylen);
3932
  yylen = 0;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
3933
  YY_STACK_PRINT (yyss, yyssp);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
3934
3935
  *++yyvsp = yyval;
3936
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3937
  /* Now 'shift' the result of the reduction.  Determine what state
30 by Arnold D. Robbins
Move to gawk-3.1.2.
3938
     that goes to, based on the state we popped back to and the rule
3939
     number reduced by.  */
28 by Arnold D. Robbins
Move to gawk-3.1.0.
3940
3941
  yyn = yyr1[yyn];
3942
30 by Arnold D. Robbins
Move to gawk-3.1.2.
3943
  yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
3944
  if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
3945
    yystate = yytable[yystate];
3946
  else
30 by Arnold D. Robbins
Move to gawk-3.1.2.
3947
    yystate = yydefgoto[yyn - YYNTOKENS];
28 by Arnold D. Robbins
Move to gawk-3.1.0.
3948
3949
  goto yynewstate;
3950
3951
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
3952
/*--------------------------------------.
3953
| yyerrlab -- here on detecting error.  |
3954
`--------------------------------------*/
30 by Arnold D. Robbins
Move to gawk-3.1.2.
3955
yyerrlab:
228 by Arnold D. Robbins
Update to bison 2.5.
3956
  /* Make sure we have latest lookahead translation.  See comments at
3957
     user semantic actions for why this is necessary.  */
3958
  yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
3959
30 by Arnold D. Robbins
Move to gawk-3.1.2.
3960
  /* If not already recovering from an error, report this error.  */
3961
  if (!yyerrstatus)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
3962
    {
3963
      ++yynerrs;
35 by Arnold D. Robbins
Move to gawk-3.1.7.
3964
#if ! YYERROR_VERBOSE
3965
      yyerror (YY_("syntax error"));
3966
#else
228 by Arnold D. Robbins
Update to bison 2.5.
3967
# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
3968
                                        yyssp, yytoken)
35 by Arnold D. Robbins
Move to gawk-3.1.7.
3969
      {
228 by Arnold D. Robbins
Update to bison 2.5.
3970
        char const *yymsgp = YY_("syntax error");
3971
        int yysyntax_error_status;
3972
        yysyntax_error_status = YYSYNTAX_ERROR;
3973
        if (yysyntax_error_status == 0)
3974
          yymsgp = yymsg;
3975
        else if (yysyntax_error_status == 1)
3976
          {
3977
            if (yymsg != yymsgbuf)
3978
              YYSTACK_FREE (yymsg);
3979
            yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
3980
            if (!yymsg)
3981
              {
3982
                yymsg = yymsgbuf;
3983
                yymsg_alloc = sizeof yymsgbuf;
3984
                yysyntax_error_status = 2;
3985
              }
3986
            else
3987
              {
3988
                yysyntax_error_status = YYSYNTAX_ERROR;
3989
                yymsgp = yymsg;
3990
              }
3991
          }
3992
        yyerror (yymsgp);
3993
        if (yysyntax_error_status == 2)
3994
          goto yyexhaustedlab;
35 by Arnold D. Robbins
Move to gawk-3.1.7.
3995
      }
228 by Arnold D. Robbins
Update to bison 2.5.
3996
# undef YYSYNTAX_ERROR
35 by Arnold D. Robbins
Move to gawk-3.1.7.
3997
#endif
28 by Arnold D. Robbins
Move to gawk-3.1.0.
3998
    }
3999
30 by Arnold D. Robbins
Move to gawk-3.1.2.
4000
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4001
4002
  if (yyerrstatus == 3)
4003
    {
35 by Arnold D. Robbins
Move to gawk-3.1.7.
4004
      /* If just tried and failed to reuse lookahead token after an
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
4005
         error, discard it.  */
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4006
33 by Arnold D. Robbins
Move to gawk 3.1.5.
4007
      if (yychar <= YYEOF)
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
4008
        {
4009
          /* Return failure if at end of input.  */
4010
          if (yychar == YYEOF)
4011
            YYABORT;
4012
        }
33 by Arnold D. Robbins
Move to gawk 3.1.5.
4013
      else
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
4014
        {
4015
          yydestruct ("Error: discarding",
4016
                      yytoken, &yylval);
4017
          yychar = YYEMPTY;
4018
        }
30 by Arnold D. Robbins
Move to gawk-3.1.2.
4019
    }
4020
35 by Arnold D. Robbins
Move to gawk-3.1.7.
4021
  /* Else will try to reuse lookahead token after shifting the error
30 by Arnold D. Robbins
Move to gawk-3.1.2.
4022
     token.  */
33 by Arnold D. Robbins
Move to gawk 3.1.5.
4023
  goto yyerrlab1;
4024
4025
4026
/*---------------------------------------------------.
4027
| yyerrorlab -- error raised explicitly by YYERROR.  |
4028
`---------------------------------------------------*/
4029
yyerrorlab:
4030
35 by Arnold D. Robbins
Move to gawk-3.1.7.
4031
  /* Pacify compilers like GCC when the user code never invokes
4032
     YYERROR and the label yyerrorlab therefore never appears in user
4033
     code.  */
4034
  if (/*CONSTCOND*/ 0)
33 by Arnold D. Robbins
Move to gawk 3.1.5.
4035
     goto yyerrorlab;
4036
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
4037
  /* Do not reclaim the symbols of the rule whose action triggered
35 by Arnold D. Robbins
Move to gawk-3.1.7.
4038
     this YYERROR.  */
4039
  YYPOPSTACK (yylen);
4040
  yylen = 0;
4041
  YY_STACK_PRINT (yyss, yyssp);
33 by Arnold D. Robbins
Move to gawk 3.1.5.
4042
  yystate = *yyssp;
4043
  goto yyerrlab1;
4044
4045
4046
/*-------------------------------------------------------------.
4047
| yyerrlab1 -- common code for both syntax error and YYERROR.  |
4048
`-------------------------------------------------------------*/
30 by Arnold D. Robbins
Move to gawk-3.1.2.
4049
yyerrlab1:
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
4050
  yyerrstatus = 3;      /* Each real token shifted decrements this.  */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
4051
4052
  for (;;)
4053
    {
4054
      yyn = yypact[yystate];
228 by Arnold D. Robbins
Update to bison 2.5.
4055
      if (!yypact_value_is_default (yyn))
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
4056
        {
4057
          yyn += YYTERROR;
4058
          if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
4059
            {
4060
              yyn = yytable[yyn];
4061
              if (0 < yyn)
4062
                break;
4063
            }
4064
        }
30 by Arnold D. Robbins
Move to gawk-3.1.2.
4065
4066
      /* Pop the current state because it cannot handle the error token.  */
4067
      if (yyssp == yyss)
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
4068
        YYABORT;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
4069
4070
35 by Arnold D. Robbins
Move to gawk-3.1.7.
4071
      yydestruct ("Error: popping",
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
4072
                  yystos[yystate], yyvsp);
35 by Arnold D. Robbins
Move to gawk-3.1.7.
4073
      YYPOPSTACK (1);
33 by Arnold D. Robbins
Move to gawk 3.1.5.
4074
      yystate = *yyssp;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
4075
      YY_STACK_PRINT (yyss, yyssp);
4076
    }
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4077
277.1.174 by Arnold D. Robbins
Update to bison 2.6.4.
4078
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4079
  *++yyvsp = yylval;
277.1.174 by Arnold D. Robbins
Update to bison 2.6.4.
4080
  YY_IGNORE_MAYBE_UNINITIALIZED_END
30 by Arnold D. Robbins
Move to gawk-3.1.2.
4081
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4082
35 by Arnold D. Robbins
Move to gawk-3.1.7.
4083
  /* Shift the error token.  */
33 by Arnold D. Robbins
Move to gawk 3.1.5.
4084
  YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
4085
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4086
  yystate = yyn;
4087
  goto yynewstate;
4088
30 by Arnold D. Robbins
Move to gawk-3.1.2.
4089
4090
/*-------------------------------------.
4091
| yyacceptlab -- YYACCEPT comes here.  |
4092
`-------------------------------------*/
4093
yyacceptlab:
4094
  yyresult = 0;
4095
  goto yyreturn;
4096
4097
/*-----------------------------------.
4098
| yyabortlab -- YYABORT comes here.  |
4099
`-----------------------------------*/
4100
yyabortlab:
4101
  yyresult = 1;
4102
  goto yyreturn;
4103
319.1.18 by Arnold D. Robbins
Update infrastructure.
4104
#if !defined yyoverflow || YYERROR_VERBOSE
35 by Arnold D. Robbins
Move to gawk-3.1.7.
4105
/*-------------------------------------------------.
4106
| yyexhaustedlab -- memory exhaustion comes here.  |
4107
`-------------------------------------------------*/
4108
yyexhaustedlab:
4109
  yyerror (YY_("memory exhausted"));
30 by Arnold D. Robbins
Move to gawk-3.1.2.
4110
  yyresult = 2;
4111
  /* Fall through.  */
4112
#endif
4113
4114
yyreturn:
35 by Arnold D. Robbins
Move to gawk-3.1.7.
4115
  if (yychar != YYEMPTY)
228 by Arnold D. Robbins
Update to bison 2.5.
4116
    {
4117
      /* Make sure we have latest lookahead translation.  See comments at
4118
         user semantic actions for why this is necessary.  */
4119
      yytoken = YYTRANSLATE (yychar);
4120
      yydestruct ("Cleanup: discarding lookahead",
4121
                  yytoken, &yylval);
4122
    }
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
4123
  /* Do not reclaim the symbols of the rule whose action triggered
35 by Arnold D. Robbins
Move to gawk-3.1.7.
4124
     this YYABORT or YYACCEPT.  */
4125
  YYPOPSTACK (yylen);
4126
  YY_STACK_PRINT (yyss, yyssp);
4127
  while (yyssp != yyss)
4128
    {
4129
      yydestruct ("Cleanup: popping",
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
4130
                  yystos[*yyssp], yyvsp);
35 by Arnold D. Robbins
Move to gawk-3.1.7.
4131
      YYPOPSTACK (1);
4132
    }
30 by Arnold D. Robbins
Move to gawk-3.1.2.
4133
#ifndef yyoverflow
4134
  if (yyss != yyssa)
4135
    YYSTACK_FREE (yyss);
4136
#endif
35 by Arnold D. Robbins
Move to gawk-3.1.7.
4137
#if YYERROR_VERBOSE
4138
  if (yymsg != yymsgbuf)
4139
    YYSTACK_FREE (yymsg);
4140
#endif
408.5.74 by Arnold D. Robbins
Update to Bison 3.0.2.
4141
  return yyresult;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4142
}
408.13.164 by Arnold D. Robbins
Fix minor coredump.
4143
#line 1805 "awkgram.y" /* yacc.c:1906  */
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4144
4145
4146
struct token {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4147
	const char *operator;	/* text to match */
4148
	OPCODE value;			/*  type */
4149
	int class;				/* lexical class */
4150
	unsigned flags;			/* # of args. allowed and compatability */
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4151
#	define	ARGS	0xFF	/* 0, 1, 2, 3 args allowed (any combination */
4152
#	define	A(n)	(1<<(n))
4153
#	define	VERSION_MASK	0xFF00	/* old awk is zero */
4154
#	define	NOT_OLD		0x0100	/* feature not in old awk */
4155
#	define	NOT_POSIX	0x0200	/* feature not in POSIX */
4156
#	define	GAWKX		0x0400	/* gawk extension */
277.1.183 by Arnold D. Robbins
fflush() is now POSIX. Fix code and document.
4157
#	define	BREAK		0x0800	/* break allowed inside */
4158
#	define	CONTINUE	0x1000	/* continue allowed inside */
408.5.265 by Arnold D. Robbins
Add builtin functions to FUNCTAB and PROCINFO["identifiers"] and doc.
4159
#	define	DEBUG_USE	0x2000	/* for use by developers */
277.1.2 by Arnold D. Robbins
Fix gsub losing white space when working on fields.
4160
	
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4161
	NODE *(*ptr)(int);	/* function that implements this keyword */
306 by john haque
Add arbitrary-precision arithmetic on integers.
4162
	NODE *(*ptr2)(int);	/* alternate arbitrary-precision function */
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4163
};
4164
408.21.1 by Arnold D. Robbins
Rework zOS patches; keep separate from autotools.
4165
#ifdef USE_EBCDIC
35 by Arnold D. Robbins
Move to gawk-3.1.7.
4166
/* tokcompare --- lexicographically compare token names for sorting */
4167
4168
static int
81 by Arnold D. Robbins
Some fixes for z/OS and also Autoconf.
4169
tokcompare(const void *l, const void *r)
35 by Arnold D. Robbins
Move to gawk-3.1.7.
4170
{
4171
	struct token *lhs, *rhs;
4172
4173
	lhs = (struct token *) l;
4174
	rhs = (struct token *) r;
4175
4176
	return strcmp(lhs->operator, rhs->operator);
4177
}
4178
#endif
4179
4180
/*
4181
 * Tokentab is sorted ASCII ascending order, so it can be binary searched.
4182
 * See check_special(), which sorts the table on EBCDIC systems.
4183
 * Function pointers come from declarations in awk.h.
4184
 */
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4185
300 by john haque
Add infrastructure for MPFR/GMP support.
4186
#ifdef HAVE_MPFR
301 by john haque
New interpreter routine for MPFR.
4187
#define MPF(F) do_mpfr_##F
300 by john haque
Add infrastructure for MPFR/GMP support.
4188
#else
4189
#define MPF(F) 0
4190
#endif
4191
30 by Arnold D. Robbins
Move to gawk-3.1.2.
4192
static const struct token tokentab[] = {
300 by john haque
Add infrastructure for MPFR/GMP support.
4193
{"BEGIN",	Op_rule,	 LEX_BEGIN,	0,		0,	0},
4194
{"BEGINFILE",	Op_rule,	 LEX_BEGINFILE,	GAWKX,		0,	0},
4195
{"END",		Op_rule,	 LEX_END,	0,		0,	0},
4196
{"ENDFILE",		Op_rule,	 LEX_ENDFILE,	GAWKX,		0,	0},
4197
#ifdef ARRAYDEBUG
408.5.265 by Arnold D. Robbins
Add builtin functions to FUNCTAB and PROCINFO["identifiers"] and doc.
4198
{"adump",	Op_builtin,    LEX_BUILTIN,	GAWKX|A(1)|A(2)|DEBUG_USE,	do_adump,	0},
300 by john haque
Add infrastructure for MPFR/GMP support.
4199
#endif
319.2.48 by Arnold D. Robbins
Extend or(), and(), xor() to N arguments, N >= 2.
4200
{"and",		Op_builtin,    LEX_BUILTIN,	GAWKX,		do_and,	MPF(and)},
300 by john haque
Add infrastructure for MPFR/GMP support.
4201
{"asort",	Op_builtin,	 LEX_BUILTIN,	GAWKX|A(1)|A(2)|A(3),	do_asort,	0},
4202
{"asorti",	Op_builtin,	 LEX_BUILTIN,	GAWKX|A(1)|A(2)|A(3),	do_asorti,	0},
301 by john haque
New interpreter routine for MPFR.
4203
{"atan2",	Op_builtin,	 LEX_BUILTIN,	NOT_OLD|A(2),	do_atan2,	MPF(atan2)},
300 by john haque
Add infrastructure for MPFR/GMP support.
4204
{"bindtextdomain",	Op_builtin,	 LEX_BUILTIN,	GAWKX|A(1)|A(2),	do_bindtextdomain,	0},
4205
{"break",	Op_K_break,	 LEX_BREAK,	0,		0,	0},
4206
{"case",	Op_K_case,	 LEX_CASE,	GAWKX,		0,	0},
4207
{"close",	Op_builtin,	 LEX_BUILTIN,	NOT_OLD|A(1)|A(2),	do_close,	0},
301 by john haque
New interpreter routine for MPFR.
4208
{"compl",	Op_builtin,    LEX_BUILTIN,	GAWKX|A(1),	do_compl,	MPF(compl)},
300 by john haque
Add infrastructure for MPFR/GMP support.
4209
{"continue",	Op_K_continue, LEX_CONTINUE,	0,		0,	0},
301 by john haque
New interpreter routine for MPFR.
4210
{"cos",		Op_builtin,	 LEX_BUILTIN,	NOT_OLD|A(1),	do_cos,	MPF(cos)},
300 by john haque
Add infrastructure for MPFR/GMP support.
4211
{"dcgettext",	Op_builtin,	 LEX_BUILTIN,	GAWKX|A(1)|A(2)|A(3),	do_dcgettext,	0},
4212
{"dcngettext",	Op_builtin,	 LEX_BUILTIN,	GAWKX|A(1)|A(2)|A(3)|A(4)|A(5),	do_dcngettext,	0},
4213
{"default",	Op_K_default,	 LEX_DEFAULT,	GAWKX,		0,	0},
4214
{"delete",	Op_K_delete,	 LEX_DELETE,	NOT_OLD,	0,	0},
4215
{"do",		Op_K_do,	 LEX_DO,	NOT_OLD|BREAK|CONTINUE,	0,	0},
4216
{"else",	Op_K_else,	 LEX_ELSE,	0,		0,	0},
4217
{"eval",	Op_symbol,	 LEX_EVAL,	0,		0,	0},
4218
{"exit",	Op_K_exit,	 LEX_EXIT,	0,		0,	0},
301 by john haque
New interpreter routine for MPFR.
4219
{"exp",		Op_builtin,	 LEX_BUILTIN,	A(1),		do_exp,	MPF(exp)},
342 by Arnold D. Robbins
Fix extension to be available only if DYNAMIC.
4220
#ifdef DYNAMIC
323 by john haque
Add optional shutdown routine for an extension lib.
4221
{"extension",	Op_builtin,	 LEX_BUILTIN,	GAWKX|A(1)|A(2)|A(3),	do_ext,	0},
342 by Arnold D. Robbins
Fix extension to be available only if DYNAMIC.
4222
#endif
319.1.136 by Arnold D. Robbins
Merge branch 'gawk-4.0-stable'. fflush is now POSIX.
4223
{"fflush",	Op_builtin,	 LEX_BUILTIN,	A(0)|A(1), do_fflush,	0},
300 by john haque
Add infrastructure for MPFR/GMP support.
4224
{"for",		Op_K_for,	 LEX_FOR,	BREAK|CONTINUE,	0,	0},
4225
{"func",	Op_func, LEX_FUNCTION,	NOT_POSIX|NOT_OLD,	0,	0},
4226
{"function",Op_func, LEX_FUNCTION,	NOT_OLD,	0,	0},
4227
{"gensub",	Op_sub_builtin,	 LEX_BUILTIN,	GAWKX|A(3)|A(4), 0,	0},
4228
{"getline",	Op_K_getline_redir,	 LEX_GETLINE,	NOT_OLD,	0,	0},
4229
{"gsub",	Op_sub_builtin,	 LEX_BUILTIN,	NOT_OLD|A(2)|A(3), 0,	0},
4230
{"if",		Op_K_if,	 LEX_IF,	0,		0,	0},
4231
{"in",		Op_symbol,	 LEX_IN,	0,		0,	0},
350 by Arnold D. Robbins
Merge branch 'gawk-4.0-stable'
4232
{"include",	Op_symbol,	 LEX_INCLUDE,	GAWKX,	0,	0},
300 by john haque
Add infrastructure for MPFR/GMP support.
4233
{"index",	Op_builtin,	 LEX_BUILTIN,	A(2),		do_index,	0},
301 by john haque
New interpreter routine for MPFR.
4234
{"int",		Op_builtin,	 LEX_BUILTIN,	A(1),		do_int,	MPF(int)},
300 by john haque
Add infrastructure for MPFR/GMP support.
4235
{"isarray",	Op_builtin,	 LEX_BUILTIN,	GAWKX|A(1),	do_isarray,	0},
4236
{"length",	Op_builtin,	 LEX_LENGTH,	A(0)|A(1),	do_length,	0},
319.1.7 by Arnold D. Robbins
Merge remote branch 'origin/xgawk-build'
4237
{"load",  	Op_symbol,	 LEX_LOAD,	GAWKX,		0,	0},
301 by john haque
New interpreter routine for MPFR.
4238
{"log",		Op_builtin,	 LEX_BUILTIN,	A(1),		do_log,	MPF(log)},
4239
{"lshift",	Op_builtin,    LEX_BUILTIN,	GAWKX|A(2),	do_lshift,	MPF(lshift)},
300 by john haque
Add infrastructure for MPFR/GMP support.
4240
{"match",	Op_builtin,	 LEX_BUILTIN,	NOT_OLD|A(2)|A(3), do_match,	0},
4241
{"mktime",	Op_builtin,	 LEX_BUILTIN,	GAWKX|A(1),	do_mktime,	0},
4242
{"next",	Op_K_next,	 LEX_NEXT,	0,		0,	0},
319.1.44 by Arnold D. Robbins
Update some things that are now POSIX.
4243
{"nextfile",	Op_K_nextfile, LEX_NEXTFILE,	0,		0,	0},
319.2.48 by Arnold D. Robbins
Extend or(), and(), xor() to N arguments, N >= 2.
4244
{"or",		Op_builtin,    LEX_BUILTIN,	GAWKX,		do_or,	MPF(or)},
300 by john haque
Add infrastructure for MPFR/GMP support.
4245
{"patsplit",	Op_builtin,    LEX_BUILTIN,	GAWKX|A(2)|A(3)|A(4), do_patsplit,	0},
4246
{"print",	Op_K_print,	 LEX_PRINT,	0,		0,	0},
4247
{"printf",	Op_K_printf,	 LEX_PRINTF,	0,		0,	0},
301 by john haque
New interpreter routine for MPFR.
4248
{"rand",	Op_builtin,	 LEX_BUILTIN,	NOT_OLD|A(0),	do_rand,	MPF(rand)},
300 by john haque
Add infrastructure for MPFR/GMP support.
4249
{"return",	Op_K_return,	 LEX_RETURN,	NOT_OLD,	0,	0},
367 by Arnold D. Robbins
Make mpfr and, or, xor, accept >= 2 arguments.
4250
{"rshift",	Op_builtin,    LEX_BUILTIN,	GAWKX|A(2),	do_rshift,	MPF(rshift)},
301 by john haque
New interpreter routine for MPFR.
4251
{"sin",		Op_builtin,	 LEX_BUILTIN,	NOT_OLD|A(1),	do_sin,	MPF(sin)},
300 by john haque
Add infrastructure for MPFR/GMP support.
4252
{"split",	Op_builtin,	 LEX_BUILTIN,	A(2)|A(3)|A(4),	do_split,	0},
4253
{"sprintf",	Op_builtin,	 LEX_BUILTIN,	0,		do_sprintf,	0},
301 by john haque
New interpreter routine for MPFR.
4254
{"sqrt",	Op_builtin,	 LEX_BUILTIN,	A(1),		do_sqrt,	MPF(sqrt)},
4255
{"srand",	Op_builtin,	 LEX_BUILTIN,	NOT_OLD|A(0)|A(1), do_srand,	MPF(srand)},
319.2.36 by Arnold D. Robbins
Restore stopme() debugging function.
4256
#if defined(GAWKDEBUG) || defined(ARRAYDEBUG) /* || ... */
408.5.265 by Arnold D. Robbins
Add builtin functions to FUNCTAB and PROCINFO["identifiers"] and doc.
4257
{"stopme",	Op_builtin,	LEX_BUILTIN,	GAWKX|A(0)|DEBUG_USE,	stopme,		0},
319.2.36 by Arnold D. Robbins
Restore stopme() debugging function.
4258
#endif
300 by john haque
Add infrastructure for MPFR/GMP support.
4259
{"strftime",	Op_builtin,	 LEX_BUILTIN,	GAWKX|A(0)|A(1)|A(2)|A(3), do_strftime,	0},
301 by john haque
New interpreter routine for MPFR.
4260
{"strtonum",	Op_builtin,    LEX_BUILTIN,	GAWKX|A(1),	do_strtonum, MPF(strtonum)},
300 by john haque
Add infrastructure for MPFR/GMP support.
4261
{"sub",		Op_sub_builtin,	 LEX_BUILTIN,	NOT_OLD|A(2)|A(3), 0,	0},
4262
{"substr",	Op_builtin,	 LEX_BUILTIN,	A(2)|A(3),	do_substr,	0},
4263
{"switch",	Op_K_switch,	 LEX_SWITCH,	GAWKX|BREAK,	0,	0},
4264
{"system",	Op_builtin,	 LEX_BUILTIN,	NOT_OLD|A(1),	do_system,	0},
4265
{"systime",	Op_builtin,	 LEX_BUILTIN,	GAWKX|A(0),	do_systime,	0},
4266
{"tolower",	Op_builtin,	 LEX_BUILTIN,	NOT_OLD|A(1),	do_tolower,	0},
4267
{"toupper",	Op_builtin,	 LEX_BUILTIN,	NOT_OLD|A(1),	do_toupper,	0},
4268
{"while",	Op_K_while,	 LEX_WHILE,	BREAK|CONTINUE,	0,	0},
319.2.48 by Arnold D. Robbins
Extend or(), and(), xor() to N arguments, N >= 2.
4269
{"xor",		Op_builtin,    LEX_BUILTIN,	GAWKX,		do_xor,	MPF(xor)},
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4270
};
4271
29 by Arnold D. Robbins
Move to gawk-3.1.1.
4272
/* Variable containing the current shift state.  */
4273
static mbstate_t cur_mbstate;
4274
/* Ring buffer containing current characters.  */
4275
#define MAX_CHAR_IN_RING_BUFFER 8
4276
#define RING_BUFFER_SIZE (MAX_CHAR_IN_RING_BUFFER * MB_LEN_MAX)
4277
static char cur_char_ring[RING_BUFFER_SIZE];
4278
/* Index for ring buffers.  */
4279
static int cur_ring_idx;
4280
/* This macro means that last nextc() return a singlebyte character
4281
   or 1st byte of a multibyte character.  */
4282
#define nextc_is_1stbyte (cur_char_ring[cur_ring_idx] == 1)
4283
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4284
/* getfname --- return name of a builtin function (for pretty printing) */
4285
4286
const char *
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4287
getfname(NODE *(*fptr)(int))
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4288
{
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4289
	int i, j;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4290
4291
	j = sizeof(tokentab) / sizeof(tokentab[0]);
4292
	/* linear search, no other way to do it */
4293
	for (i = 0; i < j; i++) 
408.5.231 by Andrew J. Schorr
Minor patch to get --profile to work in -M (MPFR) mode.
4294
		if (tokentab[i].ptr == fptr || tokentab[i].ptr2 == fptr)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4295
			return tokentab[i].operator;
4296
30 by Arnold D. Robbins
Move to gawk-3.1.2.
4297
	return NULL;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4298
}
4299
302.1.1 by john haque
Finish MPFR changes and clean up code.
4300
/* negate_num --- negate a number in NODE */
4301
4302
void
4303
negate_num(NODE *n)
4304
{
408.5.65 by Arnold D. Robbins
Remove compilation warning.
4305
#ifdef HAVE_MPFR
408.5.42 by Arnold D. Robbins
Fix -0 for MPFR.
4306
	int tval = 0;
408.5.65 by Arnold D. Robbins
Remove compilation warning.
4307
#endif
408.5.42 by Arnold D. Robbins
Fix -0 for MPFR.
4308
408.5.55 by Arnold D. Robbins
Fix bug that only showed up on 32 bit systems with MPFR.
4309
	if (! is_mpg_number(n)) {
408.5.42 by Arnold D. Robbins
Fix -0 for MPFR.
4310
		n->numbr = -n->numbr;
408.5.55 by Arnold D. Robbins
Fix bug that only showed up on 32 bit systems with MPFR.
4311
		return;
4312
	}
4313
302.1.1 by john haque
Finish MPFR changes and clean up code.
4314
#ifdef HAVE_MPFR
408.5.55 by Arnold D. Robbins
Fix bug that only showed up on 32 bit systems with MPFR.
4315
	if (is_mpg_integer(n)) {
408.5.42 by Arnold D. Robbins
Fix -0 for MPFR.
4316
		if (! iszero(n)) {
4317
			mpz_neg(n->mpg_i, n->mpg_i);
4318
			return;
4319
		}
4320
4321
		/*
4322
		 * 0 --> -0 conversion. Requires turning the MPG integer
4323
		 * into an MPFR float.
4324
		 */
408.5.55 by Arnold D. Robbins
Fix bug that only showed up on 32 bit systems with MPFR.
4325
4326
		mpz_clear(n->mpg_i);	/* release the integer storage */
4327
4328
		/* Convert and fall through. */
408.5.42 by Arnold D. Robbins
Fix -0 for MPFR.
4329
		tval = mpfr_set_d(n->mpg_numbr, 0.0, ROUND_MODE);
305 by john haque
Bug fixes and tests for MPFR.
4330
		IEEE_FMT(n->mpg_numbr, tval);
408.5.42 by Arnold D. Robbins
Fix -0 for MPFR.
4331
		n->flags &= ~MPZN;
4332
		n->flags |= MPFN;
4333
	}
4334
4335
	/* mpfr float case */
4336
	tval = mpfr_neg(n->mpg_numbr, n->mpg_numbr, ROUND_MODE);
4337
	IEEE_FMT(n->mpg_numbr, tval);
302.1.1 by john haque
Finish MPFR changes and clean up code.
4338
#endif
4339
}
4340
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
4341
/* print_included_from --- print `Included from ..' file names and locations */
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4342
4343
static void
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
4344
print_included_from()
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4345
{
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
4346
	int saveline, line;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4347
	SRCFILE *s;
4348
4349
	/* suppress current file name, line # from `.. included from ..' msgs */ 
4350
	saveline = sourceline;
4351
	sourceline = 0;
4352
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
4353
	for (s = sourcefile; s != NULL && s->stype == SRC_INC; ) {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4354
		s = s->next;
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
4355
		if (s == NULL || s->fd <= INVALID_HANDLE)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4356
			continue;
4357
		line = s->srclines;
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
4358
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4359
		/* if last token is NEWLINE, line number is off by 1. */
4360
		if (s->lasttok == NEWLINE)
4361
			line--;
4362
		msg("%s %s:%d%c",
4363
			s->prev == sourcefile ? "In file included from"
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
4364
					  : "                 from",
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4365
			(s->stype == SRC_INC ||
4366
				 s->stype == SRC_FILE) ? s->src : "cmd. line",
4367
			line,
4368
			s->stype == SRC_INC ? ',' : ':'
4369
		);
4370
	}
4371
	sourceline = saveline;
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
4372
}
4373
4374
/* warning_ln --- print a warning message with location */
4375
4376
static void
4377
warning_ln(int line, const char *mesg, ...)
4378
{
4379
	va_list args;
4380
	int saveline;
4381
4382
	saveline = sourceline;
4383
	sourceline = line;
4384
	print_included_from();
4385
	va_start(args, mesg);
319.2.33 by Arnold D. Robbins
Fix code duplication in gawkapi.c from msg.c.
4386
	err(false, _("warning: "), mesg, args);
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
4387
	va_end(args);
4388
	sourceline = saveline;
4389
}
4390
4391
/* lintwarn_ln --- print a lint warning and location */
4392
4393
static void
4394
lintwarn_ln(int line, const char *mesg, ...)
4395
{
4396
	va_list args;
4397
	int saveline;
4398
4399
	saveline = sourceline;
4400
	sourceline = line;
4401
	print_included_from();
4402
	va_start(args, mesg);
4403
	if (lintfunc == r_fatal)
319.2.33 by Arnold D. Robbins
Fix code duplication in gawkapi.c from msg.c.
4404
		err(true, _("fatal: "), mesg, args);
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
4405
	else
319.2.33 by Arnold D. Robbins
Fix code duplication in gawkapi.c from msg.c.
4406
		err(false, _("warning: "), mesg, args);
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
4407
	va_end(args);
4408
	sourceline = saveline;
4409
	if (lintfunc == r_fatal)
4410
		gawk_exit(EXIT_FATAL);
4411
}
4412
4413
/* error_ln --- print an error message and location */
4414
4415
static void
4416
error_ln(int line, const char *m, ...)
4417
{
4418
	va_list args;
4419
	int saveline;
4420
4421
	saveline = sourceline;
4422
	sourceline = line;
4423
	print_included_from();
4424
	errcount++;
4425
	va_start(args, m);
319.2.33 by Arnold D. Robbins
Fix code duplication in gawkapi.c from msg.c.
4426
	err(false, "error: ", m, args);
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
4427
	va_end(args);
4428
	sourceline = saveline;
4429
}
4430
4431
/* yyerror --- print a syntax error message, show where */
4432
4433
static void
4434
yyerror(const char *m, ...)
4435
{
4436
	va_list args;
4437
	const char *mesg = NULL;
4438
	char *bp, *cp;
4439
	char *scan;
4440
	char *buf;
4441
	int count;
4442
	static char end_of_file_line[] = "(END OF FILE)";
4443
	char save;
4444
4445
	print_included_from();
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4446
4447
	errcount++;
4448
	/* Find the current line in the input file */
4449
	if (lexptr && lexeme) {
4450
		if (thisline == NULL) {
4451
			cp = lexeme;
4452
			if (*cp == '\n') {
408.19.48 by Arnold D. Robbins
Bug fix, invalid read in yylex.
4453
				if (cp > lexptr_begin)
4454
					cp--;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
4455
				mesg = _("unexpected newline or end of string");
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4456
			}
4457
			for (; cp != lexptr_begin && *cp != '\n'; --cp)
4458
				continue;
4459
			if (*cp == '\n')
4460
				cp++;
4461
			thisline = cp;
4462
		}
4463
		/* NL isn't guaranteed */
4464
		bp = lexeme;
408.19.48 by Arnold D. Robbins
Bug fix, invalid read in yylex.
4465
		if (bp < thisline)
4466
			bp = thisline + 1;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4467
		while (bp < lexend && *bp && *bp != '\n')
4468
			bp++;
4469
	} else {
4470
		thisline = end_of_file_line;
4471
		bp = thisline + strlen(thisline);
4472
	}
30 by Arnold D. Robbins
Move to gawk-3.1.2.
4473
4474
	/*
4475
	 * Saving and restoring *bp keeps valgrind happy,
4476
	 * since the guts of glibc uses strlen, even though
4477
	 * we're passing an explict precision. Sigh.
32 by Arnold D. Robbins
Move to gawk-3.1.4.
4478
	 *
4479
	 * 8/2003: We may not need this anymore.
30 by Arnold D. Robbins
Move to gawk-3.1.2.
4480
	 */
4481
	save = *bp;
4482
	*bp = '\0';
4483
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4484
	msg("%.*s", (int) (bp - thisline), thisline);
29 by Arnold D. Robbins
Move to gawk-3.1.1.
4485
30 by Arnold D. Robbins
Move to gawk-3.1.2.
4486
	*bp = save;
29 by Arnold D. Robbins
Move to gawk-3.1.1.
4487
	va_start(args, m);
4488
	if (mesg == NULL)
4489
		mesg = m;
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
4490
29 by Arnold D. Robbins
Move to gawk-3.1.1.
4491
	count = (bp - thisline) + strlen(mesg) + 2 + 1;
4492
	emalloc(buf, char *, count, "yyerror");
4493
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4494
	bp = buf;
29 by Arnold D. Robbins
Move to gawk-3.1.1.
4495
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4496
	if (lexptr != NULL) {
4497
		scan = thisline;
29 by Arnold D. Robbins
Move to gawk-3.1.1.
4498
		while (scan < lexeme)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4499
			if (*scan++ == '\t')
4500
				*bp++ = '\t';
4501
			else
4502
				*bp++ = ' ';
4503
		*bp++ = '^';
4504
		*bp++ = ' ';
4505
	}
4506
	strcpy(bp, mesg);
319.2.33 by Arnold D. Robbins
Fix code duplication in gawkapi.c from msg.c.
4507
	err(false, "", buf, args);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4508
	va_end(args);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4509
	efree(buf);
4510
}
4511
4512
/* mk_program --- create a single list of instructions */
4513
4514
static INSTRUCTION *
4515
mk_program()
4516
{
4517
	INSTRUCTION *cp, *tmp;
4518
4519
#define begin_block         rule_block[BEGIN]
4520
#define end_block           rule_block[END]
4521
#define prog_block          rule_block[Rule]
4522
#define beginfile_block     rule_block[BEGINFILE]
4523
#define endfile_block       rule_block[ENDFILE]
4524
4525
	if (end_block == NULL)
4526
		end_block = list_create(ip_end);
4527
	else
4528
		(void) list_prepend(end_block, ip_end);
4529
49 by Arnold D. Robbins
Fix memory leaks - patch from John.
4530
	if (! in_main_context()) {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4531
		if (begin_block != NULL && prog_block != NULL)
4532
			cp = list_merge(begin_block, prog_block);
4533
		else
4534
			cp = (begin_block != NULL) ? begin_block : prog_block;
4535
4536
		if (cp != NULL)
4537
			(void) list_merge(cp, end_block);
4538
		else
4539
			cp = end_block;
4540
4541
		(void) list_append(cp, instruction(Op_stop));
4542
		goto out;
4543
	}
4544
4545
	if (endfile_block == NULL)
4546
		endfile_block = list_create(ip_endfile);
4547
	else {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
4548
		ip_rec->has_endfile = true;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4549
		(void) list_prepend(endfile_block, ip_endfile);
4550
	}
4551
4552
	if (beginfile_block == NULL)
4553
		beginfile_block = list_create(ip_beginfile);
4554
	else
4555
		(void) list_prepend(beginfile_block, ip_beginfile);
4556
4557
	if (prog_block == NULL) {
4558
		if (end_block->nexti == end_block->lasti
4559
				&& beginfile_block->nexti == beginfile_block->lasti 
4560
				&& endfile_block->nexti == endfile_block->lasti
4561
		) {
4562
			/* no pattern-action and (real) end, beginfile or endfile blocks */
4563
			bcfree(ip_rec);
4564
			bcfree(ip_newfile);
4565
			ip_rec = ip_newfile = NULL;
4566
4567
			list_append(beginfile_block, instruction(Op_after_beginfile));
4568
			(void) list_append(endfile_block, instruction(Op_after_endfile));
4569
4570
			if (begin_block == NULL)     /* no program at all */
4571
				cp = end_block;
4572
			else
4573
				cp = list_merge(begin_block, end_block);
4574
			(void) list_append(cp, ip_atexit);
4575
			(void) list_append(cp, instruction(Op_stop));
4576
4577
			/* append beginfile_block and endfile_block for sole use
4578
			 * in getline without redirection (Op_K_getline).
4579
			 */
4580
4581
			(void) list_merge(cp, beginfile_block);
4582
			(void) list_merge(cp, endfile_block);
4583
4584
			goto out;
4585
4586
		} else {
4587
			/* install a do-nothing prog block */
4588
			prog_block = list_create(instruction(Op_no_op));
4589
		}
4590
	}
4591
4592
	(void) list_append(endfile_block, instruction(Op_after_endfile));
4593
	(void) list_prepend(prog_block, ip_rec);
4594
	(void) list_append(prog_block, instruction(Op_jmp));
4595
	prog_block->lasti->target_jmp = ip_rec;
4596
		
4597
	list_append(beginfile_block, instruction(Op_after_beginfile));
4598
4599
	cp = list_merge(beginfile_block, prog_block);
4600
	(void) list_prepend(cp, ip_newfile);
4601
	(void) list_merge(cp, endfile_block);
4602
	(void) list_merge(cp, end_block);
4603
	if (begin_block != NULL)
4604
		cp = list_merge(begin_block, cp);
4605
4606
	(void) list_append(cp, ip_atexit);
4607
	(void) list_append(cp, instruction(Op_stop));
4608
4609
out:
4610
	/* delete the Op_list, not needed */
4611
	tmp = cp->nexti;
4612
	bcfree(cp);
4613
	return tmp;
4614
4615
#undef begin_block
4616
#undef end_block
4617
#undef prog_block
4618
#undef beginfile_block
4619
#undef endfile_block 
4620
}
4621
4622
/* parse_program --- read in the program and convert into a list of instructions */
4623
4624
int
4625
parse_program(INSTRUCTION **pcode)
4626
{
4627
	int ret;
4628
4629
	/* pre-create non-local jump targets
4630
	 * ip_end (Op_no_op) -- used as jump target for `exit'
4631
	 * outside an END block.
4632
	 */
4633
	ip_end = instruction(Op_no_op);
4634
49 by Arnold D. Robbins
Fix memory leaks - patch from John.
4635
	if (! in_main_context())
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4636
		ip_newfile = ip_rec = ip_atexit = ip_beginfile = ip_endfile = NULL;
4637
	else {
4638
		ip_endfile = instruction(Op_no_op);
4639
		ip_beginfile = instruction(Op_no_op);
277.1.21 by Arnold D. Robbins
BEGINFILE/ENDFILE code redone.
4640
		ip_rec = instruction(Op_get_record); /* target for `next', also ip_newfile */
4641
		ip_newfile = bcalloc(Op_newfile, 2, 0); /* target for `nextfile' */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4642
		ip_newfile->target_jmp = ip_end;
4643
		ip_newfile->target_endfile = ip_endfile;
277.1.21 by Arnold D. Robbins
BEGINFILE/ENDFILE code redone.
4644
		(ip_newfile + 1)->target_get_record = ip_rec;
4645
		ip_rec->target_newfile = ip_newfile;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4646
		ip_atexit = instruction(Op_atexit);	/* target for `exit' in END block */
4647
	}
4648
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
4649
	for (sourcefile = srcfiles->next; sourcefile->stype == SRC_EXTLIB;
4650
			sourcefile = sourcefile->next)
4651
		;
4652
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
4653
	lexeof = false;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4654
	lexptr = NULL;
4655
	lasttok = 0;
4656
	memset(rule_block, 0, sizeof(ruletab) * sizeof(INSTRUCTION *));
4657
	errcount = 0;
4658
	tok = tokstart != NULL ? tokstart : tokexpand();
4659
4660
	ret = yyparse();
4661
	*pcode = mk_program();
4662
4663
	/* avoid false source indications */
4664
	source = NULL;
4665
	sourceline = 0;
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
4666
	if (ret == 0)	/* avoid spurious warning if parser aborted with YYABORT */
4667
		check_funcs();
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4668
408.13.60 by Arnold D. Robbins
Move param checking against function names into --posix.
4669
	if (do_posix && ! check_param_names())
408.13.59 by Arnold D. Robbins
Disallow calling a function parameter. Check params are not function names.
4670
		errcount++;
4671
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
4672
	if (args_array == NULL)
4673
		emalloc(args_array, NODE **, (max_args + 2) * sizeof(NODE *), "parse_program");
4674
	else
4675
		erealloc(args_array, NODE **, (max_args + 2) * sizeof(NODE *), "parse_program");
4676
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4677
	return (ret || errcount);
4678
}
4679
408.5.166 by Arnold D. Robbins
Fix memory leak in do_eval.
4680
/* free_srcfile --- free a SRCFILE struct */
4681
4682
void
4683
free_srcfile(SRCFILE *thisfile)
4684
{
4685
	efree(thisfile->src);
4686
	efree(thisfile);
4687
}
4688
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4689
/* do_add_srcfile --- add one item to srcfiles */
4690
4691
static SRCFILE *
408.5.92 by Arnold D. Robbins
Continue to straighten out enum usage.
4692
do_add_srcfile(enum srctype stype, char *src, char *path, SRCFILE *thisfile)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4693
{
4694
	SRCFILE *s;
4695
4696
	emalloc(s, SRCFILE *, sizeof(SRCFILE), "do_add_srcfile");
4697
	memset(s, 0, sizeof(SRCFILE));
4698
	s->src = estrdup(src, strlen(src));
4699
	s->fullpath = path;
4700
	s->stype = stype;
4701
	s->fd = INVALID_HANDLE;
4702
	s->next = thisfile;
4703
	s->prev = thisfile->prev;
4704
	thisfile->prev->next = s;
4705
	thisfile->prev = s;
4706
	return s;
4707
}
4708
4709
/* add_srcfile --- add one item to srcfiles after checking if
4710
 *				a source file exists and not already in list.
4711
 */
4712
4713
SRCFILE *
408.5.92 by Arnold D. Robbins
Continue to straighten out enum usage.
4714
add_srcfile(enum srctype stype, char *src, SRCFILE *thisfile, bool *already_included, int *errcode)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4715
{
4716
	SRCFILE *s;
4717
	struct stat sbuf;
4718
	char *path;
4719
	int errno_val = 0;
4720
4721
	if (already_included)
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
4722
		*already_included = false;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4723
	if (errcode)
4724
		*errcode = 0;
4725
	if (stype == SRC_CMDLINE || stype == SRC_STDIN)
4726
		return do_add_srcfile(stype, src, NULL, thisfile);
4727
408.13.111 by Arnold D. Robbins
Minor code cleanups.
4728
	path = find_source(src, & sbuf, & errno_val, stype == SRC_EXTLIB);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4729
	if (path == NULL) {
4730
		if (errcode) {
4731
			*errcode = errno_val;
4732
			return NULL;
4733
		}
299.3.10 by Arnold D. Robbins
Rebuild after merge from xgawk.
4734
		/* use full messages to ease translation */
299.3.11 by Andrew J. Schorr
Fix minor bugs in configure.ac and awkgram.y.
4735
		fatal(stype != SRC_EXTLIB
299.3.10 by Arnold D. Robbins
Rebuild after merge from xgawk.
4736
			? _("can't open source file `%s' for reading (%s)")
4737
			: _("can't open shared library `%s' for reading (%s)"),
4738
				src,
4739
				errno_val ? strerror(errno_val) : _("reason unknown"));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4740
	}
4741
319.2.7 by Andrew J. Schorr
Add -i option, append .awk if initial search fails, and allow -f repeats.
4742
	/* N.B. We do not eliminate duplicate SRC_FILE (-f) programs. */
319.2.102 by Andrew J. Schorr
Make it a fatal error to load the same file with -f and -i (or @include).
4743
	for (s = srcfiles->next; s != srcfiles; s = s->next) {
4744
		if ((s->stype == SRC_FILE || s->stype == SRC_INC || s->stype == SRC_EXTLIB) && files_are_same(path, s)) {
4745
			if (stype == SRC_INC || stype == SRC_EXTLIB) {
4746
				/* eliminate duplicates */
4747
				if ((stype == SRC_INC) && (s->stype == SRC_FILE))
4748
					fatal(_("can't include `%s' and use it as a program file"), src);
4749
319.2.7 by Andrew J. Schorr
Add -i option, append .awk if initial search fails, and allow -f repeats.
4750
				if (do_lint) {
4751
					int line = sourceline;
4752
					/* Kludge: the line number may be off for `@include file'.
4753
					 * Since, this function is also used for '-f file' in main.c,
4754
					 * sourceline > 1 check ensures that the call is at
4755
					 * parse time.
4756
					 */
4757
					if (sourceline > 1 && lasttok == NEWLINE)
4758
						line--;
319.2.51 by Andrew J. Schorr
Improve lint warning message about a previously loaded shared library.
4759
					lintwarn_ln(line,
4760
						    stype != SRC_EXTLIB
4761
						      ? _("already included source file `%s'")
4762
						      : _("already loaded shared library `%s'"),
4763
						    src);
319.2.7 by Andrew J. Schorr
Add -i option, append .awk if initial search fails, and allow -f repeats.
4764
				}
4765
				efree(path);
4766
				if (already_included)
4767
					*already_included = true;
4768
				return NULL;
319.2.102 by Andrew J. Schorr
Make it a fatal error to load the same file with -f and -i (or @include).
4769
			} else {
4770
				/* duplicates are allowed for -f */ 
4771
				if (s->stype == SRC_INC)
4772
					fatal(_("can't include `%s' and use it as a program file"), src);
4773
				/* no need to scan for further matches, since
4774
				 * they must be of homogeneous type */
4775
				break;
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
4776
			}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4777
		}
4778
	}
4779
4780
	s = do_add_srcfile(stype, src, path, thisfile);
4781
	s->sbuf = sbuf;
4782
	s->mtime = sbuf.st_mtime;
4783
	return s;
4784
}
4785
4786
/* include_source --- read program from source included using `@include' */
4787
4788
static int
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
4789
include_source(INSTRUCTION *file)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4790
{
4791
	SRCFILE *s;
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
4792
	char *src = file->lextok;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4793
	int errcode;
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
4794
	bool already_included;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4795
4796
	if (do_traditional || do_posix) {
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
4797
		error_ln(file->source_line, _("@include is a gawk extension"));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4798
		return -1;
4799
	}
4800
4801
	if (strlen(src) == 0) {
4802
		if (do_lint)
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
4803
			lintwarn_ln(file->source_line, _("empty filename after @include"));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4804
		return 0;
4805
	}
4806
4807
	s = add_srcfile(SRC_INC, src, sourcefile, &already_included, &errcode);
4808
	if (s == NULL) {
4809
		if (already_included)
4810
			return 0;
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
4811
		error_ln(file->source_line,
4812
			_("can't open source file `%s' for reading (%s)"),
4813
			src, errcode ? strerror(errcode) : _("reason unknown"));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4814
		return -1;
4815
	}
4816
4817
	/* save scanner state for the current sourcefile */
4818
	sourcefile->srclines = sourceline;
4819
	sourcefile->lexptr = lexptr;
4820
	sourcefile->lexend = lexend;
4821
	sourcefile->lexptr_begin = lexptr_begin;        
4822
	sourcefile->lexeme = lexeme;
4823
	sourcefile->lasttok = lasttok;
4824
4825
	/* included file becomes the current source */ 
4826
	sourcefile = s;
4827
	lexptr = NULL;
4828
	sourceline = 0;
4829
	source = NULL;
4830
	lasttok = 0;
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
4831
	lexeof = false;
4832
	eof_warned = false;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4833
	return 0;
4834
}
4835
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
4836
/* load_library --- load a shared library */
4837
4838
static int
4839
load_library(INSTRUCTION *file)
4840
{
4841
	SRCFILE *s;
4842
	char *src = file->lextok;
4843
	int errcode;
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
4844
	bool already_included;
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
4845
4846
	if (do_traditional || do_posix) {
4847
		error_ln(file->source_line, _("@load is a gawk extension"));
4848
		return -1;
4849
	}
4850
4851
	if (strlen(src) == 0) {
4852
		if (do_lint)
4853
			lintwarn_ln(file->source_line, _("empty filename after @load"));
4854
		return 0;
4855
	}
4856
4857
	s = add_srcfile(SRC_EXTLIB, src, sourcefile, &already_included, &errcode);
4858
	if (s == NULL) {
4859
		if (already_included)
4860
			return 0;
4861
		error_ln(file->source_line,
4862
			_("can't open shared library `%s' for reading (%s)"),
4863
			src, errcode ? strerror(errcode) : _("reason unknown"));
4864
		return -1;
4865
	}
4866
319.2.39 by Arnold D. Robbins
Remove extension() builtin.
4867
	load_ext(s->fullpath);
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
4868
	return 0;
4869
}
4870
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4871
/* next_sourcefile --- read program from the next source in srcfiles */
4872
4873
static void
4874
next_sourcefile()
4875
{
4876
	static int (*closefunc)(int fd) = NULL;
4877
4878
	if (closefunc == NULL) {
4879
		char *cp = getenv("AWKREADFUNC");
4880
4881
		/* If necessary, one day, test value for different functions.  */
4882
		if (cp == NULL)
4883
			closefunc = close;
4884
		else
4885
			closefunc = one_line_close;
4886
	}
4887
127 by Arnold D. Robbins
Regex bug fix and token bug fix. See ChangeLog.
4888
	/*
4889
	 * This won't be true if there's an invalid character in
4890
	 * the source file or source string (e.g., user typo).
4891
	 * Previous versions of gawk did not core dump in such a
4892
	 * case.
4893
	 *
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
4894
	 * assert(lexeof == true);
127 by Arnold D. Robbins
Regex bug fix and token bug fix. See ChangeLog.
4895
	 */
281.1.1 by john haque
Speed/memory performance improvements.
4896
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
4897
	lexeof = false;
4898
	eof_warned = false;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4899
	sourcefile->srclines = sourceline;	/* total no of lines in current file */
4900
	if (sourcefile->fd > INVALID_HANDLE) {
4901
		if (sourcefile->fd != fileno(stdin))  /* safety */
4902
			(*closefunc)(sourcefile->fd);
4903
		sourcefile->fd = INVALID_HANDLE;
4904
	}
4905
	if (sourcefile->buf != NULL) {
4906
		efree(sourcefile->buf);
4907
		sourcefile->buf = NULL;
4908
		sourcefile->lexptr_begin = NULL;
4909
	}
4910
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
4911
	while ((sourcefile = sourcefile->next) != NULL) {
4912
		if (sourcefile == srcfiles)
4913
			return;
4914
		if (sourcefile->stype != SRC_EXTLIB)
4915
			break;
4916
	}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4917
4918
	if (sourcefile->lexptr_begin != NULL) {
4919
		/* resume reading from already opened file (postponed to process '@include') */
4920
		lexptr = sourcefile->lexptr;
4921
		lexend = sourcefile->lexend;
4922
		lasttok = sourcefile->lasttok;
4923
		lexptr_begin = sourcefile->lexptr_begin;
4924
		lexeme = sourcefile->lexeme;
4925
		sourceline = sourcefile->srclines;
4926
		source = sourcefile->src;
4927
	} else {
4928
		lexptr = NULL;
4929
		sourceline = 0;
4930
		source = NULL;
4931
		lasttok = 0;
4932
	}
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4933
}
4934
4935
/* get_src_buf --- read the next buffer of source program */
4936
4937
static char *
4938
get_src_buf()
4939
{
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4940
	int n;
4941
	char *scan;
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
4942
	bool newfile;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4943
	int savelen;
4944
	struct stat sbuf;
32 by Arnold D. Robbins
Move to gawk-3.1.4.
4945
34 by Arnold D. Robbins
Move to gawk-3.1.6.
4946
	/*
4947
	 * No argument prototype on readfunc on purpose,
4948
	 * avoids problems with some ancient systems where
4949
	 * the types of arguments to read() aren't up to date.
4950
	 */
4951
	static ssize_t (*readfunc)() = 0;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4952
34 by Arnold D. Robbins
Move to gawk-3.1.6.
4953
	if (readfunc == NULL) {
4954
		char *cp = getenv("AWKREADFUNC");
4955
4956
		/* If necessary, one day, test value for different functions.  */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4957
		if (cp == NULL)
101 by Arnold D. Robbins
Try to kill some warnings.
4958
			/*
4959
			 * cast is to remove warnings on systems with
4960
			 * different return types for read.
4961
			 */
4962
			readfunc = ( ssize_t(*)() ) read;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4963
		else
34 by Arnold D. Robbins
Move to gawk-3.1.6.
4964
			readfunc = read_one_line;
4965
	}
4966
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
4967
	newfile = false;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4968
	if (sourcefile == srcfiles)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4969
		return NULL;
4970
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4971
	if (sourcefile->stype == SRC_CMDLINE) {
4972
		if (sourcefile->bufsize == 0) {
4973
			sourcefile->bufsize = strlen(sourcefile->src);
4974
			lexptr = lexptr_begin = lexeme = sourcefile->src;
4975
			lexend = lexptr + sourcefile->bufsize;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
4976
			sourceline = 1;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4977
			if (sourcefile->bufsize == 0) {
4978
				/*
4979
				 * Yet Another Special case:
4980
				 *	gawk '' /path/name
4981
				 * Sigh.
4982
				 */
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
4983
				static bool warned = false;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4984
4985
				if (do_lint && ! warned) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
4986
					warned = true;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4987
					lintwarn(_("empty program text on command line"));
4988
				}
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
4989
				lexeof = true;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
4990
			}
4991
		} else if (sourcefile->buf == NULL  && *(lexptr-1) != '\n') {
4992
			/*
4993
			 * The following goop is to ensure that the source
4994
			 * ends with a newline and that the entire current
4995
			 * line is available for error messages.
4996
			 */
4997
			int offset;
4998
			char *buf;
4999
5000
			offset = lexptr - lexeme;
5001
			for (scan = lexeme; scan > lexptr_begin; scan--)
5002
				if (*scan == '\n') {
5003
					scan++;
5004
					break;
5005
				}
5006
			savelen = lexptr - scan;
5007
			emalloc(buf, char *, savelen + 1, "get_src_buf");
5008
			memcpy(buf, scan, savelen);
5009
			thisline = buf;
5010
			lexptr = buf + savelen;
5011
			*lexptr = '\n';
5012
			lexeme = lexptr - offset;
5013
			lexptr_begin = buf;
5014
			lexend = lexptr + 1;
5015
			sourcefile->buf = buf;
5016
		} else
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5017
			lexeof = true;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5018
		return lexptr;
5019
	}
32 by Arnold D. Robbins
Move to gawk-3.1.4.
5020
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5021
	if (sourcefile->fd <= INVALID_HANDLE) {
5022
		int fd;
5023
		int l;
5024
5025
		source = sourcefile->src;
5026
		if (source == NULL)
5027
			return NULL;
5028
		fd = srcopen(sourcefile);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5029
		if (fd <= INVALID_HANDLE) {
5030
			char *in;
5031
5032
			/* suppress file name and line no. in error mesg */
5033
			in = source;
5034
			source = NULL;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5035
			error(_("can't open source file `%s' for reading (%s)"),
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5036
				in, strerror(errno));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5037
			errcount++;
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5038
			lexeof = true;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5039
			return sourcefile->src;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5040
		}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5041
5042
		sourcefile->fd = fd;
5043
		l = optimal_bufsize(fd, &sbuf);
32 by Arnold D. Robbins
Move to gawk-3.1.4.
5044
		/*
5045
		 * Make sure that something silly like
5046
		 * 	AWKBUFSIZE=8 make check
5047
		 * works ok.
5048
		 */
5049
#define A_DECENT_BUFFER_SIZE	128
5050
		if (l < A_DECENT_BUFFER_SIZE)
5051
			l = A_DECENT_BUFFER_SIZE;
5052
#undef A_DECENT_BUFFER_SIZE
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5053
		sourcefile->bufsize = l;
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5054
		newfile = true;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5055
		emalloc(sourcefile->buf, char *, sourcefile->bufsize, "get_src_buf");
5056
		lexptr = lexptr_begin = lexeme = sourcefile->buf;
5057
		savelen = 0;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5058
		sourceline = 1;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5059
		thisline = NULL;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5060
	} else {
5061
		/*
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5062
		 * Here, we retain the current source line in the beginning of the buffer.
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5063
		 */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5064
		int offset;
5065
		for (scan = lexeme; scan > lexptr_begin; scan--)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5066
			if (*scan == '\n') {
5067
				scan++;
5068
				break;
5069
			}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5070
5071
		savelen = lexptr - scan;
5072
		offset = lexptr - lexeme;
5073
5074
		if (savelen > 0) {
32 by Arnold D. Robbins
Move to gawk-3.1.4.
5075
			/*
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5076
			 * Need to make sure we have room left for reading new text;
5077
			 * grow the buffer (by doubling, an arbitrary choice), if the retained line
5078
			 * takes up more than a certain percentage (50%, again an arbitrary figure)
5079
			 * of the available space.
32 by Arnold D. Robbins
Move to gawk-3.1.4.
5080
			 */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5081
5082
			if (savelen > sourcefile->bufsize / 2) { /* long line or token  */
5083
				sourcefile->bufsize *= 2;
5084
				erealloc(sourcefile->buf, char *, sourcefile->bufsize, "get_src_buf");
5085
				scan = sourcefile->buf + (scan - lexptr_begin);
5086
				lexptr_begin = sourcefile->buf;
5087
			}
5088
5089
			thisline = lexptr_begin;
5090
			memmove(thisline, scan, savelen);
5091
			lexptr = thisline + savelen;
5092
			lexeme = lexptr - offset;
5093
		} else {
5094
			savelen = 0;
5095
			lexptr = lexeme = lexptr_begin;
5096
			thisline = NULL;
32 by Arnold D. Robbins
Move to gawk-3.1.4.
5097
		}
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5098
	}
32 by Arnold D. Robbins
Move to gawk-3.1.4.
5099
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5100
	n = (*readfunc)(sourcefile->fd, lexptr, sourcefile->bufsize - savelen);
5101
	if (n == -1) {
5102
		error(_("can't read sourcefile `%s' (%s)"),
5103
				source, strerror(errno));
5104
		errcount++;
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5105
		lexeof = true;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5106
	} else {
5107
		lexend = lexptr + n;
5108
		if (n == 0) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5109
			static bool warned = false;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5110
			if (do_lint && newfile && ! warned){
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5111
				warned = true;
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
5112
				sourceline = 0;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5113
				lintwarn(_("source file `%s' is empty"), source);
5114
			}
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5115
			lexeof = true;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5116
		}
5117
	}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5118
	return sourcefile->buf;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5119
}
5120
5121
/* tokadd --- add a character to the token buffer */
5122
5123
#define	tokadd(x) (*tok++ = (x), tok == tokend ? tokexpand() : tok)
5124
5125
/* tokexpand --- grow the token buffer */
5126
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5127
static char *
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5128
tokexpand()
5129
{
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5130
	static int toksize;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5131
	int tokoffset;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5132
			
5133
	if (tokstart != NULL) {
5134
		tokoffset = tok - tokstart;
5135
		toksize *= 2;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5136
		erealloc(tokstart, char *, toksize, "tokexpand");
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5137
		tok = tokstart + tokoffset;
5138
	} else {
5139
		toksize = 60;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5140
		emalloc(tokstart, char *, toksize, "tokexpand");
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5141
		tok = tokstart;
5142
	}
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5143
	tokend = tokstart + toksize;
5144
	return tok;
5145
}
5146
408.5.217 by Arnold D. Robbins
Make source code character checking smarter.
5147
/* check_bad_char --- fatal if c isn't allowed in gawk source code */
5148
5149
/*
5150
 * The error message was inspired by someone who decided to put
5151
 * a physical \0 byte into the source code to see what would
5152
 * happen and then filed a bug report about it.  Sigh.
5153
 */
5154
5155
static void
5156
check_bad_char(int c)
5157
{
5158
	/* allow escapes. needed for autoconf. bleah. */
5159
	switch (c) {
5160
	case '\a':
5161
	case '\b':
5162
	case '\f':
5163
	case '\n':
5164
	case '\r':
5165
	case '\t':
5166
		return;
5167
	default:
5168
		break;
5169
	}
5170
5171
	if (iscntrl(c) && ! isspace(c))
408.5.282 by Arnold D. Robbins
Minor fix when checking for bad source characters.
5172
		fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), c & 0xFF);
408.5.217 by Arnold D. Robbins
Make source code character checking smarter.
5173
}
5174
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5175
/* nextc --- get the next input character */
5176
29 by Arnold D. Robbins
Move to gawk-3.1.1.
5177
static int
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5178
nextc(bool check_for_bad)
29 by Arnold D. Robbins
Move to gawk-3.1.1.
5179
{
33 by Arnold D. Robbins
Move to gawk 3.1.5.
5180
	if (gawk_mb_cur_max > 1) {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5181
again:
5182
		if (lexeof)
5183
			return END_FILE;
5184
		if (lexptr == NULL || lexptr >= lexend) {
5185
			if (get_src_buf())
5186
				goto again;
5187
			return END_SRC;
33 by Arnold D. Robbins
Move to gawk 3.1.5.
5188
		}
5189
29 by Arnold D. Robbins
Move to gawk-3.1.1.
5190
		/* Update the buffer index.  */
5191
		cur_ring_idx = (cur_ring_idx == RING_BUFFER_SIZE - 1)? 0 :
5192
			cur_ring_idx + 1;
5193
5194
		/* Did we already check the current character?  */
5195
		if (cur_char_ring[cur_ring_idx] == 0) {
5196
			/* No, we need to check the next character on the buffer.  */
5197
			int idx, work_ring_idx = cur_ring_idx;
5198
			mbstate_t tmp_state;
5199
			size_t mbclen;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5200
	
29 by Arnold D. Robbins
Move to gawk-3.1.1.
5201
			for (idx = 0 ; lexptr + idx < lexend ; idx++) {
5202
				tmp_state = cur_mbstate;
5203
				mbclen = mbrlen(lexptr, idx + 1, &tmp_state);
5204
5205
				if (mbclen == 1 || mbclen == (size_t)-1 || mbclen == 0) {
5206
					/* It is a singlebyte character, non-complete multibyte
5207
					   character or EOF.  We treat it as a singlebyte
5208
					   character.  */
5209
					cur_char_ring[work_ring_idx] = 1;
5210
					break;
5211
				} else if (mbclen == (size_t)-2) {
5212
					/* It is not a complete multibyte character.  */
5213
					cur_char_ring[work_ring_idx] = idx + 1;
5214
				} else {
5215
					/* mbclen > 1 */
5216
					cur_char_ring[work_ring_idx] = mbclen;
5217
					break;
5218
				}
5219
				work_ring_idx = (work_ring_idx == RING_BUFFER_SIZE - 1)?
5220
					0 : work_ring_idx + 1;
5221
			}
5222
			cur_mbstate = tmp_state;
5223
5224
			/* Put a mark on the position on which we write next character.  */
5225
			work_ring_idx = (work_ring_idx == RING_BUFFER_SIZE - 1)?
5226
				0 : work_ring_idx + 1;
5227
			cur_char_ring[work_ring_idx] = 0;
5228
		}
408.19.54 by Arnold D. Robbins
Disallow nul bytes in source code no matter what.
5229
		if (check_for_bad || *lexptr == '\0')
408.5.217 by Arnold D. Robbins
Make source code character checking smarter.
5230
			check_bad_char(*lexptr);
29 by Arnold D. Robbins
Move to gawk-3.1.1.
5231
5232
		return (int) (unsigned char) *lexptr++;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5233
	} else {
5234
		do {
5235
			if (lexeof)
5236
				return END_FILE;
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5237
			if (lexptr && lexptr < lexend) {
408.19.54 by Arnold D. Robbins
Disallow nul bytes in source code no matter what.
5238
				if (check_for_bad || *lexptr == '\0')
408.5.217 by Arnold D. Robbins
Make source code character checking smarter.
5239
					check_bad_char(*lexptr);
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5240
				return ((int) (unsigned char) *lexptr++);
5241
			}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5242
		} while (get_src_buf());
5243
		return END_SRC;
29 by Arnold D. Robbins
Move to gawk-3.1.1.
5244
	}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5245
}
5246
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5247
/* pushback --- push a character back on the input */
5248
33 by Arnold D. Robbins
Move to gawk 3.1.5.
5249
static inline void
30 by Arnold D. Robbins
Move to gawk-3.1.2.
5250
pushback(void)
29 by Arnold D. Robbins
Move to gawk-3.1.1.
5251
{
33 by Arnold D. Robbins
Move to gawk 3.1.5.
5252
	if (gawk_mb_cur_max > 1)
29 by Arnold D. Robbins
Move to gawk-3.1.1.
5253
		cur_ring_idx = (cur_ring_idx == 0)? RING_BUFFER_SIZE - 1 :
5254
			cur_ring_idx - 1;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5255
	(! lexeof && lexptr && lexptr > lexptr_begin ? lexptr-- : lexptr);
29 by Arnold D. Robbins
Move to gawk-3.1.1.
5256
}
5257
5258
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5259
/* allow_newline --- allow newline after &&, ||, ? and : */
5260
5261
static void
30 by Arnold D. Robbins
Move to gawk-3.1.2.
5262
allow_newline(void)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5263
{
5264
	int c;
5265
5266
	for (;;) {
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5267
		c = nextc(true);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5268
		if (c == END_FILE) {
5269
			pushback();
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5270
			break;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5271
		}
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5272
		if (c == '#') {
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5273
			while ((c = nextc(false)) != '\n' && c != END_FILE)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5274
				continue;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5275
			if (c == END_FILE) {
5276
				pushback();
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5277
				break;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5278
			}
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5279
		}
5280
		if (c == '\n')
5281
			sourceline++;
36 by Arnold D. Robbins
Move to 3.1.8.
5282
		if (! isspace(c)) {
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5283
			pushback();
5284
			break;
5285
		}
5286
	}
5287
}
5288
277.1.103 by Arnold D. Robbins
Fix warnings from gcc -Wall, GCC 4.6.2.
5289
/* newline_eof --- return newline or EOF as needed and adjust variables */
5290
5291
/*
5292
 * This routine used to be a macro, however GCC 4.6.2 warned about
5293
 * the result of a computation not being used.  Converting to a function
5294
 * removes the warnings.
5295
 */
5296
5297
static int newline_eof()
5298
{
5299
	/* NB: a newline at end does not start a source line. */
5300
	if (lasttok != NEWLINE) {
5301
                pushback();
5302
		if (do_lint && ! eof_warned) {
5303
        		lintwarn(_("source file does not end in newline"));
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5304
			eof_warned = true;
277.1.103 by Arnold D. Robbins
Fix warnings from gcc -Wall, GCC 4.6.2.
5305
		}
5306
		sourceline++;
5307
		return NEWLINE;
5308
	}
5309
5310
	sourceline--;
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5311
	eof_warned = false;
277.1.103 by Arnold D. Robbins
Fix warnings from gcc -Wall, GCC 4.6.2.
5312
	return LEX_EOF;
5313
}
5314
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5315
/* yylex --- Read the input and turn it into tokens. */
5316
5317
static int
408.21.1 by Arnold D. Robbins
Rework zOS patches; keep separate from autotools.
5318
#ifdef USE_EBCDIC
5319
yylex_ebcdic(void)
5320
#else
30 by Arnold D. Robbins
Move to gawk-3.1.2.
5321
yylex(void)
408.21.1 by Arnold D. Robbins
Rework zOS patches; keep separate from autotools.
5322
#endif
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5323
{
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5324
	int c;
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5325
	bool seen_e = false;		/* These are for numbers */
5326
	bool seen_point = false;
5327
	bool esc_seen;		/* for literal strings */
32 by Arnold D. Robbins
Move to gawk-3.1.4.
5328
	int mid;
300 by john haque
Add infrastructure for MPFR/GMP support.
5329
	int base;
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5330
	static bool did_newline = false;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5331
	char *tokkey;
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5332
	bool inhex = false;
5333
	bool intlstr = false;
281.1.1 by john haque
Speed/memory performance improvements.
5334
	AWKNUM d;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5335
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5336
#define GET_INSTRUCTION(op) bcalloc(op, 1, sourceline)
5337
277.1.103 by Arnold D. Robbins
Fix warnings from gcc -Wall, GCC 4.6.2.
5338
#define NEWLINE_EOF newline_eof()
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5339
5340
	yylval = (INSTRUCTION *) NULL;
5341
	if (lasttok == SUBSCRIPT) {
5342
		lasttok = 0;
5343
		return SUBSCRIPT;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5344
	}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5345
 
5346
	if (lasttok == LEX_EOF)		/* error earlier in current source, must give up !! */
5347
		return 0;
5348
408.13.77 by Arnold D. Robbins
Improve regexp collection on Solaris, maybe others.
5349
	c = nextc(! want_regexp);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5350
	if (c == END_SRC)
5351
		return 0;
5352
	if (c == END_FILE)
5353
		return lasttok = NEWLINE_EOF;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5354
	pushback();
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5355
71 by Arnold D. Robbins
Cleanup the mainline PC code, and pc/ directory.
5356
#if defined __EMX__
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5357
	/*
5358
	 * added for OS/2's extproc feature of cmd.exe
5359
	 * (like #! in BSD sh)
5360
	 */
5361
	if (strncasecmp(lexptr, "extproc ", 8) == 0) {
5362
		while (*lexptr && *lexptr != '\n')
5363
			lexptr++;
5364
	}
5365
#endif
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5366
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5367
	lexeme = lexptr;
5368
	thisline = NULL;
5369
	if (want_regexp) {
5370
		int in_brack = 0;	/* count brackets, [[:alnum:]] allowed */
408.13.157 by Arnold D. Robbins
Fix bracket handling. "This time for sure."
5371
		int b_index = -1;
5372
		int cur_index = 0;
5373
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5374
		/*
408.13.157 by Arnold D. Robbins
Fix bracket handling. "This time for sure."
5375
		 * Here is what's ok with brackets:
5376
		 *
408.13.163 by Arnold D. Robbins
Fix brackets in regexps again. Let's hope this is really it.
5377
		 * [..[..] []] [^]] [.../...]
408.13.157 by Arnold D. Robbins
Fix bracket handling. "This time for sure."
5378
		 * [...\[...] [...\]...] [...\/...]
5379
		 * 
5380
		 * (Remember that all of the above are inside /.../)
5381
		 *
5382
		 * The code for \ handles \[, \] and \/.
5383
		 *
5384
		 * Otherwise, track the first open [ position, and if
408.13.163 by Arnold D. Robbins
Fix brackets in regexps again. Let's hope this is really it.
5385
		 * an embedded ] occurs, allow it to pass through
408.13.157 by Arnold D. Robbins
Fix bracket handling. "This time for sure."
5386
		 * if it's right after the first [ or after [^.
5387
		 *
5388
		 * Whew!
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5389
		 */
5390
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5391
		want_regexp = false;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5392
		tok = tokstart;
5393
		for (;;) {
408.13.77 by Arnold D. Robbins
Improve regexp collection on Solaris, maybe others.
5394
			c = nextc(false);
33 by Arnold D. Robbins
Move to gawk 3.1.5.
5395
408.13.163 by Arnold D. Robbins
Fix brackets in regexps again. Let's hope this is really it.
5396
			cur_index = tok - tokstart;
33 by Arnold D. Robbins
Move to gawk 3.1.5.
5397
			if (gawk_mb_cur_max == 1 || nextc_is_1stbyte) switch (c) {
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5398
			case '[':
408.13.166 by Arnold D. Robbins
Fix parsing brackets in regexps (again).
5399
				if (nextc(false) == ':' || in_brack == 0) {
408.13.163 by Arnold D. Robbins
Fix brackets in regexps again. Let's hope this is really it.
5400
					in_brack++;
408.13.166 by Arnold D. Robbins
Fix parsing brackets in regexps (again).
5401
					if (in_brack == 1)
5402
						b_index = tok - tokstart;
5403
				}
408.13.163 by Arnold D. Robbins
Fix brackets in regexps again. Let's hope this is really it.
5404
				pushback();
5405
				break;
408.13.157 by Arnold D. Robbins
Fix bracket handling. "This time for sure."
5406
			case ']':
5407
				if (in_brack > 0
5408
				    && (cur_index == b_index + 1 
5409
					|| (cur_index == b_index + 2 && tok[-1] == '^')))
5410
					; /* do nothing */
408.13.163 by Arnold D. Robbins
Fix brackets in regexps again. Let's hope this is really it.
5411
				else {
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5412
					in_brack--;
408.13.157 by Arnold D. Robbins
Fix bracket handling. "This time for sure."
5413
					if (in_brack == 0)
5414
						b_index = -1;
5415
				}
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5416
				break;
5417
			case '\\':
408.13.77 by Arnold D. Robbins
Improve regexp collection on Solaris, maybe others.
5418
				if ((c = nextc(false)) == END_FILE) {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5419
					pushback();
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5420
					yyerror(_("unterminated regexp ends with `\\' at end of file"));
31 by Arnold D. Robbins
Move to gawk-3.1.3.
5421
					goto end_regexp; /* kludge */
408.13.86 by Arnold D. Robbins
Fix line continuation with CR-LF.
5422
				}
5423
				if (c == '\r')	/* allow MS-DOS files. bleah */
5424
					c = nextc(true);
5425
				if (c == '\n') {
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5426
					sourceline++;
5427
					continue;
5428
				} else {
5429
					tokadd('\\');
5430
					tokadd(c);
5431
					continue;
5432
				}
5433
				break;
5434
			case '/':	/* end of the regexp */
5435
				if (in_brack > 0)
5436
					break;
31 by Arnold D. Robbins
Move to gawk-3.1.3.
5437
end_regexp:
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5438
				yylval = GET_INSTRUCTION(Op_token);
5439
				yylval->lextok = estrdup(tokstart, tok - tokstart);
33 by Arnold D. Robbins
Move to gawk 3.1.5.
5440
				if (do_lint) {
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5441
					int peek = nextc(true);
33 by Arnold D. Robbins
Move to gawk 3.1.5.
5442
5443
					pushback();
5444
					if (peek == 'i' || peek == 's') {
5445
						if (source)
5446
							lintwarn(
5447
						_("%s: %d: tawk regex modifier `/.../%c' doesn't work in gawk"),
5448
								source, sourceline, peek);
5449
						else
5450
							lintwarn(
5451
						_("tawk regex modifier `/.../%c' doesn't work in gawk"),
5452
								peek);
5453
					}
5454
				}
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5455
				return lasttok = REGEXP;
5456
			case '\n':
5457
				pushback();
5458
				yyerror(_("unterminated regexp"));
31 by Arnold D. Robbins
Move to gawk-3.1.3.
5459
				goto end_regexp;	/* kludge */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5460
			case END_FILE:
5461
				pushback();
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5462
				yyerror(_("unterminated regexp at end of file"));
31 by Arnold D. Robbins
Move to gawk-3.1.3.
5463
				goto end_regexp;	/* kludge */
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5464
			}
5465
			tokadd(c);
5466
		}
5467
	}
5468
retry:
33 by Arnold D. Robbins
Move to gawk 3.1.5.
5469
5470
	/* skipping \r is a hack, but windows is just too pervasive. sigh. */
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5471
	while ((c = nextc(true)) == ' ' || c == '\t' || c == '\r')
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5472
		continue;
5473
5474
	lexeme = lexptr ? lexptr - 1 : lexptr;
5475
	thisline = NULL;
5476
	tok = tokstart;
5477
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5478
	if (gawk_mb_cur_max == 1 || nextc_is_1stbyte)
5479
	switch (c) {
5480
	case END_SRC:
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5481
		return 0;
5482
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5483
	case END_FILE:
5484
		return lasttok = NEWLINE_EOF;
5485
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5486
	case '\n':
5487
		sourceline++;
5488
		return lasttok = NEWLINE;
5489
5490
	case '#':		/* it's a comment */
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5491
		while ((c = nextc(false)) != '\n') {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5492
			if (c == END_FILE)
5493
				return lasttok = NEWLINE_EOF;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5494
		}
5495
		sourceline++;
5496
		return lasttok = NEWLINE;
5497
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5498
	case '@':
408.13.59 by Arnold D. Robbins
Disallow calling a function parameter. Check params are not function names.
5499
		at_seen = true;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5500
		return lasttok = '@';
5501
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5502
	case '\\':
5503
#ifdef RELAXED_CONTINUATION
5504
		/*
5505
		 * This code puports to allow comments and/or whitespace
5506
		 * after the `\' at the end of a line used for continuation.
5507
		 * Use it at your own risk. We think it's a bad idea, which
5508
		 * is why it's not on by default.
5509
		 */
5510
		if (! do_traditional) {
5511
			/* strip trailing white-space and/or comment */
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5512
			while ((c = nextc(true)) == ' ' || c == '\t' || c == '\r')
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5513
				continue;
5514
			if (c == '#') {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5515
				static bool warned = false;
34 by Arnold D. Robbins
Move to gawk-3.1.6.
5516
5517
				if (do_lint && ! warned) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5518
					warned = true;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5519
					lintwarn(
5520
		_("use of `\\ #...' line continuation is not portable"));
34 by Arnold D. Robbins
Move to gawk-3.1.6.
5521
				}
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5522
				while ((c = nextc(false)) != '\n')
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5523
					if (c == END_FILE)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5524
						break;
5525
			}
5526
			pushback();
5527
		}
5528
#endif /* RELAXED_CONTINUATION */
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5529
		c = nextc(true);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5530
		if (c == '\r')	/* allow MS-DOS files. bleah */
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5531
			c = nextc(true);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5532
		if (c == '\n') {
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5533
			sourceline++;
5534
			goto retry;
5535
		} else {
5536
			yyerror(_("backslash not last character on line"));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5537
			return lasttok = LEX_EOF;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5538
		}
5539
		break;
5540
5541
	case ':':
5542
	case '?':
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5543
		yylval = GET_INSTRUCTION(Op_cond_exp);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5544
		if (! do_posix)
5545
			allow_newline();
5546
		return lasttok = c;
5547
30 by Arnold D. Robbins
Move to gawk-3.1.2.
5548
		/*
5549
		 * in_parens is undefined unless we are parsing a print
5550
		 * statement (in_print), but why bother with a check?
5551
		 */
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5552
	case ')':
30 by Arnold D. Robbins
Move to gawk-3.1.2.
5553
		in_parens--;
5554
		return lasttok = c;
5555
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5556
	case '(':	
30 by Arnold D. Robbins
Move to gawk-3.1.2.
5557
		in_parens++;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5558
		return lasttok = c;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
5559
	case '$':
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5560
		yylval = GET_INSTRUCTION(Op_field_spec);
5561
		return lasttok = c;
5562
	case '{':
5563
		if (++in_braces == 1)
5564
			firstline = sourceline;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5565
	case ';':
5566
	case ',':
5567
	case '[':
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5568
			return lasttok = c;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5569
	case ']':
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5570
		c = nextc(true);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5571
		pushback();
5572
		if (c == '[') {
408.19.42 by Arnold D. Robbins
Fatal with --posix on multidimensional arrays.
5573
			if (do_traditional)
5574
				fatal(_("multidimensional arrays are a gawk extension"));
5575
			if (do_lint)
5576
				lintwarn(_("multidimensional arrays are a gawk extension"));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5577
			yylval = GET_INSTRUCTION(Op_sub_array);
5578
			lasttok = ']';
5579
		} else {
5580
			yylval = GET_INSTRUCTION(Op_subscript);
5581
			lasttok = SUBSCRIPT;	/* end of subscripts */
5582
		}
5583
		return ']';
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5584
5585
	case '*':
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5586
		if ((c = nextc(true)) == '=') {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5587
			yylval = GET_INSTRUCTION(Op_assign_times);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5588
			return lasttok = ASSIGNOP;
5589
		} else if (do_posix) {
5590
			pushback();
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5591
			yylval = GET_INSTRUCTION(Op_times);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5592
			return lasttok = '*';
5593
		} else if (c == '*') {
5594
			/* make ** and **= aliases for ^ and ^= */
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5595
			static bool did_warn_op = false, did_warn_assgn = false;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5596
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5597
			if (nextc(true) == '=') {
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5598
				if (! did_warn_assgn) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5599
					did_warn_assgn = true;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5600
					if (do_lint)
5601
						lintwarn(_("POSIX does not allow operator `**='"));
5602
					if (do_lint_old)
5603
						warning(_("old awk does not support operator `**='"));
5604
				}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5605
				yylval = GET_INSTRUCTION(Op_assign_exp);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5606
				return ASSIGNOP;
5607
			} else {
5608
				pushback();
5609
				if (! did_warn_op) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5610
					did_warn_op = true;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5611
					if (do_lint)
5612
						lintwarn(_("POSIX does not allow operator `**'"));
5613
					if (do_lint_old)
5614
						warning(_("old awk does not support operator `**'"));
5615
				}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5616
				yylval = GET_INSTRUCTION(Op_exp);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5617
				return lasttok = '^';
5618
			}
5619
		}
5620
		pushback();
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5621
		yylval = GET_INSTRUCTION(Op_times);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5622
		return lasttok = '*';
5623
5624
	case '/':
408.13.77 by Arnold D. Robbins
Improve regexp collection on Solaris, maybe others.
5625
		if (nextc(false) == '=') {
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5626
			pushback();
30 by Arnold D. Robbins
Move to gawk-3.1.2.
5627
			return lasttok = SLASH_BEFORE_EQUAL;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5628
		}
30 by Arnold D. Robbins
Move to gawk-3.1.2.
5629
		pushback();
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5630
		yylval = GET_INSTRUCTION(Op_quotient);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5631
		return lasttok = '/';
5632
5633
	case '%':
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5634
		if (nextc(true) == '=') {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5635
			yylval = GET_INSTRUCTION(Op_assign_mod);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5636
			return lasttok = ASSIGNOP;
5637
		}
5638
		pushback();
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5639
		yylval = GET_INSTRUCTION(Op_mod);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5640
		return lasttok = '%';
5641
5642
	case '^':
5643
	{
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5644
		static bool did_warn_op = false, did_warn_assgn = false;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5645
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5646
		if (nextc(true) == '=') {
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5647
			if (do_lint_old && ! did_warn_assgn) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5648
				did_warn_assgn = true;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5649
				warning(_("operator `^=' is not supported in old awk"));
5650
			}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5651
			yylval = GET_INSTRUCTION(Op_assign_exp);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5652
			return lasttok = ASSIGNOP;
5653
		}
5654
		pushback();
5655
		if (do_lint_old && ! did_warn_op) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5656
			did_warn_op = true;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5657
			warning(_("operator `^' is not supported in old awk"));
5658
		}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5659
		yylval = GET_INSTRUCTION(Op_exp);	
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5660
		return lasttok = '^';
5661
	}
5662
5663
	case '+':
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5664
		if ((c = nextc(true)) == '=') {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5665
			yylval = GET_INSTRUCTION(Op_assign_plus);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5666
			return lasttok = ASSIGNOP;
5667
		}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5668
		if (c == '+') {
5669
			yylval = GET_INSTRUCTION(Op_symbol);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5670
			return lasttok = INCREMENT;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5671
		}
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5672
		pushback();
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5673
		yylval = GET_INSTRUCTION(Op_plus);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5674
		return lasttok = '+';
5675
5676
	case '!':
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5677
		if ((c = nextc(true)) == '=') {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5678
			yylval = GET_INSTRUCTION(Op_notequal);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5679
			return lasttok = RELOP;
5680
		}
5681
		if (c == '~') {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5682
			yylval = GET_INSTRUCTION(Op_nomatch);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5683
			return lasttok = MATCHOP;
5684
		}
5685
		pushback();
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5686
		yylval = GET_INSTRUCTION(Op_symbol);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5687
		return lasttok = '!';
5688
5689
	case '<':
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5690
		if (nextc(true) == '=') {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5691
			yylval = GET_INSTRUCTION(Op_leq);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5692
			return lasttok = RELOP;
5693
		}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5694
		yylval = GET_INSTRUCTION(Op_less);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5695
		pushback();
5696
		return lasttok = '<';
5697
5698
	case '=':
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5699
		if (nextc(true) == '=') {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5700
			yylval = GET_INSTRUCTION(Op_equal);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5701
			return lasttok = RELOP;
5702
		}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5703
		yylval = GET_INSTRUCTION(Op_assign);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5704
		pushback();
30 by Arnold D. Robbins
Move to gawk-3.1.2.
5705
		return lasttok = ASSIGN;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5706
5707
	case '>':
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5708
		if ((c = nextc(true)) == '=') {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5709
			yylval = GET_INSTRUCTION(Op_geq);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5710
			return lasttok = RELOP;
5711
		} else if (c == '>') {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5712
			yylval = GET_INSTRUCTION(Op_symbol);
5713
			yylval->redir_type = redirect_append;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
5714
			return lasttok = IO_OUT;
5715
		}
5716
		pushback();
5717
		if (in_print && in_parens == 0) {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5718
			yylval = GET_INSTRUCTION(Op_symbol);
5719
			yylval->redir_type = redirect_output;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
5720
			return lasttok = IO_OUT;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5721
		}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5722
		yylval = GET_INSTRUCTION(Op_greater);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5723
		return lasttok = '>';
5724
5725
	case '~':
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5726
		yylval = GET_INSTRUCTION(Op_match);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5727
		return lasttok = MATCHOP;
5728
5729
	case '}':
5730
		/*
5731
		 * Added did newline stuff.  Easier than
5732
		 * hacking the grammar.
5733
		 */
5734
		if (did_newline) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5735
			did_newline = false;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5736
			if (--in_braces == 0)
5737
				lastline = sourceline;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5738
			return lasttok = c;
5739
		}
5740
		did_newline++;
5741
		--lexptr;	/* pick up } next time */
5742
		return lasttok = NEWLINE;
5743
5744
	case '"':
5745
	string:
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5746
		esc_seen = false;
408.5.279 by Arnold D. Robbins
Allow any kind of junk inside quoted strings.
5747
		/*
5748
		 * Allow any kind of junk in quoted string,
5749
		 * so pass false to nextc().
5750
		 */
5751
		while ((c = nextc(false)) != '"') {
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5752
			if (c == '\n') {
5753
				pushback();
5754
				yyerror(_("unterminated string"));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5755
				return lasttok = LEX_EOF;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5756
			}
33 by Arnold D. Robbins
Move to gawk 3.1.5.
5757
			if ((gawk_mb_cur_max == 1 || nextc_is_1stbyte) &&
5758
			    c == '\\') {
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5759
				c = nextc(true);
408.13.86 by Arnold D. Robbins
Fix line continuation with CR-LF.
5760
				if (c == '\r')	/* allow MS-DOS files. bleah */
5761
					c = nextc(true);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5762
				if (c == '\n') {
5763
					sourceline++;
5764
					continue;
5765
				}
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5766
				esc_seen = true;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5767
				if (! want_source || c != '"')
5768
					tokadd('\\');
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5769
			}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5770
			if (c == END_FILE) {
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5771
				pushback();
5772
				yyerror(_("unterminated string"));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5773
				return lasttok = LEX_EOF;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5774
			}
5775
			tokadd(c);
5776
		}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5777
		yylval = GET_INSTRUCTION(Op_token);
5778
		if (want_source) {
281.1.2 by john haque
Add a test file, cleanup code and update doc.
5779
			yylval->lextok = estrdup(tokstart, tok - tokstart);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5780
			return lasttok = FILENAME;
5781
		}
5782
		
5783
		yylval->opcode = Op_push_i;
281.1.2 by john haque
Add a test file, cleanup code and update doc.
5784
		yylval->memory = make_str_node(tokstart,
5785
					tok - tokstart, esc_seen ? SCAN : 0);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5786
		if (intlstr) {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5787
			yylval->memory->flags |= INTLSTR;
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5788
			intlstr = false;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5789
			if (do_intl)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5790
				dumpintlstr(yylval->memory->stptr, yylval->memory->stlen);
5791
		}
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5792
		return lasttok = YSTRING;
5793
5794
	case '-':
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5795
		if ((c = nextc(true)) == '=') {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5796
			yylval = GET_INSTRUCTION(Op_assign_minus);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5797
			return lasttok = ASSIGNOP;
5798
		}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5799
		if (c == '-') {
5800
			yylval = GET_INSTRUCTION(Op_symbol);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5801
			return lasttok = DECREMENT;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5802
		}
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5803
		pushback();
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5804
		yylval = GET_INSTRUCTION(Op_minus);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5805
		return lasttok = '-';
5806
5807
	case '.':
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5808
		c = nextc(true);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5809
		pushback();
36 by Arnold D. Robbins
Move to 3.1.8.
5810
		if (! isdigit(c))
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5811
			return lasttok = '.';
5812
		else
5813
			c = '.';
5814
		/* FALL THROUGH */
5815
	case '0':
5816
	case '1':
5817
	case '2':
5818
	case '3':
5819
	case '4':
5820
	case '5':
5821
	case '6':
5822
	case '7':
5823
	case '8':
5824
	case '9':
5825
		/* It's a number */
5826
		for (;;) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5827
			bool gotnumber = false;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5828
5829
			tokadd(c);
5830
			switch (c) {
5831
			case 'x':
5832
			case 'X':
5833
				if (do_traditional)
5834
					goto done;
33 by Arnold D. Robbins
Move to gawk 3.1.5.
5835
				if (tok == tokstart + 2) {
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5836
					int peek = nextc(true);
33 by Arnold D. Robbins
Move to gawk 3.1.5.
5837
36 by Arnold D. Robbins
Move to 3.1.8.
5838
					if (isxdigit(peek)) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5839
						inhex = true;
33 by Arnold D. Robbins
Move to gawk 3.1.5.
5840
						pushback();	/* following digit */
5841
					} else {
5842
						pushback();	/* x or X */
5843
						goto done;
5844
					}
5845
				}
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5846
				break;
5847
			case '.':
33 by Arnold D. Robbins
Move to gawk 3.1.5.
5848
				/* period ends exponent part of floating point number */
5849
				if (seen_point || seen_e) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5850
					gotnumber = true;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5851
					break;
5852
				}
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5853
				seen_point = true;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5854
				break;
5855
			case 'e':
5856
			case 'E':
5857
				if (inhex)
5858
					break;
5859
				if (seen_e) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5860
					gotnumber = true;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5861
					break;
5862
				}
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5863
				seen_e = true;
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5864
				if ((c = nextc(true)) == '-' || c == '+') {
5865
					int c2 = nextc(true);
33 by Arnold D. Robbins
Move to gawk 3.1.5.
5866
36 by Arnold D. Robbins
Move to 3.1.8.
5867
					if (isdigit(c2)) {
33 by Arnold D. Robbins
Move to gawk 3.1.5.
5868
						tokadd(c);
5869
						tokadd(c2);
5870
					} else {
5871
						pushback();	/* non-digit after + or - */
5872
						pushback();	/* + or - */
5873
						pushback();	/* e or E */
5874
					}
36 by Arnold D. Robbins
Move to 3.1.8.
5875
				} else if (! isdigit(c)) {
33 by Arnold D. Robbins
Move to gawk 3.1.5.
5876
					pushback();	/* character after e or E */
5877
					pushback();	/* e or E */
5878
				} else {
5879
					pushback();	/* digit */
5880
				}
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5881
				break;
5882
			case 'a':
5883
			case 'A':
5884
			case 'b':
5885
			case 'B':
5886
			case 'c':
5887
			case 'C':
5888
			case 'D':
5889
			case 'd':
5890
			case 'f':
5891
			case 'F':
5892
				if (do_traditional || ! inhex)
5893
					goto done;
5894
				/* fall through */
5895
			case '0':
5896
			case '1':
5897
			case '2':
5898
			case '3':
5899
			case '4':
5900
			case '5':
5901
			case '6':
5902
			case '7':
5903
			case '8':
5904
			case '9':
5905
				break;
5906
			default:
5907
			done:
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5908
				gotnumber = true;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5909
			}
5910
			if (gotnumber)
5911
				break;
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5912
			c = nextc(true);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5913
		}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5914
		pushback();
5915
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5916
		tokadd('\0');
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5917
		yylval = GET_INSTRUCTION(Op_push_i);
300 by john haque
Add infrastructure for MPFR/GMP support.
5918
5919
		base = 10;
5920
		if (! do_traditional) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
5921
			base = get_numbase(tokstart, false);
33 by Arnold D. Robbins
Move to gawk 3.1.5.
5922
			if (do_lint) {
300 by john haque
Add infrastructure for MPFR/GMP support.
5923
				if (base == 8)
33 by Arnold D. Robbins
Move to gawk 3.1.5.
5924
					lintwarn("numeric constant `%.*s' treated as octal",
5925
						(int) strlen(tokstart)-1, tokstart);
300 by john haque
Add infrastructure for MPFR/GMP support.
5926
				else if (base == 16)
33 by Arnold D. Robbins
Move to gawk 3.1.5.
5927
					lintwarn("numeric constant `%.*s' treated as hexadecimal",
5928
						(int) strlen(tokstart)-1, tokstart);
29 by Arnold D. Robbins
Move to gawk-3.1.1.
5929
			}
300 by john haque
Add infrastructure for MPFR/GMP support.
5930
		}
5931
5932
#ifdef HAVE_MPFR
5933
		if (do_mpfr) {
5934
			NODE *r;
302.1.1 by john haque
Finish MPFR changes and clean up code.
5935
306 by john haque
Add arbitrary-precision arithmetic on integers.
5936
			if (! seen_point && ! seen_e) {
5937
				r = mpg_integer();
5938
				mpg_strtoui(r->mpg_i, tokstart, strlen(tokstart), NULL, base);
5939
				errno = 0;
5940
			} else {
5941
				int tval;
5942
				r = mpg_float();
316 by john haque
Change MPFR variable RND_MODE to ROUND_MODE.
5943
				tval = mpfr_strtofr(r->mpg_numbr, tokstart, NULL, base, ROUND_MODE);
306 by john haque
Add arbitrary-precision arithmetic on integers.
5944
				errno = 0;
5945
				IEEE_FMT(r->mpg_numbr, tval);
5946
			}
300 by john haque
Add infrastructure for MPFR/GMP support.
5947
			yylval->memory = r;
5948
			return lasttok = YNUMBER;
5949
		}
5950
#endif
5951
		if (base != 10)
281.1.1 by john haque
Speed/memory performance improvements.
5952
			d = nondec2awknum(tokstart, strlen(tokstart));
300 by john haque
Add infrastructure for MPFR/GMP support.
5953
		else
281.1.1 by john haque
Speed/memory performance improvements.
5954
			d = atof(tokstart);
5955
		yylval->memory = make_number(d);
5956
		if (d <= INT32_MAX && d >= INT32_MIN && d == (int32_t) d)
5957
			yylval->memory->flags |= NUMINT;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5958
		return lasttok = YNUMBER;
5959
5960
	case '&':
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5961
		if ((c = nextc(true)) == '&') {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5962
			yylval = GET_INSTRUCTION(Op_and);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5963
			allow_newline();
5964
			return lasttok = LEX_AND;
5965
		}
5966
		pushback();
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5967
		yylval = GET_INSTRUCTION(Op_symbol);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5968
		return lasttok = '&';
5969
5970
	case '|':
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
5971
		if ((c = nextc(true)) == '|') {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5972
			yylval = GET_INSTRUCTION(Op_or);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5973
			allow_newline();
5974
			return lasttok = LEX_OR;
5975
		} else if (! do_traditional && c == '&') {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5976
			yylval = GET_INSTRUCTION(Op_symbol);
5977
			yylval->redir_type = redirect_twoway;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
5978
			return lasttok = (in_print && in_parens == 0 ? IO_OUT : IO_IN);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5979
		}
5980
		pushback();
30 by Arnold D. Robbins
Move to gawk-3.1.2.
5981
		if (in_print && in_parens == 0) {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5982
			yylval = GET_INSTRUCTION(Op_symbol);
5983
			yylval->redir_type = redirect_pipe;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
5984
			return lasttok = IO_OUT;
5985
		} else {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5986
			yylval = GET_INSTRUCTION(Op_symbol);
5987
			yylval->redir_type = redirect_pipein;
30 by Arnold D. Robbins
Move to gawk-3.1.2.
5988
			return lasttok = IO_IN;
5989
		}
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5990
	}
5991
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
5992
	if (c != '_' && ! is_alpha(c)) {
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5993
		yyerror(_("invalid char '%c' in expression"), c);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
5994
		return lasttok = LEX_EOF;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
5995
	}
5996
29 by Arnold D. Robbins
Move to gawk-3.1.1.
5997
	/*
5998
	 * Lots of fog here.  Consider:
5999
	 *
6000
	 * print "xyzzy"$_"foo"
6001
	 *
33 by Arnold D. Robbins
Move to gawk 3.1.5.
6002
	 * Without the check for ` lasttok != '$' ', this is parsed as
29 by Arnold D. Robbins
Move to gawk-3.1.1.
6003
	 *
6004
	 * print "xxyzz" $(_"foo")
6005
	 *
6006
	 * With the check, it is "correctly" parsed as three
6007
	 * string concatenations.  Sigh.  This seems to be
6008
	 * "more correct", but this is definitely one of those
6009
	 * occasions where the interactions are funny.
6010
	 */
6011
	if (! do_traditional && c == '_' && lasttok != '$') {
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
6012
		if ((c = nextc(true)) == '"') {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
6013
			intlstr = true;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6014
			goto string;
6015
		}
6016
		pushback();
6017
		c = '_';
6018
	}
6019
6020
	/* it's some type of name-type-thing.  Find its length. */
6021
	tok = tokstart;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6022
	while (c != END_FILE && is_identchar(c)) {
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6023
		tokadd(c);
408.5.215 by Arnold D. Robbins
Disallow bad characters in source files.
6024
		c = nextc(true);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6025
	}
6026
	tokadd('\0');
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6027
	pushback();
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6028
6029
	/* See if it is a special token. */
32 by Arnold D. Robbins
Move to gawk-3.1.4.
6030
	if ((mid = check_special(tokstart)) >= 0) {
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
6031
		static int warntab[sizeof(tokentab) / sizeof(tokentab[0])];
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6032
		int class = tokentab[mid].class;
6033
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
6034
		if ((class == LEX_INCLUDE || class == LEX_LOAD || class == LEX_EVAL)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6035
				&& lasttok != '@')
6036
			goto out;
6037
32 by Arnold D. Robbins
Move to gawk-3.1.4.
6038
		if (do_lint) {
319.1.140 by Arnold D. Robbins
Make bitflag checking consistent everywhere.
6039
			if ((tokentab[mid].flags & GAWKX) != 0 && (warntab[mid] & GAWKX) == 0) {
32 by Arnold D. Robbins
Move to gawk-3.1.4.
6040
				lintwarn(_("`%s' is a gawk extension"),
6041
					tokentab[mid].operator);
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
6042
				warntab[mid] |= GAWKX;
6043
			}
319.1.140 by Arnold D. Robbins
Make bitflag checking consistent everywhere.
6044
			if ((tokentab[mid].flags & NOT_POSIX) != 0 && (warntab[mid] & NOT_POSIX) == 0) {
32 by Arnold D. Robbins
Move to gawk-3.1.4.
6045
				lintwarn(_("POSIX does not allow `%s'"),
6046
					tokentab[mid].operator);
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
6047
				warntab[mid] |= NOT_POSIX;
6048
			}
32 by Arnold D. Robbins
Move to gawk-3.1.4.
6049
		}
319.1.140 by Arnold D. Robbins
Make bitflag checking consistent everywhere.
6050
		if (do_lint_old && (tokentab[mid].flags & NOT_OLD) != 0
6051
				 && (warntab[mid] & NOT_OLD) == 0
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
6052
		) {
32 by Arnold D. Robbins
Move to gawk-3.1.4.
6053
			warning(_("`%s' is not supported in old awk"),
6054
					tokentab[mid].operator);
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
6055
			warntab[mid] |= NOT_OLD;
6056
		}
6057
319.1.140 by Arnold D. Robbins
Make bitflag checking consistent everywhere.
6058
		if ((tokentab[mid].flags & BREAK) != 0)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6059
			break_allowed++;
319.1.140 by Arnold D. Robbins
Make bitflag checking consistent everywhere.
6060
		if ((tokentab[mid].flags & CONTINUE) != 0)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6061
			continue_allowed++;
6062
6063
		switch (class) {
6064
		case LEX_INCLUDE:
299.3.1 by Andrew J. Schorr
xgawk + derived files needed to build
6065
		case LEX_LOAD:
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
6066
			want_source = true;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6067
			break;
6068
		case LEX_EVAL:
49 by Arnold D. Robbins
Fix memory leaks - patch from John.
6069
			if (in_main_context())
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6070
				goto out;
6071
			emalloc(tokkey, char *, tok - tokstart + 1, "yylex");
6072
			tokkey[0] = '@';
6073
			memcpy(tokkey + 1, tokstart, tok - tokstart);
6074
			yylval = GET_INSTRUCTION(Op_token);
6075
			yylval->lextok = tokkey;
6076
			break;
6077
6078
		case LEX_FUNCTION:
6079
		case LEX_BEGIN:
6080
		case LEX_END:
6081
		case LEX_BEGINFILE:
6082
		case LEX_ENDFILE:		
6083
			yylval = bcalloc(tokentab[mid].value, 3, sourceline);
6084
			break;
6085
116 by Arnold D. Robbins
Fix switch debugging.
6086
		case LEX_FOR:
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6087
		case LEX_WHILE:
6088
		case LEX_DO:
6089
		case LEX_SWITCH:
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
6090
			if (! do_pretty_print)
116 by Arnold D. Robbins
Fix switch debugging.
6091
				return lasttok = class;
6092
			/* fall through */
6093
		case LEX_CASE:
6094
			yylval = bcalloc(tokentab[mid].value, 2, sourceline);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6095
			break;
6096
319.1.61 by Arnold D. Robbins
SYMTAB enhancements, bug fix. Doc additions.
6097
		/*
6098
		 * These must be checked here, due to the LALR nature of the parser,
6099
		 * the rules for continue and break may not be reduced until after
6100
		 * a token that increments the xxx_allowed varibles is seen. Bleah.
6101
		 */
6102
		case LEX_CONTINUE:
6103
			if (! continue_allowed) {
6104
				error_ln(sourceline,
6105
					_("`continue' is not allowed outside a loop"));
6106
				errcount++;
6107
			}
6108
			goto make_instruction;
6109
6110
		case LEX_BREAK:
6111
			if (! break_allowed) {
6112
				error_ln(sourceline,
6113
					_("`break' is not allowed outside a loop or switch"));
6114
				errcount++;
6115
			}
6116
			goto make_instruction;
6117
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6118
		default:
319.1.61 by Arnold D. Robbins
SYMTAB enhancements, bug fix. Doc additions.
6119
make_instruction:
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6120
			yylval = GET_INSTRUCTION(tokentab[mid].value);
6121
			if (class == LEX_BUILTIN || class == LEX_LENGTH)
6122
				yylval->builtin_idx = mid;
6123
			break;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6124
		}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6125
		return lasttok = class;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6126
	}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6127
out:
6128
	tokkey = estrdup(tokstart, tok - tokstart);
6129
	if (*lexptr == '(') {
6130
		yylval = bcalloc(Op_token, 2, sourceline);
6131
		yylval->lextok = tokkey;	
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6132
		return lasttok = FUNC_CALL;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6133
	} else {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
6134
		static bool goto_warned = false;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6135
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6136
		yylval = GET_INSTRUCTION(Op_token);
6137
		yylval->lextok = tokkey;
6138
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6139
#define SMART_ALECK	1
6140
		if (SMART_ALECK && do_lint
6141
		    && ! goto_warned && strcasecmp(tokkey, "goto") == 0) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
6142
			goto_warned = true;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6143
			lintwarn(_("`goto' considered harmful!\n"));
6144
		}
6145
		return lasttok = NAME;
6146
	}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6147
6148
#undef GET_INSTRUCTION
6149
#undef NEWLINE_EOF
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6150
}
6151
408.21.1 by Arnold D. Robbins
Rework zOS patches; keep separate from autotools.
6152
/* It's EBCDIC in a Bison grammar, run for the hills!
6153
6154
   Or, convert single-character tokens coming out of yylex() from EBCDIC to
6155
   ASCII values on-the-fly so that the parse tables need not be regenerated
6156
   for EBCDIC systems.  */
6157
#ifdef USE_EBCDIC
6158
static int
6159
yylex(void)
6160
{
6161
	static char etoa_xlate[256];
6162
	static int do_etoa_init = 1;
6163
	int tok;
6164
6165
	if (do_etoa_init)
6166
	{
6167
		for (tok = 0; tok < 256; tok++)
6168
			etoa_xlate[tok] = (char) tok;
6169
#ifdef HAVE___ETOA_L
6170
		/* IBM helpfully provides this function.  */
6171
		__etoa_l(etoa_xlate, sizeof(etoa_xlate));
6172
#else
6173
# error "An EBCDIC-to-ASCII translation function is needed for this system"
6174
#endif
6175
		do_etoa_init = 0;
6176
	}
6177
6178
	tok = yylex_ebcdic();
6179
6180
	if (tok >= 0 && tok <= 0xFF)
6181
		tok = etoa_xlate[tok];
6182
6183
	return tok;
6184
}
6185
#endif /* USE_EBCDIC */
6186
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6187
/* snode --- instructions for builtin functions. Checks for arg. count
6188
             and supplies defaults where possible. */
6189
6190
static INSTRUCTION *
6191
snode(INSTRUCTION *subn, INSTRUCTION *r)
6192
{
6193
	INSTRUCTION *arg;
6194
	INSTRUCTION *ip;
6195
	NODE *n;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6196
	int nexp = 0;
6197
	int args_allowed;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6198
	int idx = r->builtin_idx;
6199
6200
	if (subn != NULL) {
6201
		INSTRUCTION *tp;
6202
		for (tp = subn->nexti; tp; tp = tp->nexti) {
6203
			tp = tp->lasti;
6204
			nexp++;
6205
		}
6206
		assert(nexp > 0);
6207
	}		
6208
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6209
	/* check against how many args. are allowed for this builtin */
6210
	args_allowed = tokentab[idx].flags & ARGS;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6211
	if (args_allowed && (args_allowed & A(nexp)) == 0) {
6212
		yyerror(_("%d is invalid as number of arguments for %s"),
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6213
				nexp, tokentab[idx].operator);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6214
		return NULL;
6215
	}
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6216
277.1.2 by Arnold D. Robbins
Fix gsub losing white space when working on fields.
6217
	/* special processing for sub, gsub and gensub */
6218
6219
	if (tokentab[idx].value == Op_sub_builtin) {
6220
		const char *operator = tokentab[idx].operator;
6221
6222
		r->sub_flags = 0;
6223
6224
		arg = subn->nexti;		/* first arg list */
6225
		(void) mk_rexp(arg);
6226
6227
		if (strcmp(operator, "gensub") != 0) {
6228
			/* sub and gsub */
6229
6230
			if (strcmp(operator, "gsub") == 0)
6231
				r->sub_flags |= GSUB;
6232
6233
			arg = arg->lasti->nexti;	/* 2nd arg list */
6234
			if (nexp == 2) {
6235
				INSTRUCTION *expr;
6236
6237
				expr = list_create(instruction(Op_push_i));
281.1.1 by john haque
Speed/memory performance improvements.
6238
				expr->nexti->memory = make_number(0.0);
277.1.2 by Arnold D. Robbins
Fix gsub losing white space when working on fields.
6239
				(void) mk_expression_list(subn,
6240
						list_append(expr, instruction(Op_field_spec)));
6241
			}
6242
6243
			arg = arg->lasti->nexti; 	/* third arg list */
6244
			ip = arg->lasti;
6245
			if (ip->opcode == Op_push_i) {
6246
				if (do_lint)
6247
					lintwarn(_("%s: string literal as last arg of substitute has no effect"),
6248
						operator);
6249
				r->sub_flags |=	LITERAL;
6250
			} else {
6251
				if (make_assignable(ip) == NULL)
6252
					yyerror(_("%s third parameter is not a changeable object"),
6253
						operator);
6254
				else
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
6255
					ip->do_reference = true;
277.1.2 by Arnold D. Robbins
Fix gsub losing white space when working on fields.
6256
			}
6257
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
6258
			r->expr_count = count_expressions(&subn, false);
277.1.2 by Arnold D. Robbins
Fix gsub losing white space when working on fields.
6259
			ip = subn->lasti;
6260
6261
			(void) list_append(subn, r);
6262
6263
			/* add after_assign code */
6264
			if (ip->opcode == Op_push_lhs && ip->memory->type == Node_var && ip->memory->var_assign) {
6265
				(void) list_append(subn, instruction(Op_var_assign));
277.1.11 by Arnold D. Robbins
Fix gsub and getline pass by reference. Add tests.
6266
				subn->lasti->assign_ctxt = Op_sub_builtin;
277.1.2 by Arnold D. Robbins
Fix gsub losing white space when working on fields.
6267
				subn->lasti->assign_var = ip->memory->var_assign;
6268
			} else if (ip->opcode == Op_field_spec_lhs) {
6269
				(void) list_append(subn, instruction(Op_field_assign));
277.1.11 by Arnold D. Robbins
Fix gsub and getline pass by reference. Add tests.
6270
				subn->lasti->assign_ctxt = Op_sub_builtin;
277.1.2 by Arnold D. Robbins
Fix gsub losing white space when working on fields.
6271
				subn->lasti->field_assign = (Func_ptr) 0;
6272
				ip->target_assign = subn->lasti;
322 by john haque
Improve array interface.
6273
			} else if (ip->opcode == Op_subscript_lhs) {
6274
				(void) list_append(subn, instruction(Op_subscript_assign));
6275
				subn->lasti->assign_ctxt = Op_sub_builtin;
277.1.2 by Arnold D. Robbins
Fix gsub losing white space when working on fields.
6276
			}
322 by john haque
Improve array interface.
6277
277.1.2 by Arnold D. Robbins
Fix gsub losing white space when working on fields.
6278
			return subn;	
6279
6280
		} else {
6281
			/* gensub */
6282
6283
			r->sub_flags |= GENSUB;
6284
			if (nexp == 3) {
6285
				ip = instruction(Op_push_i);
281.1.1 by john haque
Speed/memory performance improvements.
6286
				ip->memory = make_number(0.0);
277.1.2 by Arnold D. Robbins
Fix gsub losing white space when working on fields.
6287
				(void) mk_expression_list(subn,
6288
						list_append(list_create(ip), instruction(Op_field_spec)));
6289
			}
6290
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
6291
			r->expr_count = count_expressions(&subn, false);
277.1.2 by Arnold D. Robbins
Fix gsub losing white space when working on fields.
6292
			return list_append(subn, r);
6293
		}
6294
	}
6295
300 by john haque
Add infrastructure for MPFR/GMP support.
6296
#ifdef HAVE_MPFR
6297
	/* N.B.: There isn't any special processing for an alternate function below */
6298
	if (do_mpfr && tokentab[idx].ptr2)
6299
		r->builtin =  tokentab[idx].ptr2;
6300
	else
6301
#endif
6302
		r->builtin = tokentab[idx].ptr;
277.1.2 by Arnold D. Robbins
Fix gsub losing white space when working on fields.
6303
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6304
	/* special case processing for a few builtins */
277.1.2 by Arnold D. Robbins
Fix gsub losing white space when working on fields.
6305
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6306
	if (r->builtin == do_length) {
6307
		if (nexp == 0) {		
114 by Arnold D. Robbins
Add isarray built-in function.
6308
		    /* no args. Use $0 */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6309
114 by Arnold D. Robbins
Add isarray built-in function.
6310
			INSTRUCTION *list;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6311
			r->expr_count = 1;			
6312
			list = list_create(r);
6313
			(void) list_prepend(list, instruction(Op_field_spec));
6314
			(void) list_prepend(list, instruction(Op_push_i));
281.1.1 by john haque
Speed/memory performance improvements.
6315
			list->nexti->memory = make_number(0.0);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6316
			return list; 
114 by Arnold D. Robbins
Add isarray built-in function.
6317
		} else {
6318
			arg = subn->nexti;
6319
			if (arg->nexti == arg->lasti && arg->nexti->opcode == Op_push)
6320
				arg->nexti->opcode = Op_push_arg;	/* argument may be array */
6321
 		}
6322
	} else if (r->builtin == do_isarray) {
6323
		arg = subn->nexti;
6324
		if (arg->nexti == arg->lasti && arg->nexti->opcode == Op_push)
6325
			arg->nexti->opcode = Op_push_arg;	/* argument may be array */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
6326
	} else if (r->builtin == do_match) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
6327
		static bool warned = false;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6328
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6329
		arg = subn->nexti->lasti->nexti;	/* 2nd arg list */
6330
		(void) mk_rexp(arg);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6331
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6332
		if (nexp == 3) {	/* 3rd argument there */
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6333
			if (do_lint && ! warned) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
6334
				warned = true;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6335
				lintwarn(_("match: third argument is a gawk extension"));
6336
			}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6337
			if (do_traditional) {
6338
				yyerror(_("match: third argument is a gawk extension"));
6339
				return NULL;
6340
			}
6341
6342
			arg = arg->lasti->nexti; 	/* third arg list */
6343
			ip = arg->lasti;
6344
			if (/*ip == arg->nexti  && */ ip->opcode == Op_push)
6345
				ip->opcode = Op_push_array;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6346
		}
30 by Arnold D. Robbins
Move to gawk-3.1.2.
6347
	} else if (r->builtin == do_split) {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6348
		arg = subn->nexti->lasti->nexti;	/* 2nd arg list */
6349
		ip = arg->lasti;
6350
		if (ip->opcode == Op_push)
6351
			ip->opcode = Op_push_array;
6352
		if (nexp == 2) {
6353
			INSTRUCTION *expr;
6354
			expr = list_create(instruction(Op_push));
6355
			expr->nexti->memory = FS_node;
6356
			(void) mk_expression_list(subn, expr);
6357
		}
6358
		arg = arg->lasti->nexti;
6359
		n = mk_rexp(arg);
6360
		if (nexp == 2)
6361
			n->re_flags |= FS_DFLT;
6362
		if (nexp == 4) {
6363
			arg = arg->lasti->nexti;
6364
			ip = arg->lasti;
6365
			if (ip->opcode == Op_push)
6366
				ip->opcode = Op_push_array;
6367
		}
37 by Arnold D. Robbins
Bring in development gawk changes.
6368
	} else if (r->builtin == do_patsplit) {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6369
		arg = subn->nexti->lasti->nexti;	/* 2nd arg list */
6370
		ip = arg->lasti;
6371
		if (ip->opcode == Op_push)
6372
			ip->opcode = Op_push_array;
6373
		if (nexp == 2) {
6374
			INSTRUCTION *expr;
6375
			expr = list_create(instruction(Op_push));
6376
			expr->nexti->memory = FPAT_node;
6377
			(void) mk_expression_list(subn, expr);
6378
		}
6379
		arg = arg->lasti->nexti;
6380
		n = mk_rexp(arg);
6381
		if (nexp == 4) {
6382
			arg = arg->lasti->nexti;
6383
			ip = arg->lasti;
6384
			if (ip->opcode == Op_push)
6385
				ip->opcode = Op_push_array;
6386
		}
30 by Arnold D. Robbins
Move to gawk-3.1.2.
6387
	} else if (r->builtin == do_close) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
6388
		static bool warned = false;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6389
		if (nexp == 2) {
6390
			if (do_lint && ! warned) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
6391
				warned = true;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6392
				lintwarn(_("close: second argument is a gawk extension"));
6393
			}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6394
			if (do_traditional) {
6395
				yyerror(_("close: second argument is a gawk extension"));
6396
				return NULL;
6397
			}
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6398
		}
6399
	} else if (do_intl					/* --gen-po */
30 by Arnold D. Robbins
Move to gawk-3.1.2.
6400
			&& r->builtin == do_dcgettext		/* dcgettext(...) */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6401
			&& subn->nexti->lasti->opcode == Op_push_i	/* 1st arg is constant */
6402
			&& (subn->nexti->lasti->memory->flags & STRCUR) != 0) {	/* it's a string constant */
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6403
		/* ala xgettext, dcgettext("some string" ...) dumps the string */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6404
		NODE *str = subn->nexti->lasti->memory;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6405
6406
		if ((str->flags & INTLSTR) != 0)
6407
			warning(_("use of dcgettext(_\"...\") is incorrect: remove leading underscore"));
6408
			/* don't dump it, the lexer already did */
6409
		else
6410
			dumpintlstr(str->stptr, str->stlen);
29 by Arnold D. Robbins
Move to gawk-3.1.1.
6411
	} else if (do_intl					/* --gen-po */
31 by Arnold D. Robbins
Move to gawk-3.1.3.
6412
			&& r->builtin == do_dcngettext		/* dcngettext(...) */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6413
			&& subn->nexti->lasti->opcode == Op_push_i	/* 1st arg is constant */
6414
			&& (subn->nexti->lasti->memory->flags & STRCUR) != 0	/* it's a string constant */
6415
			&& subn->nexti->lasti->nexti->lasti->opcode == Op_push_i	/* 2nd arg is constant too */
6416
			&& (subn->nexti->lasti->nexti->lasti->memory->flags & STRCUR) != 0) {	/* it's a string constant */
29 by Arnold D. Robbins
Move to gawk-3.1.1.
6417
		/* ala xgettext, dcngettext("some string", "some plural" ...) dumps the string */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6418
		NODE *str1 = subn->nexti->lasti->memory;
6419
		NODE *str2 = subn->nexti->lasti->nexti->lasti->memory;
29 by Arnold D. Robbins
Move to gawk-3.1.1.
6420
6421
		if (((str1->flags | str2->flags) & INTLSTR) != 0)
6422
			warning(_("use of dcngettext(_\"...\") is incorrect: remove leading underscore"));
6423
		else
6424
			dumpintlstr2(str1->stptr, str1->stlen, str2->stptr, str2->stlen);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6425
	} else if (r->builtin == do_asort || r->builtin == do_asorti) {
6426
		arg = subn->nexti;	/* 1st arg list */
6427
		ip = arg->lasti;
181 by Arnold D. Robbins
More array sorting changes from John.
6428
		if (ip->opcode == Op_push)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6429
			ip->opcode = Op_push_array;
181 by Arnold D. Robbins
More array sorting changes from John.
6430
		if (nexp >= 2) {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6431
			arg = ip->nexti;
6432
			ip = arg->lasti;
181 by Arnold D. Robbins
More array sorting changes from John.
6433
			if (ip->opcode == Op_push)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6434
				ip->opcode = Op_push_array;
6435
		}
6436
	}
408.2.93 by Arnold D. Robbins
Make /regex/ a 2nd arg to index() a fatal error.
6437
	else if (r->builtin == do_index) {
6438
		arg = subn->nexti->lasti->nexti;	/* 2nd arg list */
6439
		ip = arg->lasti;
6440
		if (ip->opcode == Op_match_rec)
6441
			fatal(_("index: regexp constant as second argument is not allowed"));
6442
	}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6443
#ifdef ARRAYDEBUG
6444
	else if (r->builtin == do_adump) {
6445
		ip = subn->nexti->lasti;
6446
		if (ip->opcode == Op_push)
6447
			ip->opcode = Op_push_array;
6448
	}
281.1.1 by john haque
Speed/memory performance improvements.
6449
#endif
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6450
6451
	if (subn != NULL) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
6452
		r->expr_count = count_expressions(&subn, false);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6453
		return list_append(subn, r);
6454
	}
6455
6456
	r->expr_count = 0;
6457
	return list_create(r);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6458
}
6459
6460
6461
/* parms_shadow --- check if parameters shadow globals */
6462
30 by Arnold D. Robbins
Move to gawk-3.1.2.
6463
static int
387 by Arnold D. Robbins
Considerable additional portability fixes.
6464
parms_shadow(INSTRUCTION *pc, bool *shadow)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6465
{
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6466
	int pcount, i;
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
6467
	bool ret = false;
281.1.1 by john haque
Speed/memory performance improvements.
6468
	NODE *func, *fp;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6469
	char *fname;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6470
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6471
	func = pc->func_body;
281.1.1 by john haque
Speed/memory performance improvements.
6472
	fname = func->vname;
6473
	fp = func->fparms;
6474
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6475
#if 0	/* can't happen, already exited if error ? */
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6476
	if (fname == NULL || func == NULL)	/* error earlier */
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
6477
		return false;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6478
#endif
6479
281.1.1 by john haque
Speed/memory performance improvements.
6480
	pcount = func->param_cnt;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6481
6482
	if (pcount == 0)		/* no args, no problem */
6483
		return 0;
6484
6485
	source = pc->source_file;
6486
	sourceline = pc->source_line;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6487
	/*
6488
	 * Use warning() and not lintwarn() so that can warn
6489
	 * about all shadowed parameters.
6490
	 */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6491
	for (i = 0; i < pcount; i++) {
281.1.1 by john haque
Speed/memory performance improvements.
6492
		if (lookup(fp[i].param) != NULL) {
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6493
			warning(
6494
	_("function `%s': parameter `%s' shadows global variable"),
281.1.1 by john haque
Speed/memory performance improvements.
6495
					fname, fp[i].param);
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
6496
			ret = true;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6497
		}
6498
	}
30 by Arnold D. Robbins
Move to gawk-3.1.2.
6499
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6500
	*shadow |= ret;
6501
	return 0;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6502
}
6503
6504
/* valinfo --- dump var info */
6505
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6506
void
281.1.1 by john haque
Speed/memory performance improvements.
6507
valinfo(NODE *n, Func_print print_func, FILE *fp)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6508
{
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6509
	if (n == Nnull_string)
6510
		print_func(fp, "uninitialized scalar\n");
408.13.111 by Arnold D. Robbins
Minor code cleanups.
6511
	else if ((n->flags & STRING) != 0) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
6512
		pp_string_fp(print_func, fp, n->stptr, n->stlen, '"', false);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6513
		print_func(fp, "\n");
408.13.111 by Arnold D. Robbins
Minor code cleanups.
6514
	} else if ((n->flags & NUMBER) != 0) {
302 by john haque
Finish builtins for MPFR.
6515
#ifdef HAVE_MPFR
306 by john haque
Add arbitrary-precision arithmetic on integers.
6516
		if (is_mpg_float(n))
316 by john haque
Change MPFR variable RND_MODE to ROUND_MODE.
6517
			print_func(fp, "%s\n", mpg_fmt("%.17R*g", ROUND_MODE, n->mpg_numbr));
306 by john haque
Add arbitrary-precision arithmetic on integers.
6518
		else if (is_mpg_integer(n))
6519
			print_func(fp, "%s\n", mpg_fmt("%Zd", n->mpg_i));
302 by john haque
Finish builtins for MPFR.
6520
		else
6521
#endif
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6522
		print_func(fp, "%.17g\n", n->numbr);
408.13.111 by Arnold D. Robbins
Minor code cleanups.
6523
	} else if ((n->flags & STRCUR) != 0) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
6524
		pp_string_fp(print_func, fp, n->stptr, n->stlen, '"', false);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6525
		print_func(fp, "\n");
408.13.111 by Arnold D. Robbins
Minor code cleanups.
6526
	} else if ((n->flags & NUMCUR) != 0) {
302 by john haque
Finish builtins for MPFR.
6527
#ifdef HAVE_MPFR
306 by john haque
Add arbitrary-precision arithmetic on integers.
6528
		if (is_mpg_float(n))
316 by john haque
Change MPFR variable RND_MODE to ROUND_MODE.
6529
			print_func(fp, "%s\n", mpg_fmt("%.17R*g", ROUND_MODE, n->mpg_numbr));
306 by john haque
Add arbitrary-precision arithmetic on integers.
6530
		else if (is_mpg_integer(n))
6531
			print_func(fp, "%s\n", mpg_fmt("%Zd", n->mpg_i));
302 by john haque
Finish builtins for MPFR.
6532
		else
6533
#endif
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6534
		print_func(fp, "%.17g\n", n->numbr);
302 by john haque
Finish builtins for MPFR.
6535
	} else
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6536
		print_func(fp, "?? flags %s\n", flags2str(n->flags));
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6537
}
6538
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6539
6540
/* dump_vars --- dump the symbol table */
6541
6542
void
6543
dump_vars(const char *fname)
6544
{
6545
	FILE *fp;
281.1.1 by john haque
Speed/memory performance improvements.
6546
	NODE **vars;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6547
6548
	if (fname == NULL)
6549
		fp = stderr;
6550
	else if ((fp = fopen(fname, "w")) == NULL) {
6551
		warning(_("could not open `%s' for writing (%s)"), fname, strerror(errno));
232 by Arnold D. Robbins
Documentation and compile fixes.
6552
		warning(_("sending variable list to standard error"));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6553
		fp = stderr;
6554
	}
6555
281.1.1 by john haque
Speed/memory performance improvements.
6556
	vars = variable_list();
6557
	print_vars(vars, fprintf, fp);
6558
	efree(vars);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6559
	if (fp != stderr && fclose(fp) != 0)
6560
		warning(_("%s: close failed (%s)"), fname, strerror(errno));
6561
}
6562
6563
/* dump_funcs --- print all functions */
6564
6565
void
6566
dump_funcs()
6567
{
281.1.1 by john haque
Speed/memory performance improvements.
6568
	NODE **funcs;
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
6569
	funcs = function_list(true);
281.1.1 by john haque
Speed/memory performance improvements.
6570
	(void) foreach_func(funcs, (int (*)(INSTRUCTION *, void *)) pp_func, (void *) 0);
6571
	efree(funcs);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6572
}
6573
281.1.1 by john haque
Speed/memory performance improvements.
6574
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6575
/* shadow_funcs --- check all functions for parameters that shadow globals */
6576
6577
void
6578
shadow_funcs()
6579
{
6580
	static int calls = 0;
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
6581
	bool shadow = false;
281.1.1 by john haque
Speed/memory performance improvements.
6582
	NODE **funcs;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6583
6584
	if (calls++ != 0)
6585
		fatal(_("shadow_funcs() called twice!"));
6586
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
6587
	funcs = function_list(true);
281.1.1 by john haque
Speed/memory performance improvements.
6588
	(void) foreach_func(funcs, (int (*)(INSTRUCTION *, void *)) parms_shadow, & shadow);
6589
	efree(funcs);
30 by Arnold D. Robbins
Move to gawk-3.1.2.
6590
6591
	/* End with fatal if the user requested it.  */
6592
	if (shadow && lintfunc != warning)
6593
		lintwarn(_("there were shadowed variables."));
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6594
}
6595
281.1.1 by john haque
Speed/memory performance improvements.
6596
6597
/* mk_function --- finalize function definition node; remove parameters
6598
 *	out of the symbol table.
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6599
 */
6600
281.1.1 by john haque
Speed/memory performance improvements.
6601
static INSTRUCTION *
6602
mk_function(INSTRUCTION *fi, INSTRUCTION *def)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6603
{
281.1.1 by john haque
Speed/memory performance improvements.
6604
	NODE *thisfunc;
6605
6606
	thisfunc = fi->func_body;
6607
	assert(thisfunc != NULL);
30 by Arnold D. Robbins
Move to gawk-3.1.2.
6608
408.4.50 by Arnold D. Robbins
Fix -O option.
6609
	if (do_optimize && def->lasti->opcode == Op_pop) {
281.1.4 by john haque
Optimize tail-recursive calls.
6610
		/* tail call which does not return any value. */
6611
6612
		INSTRUCTION *t;
6613
6614
		for (t = def->nexti; t->nexti != def->lasti; t = t->nexti)
6615
			;
6616
		if (t->opcode == Op_func_call
295 by Arnold D. Robbins
Merge branch 'gawk-4.0-stable', minor fixes after exe merge.
6617
		    && strcmp(t->func_name, thisfunc->vname) == 0)
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
6618
			(t + 1)->tail_call = true;
281.1.4 by john haque
Optimize tail-recursive calls.
6619
	}
6620
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6621
	/* add an implicit return at end;
6622
	 * also used by 'return' command in debugger
6623
	 */
281.1.1 by john haque
Speed/memory performance improvements.
6624
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6625
	(void) list_append(def, instruction(Op_push_i));
281.1.1 by john haque
Speed/memory performance improvements.
6626
	def->lasti->memory = dupnode(Nnull_string);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6627
	(void) list_append(def, instruction(Op_K_return));
6628
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
6629
	if (do_pretty_print)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6630
		(void) list_prepend(def, instruction(Op_exec_count));
6631
281.1.1 by john haque
Speed/memory performance improvements.
6632
	/* fi->opcode = Op_func */
6633
	(fi + 1)->firsti = def->nexti;
6634
	(fi + 1)->lasti = def->lasti;
6635
	(fi + 2)->first_line = fi->source_line;
6636
	(fi + 2)->last_line = lastline;
6637
	fi->nexti = def->nexti;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6638
	bcfree(def);
6639
281.1.1 by john haque
Speed/memory performance improvements.
6640
	(void) list_append(rule_list, fi + 1);	/* debugging */
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6641
6642
	/* update lint table info */
281.1.1 by john haque
Speed/memory performance improvements.
6643
	func_use(thisfunc->vname, FUNC_DEFINE);
6644
30 by Arnold D. Robbins
Move to gawk-3.1.2.
6645
	/* remove params from symbol table */
281.1.1 by john haque
Speed/memory performance improvements.
6646
	remove_params(thisfunc);
6647
	return fi;
6648
}
6649
6650
/* 
6651
 * install_function:
6652
 * install function name in the symbol table.
6653
 * Extra work, build up and install a list of the parameter names.
6654
 */
6655
6656
static int
6657
install_function(char *fname, INSTRUCTION *fi, INSTRUCTION *plist)
6658
{
6659
	NODE *r, *f;
6660
	int pcount = 0;
6661
6662
	r = lookup(fname);
408.13.37 by Arnold D. Robbins
Remove deferred variables.
6663
	if (r != NULL) {
281.1.1 by john haque
Speed/memory performance improvements.
6664
		error_ln(fi->source_line, _("function name `%s' previously defined"), fname);
6665
		return -1;
6666
	}
6667
6668
	if (plist != NULL)
6669
		pcount = plist->lasti->param_count + 1;
6670
	f = install_symbol(fname, Node_func);
6671
	fi->func_body = f;
6672
	f->param_cnt = pcount;
6673
	f->code_ptr = fi;
6674
	f->fparms = NULL; 
6675
	if (pcount > 0) {
6676
		char **pnames;
6677
		pnames = check_params(fname, pcount, plist);	/* frees plist */
6678
		f->fparms = make_params(pnames, pcount);
6679
		efree(pnames);
6680
		install_params(f);
6681
	}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6682
	return 0;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6683
}
6684
281.1.1 by john haque
Speed/memory performance improvements.
6685
6686
/* check_params --- build a list of function parameter names after
6687
 *	making sure that the names are valid and there are no duplicates.
6688
 */
6689
6690
static char **
6691
check_params(char *fname, int pcount, INSTRUCTION *list)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6692
{
281.1.1 by john haque
Speed/memory performance improvements.
6693
	INSTRUCTION *p, *np;
6694
	int i, j;
6695
	char *name;
6696
	char **pnames;
6697
6698
	assert(pcount > 0);
6699
6700
	emalloc(pnames, char **, pcount * sizeof(char *), "check_params");
6701
6702
	for (i = 0, p = list->nexti; p != NULL; i++, p = np) {
6703
		np = p->nexti;
6704
		name = p->lextok;
6705
		p->lextok = NULL;
6706
6707
		if (strcmp(name, fname) == 0) {
6708
			/* check for function foo(foo) { ... }.  bleah. */
6709
			error_ln(p->source_line,
6710
				_("function `%s': can't use function name as parameter name"), fname);
6711
		} else if (is_std_var(name)) {
6712
			error_ln(p->source_line,
6713
				_("function `%s': can't use special variable `%s' as a function parameter"),
6714
					fname, name);
6715
		}
6716
6717
		/* check for duplicate parameters */
6718
		for (j = 0; j < i; j++) {
6719
			if (strcmp(name, pnames[j]) == 0) {
6720
				error_ln(p->source_line,
6721
					_("function `%s': parameter #%d, `%s', duplicates parameter #%d"),
6722
					fname, i + 1, name, j + 1);
6723
			}
6724
		}
6725
6726
		pnames[i] = name;
6727
		bcfree(p);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6728
	}
281.1.1 by john haque
Speed/memory performance improvements.
6729
	bcfree(list);
6730
6731
	return pnames; 
6732
}
6733
6734
6735
#ifdef HASHSIZE
6736
undef HASHSIZE
6737
#endif
6738
#define HASHSIZE 1021
6739
 
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6740
static struct fdesc {
6741
	char *name;
6742
	short used;
6743
	short defined;
319.2.43 by Arnold D. Robbins
Fix lint checking for extension functions.
6744
	short extension;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6745
	struct fdesc *next;
6746
} *ftable[HASHSIZE];
6747
6748
/* func_use --- track uses and definitions of functions */
6749
6750
static void
30 by Arnold D. Robbins
Move to gawk-3.1.2.
6751
func_use(const char *name, enum defref how)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6752
{
6753
	struct fdesc *fp;
6754
	int len;
6755
	int ind;
6756
6757
	len = strlen(name);
34 by Arnold D. Robbins
Move to gawk-3.1.6.
6758
	ind = hash(name, len, HASHSIZE, NULL);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6759
408.5.26 by Arnold D. Robbins
Minor improvements in a few files.
6760
	for (fp = ftable[ind]; fp != NULL; fp = fp->next)
6761
		if (strcmp(fp->name, name) == 0)
6762
			goto update_value;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6763
6764
	/* not in the table, fall through to allocate a new one */
6765
6766
	emalloc(fp, struct fdesc *, sizeof(struct fdesc), "func_use");
6767
	memset(fp, '\0', sizeof(struct fdesc));
6768
	emalloc(fp->name, char *, len + 1, "func_use");
6769
	strcpy(fp->name, name);
408.5.26 by Arnold D. Robbins
Minor improvements in a few files.
6770
	fp->next = ftable[ind];
6771
	ftable[ind] = fp;
6772
6773
update_value:
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6774
	if (how == FUNC_DEFINE)
6775
		fp->defined++;
319.2.43 by Arnold D. Robbins
Fix lint checking for extension functions.
6776
	else if (how == FUNC_EXT) {
6777
		fp->defined++;
6778
		fp->extension++;
6779
	} else
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6780
		fp->used++;
6781
}
6782
319.2.43 by Arnold D. Robbins
Fix lint checking for extension functions.
6783
/* track_ext_func --- add an extension function to the table */
6784
6785
void
6786
track_ext_func(const char *name)
6787
{
6788
	func_use(name, FUNC_EXT);
6789
}
6790
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6791
/* check_funcs --- verify functions that are called but not defined */
6792
6793
static void
6794
check_funcs()
6795
{
6796
	struct fdesc *fp, *next;
6797
	int i;
6798
49 by Arnold D. Robbins
Fix memory leaks - patch from John.
6799
	if (! in_main_context())
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6800
		goto free_mem;
6801
 
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6802
	for (i = 0; i < HASHSIZE; i++) {
6803
		for (fp = ftable[i]; fp != NULL; fp = fp->next) {
408.2.25 by Arnold D. Robbins
Bug fix in awkgram.y:check_funcs.
6804
#ifdef REALLYMEAN
6805
			/* making this the default breaks old code. sigh. */
319.2.43 by Arnold D. Robbins
Fix lint checking for extension functions.
6806
			if (fp->defined == 0 && ! fp->extension) {
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6807
				error(
6808
		_("function `%s' called but never defined"), fp->name);
6809
				errcount++;
408.2.25 by Arnold D. Robbins
Bug fix in awkgram.y:check_funcs.
6810
			}
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6811
#else
408.2.25 by Arnold D. Robbins
Bug fix in awkgram.y:check_funcs.
6812
			if (do_lint && fp->defined == 0 && ! fp->extension)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6813
				lintwarn(
6814
		_("function `%s' called but never defined"), fp->name);
6815
#endif
319.2.43 by Arnold D. Robbins
Fix lint checking for extension functions.
6816
6817
			if (do_lint && fp->used == 0 && ! fp->extension) {
140 by Arnold D. Robbins
Minor message fix.
6818
				lintwarn(_("function `%s' defined but never called directly"),
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6819
					fp->name);
6820
			}
6821
		}
6822
	}
6823
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6824
free_mem:
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6825
	/* now let's free all the memory */
6826
	for (i = 0; i < HASHSIZE; i++) {
6827
		for (fp = ftable[i]; fp != NULL; fp = next) {
6828
			next = fp->next;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6829
			efree(fp->name);
6830
			efree(fp);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6831
		}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6832
		ftable[i] = NULL;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6833
	}
6834
}
6835
6836
/* param_sanity --- look for parameters that are regexp constants */
6837
6838
static void
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6839
param_sanity(INSTRUCTION *arglist)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6840
{
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6841
	INSTRUCTION *argl, *arg;
6842
	int i = 1;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6843
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6844
	if (arglist == NULL)
6845
		return;
6846
	for (argl = arglist->nexti; argl; ) {
6847
		arg = argl->lasti;
6848
		if (arg->opcode == Op_match_rec)
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
6849
			warning_ln(arg->source_line,
6850
				_("regexp constant for parameter #%d yields boolean value"), i);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6851
		argl = arg->nexti;
6852
		i++;
6853
	}
6854
}
6855
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6856
/* variable --- make sure NAME is in the symbol table */
6857
6858
NODE *
281.1.1 by john haque
Speed/memory performance improvements.
6859
variable(int location, char *name, NODETYPE type)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6860
{
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6861
	NODE *r;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6862
30 by Arnold D. Robbins
Move to gawk-3.1.2.
6863
	if ((r = lookup(name)) != NULL) {
281.1.1 by john haque
Speed/memory performance improvements.
6864
		if (r->type == Node_func || r->type == Node_ext_func )
6865
			error_ln(location, _("function `%s' called with space between name and `(',\nor used as a variable or an array"),
32 by Arnold D. Robbins
Move to gawk-3.1.4.
6866
				r->vname);
30 by Arnold D. Robbins
Move to gawk-3.1.2.
6867
	} else {
6868
		/* not found */
408.13.37 by Arnold D. Robbins
Remove deferred variables.
6869
		return install_symbol(name, type);
30 by Arnold D. Robbins
Move to gawk-3.1.2.
6870
	}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6871
	efree(name);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6872
	return r;
6873
}
6874
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6875
/* make_regnode --- make a regular expression node */
6876
408.15.4 by Arnold D. Robbins
Further progress on indirect calls of builtins.
6877
NODE *
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6878
make_regnode(int type, NODE *exp)
6879
{
6880
	NODE *n;
6881
6882
	getnode(n);
6883
	memset(n, 0, sizeof(NODE));
6884
	n->type = type;
6885
	n->re_cnt = 1;
6886
6887
	if (type == Node_regex) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
6888
		n->re_reg = make_regexp(exp->stptr, exp->stlen, false, true, false);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6889
		if (n->re_reg == NULL) {
6890
			freenode(n);
6891
			return NULL;
6892
		}
6893
		n->re_exp = exp;
6894
		n->re_flags = CONSTANT;
6895
	}
6896
	return n;
6897
}
6898
6899
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6900
/* mk_rexp --- make a regular expression constant */
6901
6902
static NODE *
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6903
mk_rexp(INSTRUCTION *list)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6904
{
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6905
	INSTRUCTION *ip;
6906
6907
	ip = list->nexti;
6908
	if (ip == list->lasti && ip->opcode == Op_match_rec)
6909
		ip->opcode = Op_push_re;
6910
	else {
6911
		ip = instruction(Op_push_re);
6912
		ip->memory = make_regnode(Node_dynregex, NULL);
6913
		ip->nexti = list->lasti->nexti;
6914
		list->lasti->nexti = ip;
6915
		list->lasti = ip;
6916
	}
6917
	return ip->memory;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6918
}
6919
348 by Arnold D. Robbins
Fix --disable-lint.
6920
#ifndef NO_LINT
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6921
/* isnoeffect --- when used as a statement, has no side effects */
6922
6923
static int
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6924
isnoeffect(OPCODE type)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6925
{
6926
	switch (type) {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6927
	case Op_times:
6928
	case Op_times_i:
6929
	case Op_quotient:
6930
	case Op_quotient_i:
6931
	case Op_mod:
6932
	case Op_mod_i:
6933
	case Op_plus:
6934
	case Op_plus_i:
6935
	case Op_minus:
6936
	case Op_minus_i:
6937
	case Op_subscript:
6938
	case Op_concat:
6939
	case Op_exp:
6940
	case Op_exp_i:
6941
	case Op_unary_minus:
6942
	case Op_field_spec:
6943
	case Op_and_final:
6944
	case Op_or_final:
6945
	case Op_equal:
6946
	case Op_notequal:
6947
	case Op_less:
6948
	case Op_greater:
6949
	case Op_leq:
6950
	case Op_geq:
6951
	case Op_match:
6952
	case Op_nomatch:
6953
	case Op_match_rec:
6954
	case Op_not:
6955
	case Op_in_array:
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
6956
		return true;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6957
	default:
6958
		break;	/* keeps gcc -Wall happy */
6959
	}
6960
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
6961
	return false;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6962
}
348 by Arnold D. Robbins
Fix --disable-lint.
6963
#endif /* NO_LINT */
6964
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6965
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6966
/* make_assignable --- make this operand an assignable one if posiible */
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6967
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6968
static INSTRUCTION *
6969
make_assignable(INSTRUCTION *ip)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6970
{
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6971
	switch (ip->opcode) {
6972
	case Op_push:
6973
		ip->opcode = Op_push_lhs;
6974
		return ip;
6975
	case Op_field_spec:
6976
		ip->opcode = Op_field_spec_lhs;
6977
		return ip;
6978
	case Op_subscript:
6979
		ip->opcode = Op_subscript_lhs;
6980
		return ip;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6981
	default:
6982
		break;	/* keeps gcc -Wall happy */
6983
	}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
6984
	return NULL;
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6985
}
6986
319.2.36 by Arnold D. Robbins
Restore stopme() debugging function.
6987
/* stopme --- for debugging */
6988
6989
NODE *
319.2.38 by Arnold D. Robbins
Further API code and test code.
6990
stopme(int nargs ATTRIBUTE_UNUSED)
319.2.36 by Arnold D. Robbins
Restore stopme() debugging function.
6991
{
6992
	return make_number(0.0);
6993
}
6994
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6995
/* dumpintlstr --- write out an initial .po file entry for the string */
6996
6997
static void
30 by Arnold D. Robbins
Move to gawk-3.1.2.
6998
dumpintlstr(const char *str, size_t len)
28 by Arnold D. Robbins
Move to gawk-3.1.0.
6999
{
7000
	char *cp;
7001
7002
	/* See the GNU gettext distribution for details on the file format */
7003
7004
	if (source != NULL) {
7005
		/* ala the gettext sources, remove leading `./'s */
7006
		for (cp = source; cp[0] == '.' && cp[1] == '/'; cp += 2)
7007
			continue;
7008
		printf("#: %s:%d\n", cp, sourceline);
7009
	}
7010
7011
	printf("msgid ");
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
7012
	pp_string_fp(fprintf, stdout, str, len, '"', true);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
7013
	putchar('\n');
7014
	printf("msgstr \"\"\n\n");
29 by Arnold D. Robbins
Move to gawk-3.1.1.
7015
	fflush(stdout);
7016
}
7017
7018
/* dumpintlstr2 --- write out an initial .po file entry for the string and its plural */
7019
7020
static void
30 by Arnold D. Robbins
Move to gawk-3.1.2.
7021
dumpintlstr2(const char *str1, size_t len1, const char *str2, size_t len2)
29 by Arnold D. Robbins
Move to gawk-3.1.1.
7022
{
7023
	char *cp;
7024
7025
	/* See the GNU gettext distribution for details on the file format */
7026
7027
	if (source != NULL) {
7028
		/* ala the gettext sources, remove leading `./'s */
7029
		for (cp = source; cp[0] == '.' && cp[1] == '/'; cp += 2)
7030
			continue;
7031
		printf("#: %s:%d\n", cp, sourceline);
7032
	}
7033
7034
	printf("msgid ");
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
7035
	pp_string_fp(fprintf, stdout, str1, len1, '"', true);
29 by Arnold D. Robbins
Move to gawk-3.1.1.
7036
	putchar('\n');
7037
	printf("msgid_plural ");
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
7038
	pp_string_fp(fprintf, stdout, str2, len2, '"', true);
29 by Arnold D. Robbins
Move to gawk-3.1.1.
7039
	putchar('\n');
7040
	printf("msgstr[0] \"\"\nmsgstr[1] \"\"\n\n");
7041
	fflush(stdout);
28 by Arnold D. Robbins
Move to gawk-3.1.0.
7042
}
7043
109 by Arnold D. Robbins
Bug fixes and cleanup.
7044
/* mk_binary --- instructions for binary operators */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7045
7046
static INSTRUCTION *
7047
mk_binary(INSTRUCTION *s1, INSTRUCTION *s2, INSTRUCTION *op)
7048
{
109 by Arnold D. Robbins
Bug fixes and cleanup.
7049
	INSTRUCTION *ip1,*ip2;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7050
	AWKNUM res;
7051
109 by Arnold D. Robbins
Bug fixes and cleanup.
7052
	ip2 = s2->nexti;
7053
	if (s2->lasti == ip2 && ip2->opcode == Op_push_i) {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7054
	/* do any numeric constant folding */
7055
		ip1 = s1->nexti;
408.4.50 by Arnold D. Robbins
Fix -O option.
7056
		if (do_optimize
109 by Arnold D. Robbins
Bug fixes and cleanup.
7057
				&& ip1 == s1->lasti && ip1->opcode == Op_push_i
306 by john haque
Add arbitrary-precision arithmetic on integers.
7058
				&& (ip1->memory->flags & (MPFN|MPZN|STRCUR|STRING)) == 0
7059
				&& (ip2->memory->flags & (MPFN|MPZN|STRCUR|STRING)) == 0
109 by Arnold D. Robbins
Bug fixes and cleanup.
7060
		) {
7061
			NODE *n1 = ip1->memory, *n2 = ip2->memory;
301 by john haque
New interpreter routine for MPFR.
7062
			res = force_number(n1)->numbr;
109 by Arnold D. Robbins
Bug fixes and cleanup.
7063
			(void) force_number(n2);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7064
			switch (op->opcode) {
7065
			case Op_times:
109 by Arnold D. Robbins
Bug fixes and cleanup.
7066
				res *= n2->numbr;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7067
				break;
7068
			case Op_quotient:
109 by Arnold D. Robbins
Bug fixes and cleanup.
7069
				if (n2->numbr == 0.0) {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7070
					/* don't fatalize, allow parsing rest of the input */
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
7071
					error_ln(op->source_line, _("division by zero attempted"));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7072
					goto regular;
7073
				}
7074
109 by Arnold D. Robbins
Bug fixes and cleanup.
7075
				res /= n2->numbr;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7076
				break;
7077
			case Op_mod:
109 by Arnold D. Robbins
Bug fixes and cleanup.
7078
				if (n2->numbr == 0.0) {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7079
					/* don't fatalize, allow parsing rest of the input */
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
7080
					error_ln(op->source_line, _("division by zero attempted in `%%'"));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7081
					goto regular;
7082
				}
7083
#ifdef HAVE_FMOD
109 by Arnold D. Robbins
Bug fixes and cleanup.
7084
				res = fmod(res, n2->numbr);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7085
#else	/* ! HAVE_FMOD */
109 by Arnold D. Robbins
Bug fixes and cleanup.
7086
				(void) modf(res / n2->numbr, &res);
7087
				res = n1->numbr - res * n2->numbr;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7088
#endif	/* ! HAVE_FMOD */
7089
				break;
7090
			case Op_plus:
109 by Arnold D. Robbins
Bug fixes and cleanup.
7091
				res += n2->numbr;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7092
				break;
7093
			case Op_minus:
109 by Arnold D. Robbins
Bug fixes and cleanup.
7094
				res -= n2->numbr;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7095
				break;
7096
			case Op_exp:
109 by Arnold D. Robbins
Bug fixes and cleanup.
7097
				res = calc_exp(res, n2->numbr);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7098
				break;
7099
			default:
7100
				goto regular;
7101
			}
7102
7103
			op->opcode = Op_push_i;
281.1.1 by john haque
Speed/memory performance improvements.
7104
			op->memory = make_number(res);
109 by Arnold D. Robbins
Bug fixes and cleanup.
7105
			unref(n1);
7106
			unref(n2);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7107
			bcfree(ip1);
109 by Arnold D. Robbins
Bug fixes and cleanup.
7108
			bcfree(ip2);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7109
			bcfree(s1);
7110
			bcfree(s2);
7111
			return list_create(op);
7112
		} else {
7113
		/* do basic arithmetic optimisation */
7114
		/* convert (Op_push_i Node_val) + (Op_plus) to (Op_plus_i Node_val) */
7115
			switch (op->opcode) {
7116
			case Op_times:
7117
				op->opcode = Op_times_i;
7118
				break;
7119
			case Op_quotient:
7120
				op->opcode = Op_quotient_i;
7121
				break;
7122
			case Op_mod:
7123
				op->opcode = Op_mod_i;
7124
				break;
7125
			case Op_plus:
7126
				op->opcode = Op_plus_i;
7127
				break;
7128
			case Op_minus:
7129
				op->opcode = Op_minus_i;
7130
				break;
7131
			case Op_exp:
7132
				op->opcode = Op_exp_i;
7133
				break;
7134
			default:
7135
				goto regular;
7136
			}	
7137
109 by Arnold D. Robbins
Bug fixes and cleanup.
7138
			op->memory = ip2->memory;
7139
			bcfree(ip2);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7140
			bcfree(s2);	/* Op_list */
7141
			return list_append(s1, op);
7142
		}
7143
	}
7144
7145
regular:
7146
	/* append lists s1, s2 and add `op' bytecode */
7147
	(void) list_merge(s1, s2);
7148
	return list_append(s1, op);
7149
}
7150
7151
/* mk_boolean --- instructions for boolean and, or */
7152
 
7153
static INSTRUCTION *
7154
mk_boolean(INSTRUCTION *left, INSTRUCTION *right, INSTRUCTION *op)
7155
{
7156
	INSTRUCTION *tp;
7157
	OPCODE opc, final_opc;
7158
7159
	opc = op->opcode;		/* Op_and or Op_or */
7160
	final_opc = (opc == Op_or) ? Op_or_final : Op_and_final;
7161
7162
	add_lint(right, LINT_assign_in_cond);
7163
7164
	tp = left->lasti;
7165
7166
	if (tp->opcode != final_opc) {	/* x || y */
7167
		list_append(right, instruction(final_opc));
7168
		add_lint(left, LINT_assign_in_cond);
7169
		(void) list_append(left, op);
7170
		left->lasti->target_jmp = right->lasti;
7171
7172
		/* NB: target_stmt points to previous Op_and(Op_or) in a chain;
7173
		 *     target_stmt only used in the parser (see below).
7174
		 */
7175
7176
		left->lasti->target_stmt = left->lasti;
7177
		right->lasti->target_stmt = left->lasti;
7178
	} else {		/* optimization for x || y || z || ... */
7179
		INSTRUCTION *ip;
7180
		
7181
		op->opcode = final_opc;
7182
		(void) list_append(right, op);
7183
		op->target_stmt = tp;
7184
		tp->opcode = opc;
7185
		tp->target_jmp = op;
7186
7187
		/* update jump targets */
7188
		for (ip = tp->target_stmt; ; ip = ip->target_stmt) {
7189
			assert(ip->opcode == opc);
7190
			assert(ip->target_jmp == tp);
7191
			/* if (ip->opcode == opc &&  ip->target_jmp == tp) */
7192
			ip->target_jmp = op;
7193
			if (ip->target_stmt == ip)
7194
				break;
7195
		}
7196
	}
7197
7198
	return list_merge(left, right);
7199
}
7200
7201
/* mk_condition --- if-else and conditional */
7202
7203
static INSTRUCTION *
7204
mk_condition(INSTRUCTION *cond, INSTRUCTION *ifp, INSTRUCTION *true_branch,
7205
		INSTRUCTION *elsep, INSTRUCTION *false_branch)
7206
{
7207
	/*
7208
	 *    ----------------
7209
	 *       cond
7210
	 *    ----------------
7211
	 * t: [Op_jmp_false f ]
7212
	 *    ----------------
7213
	 *       true_branch
7214
	 *
7215
	 *    ----------------
7216
	 *    [Op_jmp y]
7217
	 *    ---------------- 
7218
	 * f:
7219
	 *      false_branch
7220
	 *    ----------------
7221
	 * y: [Op_no_op]
7222
	 *    ----------------
7223
	 */
7224
7225
	INSTRUCTION *ip;
408.19.69 by Arnold D. Robbins
Bug fix for pretty printing empty else part.
7226
	bool setup_else_part = true;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7227
7228
	if (false_branch == NULL) {
116 by Arnold D. Robbins
Fix switch debugging.
7229
		false_branch = list_create(instruction(Op_no_op));
408.19.69 by Arnold D. Robbins
Bug fix for pretty printing empty else part.
7230
		if (elsep == NULL) {		/* else { } */
7231
			setup_else_part = false;
116 by Arnold D. Robbins
Fix switch debugging.
7232
		}
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7233
	} else {
7234
		/* assert(elsep != NULL); */
7235
7236
		/* avoid a series of no_op's: if .. else if .. else if .. */
7237
		if (false_branch->lasti->opcode != Op_no_op)
7238
			(void) list_append(false_branch, instruction(Op_no_op));
408.19.69 by Arnold D. Robbins
Bug fix for pretty printing empty else part.
7239
	}
7240
7241
	if (setup_else_part) {
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
7242
		if (do_pretty_print) {
116 by Arnold D. Robbins
Fix switch debugging.
7243
			(void) list_prepend(false_branch, elsep);
7244
			false_branch->nexti->branch_end = false_branch->lasti;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7245
			(void) list_prepend(false_branch, instruction(Op_exec_count));
116 by Arnold D. Robbins
Fix switch debugging.
7246
		} else
7247
			bcfree(elsep);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7248
	}
7249
7250
	(void) list_prepend(false_branch, instruction(Op_jmp));
7251
	false_branch->nexti->target_jmp = false_branch->lasti;
7252
7253
	add_lint(cond, LINT_assign_in_cond);
7254
	ip = list_append(cond, instruction(Op_jmp_false));
7255
	ip->lasti->target_jmp = false_branch->nexti->nexti;
7256
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
7257
	if (do_pretty_print) {
116 by Arnold D. Robbins
Fix switch debugging.
7258
		(void) list_prepend(ip, ifp);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7259
		(void) list_append(ip, instruction(Op_exec_count));
7260
		ip->nexti->branch_if = ip->lasti;
7261
		ip->nexti->branch_else = false_branch->nexti;
116 by Arnold D. Robbins
Fix switch debugging.
7262
	} else
7263
		bcfree(ifp);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7264
7265
	if (true_branch != NULL)
7266
		list_merge(ip, true_branch);
7267
	return list_merge(ip, false_branch);
7268
}
7269
7270
enum defline { FIRST_LINE, LAST_LINE };
7271
7272
/* find_line -- find the first(last) line in a list of (pattern) instructions */
7273
7274
static int
7275
find_line(INSTRUCTION *pattern, enum defline what)
7276
{
7277
	INSTRUCTION *ip;
7278
	int lineno = 0;
7279
7280
	for (ip = pattern->nexti; ip; ip = ip->nexti) {
7281
		if (what == LAST_LINE) {
7282
			if (ip->source_line > lineno)
7283
				lineno = ip->source_line;
7284
		} else {	/* FIRST_LINE */
7285
			if (ip->source_line > 0
7286
					&& (lineno == 0 || ip->source_line < lineno))
7287
				lineno = ip->source_line;
7288
		}
7289
		if (ip == pattern->lasti)
7290
			break;
7291
	}
7292
	assert(lineno > 0);
7293
	return lineno;
7294
}
7295
7296
/* append_rule --- pattern-action instructions */
7297
7298
static INSTRUCTION *
7299
append_rule(INSTRUCTION *pattern, INSTRUCTION *action)
7300
{
7301
	/*
7302
	 *    ----------------
7303
	 *       pattern
7304
	 *    ----------------
7305
	 *    [Op_jmp_false f ]
7306
	 *    ----------------
7307
	 *       action
7308
	 *    ----------------
7309
	 * f: [Op_no_op       ]
7310
	 *    ----------------
7311
	 */
7312
7313
	INSTRUCTION *rp;
7314
	INSTRUCTION *tp;
7315
	INSTRUCTION *ip;
7316
7317
	if (rule != Rule) {
7318
		rp = pattern;
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
7319
		if (do_pretty_print)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7320
			(void) list_append(action, instruction(Op_no_op));
7321
		(rp + 1)->firsti = action->nexti;
7322
		(rp + 1)->lasti = action->lasti;
7323
		(rp + 2)->first_line = pattern->source_line;
7324
		(rp + 2)->last_line = lastline;
7325
		ip = list_prepend(action, rp);
7326
7327
	} else {
7328
		rp = bcalloc(Op_rule, 3, 0);
7329
		rp->in_rule = Rule;
7330
		rp->source_file = source;
7331
		tp = instruction(Op_no_op);
7332
7333
		if (pattern == NULL) {
7334
			/* assert(action != NULL); */
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
7335
			if (do_pretty_print)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7336
				(void) list_prepend(action, instruction(Op_exec_count));
7337
			(rp + 1)->firsti = action->nexti;
7338
			(rp + 1)->lasti = tp;
7339
			(rp + 2)->first_line = firstline;
7340
			(rp + 2)->last_line = lastline;
7341
			rp->source_line = firstline;
7342
			ip = list_prepend(list_append(action, tp), rp);
7343
		} else {
7344
			(void) list_append(pattern, instruction(Op_jmp_false));
7345
			pattern->lasti->target_jmp = tp;
7346
			(rp + 2)->first_line = find_line(pattern, FIRST_LINE);
7347
			rp->source_line = (rp + 2)->first_line;
7348
			if (action == NULL) {
7349
				(rp + 2)->last_line = find_line(pattern, LAST_LINE);
7350
				action = list_create(instruction(Op_K_print_rec));
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
7351
				if (do_pretty_print)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7352
					(void) list_prepend(action, instruction(Op_exec_count));
7353
			} else
7354
				(rp + 2)->last_line = lastline;
7355
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
7356
			if (do_pretty_print) {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7357
				(void) list_prepend(pattern, instruction(Op_exec_count));
7358
				(void) list_prepend(action, instruction(Op_exec_count));
7359
			}
7360
 			(rp + 1)->firsti = action->nexti;
7361
			(rp + 1)->lasti = tp;
7362
			ip = list_append(
7363
					list_merge(list_prepend(pattern, rp),
7364
						action),
7365
					tp);
7366
		}
7367
7368
	}
7369
7370
	list_append(rule_list, rp + 1);
7371
7372
	if (rule_block[rule] == NULL)
7373
		rule_block[rule] = ip;
7374
	else
7375
		(void) list_merge(rule_block[rule], ip);
7376
	
7377
	return rule_block[rule];
7378
}
7379
7380
/* mk_assignment --- assignment bytecodes */
7381
7382
static INSTRUCTION *
7383
mk_assignment(INSTRUCTION *lhs, INSTRUCTION *rhs, INSTRUCTION *op)
7384
{
7385
	INSTRUCTION *tp;
7386
	INSTRUCTION *ip;
7387
7388
	tp = lhs->lasti;
7389
	switch (tp->opcode) {
7390
	case Op_field_spec:
7391
		tp->opcode = Op_field_spec_lhs;
7392
		break;
7393
	case Op_subscript:
7394
		tp->opcode = Op_subscript_lhs;
7395
		break;
7396
	case Op_push:
7397
	case Op_push_array:
7398
		tp->opcode = Op_push_lhs; 
7399
		break;
408.4.42 by Arnold D. Robbins
Bug fix for $i++ = 3.
7400
	case Op_field_assign:
7401
		yyerror(_("cannot assign a value to the result of a field post-increment expression"));
7402
		break;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7403
	default:
408.4.42 by Arnold D. Robbins
Bug fix for $i++ = 3.
7404
		yyerror(_("invalid target of assignment (opcode %s)"),
7405
				opcode2str(tp->opcode));
7406
		break;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7407
	}
7408
7409
	tp->do_reference = (op->opcode != Op_assign);	/* check for uninitialized reference */
7410
7411
	if (rhs != NULL)
7412
		ip = list_merge(rhs, lhs);
7413
	else
7414
		ip = lhs;
7415
7416
	(void) list_append(ip, op);
7417
7418
	if (tp->opcode == Op_push_lhs
7419
			&& tp->memory->type == Node_var
7420
			&& tp->memory->var_assign
7421
	) {
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
7422
		tp->do_reference = false; /* no uninitialized reference checking
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7423
		                           * for a special variable.
7424
		                           */
7425
		(void) list_append(ip, instruction(Op_var_assign));
146 by Arnold D. Robbins
Bug fixes in scanning, updating variables.
7426
		ip->lasti->assign_var = tp->memory->var_assign;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7427
	} else if (tp->opcode == Op_field_spec_lhs) {
7428
		(void) list_append(ip, instruction(Op_field_assign));
7429
		ip->lasti->field_assign = (Func_ptr) 0;
7430
		tp->target_assign = ip->lasti;
322 by john haque
Improve array interface.
7431
	} else if (tp->opcode == Op_subscript_lhs) {
7432
		(void) list_append(ip, instruction(Op_subscript_assign));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7433
	}
7434
7435
	return ip;
7436
}
7437
7438
/* optimize_assignment --- peephole optimization for assignment */
7439
7440
static INSTRUCTION *
7441
optimize_assignment(INSTRUCTION *exp)
7442
{
281.1.1 by john haque
Speed/memory performance improvements.
7443
	INSTRUCTION *i1, *i2, *i3;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7444
7445
	/*
7446
	 * Optimize assignment statements array[subs] = x; var = x; $n = x;
7447
	 * string concatenation of the form s = s t.
7448
	 *
7449
	 * 1) Array element assignment array[subs] = x:
7450
	 *   Replaces Op_push_array + Op_subscript_lhs + Op_assign + Op_pop
7451
	 *   with single instruction Op_store_sub.
116 by Arnold D. Robbins
Fix switch debugging.
7452
	 *	 Limitation: 1 dimension and sub is simple var/value.
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7453
	 * 
7454
	 * 2) Simple variable assignment var = x:
7455
	 *   Replaces Op_push_lhs + Op_assign + Op_pop with Op_store_var.
7456
	 *
7457
	 * 3) Field assignment $n = x:
7458
	 *   Replaces Op_field_spec_lhs + Op_assign + Op_field_assign + Op_pop
7459
	 *   with Op_store_field.
7460
	 *
7461
	 * 4) Optimization for string concatenation:
7462
	 *   For cases like x = x y, uses realloc to include y in x;
7463
	 *   also eliminates instructions Op_push_lhs and Op_pop.
7464
	 */
7465
7466
	/*
7467
	 * N.B.: do not append Op_pop instruction to the returned
7468
	 * instruction list if optimized. None of these
49 by Arnold D. Robbins
Fix memory leaks - patch from John.
7469
	 * optimized instructions pushes the r-value of assignment
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7470
	 * onto the runtime stack.
7471
	 */
7472
7473
	i2 = NULL;
7474
	i1 = exp->lasti;
7475
408.4.50 by Arnold D. Robbins
Fix -O option.
7476
	if (   i1->opcode != Op_assign
7477
	    && i1->opcode != Op_field_assign) 
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7478
		return list_append(exp, instruction(Op_pop));
7479
7480
	for (i2 = exp->nexti; i2 != i1; i2 = i2->nexti) {
7481
		switch (i2->opcode) {
7482
		case Op_concat:
7483
			if (i2->nexti->opcode == Op_push_lhs    /* l.h.s is a simple variable */
408.13.111 by Arnold D. Robbins
Minor code cleanups.
7484
				&& (i2->concat_flag & CSVAR) != 0   /* 1st exp in r.h.s is a simple variable;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7485
				                                     * see Op_concat in the grammer above.
7486
				                                     */
7487
				&& i2->nexti->memory == exp->nexti->memory	 /* and the same as in l.h.s */
7488
				&& i2->nexti->nexti == i1
7489
				&& i1->opcode == Op_assign
7490
			) {
7491
				/* s = s ... optimization */
7492
7493
				/* avoid stuff like x = x (x = y) or x = x gsub(/./, "b", x);
7494
				 * check for l-value reference to this variable in the r.h.s.
116 by Arnold D. Robbins
Fix switch debugging.
7495
				 * Also, avoid function calls in general to guard against
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7496
				 * global variable assignment.
7497
				 */
7498
7499
				for (i3 = exp->nexti->nexti; i3 != i2; i3 = i3->nexti) {
7500
					if ((i3->opcode == Op_push_lhs && i3->memory == i2->nexti->memory)
7501
							|| i3->opcode == Op_func_call)
7502
						return list_append(exp, instruction(Op_pop)); /* no optimization */
7503
				}
7504
7505
				/* remove the variable from r.h.s */
7506
				i3 = exp->nexti;
7507
				exp->nexti = i3->nexti;
7508
				bcfree(i3);
7509
7510
				if (--i2->expr_count == 1)	/* one less expression in Op_concat */
7511
					i2->opcode = Op_no_op;
7512
7513
				i3 = i2->nexti;
7514
				assert(i3->opcode == Op_push_lhs);
7515
				i3->opcode = Op_assign_concat;	/* change Op_push_lhs to Op_assign_concat */
7516
				i3->nexti = NULL;
7517
				bcfree(i1);          /* Op_assign */
7518
				exp->lasti = i3;     /* update Op_list */
7519
				return exp;
7520
			}
7521
			break;
7522
7523
		case Op_field_spec_lhs:
7524
			if (i2->nexti->opcode == Op_assign
7525
					&& i2->nexti->nexti == i1
7526
					&& i1->opcode == Op_field_assign
7527
			) {
7528
				/* $n = .. */
7529
				i2->opcode = Op_store_field;
7530
				bcfree(i2->nexti);  /* Op_assign */
7531
				i2->nexti = NULL;
7532
				bcfree(i1);          /* Op_field_assign */
7533
				exp->lasti = i2;    /* update Op_list */
7534
				return exp;
7535
			}
7536
			break;
7537
7538
		case Op_push_array:
7539
			if (i2->nexti->nexti->opcode == Op_subscript_lhs) {
7540
				i3 = i2->nexti->nexti;
7541
				if (i3->sub_count == 1
7542
						&& i3->nexti == i1
7543
						&& i1->opcode == Op_assign
7544
				) {
7545
					/* array[sub] = .. */
7546
					i3->opcode = Op_store_sub;
7547
					i3->memory = i2->memory;
7548
					i3->expr_count = 1;  /* sub_count shadows memory,
7549
                                          * so use expr_count instead.
7550
				                          */
7551
					i3->nexti = NULL;
7552
					i2->opcode = Op_no_op;					
7553
					bcfree(i1);          /* Op_assign */
7554
					exp->lasti = i3;     /* update Op_list */
7555
					return exp;
7556
				}
7557
			}
7558
			break;
7559
7560
		case Op_push_lhs:
7561
			if (i2->nexti == i1
281.1.1 by john haque
Speed/memory performance improvements.
7562
					&& i1->opcode == Op_assign
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7563
			) {
7564
				/* var = .. */
7565
				i2->opcode = Op_store_var;
7566
				i2->nexti = NULL;
7567
				bcfree(i1);          /* Op_assign */
7568
				exp->lasti = i2;     /* update Op_list */
281.1.1 by john haque
Speed/memory performance improvements.
7569
7570
				i3 = exp->nexti;
7571
				if (i3->opcode == Op_push_i
7572
					&& (i3->memory->flags & INTLSTR) == 0
7573
					&& i3->nexti == i2
7574
				) {
7575
					/* constant initializer */ 
7576
					i2->initval = i3->memory;
7577
					bcfree(i3);
7578
					exp->nexti = i2;
7579
				} else
7580
					i2->initval = NULL;
7581
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7582
				return exp;
7583
			}
7584
			break;
7585
7586
		default:
7587
			break;
7588
		}
7589
	}
7590
7591
	/* no optimization  */
7592
	return list_append(exp, instruction(Op_pop));
7593
}
7594
7595
7596
/* mk_getline --- make instructions for getline */
7597
7598
static INSTRUCTION *
116 by Arnold D. Robbins
Fix switch debugging.
7599
mk_getline(INSTRUCTION *op, INSTRUCTION *var, INSTRUCTION *redir, int redirtype)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7600
{
7601
	INSTRUCTION *ip;
7602
	INSTRUCTION *tp;
7603
	INSTRUCTION *asgn = NULL;
7604
7605
	/*
7606
	 *  getline [var] < [file]
7607
	 *
7608
	 *  [ file (simp_exp)]
7609
	 *  [ [ var ] ]
7610
	 *  [ Op_K_getline_redir|NULL|redir_type|into_var]
7611
	 *  [ [var_assign] ] 
7612
	 *
7613
	 */
7614
7615
	if (redir == NULL) {
7616
		int sline = op->source_line;
7617
		bcfree(op);
7618
		op = bcalloc(Op_K_getline, 2, sline);
7619
		(op + 1)->target_endfile = ip_endfile;
7620
		(op + 1)->target_beginfile = ip_beginfile;	
7621
	}
7622
7623
	if (var != NULL) {
7624
		tp = make_assignable(var->lasti);
7625
		assert(tp != NULL);
7626
7627
		/* check if we need after_assign bytecode */
7628
		if (tp->opcode == Op_push_lhs
7629
				&& tp->memory->type == Node_var
7630
				&& tp->memory->var_assign
7631
		) {
7632
			asgn = instruction(Op_var_assign);
277.1.11 by Arnold D. Robbins
Fix gsub and getline pass by reference. Add tests.
7633
			asgn->assign_ctxt = op->opcode;
146 by Arnold D. Robbins
Bug fixes in scanning, updating variables.
7634
			asgn->assign_var = tp->memory->var_assign;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7635
		} else if (tp->opcode == Op_field_spec_lhs) {
7636
			asgn = instruction(Op_field_assign);
277.1.11 by Arnold D. Robbins
Fix gsub and getline pass by reference. Add tests.
7637
			asgn->assign_ctxt = op->opcode;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7638
			asgn->field_assign = (Func_ptr) 0;   /* determined at run time */
7639
			tp->target_assign = asgn;
322 by john haque
Improve array interface.
7640
		} else if (tp->opcode == Op_subscript_lhs) {
7641
			asgn = instruction(Op_subscript_assign);
7642
			asgn->assign_ctxt = op->opcode;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7643
		}
322 by john haque
Improve array interface.
7644
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7645
		if (redir != NULL) {
7646
			ip = list_merge(redir, var);
7647
			(void) list_append(ip, op);
7648
		} else
7649
			ip = list_append(var, op);
7650
	} else if (redir != NULL)
7651
		ip = list_append(redir, op);
7652
	else
7653
		ip = list_create(op);
7654
	op->into_var = (var != NULL);
319.1.1 by Arnold D. Robbins
Cleanups in io.c and improve RS as regexp.
7655
	op->redir_type = (redir != NULL) ? redirtype : redirect_none;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7656
7657
	return (asgn == NULL ? ip : list_append(ip, asgn));
7658
}
7659
7660
7661
/* mk_for_loop --- for loop bytecodes */
7662
7663
static INSTRUCTION *
7664
mk_for_loop(INSTRUCTION *forp, INSTRUCTION *init, INSTRUCTION *cond,
7665
				INSTRUCTION *incr, INSTRUCTION *body)
7666
{
7667
	/*
7668
	 *   ------------------------
7669
	 *        init                 (may be NULL)
7670
	 *   ------------------------
7671
	 * x:
7672
	 *        cond                 (Op_no_op if NULL)
7673
	 *   ------------------------
116 by Arnold D. Robbins
Fix switch debugging.
7674
	 *    [ Op_jmp_false tb      ]
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7675
	 *   ------------------------
7676
	 *        body                 (may be NULL)
7677
	 *   ------------------------
116 by Arnold D. Robbins
Fix switch debugging.
7678
	 * tc: 
7679
	 *    incr                      (may be NULL)
7680
	 *    [ Op_jmp x             ] 
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7681
	 *   ------------------------
116 by Arnold D. Robbins
Fix switch debugging.
7682
	 * tb:[ Op_no_op             ] 
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7683
	 */
7684
116 by Arnold D. Robbins
Fix switch debugging.
7685
	INSTRUCTION *ip, *tbreak, *tcont;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7686
	INSTRUCTION *jmp;
7687
	INSTRUCTION *pp_cond;
7688
	INSTRUCTION *ret;
7689
116 by Arnold D. Robbins
Fix switch debugging.
7690
	tbreak = instruction(Op_no_op);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7691
7692
	if (cond != NULL) {
7693
		add_lint(cond, LINT_assign_in_cond);
7694
		pp_cond = cond->nexti;
116 by Arnold D. Robbins
Fix switch debugging.
7695
		ip = cond;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7696
		(void) list_append(ip, instruction(Op_jmp_false));
116 by Arnold D. Robbins
Fix switch debugging.
7697
		ip->lasti->target_jmp = tbreak;
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7698
	} else {
7699
		pp_cond = instruction(Op_no_op);
116 by Arnold D. Robbins
Fix switch debugging.
7700
		ip = list_create(pp_cond);
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7701
	}
7702
116 by Arnold D. Robbins
Fix switch debugging.
7703
	if (init != NULL)
7704
		ip = list_merge(init, ip);
7705
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
7706
	if (do_pretty_print) {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7707
		(void) list_append(ip, instruction(Op_exec_count));
7708
		(forp + 1)->forloop_cond = pp_cond;
7709
		(forp + 1)->forloop_body = ip->lasti;
7710
	}
7711
7712
	if (body != NULL)
7713
		(void) list_merge(ip, body);
116 by Arnold D. Robbins
Fix switch debugging.
7714
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7715
	jmp = instruction(Op_jmp);
7716
	jmp->target_jmp = pp_cond;
7717
	if (incr == NULL)
116 by Arnold D. Robbins
Fix switch debugging.
7718
		tcont = jmp;
7719
	else {
7720
		tcont = incr->nexti;
7721
		(void) list_merge(ip, incr);
7722
	}
7723
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7724
	(void) list_append(ip, jmp);
116 by Arnold D. Robbins
Fix switch debugging.
7725
	ret = list_append(ip, tbreak);
7726
	fix_break_continue(ret, tbreak, tcont);
7727
291 by Arnold D. Robbins
The grand merge: dgawk and pgawk folded into gawk.
7728
	if (do_pretty_print) {
116 by Arnold D. Robbins
Fix switch debugging.
7729
		forp->target_break = tbreak;
7730
		forp->target_continue = tcont;
7731
		ret = list_prepend(ret, forp);
7732
	} /* else
7733
			forp is NULL */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7734
7735
	return ret;
7736
}
7737
7738
/* add_lint --- add lint warning bytecode if needed */
7739
7740
static void
7741
add_lint(INSTRUCTION *list, LINTTYPE linttype)
7742
{
7743
#ifndef NO_LINT
7744
	INSTRUCTION *ip;
7745
7746
	switch (linttype) {
7747
	case LINT_assign_in_cond:
7748
		ip = list->lasti;
7749
		if (ip->opcode == Op_var_assign || ip->opcode == Op_field_assign) {
7750
			assert(ip != list->nexti);
7751
			for (ip = list->nexti; ip->nexti != list->lasti; ip = ip->nexti)
7752
				;
7753
		}
7754
7755
		if (ip->opcode == Op_assign || ip->opcode == Op_assign_concat) {
7756
			list_append(list, instruction(Op_lint));
7757
			list->lasti->lint_type = linttype;
7758
		}
7759
		break;
7760
7761
	case LINT_no_effect:
7762
		if (list->lasti->opcode == Op_pop && list->nexti != list->lasti) {
7763
			for (ip = list->nexti; ip->nexti != list->lasti; ip = ip->nexti)
7764
				;
7765
7766
			if (do_lint) {		/* compile-time warning */
7767
				if (isnoeffect(ip->opcode))
150 by Arnold D. Robbins
Fix line numbers in lint warnings.
7768
					lintwarn_ln(ip->source_line, ("statement may have no effect"));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7769
			}
7770
7771
			if (ip->opcode == Op_push) {		/* run-time warning */
7772
				list_append(list, instruction(Op_lint));
7773
				list->lasti->lint_type = linttype;
7774
			}
7775
		}
7776
		break;
7777
7778
	default:
7779
		break;
7780
	}
7781
#endif
7782
}
7783
7784
/* mk_expression_list --- list of bytecode lists */
7785
7786
static INSTRUCTION *
7787
mk_expression_list(INSTRUCTION *list, INSTRUCTION *s1)
7788
{
7789
	INSTRUCTION *r;
7790
7791
	/* we can't just combine all bytecodes, since we need to
7792
	 * process individual expressions for a few builtins in snode() (-:
7793
	 */
7794
	
7795
	/* -- list of lists     */
7796
	/* [Op_list| ... ]------
7797
	 *                       |
7798
	 * [Op_list| ... ]   --  |
7799
	 *  ...               |  |
7800
	 *  ...       <-------   |
7801
	 * [Op_list| ... ]   --  |
7802
	 *  ...               |  |
7803
	 *  ...               |  |
7804
	 *  ...       <------- --
7805
	 */
7806
7807
	assert(s1 != NULL && s1->opcode == Op_list);
7808
	if (list == NULL) {
7809
		list = instruction(Op_list);
7810
		list->nexti = s1;
7811
		list->lasti = s1->lasti;
7812
		return list;
7813
	}
7814
7815
	/* append expression to the end of the list */
7816
7817
	r = list->lasti;
7818
	r->nexti = s1;
7819
	list->lasti = s1->lasti;
7820
	return list;
7821
}
7822
7823
/* count_expressions --- fixup expression_list from mk_expression_list.
7824
 *                       returns no of expressions in list. isarg is true
7825
 *                       for function arguments.
7826
 */
7827
7828
static int
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
7829
count_expressions(INSTRUCTION **list, bool isarg)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7830
{
7831
	INSTRUCTION *expr;
7832
	INSTRUCTION *r = NULL;
7833
	int count = 0;
7834
7835
	if (*list == NULL)	/* error earlier */
7836
		return 0;
7837
7838
	for (expr = (*list)->nexti; expr; ) {
7839
		INSTRUCTION *t1, *t2;
7840
		t1 = expr->nexti;
7841
		t2 = expr->lasti;
7842
		if (isarg && t1 == t2 && t1->opcode == Op_push)
7843
			t1->opcode = Op_push_param;
7844
		if (++count == 1)
7845
			r = expr;
7846
		else
7847
			(void) list_merge(r, expr);
7848
		expr = t2->nexti;
7849
	}
7850
 
7851
	assert(count > 0);
7852
	if (! isarg && count > max_args)
7853
		max_args = count;
7854
	bcfree(*list);
7855
	*list = r;
7856
	return count;
7857
}
7858
116 by Arnold D. Robbins
Fix switch debugging.
7859
/* fix_break_continue --- fix up break & continue codes in loop bodies */
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7860
7861
static void
116 by Arnold D. Robbins
Fix switch debugging.
7862
fix_break_continue(INSTRUCTION *list, INSTRUCTION *b_target, INSTRUCTION *c_target)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7863
{
116 by Arnold D. Robbins
Fix switch debugging.
7864
	INSTRUCTION *ip;
7865
7866
	list->lasti->nexti = NULL;	/* just to make sure */
7867
7868
	for (ip = list->nexti; ip != NULL; ip = ip->nexti) {
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7869
		switch (ip->opcode) {
7870
		case Op_K_break:
7871
			if (ip->target_jmp == NULL)
7872
				ip->target_jmp = b_target;
7873
			break;
7874
7875
		case Op_K_continue:
116 by Arnold D. Robbins
Fix switch debugging.
7876
			if (ip->target_jmp == NULL)
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
7877
				ip->target_jmp = c_target;
7878
			break;
7879
7880
		default:
7881
			/* this is to keep the compiler happy. sheesh. */
7882
			break;
7883
		}
7884
	}
7885
}
7886
7887
static inline INSTRUCTION *
7888
list_create(INSTRUCTION *x)
7889
{
7890
	INSTRUCTION *l;
7891
7892
	l = instruction(Op_list);
7893
	l->nexti = x;
7894
	l->lasti = x;
7895
	return l;
7896
}
7897
7898
static inline INSTRUCTION *
7899
list_append(INSTRUCTION *l, INSTRUCTION *x)
7900
{
7901
#ifdef GAWKDEBUG
7902
	if (l->opcode != Op_list)
7903
		cant_happen();
7904
#endif
7905
	l->lasti->nexti = x;
7906
	l->lasti = x;
7907
	return l;
7908
}
7909
7910
static inline INSTRUCTION *
7911
list_prepend(INSTRUCTION *l, INSTRUCTION *x)
7912
{
7913
#ifdef GAWKDEBUG
7914
	if (l->opcode != Op_list)
7915
		cant_happen();
7916
#endif
7917
	x->nexti = l->nexti;
7918
	l->nexti = x;
7919
	return l;
7920
}
7921
7922
static inline INSTRUCTION *
7923
list_merge(INSTRUCTION *l1, INSTRUCTION *l2)
7924
{
7925
#ifdef GAWKDEBUG
7926
	if (l1->opcode != Op_list)
7927
		cant_happen();
7928
	if (l2->opcode != Op_list)
7929
		cant_happen();
7930
#endif
7931
	l1->lasti->nexti = l2->nexti;
7932
	l1->lasti = l2->lasti;
7933
	bcfree(l2);
7934
	return l1;
7935
}
7936
32 by Arnold D. Robbins
Move to gawk-3.1.4.
7937
/* See if name is a special token. */
7938
7939
int
7940
check_special(const char *name)
7941
{
7942
	int low, high, mid;
7943
	int i;
408.13.111 by Arnold D. Robbins
Minor code cleanups.
7944
	int non_standard_flags = 0;
408.21.1 by Arnold D. Robbins
Rework zOS patches; keep separate from autotools.
7945
#ifdef USE_EBCDIC
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
7946
	static bool did_sort = false;
35 by Arnold D. Robbins
Move to gawk-3.1.7.
7947
7948
	if (! did_sort) {
81 by Arnold D. Robbins
Some fixes for z/OS and also Autoconf.
7949
		qsort((void *) tokentab,
7950
				sizeof(tokentab) / sizeof(tokentab[0]),
35 by Arnold D. Robbins
Move to gawk-3.1.7.
7951
				sizeof(tokentab[0]), tokcompare);
319.1.9 by Arnold D. Robbins
Move to use of bool type, true, false, everywhere.
7952
		did_sort = true;
35 by Arnold D. Robbins
Move to gawk-3.1.7.
7953
	}
7954
#endif
7955
408.13.111 by Arnold D. Robbins
Minor code cleanups.
7956
	if (do_traditional)
7957
		non_standard_flags |= GAWKX;
7958
	if (do_posix)
7959
		non_standard_flags |= NOT_POSIX;
7960
32 by Arnold D. Robbins
Move to gawk-3.1.4.
7961
	low = 0;
7962
	high = (sizeof(tokentab) / sizeof(tokentab[0])) - 1;
7963
	while (low <= high) {
7964
		mid = (low + high) / 2;
7965
		i = *name - tokentab[mid].operator[0];
7966
		if (i == 0)
7967
			i = strcmp(name, tokentab[mid].operator);
7968
7969
		if (i < 0)		/* token < mid */
7970
			high = mid - 1;
7971
		else if (i > 0)		/* token > mid */
7972
			low = mid + 1;
254 by Arnold D. Robbins
Disallow gawk builtin/keyword as variable assignment.
7973
		else {
408.13.111 by Arnold D. Robbins
Minor code cleanups.
7974
			if ((tokentab[mid].flags & non_standard_flags) != 0)
254 by Arnold D. Robbins
Disallow gawk builtin/keyword as variable assignment.
7975
				return -1;
32 by Arnold D. Robbins
Move to gawk-3.1.4.
7976
			return mid;
254 by Arnold D. Robbins
Disallow gawk builtin/keyword as variable assignment.
7977
		}
32 by Arnold D. Robbins
Move to gawk-3.1.4.
7978
	}
7979
	return -1;
7980
}
7981
34 by Arnold D. Robbins
Move to gawk-3.1.6.
7982
/*
7983
 * This provides a private version of functions that act like VMS's
7984
 * variable-length record filesystem, where there was a bug on
7985
 * certain source files.
7986
 */
7987
7988
static FILE *fp = NULL;
7989
7990
/* read_one_line --- return one input line at a time. mainly for debugging. */
7991
7992
static ssize_t
7993
read_one_line(int fd, void *buffer, size_t count)
7994
{
7995
	char buf[BUFSIZ];
7996
7997
	/* Minor potential memory leak here. Too bad. */
7998
	if (fp == NULL) {
7999
		fp = fdopen(fd, "r");
8000
		if (fp == NULL) {
8001
			fprintf(stderr, "ugh. fdopen: %s\n", strerror(errno));
40 by Arnold D. Robbins
Bring latest byte code gawk into git. Hurray!
8002
			gawk_exit(EXIT_FAILURE);
34 by Arnold D. Robbins
Move to gawk-3.1.6.
8003
		}
8004
	}
8005
8006
	if (fgets(buf, sizeof buf, fp) == NULL)
8007
		return 0;
8008
8009
	memcpy(buffer, buf, strlen(buf));
8010
	return strlen(buf);
8011
}
8012
8013
/* one_line_close --- close the open file being read with read_one_line() */
8014
8015
static int
8016
one_line_close(int fd)
8017
{
8018
	int ret;
8019
8020
	if (fp == NULL || fd != fileno(fp))
8021
		fatal("debugging read/close screwed up!");
8022
8023
	ret = fclose(fp);
8024
	fp = NULL;
8025
	return ret;
8026
}
8027
30 by Arnold D. Robbins
Move to gawk-3.1.2.
8028
408.5.261 by Arnold D. Robbins
Make indirect calls work on built-in and extension functions.
8029
/* lookup_builtin --- find a builtin function or return NULL */
8030
8031
builtin_func_t
8032
lookup_builtin(const char *name)
8033
{
8034
	int mid = check_special(name);
8035
408.15.1 by Arnold D. Robbins
Start on testing/fixing indirect calls of builtins.
8036
	if (mid == -1)
8037
		return NULL;
8038
8039
	switch (tokentab[mid].class) {
8040
	case LEX_BUILTIN:
8041
	case LEX_LENGTH:
8042
		break;
8043
	default:
8044
		return NULL;
8045
	}
8046
408.5.261 by Arnold D. Robbins
Make indirect calls work on built-in and extension functions.
8047
#ifdef HAVE_MPFR
8048
	if (do_mpfr)
8049
		return tokentab[mid].ptr2;
8050
#endif
8051
408.15.1 by Arnold D. Robbins
Start on testing/fixing indirect calls of builtins.
8052
	/* And another special case... */
8053
	if (tokentab[mid].value == Op_sub_builtin)
8054
		return (builtin_func_t) do_sub;
8055
408.5.261 by Arnold D. Robbins
Make indirect calls work on built-in and extension functions.
8056
	return tokentab[mid].ptr;
8057
}
408.5.265 by Arnold D. Robbins
Add builtin functions to FUNCTAB and PROCINFO["identifiers"] and doc.
8058
8059
/* install_builtins --- add built-in functions to FUNCTAB */
8060
8061
void
8062
install_builtins(void)
8063
{
8064
	int i, j;
408.13.109 by Arnold D. Robbins
Don't install gawk extensions if --posix or --traditional.
8065
	int flags_that_must_be_clear = DEBUG_USE;
8066
8067
	if (do_traditional)
8068
		flags_that_must_be_clear |= GAWKX;
8069
8070
	if (do_posix)
8071
		flags_that_must_be_clear |= NOT_POSIX;
8072
408.5.265 by Arnold D. Robbins
Add builtin functions to FUNCTAB and PROCINFO["identifiers"] and doc.
8073
8074
	j = sizeof(tokentab) / sizeof(tokentab[0]);
8075
	for (i = 0; i < j; i++) {
408.13.109 by Arnold D. Robbins
Don't install gawk extensions if --posix or --traditional.
8076
		if (   (tokentab[i].class == LEX_BUILTIN
8077
		        || tokentab[i].class == LEX_LENGTH)
8078
		    && (tokentab[i].flags & flags_that_must_be_clear) == 0) {
408.5.265 by Arnold D. Robbins
Add builtin functions to FUNCTAB and PROCINFO["identifiers"] and doc.
8079
			(void) install_symbol(tokentab[i].operator, Node_builtin_func);
8080
		}
8081
	}
8082
}
408.5.270 by Arnold D. Robbins
Force only ASCII letters to be allowed in identifiers.
8083
8084
/*
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
8085
 * 9/2014: Gawk cannot use <ctype.h> isalpha or isalnum when
8086
 * parsing the program since that can let through non-English
8087
 * letters.  So, we supply our own. !@#$%^&*()-ing locales!
408.5.270 by Arnold D. Robbins
Force only ASCII letters to be allowed in identifiers.
8088
 */
8089
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
8090
/* is_alpha --- return true if c is an English letter */
8091
408.5.276 by Arnold D. Robbins
More commentary on isalnum.
8092
/*
8093
 * The scene of the murder was grisly to look upon.  When the inspector
8094
 * arrived, the sergeant turned to him and said, "Another programmer stabbed
8095
 * in the back. He never knew what happened."
8096
 * 
8097
 * The inspector replied, "Looks like the MO of isalpha, and his even meaner
8098
 * big brother, isalnum. The Locale brothers."  The sergeant merely
8099
 * shuddered in horror.
8100
 */
8101
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
8102
bool
8103
is_alpha(int c)
408.5.270 by Arnold D. Robbins
Force only ASCII letters to be allowed in identifiers.
8104
{
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
8105
#ifdef I_DONT_KNOW_WHAT_IM_DOING
8106
	return isalpha(c);
8107
#else /* ! I_DONT_KNOW_WHAT_IM_DOING */
408.5.270 by Arnold D. Robbins
Force only ASCII letters to be allowed in identifiers.
8108
	switch (c) {
8109
	case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
8110
	case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
8111
	case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
8112
	case 's': case 't': case 'u': case 'v': case 'w': case 'x':
8113
	case 'y': case 'z':
8114
	case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
8115
	case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
8116
	case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
8117
	case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
8118
	case 'Y': case 'Z':
8119
		return true;
8120
	}
8121
	return false;
408.5.273 by Arnold D. Robbins
Finish excising isalpha and isalnum. Document.
8122
#endif /* ! I_DONT_KNOW_WHAT_IM_DOING */
8123
}
8124
8125
/* is_alnum --- return true for alphanumeric, English only letters */
8126
8127
bool
8128
is_alnum(int c)
8129
{
8130
	/* digit test is good for EBCDIC too. so there. */
8131
	return (is_alpha(c) || ('0' <= c && c <= '9'));
8132
}
8133
8134
8135
/* is_identchar --- return true if c can be in an identifier */
8136
8137
bool
8138
is_identchar(int c)
8139
{
8140
	return (is_alnum(c) || c == '_');
408.5.270 by Arnold D. Robbins
Force only ASCII letters to be allowed in identifiers.
8141
}