diff --git a/lparser.c b/lparser.c index 91f585f0..8f3f7efb 100644 --- a/lparser.c +++ b/lparser.c @@ -1,5 +1,5 @@ /* -** $Id: lparser.c,v 1.27 1999/03/05 21:16:07 roberto Exp roberto $ +** $Id: lparser.c,v 1.28 1999/03/10 14:09:45 roberto Exp roberto $ ** LL(1) Parser and code generator for Lua ** See Copyright Notice in lua.h */ @@ -118,7 +118,7 @@ static void exp1 (LexState *ls); static void exp2 (LexState *ls, vardesc *v); static void explist (LexState *ls, listdesc *e); static void explist1 (LexState *ls, listdesc *e); -static void ifpart (LexState *ls, int isexp, int line); +static void ifpart (LexState *ls, int line); static void parlist (LexState *ls); static void part (LexState *ls, constdesc *cd); static void recfield (LexState *ls); @@ -684,7 +684,7 @@ static int stat (LexState *ls) { FuncState *fs = ls->fs; switch (ls->token) { case IF: /* stat -> IF ifpart END */ - ifpart(ls, 0, line); + ifpart(ls, line); return 1; case WHILE: { /* stat -> WHILE cond DO block END */ @@ -833,31 +833,20 @@ static void body (LexState *ls, int needself, int line) { } -static void ifpart (LexState *ls, int isexp, int line) { +static void ifpart (LexState *ls, int line) { /* ifpart -> cond THEN block [ELSE block | ELSEIF ifpart] */ - /* ifpart -> cond THEN exp [ELSE exp | ELSEIF ifpart] */ int c; int e; next(ls); /* skip IF or ELSEIF */ c = cond(ls); check(ls, THEN); - if (isexp) { - exp1(ls); - deltastack(ls, -1); /* only 'then' x-or 'else' will stay on the stack */ - } - else block(ls); + block(ls); e = SaveWord(ls); if (ls->token == ELSEIF) - ifpart(ls, isexp, line); + ifpart(ls, line); else { - int elsepart = optional(ls, ELSE); - if (!isexp) { - if (elsepart) block(ls); - } - else { /* is exp */ - if (elsepart) exp1(ls); - else adjuststack(ls, -1); /* empty else exp -> push nil */ - } + if (optional(ls, ELSE)) + block(ls); check_match(ls, END, IF, line); } codeIf(ls, c, e); @@ -991,10 +980,6 @@ static void simpleexp (LexState *ls, vardesc *v, stack_op *s) { body(ls, 0, ls->linenumber); break; - case IF: /* simpleexp -> IF ifpart END */ - ifpart(ls, 1, ls->linenumber); - break; - case '(': /* simpleexp -> '(' exp0 ')' */ next(ls); exp0(ls, v); diff --git a/manual.tex b/manual.tex index 373e0e10..3c550cd7 100644 --- a/manual.tex +++ b/manual.tex @@ -1,4 +1,4 @@ -% $Id: manual.tex,v 1.25 1999/03/04 21:23:39 roberto Exp roberto $ +% $Id: manual.tex,v 1.26 1999/03/10 14:09:45 roberto Exp roberto $ \documentclass[11pt]{article} \usepackage{fullpage,bnf} @@ -41,7 +41,7 @@ Waldemar Celes \tecgraf\ --- Computer Science Department --- PUC-Rio } -%\date{\small \verb$Date: 1999/03/04 21:23:39 $} +%\date{\small \verb$Date: 1999/03/10 14:09:45 $} \maketitle @@ -686,17 +686,6 @@ All binary operators are left associative, except for \verb|^| (exponentiation), which is right associative. -\subsubsection{If Expressions} -\begin{Produc} -\produc{exp}{\rwd{if} exp1 \rwd{then} exp1 - \rep{\rwd{elseif} exp1 \rwd{then} exp1} - \opt{\rwd{else} exp1} \rwd{end}} -\end{Produc}% -An \Index{if expression} chooses an expression to evaluate -according to its condition. -Its final value is the value of the chosen expression. -An absent else-part is equivalent to \verb|else nil|. - \subsubsection{Table Constructors} \label{tableconstructor} Table \Index{constructors} are expressions that create tables; every time a constructor is evaluated, a new table is created.