123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882 |
- %{
- /*
- ** $Id: lua.stx,v 1.3 1997/09/19 21:17:52 roberto Exp roberto $
- ** Syntax analizer and code generator
- ** See Copyright Notice in lua.h
- */
- #include <stdlib.h>
- #include "lauxlib.h"
- #include "ldo.h"
- #include "lfunc.h"
- #include "llex.h"
- #include "lmem.h"
- #include "lopcodes.h"
- #include "lparser.h"
- #include "lstring.h"
- #include "lua.h"
- #include "luadebug.h"
- #include "lzio.h"
- /* to avoid warnings generated by yacc */
- int luaY_parse (void);
- #define malloc luaM_malloc
- #define realloc luaM_realloc
- #define free luaM_free
- /* maximum number of local variables */
- #define MAXLOCALS 32
- /* maximum number of variables in a multiple assignment */
- #define MAXVAR 32
- /* maximum number of nested functions */
- #define MAXSTATES 6
- /* maximum number of upvalues */
- #define MAXUPVALUES 8
- /*
- ** Variable descriptor: if n>0, represents global variable indexed
- ** by (n-1); if n<0, represents local variable index (-n)-1;
- ** if n==0, represents an indexed variable (table and index on top of stack)
- ** Must be long to store negative Word values.
- */
- typedef long vardesc;
- /* state needed to generate code for a given function */
- typedef struct State {
- TProtoFunc *f; /* current function header */
- int pc; /* next position to code */
- TaggedString *localvar[MAXLOCALS]; /* store local variable names */
- int stacksize; /* number of values on activation register */
- int maxstacksize; /* maximum number of values on activation register */
- int nlocalvar; /* number of active local variables */
- int nvars; /* number of entries in f->locvars */
- int maxcode; /* size of f->code */
- int maxvars; /* size of f->locvars (-1 if no debug information) */
- int maxconsts; /* size of f->consts */
- vardesc varbuffer[MAXVAR]; /* variables in an assignment list */
- vardesc upvalues[MAXUPVALUES]; /* upvalues */
- } State;
- static State *mainState, *currState;
- void luaY_syntaxerror (char *s, char *token)
- {
- if (token[0] == 0)
- token = "<eof>";
- luaL_verror("%.100s;\n> last token read: \"%.50s\" at line %d in file %.50s",
- s, token, luaX_linenumber, mainState->f->fileName->str);
- }
- void luaY_error (char *s)
- {
- luaY_syntaxerror(s, luaX_lasttoken());
- }
- static void code_byte (Byte c)
- {
- if (currState->pc >= currState->maxcode)
- currState->maxcode = luaM_growvector(&currState->f->code,
- currState->maxcode, Byte, codeEM, MAX_INT);
- currState->f->code[currState->pc++] = c;
- }
- static void code_word_at (int pc, int n)
- {
- Word w = n;
- if (w != n)
- luaY_error("block too big");
- currState->f->code[pc] = n&0xFF;
- currState->f->code[pc+1] = n>>8;
- }
- static void code_word (int n)
- {
- code_byte(n&0xFF);
- code_byte(n>>8);
- }
- static void deltastack (int delta)
- {
- currState->stacksize += delta;
- if (currState->stacksize > currState->maxstacksize) {
- if (currState->stacksize > 255)
- luaY_error("expression too complex");
- currState->maxstacksize = currState->stacksize;
- }
- }
- static void code_opcode (OpCode op, int delta)
- {
- code_byte(op);
- deltastack(delta);
- }
- static void code_opborw(OpCode opbyte, int arg, int delta)
- {
- if (arg <= 255) {
- code_opcode(opbyte, delta);
- code_byte(arg);
- }
- else {
- code_opcode(opbyte+1, delta);
- code_word(arg);
- }
- }
- static void code_oparg (OpCode firstop, OpCode opbyte, int arg, int delta)
- {
- if (firstop+arg < opbyte)
- code_opcode(firstop+arg, delta);
- else
- code_opborw(opbyte, arg, delta);
- }
- static void code_pop (OpCode op)
- {
- code_opcode(op, -1);
- }
- /* binary operations get 2 arguments and leave one, so they pop one */
- #define code_binop(op) code_pop(op)
- #define code_neutralop(op) code_byte(op)
- /* unary operations get 1 argument and leave one, so they are neutral */
- #define code_unop(op) code_neutralop(op)
- static void code_constant (int c)
- {
- code_opborw(PUSHCONSTANTB, c, 1);
- }
- static int next_constant (State *cs)
- {
- TProtoFunc *f = cs->f;
- if (f->nconsts >= cs->maxconsts) {
- cs->maxconsts = luaM_growvector(&f->consts, cs->maxconsts, TObject,
- constantEM, MAX_WORD);
- }
- return f->nconsts++;
- }
- static int string_constant (TaggedString *s, State *cs)
- {
- TProtoFunc *f = cs->f;
- int c = s->u.s.constindex;
- if (!(0 <= c && c < f->nconsts &&
- ttype(&f->consts[c]) == LUA_T_STRING && tsvalue(&f->consts[c]) == s)) {
- c = next_constant(cs);
- ttype(&f->consts[c]) = LUA_T_STRING;
- tsvalue(&f->consts[c]) = s;
- s->u.s.constindex = c; /* hint for next time */
- }
- return c;
- }
- static void code_string (TaggedString *s)
- {
- code_constant(string_constant(s, currState));
- }
- #define LIM 13
- static int real_constant (real r)
- {
- /* check whether 'r' has appeared within the last LIM entries */
- TObject *cnt = currState->f->consts;
- int c = currState->f->nconsts;
- int lim = c < LIM ? 0 : c-LIM;
- while (--c >= lim) {
- if (ttype(&cnt[c]) == LUA_T_NUMBER && nvalue(&cnt[c]) == r)
- return c;
- }
- /* not found; create a luaM_new entry */
- c = next_constant(currState);
- cnt = currState->f->consts; /* 'next_constant' may reallocate this vector */
- ttype(&cnt[c]) = LUA_T_NUMBER;
- nvalue(&cnt[c]) = r;
- return c;
- }
- static void code_number (real f)
- {
- Word i;
- if (f >= 0 && f <= (real)MAX_WORD && (real)(i=(Word)f) == f)
- code_oparg(PUSH0, PUSHBYTE, i, 1); /* f has an (short) integer value */
- else
- code_constant(real_constant(f));
- }
- static void flush_record (int n)
- {
- if (n == 0) return;
- code_opcode(SETMAP, -2*n);
- code_byte(n);
- }
- static void flush_list (int m, int n)
- {
- if (n == 0) return;
- if (m == 0)
- code_opcode(SETLIST0, -n);
- else if (m < 255) {
- code_opcode(SETLIST, -n);
- code_byte(m);
- }
- else
- luaY_error("list constructor too long");
- code_byte(n);
- }
- static void luaI_registerlocalvar (TaggedString *varname, int line)
- {
- if (currState->maxvars != -1) { /* debug information? */
- if (currState->nvars >= currState->maxvars)
- currState->maxvars = luaM_growvector(&currState->f->locvars,
- currState->maxvars, LocVar, "", MAX_WORD);
- currState->f->locvars[currState->nvars].varname = varname;
- currState->f->locvars[currState->nvars].line = line;
- currState->nvars++;
- }
- }
- static void luaI_unregisterlocalvar (int line)
- {
- luaI_registerlocalvar(NULL, line);
- }
- static void store_localvar (TaggedString *name, int n)
- {
- if (currState->nlocalvar+n < MAXLOCALS)
- currState->localvar[currState->nlocalvar+n] = name;
- else
- luaY_error("too many local variables");
- luaI_registerlocalvar(name, luaX_linenumber);
- }
- static void add_localvar (TaggedString *name)
- {
- store_localvar(name, 0);
- currState->nlocalvar++;
- }
- static void add_varbuffer (vardesc var, int n)
- {
- if (n >= MAXVAR)
- luaY_error("variable buffer overflow");
- currState->varbuffer[n] = var;
- }
- static int aux_localname (TaggedString *n, State *st)
- {
- int i;
- for (i=st->nlocalvar-1; i >= 0; i--)
- if (n == st->localvar[i]) return i; /* local var index */
- return -1; /* not found */
- }
- static vardesc singlevar (TaggedString *n, State *st)
- {
- int i = aux_localname(n, st);
- if (i == -1) { /* check shadowing */
- int l;
- for (l=1; l<=(st-mainState); l++)
- if (aux_localname(n, st-l) >= 0)
- luaY_syntaxerror("cannot access a variable in outer scope", n->str);
- return string_constant(n, st)+1; /* positive value */
- }
- else return -(i+1); /* negative value */
- }
- static int indexupvalue (TaggedString *n)
- {
- vardesc v = singlevar(n, currState-1);
- int i;
- for (i=0; i<currState->f->nupvalues; i++) {
- if (currState->upvalues[i] == v)
- return i;
- }
- /* new one */
- if (++currState->f->nupvalues > MAXUPVALUES)
- luaY_error("too many upvalues in a single function");
- currState->upvalues[i] = v; /* i = currState->f->nupvalues - 1 */
- return i;
- }
- static void pushupvalue (TaggedString *n)
- {
- int i;
- if (currState == mainState)
- luaY_error("cannot access upvalue in main");
- if (aux_localname(n, currState) >= 0)
- luaY_syntaxerror("cannot access an upvalue in current scope", n->str);
- i = indexupvalue(n);
- code_oparg(PUSHUPVALUE0, PUSHUPVALUE, i, 1);
- }
- void luaY_codedebugline (int line)
- {
- static int lastline = 0;
- if (lua_debug && line != lastline) {
- code_neutralop(SETLINE);
- code_word(line);
- lastline = line;
- }
- }
- static void adjuststack (int n)
- {
- if (n > 0)
- code_oparg(POP1-1, POPS, n, -n); /* POP1-1 = POP0 */
- else if (n < 0)
- code_oparg(PUSHNIL-1, PUSHNILS, -n, -n); /* PUSHNIL1-1 = PUSHNIL0 */
- }
- static long adjust_functioncall (long exp, int i)
- {
- if (exp <= 0)
- return -exp; /* exp is -list length */
- else {
- int temp = currState->f->code[exp];
- currState->f->code[exp] = i;
- if (i != MULT_RET)
- deltastack(i);
- return temp+i;
- }
- }
- static void adjust_mult_assign (int vars, long exps)
- {
- if (exps > 0) { /* must correct function call */
- int diff = currState->f->code[exps] - vars;
- if (diff < 0)
- adjust_functioncall(exps, -diff);
- else {
- adjust_functioncall(exps, 0);
- adjuststack(diff);
- }
- }
- else adjuststack((-exps)-vars);
- }
- static void code_args (int dots)
- {
- if (!dots) {
- code_opcode(ARGS, currState->nlocalvar);
- code_byte(currState->nlocalvar);
- }
- else {
- code_opcode(VARARGS, currState->nlocalvar+1);
- code_byte(currState->nlocalvar);
- add_localvar(luaS_new("arg"));
- }
- }
- static void lua_pushvar (vardesc number)
- {
- if (number > 0) /* global var */
- code_opborw(GETGLOBALB, number-1, 1);
- else if (number < 0) /* local var */
- code_oparg(PUSHLOCAL0, PUSHLOCAL, (-number)-1, 1);
- else
- code_pop(GETTABLE);
- }
- static void storevar (vardesc number)
- {
- if (number == 0) /* indexed var */
- code_opcode(SETTABLE0, -3);
- else if (number > 0) /* global var */
- code_opborw(SETGLOBALB, number-1, -1);
- else /* number < 0 - local var */
- code_oparg(SETLOCAL0, SETLOCAL, (-number)-1, -1);
- }
- /* returns how many elements are left as 'garbage' on the stack */
- static int lua_codestore (int i, int left)
- {
- if (currState->varbuffer[i] != 0 || /* global or local var or */
- left+i == 0) { /* indexed var without values in between */
- storevar(currState->varbuffer[i]);
- return left;
- }
- else { /* indexed var with values in between*/
- code_pop(SETTABLE);
- code_byte(left+i); /* number of elements between table/index and value */
- return left+2; /* table/index are not poped, since they are not on top */
- }
- }
- static void codeIf (int thenAdd, int elseAdd)
- {
- int elseinit = elseAdd+sizeof(Word)+1;
- if (currState->pc == elseinit) { /* no else part */
- currState->pc -= sizeof(Word)+1;
- elseinit = currState->pc;
- }
- else {
- currState->f->code[elseAdd] = JMP;
- code_word_at(elseAdd+1, currState->pc-elseinit);
- }
- currState->f->code[thenAdd] = IFFJMP;
- code_word_at(thenAdd+1, elseinit-(thenAdd+sizeof(Word)+1));
- }
- static void code_shortcircuit (int pc, Byte jmp)
- {
- currState->f->code[pc] = jmp;
- code_word_at(pc+1, currState->pc - (pc + sizeof(Word)+1));
- }
- static void codereturn (void)
- {
- code_neutralop(RETCODE);
- code_byte(currState->nlocalvar);
- currState->stacksize = currState->nlocalvar;
- }
- static void func_onstack (TProtoFunc *f)
- {
- int i;
- int nupvalues = (currState+1)->f->nupvalues;
- int c = next_constant(currState);
- ttype(&currState->f->consts[c]) = LUA_T_PROTO;
- currState->f->consts[c].value.tf = (currState+1)->f;
- for (i=0; i<nupvalues; i++)
- lua_pushvar((currState+1)->upvalues[i]);
- code_opborw(CLOSUREB, c, 1-nupvalues);
- }
- static void init_state (TaggedString *filename)
- {
- TProtoFunc *f = luaF_newproto();
- currState->stacksize = 0;
- currState->maxstacksize = 0;
- currState->nlocalvar = 0;
- currState->f = f;
- f->fileName = filename;
- currState->pc = 0;
- currState->maxcode = 0;
- f->code = NULL;
- currState->maxconsts = 0;
- if (lua_debug) {
- currState->nvars = 0;
- currState->maxvars = 0;
- }
- else
- currState->maxvars = -1; /* flag no debug information */
- code_byte(0); /* to be filled with stacksize */
- }
- static void init_func (void)
- {
- if (currState-mainState >= MAXSTATES-1)
- luaY_error("too many nested functions");
- currState++;
- init_state(mainState->f->fileName);
- luaY_codedebugline(luaX_linenumber);
- currState->f->lineDefined = luaX_linenumber;
- }
- static TProtoFunc *close_func (void)
- {
- TProtoFunc *f = currState->f;
- code_neutralop(ENDCODE);
- f->code[0] = currState->maxstacksize;
- f->code = luaM_reallocvector(f->code, currState->pc, Byte);
- f->consts = luaM_reallocvector(f->consts, f->nconsts, TObject);
- if (currState->maxvars != -1) { /* debug information? */
- luaI_registerlocalvar(NULL, -1); /* flag end of vector */
- f->locvars = luaM_reallocvector(f->locvars, currState->nvars, LocVar);
- }
- currState--;
- return f;
- }
- /*
- ** Parse LUA code.
- */
- TProtoFunc *luaY_parser (ZIO *z, char *chunkname)
- {
- State state[MAXSTATES];
- currState = mainState = &state[0];
- luaX_setinput(z);
- init_state(luaS_new(chunkname));
- if (luaY_parse ()) lua_error("parse error");
- return close_func();
- }
- %}
- %union
- {
- int vInt;
- real vReal;
- char *pChar;
- long vLong;
- TaggedString *pTStr;
- TProtoFunc *pFunc;
- }
- %start chunk
- %token WRONGTOKEN
- %token NIL
- %token IF THEN ELSE ELSEIF WHILE DO REPEAT UNTIL END
- %token RETURN
- %token LOCAL
- %token FUNCTION
- %token DOTS
- %token <vReal> NUMBER
- %token <pTStr> NAME STRING
- %type <vInt> PrepJump, PrepJumpPop
- %type <vLong> exprlist, exprlist1 /* if > 0, points to function return
- counter (which has list length); if <= 0, -list lenght */
- %type <vLong> functioncall, expr /* if != 0, points to function return
- counter */
- %type <vInt> varlist1, funcParams, funcvalue
- %type <vInt> fieldlist, localdeclist, decinit
- %type <vInt> ffieldlist, ffieldlist1, semicolonpart
- %type <vInt> lfieldlist, lfieldlist1
- %type <vInt> parlist1, par
- %type <vLong> var, singlevar, funcname /* vardesc */
- %type <pFunc> body
- %left AND OR
- %left EQ NE '>' '<' LE GE
- %left CONC
- %left '+' '-'
- %left '*' '/'
- %left UNARY NOT
- %right '^'
- %% /* beginning of rules section */
- chunk : statlist ret
- ;
- statlist : /* empty */
- | statlist stat sc
- ;
- sc : /* empty */ | ';' ;
- stat : IF expr1 THEN PrepJumpPop block PrepJump elsepart END
- { codeIf($4, $6); }
- | WHILE {$<vInt>$=currState->pc;} expr1 DO PrepJumpPop block PrepJump END
- {
- currState->f->code[$5] = IFFJMP;
- code_word_at($5+1, currState->pc - ($5+sizeof(Word)+1));
- currState->f->code[$7] = UPJMP;
- code_word_at($7+1, currState->pc - ($<vInt>2));
- }
- | REPEAT {$<vInt>$=currState->pc;} block UNTIL expr1 PrepJumpPop
- {
- currState->f->code[$6] = IFFUPJMP;
- code_word_at($6+1, currState->pc - ($<vInt>2));
- }
- | varlist1 '=' exprlist1
- {{
- int i;
- int left = 0;
- adjust_mult_assign($1, $3);
- for (i=$1-1; i>=0; i--)
- left = lua_codestore(i, left);
- adjuststack(left); /* remove eventual 'garbage' left on stack */
- }}
- | functioncall
- | LOCAL localdeclist decinit
- {
- currState->nlocalvar += $2;
- adjust_mult_assign($2, $3);
- }
- | FUNCTION funcname body
- {
- func_onstack($3);
- storevar($2);
- }
- ;
- block : {$<vInt>$ = currState->nlocalvar;} chunk
- {
- adjuststack(currState->nlocalvar - $<vInt>1);
- for (; currState->nlocalvar > $<vInt>1; currState->nlocalvar--)
- luaI_unregisterlocalvar(luaX_linenumber);
- }
- ;
- funcname : var { init_func(); $$ = $1; }
- | varexp ':' NAME
- {
- code_string($3);
- $$ = 0; /* indexed variable */
- init_func();
- add_localvar(luaS_new("self"));
- }
- ;
- body : '(' parlist ')' chunk END { $$ = close_func(); }
- ;
- elsepart : /* empty */
- | ELSE block
- | ELSEIF expr1 THEN PrepJumpPop block PrepJump elsepart
- { codeIf($4, $6); }
- ;
- ret : /* empty */
- | RETURN exprlist sc
- {
- adjust_functioncall($2, MULT_RET);
- codereturn();
- }
- ;
- PrepJump : /* empty */
- {
- $$ = currState->pc;
- code_byte(0); /* open space */
- code_word(0);
- }
- ;
- PrepJumpPop : PrepJump { $$ = $1; deltastack(-1); /* pop condition */ }
- ;
- expr1 : expr { adjust_functioncall($1, 1); }
- ;
-
- expr : '(' expr ')' { $$ = $2; }
- | expr1 EQ expr1 { code_binop(EQOP); $$ = 0; }
- | expr1 '<' expr1 { code_binop(LTOP); $$ = 0; }
- | expr1 '>' expr1 { code_binop(GTOP); $$ = 0; }
- | expr1 NE expr1 { code_binop(NEQOP); $$ = 0; }
- | expr1 LE expr1 { code_binop(LEOP); $$ = 0; }
- | expr1 GE expr1 { code_binop(GEOP); $$ = 0; }
- | expr1 '+' expr1 { code_binop(ADDOP); $$ = 0; }
- | expr1 '-' expr1 { code_binop(SUBOP); $$ = 0; }
- | expr1 '*' expr1 { code_binop(MULTOP); $$ = 0; }
- | expr1 '/' expr1 { code_binop(DIVOP); $$ = 0; }
- | expr1 '^' expr1 { code_binop(POWOP); $$ = 0; }
- | expr1 CONC expr1 { code_binop(CONCOP); $$ = 0; }
- | '-' expr1 %prec UNARY { code_unop(MINUSOP); $$ = 0;}
- | NOT expr1 { code_unop(NOTOP); $$ = 0;}
- | table { $$ = 0; }
- | varexp { $$ = 0;}
- | NUMBER { code_number($1); $$ = 0; }
- | STRING { code_string($1); $$ = 0; }
- | NIL {code_opcode(PUSHNIL, 1); $$ = 0; }
- | functioncall { $$ = $1; }
- | expr1 AND PrepJumpPop expr1 { code_shortcircuit($3, ONFJMP); $$ = 0; }
- | expr1 OR PrepJumpPop expr1 { code_shortcircuit($3, ONTJMP); $$ = 0; }
- | FUNCTION { init_func(); } body { func_onstack($3); $$ = 0; }
- ;
- table :
- { code_opcode(CREATEARRAY, 1); $<vInt>$ = currState->pc; code_word(0); }
- '{' fieldlist '}'
- { code_word_at($<vInt>1, $3); }
- ;
- functioncall : funcvalue funcParams
- {
- code_opcode(CALLFUNC, -($1+$2+1)); /* ajdust counts results */
- code_byte($1+$2);
- $$ = currState->pc;
- code_byte(0); /* may be adjusted by other rules */
- }
- ;
- funcvalue : varexp { $$ = 0; }
- | varexp ':' NAME
- {
- code_opborw(PUSHSELFB, string_constant($3, currState), 1);
- $$ = 1;
- }
- ;
- funcParams : '(' exprlist ')'
- { $$ = adjust_functioncall($2, 1); }
- | table { $$ = 1; }
- ;
- exprlist : /* empty */ { $$ = 0; }
- | exprlist1 { $$ = $1; }
- ;
-
- exprlist1 : expr { if ($1 != 0) $$ = $1; else $$ = -1; }
- | exprlist1 ',' { $<vLong>$ = adjust_functioncall($1, 1); } expr
- {
- if ($4 == 0) $$ = -($<vLong>3 + 1); /* -length */
- else
- {
- currState->f->code[$4] = $<vLong>3; /* store list length */
- $$ = $4;
- }
- }
- ;
- parlist : /* empty */ { code_args(0); }
- | parlist1 { code_args($1); }
- ;
-
- parlist1 : par { $$ = $1; }
- | parlist1 ',' par
- {
- if ($1)
- luaY_error("invalid parameter list");
- $$ = $3;
- }
- ;
- par : NAME { add_localvar($1); $$ = 0; }
- | DOTS { $$ = 1; }
- ;
-
- fieldlist : lfieldlist
- { flush_list($1/LFIELDS_PER_FLUSH, $1%LFIELDS_PER_FLUSH); }
- semicolonpart
- { $$ = $1+$3; }
- | ffieldlist1 lastcomma
- { $$ = $1; flush_record($1%RFIELDS_PER_FLUSH); }
- ;
- semicolonpart : /* empty */
- { $$ = 0; }
- | ';' ffieldlist
- { $$ = $2; flush_record($2%RFIELDS_PER_FLUSH); }
- ;
- lastcomma : /* empty */
- | ','
- ;
- ffieldlist : /* empty */ { $$ = 0; }
- | ffieldlist1 lastcomma { $$ = $1; }
- ;
- ffieldlist1 : ffield {$$=1;}
- | ffieldlist1 ',' ffield
- {
- $$=$1+1;
- if ($$%RFIELDS_PER_FLUSH == 0)
- flush_record(RFIELDS_PER_FLUSH);
- }
- ;
- ffield : ffieldkey '=' expr1
- ;
- ffieldkey : '[' expr1 ']'
- | NAME { code_string($1); }
- ;
- lfieldlist : /* empty */ { $$ = 0; }
- | lfieldlist1 lastcomma { $$ = $1; }
- ;
- lfieldlist1 : expr1 {$$=1;}
- | lfieldlist1 ',' expr1
- {
- $$=$1+1;
- if ($$%LFIELDS_PER_FLUSH == 0)
- flush_list($$/LFIELDS_PER_FLUSH - 1, LFIELDS_PER_FLUSH);
- }
- ;
- varlist1 : var
- {
- $$ = 1;
- add_varbuffer($1, 0);
- }
- | varlist1 ',' var
- {
- add_varbuffer($3, $1);
- $$ = $1+1;
- }
- ;
-
- var : singlevar { $$ = $1; }
- | varexp '[' expr1 ']' { $$ = 0; } /* indexed variable */
- | varexp '.' NAME { code_string($3); $$ = 0; }/* ind. var. */
- ;
-
- singlevar : NAME { $$ = singlevar($1, currState); }
- ;
- varexp : var { lua_pushvar($1); }
- | '%' NAME { pushupvalue($2); }
- ;
- localdeclist : NAME {store_localvar($1, 0); $$ = 1;}
- | localdeclist ',' NAME
- {
- store_localvar($3, $1);
- $$ = $1+1;
- }
- ;
-
- decinit : /* empty */ { $$ = 0; }
- | '=' exprlist1 { $$ = $2; }
- ;
- %%
|