diff options
Diffstat (limited to '')
| -rw-r--r-- | lparser.c | 31 | ||||
| -rw-r--r-- | manual.tex | 15 |
2 files changed, 10 insertions, 36 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); |
| @@ -1,4 +1,4 @@ | |||
| 1 | % $Id: manual.tex,v 1.25 1999/03/04 21:23:39 roberto Exp roberto $ | 1 | % $Id: manual.tex,v 1.26 1999/03/10 14:09:45 roberto Exp roberto $ |
| 2 | 2 | ||
| 3 | \documentclass[11pt]{article} | 3 | \documentclass[11pt]{article} |
| 4 | \usepackage{fullpage,bnf} | 4 | \usepackage{fullpage,bnf} |
| @@ -41,7 +41,7 @@ Waldemar Celes | |||
| 41 | \tecgraf\ --- Computer Science Department --- PUC-Rio | 41 | \tecgraf\ --- Computer Science Department --- PUC-Rio |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | %\date{\small \verb$Date: 1999/03/04 21:23:39 $} | 44 | %\date{\small \verb$Date: 1999/03/10 14:09:45 $} |
| 45 | 45 | ||
| 46 | \maketitle | 46 | \maketitle |
| 47 | 47 | ||
| @@ -686,17 +686,6 @@ All binary operators are left associative, | |||
| 686 | except for \verb|^| (exponentiation), | 686 | except for \verb|^| (exponentiation), |
| 687 | which is right associative. | 687 | which is right associative. |
| 688 | 688 | ||
| 689 | \subsubsection{If Expressions} | ||
| 690 | \begin{Produc} | ||
| 691 | \produc{exp}{\rwd{if} exp1 \rwd{then} exp1 | ||
| 692 | \rep{\rwd{elseif} exp1 \rwd{then} exp1} | ||
| 693 | \opt{\rwd{else} exp1} \rwd{end}} | ||
| 694 | \end{Produc}% | ||
| 695 | An \Index{if expression} chooses an expression to evaluate | ||
| 696 | according to its condition. | ||
| 697 | Its final value is the value of the chosen expression. | ||
| 698 | An absent else-part is equivalent to \verb|else nil|. | ||
| 699 | |||
| 700 | \subsubsection{Table Constructors} \label{tableconstructor} | 689 | \subsubsection{Table Constructors} \label{tableconstructor} |
| 701 | Table \Index{constructors} are expressions that create tables; | 690 | Table \Index{constructors} are expressions that create tables; |
| 702 | every time a constructor is evaluated, a new table is created. | 691 | every time a constructor is evaluated, a new table is created. |
