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
|
>> lua_tag should return LUA_NOTAG for non-valid indices
|
||||||
(by Paul Hankin; since 4.0b)
|
(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
|
** Lexical Analyzer
|
||||||
** See Copyright Notice in lua.h
|
** 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) {
|
void luaX_syntaxerror (LexState *ls, const char *s, const char *token) {
|
||||||
char buff[MAXSRC];
|
char buff[MAXSRC];
|
||||||
luaO_chunkid(buff, ls->source->str, sizeof(buff));
|
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);
|
s, token, ls->linenumber, buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ static const char *readname (LexState *LS) {
|
||||||
|
|
||||||
|
|
||||||
/* LUA_NUMBER */
|
/* 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;
|
lua_State *L = LS->L;
|
||||||
size_t l = 0;
|
size_t l = 0;
|
||||||
checkbuffer(L, 10, l);
|
checkbuffer(L, 10, l);
|
||||||
|
@ -178,12 +178,12 @@ static void read_number (LexState *LS, int comma) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
save(L, '\0', l);
|
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);
|
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;
|
lua_State *L = LS->L;
|
||||||
int cont = 0;
|
int cont = 0;
|
||||||
size_t l = 0;
|
size_t l = 0;
|
||||||
|
@ -222,11 +222,11 @@ static void read_long_string (LexState *LS) {
|
||||||
} endloop:
|
} endloop:
|
||||||
save_and_next(L, LS, l); /* skip the second ']' */
|
save_and_next(L, LS, l); /* skip the second ']' */
|
||||||
save(L, '\0', l);
|
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;
|
lua_State *L = LS->L;
|
||||||
size_t l = 0;
|
size_t l = 0;
|
||||||
checkbuffer(L, 10, l);
|
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_and_next(L, LS, l); /* skip delimiter */
|
||||||
save(L, '\0', l);
|
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 (;;) {
|
for (;;) {
|
||||||
switch (LS->current) {
|
switch (LS->current) {
|
||||||
|
|
||||||
|
@ -304,7 +304,7 @@ int luaX_lex (LexState *LS) {
|
||||||
next(LS);
|
next(LS);
|
||||||
if (LS->current != '[') return '[';
|
if (LS->current != '[') return '[';
|
||||||
else {
|
else {
|
||||||
read_long_string(LS);
|
read_long_string(LS, seminfo);
|
||||||
return TK_STRING;
|
return TK_STRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,7 +330,7 @@ int luaX_lex (LexState *LS) {
|
||||||
|
|
||||||
case '"':
|
case '"':
|
||||||
case '\'':
|
case '\'':
|
||||||
read_string(LS, LS->current);
|
read_string(LS, LS->current, seminfo);
|
||||||
return TK_STRING;
|
return TK_STRING;
|
||||||
|
|
||||||
case '.':
|
case '.':
|
||||||
|
@ -345,13 +345,13 @@ int luaX_lex (LexState *LS) {
|
||||||
}
|
}
|
||||||
else if (!isdigit(LS->current)) return '.';
|
else if (!isdigit(LS->current)) return '.';
|
||||||
else {
|
else {
|
||||||
read_number(LS, 1);
|
read_number(LS, 1, seminfo);
|
||||||
return TK_NUMBER;
|
return TK_NUMBER;
|
||||||
}
|
}
|
||||||
|
|
||||||
case '0': case '1': case '2': case '3': case '4':
|
case '0': case '1': case '2': case '3': case '4':
|
||||||
case '5': case '6': case '7': case '8': case '9':
|
case '5': case '6': case '7': case '8': case '9':
|
||||||
read_number(LS, 0);
|
read_number(LS, 0, seminfo);
|
||||||
return TK_NUMBER;
|
return TK_NUMBER;
|
||||||
|
|
||||||
case EOZ:
|
case EOZ:
|
||||||
|
@ -371,7 +371,7 @@ int luaX_lex (LexState *LS) {
|
||||||
TString *ts = luaS_new(LS->L, readname(LS));
|
TString *ts = luaS_new(LS->L, readname(LS));
|
||||||
if (ts->marked >= RESERVEDMARK) /* reserved word? */
|
if (ts->marked >= RESERVEDMARK) /* reserved word? */
|
||||||
return ts->marked-RESERVEDMARK+FIRST_RESERVED;
|
return ts->marked-RESERVEDMARK+FIRST_RESERVED;
|
||||||
LS->t.seminfo.ts = ts;
|
seminfo->ts = ts;
|
||||||
return TK_NAME;
|
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
|
** Lexical Analyzer
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -35,14 +35,18 @@ enum RESERVED {
|
||||||
#define NUM_RESERVED ((int)(TK_WHILE-FIRST_RESERVED+1))
|
#define NUM_RESERVED ((int)(TK_WHILE-FIRST_RESERVED+1))
|
||||||
|
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
Number r;
|
||||||
|
TString *ts;
|
||||||
|
} SemInfo; /* semantics information */
|
||||||
|
|
||||||
|
|
||||||
typedef struct Token {
|
typedef struct Token {
|
||||||
int token;
|
int token;
|
||||||
union {
|
SemInfo seminfo;
|
||||||
Number r;
|
|
||||||
TString *ts;
|
|
||||||
} seminfo; /* semantics information */
|
|
||||||
} Token;
|
} Token;
|
||||||
|
|
||||||
|
|
||||||
typedef struct LexState {
|
typedef struct LexState {
|
||||||
int current; /* current character */
|
int current; /* current character */
|
||||||
Token t; /* current token */
|
Token t; /* current token */
|
||||||
|
@ -58,7 +62,7 @@ typedef struct LexState {
|
||||||
|
|
||||||
void luaX_init (lua_State *L);
|
void luaX_init (lua_State *L);
|
||||||
void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source);
|
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_checklimit (LexState *ls, int val, int limit, const char *msg);
|
||||||
void luaX_syntaxerror (LexState *ls, const char *s, const char *token);
|
void luaX_syntaxerror (LexState *ls, const char *s, const char *token);
|
||||||
void luaX_error (LexState *ls, const char *s, int 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
|
** LL(1) Parser and code generator for Lua
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -60,13 +60,13 @@ static void next (LexState *ls) {
|
||||||
ls->lookahead.token = TK_EOS; /* and discharge it */
|
ls->lookahead.token = TK_EOS; /* and discharge it */
|
||||||
}
|
}
|
||||||
else
|
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) {
|
static void lookahead (LexState *ls) {
|
||||||
LUA_ASSERT(ls->lookahead.token == TK_EOS, "two look-aheads");
|
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