/* A Bison parser, made from parse.y by GNU bison 1.35. */ #define YYBISON 1 /* Identify Bison output. */ # define NUMBER 257 # define STRING 258 # define SYMBOL 259 # define DELETE 260 # define ARG_LOOKUP 261 # define IF 262 # define WHILE 263 # define ELSE 264 # define FOR 265 # define BREAK 266 # define CONTINUE 267 # define RETURN 268 # define IF_NO_ELSE 269 # define ADDEQ 270 # define SUBEQ 271 # define MULEQ 272 # define DIVEQ 273 # define MODEQ 274 # define ANDEQ 275 # define OREQ 276 # define CONCAT 277 # define OR 278 # define AND 279 # define GT 280 # define GE 281 # define LT 282 # define LE 283 # define EQ 284 # define NE 285 # define IN 286 # define UNARY_MINUS 287 # define NOT 288 # define INCR 289 # define DECR 290 # define POW 291 #line 2 "parse.y" #ifdef HAVE_CONFIG_H #include "../config.h" #endif #include "parse.h" #include "textBuf.h" #include "nedit.h" #include "rbTree.h" #include "interpret.h" #include #include #include #include #include #include #ifdef VMS #include "../util/VMSparam.h" #else #ifndef __MVS__ #include #endif #endif /*VMS*/ #ifdef HAVE_DEBUG_H #include "../debug.h" #endif /* Macros to add error processing to AddOp and AddSym calls */ #define ADD_OP(op) if (!AddOp(op, &ErrMsg)) return 1 #define ADD_SYM(sym) if (!AddSym(sym, &ErrMsg)) return 1 #define ADD_IMMED(val) if (!AddImmediate(val, &ErrMsg)) return 1 #define ADD_BR_OFF(to) if (!AddBranchOffset(to, &ErrMsg)) return 1 #define SET_BR_OFF(from, to) *((int *)(from)) = ((Inst *)(to)) - ((Inst *)(from)) /* Max. length for a string constant (... there shouldn't be a maximum) */ #define MAX_STRING_CONST_LEN 5000 static const char CVSID[] = "$Id: parse.y,v 1.27 2003/12/19 23:23:31 slobasso Exp $"; static int yyerror(char *s); static int yylex(void); int yyparse(void); static int follow(char expect, int yes, int no); static int follow2(char expect1, int yes1, char expect2, int yes2, int no); static int follow_non_whitespace(char expect, int yes, int no); static Symbol *matchesActionRoutine(char **inPtr); static char *ErrMsg; static char *InPtr; extern Inst *LoopStack[]; /* addresses of break, cont stmts */ extern Inst **LoopStackPtr; /* to fill at the end of a loop */ #line 57 "parse.y" #ifndef YYSTYPE typedef union { Symbol *sym; Inst *inst; int nArgs; } yystype; # define YYSTYPE yystype # define YYSTYPE_IS_TRIVIAL 1 #endif #ifndef YYDEBUG # define YYDEBUG 0 #endif #define YYFINAL 208 #define YYFLAG -32768 #define YYNTBASE 55 /* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */ #define YYTRANSLATE(x) ((unsigned)(x) <= 291 ? yytranslate[x] : 76) /* YYTRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX. */ static const char yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 50, 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, 40, 28, 2, 47, 51, 38, 36, 54, 37, 2, 39, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 52, 2, 16, 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, 46, 2, 53, 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, 48, 27, 49, 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, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 29, 30, 31, 32, 33, 34, 35, 41, 42, 43, 44, 45 }; #if YYDEBUG static const short yyprhs[] = { 0, 0, 3, 9, 14, 16, 22, 27, 29, 31, 34, 38, 45, 55, 62, 73, 74, 84, 88, 92, 97, 101, 105, 109, 113, 117, 121, 125, 129, 133, 139, 146, 153, 160, 167, 174, 181, 188, 195, 201, 207, 213, 219, 224, 227, 230, 233, 236, 238, 239, 241, 245, 246, 248, 252, 254, 257, 259, 264, 266, 271, 273, 275, 277, 279, 284, 288, 293, 297, 299, 304, 308, 312, 316, 320, 324, 328, 331, 335, 339, 343, 347, 351, 355, 359, 363, 367, 371, 374, 377, 380, 383, 386, 390, 392, 394, 396, 397, 399, 401, 403, 404 }; static const short yyrhs[] = { 75, 57, 0, 75, 48, 75, 57, 49, 0, 75, 48, 75, 49, 0, 1, 0, 48, 75, 57, 49, 75, 0, 48, 75, 49, 75, 0, 58, 0, 58, 0, 57, 58, 0, 60, 50, 75, 0, 8, 47, 72, 51, 75, 56, 0, 8, 47, 72, 51, 75, 56, 71, 75, 56, 0, 69, 47, 72, 51, 75, 56, 0, 70, 47, 62, 52, 72, 52, 62, 51, 75, 56, 0, 0, 70, 47, 5, 35, 67, 51, 59, 75, 56, 0, 12, 50, 75, 0, 13, 50, 75, 0, 14, 64, 50, 75, 0, 14, 50, 75, 0, 5, 16, 64, 0, 61, 17, 64, 0, 61, 18, 64, 0, 61, 19, 64, 0, 61, 20, 64, 0, 61, 21, 64, 0, 61, 22, 64, 0, 61, 23, 64, 0, 6, 66, 46, 63, 53, 0, 65, 46, 63, 53, 16, 64, 0, 65, 46, 63, 53, 17, 64, 0, 65, 46, 63, 53, 18, 64, 0, 65, 46, 63, 53, 19, 64, 0, 65, 46, 63, 53, 20, 64, 0, 65, 46, 63, 53, 21, 64, 0, 65, 46, 63, 53, 22, 64, 0, 65, 46, 63, 53, 23, 64, 0, 65, 46, 63, 53, 43, 0, 65, 46, 63, 53, 44, 0, 43, 65, 46, 63, 53, 0, 44, 65, 46, 63, 53, 0, 5, 47, 63, 51, 0, 43, 5, 0, 5, 43, 0, 44, 5, 0, 5, 44, 0, 5, 0, 0, 60, 0, 62, 54, 60, 0, 0, 64, 0, 63, 54, 64, 0, 68, 0, 64, 68, 0, 5, 0, 65, 46, 63, 53, 0, 5, 0, 66, 46, 63, 53, 0, 68, 0, 3, 0, 4, 0, 5, 0, 5, 47, 63, 51, 0, 47, 64, 51, 0, 7, 46, 68, 53, 0, 7, 46, 53, 0, 7, 0, 68, 46, 63, 53, 0, 68, 36, 68, 0, 68, 37, 68, 0, 68, 38, 68, 0, 68, 39, 68, 0, 68, 40, 68, 0, 68, 45, 68, 0, 37, 68, 0, 68, 29, 68, 0, 68, 30, 68, 0, 68, 31, 68, 0, 68, 32, 68, 0, 68, 33, 68, 0, 68, 34, 68, 0, 68, 28, 68, 0, 68, 27, 68, 0, 68, 73, 68, 0, 68, 74, 68, 0, 42, 68, 0, 43, 5, 0, 5, 43, 0, 44, 5, 0, 5, 44, 0, 68, 35, 68, 0, 9, 0, 11, 0, 10, 0, 0, 68, 0, 26, 0, 25, 0, 0, 75, 50, 0 }; #endif #if YYDEBUG /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const short yyrline[] = { 0, 91, 94, 97, 100, 104, 105, 106, 108, 109, 111, 112, 115, 118, 122, 127, 127, 137, 143, 149, 152, 156, 159, 162, 165, 168, 171, 174, 177, 180, 183, 186, 191, 196, 201, 206, 211, 216, 221, 226, 231, 236, 241, 245, 249, 253, 257, 262, 266, 269, 272, 276, 279, 282, 286, 287, 291, 294, 298, 301, 305, 309, 312, 315, 318, 323, 324, 327, 330, 333, 336, 339, 342, 345, 348, 351, 354, 357, 360, 363, 366, 369, 372, 375, 378, 381, 384, 387, 390, 394, 398, 402, 406, 410, 414, 418, 422, 425, 429, 434, 439, 440 }; #endif #if (YYDEBUG) || defined YYERROR_VERBOSE /* YYTNAME[TOKEN_NUM] -- String name of the token TOKEN_NUM. */ static const char *const yytname[] = { "$", "error", "$undefined.", "NUMBER", "STRING", "SYMBOL", "DELETE", "ARG_LOOKUP", "IF", "WHILE", "ELSE", "FOR", "BREAK", "CONTINUE", "RETURN", "IF_NO_ELSE", "'='", "ADDEQ", "SUBEQ", "MULEQ", "DIVEQ", "MODEQ", "ANDEQ", "OREQ", "CONCAT", "OR", "AND", "'|'", "'&'", "GT", "GE", "LT", "LE", "EQ", "NE", "IN", "'+'", "'-'", "'*'", "'/'", "'%'", "UNARY_MINUS", "NOT", "INCR", "DECR", "POW", "'['", "'('", "'{'", "'}'", "'\\n'", "')'", "';'", "']'", "','", "program", "block", "stmts", "stmt", "@1", "simpstmt", "evalsym", "comastmts", "arglist", "expr", "initarraylv", "arraylv", "arrayexpr", "numexpr", "while", "for", "else", "cond", "and", "or", "blank", 0 }; #endif /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ static const short yyr1[] = { 0, 55, 55, 55, 55, 56, 56, 56, 57, 57, 58, 58, 58, 58, 58, 59, 58, 58, 58, 58, 58, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 61, 62, 62, 62, 63, 63, 63, 64, 64, 65, 65, 66, 66, 67, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 69, 70, 71, 72, 72, 73, 74, 75, 75 }; /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ static const short yyr2[] = { 0, 2, 5, 4, 1, 5, 4, 1, 1, 2, 3, 6, 9, 6, 10, 0, 9, 3, 3, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 4, 2, 2, 2, 2, 1, 0, 1, 3, 0, 1, 3, 1, 2, 1, 4, 1, 4, 1, 1, 1, 1, 4, 3, 4, 3, 1, 4, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 3, 1, 1, 1, 0, 1, 1, 1, 0, 2 }; /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE doesn't specify something else to do. Zero means the default is an error. */ static const short yydefact[] = { 0, 4, 0, 47, 0, 0, 93, 94, 0, 0, 0, 0, 0, 100, 101, 1, 8, 0, 0, 0, 0, 0, 0, 44, 46, 51, 58, 0, 96, 100, 100, 61, 62, 63, 68, 0, 0, 0, 0, 0, 100, 0, 54, 43, 0, 45, 0, 0, 9, 100, 0, 0, 0, 0, 0, 0, 0, 51, 96, 48, 21, 0, 52, 51, 97, 0, 17, 18, 89, 91, 51, 0, 76, 87, 88, 90, 0, 20, 100, 55, 99, 98, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 51, 0, 0, 51, 51, 3, 0, 10, 22, 23, 24, 25, 26, 27, 28, 0, 0, 47, 49, 0, 42, 0, 0, 100, 0, 67, 0, 65, 19, 84, 83, 77, 78, 79, 80, 81, 82, 92, 70, 71, 72, 73, 74, 75, 0, 85, 86, 0, 0, 2, 57, 100, 0, 96, 0, 53, 29, 0, 64, 66, 69, 40, 41, 0, 0, 0, 0, 0, 0, 0, 0, 38, 39, 0, 0, 60, 0, 50, 100, 11, 7, 30, 31, 32, 33, 34, 35, 36, 37, 13, 15, 48, 0, 95, 100, 100, 0, 100, 0, 0, 0, 100, 6, 100, 12, 16, 0, 5, 14, 0, 0, 0 }; static const short yydefgoto[] = { 206, 176, 15, 177, 192, 17, 18, 116, 61, 62, 19, 27, 171, 42, 20, 21, 191, 65, 98, 99, 2 }; static const short yypact[] = { 21,-32768, 186, 354, 5, -31,-32768,-32768, -19, 0, 81, 33, 47,-32768,-32768, 343,-32768, 6, 524, 22, 26, 28, 338,-32768,-32768, 338,-32768, 35, 338,-32768, -32768,-32768,-32768, -41, 37, 338, 338, 86, 93, 338, -32768, 209, 416, 58, 61, 58, 63, 249,-32768,-32768, 338, 338, 338, 338, 338, 338, 338, 338, 338, 34, 338, -39, 338, 338, 416, 69, 72, 72,-32768,-32768, 338, 4, 44, 44,-32768,-32768, 16, 72,-32768, 416, -32768,-32768, 338, 338, 338, 338, 338, 338, 338, 338, 338, 338, 338, 338, 338, 338, 338, 338, 338, 338, 338, 338,-32768, 315, 72, 338, 338, 338, 338, 338, 338, 338, -29, 78, 349,-32768, 20,-32768, 338, -10, -32768, 51,-32768, 377,-32768, 72, 476, 494, 250, 250, 250, 250, 250, 250, 250, 333, 333, 44, 44, 44, 44, 8, 457, 437, 73, 84,-32768, 415,-32768, 338, 338, 49, 338, 88, 259,-32768,-32768,-32768, 113, 113, 338, 338, 338, 338, 338, 338, 338, 338,-32768,-32768, 259, 109, 416, 80,-32768,-32768, 151,-32768, 338, 338, 338, 338, 338, 338, 338, 338,-32768,-32768, 49, 269, -32768,-32768,-32768, 52,-32768, 325, 259, 259,-32768, 72, -32768,-32768,-32768, 259, 72,-32768, 162, 171,-32768 }; static const short yypgoto[] = { -32768, 7, -33, -2,-32768, -55,-32768, -16, -21, 60, 128,-32768,-32768, 59,-32768,-32768,-32768, -53,-32768,-32768, -12 }; #define YYLAST 547 static const short yytable[] = { 16, 47, 68, 69, 115, 113, 70, 31, 32, 33, 26, 34, 117, 48, 103, 118, 28, 66, 67, 31, 32, 33, 1, 34, 147, 118, -100, -100, 77, -100, -100, 29, -100, -100, -100, -100, 112, 104, 43, 114, 4, 35, 119, 153, 118, 16, 36, 37, 38, 121, 30, 39, 45, 35, 3, 4, 49, 122, 36, 37, 38, 157, 118, 39, -100, -100, 125, 124, 57, -100, 41, -100, 150, 58, 151, 59, 141, 11, 12, 144, 145, 63, 60, 71, 31, 32, 33, 64, 34, 96, 97, 74, 11, 12, 72, 73, 174, 173, 75, 76, 79, 48, 155, 198, -56, 118, 151, 100, 154, 101, 105, 106, 107, 108, 109, 110, 111, 64, 35, 79, 120, 79, 14, 36, 37, 38, 158, 118, 39, 148, 123, 40, 188, 115, -59, 79, 170, 159, 118, 44, 46, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 195, 142, 143, -57, 187, 190, 207, 189, 79, 79, 79, 79, 79, 79, 79, 208, 193, 0, 0, 0, 0, 186, 152, 196, 197, 0, 199, 0, 0, 0, 203, 16, 204, 0, 0, 3, 4, 48, 5, 6, 0, 7, 8, 9, 10, 0, 0, 201, 202, 0, 0, 0, 172, 64, 205, 79, 31, 32, 33, 0, 34, 0, 0, 0, 178, 179, 180, 181, 182, 183, 184, 185, 0, 11, 12, 0, 0, 0, 13, 0, 14, 79, 79, 79, 79, 79, 79, 79, 79, 0, 35, 0, 0, 0, 0, 36, 37, 38, 3, 4, 39, 5, 6, 78, 7, 8, 9, 10, 3, 4, 0, 5, 6, 0, 7, 8, 9, 10, 3, 4, 0, 5, 6, 0, 7, 8, 9, 10, 0, 0, 91, 92, 93, 94, 95, 0, 11, 12, 0, 96, 97, 0, 102, 14, 0, 0, 11, 12, 0, 0, 0, 175, 0, 14, 0, 0, 11, 12, 0, 0, 0, 0, 194, 14, 3, 4, 0, 5, 6, 0, 7, 8, 9, 10, 3, 4, 0, 5, 6, 0, 7, 8, 9, 10, 0, 31, 32, 33, 0, 34, 0, 0, 3, 4, 0, 5, 6, 0, 7, 8, 9, 10, 11, 12, 0, 0, 0, 0, 146, 22, 0, 0, 11, 12, 22, 93, 94, 95, 200, 35, 0, 0, 96, 97, 36, 37, 38, 0, 149, 39, 11, 12, 0, 0, 0, 0, 23, 24, 0, -56, 25, 23, 24, 0, -56, 25, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 0, 0, 0, 0, 96, 97, 0, 0, 0, 0, 0, 0, 156, 160, 161, 162, 163, 164, 165, 166, 167, 0, 0, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 0, 168, 169, 0, 96, 97, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 0, 0, 0, 0, 96, 97, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 0, 0, 0, 0, 96, 97, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 0, 0, 0, 0, 96, 97, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 0, 0, 0, 0, 96, 97, 50, 51, 52, 53, 54, 55, 56 }; static const short yycheck[] = { 2, 13, 43, 44, 59, 58, 47, 3, 4, 5, 5, 7, 51, 15, 47, 54, 47, 29, 30, 3, 4, 5, 1, 7, 53, 54, 5, 6, 40, 8, 9, 50, 11, 12, 13, 14, 57, 49, 5, 5, 6, 37, 63, 53, 54, 47, 42, 43, 44, 70, 50, 47, 5, 37, 5, 6, 50, 53, 42, 43, 44, 53, 54, 47, 43, 44, 78, 51, 46, 48, 10, 50, 52, 47, 54, 47, 97, 43, 44, 100, 101, 46, 22, 46, 3, 4, 5, 28, 7, 45, 46, 5, 43, 44, 35, 36, 151, 150, 5, 39, 41, 103, 51, 51, 46, 54, 54, 46, 120, 46, 50, 51, 52, 53, 54, 55, 56, 58, 37, 60, 51, 62, 50, 42, 43, 44, 53, 54, 47, 51, 71, 50, 52, 188, 46, 76, 148, 53, 54, 11, 12, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 189, 98, 99, 46, 51, 10, 0, 175, 105, 106, 107, 108, 109, 110, 111, 0, 188, -1, -1, -1, -1, 170, 118, 191, 192, -1, 194, -1, -1, -1, 198, 189, 200, -1, -1, 5, 6, 195, 8, 9, -1, 11, 12, 13, 14, -1, -1, 196, 197, -1, -1, -1, 149, 150, 203, 152, 3, 4, 5, -1, 7, -1, -1, -1, 160, 161, 162, 163, 164, 165, 166, 167, -1, 43, 44, -1, -1, -1, 48, -1, 50, 178, 179, 180, 181, 182, 183, 184, 185, -1, 37, -1, -1, -1, -1, 42, 43, 44, 5, 6, 47, 8, 9, 50, 11, 12, 13, 14, 5, 6, -1, 8, 9, -1, 11, 12, 13, 14, 5, 6, -1, 8, 9, -1, 11, 12, 13, 14, -1, -1, 36, 37, 38, 39, 40, -1, 43, 44, -1, 45, 46, -1, 49, 50, -1, -1, 43, 44, -1, -1, -1, 48, -1, 50, -1, -1, 43, 44, -1, -1, -1, -1, 49, 50, 5, 6, -1, 8, 9, -1, 11, 12, 13, 14, 5, 6, -1, 8, 9, -1, 11, 12, 13, 14, -1, 3, 4, 5, -1, 7, -1, -1, 5, 6, -1, 8, 9, -1, 11, 12, 13, 14, 43, 44, -1, -1, -1, -1, 49, 16, -1, -1, 43, 44, 16, 38, 39, 40, 49, 37, -1, -1, 45, 46, 42, 43, 44, -1, 35, 47, 43, 44, -1, -1, -1, -1, 43, 44, -1, 46, 47, 43, 44, -1, 46, 47, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, -1, -1, -1, -1, 45, 46, -1, -1, -1, -1, -1, -1, 53, 16, 17, 18, 19, 20, 21, 22, 23, -1, -1, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, -1, 43, 44, -1, 45, 46, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, -1, -1, -1, -1, 45, 46, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, -1, -1, -1, -1, 45, 46, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, -1, -1, -1, -1, 45, 46, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, -1, -1, -1, -1, 45, 46, 17, 18, 19, 20, 21, 22, 23 }; /* -*-C-*- Note some compilers choke on comments on `#line' lines. */ #line 3 "/usr/local/share/bison/bison.simple" /* Skeleton output parser for bison, Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* As a special exception, when this file is copied by Bison into a Bison output file, you may use that output file without restriction. This special exception was added by the Free Software Foundation in version 1.24 of Bison. */ /* 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. */ /* All symbols defined below should begin with yy or YY, to avoid infringing on user name space. This should be done even for local variables, as they might otherwise be expanded by user macros. There are some unavoidable exceptions within include files to define necessary library symbols; they are noted "INFRINGES ON USER NAME SPACE" below. */ #if ! defined (yyoverflow) || defined (YYERROR_VERBOSE) /* The parser invokes alloca or malloc; define the necessary symbols. */ # if YYSTACK_USE_ALLOCA # define YYSTACK_ALLOC alloca # else # ifndef YYSTACK_USE_ALLOCA # if defined (alloca) || defined (_ALLOCA_H) # define YYSTACK_ALLOC alloca # else # ifdef __GNUC__ # define YYSTACK_ALLOC __builtin_alloca # endif # endif # endif # endif # ifdef YYSTACK_ALLOC /* Pacify GCC's `empty if-body' warning. */ # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) # else # if defined (__STDC__) || defined (__cplusplus) # include /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # endif # define YYSTACK_ALLOC malloc # define YYSTACK_FREE free # endif #endif /* ! defined (yyoverflow) || defined (YYERROR_VERBOSE) */ #if (! defined (yyoverflow) \ && (! defined (__cplusplus) \ || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ union yyalloc { short yyss; YYSTYPE yyvs; # if YYLSP_NEEDED YYLTYPE yyls; # endif }; /* The size of the maximum gap between one aligned stack and the next. */ # define YYSTACK_GAP_MAX (sizeof (union yyalloc) - 1) /* The size of an array large to enough to hold all stacks, each with N elements. */ # if YYLSP_NEEDED # define YYSTACK_BYTES(N) \ ((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ + 2 * YYSTACK_GAP_MAX) # else # define YYSTACK_BYTES(N) \ ((N) * (sizeof (short) + sizeof (YYSTYPE)) \ + YYSTACK_GAP_MAX) # endif /* Copy COUNT objects from FROM to TO. The source and destination do not overlap. */ # ifndef YYCOPY # if 1 < __GNUC__ # define YYCOPY(To, From, Count) \ __builtin_memcpy (To, From, (Count) * sizeof (*(From))) # else # define YYCOPY(To, From, Count) \ do \ { \ register YYSIZE_T yyi; \ for (yyi = 0; yyi < (Count); yyi++) \ (To)[yyi] = (From)[yyi]; \ } \ while (0) # endif # endif /* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of elements in the stack, and YYPTR gives the new location of the stack. Advance YYPTR to a properly aligned location for the next stack. */ # define YYSTACK_RELOCATE(Stack) \ do \ { \ YYSIZE_T yynewbytes; \ YYCOPY (&yyptr->Stack, Stack, yysize); \ Stack = &yyptr->Stack; \ yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAX; \ yyptr += yynewbytes / sizeof (*yyptr); \ } \ while (0) #endif #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) # define YYSIZE_T __SIZE_TYPE__ #endif #if ! defined (YYSIZE_T) && defined (size_t) # define YYSIZE_T size_t #endif #if ! defined (YYSIZE_T) # if defined (__STDC__) || defined (__cplusplus) # include /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # endif #endif #if ! defined (YYSIZE_T) # define YYSIZE_T unsigned int #endif #define yyerrok (yyerrstatus = 0) #define yyclearin (yychar = YYEMPTY) #define YYEMPTY -2 #define YYEOF 0 #define YYACCEPT goto yyacceptlab #define YYABORT goto yyabortlab #define YYERROR goto yyerrlab1 /* Like YYERROR except do call yyerror. This remains here temporarily to ease the transition to the new meaning of YYERROR, for GCC. Once GCC version 2 has supplanted version 1, this can go. */ #define YYFAIL goto yyerrlab #define YYRECOVERING() (!!yyerrstatus) #define YYBACKUP(Token, Value) \ do \ if (yychar == YYEMPTY && yylen == 1) \ { \ yychar = (Token); \ yylval = (Value); \ yychar1 = YYTRANSLATE (yychar); \ YYPOPSTACK; \ goto yybackup; \ } \ else \ { \ yyerror ("syntax error: cannot back up"); \ YYERROR; \ } \ while (0) #define YYTERROR 1 #define YYERRCODE 256 /* YYLLOC_DEFAULT -- Compute the default location (before the actions are run). When YYLLOC_DEFAULT is run, CURRENT is set the location of the first token. By default, to implement support for ranges, extend its range to the last symbol. */ #ifndef YYLLOC_DEFAULT # define YYLLOC_DEFAULT(Current, Rhs, N) \ Current.last_line = Rhs[N].last_line; \ Current.last_column = Rhs[N].last_column; #endif /* YYLEX -- calling `yylex' with the right arguments. */ #if YYPURE # if YYLSP_NEEDED # ifdef YYLEX_PARAM # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM) # else # define YYLEX yylex (&yylval, &yylloc) # endif # else /* !YYLSP_NEEDED */ # ifdef YYLEX_PARAM # define YYLEX yylex (&yylval, YYLEX_PARAM) # else # define YYLEX yylex (&yylval) # endif # endif /* !YYLSP_NEEDED */ #else /* !YYPURE */ # define YYLEX yylex () #endif /* !YYPURE */ /* Enable debugging if requested. */ #if YYDEBUG # ifndef YYFPRINTF # include /* INFRINGES ON USER NAME SPACE */ # define YYFPRINTF fprintf # endif # define YYDPRINTF(Args) \ do { \ if (yydebug) \ YYFPRINTF Args; \ } while (0) /* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */ int yydebug; #else /* !YYDEBUG */ # define YYDPRINTF(Args) #endif /* !YYDEBUG */ /* YYINITDEPTH -- initial size of the parser's stacks. */ #ifndef YYINITDEPTH # define YYINITDEPTH 200 #endif /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only if the built-in stack extension method is used). Do not make this value too large; the results are undefined if SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH) evaluated with infinite-precision integer arithmetic. */ #if YYMAXDEPTH == 0 # undef YYMAXDEPTH #endif #ifndef YYMAXDEPTH # define YYMAXDEPTH 10000 #endif #ifdef YYERROR_VERBOSE # ifndef yystrlen # if defined (__GLIBC__) && defined (_STRING_H) # define yystrlen strlen # else /* Return the length of YYSTR. */ static YYSIZE_T # if defined (__STDC__) || defined (__cplusplus) yystrlen (const char *yystr) # else yystrlen (yystr) const char *yystr; # endif { register const char *yys = yystr; while (*yys++ != '\0') continue; return yys - yystr - 1; } # endif # endif # ifndef yystpcpy # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE) # define yystpcpy stpcpy # else /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in YYDEST. */ static char * # if defined (__STDC__) || defined (__cplusplus) yystpcpy (char *yydest, const char *yysrc) # else yystpcpy (yydest, yysrc) char *yydest; const char *yysrc; # endif { register char *yyd = yydest; register const char *yys = yysrc; while ((*yyd++ = *yys++) != '\0') continue; return yyd - 1; } # endif # endif #endif #line 315 "/usr/local/share/bison/bison.simple" /* The user can define YYPARSE_PARAM as the name of an argument to be passed into yyparse. The argument should have type void *. It should actually point to an object. Grammar actions can access the variable by casting it to the proper pointer type. */ #ifdef YYPARSE_PARAM # if defined (__STDC__) || defined (__cplusplus) # define YYPARSE_PARAM_ARG void *YYPARSE_PARAM # define YYPARSE_PARAM_DECL # else # define YYPARSE_PARAM_ARG YYPARSE_PARAM # define YYPARSE_PARAM_DECL void *YYPARSE_PARAM; # endif #else /* !YYPARSE_PARAM */ # define YYPARSE_PARAM_ARG # define YYPARSE_PARAM_DECL #endif /* !YYPARSE_PARAM */ /* Prevent warning if -Wstrict-prototypes. */ #ifdef __GNUC__ # ifdef YYPARSE_PARAM int yyparse (void *); # else int yyparse (void); # endif #endif /* YY_DECL_VARIABLES -- depending whether we use a pure parser, variables are global, or local to YYPARSE. */ #define YY_DECL_NON_LSP_VARIABLES \ /* The lookahead symbol. */ \ int yychar; \ \ /* The semantic value of the lookahead symbol. */ \ YYSTYPE yylval; \ \ /* Number of parse errors so far. */ \ int yynerrs; #if YYLSP_NEEDED # define YY_DECL_VARIABLES \ YY_DECL_NON_LSP_VARIABLES \ \ /* Location data for the lookahead symbol. */ \ YYLTYPE yylloc; #else # define YY_DECL_VARIABLES \ YY_DECL_NON_LSP_VARIABLES #endif /* If nonreentrant, generate the variables here. */ #if !YYPURE YY_DECL_VARIABLES #endif /* !YYPURE */ int yyparse (YYPARSE_PARAM_ARG) YYPARSE_PARAM_DECL { /* If reentrant, generate the variables here. */ #if YYPURE YY_DECL_VARIABLES #endif /* !YYPURE */ register int yystate; register int yyn; int yyresult; /* Number of tokens to shift before error messages enabled. */ int yyerrstatus; /* Lookahead token as an internal (translated) token number. */ int yychar1 = 0; /* Three stacks and their tools: `yyss': related to states, `yyvs': related to semantic values, `yyls': related to locations. Refer to the stacks thru separate pointers, to allow yyoverflow to reallocate them elsewhere. */ /* The state stack. */ short yyssa[YYINITDEPTH]; short *yyss = yyssa; register short *yyssp; /* The semantic value stack. */ YYSTYPE yyvsa[YYINITDEPTH]; YYSTYPE *yyvs = yyvsa; register YYSTYPE *yyvsp; #if YYLSP_NEEDED /* The location stack. */ YYLTYPE yylsa[YYINITDEPTH]; YYLTYPE *yyls = yylsa; YYLTYPE *yylsp; #endif #if YYLSP_NEEDED # define YYPOPSTACK (yyvsp--, yyssp--, yylsp--) #else # define YYPOPSTACK (yyvsp--, yyssp--) #endif YYSIZE_T yystacksize = YYINITDEPTH; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; #if YYLSP_NEEDED YYLTYPE yyloc; #endif /* When reducing, the number of symbols on the RHS of the reduced rule. */ int yylen; YYDPRINTF ((stderr, "Starting parse\n")); yystate = 0; yyerrstatus = 0; yynerrs = 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. The wasted elements are never initialized. */ yyssp = yyss; yyvsp = yyvs; #if YYLSP_NEEDED yylsp = yyls; #endif goto yysetstate; /*------------------------------------------------------------. | yynewstate -- Push a new state, which is found in yystate. | `------------------------------------------------------------*/ yynewstate: /* In all cases, when you get here, the value and location stacks have just been pushed. so pushing a state here evens the stacks. */ yyssp++; yysetstate: *yyssp = yystate; if (yyssp >= yyss + yystacksize - 1) { /* Get the current used size of the three stacks, in elements. */ YYSIZE_T yysize = yyssp - yyss + 1; #ifdef yyoverflow { /* 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; short *yyss1 = yyss; /* Each stack pointer address is followed by the size of the data in use in that stack, in bytes. */ # if YYLSP_NEEDED YYLTYPE *yyls1 = yyls; /* This used to be a conditional around just the two extra args, but that might be undefined if yyoverflow is a macro. */ yyoverflow ("parser stack overflow", &yyss1, yysize * sizeof (*yyssp), &yyvs1, yysize * sizeof (*yyvsp), &yyls1, yysize * sizeof (*yylsp), &yystacksize); yyls = yyls1; # else yyoverflow ("parser stack overflow", &yyss1, yysize * sizeof (*yyssp), &yyvs1, yysize * sizeof (*yyvsp), &yystacksize); # endif yyss = yyss1; yyvs = yyvs1; } #else /* no yyoverflow */ # ifndef YYSTACK_RELOCATE goto yyoverflowlab; # else /* Extend the stack our own way. */ if (yystacksize >= YYMAXDEPTH) goto yyoverflowlab; yystacksize *= 2; if (yystacksize > YYMAXDEPTH) yystacksize = YYMAXDEPTH; { short *yyss1 = yyss; union yyalloc *yyptr = (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); if (! yyptr) goto yyoverflowlab; YYSTACK_RELOCATE (yyss); YYSTACK_RELOCATE (yyvs); # if YYLSP_NEEDED YYSTACK_RELOCATE (yyls); # endif # undef YYSTACK_RELOCATE if (yyss1 != yyssa) YYSTACK_FREE (yyss1); } # endif #endif /* no yyoverflow */ yyssp = yyss + yysize - 1; yyvsp = yyvs + yysize - 1; #if YYLSP_NEEDED yylsp = yyls + yysize - 1; #endif YYDPRINTF ((stderr, "Stack size increased to %lu\n", (unsigned long int) yystacksize)); if (yyssp >= yyss + yystacksize - 1) YYABORT; } YYDPRINTF ((stderr, "Entering state %d\n", yystate)); goto yybackup; /*-----------. | yybackup. | `-----------*/ yybackup: /* 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 = yypact[yystate]; 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) { YYDPRINTF ((stderr, "Reading a token: ")); 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 */ YYDPRINTF ((stderr, "Now at end of input.\n")); } else { yychar1 = YYTRANSLATE (yychar); #if YYDEBUG /* We have to keep this `#if YYDEBUG', since we use variables which are defined only if `YYDEBUG' is set. */ if (yydebug) { YYFPRINTF (stderr, "Next token is %d (%s", yychar, yytname[yychar1]); /* Give the individual parser a way to print the precise meaning of a token, for further debugging info. */ # ifdef YYPRINT YYPRINT (stderr, yychar, yylval); # endif YYFPRINTF (stderr, ")\n"); } #endif } 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 == YYFLAG) goto yyerrlab; yyn = -yyn; goto yyreduce; } else if (yyn == 0) goto yyerrlab; if (yyn == YYFINAL) YYACCEPT; /* Shift the lookahead token. */ YYDPRINTF ((stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1])); /* Discard the token being shifted unless it is eof. */ if (yychar != YYEOF) yychar = YYEMPTY; *++yyvsp = yylval; #if YYLSP_NEEDED *++yylsp = yylloc; #endif /* Count tokens shifted since error; after three, turn off error status. */ if (yyerrstatus) yyerrstatus--; yystate = yyn; goto yynewstate; /*-----------------------------------------------------------. | yydefault -- do the default action for the current state. | `-----------------------------------------------------------*/ yydefault: yyn = yydefact[yystate]; if (yyn == 0) goto yyerrlab; goto yyreduce; /*-----------------------------. | yyreduce -- Do a reduction. | `-----------------------------*/ yyreduce: /* yyn is the number of a rule to reduce with. */ yylen = yyr2[yyn]; /* If YYLEN is nonzero, implement the default value of the action: `$$ = $1'. Otherwise, the following line sets YYVAL to the semantic value of the lookahead token. This behavior is undocumented and Bison users should not rely upon it. Assigning to YYVAL unconditionally makes the parser a bit smaller, and it avoids a GCC warning that YYVAL may be used uninitialized. */ yyval = yyvsp[1-yylen]; #if YYLSP_NEEDED /* Similarly for the default location. Let the user run additional commands if for instance locations are ranges. */ yyloc = yylsp[1-yylen]; YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen); #endif #if YYDEBUG /* We have to keep this `#if YYDEBUG', since we use variables which are defined only if `YYDEBUG' is set. */ if (yydebug) { int yyi; YYFPRINTF (stderr, "Reducing via rule %d (line %d), ", yyn, yyrline[yyn]); /* Print the symbols being reduced, and their result. */ for (yyi = yyprhs[yyn]; yyrhs[yyi] > 0; yyi++) YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]); YYFPRINTF (stderr, " -> %s\n", yytname[yyr1[yyn]]); } #endif switch (yyn) { case 1: #line 91 "parse.y" { ADD_OP(OP_RETURN_NO_VAL); return 0; ; break;} case 2: #line 94 "parse.y" { ADD_OP(OP_RETURN_NO_VAL); return 0; ; break;} case 3: #line 97 "parse.y" { ADD_OP(OP_RETURN_NO_VAL); return 0; ; break;} case 4: #line 100 "parse.y" { return 1; ; break;} case 11: #line 112 "parse.y" { SET_BR_OFF(yyvsp[-3].inst, GetPC()); ; break;} case 12: #line 115 "parse.y" { SET_BR_OFF(yyvsp[-6].inst, (yyvsp[-2].inst+1)); SET_BR_OFF(yyvsp[-2].inst, GetPC()); ; break;} case 13: #line 118 "parse.y" { ADD_OP(OP_BRANCH); ADD_BR_OFF(yyvsp[-5].inst); SET_BR_OFF(yyvsp[-3].inst, GetPC()); FillLoopAddrs(GetPC(), yyvsp[-5].inst); ; break;} case 14: #line 122 "parse.y" { FillLoopAddrs(GetPC()+2+(yyvsp[-3].inst-(yyvsp[-5].inst+1)), GetPC()); SwapCode(yyvsp[-5].inst+1, yyvsp[-3].inst, GetPC()); ADD_OP(OP_BRANCH); ADD_BR_OFF(yyvsp[-7].inst); SET_BR_OFF(yyvsp[-5].inst, GetPC()); ; break;} case 15: #line 127 "parse.y" { Symbol *iterSym = InstallIteratorSymbol(); ADD_OP(OP_BEGIN_ARRAY_ITER); ADD_SYM(iterSym); ADD_OP(OP_ARRAY_ITER); ADD_SYM(yyvsp[-3].sym); ADD_SYM(iterSym); ADD_BR_OFF(0); ; break;} case 16: #line 132 "parse.y" { ADD_OP(OP_BRANCH); ADD_BR_OFF(yyvsp[-4].inst+2); SET_BR_OFF(yyvsp[-4].inst+5, GetPC()); FillLoopAddrs(GetPC(), yyvsp[-4].inst+2); ; break;} case 17: #line 137 "parse.y" { ADD_OP(OP_BRANCH); ADD_BR_OFF(0); if (AddBreakAddr(GetPC()-1)) { yyerror("break outside loop"); YYERROR; } ; break;} case 18: #line 143 "parse.y" { ADD_OP(OP_BRANCH); ADD_BR_OFF(0); if (AddContinueAddr(GetPC()-1)) { yyerror("continue outside loop"); YYERROR; } ; break;} case 19: #line 149 "parse.y" { ADD_OP(OP_RETURN); ; break;} case 20: #line 152 "parse.y" { ADD_OP(OP_RETURN_NO_VAL); ; break;} case 21: #line 156 "parse.y" { ADD_OP(OP_ASSIGN); ADD_SYM(yyvsp[-2].sym); ; break;} case 22: #line 159 "parse.y" { ADD_OP(OP_ADD); ADD_OP(OP_ASSIGN); ADD_SYM(yyvsp[-2].sym); ; break;} case 23: #line 162 "parse.y" { ADD_OP(OP_SUB); ADD_OP(OP_ASSIGN); ADD_SYM(yyvsp[-2].sym); ; break;} case 24: #line 165 "parse.y" { ADD_OP(OP_MUL); ADD_OP(OP_ASSIGN); ADD_SYM(yyvsp[-2].sym); ; break;} case 25: #line 168 "parse.y" { ADD_OP(OP_DIV); ADD_OP(OP_ASSIGN); ADD_SYM(yyvsp[-2].sym); ; break;} case 26: #line 171 "parse.y" { ADD_OP(OP_MOD); ADD_OP(OP_ASSIGN); ADD_SYM(yyvsp[-2].sym); ; break;} case 27: #line 174 "parse.y" { ADD_OP(OP_BIT_AND); ADD_OP(OP_ASSIGN); ADD_SYM(yyvsp[-2].sym); ; break;} case 28: #line 177 "parse.y" { ADD_OP(OP_BIT_OR); ADD_OP(OP_ASSIGN); ADD_SYM(yyvsp[-2].sym); ; break;} case 29: #line 180 "parse.y" { ADD_OP(OP_ARRAY_DELETE); ADD_IMMED((void *)yyvsp[-1].nArgs); ; break;} case 30: #line 183 "parse.y" { ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED((void *)yyvsp[-3].nArgs); ; break;} case 31: #line 186 "parse.y" { ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED((void *)1); ADD_IMMED((void *)yyvsp[-3].nArgs); ADD_OP(OP_ADD); ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED((void *)yyvsp[-3].nArgs); ; break;} case 32: #line 191 "parse.y" { ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED((void *)1); ADD_IMMED((void *)yyvsp[-3].nArgs); ADD_OP(OP_SUB); ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED((void *)yyvsp[-3].nArgs); ; break;} case 33: #line 196 "parse.y" { ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED((void *)1); ADD_IMMED((void *)yyvsp[-3].nArgs); ADD_OP(OP_MUL); ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED((void *)yyvsp[-3].nArgs); ; break;} case 34: #line 201 "parse.y" { ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED((void *)1); ADD_IMMED((void *)yyvsp[-3].nArgs); ADD_OP(OP_DIV); ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED((void *)yyvsp[-3].nArgs); ; break;} case 35: #line 206 "parse.y" { ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED((void *)1); ADD_IMMED((void *)yyvsp[-3].nArgs); ADD_OP(OP_MOD); ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED((void *)yyvsp[-3].nArgs); ; break;} case 36: #line 211 "parse.y" { ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED((void *)1); ADD_IMMED((void *)yyvsp[-3].nArgs); ADD_OP(OP_BIT_AND); ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED((void *)yyvsp[-3].nArgs); ; break;} case 37: #line 216 "parse.y" { ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED((void *)1); ADD_IMMED((void *)yyvsp[-3].nArgs); ADD_OP(OP_BIT_OR); ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED((void *)yyvsp[-3].nArgs); ; break;} case 38: #line 221 "parse.y" { ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED((void *)0); ADD_IMMED((void *)yyvsp[-2].nArgs); ADD_OP(OP_INCR); ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED((void *)yyvsp[-2].nArgs); ; break;} case 39: #line 226 "parse.y" { ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED((void *)0); ADD_IMMED((void *)yyvsp[-2].nArgs); ADD_OP(OP_DECR); ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED((void *)yyvsp[-2].nArgs); ; break;} case 40: #line 231 "parse.y" { ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED((void *)0); ADD_IMMED((void *)yyvsp[-1].nArgs); ADD_OP(OP_INCR); ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED((void *)yyvsp[-1].nArgs); ; break;} case 41: #line 236 "parse.y" { ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED((void *)0); ADD_IMMED((void *)yyvsp[-1].nArgs); ADD_OP(OP_DECR); ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED((void *)yyvsp[-1].nArgs); ; break;} case 42: #line 241 "parse.y" { ADD_OP(OP_SUBR_CALL); ADD_SYM(PromoteToGlobal(yyvsp[-3].sym)); ADD_IMMED((void *)yyvsp[-1].nArgs); ; break;} case 43: #line 245 "parse.y" { ADD_OP(OP_PUSH_SYM); ADD_SYM(yyvsp[0].sym); ADD_OP(OP_INCR); ADD_OP(OP_ASSIGN); ADD_SYM(yyvsp[0].sym); ; break;} case 44: #line 249 "parse.y" { ADD_OP(OP_PUSH_SYM); ADD_SYM(yyvsp[-1].sym); ADD_OP(OP_INCR); ADD_OP(OP_ASSIGN); ADD_SYM(yyvsp[-1].sym); ; break;} case 45: #line 253 "parse.y" { ADD_OP(OP_PUSH_SYM); ADD_SYM(yyvsp[0].sym); ADD_OP(OP_DECR); ADD_OP(OP_ASSIGN); ADD_SYM(yyvsp[0].sym); ; break;} case 46: #line 257 "parse.y" { ADD_OP(OP_PUSH_SYM); ADD_SYM(yyvsp[-1].sym); ADD_OP(OP_DECR); ADD_OP(OP_ASSIGN); ADD_SYM(yyvsp[-1].sym); ; break;} case 47: #line 262 "parse.y" { yyval.sym = yyvsp[0].sym; ADD_OP(OP_PUSH_SYM); ADD_SYM(yyvsp[0].sym); ; break;} case 48: #line 266 "parse.y" { yyval.inst = GetPC(); ; break;} case 49: #line 269 "parse.y" { yyval.inst = GetPC(); ; break;} case 50: #line 272 "parse.y" { yyval.inst = GetPC(); ; break;} case 51: #line 276 "parse.y" { yyval.nArgs = 0; ; break;} case 52: #line 279 "parse.y" { yyval.nArgs = 1; ; break;} case 53: #line 282 "parse.y" { yyval.nArgs = yyvsp[-2].nArgs + 1; ; break;} case 55: #line 287 "parse.y" { ADD_OP(OP_CONCAT); ; break;} case 56: #line 291 "parse.y" { ADD_OP(OP_PUSH_ARRAY_SYM); ADD_SYM(yyvsp[0].sym); ADD_IMMED((void *)1); ; break;} case 57: #line 294 "parse.y" { ADD_OP(OP_ARRAY_REF); ADD_IMMED((void *)yyvsp[-1].nArgs); ; break;} case 58: #line 298 "parse.y" { ADD_OP(OP_PUSH_ARRAY_SYM); ADD_SYM(yyvsp[0].sym); ADD_IMMED((void *)0); ; break;} case 59: #line 301 "parse.y" { ADD_OP(OP_ARRAY_REF); ADD_IMMED((void *)yyvsp[-1].nArgs); ; break;} case 60: #line 305 "parse.y" { yyval.inst = GetPC(); ; break;} case 61: #line 309 "parse.y" { ADD_OP(OP_PUSH_SYM); ADD_SYM(yyvsp[0].sym); ; break;} case 62: #line 312 "parse.y" { ADD_OP(OP_PUSH_SYM); ADD_SYM(yyvsp[0].sym); ; break;} case 63: #line 315 "parse.y" { ADD_OP(OP_PUSH_SYM); ADD_SYM(yyvsp[0].sym); ; break;} case 64: #line 318 "parse.y" { ADD_OP(OP_SUBR_CALL); ADD_SYM(PromoteToGlobal(yyvsp[-3].sym)); ADD_IMMED((void *)yyvsp[-1].nArgs); ADD_OP(OP_FETCH_RET_VAL); ; break;} case 66: #line 324 "parse.y" { ADD_OP(OP_PUSH_ARG); ; break;} case 67: #line 327 "parse.y" { ADD_OP(OP_PUSH_ARG_COUNT); ; break;} case 68: #line 330 "parse.y" { ADD_OP(OP_PUSH_ARG_ARRAY); ; break;} case 69: #line 333 "parse.y" { ADD_OP(OP_ARRAY_REF); ADD_IMMED((void *)yyvsp[-1].nArgs); ; break;} case 70: #line 336 "parse.y" { ADD_OP(OP_ADD); ; break;} case 71: #line 339 "parse.y" { ADD_OP(OP_SUB); ; break;} case 72: #line 342 "parse.y" { ADD_OP(OP_MUL); ; break;} case 73: #line 345 "parse.y" { ADD_OP(OP_DIV); ; break;} case 74: #line 348 "parse.y" { ADD_OP(OP_MOD); ; break;} case 75: #line 351 "parse.y" { ADD_OP(OP_POWER); ; break;} case 76: #line 354 "parse.y" { ADD_OP(OP_NEGATE); ; break;} case 77: #line 357 "parse.y" { ADD_OP(OP_GT); ; break;} case 78: #line 360 "parse.y" { ADD_OP(OP_GE); ; break;} case 79: #line 363 "parse.y" { ADD_OP(OP_LT); ; break;} case 80: #line 366 "parse.y" { ADD_OP(OP_LE); ; break;} case 81: #line 369 "parse.y" { ADD_OP(OP_EQ); ; break;} case 82: #line 372 "parse.y" { ADD_OP(OP_NE); ; break;} case 83: #line 375 "parse.y" { ADD_OP(OP_BIT_AND); ; break;} case 84: #line 378 "parse.y" { ADD_OP(OP_BIT_OR); ; break;} case 85: #line 381 "parse.y" { ADD_OP(OP_AND); SET_BR_OFF(yyvsp[-1].inst, GetPC()); ; break;} case 86: #line 384 "parse.y" { ADD_OP(OP_OR); SET_BR_OFF(yyvsp[-1].inst, GetPC()); ; break;} case 87: #line 387 "parse.y" { ADD_OP(OP_NOT); ; break;} case 88: #line 390 "parse.y" { ADD_OP(OP_PUSH_SYM); ADD_SYM(yyvsp[0].sym); ADD_OP(OP_INCR); ADD_OP(OP_DUP); ADD_OP(OP_ASSIGN); ADD_SYM(yyvsp[0].sym); ; break;} case 89: #line 394 "parse.y" { ADD_OP(OP_PUSH_SYM); ADD_SYM(yyvsp[-1].sym); ADD_OP(OP_DUP); ADD_OP(OP_INCR); ADD_OP(OP_ASSIGN); ADD_SYM(yyvsp[-1].sym); ; break;} case 90: #line 398 "parse.y" { ADD_OP(OP_PUSH_SYM); ADD_SYM(yyvsp[0].sym); ADD_OP(OP_DECR); ADD_OP(OP_DUP); ADD_OP(OP_ASSIGN); ADD_SYM(yyvsp[0].sym); ; break;} case 91: #line 402 "parse.y" { ADD_OP(OP_PUSH_SYM); ADD_SYM(yyvsp[-1].sym); ADD_OP(OP_DUP); ADD_OP(OP_DECR); ADD_OP(OP_ASSIGN); ADD_SYM(yyvsp[-1].sym); ; break;} case 92: #line 406 "parse.y" { ADD_OP(OP_IN_ARRAY); ; break;} case 93: #line 410 "parse.y" { yyval.inst = GetPC(); StartLoopAddrList(); ; break;} case 94: #line 414 "parse.y" { StartLoopAddrList(); yyval.inst = GetPC(); ; break;} case 95: #line 418 "parse.y" { ADD_OP(OP_BRANCH); yyval.inst = GetPC(); ADD_BR_OFF(0); ; break;} case 96: #line 422 "parse.y" { ADD_OP(OP_BRANCH_NEVER); yyval.inst = GetPC(); ADD_BR_OFF(0); ; break;} case 97: #line 425 "parse.y" { ADD_OP(OP_BRANCH_FALSE); yyval.inst = GetPC(); ADD_BR_OFF(0); ; break;} case 98: #line 429 "parse.y" { ADD_OP(OP_DUP); ADD_OP(OP_BRANCH_FALSE); yyval.inst = GetPC(); ADD_BR_OFF(0); ; break;} case 99: #line 434 "parse.y" { ADD_OP(OP_DUP); ADD_OP(OP_BRANCH_TRUE); yyval.inst = GetPC(); ADD_BR_OFF(0); ; break;} } #line 705 "/usr/local/share/bison/bison.simple" yyvsp -= yylen; yyssp -= yylen; #if YYLSP_NEEDED yylsp -= yylen; #endif #if YYDEBUG if (yydebug) { short *yyssp1 = yyss - 1; YYFPRINTF (stderr, "state stack now"); while (yyssp1 != yyssp) YYFPRINTF (stderr, " %d", *++yyssp1); YYFPRINTF (stderr, "\n"); } #endif *++yyvsp = yyval; #if YYLSP_NEEDED *++yylsp = yyloc; #endif /* 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 | `------------------------------------*/ yyerrlab: /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { ++yynerrs; #ifdef YYERROR_VERBOSE yyn = yypact[yystate]; if (yyn > YYFLAG && yyn < YYLAST) { YYSIZE_T yysize = 0; char *yymsg; int yyx, yycount; yycount = 0; /* Start YYX at -YYN if negative to avoid negative indexes in YYCHECK. */ for (yyx = yyn < 0 ? -yyn : 0; yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++) if (yycheck[yyx + yyn] == yyx) yysize += yystrlen (yytname[yyx]) + 15, yycount++; yysize += yystrlen ("parse error, unexpected ") + 1; yysize += yystrlen (yytname[YYTRANSLATE (yychar)]); yymsg = (char *) YYSTACK_ALLOC (yysize); if (yymsg != 0) { char *yyp = yystpcpy (yymsg, "parse error, unexpected "); yyp = yystpcpy (yyp, yytname[YYTRANSLATE (yychar)]); if (yycount < 5) { yycount = 0; for (yyx = yyn < 0 ? -yyn : 0; yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++) if (yycheck[yyx + yyn] == yyx) { const char *yyq = ! yycount ? ", expecting " : " or "; yyp = yystpcpy (yyp, yyq); yyp = yystpcpy (yyp, yytname[yyx]); yycount++; } } yyerror (yymsg); YYSTACK_FREE (yymsg); } else yyerror ("parse error; also virtual memory exhausted"); } else #endif /* defined (YYERROR_VERBOSE) */ yyerror ("parse error"); } goto yyerrlab1; /*--------------------------------------------------. | yyerrlab1 -- error raised explicitly by an action | `--------------------------------------------------*/ yyerrlab1: 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) YYABORT; YYDPRINTF ((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. | `-------------------------------------------------------------------*/ yyerrdefault: #if 0 /* This is wrong; only states that explicitly want error tokens should shift them. */ /* If its default is to accept any token, ok. Otherwise pop it. */ yyn = yydefact[yystate]; if (yyn) goto yydefault; #endif /*---------------------------------------------------------------. | yyerrpop -- pop the current state because it cannot handle the | | error token | `---------------------------------------------------------------*/ yyerrpop: if (yyssp == yyss) YYABORT; yyvsp--; yystate = *--yyssp; #if YYLSP_NEEDED yylsp--; #endif #if YYDEBUG if (yydebug) { short *yyssp1 = yyss - 1; YYFPRINTF (stderr, "Error: state stack now"); while (yyssp1 != yyssp) YYFPRINTF (stderr, " %d", *++yyssp1); YYFPRINTF (stderr, "\n"); } #endif /*--------------. | yyerrhandle. | `--------------*/ yyerrhandle: yyn = yypact[yystate]; if (yyn == YYFLAG) 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; YYDPRINTF ((stderr, "Shifting error token, ")); *++yyvsp = yylval; #if YYLSP_NEEDED *++yylsp = yylloc; #endif yystate = yyn; goto yynewstate; /*-------------------------------------. | yyacceptlab -- YYACCEPT comes here. | `-------------------------------------*/ yyacceptlab: yyresult = 0; goto yyreturn; /*-----------------------------------. | yyabortlab -- YYABORT comes here. | `-----------------------------------*/ yyabortlab: yyresult = 1; goto yyreturn; /*---------------------------------------------. | yyoverflowab -- parser overflow comes here. | `---------------------------------------------*/ yyoverflowlab: yyerror ("parser stack overflow"); yyresult = 2; /* Fall through. */ yyreturn: #ifndef yyoverflow if (yyss != yyssa) YYSTACK_FREE (yyss); #endif return yyresult; } #line 443 "parse.y" /* User Subroutines Section */ /* ** Parse a null terminated string and create a program from it (this is the ** parser entry point). The program created by this routine can be ** executed using ExecuteProgram. Returns program on success, or NULL ** on failure. If the command failed, the error message is returned ** as a pointer to a static string in msg, and the length of the string up ** to where parsing failed in stoppedAt. */ Program *ParseMacro(char *expr, char **msg, char **stoppedAt) { Program *prog; BeginCreatingProgram(); /* call yyparse to parse the string and check for success. If the parse failed, return the error message and string index (the grammar aborts parsing at the first error) */ InPtr = expr; if (yyparse()) { *msg = ErrMsg; *stoppedAt = InPtr; FreeProgram(FinishCreatingProgram()); return NULL; } /* get the newly created program */ prog = FinishCreatingProgram(); /* parse succeeded */ *msg = ""; *stoppedAt = InPtr; return prog; } static int yylex(void) { int i, len; Symbol *s; static DataValue value = {NO_TAG, {0}}; static char escape[] = "\\\"ntbrfav"; static char replace[] = "\\\"\n\t\b\r\f\a\v"; /* skip whitespace, backslash-newline combinations, and comments, which are all considered whitespace */ for (;;) { if (*InPtr == '\\' && *(InPtr + 1) == '\n') InPtr += 2; else if (*InPtr == ' ' || *InPtr == '\t') InPtr++; else if (*InPtr == '#') while (*InPtr != '\n' && *InPtr != '\0') { /* Comments stop at escaped newlines */ if (*InPtr == '\\' && *(InPtr + 1) == '\n') { InPtr += 2; break; } InPtr++; } else break; } /* return end of input at the end of the string */ if (*InPtr == '\0') { return 0; } /* process number tokens */ if (isdigit((unsigned char)*InPtr)) { /* number */ char name[28]; sscanf(InPtr, "%d%n", &value.val.n, &len); sprintf(name, "const %d", value.val.n); InPtr += len; value.tag = INT_TAG; if ((yylval.sym=LookupSymbol(name)) == NULL) yylval.sym = InstallSymbol(name, CONST_SYM, value); return NUMBER; } /* process symbol tokens. "define" is a special case not handled by this parser, considered end of input. Another special case is action routine names which are allowed to contain '-' despite the ambiguity, handled in matchesActionRoutine. */ if (isalpha((unsigned char)*InPtr) || *InPtr == '$') { if ((s=matchesActionRoutine(&InPtr)) == NULL) { char symName[MAX_SYM_LEN+1], *p = symName; *p++ = *InPtr++; while (isalnum((unsigned char)*InPtr) || *InPtr=='_') { if (p >= symName + MAX_SYM_LEN) InPtr++; else *p++ = *InPtr++; } *p = '\0'; if (!strcmp(symName, "while")) return WHILE; if (!strcmp(symName, "if")) return IF; if (!strcmp(symName, "else")) return ELSE; if (!strcmp(symName, "for")) return FOR; if (!strcmp(symName, "break")) return BREAK; if (!strcmp(symName, "continue")) return CONTINUE; if (!strcmp(symName, "return")) return RETURN; if (!strcmp(symName, "in")) return IN; if (!strcmp(symName, "$args")) return ARG_LOOKUP; if (!strcmp(symName, "delete") && follow_non_whitespace('(', SYMBOL, DELETE) == DELETE) return DELETE; if (!strcmp(symName, "define")) { InPtr -= 6; return 0; } if ((s=LookupSymbol(symName)) == NULL) { s = InstallSymbol(symName, symName[0]=='$' ? (((symName[1] > '0' && symName[1] <= '9') && symName[2] == 0) ? ARG_SYM : GLOBAL_SYM) : LOCAL_SYM, value); s->value.tag = NO_TAG; } } yylval.sym = s; return SYMBOL; } /* process quoted strings w/ embedded escape sequences */ if (*InPtr == '\"') { char string[MAX_STRING_CONST_LEN], *p = string; InPtr++; while (*InPtr != '\0' && *InPtr != '\"' && *InPtr != '\n') { if (p >= string + MAX_STRING_CONST_LEN) { InPtr++; continue; } if (*InPtr == '\\') { InPtr++; if (*InPtr == '\n') { InPtr++; continue; } for (i=0; escape[i]!='\0'; i++) { if (escape[i] == '\0') { *p++= *InPtr++; break; } else if (escape[i] == *InPtr) { *p++ = replace[i]; InPtr++; break; } } } else *p++= *InPtr++; } *p = '\0'; InPtr++; yylval.sym = InstallStringConstSymbol(string); return STRING; } /* process remaining two character tokens or return single char as token */ switch(*InPtr++) { case '>': return follow('=', GE, GT); case '<': return follow('=', LE, LT); case '=': return follow('=', EQ, '='); case '!': return follow('=', NE, NOT); case '+': return follow2('+', INCR, '=', ADDEQ, '+'); case '-': return follow2('-', DECR, '=', SUBEQ, '-'); case '|': return follow2('|', OR, '=', OREQ, '|'); case '&': return follow2('&', AND, '=', ANDEQ, '&'); case '*': return follow2('*', POW, '=', MULEQ, '*'); case '/': return follow('=', DIVEQ, '/'); case '%': return follow('=', MODEQ, '%'); case '^': return POW; default: return *(InPtr-1); } } /* ** look ahead for >=, etc. */ static int follow(char expect, int yes, int no) { if (*InPtr++ == expect) return yes; InPtr--; return no; } static int follow2(char expect1, int yes1, char expect2, int yes2, int no) { char next = *InPtr++; if (next == expect1) return yes1; if (next == expect2) return yes2; InPtr--; return no; } static int follow_non_whitespace(char expect, int yes, int no) { char *localInPtr = InPtr; while (1) { if (*localInPtr == ' ' || *localInPtr == '\t') { ++localInPtr; } else if (*localInPtr == '\\' && *(localInPtr + 1) == '\n') { localInPtr += 2; } else if (*localInPtr == expect) { return(yes); } else { return(no); } } } /* ** Look (way) ahead for hyphenated routine names which begin at inPtr. A ** hyphenated name is allowed if it is pre-defined in the global symbol ** table. If a matching name exists, returns the symbol, and update "inPtr". ** ** I know this is horrible language design, but existing nedit action routine ** names contain hyphens. Handling them here in the lexical analysis process ** is much easier than trying to deal with it in the parser itself. (sorry) */ static Symbol *matchesActionRoutine(char **inPtr) { char *c, *symPtr; int hasDash = False; char symbolName[MAX_SYM_LEN+1]; Symbol *s; symPtr = symbolName; for (c = *inPtr; isalnum((unsigned char)*c) || *c=='_' || ( *c=='-' && isalnum((unsigned char)(*(c+1)))); c++) { if (*c == '-') hasDash = True; *symPtr++ = *c; } if (!hasDash) return NULL; *symPtr = '\0'; s = LookupSymbol(symbolName); if (s != NULL) *inPtr = c; return s; } /* ** Called by yacc to report errors (just stores for returning when ** parsing is aborted. The error token action is to immediate abort ** parsing, so this message is immediately reported to the caller ** of ParseExpr) */ static int yyerror(char *s) { ErrMsg = s; return 0; }