diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-05-25 15:59:59 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-05-25 15:59:59 -0300 |
commit | 58fbdc76d558c8039a966852ca07802f0a413b11 (patch) | |
tree | f0de4a6d4ed8e7dc88d476b9f5348e353f05f6eb /lparser.c | |
parent | a3013046121b186bf4b5e54b247d3209fd76de5a (diff) | |
download | lua-58fbdc76d558c8039a966852ca07802f0a413b11.tar.gz lua-58fbdc76d558c8039a966852ca07802f0a413b11.tar.bz2 lua-58fbdc76d558c8039a966852ca07802f0a413b11.zip |
better implementation for looh-ahead
Diffstat (limited to 'lparser.c')
-rw-r--r-- | lparser.c | 23 |
1 files changed, 9 insertions, 14 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 1.90 2000/05/24 18:04:17 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.91 2000/05/25 18:26:42 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 | */ |
@@ -56,18 +56,18 @@ static void exp1 (LexState *ls); | |||
56 | 56 | ||
57 | 57 | ||
58 | static void next (LexState *ls) { | 58 | static void next (LexState *ls) { |
59 | if (ls->next.token != TK_EOS) { /* is there an `unget' token? */ | 59 | if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */ |
60 | ls->t = ls->next; /* use this one */ | 60 | ls->t = ls->lookahead; /* use this one */ |
61 | ls->next.token = TK_EOS; /* and discharge it */ | 61 | ls->lookahead.token = TK_EOS; /* and discharge it */ |
62 | } | 62 | } |
63 | else | 63 | else |
64 | ls->t.token = luaX_lex(ls); /* read next token */ | 64 | ls->t.token = luaX_lex(ls); /* read next token */ |
65 | } | 65 | } |
66 | 66 | ||
67 | 67 | ||
68 | static void ungettoken (LexState *ls, Token *t) { | 68 | static void lookahead (LexState *ls) { |
69 | ls->next = ls->t; | 69 | LUA_ASSERT(ls->L, ls->lookahead.token == TK_EOS, "two look-aheads"); |
70 | ls->t = *t; | 70 | ls->lookahead.token = luaX_lex(ls); |
71 | } | 71 | } |
72 | 72 | ||
73 | 73 | ||
@@ -633,13 +633,8 @@ static void constructor_part (LexState *ls, Constdesc *cd) { | |||
633 | break; | 633 | break; |
634 | } | 634 | } |
635 | case TK_NAME: { /* may be listfields or recfields */ | 635 | case TK_NAME: { /* may be listfields or recfields */ |
636 | Token current; | 636 | lookahead(ls); |
637 | int nexttoken; /* to get the look ahead */ | 637 | if (ls->lookahead.token != '=') /* expression? */ |
638 | current = ls->t; /* save for `unget' */ | ||
639 | next(ls); | ||
640 | nexttoken = ls->t.token; | ||
641 | ungettoken(ls, ¤t); | ||
642 | if (nexttoken != '=') /* expression? */ | ||
643 | goto case_default; | 638 | goto case_default; |
644 | /* else go through to recfields */ | 639 | /* else go through to recfields */ |
645 | } | 640 | } |