diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-03-11 16:00:12 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-03-11 16:00:12 -0300 |
| commit | c454dc7bdd7f5b30bcd8a691351839b3179fe45c (patch) | |
| tree | 2854379b2e1da815673cb645896935229b188131 /lparser.c | |
| parent | 82ad0d57705dd3be41081118781762b72e334f1b (diff) | |
| download | lua-c454dc7bdd7f5b30bcd8a691351839b3179fe45c.tar.gz lua-c454dc7bdd7f5b30bcd8a691351839b3179fe45c.tar.bz2 lua-c454dc7bdd7f5b30bcd8a691351839b3179fe45c.zip | |
no more if expressions.
Diffstat (limited to 'lparser.c')
| -rw-r--r-- | lparser.c | 31 |
1 files changed, 8 insertions, 23 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 1.27 1999/03/05 21:16:07 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.28 1999/03/10 14:09:45 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 | */ |
| @@ -118,7 +118,7 @@ static void exp1 (LexState *ls); | |||
| 118 | static void exp2 (LexState *ls, vardesc *v); | 118 | static void exp2 (LexState *ls, vardesc *v); |
| 119 | static void explist (LexState *ls, listdesc *e); | 119 | static void explist (LexState *ls, listdesc *e); |
| 120 | static void explist1 (LexState *ls, listdesc *e); | 120 | static void explist1 (LexState *ls, listdesc *e); |
| 121 | static void ifpart (LexState *ls, int isexp, int line); | 121 | static void ifpart (LexState *ls, int line); |
| 122 | static void parlist (LexState *ls); | 122 | static void parlist (LexState *ls); |
| 123 | static void part (LexState *ls, constdesc *cd); | 123 | static void part (LexState *ls, constdesc *cd); |
| 124 | static void recfield (LexState *ls); | 124 | static void recfield (LexState *ls); |
| @@ -684,7 +684,7 @@ static int stat (LexState *ls) { | |||
| 684 | FuncState *fs = ls->fs; | 684 | FuncState *fs = ls->fs; |
| 685 | switch (ls->token) { | 685 | switch (ls->token) { |
| 686 | case IF: /* stat -> IF ifpart END */ | 686 | case IF: /* stat -> IF ifpart END */ |
| 687 | ifpart(ls, 0, line); | 687 | ifpart(ls, line); |
| 688 | return 1; | 688 | return 1; |
| 689 | 689 | ||
| 690 | case WHILE: { /* stat -> WHILE cond DO block END */ | 690 | case WHILE: { /* stat -> WHILE cond DO block END */ |
| @@ -833,31 +833,20 @@ static void body (LexState *ls, int needself, int line) { | |||
| 833 | } | 833 | } |
| 834 | 834 | ||
| 835 | 835 | ||
| 836 | static void ifpart (LexState *ls, int isexp, int line) { | 836 | static void ifpart (LexState *ls, int line) { |
| 837 | /* ifpart -> cond THEN block [ELSE block | ELSEIF ifpart] */ | 837 | /* ifpart -> cond THEN block [ELSE block | ELSEIF ifpart] */ |
| 838 | /* ifpart -> cond THEN exp [ELSE exp | ELSEIF ifpart] */ | ||
| 839 | int c; | 838 | int c; |
| 840 | int e; | 839 | int e; |
| 841 | next(ls); /* skip IF or ELSEIF */ | 840 | next(ls); /* skip IF or ELSEIF */ |
| 842 | c = cond(ls); | 841 | c = cond(ls); |
| 843 | check(ls, THEN); | 842 | check(ls, THEN); |
| 844 | if (isexp) { | 843 | block(ls); |
| 845 | exp1(ls); | ||
| 846 | deltastack(ls, -1); /* only 'then' x-or 'else' will stay on the stack */ | ||
| 847 | } | ||
| 848 | else block(ls); | ||
| 849 | e = SaveWord(ls); | 844 | e = SaveWord(ls); |
| 850 | if (ls->token == ELSEIF) | 845 | if (ls->token == ELSEIF) |
| 851 | ifpart(ls, isexp, line); | 846 | ifpart(ls, line); |
| 852 | else { | 847 | else { |
| 853 | int elsepart = optional(ls, ELSE); | 848 | if (optional(ls, ELSE)) |
| 854 | if (!isexp) { | 849 | block(ls); |
| 855 | if (elsepart) block(ls); | ||
| 856 | } | ||
| 857 | else { /* is exp */ | ||
| 858 | if (elsepart) exp1(ls); | ||
| 859 | else adjuststack(ls, -1); /* empty else exp -> push nil */ | ||
| 860 | } | ||
| 861 | check_match(ls, END, IF, line); | 850 | check_match(ls, END, IF, line); |
| 862 | } | 851 | } |
| 863 | codeIf(ls, c, e); | 852 | codeIf(ls, c, e); |
| @@ -991,10 +980,6 @@ static void simpleexp (LexState *ls, vardesc *v, stack_op *s) { | |||
| 991 | body(ls, 0, ls->linenumber); | 980 | body(ls, 0, ls->linenumber); |
| 992 | break; | 981 | break; |
| 993 | 982 | ||
| 994 | case IF: /* simpleexp -> IF ifpart END */ | ||
| 995 | ifpart(ls, 1, ls->linenumber); | ||
| 996 | break; | ||
| 997 | |||
| 998 | case '(': /* simpleexp -> '(' exp0 ')' */ | 983 | case '(': /* simpleexp -> '(' exp0 ')' */ |
| 999 | next(ls); | 984 | next(ls); |
| 1000 | exp0(ls, v); | 985 | exp0(ls, v); |
