mirror of https://github.com/rusefi/lua.git
bug: parser overwrites semantic information when looking ahead
This commit is contained in:
parent
444d6a106b
commit
282ab366f4
6
bugs
6
bugs
|
@ -223,3 +223,9 @@ Wed Sep 27 09:50:19 EST 2000
|
|||
>> lua_tag should return LUA_NOTAG for non-valid indices
|
||||
(by Paul Hankin; since 4.0b)
|
||||
|
||||
** llex.h / llex.c / lparser.c
|
||||
Wed Sep 27 13:39:45 EST 2000
|
||||
>> parser overwrites semantic information when looking ahead
|
||||
>> (e.g. «a = {print'foo'}»)
|
||||
(by Edgar Toernig; since 4.0b, deriving from previous bug)
|
||||
|
||||
|
|
28
llex.c
28
llex.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: llex.c,v 1.69 2000/09/11 17:38:42 roberto Exp roberto $
|
||||
** $Id: llex.c,v 1.70 2000/09/11 20:29:27 roberto Exp roberto $
|
||||
** Lexical Analyzer
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -58,7 +58,7 @@ void luaX_checklimit (LexState *ls, int val, int limit, const char *msg) {
|
|||
void luaX_syntaxerror (LexState *ls, const char *s, const char *token) {
|
||||
char buff[MAXSRC];
|
||||
luaO_chunkid(buff, ls->source->str, sizeof(buff));
|
||||
luaO_verror(ls->L, "%.100s;\n last token read: `%.50s' at line %d in %.80s",
|
||||
luaO_verror(ls->L, "%.99s;\n last token read: `%.50s' at line %d in %.80s",
|
||||
s, token, ls->linenumber, buff);
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,7 @@ static const char *readname (LexState *LS) {
|
|||
|
||||
|
||||
/* LUA_NUMBER */
|
||||
static void read_number (LexState *LS, int comma) {
|
||||
static void read_number (LexState *LS, int comma, SemInfo *seminfo) {
|
||||
lua_State *L = LS->L;
|
||||
size_t l = 0;
|
||||
checkbuffer(L, 10, l);
|
||||
|
@ -178,12 +178,12 @@ static void read_number (LexState *LS, int comma) {
|
|||
}
|
||||
}
|
||||
save(L, '\0', l);
|
||||
if (!luaO_str2d(L->Mbuffer, &LS->t.seminfo.r))
|
||||
if (!luaO_str2d(L->Mbuffer, &seminfo->r))
|
||||
luaX_error(LS, "malformed number", TK_NUMBER);
|
||||
}
|
||||
|
||||
|
||||
static void read_long_string (LexState *LS) {
|
||||
static void read_long_string (LexState *LS, SemInfo *seminfo) {
|
||||
lua_State *L = LS->L;
|
||||
int cont = 0;
|
||||
size_t l = 0;
|
||||
|
@ -222,11 +222,11 @@ static void read_long_string (LexState *LS) {
|
|||
} endloop:
|
||||
save_and_next(L, LS, l); /* skip the second ']' */
|
||||
save(L, '\0', l);
|
||||
LS->t.seminfo.ts = luaS_newlstr(L, L->Mbuffer+2, l-5);
|
||||
seminfo->ts = luaS_newlstr(L, L->Mbuffer+2, l-5);
|
||||
}
|
||||
|
||||
|
||||
static void read_string (LexState *LS, int del) {
|
||||
static void read_string (LexState *LS, int del, SemInfo *seminfo) {
|
||||
lua_State *L = LS->L;
|
||||
size_t l = 0;
|
||||
checkbuffer(L, 10, l);
|
||||
|
@ -274,11 +274,11 @@ static void read_string (LexState *LS, int del) {
|
|||
}
|
||||
save_and_next(L, LS, l); /* skip delimiter */
|
||||
save(L, '\0', l);
|
||||
LS->t.seminfo.ts = luaS_newlstr(L, L->Mbuffer+1, l-3);
|
||||
seminfo->ts = luaS_newlstr(L, L->Mbuffer+1, l-3);
|
||||
}
|
||||
|
||||
|
||||
int luaX_lex (LexState *LS) {
|
||||
int luaX_lex (LexState *LS, SemInfo *seminfo) {
|
||||
for (;;) {
|
||||
switch (LS->current) {
|
||||
|
||||
|
@ -304,7 +304,7 @@ int luaX_lex (LexState *LS) {
|
|||
next(LS);
|
||||
if (LS->current != '[') return '[';
|
||||
else {
|
||||
read_long_string(LS);
|
||||
read_long_string(LS, seminfo);
|
||||
return TK_STRING;
|
||||
}
|
||||
|
||||
|
@ -330,7 +330,7 @@ int luaX_lex (LexState *LS) {
|
|||
|
||||
case '"':
|
||||
case '\'':
|
||||
read_string(LS, LS->current);
|
||||
read_string(LS, LS->current, seminfo);
|
||||
return TK_STRING;
|
||||
|
||||
case '.':
|
||||
|
@ -345,13 +345,13 @@ int luaX_lex (LexState *LS) {
|
|||
}
|
||||
else if (!isdigit(LS->current)) return '.';
|
||||
else {
|
||||
read_number(LS, 1);
|
||||
read_number(LS, 1, seminfo);
|
||||
return TK_NUMBER;
|
||||
}
|
||||
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
read_number(LS, 0);
|
||||
read_number(LS, 0, seminfo);
|
||||
return TK_NUMBER;
|
||||
|
||||
case EOZ:
|
||||
|
@ -371,7 +371,7 @@ int luaX_lex (LexState *LS) {
|
|||
TString *ts = luaS_new(LS->L, readname(LS));
|
||||
if (ts->marked >= RESERVEDMARK) /* reserved word? */
|
||||
return ts->marked-RESERVEDMARK+FIRST_RESERVED;
|
||||
LS->t.seminfo.ts = ts;
|
||||
seminfo->ts = ts;
|
||||
return TK_NAME;
|
||||
}
|
||||
}
|
||||
|
|
16
llex.h
16
llex.h
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: llex.h,v 1.29 2000/06/19 18:05:14 roberto Exp roberto $
|
||||
** $Id: llex.h,v 1.30 2000/06/21 18:13:56 roberto Exp roberto $
|
||||
** Lexical Analyzer
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -35,14 +35,18 @@ enum RESERVED {
|
|||
#define NUM_RESERVED ((int)(TK_WHILE-FIRST_RESERVED+1))
|
||||
|
||||
|
||||
typedef union {
|
||||
Number r;
|
||||
TString *ts;
|
||||
} SemInfo; /* semantics information */
|
||||
|
||||
|
||||
typedef struct Token {
|
||||
int token;
|
||||
union {
|
||||
Number r;
|
||||
TString *ts;
|
||||
} seminfo; /* semantics information */
|
||||
SemInfo seminfo;
|
||||
} Token;
|
||||
|
||||
|
||||
typedef struct LexState {
|
||||
int current; /* current character */
|
||||
Token t; /* current token */
|
||||
|
@ -58,7 +62,7 @@ typedef struct LexState {
|
|||
|
||||
void luaX_init (lua_State *L);
|
||||
void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source);
|
||||
int luaX_lex (LexState *LS);
|
||||
int luaX_lex (LexState *LS, SemInfo *seminfo);
|
||||
void luaX_checklimit (LexState *ls, int val, int limit, const char *msg);
|
||||
void luaX_syntaxerror (LexState *ls, const char *s, const char *token);
|
||||
void luaX_error (LexState *ls, const char *s, int token);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lparser.c,v 1.111 2000/08/31 14:08:27 roberto Exp roberto $
|
||||
** $Id: lparser.c,v 1.112 2000/09/20 17:57:08 roberto Exp roberto $
|
||||
** LL(1) Parser and code generator for Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -60,13 +60,13 @@ static void next (LexState *ls) {
|
|||
ls->lookahead.token = TK_EOS; /* and discharge it */
|
||||
}
|
||||
else
|
||||
ls->t.token = luaX_lex(ls); /* read next token */
|
||||
ls->t.token = luaX_lex(ls, &ls->t.seminfo); /* read next token */
|
||||
}
|
||||
|
||||
|
||||
static void lookahead (LexState *ls) {
|
||||
LUA_ASSERT(ls->lookahead.token == TK_EOS, "two look-aheads");
|
||||
ls->lookahead.token = luaX_lex(ls);
|
||||
ls->lookahead.token = luaX_lex(ls, &ls->lookahead.seminfo);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue