diff options
| -rw-r--r-- | bugs | 6 | ||||
| -rw-r--r-- | llex.c | 28 | ||||
| -rw-r--r-- | llex.h | 16 | ||||
| -rw-r--r-- | lparser.c | 6 |
4 files changed, 33 insertions, 23 deletions
| @@ -223,3 +223,9 @@ Wed Sep 27 09:50:19 EST 2000 | |||
| 223 | >> lua_tag should return LUA_NOTAG for non-valid indices | 223 | >> lua_tag should return LUA_NOTAG for non-valid indices |
| 224 | (by Paul Hankin; since 4.0b) | 224 | (by Paul Hankin; since 4.0b) |
| 225 | 225 | ||
| 226 | ** llex.h / llex.c / lparser.c | ||
| 227 | Wed Sep 27 13:39:45 EST 2000 | ||
| 228 | >> parser overwrites semantic information when looking ahead | ||
| 229 | >> (e.g. «a = {print'foo'}») | ||
| 230 | (by Edgar Toernig; since 4.0b, deriving from previous bug) | ||
| 231 | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.c,v 1.69 2000/09/11 17:38:42 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 1.70 2000/09/11 20:29:27 roberto Exp roberto $ |
| 3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -58,7 +58,7 @@ void luaX_checklimit (LexState *ls, int val, int limit, const char *msg) { | |||
| 58 | void luaX_syntaxerror (LexState *ls, const char *s, const char *token) { | 58 | void luaX_syntaxerror (LexState *ls, const char *s, const char *token) { |
| 59 | char buff[MAXSRC]; | 59 | char buff[MAXSRC]; |
| 60 | luaO_chunkid(buff, ls->source->str, sizeof(buff)); | 60 | luaO_chunkid(buff, ls->source->str, sizeof(buff)); |
| 61 | luaO_verror(ls->L, "%.100s;\n last token read: `%.50s' at line %d in %.80s", | 61 | luaO_verror(ls->L, "%.99s;\n last token read: `%.50s' at line %d in %.80s", |
| 62 | s, token, ls->linenumber, buff); | 62 | s, token, ls->linenumber, buff); |
| 63 | } | 63 | } |
| 64 | 64 | ||
| @@ -146,7 +146,7 @@ static const char *readname (LexState *LS) { | |||
| 146 | 146 | ||
| 147 | 147 | ||
| 148 | /* LUA_NUMBER */ | 148 | /* LUA_NUMBER */ |
| 149 | static void read_number (LexState *LS, int comma) { | 149 | static void read_number (LexState *LS, int comma, SemInfo *seminfo) { |
| 150 | lua_State *L = LS->L; | 150 | lua_State *L = LS->L; |
| 151 | size_t l = 0; | 151 | size_t l = 0; |
| 152 | checkbuffer(L, 10, l); | 152 | checkbuffer(L, 10, l); |
| @@ -178,12 +178,12 @@ static void read_number (LexState *LS, int comma) { | |||
| 178 | } | 178 | } |
| 179 | } | 179 | } |
| 180 | save(L, '\0', l); | 180 | save(L, '\0', l); |
| 181 | if (!luaO_str2d(L->Mbuffer, &LS->t.seminfo.r)) | 181 | if (!luaO_str2d(L->Mbuffer, &seminfo->r)) |
| 182 | luaX_error(LS, "malformed number", TK_NUMBER); | 182 | luaX_error(LS, "malformed number", TK_NUMBER); |
| 183 | } | 183 | } |
| 184 | 184 | ||
| 185 | 185 | ||
| 186 | static void read_long_string (LexState *LS) { | 186 | static void read_long_string (LexState *LS, SemInfo *seminfo) { |
| 187 | lua_State *L = LS->L; | 187 | lua_State *L = LS->L; |
| 188 | int cont = 0; | 188 | int cont = 0; |
| 189 | size_t l = 0; | 189 | size_t l = 0; |
| @@ -222,11 +222,11 @@ static void read_long_string (LexState *LS) { | |||
| 222 | } endloop: | 222 | } endloop: |
| 223 | save_and_next(L, LS, l); /* skip the second ']' */ | 223 | save_and_next(L, LS, l); /* skip the second ']' */ |
| 224 | save(L, '\0', l); | 224 | save(L, '\0', l); |
| 225 | LS->t.seminfo.ts = luaS_newlstr(L, L->Mbuffer+2, l-5); | 225 | seminfo->ts = luaS_newlstr(L, L->Mbuffer+2, l-5); |
| 226 | } | 226 | } |
| 227 | 227 | ||
| 228 | 228 | ||
| 229 | static void read_string (LexState *LS, int del) { | 229 | static void read_string (LexState *LS, int del, SemInfo *seminfo) { |
| 230 | lua_State *L = LS->L; | 230 | lua_State *L = LS->L; |
| 231 | size_t l = 0; | 231 | size_t l = 0; |
| 232 | checkbuffer(L, 10, l); | 232 | checkbuffer(L, 10, l); |
| @@ -274,11 +274,11 @@ static void read_string (LexState *LS, int del) { | |||
| 274 | } | 274 | } |
| 275 | save_and_next(L, LS, l); /* skip delimiter */ | 275 | save_and_next(L, LS, l); /* skip delimiter */ |
| 276 | save(L, '\0', l); | 276 | save(L, '\0', l); |
| 277 | LS->t.seminfo.ts = luaS_newlstr(L, L->Mbuffer+1, l-3); | 277 | seminfo->ts = luaS_newlstr(L, L->Mbuffer+1, l-3); |
| 278 | } | 278 | } |
| 279 | 279 | ||
| 280 | 280 | ||
| 281 | int luaX_lex (LexState *LS) { | 281 | int luaX_lex (LexState *LS, SemInfo *seminfo) { |
| 282 | for (;;) { | 282 | for (;;) { |
| 283 | switch (LS->current) { | 283 | switch (LS->current) { |
| 284 | 284 | ||
| @@ -304,7 +304,7 @@ int luaX_lex (LexState *LS) { | |||
| 304 | next(LS); | 304 | next(LS); |
| 305 | if (LS->current != '[') return '['; | 305 | if (LS->current != '[') return '['; |
| 306 | else { | 306 | else { |
| 307 | read_long_string(LS); | 307 | read_long_string(LS, seminfo); |
| 308 | return TK_STRING; | 308 | return TK_STRING; |
| 309 | } | 309 | } |
| 310 | 310 | ||
| @@ -330,7 +330,7 @@ int luaX_lex (LexState *LS) { | |||
| 330 | 330 | ||
| 331 | case '"': | 331 | case '"': |
| 332 | case '\'': | 332 | case '\'': |
| 333 | read_string(LS, LS->current); | 333 | read_string(LS, LS->current, seminfo); |
| 334 | return TK_STRING; | 334 | return TK_STRING; |
| 335 | 335 | ||
| 336 | case '.': | 336 | case '.': |
| @@ -345,13 +345,13 @@ int luaX_lex (LexState *LS) { | |||
| 345 | } | 345 | } |
| 346 | else if (!isdigit(LS->current)) return '.'; | 346 | else if (!isdigit(LS->current)) return '.'; |
| 347 | else { | 347 | else { |
| 348 | read_number(LS, 1); | 348 | read_number(LS, 1, seminfo); |
| 349 | return TK_NUMBER; | 349 | return TK_NUMBER; |
| 350 | } | 350 | } |
| 351 | 351 | ||
| 352 | case '0': case '1': case '2': case '3': case '4': | 352 | case '0': case '1': case '2': case '3': case '4': |
| 353 | case '5': case '6': case '7': case '8': case '9': | 353 | case '5': case '6': case '7': case '8': case '9': |
| 354 | read_number(LS, 0); | 354 | read_number(LS, 0, seminfo); |
| 355 | return TK_NUMBER; | 355 | return TK_NUMBER; |
| 356 | 356 | ||
| 357 | case EOZ: | 357 | case EOZ: |
| @@ -371,7 +371,7 @@ int luaX_lex (LexState *LS) { | |||
| 371 | TString *ts = luaS_new(LS->L, readname(LS)); | 371 | TString *ts = luaS_new(LS->L, readname(LS)); |
| 372 | if (ts->marked >= RESERVEDMARK) /* reserved word? */ | 372 | if (ts->marked >= RESERVEDMARK) /* reserved word? */ |
| 373 | return ts->marked-RESERVEDMARK+FIRST_RESERVED; | 373 | return ts->marked-RESERVEDMARK+FIRST_RESERVED; |
| 374 | LS->t.seminfo.ts = ts; | 374 | seminfo->ts = ts; |
| 375 | return TK_NAME; | 375 | return TK_NAME; |
| 376 | } | 376 | } |
| 377 | } | 377 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.h,v 1.29 2000/06/19 18:05:14 roberto Exp roberto $ | 2 | ** $Id: llex.h,v 1.30 2000/06/21 18:13:56 roberto Exp roberto $ |
| 3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -35,14 +35,18 @@ enum RESERVED { | |||
| 35 | #define NUM_RESERVED ((int)(TK_WHILE-FIRST_RESERVED+1)) | 35 | #define NUM_RESERVED ((int)(TK_WHILE-FIRST_RESERVED+1)) |
| 36 | 36 | ||
| 37 | 37 | ||
| 38 | typedef union { | ||
| 39 | Number r; | ||
| 40 | TString *ts; | ||
| 41 | } SemInfo; /* semantics information */ | ||
| 42 | |||
| 43 | |||
| 38 | typedef struct Token { | 44 | typedef struct Token { |
| 39 | int token; | 45 | int token; |
| 40 | union { | 46 | SemInfo seminfo; |
| 41 | Number r; | ||
| 42 | TString *ts; | ||
| 43 | } seminfo; /* semantics information */ | ||
| 44 | } Token; | 47 | } Token; |
| 45 | 48 | ||
| 49 | |||
| 46 | typedef struct LexState { | 50 | typedef struct LexState { |
| 47 | int current; /* current character */ | 51 | int current; /* current character */ |
| 48 | Token t; /* current token */ | 52 | Token t; /* current token */ |
| @@ -58,7 +62,7 @@ typedef struct LexState { | |||
| 58 | 62 | ||
| 59 | void luaX_init (lua_State *L); | 63 | void luaX_init (lua_State *L); |
| 60 | void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source); | 64 | void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source); |
| 61 | int luaX_lex (LexState *LS); | 65 | int luaX_lex (LexState *LS, SemInfo *seminfo); |
| 62 | void luaX_checklimit (LexState *ls, int val, int limit, const char *msg); | 66 | void luaX_checklimit (LexState *ls, int val, int limit, const char *msg); |
| 63 | void luaX_syntaxerror (LexState *ls, const char *s, const char *token); | 67 | void luaX_syntaxerror (LexState *ls, const char *s, const char *token); |
| 64 | void luaX_error (LexState *ls, const char *s, int token); | 68 | void luaX_error (LexState *ls, const char *s, int token); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 1.111 2000/08/31 14:08:27 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.112 2000/09/20 17:57:08 roberto Exp roberto $ |
| 3 | ** LL(1) Parser and code generator for Lua | 3 | ** LL(1) Parser and code generator for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -60,13 +60,13 @@ static void next (LexState *ls) { | |||
| 60 | ls->lookahead.token = TK_EOS; /* and discharge it */ | 60 | ls->lookahead.token = TK_EOS; /* and discharge it */ |
| 61 | } | 61 | } |
| 62 | else | 62 | else |
| 63 | ls->t.token = luaX_lex(ls); /* read next token */ | 63 | ls->t.token = luaX_lex(ls, &ls->t.seminfo); /* read next token */ |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | 66 | ||
| 67 | static void lookahead (LexState *ls) { | 67 | static void lookahead (LexState *ls) { |
| 68 | LUA_ASSERT(ls->lookahead.token == TK_EOS, "two look-aheads"); | 68 | LUA_ASSERT(ls->lookahead.token == TK_EOS, "two look-aheads"); |
| 69 | ls->lookahead.token = luaX_lex(ls); | 69 | ls->lookahead.token = luaX_lex(ls, &ls->lookahead.seminfo); |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | 72 | ||
