#if defined (__cplusplus) || defined (c_plusplus) #include #ifdef __EXTERN_C__ EXTERN_FUNCTION ( extern int luaY_lex, ()); #else extern int luaY_lex(); #endif extern void luaY_error(char *); extern int luaY_parse(); #endif #include # line 2 "lua.stx" char *rcs_luastx = "$Id: parser.c,v 1.1 1996/05/14 19:44:57 lhf Exp $"; #include #include #include "luadebug.h" #include "mem.h" #include "lex.h" #include "opcode.h" #include "hash.h" #include "inout.h" #include "tree.h" #include "table.h" #include "lua.h" #include "func.h" /* to avoid warnings generated by yacc */ int luaY_parse (void); #define malloc luaI_malloc #define realloc luaI_realloc #define free luaI_free #ifndef LISTING #define LISTING 0 #endif #ifndef CODE_BLOCK #define CODE_BLOCK 256 #endif static int maxcode; static int maxmain; static int maxcurr; static Byte *funcCode = NULL; static Byte **initcode; static Byte *basepc; static int maincode; static int pc; #define MAXVAR 32 static Long varbuffer[MAXVAR]; /* variables in an assignment list; it's long to store negative Word values */ static int nvarbuffer=0; /* number of variables at a list */ #define MAXLOCALS 32 static TaggedString *localvar[MAXLOCALS]; /* store local variable names */ static int nlocalvar=0; /* number of local variables */ #define MAXFIELDS FIELDS_PER_FLUSH*2 static Word fields[MAXFIELDS]; /* fieldnames to be flushed */ static int nfields=0; int lua_debug = 0; /* Internal functions */ static void luaY_error (char *s) { char msg[256]; char *token = lua_lasttext(); if (token[0] == 0) token = ""; sprintf (msg,"%s; last token read: \"%s\" at line %d in file `%s'", s, token, lua_linenumber, lua_parsedfile); lua_error (msg); } static void code_byte (Byte c) { if (pc>maxcurr-2) /* 1 byte free to code HALT of main code */ maxcurr = growvector(&basepc, maxcurr, Byte, codeEM, MAX_INT); basepc[pc++] = c; } static void code_word (Word n) { CodeWord code; code.w = n; code_byte(code.m.c1); code_byte(code.m.c2); } static void code_float (float n) { CodeFloat code; code.f = n; code_byte(code.m.c1); code_byte(code.m.c2); code_byte(code.m.c3); code_byte(code.m.c4); } static void code_code (TFunc *tf) { CodeCode code; code.tf = tf; code_byte(code.m.c1); code_byte(code.m.c2); code_byte(code.m.c3); code_byte(code.m.c4); } static void code_word_at (Byte *p, int n) { CodeWord code; if ((Word)n != n) luaY_error("block too big"); code.w = (Word)n; *p++ = code.m.c1; *p++ = code.m.c2; } static void push_field (Word name) { if (nfields < MAXFIELDS) fields[nfields++] = name; else luaY_error ("too many fields in nested constructors"); } static void flush_record (int n) { int i; if (n == 0) return; code_byte(STORERECORD); code_byte(n); for (i=0; i= 0; i--) if (n == localvar[i]) return i; /* local var */ return -1; /* global var */ } /* ** Push a variable given a number. If number is positive, push global variable ** indexed by (number -1). If negative, push local indexed by ABS(number)-1. ** Otherwise, if zero, push indexed variable (record). */ static void lua_pushvar (Long number) { if (number > 0) /* global var */ { code_byte(PUSHGLOBAL); code_word(number-1); } else if (number < 0) /* local var */ { number = (-number) - 1; if (number < 10) code_byte(PUSHLOCAL0 + number); else { code_byte(PUSHLOCAL); code_byte(number); } } else { code_byte(PUSHINDEXED); } } static void lua_codeadjust (int n) { if (n+nlocalvar == 0) code_byte(ADJUST0); else { code_byte(ADJUST); code_byte(n+nlocalvar); } } static void change2main (void) { /* (re)store main values */ pc=maincode; basepc=*initcode; maxcurr=maxmain; nlocalvar=0; } static void savemain (void) { /* save main values */ maincode=pc; *initcode=basepc; maxmain=maxcurr; } static void init_func (void) { if (funcCode == NULL) /* first function */ { funcCode = newvector(CODE_BLOCK, Byte); maxcode = CODE_BLOCK; } savemain(); /* save main values */ /* set func values */ pc=0; basepc=funcCode; maxcurr=maxcode; nlocalvar = 0; luaI_codedebugline(lua_linenumber); } static void codereturn (void) { if (nlocalvar == 0) code_byte(RETCODE0); else { code_byte(RETCODE); code_byte(nlocalvar); } } void luaI_codedebugline (int line) { static int lastline = 0; if (lua_debug && line != lastline) { code_byte(SETLINE); code_word(line); lastline = line; } } static int adjust_functioncall (Long exp, int i) { if (exp <= 0) return -exp; /* exp is -list length */ else { int temp = basepc[exp]; basepc[exp] = i; return temp+i; } } static void adjust_mult_assign (int vars, Long exps, int temps) { if (exps > 0) { /* must correct function call */ int diff = vars - basepc[exps]; if (diff >= 0) adjust_functioncall(exps, diff); else { adjust_functioncall(exps, 0); lua_codeadjust(temps); } } else if (vars != -exps) lua_codeadjust(temps); } static void storesinglevar (Long v) { if (v > 0) /* global var */ { code_byte(STOREGLOBAL); code_word(v-1); } else if (v < 0) /* local var */ { int number = (-v) - 1; if (number < 10) code_byte(STORELOCAL0 + number); else { code_byte(STORELOCAL); code_byte(number); } } else code_byte(STOREINDEXED0); } static void lua_codestore (int i) { if (varbuffer[i] != 0) /* global or local var */ storesinglevar(varbuffer[i]); else /* indexed var */ { int j; int upper=0; /* number of indexed variables upper */ int param; /* number of itens until indexed expression */ for (j=i+1; j code); *initcode = newvector(CODE_BLOCK, Byte); maincode = 0; maxmain = CODE_BLOCK; change2main(); if (luaY_parse ()) lua_error("parse error"); savemain(); (*initcode)[maincode++] = RETCODE0; tf->size = maincode; #if LISTING { static void PrintCode (Byte *c, Byte *end); PrintCode(*initcode,*initcode+maincode); } #endif } # line 410 "lua.stx" typedef union { int vInt; float vFloat; char *pChar; Word vWord; Long vLong; TFunc *pFunc; TaggedString *pTStr; } YYSTYPE; # define WRONGTOKEN 257 # define NIL 258 # define IF 259 # define THEN 260 # define ELSE 261 # define ELSEIF 262 # define WHILE 263 # define DO 264 # define REPEAT 265 # define UNTIL 266 # define END 267 # define RETURN 268 # define LOCAL 269 # define FUNCTION 270 # define NUMBER 271 # define STRING 272 # define NAME 273 # define DEBUG 274 # define AND 275 # define OR 276 # define EQ 277 # define NE 278 # define LE 279 # define GE 280 # define CONC 281 # define UNARY 282 # define NOT 283 #define luaY_clearin luaY_char = -1 #define luaY_errok luaY_errflag = 0 extern int luaY_char; extern int luaY_errflag; #ifndef YYMAXDEPTH #define YYMAXDEPTH 150 #endif YYSTYPE luaY_lval, luaY_val; # define YYERRCODE 256 # line 788 "lua.stx" int luaY_exca[] ={ -1, 1, 0, -1, -2, 0, -1, 14, 61, 88, 44, 88, -2, 94, -1, 22, 40, 7, -2, 94, -1, 29, 40, 59, 123, 59, -2, 46, -1, 44, 123, 56, -2, 63, -1, 71, 123, 56, -2, 84, -1, 76, 275, 30, 276, 30, 277, 30, 278, 30, 62, 30, 60, 30, 279, 30, 280, 30, 281, 30, 43, 30, 45, 30, 42, 30, 47, 30, 94, 30, -2, 65, -1, 77, 91, 94, 46, 94, -2, 89, -1, 132, 123, 56, -2, 78, -1, 138, 123, 56, -2, 63, -1, 155, 275, 30, 276, 30, 277, 30, 278, 30, 62, 30, 60, 30, 279, 30, 280, 30, 281, 30, 43, 30, 45, 30, 42, 30, 47, 30, 94, 30, -2, 67, }; # define YYNPROD 100 # define YYLAST 311 int luaY_act[]={ 61, 59, 148, 60, 141, 62, 118, 61, 59, 90, 60, 89, 62, 86, 84, 18, 42, 168, 54, 164, 55, 61, 59, 156, 60, 54, 62, 55, 61, 59, 115, 60, 73, 62, 157, 61, 59, 19, 60, 54, 62, 55, 61, 59, 82, 60, 54, 62, 55, 158, 159, 129, 63, 54, 91, 55, 111, 25, 121, 63, 54, 109, 55, 127, 26, 61, 59, 26, 60, 27, 62, 7, 27, 63, 71, 8, 33, 9, 11, 63, 63, 12, 6, 80, 67, 18, 13, 63, 68, 7, 48, 40, 4, 8, 63, 9, 24, 76, 138, 12, 81, 133, 76, 18, 61, 59, 61, 60, 39, 62, 20, 62, 146, 130, 117, 132, 69, 63, 123, 48, 104, 105, 122, 70, 124, 120, 72, 106, 48, 50, 29, 46, 17, 44, 128, 47, 85, 23, 83, 76, 51, 28, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 88, 140, 63, 45, 63, 36, 112, 14, 131, 139, 47, 35, 22, 151, 126, 134, 125, 78, 137, 47, 153, 74, 38, 37, 75, 142, 116, 5, 3, 154, 2, 49, 21, 147, 16, 87, 152, 165, 163, 11, 110, 108, 76, 155, 145, 160, 77, 79, 41, 171, 135, 107, 162, 173, 161, 136, 15, 43, 10, 167, 143, 144, 1, 0, 169, 0, 119, 149, 150, 0, 170, 0, 172, 0, 0, 0, 0, 0, 0, 65, 66, 53, 56, 57, 58, 64, 65, 66, 53, 56, 57, 58, 64, 17, 166, 0, 114, 0, 0, 52, 65, 66, 53, 56, 57, 58, 64, 65, 66, 53, 56, 57, 58, 64, 65, 66, 53, 56, 57, 58, 64, 0, 14, 53, 56, 57, 58, 64, 32, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 31, 18, 30, 31, 113, 0, 0, 0, 64, 0, 0, 34, 0, 0, 34 }; int luaY_pact[]={ -1000, -188, -1000, -1000, 51, -1000, -258, 24, -1000, -1000, 47, -1000, -257, -1000, -1000, 93, -1000, 73, -1000, -1000, -1000, 89, -1000, 82, -7, -1000, 24, 24, -1000, 73, -1000, -1000, -1000, -1000, 24, -49, -1000, 24, -1000, 24, -258, 39, -1000, -1000, 24, -1000, -259, 24, -260, -1000, -262, -264, -1000, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, -1000, -1000, 86, -21, -15, -15, 27, -14, -236, -1000, 70, -1000, -1000, 44, -1000, -267, 24, 84, 70, -1000, -35, -1000, 81, 74, -1000, -1000, -1000, 23, 23, 23, 23, 23, 23, 64, 64, -15, -15, -15, 62, -1000, -1000, -1000, -62, -1000, 69, 71, -1000, -21, 40, -1000, 24, -170, -1000, -1000, 70, -1000, -1000, -1000, -269, -1000, 24, 24, -1000, 53, -1000, -271, -1000, 24, 24, -1000, -21, 51, -1000, 24, 24, -244, -1000, -212, 0, 0, -1000, -271, -1000, 40, -21, -21, -1000, -1000, -1000, 51, -1000, -1000, -248, -1000, 24, -1000, 69, -250, -1000, -1000, -1000, -42, -1000, -1000, -1000, -1000, -1000, -212, -1000 }; int luaY_pgo[]={ 0, 216, 54, 44, 138, 76, 57, 212, 211, 210, 205, 202, 201, 199, 61, 198, 195, 194, 189, 159, 188, 186, 185, 184, 182, 92, 37, 181, 130, 32, 180, 88, 34, 177, 176, 175, 172, 141, 170, 168, 165, 163, 154, 134, 51, 56 }; int luaY_r1[]={ 0, 1, 1, 1, 23, 23, 24, 21, 21, 22, 30, 30, 26, 26, 25, 33, 25, 34, 25, 25, 25, 25, 32, 32, 32, 35, 29, 36, 36, 2, 31, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 38, 6, 39, 6, 40, 37, 5, 9, 9, 8, 8, 3, 3, 4, 41, 4, 18, 18, 42, 42, 43, 10, 10, 15, 15, 44, 44, 13, 13, 14, 14, 45, 16, 16, 17, 17, 7, 7, 19, 19, 19, 20, 28, 11, 11, 12, 12, 27 }; int luaY_r2[]={ 0, 0, 4, 4, 4, 2, 7, 3, 7, 11, 0, 6, 0, 2, 17, 1, 17, 1, 13, 7, 2, 7, 0, 4, 15, 1, 7, 0, 7, 1, 3, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 5, 3, 3, 3, 3, 3, 3, 5, 1, 11, 1, 11, 1, 9, 5, 3, 7, 7, 3, 1, 3, 3, 1, 9, 1, 3, 3, 7, 1, 7, 5, 1, 5, 0, 2, 1, 5, 3, 7, 7, 1, 5, 3, 7, 3, 7, 3, 9, 7, 3, 3, 3, 7, 1, 5, 3 }; int luaY_chk[]={ -1000, -1, -23, -24, -25, -27, 270, 259, 263, 265, -7, -5, 269, 274, -19, -9, -20, -28, 273, -26, 59, -21, -19, -28, -31, -6, 40, 45, -37, -28, 271, 272, 258, -5, 283, -40, -19, -33, -34, 61, 44, -11, 273, -8, 40, -37, 58, 91, 46, -22, 40, 58, 260, 277, 60, 62, 278, 279, 280, 43, 45, 42, 47, 94, 281, 275, 276, -6, -31, -31, -31, 123, -31, -29, -35, -4, -6, -19, -28, -12, 44, 61, -3, -4, 273, -31, 273, -18, -42, 273, 273, -2, -31, -31, -31, -31, -31, -31, -31, -31, -31, -31, -31, -31, -2, -2, 41, -10, -16, -14, -17, -45, -31, 273, 264, 266, -30, 44, 273, -4, 41, 93, 41, 44, -29, -38, -39, 125, -43, -44, 44, -44, 44, 61, -2, -31, -25, -36, 268, -41, -29, 273, -2, -31, -31, -15, 59, -45, 273, -31, -31, -29, -2, -26, -3, -6, 267, -32, 261, 262, -13, -14, -2, -26, 267, -29, -31, -44, 267, 260, -2, -29, -2, -32 }; int luaY_def[]={ 1, -2, 2, 3, 12, 5, 0, 56, 15, 17, 0, 20, 0, 99, -2, 56, 90, 59, 93, 4, 13, 0, -2, 0, 0, 30, 56, 56, 45, -2, 47, 48, 49, 50, 56, 0, 94, 56, 25, 56, 0, 97, 95, 58, -2, 62, 0, 56, 0, 6, 68, 0, 29, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 29, 29, 30, 0, 44, 51, -2, 0, 0, 10, 19, -2, -2, 0, 21, 0, 56, 0, 64, 60, 0, 92, 0, 69, 70, 8, 25, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 52, 54, 31, 0, 72, 77, 77, 81, 86, 93, 29, 56, 27, 66, 96, 98, 61, 91, 25, 0, 29, 56, 56, 57, 75, 74, 78, 85, -2, 56, 25, 29, 12, 26, -2, 56, 0, 71, 22, 53, 55, 73, 79, 82, 0, 87, 83, 29, 18, 11, 12, -2, 9, 0, 25, 56, 76, 77, 0, 28, 14, 23, 0, 80, 16, 29, 25, 29, 22, 24 }; typedef struct { char *t_name; int t_val; } luaY_toktype; #ifndef YYDEBUG # define YYDEBUG 0 /* don't allow debugging */ #endif #if YYDEBUG luaY_toktype luaY_toks[] = { "WRONGTOKEN", 257, "NIL", 258, "IF", 259, "THEN", 260, "ELSE", 261, "ELSEIF", 262, "WHILE", 263, "DO", 264, "REPEAT", 265, "UNTIL", 266, "END", 267, "RETURN", 268, "LOCAL", 269, "FUNCTION", 270, "NUMBER", 271, "STRING", 272, "NAME", 273, "DEBUG", 274, "AND", 275, "OR", 276, "EQ", 277, "NE", 278, ">", 62, "<", 60, "LE", 279, "GE", 280, "CONC", 281, "+", 43, "-", 45, "*", 42, "/", 47, "UNARY", 282, "NOT", 283, "^", 94, "-unknown-", -1 /* ends search */ }; char * luaY_reds[] = { "-no such reduction-", "functionlist : /* empty */", "functionlist : functionlist globalstat", "functionlist : functionlist function", "globalstat : stat sc", "globalstat : setdebug", "function : FUNCTION funcname body", "funcname : var", "funcname : varexp ':' NAME", "body : '(' parlist ')' block END", "statlist : /* empty */", "statlist : statlist stat sc", "sc : /* empty */", "sc : ';'", "stat : IF expr1 THEN PrepJump block PrepJump elsepart END", "stat : WHILE", "stat : WHILE expr1 DO PrepJump block PrepJump END", "stat : REPEAT", "stat : REPEAT block UNTIL expr1 PrepJump", "stat : varlist1 '=' exprlist1", "stat : functioncall", "stat : LOCAL localdeclist decinit", "elsepart : /* empty */", "elsepart : ELSE block", "elsepart : ELSEIF expr1 THEN PrepJump block PrepJump elsepart", "block : /* empty */", "block : statlist ret", "ret : /* empty */", "ret : RETURN exprlist sc", "PrepJump : /* empty */", "expr1 : expr", "expr : '(' expr ')'", "expr : expr1 EQ expr1", "expr : expr1 '<' expr1", "expr : expr1 '>' expr1", "expr : expr1 NE expr1", "expr : expr1 LE expr1", "expr : expr1 GE expr1", "expr : expr1 '+' expr1", "expr : expr1 '-' expr1", "expr : expr1 '*' expr1", "expr : expr1 '/' expr1", "expr : expr1 '^' expr1", "expr : expr1 CONC expr1", "expr : '-' expr1", "expr : table", "expr : varexp", "expr : NUMBER", "expr : STRING", "expr : NIL", "expr : functioncall", "expr : NOT expr1", "expr : expr1 AND PrepJump", "expr : expr1 AND PrepJump expr1", "expr : expr1 OR PrepJump", "expr : expr1 OR PrepJump expr1", "table : /* empty */", "table : '{' fieldlist '}'", "functioncall : funcvalue funcParams", "funcvalue : varexp", "funcvalue : varexp ':' NAME", "funcParams : '(' exprlist ')'", "funcParams : table", "exprlist : /* empty */", "exprlist : exprlist1", "exprlist1 : expr", "exprlist1 : exprlist1 ','", "exprlist1 : exprlist1 ',' expr", "parlist : /* empty */", "parlist : parlist1", "parlist1 : NAME", "parlist1 : parlist1 ',' NAME", "fieldlist : lfieldlist", "fieldlist : lfieldlist semicolonpart", "fieldlist : ffieldlist1 lastcomma", "semicolonpart : /* empty */", "semicolonpart : ';' ffieldlist", "lastcomma : /* empty */", "lastcomma : ','", "ffieldlist : /* empty */", "ffieldlist : ffieldlist1 lastcomma", "ffieldlist1 : ffield", "ffieldlist1 : ffieldlist1 ',' ffield", "ffield : NAME '=' expr1", "lfieldlist : /* empty */", "lfieldlist : lfieldlist1 lastcomma", "lfieldlist1 : expr1", "lfieldlist1 : lfieldlist1 ',' expr1", "varlist1 : var", "varlist1 : varlist1 ',' var", "var : singlevar", "var : varexp '[' expr1 ']'", "var : varexp '.' NAME", "singlevar : NAME", "varexp : var", "localdeclist : NAME", "localdeclist : localdeclist ',' NAME", "decinit : /* empty */", "decinit : '=' exprlist1", "setdebug : DEBUG", }; #endif /* YYDEBUG */ #line 1 "/usr/lang/SC1.0/yaccpar" /* @(#)yaccpar 1.10 89/04/04 SMI; from S5R3 1.10 */ /* ** Skeleton parser driver for yacc output */ /* @(#)RELEASE SC1.0 C++ 2.1 1Mar1991 */ /* ** yacc user known macros and defines */ #define YYERROR goto luaY_errlab #define YYACCEPT return(0) #define YYABORT return(1) #define YYBACKUP( newtoken, newvalue )\ {\ if ( luaY_char >= 0 || ( luaY_r2[ luaY_tmp ] >> 1 ) != 1 )\ {\ luaY_error( "syntax error - cannot backup" );\ goto luaY_errlab;\ }\ luaY_char = newtoken;\ luaY_state = *luaY_ps;\ luaY_lval = newvalue;\ goto luaY_newstate;\ } #define YYRECOVERING() (!!luaY_errflag) #define YYCOPY(to, from, type) \ (type *) memcpy(to, (char *) from, luaY_newmax * sizeof(type)) #ifndef YYDEBUG # define YYDEBUG 1 /* make debugging available */ #endif /* ** extern declarations for C++ - check your own code for correctness ** if you have function redefined error messages here. */ #ifdef __cplusplus EXTERN_FUNCTION ( extern int printf, (const char*, DOTDOTDOT) ); EXTERN_FUNCTION ( extern void *memcpy, (void *, const void *, int) ); #endif /* ** user known globals */ int luaY_debug; /* set to 1 to get debugging */ /* ** driver internal defines */ #define YYFLAG (-1000) /* ** static variables used by the parser */ static YYSTYPE luaY__luaY_v[YYMAXDEPTH], *luaY_v = luaY__luaY_v; /* value stack */ static int luaY__luaY_s[YYMAXDEPTH], *luaY_s = luaY__luaY_s; /* state stack */ static YYSTYPE *luaY_pv; /* top of value stack */ static int *luaY_ps; /* top of state stack */ static int luaY_state; /* current state */ static int luaY_tmp; /* extra var (lasts between blocks) */ #if defined(__cplusplus) || defined(__STDC__) || defined(lint) static int __yaccpar_lint_hack__ = 0; /* if you change the value from 0 to something else, make sure you know what to do with luaY_errlab reference. This is a hack - to make sure C++ and lint are happy with the 4.1 yacc code. */ #endif int luaY_nerrs; /* number of errors */ int luaY_errflag; /* error recovery flag */ int luaY_char; /* current input token number */ static unsigned luaY_maxdepth = YYMAXDEPTH; /* ** luaY_parse - return 0 if worked, 1 if syntax error not recovered from */ int luaY_parse() { register YYSTYPE *luaY_pvt = (YYSTYPE*)0 ; /* top of value stack for $vars */ /* ** Initialize externals - luaY_parse may be called more than once */ luaY_pv = &luaY_v[-1]; luaY_ps = &luaY_s[-1]; luaY_state = 0; luaY_tmp = 0; luaY_nerrs = 0; luaY_errflag = 0; luaY_char = -1; #if defined(__cplusplus) || defined(__STDC__) || defined(lint) /* Note that the following can never be executed but simply to please lint and C++ */ switch (__yaccpar_lint_hack__) { case 1: goto luaY_errlab; case 2: goto luaY_newstate; } #endif { register YYSTYPE *luaY__pv; /* top of value stack */ register int *luaY__ps; /* top of state stack */ register int luaY__state; /* current state */ register int luaY__n; /* internal state number info */ goto luaY_stack; /* ** get globals into registers. ** branch to here only if YYBACKUP was called. */ luaY_newstate: luaY__pv = luaY_pv; luaY__ps = luaY_ps; luaY__state = luaY_state; goto luaY__newstate; /* ** get globals into registers. ** either we just started, or we just finished a reduction */ luaY_stack: luaY__pv = luaY_pv; luaY__ps = luaY_ps; luaY__state = luaY_state; /* ** top of for (;;) loop while no reductions done */ luaY__stack: /* ** put a state and value onto the stacks */ #if YYDEBUG /* ** if debugging, look up token value in list of value vs. ** name pairs. 0 and negative (-1) are special values. ** Note: linear search is used since time is not a real ** consideration while debugging. */ if ( luaY_debug ) { register int luaY__i; (void)printf( "State %d, token ", luaY__state ); if ( luaY_char == 0 ) (void)printf( "end-of-file\n" ); else if ( luaY_char < 0 ) (void)printf( "-none-\n" ); else { for ( luaY__i = 0; luaY_toks[luaY__i].t_val >= 0; luaY__i++ ) { if ( luaY_toks[luaY__i].t_val == luaY_char ) break; } (void)printf( "%s\n", luaY_toks[luaY__i].t_name ); } } #endif /* YYDEBUG */ if ( ++luaY__ps >= &luaY_s[ luaY_maxdepth ] ) /* room on stack? */ { /* ** reallocate and recover. Note that pointers ** have to be reset, or bad things will happen */ int luaY_ps_index = (luaY__ps - luaY_s); int luaY_pv_index = (luaY__pv - luaY_v); int luaY_pvt_index = (luaY_pvt - luaY_v); int luaY_newmax; luaY_newmax = luaY_maxdepth + YYMAXDEPTH; if (luaY_maxdepth == YYMAXDEPTH) /* first time growth */ { YYSTYPE *newluaY_v = (YYSTYPE*)malloc(luaY_newmax*sizeof(YYSTYPE)); int *newluaY_s = (int*)malloc(luaY_newmax*sizeof(int)); if (newluaY_s != 0 && newluaY_v != 0) { luaY_s = YYCOPY(newluaY_s, luaY_s, int); luaY_v = YYCOPY(newluaY_v, luaY_v, YYSTYPE); } else luaY_newmax = 0; /* failed */ } else /* not first time */ { luaY_v = (YYSTYPE*)realloc((char*)luaY_v, luaY_newmax * sizeof(YYSTYPE)); luaY_s = (int*)realloc((char*)luaY_s, luaY_newmax * sizeof(int)); if (luaY_s == 0 || luaY_v == 0) luaY_newmax = 0; /* failed */ } if (luaY_newmax <= luaY_maxdepth) /* tables not expanded */ { luaY_error( "yacc stack overflow" ); YYABORT; } luaY_maxdepth = luaY_newmax; luaY__ps = luaY_s + luaY_ps_index; luaY__pv = luaY_v + luaY_pv_index; luaY_pvt = luaY_v + luaY_pvt_index; } *luaY__ps = luaY__state; *++luaY__pv = luaY_val; /* ** we have a new state - find out what to do */ luaY__newstate: if ( ( luaY__n = luaY_pact[ luaY__state ] ) <= YYFLAG ) goto luaY_default; /* simple state */ #if YYDEBUG /* ** if debugging, need to mark whether new token grabbed */ luaY_tmp = luaY_char < 0; #endif if ( ( luaY_char < 0 ) && ( ( luaY_char = luaY_lex() ) < 0 ) ) luaY_char = 0; /* reached EOF */ #if YYDEBUG if ( luaY_debug && luaY_tmp ) { register int luaY__i; (void)printf( "Received token " ); if ( luaY_char == 0 ) (void)printf( "end-of-file\n" ); else if ( luaY_char < 0 ) (void)printf( "-none-\n" ); else { for ( luaY__i = 0; luaY_toks[luaY__i].t_val >= 0; luaY__i++ ) { if ( luaY_toks[luaY__i].t_val == luaY_char ) break; } (void)printf( "%s\n", luaY_toks[luaY__i].t_name ); } } #endif /* YYDEBUG */ if ( ( ( luaY__n += luaY_char ) < 0 ) || ( luaY__n >= YYLAST ) ) goto luaY_default; if ( luaY_chk[ luaY__n = luaY_act[ luaY__n ] ] == luaY_char ) /*valid shift*/ { luaY_char = -1; luaY_val = luaY_lval; luaY__state = luaY__n; if ( luaY_errflag > 0 ) luaY_errflag--; goto luaY__stack; } luaY_default: if ( ( luaY__n = luaY_def[ luaY__state ] ) == -2 ) { #if YYDEBUG luaY_tmp = luaY_char < 0; #endif if ( ( luaY_char < 0 ) && ( ( luaY_char = luaY_lex() ) < 0 ) ) luaY_char = 0; /* reached EOF */ #if YYDEBUG if ( luaY_debug && luaY_tmp ) { register int luaY__i; (void)printf( "Received token " ); if ( luaY_char == 0 ) (void)printf( "end-of-file\n" ); else if ( luaY_char < 0 ) (void)printf( "-none-\n" ); else { for ( luaY__i = 0; luaY_toks[luaY__i].t_val >= 0; luaY__i++ ) { if ( luaY_toks[luaY__i].t_val == luaY_char ) { break; } } (void)printf( "%s\n", luaY_toks[luaY__i].t_name ); } } #endif /* YYDEBUG */ /* ** look through exception table */ { register int *luaY_xi = luaY_exca; while ( ( *luaY_xi != -1 ) || ( luaY_xi[1] != luaY__state ) ) { luaY_xi += 2; } while ( ( *(luaY_xi += 2) >= 0 ) && ( *luaY_xi != luaY_char ) ) ; if ( ( luaY__n = luaY_xi[1] ) < 0 ) YYACCEPT; } } /* ** check for syntax error */ if ( luaY__n == 0 ) /* have an error */ { /* no worry about speed here! */ switch ( luaY_errflag ) { case 0: /* new error */ luaY_error( "syntax error" ); goto skip_init; luaY_errlab: /* ** get globals into registers. ** we have a user generated syntax type error */ luaY__pv = luaY_pv; luaY__ps = luaY_ps; luaY__state = luaY_state; luaY_nerrs++; skip_init: case 1: case 2: /* incompletely recovered error */ /* try again... */ luaY_errflag = 3; /* ** find state where "error" is a legal ** shift action */ while ( luaY__ps >= luaY_s ) { luaY__n = luaY_pact[ *luaY__ps ] + YYERRCODE; if ( luaY__n >= 0 && luaY__n < YYLAST && luaY_chk[luaY_act[luaY__n]] == YYERRCODE) { /* ** simulate shift of "error" */ luaY__state = luaY_act[ luaY__n ]; goto luaY__stack; } /* ** current state has no shift on ** "error", pop stack */ #if YYDEBUG # define _POP_ "Error recovery pops state %d, uncovers state %d\n" if ( luaY_debug ) (void)printf( _POP_, *luaY__ps, luaY__ps[-1] ); # undef _POP_ #endif luaY__ps--; luaY__pv--; } /* ** there is no state on stack with "error" as ** a valid shift. give up. */ YYABORT; case 3: /* no shift yet; eat a token */ #if YYDEBUG /* ** if debugging, look up token in list of ** pairs. 0 and negative shouldn't occur, ** but since timing doesn't matter when ** debugging, it doesn't hurt to leave the ** tests here. */ if ( luaY_debug ) { register int luaY__i; (void)printf( "Error recovery discards " ); if ( luaY_char == 0 ) (void)printf( "token end-of-file\n" ); else if ( luaY_char < 0 ) (void)printf( "token -none-\n" ); else { for ( luaY__i = 0; luaY_toks[luaY__i].t_val >= 0; luaY__i++ ) { if ( luaY_toks[luaY__i].t_val == luaY_char ) { break; } } (void)printf( "token %s\n", luaY_toks[luaY__i].t_name ); } } #endif /* YYDEBUG */ if ( luaY_char == 0 ) /* reached EOF. quit */ YYABORT; luaY_char = -1; goto luaY__newstate; } }/* end if ( luaY__n == 0 ) */ /* ** reduction by production luaY__n ** put stack tops, etc. so things right after switch */ #if YYDEBUG /* ** if debugging, print the string that is the user's ** specification of the reduction which is just about ** to be done. */ if ( luaY_debug ) (void)printf( "Reduce by (%d) \"%s\"\n", luaY__n, luaY_reds[ luaY__n ] ); #endif luaY_tmp = luaY__n; /* value to switch over */ luaY_pvt = luaY__pv; /* $vars top of value stack */ /* ** Look in goto table for next state ** Sorry about using luaY__state here as temporary ** register variable, but why not, if it works... ** If luaY_r2[ luaY__n ] doesn't have the low order bit ** set, then there is no action to be done for ** this reduction. So, no saving & unsaving of ** registers done. The only difference between the ** code just after the if and the body of the if is ** the goto luaY__stack in the body. This way the test ** can be made before the choice of what to do is needed. */ { /* length of production doubled with extra bit */ register int luaY__len = luaY_r2[ luaY__n ]; if ( !( luaY__len & 01 ) ) { luaY__len >>= 1; luaY_val = ( luaY__pv -= luaY__len )[1]; /* $$ = $1 */ luaY__state = luaY_pgo[ luaY__n = luaY_r1[ luaY__n ] ] + *( luaY__ps -= luaY__len ) + 1; if ( luaY__state >= YYLAST || luaY_chk[ luaY__state = luaY_act[ luaY__state ] ] != -luaY__n ) { luaY__state = luaY_act[ luaY_pgo[ luaY__n ] ]; } goto luaY__stack; } luaY__len >>= 1; luaY_val = ( luaY__pv -= luaY__len )[1]; /* $$ = $1 */ luaY__state = luaY_pgo[ luaY__n = luaY_r1[ luaY__n ] ] + *( luaY__ps -= luaY__len ) + 1; if ( luaY__state >= YYLAST || luaY_chk[ luaY__state = luaY_act[ luaY__state ] ] != -luaY__n ) { luaY__state = luaY_act[ luaY_pgo[ luaY__n ] ]; } } /* save until reenter driver code */ luaY_state = luaY__state; luaY_ps = luaY__ps; luaY_pv = luaY__pv; } /* ** code supplied by user is placed in this switch */ switch( luaY_tmp ) { case 6: # line 469 "lua.stx" { code_byte(PUSHFUNCTION); code_code(luaY_pvt[-0].pFunc); storesinglevar(luaY_pvt[-1].vLong); } break; case 7: # line 476 "lua.stx" { luaY_val.vLong =luaY_pvt[-0].vLong; init_func(); } break; case 8: # line 478 "lua.stx" { code_byte(PUSHSTRING); code_word(luaI_findconstant(luaY_pvt[-0].pTStr)); luaY_val.vLong = 0; /* indexed variable */ init_func(); add_localvar(luaI_createfixedstring("self")); } break; case 9: # line 488 "lua.stx" { codereturn(); luaY_val.pFunc = new(TFunc); luaI_initTFunc(luaY_val.pFunc); luaY_val.pFunc->size = pc; luaY_val.pFunc->code = newvector(pc, Byte); luaY_val.pFunc->fileName = lua_parsedfile; luaY_val.pFunc->lineDefined = luaY_pvt[-3].vInt; memcpy(luaY_val.pFunc->code, basepc, pc*sizeof(Byte)); if (lua_debug) luaI_closelocalvars(luaY_val.pFunc); /* save func values */ funcCode = basepc; maxcode=maxcurr; #if LISTING PrintCode(funcCode,funcCode+pc); #endif change2main(); /* change back to main code */ } break; case 14: # line 515 "lua.stx" { codeIf(luaY_pvt[-4].vLong, luaY_pvt[-2].vLong); } break; case 15: # line 517 "lua.stx" {luaY_val.vLong=pc;} break; case 16: # line 518 "lua.stx" { basepc[luaY_pvt[-3].vLong] = IFFJMP; code_word_at(basepc+luaY_pvt[-3].vLong+1, pc - (luaY_pvt[-3].vLong + sizeof(Word)+1)); basepc[luaY_pvt[-1].vLong] = UPJMP; code_word_at(basepc+luaY_pvt[-1].vLong+1, pc - (luaY_pvt[-6].vLong)); } break; case 17: # line 525 "lua.stx" {luaY_val.vLong=pc;} break; case 18: # line 526 "lua.stx" { basepc[luaY_pvt[-0].vLong] = IFFUPJMP; code_word_at(basepc+luaY_pvt[-0].vLong+1, pc - (luaY_pvt[-4].vLong)); } break; case 19: # line 532 "lua.stx" { { int i; adjust_mult_assign(nvarbuffer, luaY_pvt[-0].vLong, luaY_pvt[-2].vInt * 2 + nvarbuffer); for (i=nvarbuffer-1; i>=0; i--) lua_codestore (i); if (luaY_pvt[-2].vInt > 1 || (luaY_pvt[-2].vInt == 1 && varbuffer[0] != 0)) lua_codeadjust (0); } } break; case 21: # line 544 "lua.stx" { nlocalvar += luaY_pvt[-1].vInt; adjust_mult_assign(luaY_pvt[-1].vInt, luaY_pvt[-0].vInt, 0); } break; case 24: # line 552 "lua.stx" { codeIf(luaY_pvt[-3].vLong, luaY_pvt[-1].vLong); } break; case 25: # line 555 "lua.stx" {luaY_val.vInt = nlocalvar;} break; case 26: # line 556 "lua.stx" { if (nlocalvar != luaY_pvt[-2].vInt) { if (lua_debug) for (; nlocalvar > luaY_pvt[-2].vInt; nlocalvar--) luaI_unregisterlocalvar(lua_linenumber); else nlocalvar = luaY_pvt[-2].vInt; lua_codeadjust (0); } } break; case 28: # line 571 "lua.stx" { adjust_functioncall(luaY_pvt[-1].vLong, MULT_RET); codereturn(); } break; case 29: # line 578 "lua.stx" { luaY_val.vLong = pc; code_byte(0); /* open space */ code_word (0); } break; case 30: # line 584 "lua.stx" { adjust_functioncall(luaY_pvt[-0].vLong, 1); } break; case 31: # line 587 "lua.stx" { luaY_val.vLong = luaY_pvt[-1].vLong; } break; case 32: # line 588 "lua.stx" { code_byte(EQOP); luaY_val.vLong = 0; } break; case 33: # line 589 "lua.stx" { code_byte(LTOP); luaY_val.vLong = 0; } break; case 34: # line 590 "lua.stx" { code_byte(GTOP); luaY_val.vLong = 0; } break; case 35: # line 591 "lua.stx" { code_byte(EQOP); code_byte(NOTOP); luaY_val.vLong = 0; } break; case 36: # line 592 "lua.stx" { code_byte(LEOP); luaY_val.vLong = 0; } break; case 37: # line 593 "lua.stx" { code_byte(GEOP); luaY_val.vLong = 0; } break; case 38: # line 594 "lua.stx" { code_byte(ADDOP); luaY_val.vLong = 0; } break; case 39: # line 595 "lua.stx" { code_byte(SUBOP); luaY_val.vLong = 0; } break; case 40: # line 596 "lua.stx" { code_byte(MULTOP); luaY_val.vLong = 0; } break; case 41: # line 597 "lua.stx" { code_byte(DIVOP); luaY_val.vLong = 0; } break; case 42: # line 598 "lua.stx" { code_byte(POWOP); luaY_val.vLong = 0; } break; case 43: # line 599 "lua.stx" { code_byte(CONCOP); luaY_val.vLong = 0; } break; case 44: # line 600 "lua.stx" { code_byte(MINUSOP); luaY_val.vLong = 0;} break; case 45: # line 601 "lua.stx" { luaY_val.vLong = 0; } break; case 46: # line 602 "lua.stx" { luaY_val.vLong = 0;} break; case 47: # line 603 "lua.stx" { code_number(luaY_pvt[-0].vFloat); luaY_val.vLong = 0; } break; case 48: # line 605 "lua.stx" { code_byte(PUSHSTRING); code_word(luaY_pvt[-0].vWord); luaY_val.vLong = 0; } break; case 49: # line 610 "lua.stx" {code_byte(PUSHNIL); luaY_val.vLong = 0; } break; case 50: # line 611 "lua.stx" { luaY_val.vLong = luaY_pvt[-0].vLong; } break; case 51: # line 612 "lua.stx" { code_byte(NOTOP); luaY_val.vLong = 0;} break; case 52: # line 613 "lua.stx" {code_byte(POP); } break; case 53: # line 614 "lua.stx" { basepc[luaY_pvt[-2].vLong] = ONFJMP; code_word_at(basepc+luaY_pvt[-2].vLong+1, pc - (luaY_pvt[-2].vLong + sizeof(Word)+1)); luaY_val.vLong = 0; } break; case 54: # line 619 "lua.stx" {code_byte(POP); } break; case 55: # line 620 "lua.stx" { basepc[luaY_pvt[-2].vLong] = ONTJMP; code_word_at(basepc+luaY_pvt[-2].vLong+1, pc - (luaY_pvt[-2].vLong + sizeof(Word)+1)); luaY_val.vLong = 0; } break; case 56: # line 628 "lua.stx" { code_byte(CREATEARRAY); luaY_val.vLong = pc; code_word(0); } break; case 57: # line 633 "lua.stx" { code_word_at(basepc+luaY_pvt[-3].vLong, luaY_pvt[-1].vInt); } break; case 58: # line 639 "lua.stx" { code_byte(CALLFUNC); code_byte(luaY_pvt[-1].vInt+luaY_pvt[-0].vInt); luaY_val.vLong = pc; code_byte(0); /* may be modified by other rules */ } break; case 59: # line 647 "lua.stx" { luaY_val.vInt = 0; } break; case 60: # line 649 "lua.stx" { code_byte(PUSHSELF); code_word(luaI_findconstant(luaY_pvt[-0].pTStr)); luaY_val.vInt = 1; } break; case 61: # line 657 "lua.stx" { luaY_val.vInt = adjust_functioncall(luaY_pvt[-1].vLong, 1); } break; case 62: # line 658 "lua.stx" { luaY_val.vInt = 1; } break; case 63: # line 661 "lua.stx" { luaY_val.vLong = 0; } break; case 64: # line 662 "lua.stx" { luaY_val.vLong = luaY_pvt[-0].vLong; } break; case 65: # line 665 "lua.stx" { if (luaY_pvt[-0].vLong != 0) luaY_val.vLong = luaY_pvt[-0].vLong; else luaY_val.vLong = -1; } break; case 66: # line 666 "lua.stx" { luaY_val.vLong = adjust_functioncall(luaY_pvt[-1].vLong, 1); } break; case 67: # line 667 "lua.stx" { if (luaY_pvt[-0].vLong == 0) luaY_val.vLong = -(luaY_pvt[-1].vLong + 1); /* -length */ else { adjust_functioncall(luaY_pvt[-0].vLong, luaY_pvt[-1].vLong); luaY_val.vLong = luaY_pvt[-0].vLong; } } break; case 68: # line 677 "lua.stx" { lua_codeadjust(0); luaY_val.vInt = lua_linenumber; } break; case 69: # line 678 "lua.stx" { lua_codeadjust(0); luaY_val.vInt = lua_linenumber; } break; case 70: # line 681 "lua.stx" { add_localvar(luaY_pvt[-0].pTStr); } break; case 71: # line 682 "lua.stx" { add_localvar(luaY_pvt[-0].pTStr); } break; case 72: # line 686 "lua.stx" { flush_list(luaY_pvt[-0].vInt/FIELDS_PER_FLUSH, luaY_pvt[-0].vInt%FIELDS_PER_FLUSH); } break; case 73: # line 688 "lua.stx" { luaY_val.vInt = luaY_pvt[-2].vInt+luaY_pvt[-0].vInt; } break; case 74: # line 690 "lua.stx" { luaY_val.vInt = luaY_pvt[-1].vInt; flush_record(luaY_pvt[-1].vInt%FIELDS_PER_FLUSH); } break; case 75: # line 694 "lua.stx" { luaY_val.vInt = 0; } break; case 76: # line 696 "lua.stx" { luaY_val.vInt = luaY_pvt[-0].vInt; flush_record(luaY_pvt[-0].vInt%FIELDS_PER_FLUSH); } break; case 79: # line 703 "lua.stx" { luaY_val.vInt = 0; } break; case 80: # line 704 "lua.stx" { luaY_val.vInt = luaY_pvt[-1].vInt; } break; case 81: # line 707 "lua.stx" {luaY_val.vInt=1;} break; case 82: # line 709 "lua.stx" { luaY_val.vInt=luaY_pvt[-2].vInt+1; if (luaY_val.vInt%FIELDS_PER_FLUSH == 0) flush_record(FIELDS_PER_FLUSH); } break; case 83: # line 716 "lua.stx" { push_field(luaI_findconstant(luaY_pvt[-2].pTStr)); } break; case 84: # line 721 "lua.stx" { luaY_val.vInt = 0; } break; case 85: # line 722 "lua.stx" { luaY_val.vInt = luaY_pvt[-1].vInt; } break; case 86: # line 725 "lua.stx" {luaY_val.vInt=1;} break; case 87: # line 727 "lua.stx" { luaY_val.vInt=luaY_pvt[-2].vInt+1; if (luaY_val.vInt%FIELDS_PER_FLUSH == 0) flush_list(luaY_val.vInt/FIELDS_PER_FLUSH - 1, FIELDS_PER_FLUSH); } break; case 88: # line 735 "lua.stx" { nvarbuffer = 0; add_varbuffer(luaY_pvt[-0].vLong); luaY_val.vInt = (luaY_pvt[-0].vLong == 0) ? 1 : 0; } break; case 89: # line 741 "lua.stx" { add_varbuffer(luaY_pvt[-0].vLong); luaY_val.vInt = (luaY_pvt[-0].vLong == 0) ? luaY_pvt[-2].vInt + 1 : luaY_pvt[-2].vInt; } break; case 90: # line 747 "lua.stx" { luaY_val.vLong = luaY_pvt[-0].vLong; } break; case 91: # line 749 "lua.stx" { luaY_val.vLong = 0; /* indexed variable */ } break; case 92: # line 753 "lua.stx" { code_byte(PUSHSTRING); code_word(luaI_findconstant(luaY_pvt[-0].pTStr)); luaY_val.vLong = 0; /* indexed variable */ } break; case 93: # line 761 "lua.stx" { int local = lua_localname(luaY_pvt[-0].pTStr); if (local == -1) /* global var */ luaY_val.vLong = luaI_findsymbol(luaY_pvt[-0].pTStr)+1; /* return positive value */ else luaY_val.vLong = -(local+1); /* return negative value */ } break; case 94: # line 770 "lua.stx" { lua_pushvar(luaY_pvt[-0].vLong); } break; case 95: # line 773 "lua.stx" {store_localvar(luaY_pvt[-0].pTStr, 0); luaY_val.vInt = 1;} break; case 96: # line 775 "lua.stx" { store_localvar(luaY_pvt[-0].pTStr, luaY_pvt[-2].vInt); luaY_val.vInt = luaY_pvt[-2].vInt+1; } break; case 97: # line 781 "lua.stx" { luaY_val.vInt = 0; } break; case 98: # line 782 "lua.stx" { luaY_val.vInt = luaY_pvt[-0].vLong; } break; case 99: # line 785 "lua.stx" { lua_debug = luaY_pvt[-0].vInt; } break; } goto luaY_stack; /* reset registers in driver code */ }