|
@ -1,5 +1,5 @@ |
|
|
/*
|
|
|
/*
|
|
|
** $Id: lparser.c,v 2.177 2018/02/09 15:16:06 roberto Exp roberto $ |
|
|
** $Id: lparser.c,v 2.178 2018/02/17 19:20:00 roberto Exp roberto $ |
|
|
** Lua Parser |
|
|
** Lua Parser |
|
|
** See Copyright Notice in lua.h |
|
|
** See Copyright Notice in lua.h |
|
|
*/ |
|
|
*/ |
|
@ -65,13 +65,6 @@ static void statement (LexState *ls); |
|
|
static void expr (LexState *ls, expdesc *v); |
|
|
static void expr (LexState *ls, expdesc *v); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* semantic error */ |
|
|
|
|
|
static l_noret semerror (LexState *ls, const char *msg) { |
|
|
|
|
|
ls->t.token = 0; /* remove "near <token>" from final message */ |
|
|
|
|
|
luaX_syntaxerror(ls, msg); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static l_noret error_expected (LexState *ls, int token) { |
|
|
static l_noret error_expected (LexState *ls, int token) { |
|
|
luaX_syntaxerror(ls, |
|
|
luaX_syntaxerror(ls, |
|
|
luaO_pushfstring(ls->L, "%s expected", luaX_token2str(ls, token))); |
|
|
luaO_pushfstring(ls->L, "%s expected", luaX_token2str(ls, token))); |
|
@ -347,7 +340,7 @@ static void closegoto (LexState *ls, int g, Labeldesc *label) { |
|
|
const char *msg = luaO_pushfstring(ls->L, |
|
|
const char *msg = luaO_pushfstring(ls->L, |
|
|
"<goto %s> at line %d jumps into the scope of local '%s'", |
|
|
"<goto %s> at line %d jumps into the scope of local '%s'", |
|
|
getstr(gt->name), gt->line, getstr(vname)); |
|
|
getstr(gt->name), gt->line, getstr(vname)); |
|
|
semerror(ls, msg); |
|
|
luaK_semerror(ls, msg); |
|
|
} |
|
|
} |
|
|
luaK_patchgoto(fs, gt->pc, label->pc, 1); |
|
|
luaK_patchgoto(fs, gt->pc, label->pc, 1); |
|
|
/* remove goto from pending list */ |
|
|
/* remove goto from pending list */ |
|
@ -477,7 +470,7 @@ static void fixbreaks (FuncState *fs, BlockCnt *bl) { |
|
|
static l_noret undefgoto (LexState *ls, Labeldesc *gt) { |
|
|
static l_noret undefgoto (LexState *ls, Labeldesc *gt) { |
|
|
const char *msg = "no visible label '%s' for <goto> at line %d"; |
|
|
const char *msg = "no visible label '%s' for <goto> at line %d"; |
|
|
msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line); |
|
|
msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line); |
|
|
semerror(ls, msg); |
|
|
luaK_semerror(ls, msg); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -900,6 +893,11 @@ static void primaryexp (LexState *ls, expdesc *v) { |
|
|
singlevar(ls, v); |
|
|
singlevar(ls, v); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
case TK_UNDEF: { |
|
|
|
|
|
luaX_next(ls); |
|
|
|
|
|
init_exp(v, VUNDEF, 0); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
default: { |
|
|
default: { |
|
|
luaX_syntaxerror(ls, "unexpected symbol"); |
|
|
luaX_syntaxerror(ls, "unexpected symbol"); |
|
|
} |
|
|
} |
|
@ -1185,6 +1183,10 @@ static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) { |
|
|
else { /* assignment -> '=' explist */ |
|
|
else { /* assignment -> '=' explist */ |
|
|
int nexps; |
|
|
int nexps; |
|
|
checknext(ls, '='); |
|
|
checknext(ls, '='); |
|
|
|
|
|
if (nvars == 1 && testnext(ls, TK_UNDEF)) { |
|
|
|
|
|
luaK_codeundef(ls->fs, &lh->v); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
nexps = explist(ls, &e); |
|
|
nexps = explist(ls, &e); |
|
|
if (nexps != nvars) |
|
|
if (nexps != nvars) |
|
|
adjust_assign(ls, nvars, nexps, &e); |
|
|
adjust_assign(ls, nvars, nexps, &e); |
|
@ -1237,7 +1239,7 @@ static void checkrepeated (FuncState *fs, Labellist *ll, TString *label) { |
|
|
const char *msg = luaO_pushfstring(fs->ls->L, |
|
|
const char *msg = luaO_pushfstring(fs->ls->L, |
|
|
"label '%s' already defined on line %d", |
|
|
"label '%s' already defined on line %d", |
|
|
getstr(label), ll->arr[i].line); |
|
|
getstr(label), ll->arr[i].line); |
|
|
semerror(fs->ls, msg); |
|
|
luaK_semerror(fs->ls, msg); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -1650,6 +1652,11 @@ static void statement (LexState *ls) { |
|
|
luaX_next(ls); /* skip LOCAL */ |
|
|
luaX_next(ls); /* skip LOCAL */ |
|
|
if (testnext(ls, TK_FUNCTION)) /* local function? */ |
|
|
if (testnext(ls, TK_FUNCTION)) /* local function? */ |
|
|
localfunc(ls); |
|
|
localfunc(ls); |
|
|
|
|
|
else if (testnext(ls, TK_UNDEF)) |
|
|
|
|
|
(void)0; /* ignore */ |
|
|
|
|
|
/* old versions may need to declare 'local undef'
|
|
|
|
|
|
when using 'undef' with no environment; so this |
|
|
|
|
|
version accepts (and ignores) these declarations */ |
|
|
else |
|
|
else |
|
|
localstat(ls); |
|
|
localstat(ls); |
|
|
break; |
|
|
break; |
|
|