home *** CD-ROM | disk | FTP | other *** search
- /**
- * $Revision: 1.1 $
- * $Log: C:/AWK/AWK.C_V $
- *
- * Rev 1.1 09 Sep 1988 18:32:40 vince
- * MC 5.1 version
- *
- * Rev 1.0 09 Sep 1988 18:03:32 vince
- * Original source
- */
-
- #define NAME 258
- #define REGEXP 259
- #define YSTRING 260
- #define ERROR 261
- #define INCDEC 262
- #define NUMBER 263
- #define ASSIGNOP 264
- #define RELOP 265
- #define MATCHOP 266
- #define NEWLINE 267
- #define REDIRECT_OP 268
- #define CONCAT_OP 269
- #define LEX_BEGIN 270
- #define LEX_END 271
- #define LEX_IF 272
- #define LEX_ELSE 273
- #define LEX_WHILE 274
- #define LEX_FOR 275
- #define LEX_BREAK 276
- #define LEX_CONTINUE 277
- #define LEX_GETLINE 278
- #define LEX_PRINT 279
- #define LEX_PRINTF 280
- #define LEX_NEXT 281
- #define LEX_EXIT 282
- #define LEX_IN 283
- #define LEX_AND 284
- #define LEX_OR 285
- #define INCREMENT 286
- #define DECREMENT 287
- #define LEX_BUILTIN 288
- #define LEX_SUB 289
- #define UNARY 290
-
- #define YYDEBUG 12
-
- #include <stdio.h>
- #include <string.h>
- #include "awk.h"
-
- static int yylex();
-
- /**
- * The following variable is used for a very sickening thing.
- * The awk language uses white space as the string concatenation
- * operator, but having a white space token that would have to appear
- * everywhere in all the grammar rules would be unbearable.
- * It turns out we can return CONCAT_OP exactly when there really
- * is one, just from knowing what kinds of other tokens it can appear
- * between (namely, constants, variables, or close parentheses).
- * This is because concatenation has the lowest priority of all
- * operators. want_concat_token is used to remember that something
- * that could be the left side of a concat has just been returned.
- *
- * If anyone knows a cleaner way to do this (don't look at the Un*x
- * code to find one, though), please suggest it.
- */
- static int want_concat_token;
-
- /* Two more horrible kludges. The same comment applies to these two too */
- static int want_regexp; /* lexical scanning kludge */
- static int want_redirect; /* similarly */
- int lineno = 1; /* JF for error msgs */
-
- /*
- * Speaking of kludges. We don't want to treat arguments as filenames
- * if there are no pattern action pairs to perform; sooo I am creating
- * a counter for patterns and actions. -ADE
- */
- int patterns = 0;
- int actions = 0;
- /*
- * During parsing of a gawk program, the pointer to the next character is in this variable.
- */
- char *lexptr; /* JF moved it up here */
- char *lexptr_begin; /* JF for error msgs */
-
- typedef union
- {
- long lval;
- AWKNUM fval;
- NODE *nodeval;
- NODETYPE nodetypeval;
- char *sval;
- NODE *(*ptrval) ();
- } YYSTYPE;
-
- #ifndef YYLTYPE
- typedef struct yyltype
- {
- int timestamp;
- int first_line;
- int first_column;
- int last_line;
- int last_column;
- char *text;
- } yyltype;
-
- #define YYLTYPE yyltype
- #endif
-
- #define YYACCEPT return(0)
- #define YYABORT return(1)
- #define YYERROR return(1)
- #include <stdio.h>
-
- #define YYFINAL 204
- #define YYFLAG -32768
- #define YYNTBASE 54
-
- #define YYTRANSLATE(x) (yytranslate[x])
-
- static char yytranslate[] = {
- 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 43, 2, 2, 51, 40, 2, 2, 44,
- 45, 38, 36, 35, 37, 2, 39, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 53, 48, 2,
- 2, 2, 52, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 49, 2, 50, 41, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 46, 2, 47, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 1, 2, 3, 4, 5,
- 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
- 26, 27, 28, 29, 30, 31, 32, 33, 34, 42
- };
-
- static short yyrline[] = {
- 0, 118, 124, 126, 132, 142, 144, 150, 152, 157, 159,
- 162, 164, 166, 168, 173, 175, 177, 183, 185, 191,
- 193, 195, 197, 199, 204, 209, 211, 217, 219, 225,
- 228, 236, 238, 240, 242, 244, 246, 249, 251, 254,
- 257, 259, 261, 263, 269, 271, 277, 279, 285, 288,
- 297, 298, 303, 305, 310, 312, 320, 322, 329, 331,
- 336, 338, 343, 345, 347, 349, 351, 353, 356, 358,
- 363, 367, 370, 372, 374, 379, 381, 387, 389, 391,
- 393, 395, 400, 402, 404, 406, 408, 413, 415, 417,
- 422, 424, 426, 431, 433, 438, 440, 445, 447, 452,
- 454, 459, 464, 466, 467, 468, 469
- };
-
- static char *yytname[] = {
- 0, "error", "$illegal.", "NAME", "REGEXP", "YSTRING", "ERROR", "INCDEC", "NUMBER", "ASSIGNOP", "RELOP",
- "MATCHOP", "NEWLINE", "REDIRECT_OP", "CONCAT_OP", "LEX_BEGIN", "LEX_END", "LEX_IF", "LEX_ELSE", "LEX_WHILE", "LEX_FOR",
- "LEX_BREAK", "LEX_CONTINUE", "LEX_GETLINE", "LEX_PRINT", "LEX_PRINTF", "LEX_NEXT", "LEX_EXIT", "LEX_IN", "LEX_AND", "LEX_OR",
- "INCREMENT", "DECREMENT", "LEX_BUILTIN", "LEX_SUB", "','", "'+'", "'-'", "'*'", "'/'", "'%'",
- "'^'", "UNARY", "'!'", "'('", "')'", "'{'", "'}'", "';'", "'['", "']'",
- "'$'", "'?'", "':'", "start"
- };
-
- static short yyr1[] = {
- 0, 54, 55, 55, 56, 57, 57, 57, 57, 58, 58,
- 58, 58, 58, 58, 58, 58, 58, 59, 59, 60,
- 60, 60, 60, 60, 61, 62, 62, 63, 63, 64,
- 64, 66, 65, 67, 65, 68, 65, 69, 65, 65,
- 65, 65, 65, 65, 71, 70, 72, 70, 73, 70,
- 74, 74, 75, 75, 77, 76, 78, 78, 79, 79,
- 80, 80, 81, 81, 81, 81, 81, 81, 82, 81,
- 81, 83, 83, 83, 83, 84, 84, 85, 85, 85,
- 85, 85, 86, 86, 86, 86, 86, 87, 87, 87,
- 88, 88, 88, 89, 89, 90, 90, 91, 91, 92,
- 92, 93, 94, 94, 94, 94, 94
- };
-
- static short yyr2[] = {
- 0, 2, 1, 2, 4, 0, 1, 1, 1, 1, 1,
- 2, 3, 3, 3, 3, 3, 3, 0, 1, 2,
- 1, 1, 1, 1, 4, 1, 2, 2, 2, 6,
- 9, 0, 7, 0, 11, 0, 10, 0, 10, 2,
- 2, 2, 2, 5, 0, 5, 0, 5, 0, 7,
- 0, 2, 2, 2, 0, 4, 0, 2, 0, 1,
- 0, 1, 1, 1, 1, 4, 1, 6, 0, 4,
- 3, 1, 4, 2, 2, 1, 4, 1, 2, 2,
- 2, 2, 1, 3, 3, 3, 3, 1, 3, 3,
- 1, 3, 3, 1, 3, 1, 3, 1, 5, 1,
- 3, 1, 0, 1, 1, 2, 2
- };
-
- static short yydefact[] = {
- 51, 5, 63, 65, 64, 52, 6, 7, 69, 0, 0,
- 67, 0, 0, 55, 5, 5, 0, 5, 2, 9,
- 18, 10, 72, 78, 83, 88, 91, 94, 96, 98,
- 100, 102, 8, 0, 59, 0, 79, 80, 61, 0,
- 81, 0, 11, 0, 8, 82, 3, 5, 5, 5,
- 5, 51, 0, 19, 74, 75, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 57,
- 60, 0, 0, 62, 76, 0, 0, 14, 71, 12,
- 13, 16, 15, 17, 0, 51, 86, 87, 85, 84,
- 89, 90, 93, 92, 101, 95, 94, 97, 0, 73,
- 0, 70, 66, 51, 0, 56, 0, 0, 0, 0,
- 0, 45, 47, 0, 0, 51, 26, 51, 0, 21,
- 22, 23, 24, 0, 4, 0, 58, 0, 0, 0,
- 0, 59, 51, 51, 40, 41, 61, 0, 61, 42,
- 0, 43, 28, 20, 25, 27, 29, 99, 77, 68,
- 0, 0, 63, 0, 53, 54, 57, 0, 57, 0,
- 51, 32, 0, 0, 0, 49, 0, 0, 0, 51,
- 0, 59, 0, 46, 57, 48, 44, 30, 0, 0,
- 0, 59, 0, 51, 33, 38, 36, 0, 50, 0,
- 51, 51, 34, 31, 0, 0, 51, 39, 37, 0,
- 35, 0, 0, 0
- };
-
- static short yydefgoto[] = {
- 202, 18, 19, 20, 21, 53, 117, 118, 119, 120, 121,
- 122, 170, 197, 192, 191, 123, 137, 139, 175, 1,
- 135, 22, 42, 102, 70, 73, 23, 35, 24, 74,
- 25, 26, 27, 28, 29, 30, 31, 32, 124, -1
- };
-
- static short yypact[] = {
- -32768, 250, -33, -32768, -32768, -32768, -32768, -32768, -32768, 409, 409,
- -31, -25, 409, -32768, 349, 283, 409, 143, -32768, 68,
- 41, -32768, -32768, 75, 55, 73, 18, 29, 1, 7,
- -32768, -32768, -32768, 409, 409, 409, -32768, -32768, 409, -2,
- -32768, 63, -32768, 44, 45, -32768, -32768, 283, 283, 316,
- 283, -32768, 62, -32768, -32768, -32768, 409, 409, 409, 409,
- 409, 409, 409, 409, 409, 409, 409, 409, 49, 104,
- -32768, 45, 76, 87, -32768, 88, 85, -32768, -32768, 114,
- 114, -32768, -32768, 114, 180, -32768, -32768, -32768, -32768, -32768,
- -32768, -32768, -32768, -32768, -32768, -32768, 97, -32768, 74, -32768,
- 409, -32768, -32768, -32768, 409, -32768, 84, 89, 91, -8,
- -8, -32768, 92, -8, -5, -32768, -32768, -32768, 213, -32768,
- -32768, -32768, -32768, -8, 120, 409, -32768, 365, -15, 409,
- 409, 425, -32768, -32768, -32768, -32768, 409, 409, 409, -32768,
- 409, -32768, 120, 120, -32768, -32768, -32768, -32768, -32768, -32768,
- 93, 94, -4, 96, 120, 120, 104, 25, 104, 100,
- -32768, -32768, 109, 387, -8, -32768, -8, -8, 180, -32768,
- 146, 409, 102, -32768, 104, -32768, -32768, 134, 180, 108,
- 110, 409, -8, -32768, -32768, -32768, -32768, 111, -32768, 180,
- -32768, -32768, -32768, -32768, 180, 180, -32768, -32768, -32768, 180,
- -32768, 154, 157, -32768
- };
-
- static short yypgoto[] = {
- -32768, -32768, 142, 3, -7, -32768, -118, 140, -32768, -32768, -32768,
- -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768, -50,
- -103, 31, -32768, -84, -126, -51, -32768, -32768, -32768, -81,
- 95, 56, 57, -41, 98, -63, -32768, -36, -1, -32768
- };
-
- #define YYLAST 476
-
- static short yytable[] = {
- 33, 146, 85, 75, 133, 99, 154, 133, 136, 44, 163,
- 140, 142, 39, 33, 45, 34, 33, 43, 40, 104,
- 147, 93, 94, 129, 96, 97, 97, 63, 95, 150,
- 67, 64, 69, 71, 72, 125, 14, 65, 141, 134,
- 80, 81, 134, 84, 34, 181, 33, 33, 33, 33,
- 178, 50, 82, 128, 50, 188, 158, 66, 68, 104,
- 185, 174, 148, 176, 177, 143, 77, 144, 75, 166,
- 76, 194, 165, 86, 167, 51, 198, 199, 51, 189,
- 83, 201, 155, 156, 97, 157, 52, 159, 78, 79,
- 183, 149, 57, 58, 59, 60, 48, 49, 100, 127,
- 75, 75, 75, 37, 38, 55, 56, 41, 61, 62,
- 169, 46, 87, 88, 89, 90, 101, 91, 92, 179,
- 103, 104, 105, 106, 50, 66, 126, 130, 151, 152,
- 71, 5, 131, 190, 132, 138, 171, 161, 162, 160,
- 195, 196, -1, 164, 168, 2, 200, 3, 180, 182,
- 4, 184, 186, 203, 187, 193, 204, 6, 7, 47,
- 54, 0, 173, 0, 98, 8, 0, 0, 0, 0,
- 71, 0, 0, 9, 10, 11, 12, 0, 0, 13,
- 71, 14, 2, 0, 3, 15, 16, 4, 0, 0,
- 0, 5, 0, 17, 0, 0, 107, 0, 108, 109,
- 110, 111, 8, 112, 113, 114, 115, 0, 0, 0,
- 9, 10, 11, 12, 0, 2, 13, 3, 0, 0,
- 4, 0, 0, 36, 0, 52, 0, 116, 0, 107,
- 17, 108, 109, 110, 111, 8, 112, 113, 114, 115,
- 0, 0, 0, 9, 10, 11, 12, 0, 0, 13,
- 0, 0, 2, 0, 3, 0, 36, 4, 52, 145,
- 116, 5, 0, 17, 6, 7, 0, 0, 0, 0,
- 0, 0, 8, 0, 0, 0, 0, 0, 0, 0,
- 9, 10, 11, 12, 0, 2, 13, 3, 14, 0,
- 4, 0, 15, 16, 0, 0, 0, 6, 7, 0,
- 17, 0, 0, 0, 0, 8, 0, 0, 0, 0,
- 0, 0, 0, 9, 10, 11, 12, 0, 2, 13,
- 3, 14, 0, 4, 0, 15, 16, 0, 0, 0,
- 6, 7, 0, 17, 0, 0, 0, 0, 8, 0,
- 0, 0, 0, 0, 0, 0, 9, 10, 11, 12,
- 0, 2, 13, 3, 14, 0, 4, 0, 0, 36,
- 0, 0, 0, 6, 7, 0, 17, 2, 0, 3,
- 0, 8, 4, 0, 0, 0, 5, 0, 0, 9,
- 10, 11, 12, 0, 0, 13, 0, 8, 0, 2,
- 0, 3, 36, 0, 4, 9, 10, 11, 12, 17,
- 0, 13, 0, 0, 0, 0, 0, 0, 36, 8,
- 0, 2, 0, 3, 0, 17, 4, 9, 10, 11,
- 12, 0, 0, 13, 0, 0, 0, 153, 0, 3,
- 36, 8, 4, 0, 172, 0, 0, 17, 0, 9,
- 10, 11, 12, 0, 0, 13, 0, 8, 0, 0,
- 0, 0, 36, 0, 0, 9, 10, 11, 12, 17,
- 0, 13, 0, 0, 0, 0, 0, 0, 36, 0,
- 0, 0, 0, 0, 0, 17
- };
-
- static short yycheck[] = {
- 1, 119, 52, 39, 12, 68, 132, 12, 111, 16, 14,
- 114, 115, 44, 15, 16, 49, 18, 15, 44, 35,
- 124, 63, 64, 105, 66, 67, 68, 10, 65, 45,
- 30, 14, 34, 35, 36, 86, 39, 9, 44, 48,
- 48, 49, 48, 51, 49, 172, 48, 49, 50, 51,
- 169, 11, 50, 104, 11, 182, 138, 29, 52, 35,
- 179, 165, 126, 167, 168, 116, 4, 118, 105, 45,
- 40, 190, 157, 12, 159, 35, 195, 196, 35, 183,
- 50, 200, 133, 134, 126, 137, 46, 139, 45, 45,
- 175, 128, 38, 39, 40, 41, 29, 30, 50, 101,
- 137, 138, 139, 9, 10, 31, 32, 13, 36, 37,
- 161, 17, 57, 58, 59, 60, 13, 61, 62, 170,
- 45, 35, 35, 39, 11, 29, 53, 44, 130, 131,
- 132, 12, 44, 184, 44, 44, 28, 45, 45, 141,
- 191, 192, 0, 48, 45, 3, 197, 5, 3, 48,
- 8, 18, 45, 0, 45, 45, 0, 15, 16, 18,
- 21, -1, 164, -1, 67, 23, -1, -1, -1, -1,
- 172, -1, -1, 31, 32, 33, 34, -1, -1, 37,
- 182, 39, 3, -1, 5, 43, 44, 8, -1, -1,
- -1, 12, -1, 51, -1, -1, 17, -1, 19, 20,
- 21, 22, 23, 24, 25, 26, 27, -1, -1, -1,
- 31, 32, 33, 34, -1, 3, 37, 5, -1, -1,
- 8, -1, -1, 44, -1, 46, -1, 48, -1, 17,
- 51, 19, 20, 21, 22, 23, 24, 25, 26, 27,
- -1, -1, -1, 31, 32, 33, 34, -1, -1, 37,
- -1, -1, 3, -1, 5, -1, 44, 8, 46, 47,
- 48, 12, -1, 51, 15, 16, -1, -1, -1, -1,
- -1, -1, 23, -1, -1, -1, -1, -1, -1, -1,
- 31, 32, 33, 34, -1, 3, 37, 5, 39, -1,
- 8, -1, 43, 44, -1, -1, -1, 15, 16, -1,
- 51, -1, -1, -1, -1, 23, -1, -1, -1, -1,
- -1, -1, -1, 31, 32, 33, 34, -1, 3, 37,
- 5, 39, -1, 8, -1, 43, 44, -1, -1, -1,
- 15, 16, -1, 51, -1, -1, -1, -1, 23, -1,
- -1, -1, -1, -1, -1, -1, 31, 32, 33, 34,
- -1, 3, 37, 5, 39, -1, 8, -1, -1, 44,
- -1, -1, -1, 15, 16, -1, 51, 3, -1, 5,
- -1, 23, 8, -1, -1, -1, 12, -1, -1, 31,
- 32, 33, 34, -1, -1, 37, -1, 23, -1, 3,
- -1, 5, 44, -1, 8, 31, 32, 33, 34, 51,
- -1, 37, -1, -1, -1, -1, -1, -1, 44, 23,
- -1, 3, -1, 5, -1, 51, 8, 31, 32, 33,
- 34, -1, -1, 37, -1, -1, -1, 3, -1, 5,
- 44, 23, 8, -1, 48, -1, -1, 51, -1, 31,
- 32, 33, 34, -1, -1, 37, -1, 23, -1, -1,
- -1, -1, 44, -1, -1, 31, 32, 33, 34, 51,
- -1, 37, -1, -1, -1, -1, -1, -1, 44, -1,
- -1, -1, -1, -1, -1, 51
- };
- #define YYPURE 1
-
- /*
- * Skeleton output parser for bison,
- * copyright (C) 1984 Bob Corbett and Richard Stallman
- *
- * Permission is granted to anyone to make or distribute verbatim copies of this
- * program provided that the copyright notice and this permission notice are
- * preserved; and provided that the recipient is not asked to waive or limit his
- * right to redistribute copies as permitted by this permission notice; and
- * provided that anyone possessing an executable copy is granted access to copy the
- * source code, in machine-readable form, in some reasonable manner.
- *
- * Permission is granted to distribute derived works or enhanced versions of this
- * program under the above conditions with the additional condition that the
- * entire derivative or enhanced work must be covered by a permission notice
- * identical to this one.
- *
- * Anything distributed as part of a package containing portions derived from
- * this program, which cannot in current practice perform its function
- * usefully in the absense of what was derived directly from this program, is
- * to be considered as forming, together with the latter, a single work
- * derived from this program, which must be entirely covered by a permission
- * notice identical to this one in order for distribution of the package to be
- * permitted.
- *
- * In other words, you are welcome to use, share and improve this program.
- * You are forbidden to forbid anyone else to use, share and improve what you
- * give them. Help stamp out software-hoarding!
- */
-
- /*
- * This is the parser code that is written into each bison parser when the
- * %semantic_parser declaration is not specified in the grammar. It was
- * written by Richard Stallman by simplifying the hairy parser used when
- * %semantic_parser is specified.
- */
-
- /*
- * Note: there must be only one dollar sign in this file. It is replaced by
- * the list of actions, each action as one case of the switch.
- */
-
- #include <malloc.h>
- #include <string.h>
-
- #define yyerrok (yyerrstatus = 0)
- #define yyclearin (yychar = YYEMPTY)
- #define YYEMPTY -2
- #define YYEOF 0
- #define YYFAIL goto yyerrlab;
-
- #define YYTERROR 1
-
- #ifndef YYIMPURE
- #define YYLEX yylex()
- int yylex(void); /* WG */
- #endif
-
- #ifndef YYPURE
- #define YYLEX yylex(&yylval, &yylloc)
- int yylex(int, int); /* WG */
- #endif
-
- /* If nonreentrant, generate the variables here */
-
- #ifndef YYIMPURE
-
- int yychar; /* the lookahead symbol */
- YYSTYPE yylval; /* the semantic value of the */
- /* lookahead symbol */
-
- YYLTYPE yylloc; /* location data for the lookahead */
- /* symbol */
-
- int yydebug = 0; /* nonzero means print parse trace */
-
- #endif
-
-
- /* YYMAXDEPTH indicates the initial size of the parser's stacks */
-
- #ifndef YYMAXDEPTH
- #define YYMAXDEPTH 200
- #endif
-
- /*
- * YYMAXLIMIT is the maximum size the stacks can grow to (effective only if the built-in stack extension method is used).
- */
-
- #ifndef YYMAXLIMIT
- #define YYMAXLIMIT 10000
- #endif
-
-
- int yyparse()
- {
- register int yystate;
- register int yyn;
- register short *yyssp;
- register YYSTYPE *yyvsp;
- void yyerror(char *,...); /* WG [ ',...' - added ADE ] */
- YYLTYPE *yylsp;
- int yyerrstatus; /* number of tokens to shift before error messages enabled */
- int yychar1; /* lookahead token as an internal (translated) token number */
-
- short yyssa[YYMAXDEPTH]; /* the state stack */
- YYSTYPE yyvsa[YYMAXDEPTH]; /* the semantic value stack */
- YYLTYPE yylsa[YYMAXDEPTH]; /* the location stack */
-
- short *yyss = yyssa; /* refer to the stacks thru separate pointers */
- YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
- YYLTYPE *yyls = yylsa;
-
- int yymaxdepth = YYMAXDEPTH;
-
- #ifndef YYPURE
-
- int yychar;
- YYSTYPE yylval;
- YYLTYPE yylloc;
-
- extern int yydebug;
-
- #endif
-
-
- YYSTYPE yyval; /* the variable used to return */
- /* semantic values from the action */
- /* routines */
- int yylen;
-
- if (yydebug)
- fprintf(stderr, "Starting parse\n");
-
- yystate = 0;
- yyerrstatus = 0;
- yychar = YYEMPTY; /* Cause a token to be read. */
-
- /*
- * Initialize stack pointers. Waste one element of value and location
- * stack so that they stay on the same level as the state stack.
- */
-
- yyssp = yyss - 1;
- yyvsp = yyvs;
- yylsp = yyls;
-
- /* Push a new state, which is found in yystate
- *
- * In all cases, when you get here, the value and location stacks have
- * just been pushed. so pushing a state here evens the stacks.
- */
- yynewstate:
-
- *++yyssp = yystate;
-
- if (yyssp >= yyss + yymaxdepth - 1)
- {
- /* Give user a chance to reallocate the stack */
- /* Use copies of these so that the &'s don't force the real ones into memory. */
- YYSTYPE *yyvs1 = yyvs;
- YYLTYPE *yyls1 = yyls;
- short *yyss1 = yyss;
-
- /* Get the current used size of the three stacks, in elements. */
- int size = yyssp - yyss + 1;
-
- #ifdef yyoverflow
- /*
- * Each stack pointer address is followed by the size of the data in use in that stack, in bytes.
- */
- yyoverflow("parser stack overflow", &yyss1, size * sizeof(*yyssp),
- &yyvs1, size * sizeof(*yyvsp), &yyls1, size * sizeof(*yylsp),
- &yymaxdepth);
-
- yyss = yyss1;
- yyvs = yyvs1;
- yyls = yyls1;
- #else
- /* Extend the stack our own way. */
- if (yymaxdepth >= YYMAXLIMIT)
- yyerror("parser stack overflow");
- yymaxdepth *= 2;
- if (yymaxdepth > YYMAXLIMIT)
- yymaxdepth = YYMAXLIMIT;
- yyss = (short *) alloca(yymaxdepth * sizeof(*yyssp));
- memcpy((char *) yyss, (char *) yyss1, size * sizeof(*yyssp)); /* WG */
- yyls = (YYLTYPE *) alloca(yymaxdepth * sizeof(*yylsp));
- memcpy((char *) yyls, (char *) yyls1, size * sizeof(*yylsp)); /* WG */
- yyvs = (YYSTYPE *) alloca(yymaxdepth * sizeof(*yyvsp));
- memcpy((char *) yyvs, (char *) yyvs1, size * sizeof(*yyvsp)); /* WG */
- #endif
-
- yyssp = yyss + size - 1;
- yylsp = yyls + size - 1;
- yyvsp = yyvs + size - 1;
-
- if (yydebug)
- fprintf(stderr, "Stack size increased to %d\n", yymaxdepth);
-
- if (yyssp >= yyss + yymaxdepth - 1)
- YYERROR;
- }
-
- if (yydebug)
- fprintf(stderr, "Entering state %d\n", yystate);
-
- /* Do appropriate processing given the current state. */
- /* Read a lookahead token if we need one and don't already have one. */
- yyresume:
-
- /* First try to decide what to do without reference to lookahead token. */
-
- yyn = (int) yypact[yystate]; /* WG */
- if (yyn == YYFLAG)
- goto yydefault;
-
- /* Not known => get a lookahead token if don't already have one. */
-
- /*
- * yychar is either YYEMPTY or YYEOF or a valid token in external form.
- */
-
- if (yychar == YYEMPTY)
- {
- yychar = YYLEX;
- }
-
- /* Convert token to internal form (in yychar1) for indexing tables with */
-
- if (yychar <= 0) /* This means end of input. */
- {
- yychar1 = 0;
- yychar = YYEOF; /* Don't call YYLEX any more */
-
- if (yydebug)
- fprintf(stderr, "Now at end of input.\n");
- }
- else
- {
- yychar1 = YYTRANSLATE(yychar);
-
- if (yydebug)
- fprintf(stderr, "Parsing next token; it is %d (%s)\n", yychar, yytname[yychar1]);
- }
-
- yyn += yychar1;
- if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
- goto yydefault;
-
- yyn = yytable[yyn];
-
- /*
- * yyn is what to do for this token type in this state.
- * Negative => reduce, -yyn is rule number.
- * Positive => shift, yyn is new state. New state is final state
- * don't bother to shift, just return success.
- * 0, or most negative number => error.
- */
-
- if (yyn < 0)
- {
- if (yyn == (int) YYFLAG) /* WG */
- goto yyerrlab;
- yyn = -yyn;
- goto yyreduce;
- }
- else if (yyn == 0)
- goto yyerrlab;
-
- if (yyn == YYFINAL)
- YYACCEPT;
-
- /* Shift the lookahead token. */
-
- if (yydebug)
- fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
-
- /* Discard the token being shifted unless it is eof. */
- if (yychar != YYEOF)
- yychar = YYEMPTY;
-
- *++yyvsp = yylval;
- *++yylsp = yylloc;
-
- /* count tokens shifted since error; after three, turn off error status. */
- if (yyerrstatus)
- yyerrstatus--;
-
- yystate = yyn;
- goto yynewstate;
-
- /* Do the default action for the current state. */
- yydefault:
-
- yyn = yydefact[yystate];
- if (yyn == 0)
- goto yyerrlab;
-
- /* Do a reduction. yyn is the number of a rule to reduce with. */
- yyreduce:
- yylen = yyr2[yyn];
- yyval = yyvsp[1 - yylen]; /* implement default value of the action */
-
- if (yydebug)
- {
- if (yylen == 1)
- fprintf(stderr, "Reducing 1 value via line %d, ", yyrline[yyn]);
- else
- fprintf(stderr, "Reducing %d values via line %d, ", yylen, yyrline[yyn]);
- }
- /* the action file follows */
-
- switch (yyn)
- {
- case 1:
- {
- expression_value = yyvsp[0].nodeval;
- break;
- }
- case 2:
- {
- yyval.nodeval = node(yyvsp[0].nodeval, Node_rule_list, (NODE *) NULL);
- break;
- }
- case 3:
- {
- yyval.nodeval = append_right(yyvsp[-1].nodeval, node(yyvsp[0].nodeval, Node_rule_list, (NODE *) NULL));
- break;
- }
- case 4:
- {
- ++patterns;
- ++actions;
- yyval.nodeval = node(yyvsp[-3].nodeval, Node_rule_node, yyvsp[-2].nodeval);
- break;
- }
- case 5:
- {
- yyval.nodeval = NULL;
- break;
- }
- case 6:
- {
- --patterns;
- --actions;
- yyval.nodeval = node((NODE *) NULL, Node_K_BEGIN, (NODE *) NULL);
- break;
- }
- case 7:
- {
- yyval.nodeval = node((NODE *) NULL, Node_K_END, (NODE *) NULL);
- break;
- }
- case 8:
- {
- yyval.nodeval = yyvsp[0].nodeval;
- break;
- }
- case 9:
- {
- yyval.nodeval = yyvsp[0].nodeval;
- break;
- }
- case 10:
- {
- yyval.nodeval = node(node(make_number((AWKNUM) 0), Node_field_spec, (NODE *) NULL), Node_match, yyvsp[0].nodeval);
- break;
- }
- case 11:
- {
- yyval.nodeval = node(yyvsp[0].nodeval, Node_not, (NODE *) NULL);
- break;
- }
- case 12:
- {
- yyval.nodeval = node(yyvsp[-2].nodeval, Node_and, yyvsp[0].nodeval);
- break;
- }
- case 13:
- {
- yyval.nodeval = node(yyvsp[-2].nodeval, Node_or, yyvsp[0].nodeval);
- break;
- }
- case 14:
- {
- yyval.nodeval = yyvsp[-1].nodeval;
- want_concat_token = 0;
- break;
- }
- case 15:
- {
- yyval.nodeval = node(yyvsp[-2].nodeval, Node_match, yyvsp[0].nodeval);
- break;
- }
- case 16:
- {
- yyval.nodeval = node(yyvsp[-2].nodeval, Node_match, yyvsp[0].nodeval);
- break;
- }
- case 17:
- {
- yyval.nodeval = mkrangenode(node(yyvsp[-2].nodeval, Node_cond_pair, yyvsp[0].nodeval));
- break;
- }
- case 18:
- {
- --actions;
- yyval.nodeval = NULL;
- break;
- }
- case 19:
- {
- yyval.nodeval = yyvsp[0].nodeval;
- break;
- }
- case 20:
- {
- yyval.nodeval = yyvsp[-1].nodeval;
- break;
- }
- case 21:
- {
- yyval.nodeval = yyvsp[0].nodeval;
- break;
- }
- case 22:
- {
- yyval.nodeval = yyvsp[0].nodeval;
- break;
- }
- case 23:
- {
- yyval.nodeval = yyvsp[0].nodeval;
- break;
- }
- case 24:
- {
- yyval.nodeval = yyvsp[0].nodeval;
- break;
- }
- case 25:
- {
- yyval.nodeval = node(yyvsp[-1].nodeval, Node_statement_list, (NODE *) NULL);
- break;
- }
- case 26:
- {
- yyval.nodeval = node(yyvsp[0].nodeval, Node_statement_list, (NODE *) NULL);
- break;
- }
- case 27:
- {
- yyval.nodeval = append_right(yyvsp[-1].nodeval, node(yyvsp[0].nodeval, Node_statement_list, (NODE *) NULL));
- break;
- }
- case 28:
- {
- yyval.nodeval = (NODE *) NULL;
- break;
- }
- case 29:
- {
- yyval.nodeval = node(yyvsp[-1].nodeval, Node_statement_list, (NODE *) NULL);
- break;
- }
- case 30:
- {
- yyval.nodeval = node(yyvsp[-3].nodeval, Node_K_if, node(yyvsp[0].nodeval, Node_if_branches, (NODE *) NULL));
- break;
- }
- case 31:
- {
- yyval.nodeval = node(yyvsp[-6].nodeval, Node_K_if, node(yyvsp[-3].nodeval, Node_if_branches, yyvsp[0].nodeval));
- break;
- }
- case 32:
- {
- want_concat_token = 0;
- break;
- }
- case 33:
- {
- yyval.nodeval = node(yyvsp[-4].nodeval, Node_K_while, yyvsp[0].nodeval);
- break;
- }
- case 34:
- {
- want_concat_token = 0;
- break;
- }
- case 35:
- {
- yyval.nodeval = node(yyvsp[0].nodeval, Node_K_for, (NODE *) make_for_loop(yyvsp[-8].nodeval, yyvsp[-6].nodeval, yyvsp[-4].nodeval));
- break;
- }
- case 36:
- {
- want_concat_token = 0;
- break;
- }
- case 37:
- {
- yyval.nodeval = node(yyvsp[0].nodeval, Node_K_for,
- (NODE *) make_for_loop(yyvsp[-7].nodeval, (NODE *) NULL, yyvsp[-4].nodeval));
- break;
- }
- case 38:
- {
- want_concat_token = 0;
- break;
- }
- case 39:
- {
- yyval.nodeval = node(yyvsp[0].nodeval, Node_K_arrayfor,
- (NODE *) make_for_loop(variable(yyvsp[-7].sval), (NODE *) NULL, variable(yyvsp[-4].sval)));
- break;
- }
- case 40:
- {
- yyval.nodeval = node((NODE *) NULL, Node_K_break, (NODE *) NULL);
- break;
- }
- case 41:
- {
- yyval.nodeval = node((NODE *) NULL, Node_K_continue, (NODE *) NULL);
- break;
- }
- case 42:
- {
- yyval.nodeval = node((NODE *) NULL, Node_K_next, (NODE *) NULL);
- break;
- }
- case 43:
- {
- yyval.nodeval = node((NODE *) NULL, Node_K_exit, (NODE *) NULL);
- break;
- }
- case 44:
- {
- yyval.nodeval = node(yyvsp[-2].nodeval, Node_K_exit, (NODE *) NULL);
- break;
- }
- case 45:
- {
- ++want_redirect;
- want_concat_token = 0;
- break;
- }
- case 46:
- {
- want_redirect = 0;
- /* $4->lnode = NULL; */
- yyval.nodeval = node(yyvsp[-2].nodeval, Node_K_print, yyvsp[-1].nodeval);
- break;
- }
- case 47:
- {
- ++want_redirect;
- want_concat_token = 0;
- break;
- }
- case 48:
- {
- want_redirect = 0;
- /* $4->lnode = NULL; */
- yyval.nodeval = node(yyvsp[-2].nodeval, Node_K_printf, yyvsp[-1].nodeval);
- break;
- }
- case 49:
- {
- ++want_redirect;
- want_concat_token = 0;
- break;
- }
- case 50:
- {
- want_redirect = 0;
- yyval.nodeval = node(yyvsp[-4].nodeval, Node_K_printf, yyvsp[-1].nodeval);
- break;
- }
- case 52:
- {
- yyval.nodetypeval = Node_illegal;
- break;
- }
- case 53:
- {
- yyval.nodetypeval = Node_illegal;
- break;
- }
- case 54:
- {
- yyval.nodetypeval = Node_illegal;
- break;
- }
- case 55:
- {
- ++want_regexp;
- break;
- }
- case 56:
- {
- want_regexp = 0;
- yyval.nodeval = make_regex(yyvsp[-1].sval);
- break;
- }
- case 57:
- {
- yyval.nodeval = NULL; /* node (NULL, Node_redirect_nil, NULL); */ ;
- break;
- }
- case 58:
- {
- yyval.nodeval = node(yyvsp[0].nodeval, yyvsp[-1].nodetypeval, (NODE *) NULL);
- break;
- }
- case 59:
- {
- yyval.nodeval = NULL; /* node(NULL, Node_builtin, NULL); */ ;
- break;
- }
- case 60:
- {
- yyval.nodeval = yyvsp[0].nodeval;
- break;
- }
- case 61:
- {
- yyval.nodeval = NULL;
- break;
- }
- case 62:
- {
- yyval.nodeval = yyvsp[0].nodeval;
- break;
- }
- case 63:
- {
- yyval.nodeval = variable(yyvsp[0].sval);
- break;
- }
- case 64:
- {
- yyval.nodeval = make_number(yyvsp[0].fval);
- break;
- }
- case 65:
- {
- yyval.nodeval = make_string(yyvsp[0].sval, -1);
- break;
- }
- case 66:
- {
- ++want_concat_token;
- yyval.nodeval = snode(yyvsp[-1].nodeval, Node_builtin, yyvsp[-3].ptrval);
- break;
- }
- case 67:
- {
- ++want_concat_token;
- yyval.nodeval = snode((NODE *) NULL, Node_builtin, yyvsp[0].ptrval);
- break;
- }
- case 68:
- {
- want_concat_token;
- yyval.nodeval = snode(node(yyvsp[-3].nodeval, Node_expression_list, yyvsp[-1].nodeval), Node_builtin, yyvsp[-5].ptrval);
- break;
- }
- case 69:
- {
- ++want_redirect;
- break;
- }
- case 70:
- {
- want_redirect = 0;
- yyval.nodeval = node(yyvsp[-1].nodeval, Node_K_getline, yyvsp[0].nodeval);
- break;
- }
- case 71:
- {
- yyval.nodeval = yyvsp[-1].nodeval;
- break;
- }
- case 72:
- {
- yyval.nodeval = yyvsp[0].nodeval;
- break;
- }
- case 73:
- {
- yyval.nodeval = node(variable(yyvsp[-3].sval), Node_subscript, yyvsp[-1].nodeval);
- break;
- }
- case 74:
- {
- yyval.nodeval = node(yyvsp[-1].nodeval, Node_postincrement, (NODE *) NULL);
- break;
- }
- case 75:
- {
- yyval.nodeval = node(yyvsp[-1].nodeval, Node_postdecrement, (NODE *) NULL);
- break;
- }
- case 76:
- {
- yyval.nodeval = node(yyvsp[0].nodeval, Node_expression_list, (NODE *) NULL);
- break;
- }
- case 77:
- {
- yyval.nodeval = append_right(yyvsp[-3].nodeval,
- node(yyvsp[0].nodeval, Node_expression_list, (NODE *) NULL));
- break;
- }
- case 78:
- {
- yyval.nodeval = yyvsp[0].nodeval;
- break;
- }
- case 79:
- {
- yyval.nodeval = node(yyvsp[0].nodeval, Node_preincrement, (NODE *) NULL);
- break;
- }
- case 80:
- {
- yyval.nodeval = node(yyvsp[0].nodeval, Node_predecrement, (NODE *) NULL);
- break;
- }
- case 81:
- {
- yyval.nodeval = node(yyvsp[0].nodeval, Node_unary_minus, (NODE *) NULL);
- break;
- }
- case 82:
- {
- yyval.nodeval = node(yyvsp[0].nodeval, Node_field_spec, (NODE *) NULL);
- break;
- }
- case 83:
- {
- yyval.nodeval = yyvsp[0].nodeval;
- break;
- }
- case 84:
- {
- yyval.nodeval = node(yyvsp[-2].nodeval, Node_pow, yyvsp[0].nodeval);
- break;
- }
- case 85:
- {
- yyval.nodeval = node(yyvsp[-2].nodeval, Node_mod, yyvsp[0].nodeval);
- break;
- }
- case 86:
- {
- yyval.nodeval = node(yyvsp[-2].nodeval, Node_times, yyvsp[0].nodeval);
- break;
- }
- case 87:
- {
- yyval.nodeval = node(yyvsp[-2].nodeval, Node_quotient, yyvsp[0].nodeval);
- break;
- }
- case 88:
- {
- yyval.nodeval = yyvsp[0].nodeval;
- break;
- }
- case 89:
- {
- yyval.nodeval = node(yyvsp[-2].nodeval, Node_plus, yyvsp[0].nodeval);
- break;
- }
- case 90:
- {
- yyval.nodeval = node(yyvsp[-2].nodeval, Node_minus, yyvsp[0].nodeval);
- break;
- }
- case 91:
- {
- yyval.nodeval = yyvsp[0].nodeval;
- break;
- }
- case 92:
- {
- yyval.nodeval = node(yyvsp[-2].nodeval, Node_concat, yyvsp[0].nodeval);
- break;
- }
- case 93:
- {
- yyval.nodeval = node(yyvsp[-2].nodeval, yyvsp[-1].nodetypeval, yyvsp[0].nodeval);
- break;
- }
- case 94:
- {
- yyval.nodeval = yyvsp[0].nodeval;
- break;
- }
- case 95:
- {
- yyval.nodeval = node(yyvsp[-2].nodeval, Node_and, yyvsp[0].nodeval);
- break;
- }
- case 96:
- {
- yyval.nodeval = yyvsp[0].nodeval;
- break;
- }
- case 97:
- {
- yyval.nodeval = node(yyvsp[-2].nodeval, Node_or, yyvsp[0].nodeval);
- break;
- }
- case 98:
- {
- yyval.nodeval = yyvsp[0].nodeval;
- break;
- }
- case 99:
- {
- yyval.nodeval = node(yyvsp[-4].nodeval, Node_cond_exp, node(yyvsp[-2].nodeval, Node_illegal, yyvsp[0].nodeval));
- break;
- }
- case 100:
- {
- yyval.nodeval = yyvsp[0].nodeval;
- break;
- }
- case 101:
- {
- yyval.nodeval = node(yyvsp[-2].nodeval, yyvsp[-1].nodetypeval, yyvsp[0].nodeval);
- break;
- }
- case 102:
- {
- yyval.nodeval = yyvsp[0].nodeval;
- break;
- }
- case 103:
- {
- yyval.nodetypeval = Node_illegal;
- break;
- }
- }
- /* the action file gets copied in in place of this dollarsign */
- /* the action file ends */
- yyvsp -= yylen;
- yylsp -= yylen;
- yyssp -= yylen;
-
- if (yydebug)
- {
- short *ssp1 = yyss - 1;
-
- fprintf(stderr, "state stack now", yyssp - yyss);
- while (ssp1 != yyssp)
- fprintf(stderr, " %d", *++ssp1);
- fprintf(stderr, "\n");
- }
-
- *++yyvsp = yyval;
-
- yylsp++;
- if (yylen == 0)
- {
- yylsp->first_line = yylloc.first_line;
- yylsp->first_column = yylloc.first_column;
- yylsp->last_line = (yylsp - 1)->last_line;
- yylsp->last_column = (yylsp - 1)->last_column;
- yylsp->text = 0;
- }
- else
- {
- yylsp->last_line = (yylsp + yylen - 1)->last_line;
- yylsp->last_column = (yylsp + yylen - 1)->last_column;
- }
-
- /*
- * Now "shift" the result of the reduction. Determine what state that goes to,
- * based on the state we popped back to and the rule number reduced by.
- */
-
- yyn = yyr1[yyn];
-
- yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
- if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
- yystate = yytable[yystate];
- else
- yystate = yydefgoto[yyn - YYNTBASE];
-
- goto yynewstate;
-
- yyerrlab: /* here on detecting error */
-
- if (!yyerrstatus)
- /* If not already recovering from an error, report this error. */
- {
- yyerror("parse error");
- }
-
- if (yyerrstatus == 3)
- {
- /* if just tried and failed to reuse lookahead token after an error, discard it. */
-
- /* return failure if at end of input */
- if (yychar == YYEOF)
- YYERROR;
-
- if (yydebug)
- fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
-
- yychar = YYEMPTY;
- }
-
- /*
- * Else will try to reuse lookahead token after shifting the error token.
- */
-
- yyerrstatus = 3; /* Each real token shifted decrements this */
-
- goto yyerrhandle;
-
- yyerrdefault: /* current state does not do anything special for the error token. */
-
- yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it. */
- if (yyn)
- goto yydefault;
-
- yyerrpop: /* pop the current state because it cannot handle the error token */
-
- if (yyssp == yyss)
- YYERROR;
- yyvsp--;
- yylsp--;
- yystate = *--yyssp;
-
- if (yydebug)
- {
- short *ssp1 = yyss - 1;
- fprintf(stderr, "Error: state stack now", yyssp - yyss);
- while (ssp1 != yyssp)
- fprintf(stderr, " %d", *++ssp1);
- fprintf(stderr, "\n");
- }
-
- yyerrhandle:
-
- yyn = yypact[yystate];
- if (yyn == (int) YYFLAG) /* WG */
- goto yyerrdefault;
-
- yyn += YYTERROR;
- if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
- goto yyerrdefault;
-
- yyn = yytable[yyn];
- if (yyn < 0)
- {
- if (yyn == YYFLAG)
- goto yyerrpop;
- yyn = -yyn;
- goto yyreduce;
- }
- else if (yyn == 0)
- goto yyerrpop;
-
- if (yyn == YYFINAL)
- YYACCEPT;
-
- if (yydebug)
- fprintf(stderr, "Shifting error token, ");
-
- *++yyvsp = yylval;
- *++yylsp = yylloc;
-
- yystate = yyn;
- goto yynewstate;
- }
-
- struct token
- {
- char *operator;
- NODETYPE value;
- int class;
- NODE *(*ptr) ();
- };
-
- #ifndef NULL
-
- #define NULL 0
-
- #endif
-
- NODE *do_atan2(), *do_close(), *do_cos(), *do_exp(), *do_getline(),
- *do_gsub(), *do_index(), *do_length(), *do_log(), *do_match(),
- *do_rand(), *do_sin(), *do_sqrt(),
- *do_srand(), *do_sprintf(), *do_sub(), *do_substr(), *do_system(),
- *do_split(), *do_int();
-
- /* Special functions for debugging */
- #ifndef FAST
- NODE *do_prvars(), *do_bp();
- #endif
-
- /* Tokentab is sorted ascii ascending order, so it can be binary searched. */
- /* (later. Right now its just sort of linear search (SLOW!!) */
-
- #define END(s) (s-1 + sizeof(s)/sizeof(s[0]))
-
- static struct token tokentab[] = {
- {"BEGIN", Node_illegal, LEX_BEGIN, 0},
- {"END", Node_illegal, LEX_END, 0},
- {"atan2", Node_builtin, LEX_BUILTIN, do_atan2},
- #ifndef FAST
- {"bp", Node_builtin, LEX_BUILTIN, do_bp},
- #endif
- {"break", Node_K_break, LEX_BREAK, 0},
- {"close", Node_builtin, LEX_BUILTIN, do_close},
- {"continue", Node_K_continue, LEX_CONTINUE, 0},
- {"cos", Node_builtin, LEX_BUILTIN, do_cos},
- {"else", Node_illegal, LEX_ELSE, 0},
- {"exit", Node_K_exit, LEX_EXIT, 0},
- {"exp", Node_builtin, LEX_BUILTIN, do_exp},
- {"for", Node_K_for, LEX_FOR, 0},
- {"getline", Node_K_getline, LEX_GETLINE, do_getline},
- {"gsub", Node_builtin, LEX_SUB, do_gsub},
- {"if", Node_K_if, LEX_IF, 0},
- {"in", Node_illegal, LEX_IN, 0},
- {"index", Node_builtin, LEX_BUILTIN, do_index},
- {"int", Node_builtin, LEX_BUILTIN, do_int},
- {"length", Node_builtin, LEX_BUILTIN, do_length},
- {"log", Node_builtin, LEX_BUILTIN, do_log},
- {"match", Node_builtin, LEX_BUILTIN, do_match},
- {"next", Node_K_next, LEX_NEXT, 0},
- {"print", Node_K_print, LEX_PRINT, 0},
- {"printf", Node_K_printf, LEX_PRINTF, 0},
- #ifndef FAST
- {"prvars", Node_builtin, LEX_BUILTIN, do_prvars},
- #endif
- {"rand", Node_builtin, LEX_BUILTIN, do_rand},
- {"sin", Node_builtin, LEX_BUILTIN, do_sin},
- {"split", Node_builtin, LEX_BUILTIN, do_split},
- {"sprintf", Node_builtin, LEX_BUILTIN, do_sprintf},
- {"srand", Node_builtin, LEX_BUILTIN, do_srand},
- {"sqrt", Node_builtin, LEX_BUILTIN, do_sqrt},
- {"sub", Node_builtin, LEX_SUB, do_sub},
- {"substr", Node_builtin, LEX_BUILTIN, do_substr},
- {"system", Node_builtin, LEX_BUILTIN, do_system},
- {"while", Node_K_while, LEX_WHILE, 0},
- {NULL, Node_illegal, ERROR, 0}
- };
-
- /* Read one token, getting characters through lexptr. */
-
- static int yylex()
- {
- register int c;
- register int namelen;
- register char *tokstart;
- register struct token *toktab, *low, *high, *mid;
- int dif;
- double atof(); /* JF know what happens if you forget this? */
-
- static did_newline = 0; /* JF the grammar insists that actions end with newlines. This was easier than hacking the
- * grammar. */
- int do_concat;
-
- int seen_e = 0; /* These are for numbers */
- int seen_point = 0;
-
- retry:
-
- if (!lexptr)
- return 0;
-
- if (want_regexp)
- {
- want_regexp = 0;
- /**
- * there is a potential bug if a regexp is followed by an equal sign:
- * "/foo/=bar" would result in assign_quotient being returned as the
- * next token. Nothing is done about it since it is not valid awk,
- * but maybe something should be done anyway.
- */
-
- tokstart = lexptr;
- while (c = *lexptr++)
- {
- switch (c)
- {
- case '\\':
- if (*lexptr++ == '\0')
- {
- yyerror("unterminated regexp ends with \\");
- return ERROR;
- }
- break;
- case '/': /* end of the regexp */
- lexptr--;
- yylval.sval = tokstart;
- return REGEXP;
- case '\n':
- case '\0':
- yyerror("unterminated regexp");
- return ERROR;
- }
- }
- }
- do_concat = want_concat_token;
- want_concat_token = 0;
-
- if (*lexptr == '\0')
- {
- lexptr = 0;
- return NEWLINE;
- }
-
- /*
- * if lexptr is at white space between two terminal tokens or parens,
- * it is a concatenation operator.
- */
- if (do_concat && (*lexptr == ' ' || *lexptr == '\t'))
- {
- while (*lexptr == ' ' || *lexptr == '\t')
- lexptr++;
- if (isalnum(*lexptr) || *lexptr == '\"' || *lexptr == '(' || *lexptr == '.' || *lexptr == '$')
- /* the '.' is for decimal pt */
- return CONCAT_OP;
- }
-
- while (*lexptr == ' ' || *lexptr == '\t')
- lexptr++;
-
- tokstart = lexptr; /* JF */
-
- switch (c = *lexptr++)
- {
- case 0:
- return 0;
-
- case '\n':
- lineno++;
- return NEWLINE;
-
- case '#': /* it's a comment */
- while (*lexptr != '\n' && *lexptr != '\0')
- lexptr++;
- goto retry;
-
- case '\\':
- if (*lexptr == '\n')
- {
- lexptr++;
- goto retry;
- }
- else
- break;
- case ')':
- case ']':
- ++want_concat_token;
- /* fall through */
- case '(': /* JF these were above, but I don't see why they should turn on concat. . . & */
- case '[':
-
- case '{':
- case ',': /* JF */
- case '$':
- case ';':
- case ':':
- case '?':
- /*
- * set node type to ILLEGAL because the action should set it to the right thing
- */
- yylval.nodetypeval = Node_illegal;
- return c;
-
- case '^':
- if (*lexptr == '=')
- {
- yylval.nodetypeval = Node_assign_pow;
- lexptr++;
- return ASSIGNOP;
- }
- yylval.nodetypeval = Node_illegal;
- return c;
-
- case '*':
- if (*lexptr == '=')
- {
- yylval.nodetypeval = Node_assign_times;
- lexptr++;
- return ASSIGNOP;
- }
- yylval.nodetypeval = Node_illegal;
- return c;
-
- case '/':
- if (*lexptr == '=')
- {
- yylval.nodetypeval = Node_assign_quotient;
- lexptr++;
- return ASSIGNOP;
- }
- yylval.nodetypeval = Node_illegal;
- return c;
-
- case '%':
- if (*lexptr == '=')
- {
- yylval.nodetypeval = Node_assign_mod;
- lexptr++;
- return ASSIGNOP;
- }
- yylval.nodetypeval = Node_illegal;
- return c;
-
- case '+':
- if (*lexptr == '=')
- {
- yylval.nodetypeval = Node_assign_plus;
- lexptr++;
- return ASSIGNOP;
- }
- if (*lexptr == '+')
- {
- yylval.nodetypeval = Node_illegal;
- lexptr++;
- return INCREMENT;
- }
- yylval.nodetypeval = Node_illegal;
- return c;
-
- case '!':
- if (*lexptr == '=')
- {
- yylval.nodetypeval = Node_notequal;
- lexptr++;
- return RELOP;
- }
- if (*lexptr == '~')
- {
- yylval.nodetypeval = Node_nomatch;
- lexptr++;
- return MATCHOP;
- }
- yylval.nodetypeval = Node_illegal;
- return c;
-
- case '<':
- if (want_redirect)
- {
- yylval.nodetypeval = Node_redirect_input;
- return REDIRECT_OP;
- }
- if (*lexptr == '=')
- {
- yylval.nodetypeval = Node_leq;
- lexptr++;
- return RELOP;
- }
- yylval.nodetypeval = Node_less;
- return RELOP;
-
- case '=':
- if (*lexptr == '=')
- {
- yylval.nodetypeval = Node_equal;
- lexptr++;
- return RELOP;
- }
- yylval.nodetypeval = Node_assign;
- return ASSIGNOP;
-
- case '>':
- if (want_redirect)
- {
- if (*lexptr == '>')
- {
- yylval.nodetypeval = Node_redirect_append;
- lexptr++;
- }
- else
- yylval.nodetypeval = Node_redirect_output;
- return REDIRECT_OP;
- }
- if (*lexptr == '=')
- {
- yylval.nodetypeval = Node_geq;
- lexptr++;
- return RELOP;
- }
- yylval.nodetypeval = Node_greater;
- return RELOP;
-
- case '~':
- yylval.nodetypeval = Node_match;
- return MATCHOP;
-
- case '}':
- if (did_newline)
- {
- did_newline = 0;
- return c;
- }
- did_newline++;
- --lexptr;
- return NEWLINE;
-
- case '"':
- while (*lexptr != '\0')
- {
- switch (*lexptr++)
- {
- case '\\':
- if (*lexptr++ != '\0')
- break;
- /* fall through */
- case '\n':
- yyerror("unterminated string");
- return ERROR;
- case '\"':
- yylval.sval = tokstart + 1;/* JF Skip the doublequote */
- ++want_concat_token;
- return YSTRING;
- }
- }
- return ERROR; /* JF this was one level up, wrong? */
-
- case '-':
- if (*lexptr == '=')
- {
- yylval.nodetypeval = Node_assign_minus;
- lexptr++;
- return ASSIGNOP;
- }
- if (*lexptr == '-')
- {
- yylval.nodetypeval = Node_illegal;
- lexptr++;
- return DECREMENT;
- }
- /*
- * JF I think space tab comma and newline are the legal places for a UMINUS. Have I missed any?
- */
- if ((!isdigit(*lexptr) && *lexptr != '.') || (lexptr > lexptr_begin + 1 && !index(" \t,\n", lexptr[-2])))
- {
- /*
- * set node type to ILLEGAL because the action should set it to the right thing
- */
- yylval.nodetypeval = Node_illegal;
- return c;
- }
- /* FALL through into number code */
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- case '.':
- /* It's a number */
- if (c == '-')
- namelen = 1;
- else
- namelen = 0;
- for (; (c = tokstart[namelen]) != '\0'; namelen++)
- {
- switch (c)
- {
- case '.':
- if (seen_point)
- goto got_number;
- ++seen_point;
- break;
- case 'e':
- case 'E':
- if (seen_e)
- goto got_number;
- ++seen_e;
- if (tokstart[namelen + 1] == '-' || tokstart[namelen + 1] == '+')
- namelen++;
- break;
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- break;
- default:
- goto got_number;
- }
- }
-
- /*
- * There seems to be a bug (feature?) in the Microsoft Large Model
- * atof function. If the string to convert is too long, atof returns a
- * zero without bothering to scan the string. The following hack simply
- * truncates tokstart for the duration of the call. -ADE-
- */
-
- got_number:
- lexptr = tokstart + namelen;
- *lexptr = '\0';
- yylval.fval = atof(tokstart);
- *lexptr = c;
- ++want_concat_token;
- return NUMBER;
-
- case '&':
- if (*lexptr == '&')
- {
- yylval.nodetypeval = Node_and;
- lexptr++;
- return LEX_AND;
- }
- return ERROR;
-
- case '|':
- if (want_redirect)
- {
- lexptr++;
- yylval.nodetypeval = Node_redirect_pipe;
- return REDIRECT_OP;
- }
- if (*lexptr == '|')
- {
- yylval.nodetypeval = Node_or;
- lexptr++;
- return LEX_OR;
- }
- return ERROR;
- }
-
- if (!(is_identchar(c)))
- {
- yyerror("Invalid char '%c' in expression\n", c);
- return ERROR;
- }
-
- /* its some type of name-type-thing. Find its length */
- for (namelen = 0; is_identchar(tokstart[namelen]); namelen++)
- ;
-
-
- /* See if it is a special token. */
-
- low = tokentab;
- high = END(tokentab);
- while (low <= high)
- {
- mid = low + (high - low) / 2;
- if (!(dif = strncmp(tokstart, mid->operator, namelen)) &&
- *tokstart == mid->operator[0] && mid->operator[namelen] == '\0')
- {
- lexptr = tokstart + namelen;
- if (mid->class == LEX_BUILTIN || mid->class == LEX_SUB)
- yylval.ptrval = mid->ptr;
- else
- yylval.nodetypeval = mid->value;
- return mid->class;
- }
- else if (dif > 0)
- low = mid + 1;
- else
- high = mid - 1;
- }
-
- /*
- * for (toktab = tokentab; toktab->operator != NULL; toktab++)
- * {
- * if(*tokstart == toktab->operator[0] && !strncmp(tokstart, toktab->operator, namelen)
- * && toktab->operator[namelen]=='\0')
- * {
- * lexptr = tokstart + namelen;
- * if(toktab->class == LEX_BUILTIN || toktab->class == LEX_SUB)
- * yylval.ptrval = toktab->ptr;
- * else
- * lexptr = tokstart + namelen;
- * if(toktab->class == LEX_BUILTIN || toktab->class == LEX_SUB)
- * yylval.ptrval = toktab->ptr;
- * else
- * yylval.nodetypeval = toktab->value;
- * return toktab->class;
- * }
- * }
- */
- yylval.sval = tokstart;
- lexptr = tokstart + namelen;
- ++want_concat_token;
- return NAME;
- }
-
- void yyerror(mesg, a1, a2, a3, a4, a5, a6, a7, a8)
- char *mesg;
- {
- register char *ptr, *beg;
-
- /* Find the current line in the input file */
- if (!lexptr)
- {
- beg = "(END OF FILE)";
- ptr = beg + 13;
- }
- else
- {
- if (*lexptr == '\n' && lexptr != lexptr_begin)
- --lexptr;
- for (beg = lexptr; beg != lexptr_begin && *beg != '\n'; --beg)
- ;
- for (ptr = lexptr; *ptr && *ptr != '\n'; ptr++) /* jfw: NL isn't guaranteed */
- ;
- if (beg != lexptr_begin)
- beg++;
- }
- fprintf(stderr, "Error near line %d, '%.*s'\n", lineno, ptr - beg, beg);
- /* figure out line number, etc. later */
- fprintf(stderr, mesg, a1, a2, a3, a4, a5, a6, a7, a8);
- fprintf(stderr, "\n");
- exit(1);
- }
-
- /*
- * Parse a C escape sequence.
- * STRING_PTR points to a variable containing a pointer to the string to
- * parse. That pointer is updated past the characters we use. The value of
- * the escape sequence is returned.
- *
- * A negative value means the sequence \ newline was seen, which is supposed
- * to be equivalent to nothing at all.
- *
- * If \ is followed by a null character, we return a negative value and leave
- * the string pointer pointing at the null character.
- *
- * If \ is followed by 000, we return 0 and leave the string pointer after
- * the zeros. A value of 0 does not mean end of string.
- */
-
- static int parse_escape(string_ptr)
- char **string_ptr;
- {
- register int c = *(*string_ptr)++;
-
- switch (c)
- {
- case 'a':
- return '\a';
- case 'b':
- return '\b';
- case 'e':
- return 033;
- case 'f':
- return '\f';
- case 'n':
- return '\n';
- case 'r':
- return '\r';
- case 't':
- return '\t';
- case 'v':
- return '\v';
- case '\n':
- return -2;
- case 0:
- (*string_ptr)--;
- return 0;
- case '^':
- c = *(*string_ptr)++;
- if (c == '\\')
- c = parse_escape(string_ptr);
- if (c == '?')
- return 0177;
- return (c & 0200) | (c & 037);
-
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- {
- register int i = c - '0';
- register int count = 0;
- while (++count < 3)
- {
- if ((c = *(*string_ptr)++) >= '0' && c <= '7')
- {
- i *= 8;
- i += c - '0';
- }
- else
- {
- (*string_ptr)--;
- break;
- }
- }
- return i;
- }
- default:
- return c;
- }
- }