Skip to content

Commit

Permalink
DIRECTOR: Lingo: Fix mixing of one-line and multi-line ifs
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Aug 3, 2016
1 parent a6ded36 commit 2415a4c
Show file tree
Hide file tree
Showing 6 changed files with 632 additions and 608 deletions.
3 changes: 2 additions & 1 deletion engines/director/director.cpp
Expand Up @@ -110,7 +110,8 @@ Common::Error DirectorEngine::run() {

_lingo->addCode("--\n\
set x = 1\n\
if 5 then exit\n\
if x = 5 then exit\n\
else put 10.0\n\
repeat with x = 1 to 5\n\
if x = 1 then\n\
put 1\n\
Expand Down
812 changes: 411 additions & 401 deletions engines/director/lingo/lingo-gr.cpp

Large diffs are not rendered by default.

32 changes: 17 additions & 15 deletions engines/director/lingo/lingo-gr.h
Expand Up @@ -51,7 +51,7 @@
HANDLER = 267,
tDOWN = 268,
tELSE = 269,
tELSIF = 270,
tNLELSIF = 270,
tEND = 271,
tEXIT = 272,
tFRAME = 273,
Expand All @@ -74,12 +74,13 @@
tTO = 290,
tWITH = 291,
tWHILE = 292,
tGE = 293,
tLE = 294,
tGT = 295,
tLT = 296,
tEQ = 297,
tNEQ = 298
tNLELSE = 293,
tGE = 294,
tLE = 295,
tGT = 296,
tLT = 297,
tEQ = 298,
tNEQ = 299
};
#endif
/* Tokens. */
Expand All @@ -95,7 +96,7 @@
#define HANDLER 267
#define tDOWN 268
#define tELSE 269
#define tELSIF 270
#define tNLELSIF 270
#define tEND 271
#define tEXIT 272
#define tFRAME 273
Expand All @@ -118,12 +119,13 @@
#define tTO 290
#define tWITH 291
#define tWHILE 292
#define tGE 293
#define tLE 294
#define tGT 295
#define tLT 296
#define tEQ 297
#define tNEQ 298
#define tNLELSE 293
#define tGE 294
#define tLE 295
#define tGT 296
#define tLT 297
#define tEQ 298
#define tNEQ 299



Expand All @@ -139,7 +141,7 @@ typedef union YYSTYPE
int narg; /* number of arguments */
}
/* Line 1529 of yacc.c. */
#line 143 "engines/director/lingo/lingo-gr.hpp"
#line 145 "engines/director/lingo/lingo-gr.hpp"
YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
Expand Down
44 changes: 20 additions & 24 deletions engines/director/lingo/lingo-gr.y
Expand Up @@ -74,12 +74,12 @@ using namespace Director;
%token<i> INT
%token<f> FLOAT
%token<s> BLTIN ID STRING HANDLER
%token tDOWN tELSE tELSIF tEND tEXIT tFRAME tGLOBAL tGO tIF tINTO tLOOP tMACRO
%token tDOWN tELSE tNLELSIF tEND tEXIT tFRAME tGLOBAL tGO tIF tINTO tLOOP tMACRO
%token tMCI tMCIWAIT tMOVIE tNEXT tOF tPREVIOUS tPUT tREPEAT tSET tTHEN tTO
%token tWITH tWHILE
%token tWITH tWHILE tNLELSE
%token tGE tLE tGT tLT tEQ tNEQ

%type<code> asgn begin elseif end expr if repeatwhile repeatwith stmtlist
%type<code> asgn begin elseif elsestmt end expr if repeatwhile repeatwith stmtlist
%type<s> gotoframe gotomovie
%type<narg> argdef arglist

Expand Down Expand Up @@ -122,9 +122,10 @@ asgn: tPUT expr tINTO ID {
$$ = $4;
delete $2; }
;

stmt: expr { g_lingo->code1(g_lingo->c_xpop); }
stmtoneliner: expr { g_lingo->code1(g_lingo->c_xpop); }
| func
;
stmt: stmtoneliner
| ifstmt
// repeat while (expression = TRUE)
// statements
Expand Down Expand Up @@ -178,14 +179,6 @@ ifstmt: if cond tTHEN '\n' stmtlist end tEND tIF {
(*g_lingo->_currentScript)[$1 + 1] = then; /* thenpart */
(*g_lingo->_currentScript)[$1 + 3] = end; /* end, if cond fails */
g_lingo->processIf(0, 0); }
| if cond tTHEN begin stmt end '\n' {
inst then = 0, end = 0;
WRITE_UINT32(&then, $4);
WRITE_UINT32(&end, $6);
(*g_lingo->_currentScript)[$1 + 1] = then; /* thenpart */
(*g_lingo->_currentScript)[$1 + 3] = end; /* end, if cond fails */

g_lingo->processIf(0, 0); }
| if cond tTHEN '\n' stmtlist end tELSE stmtlist end tEND tIF {
inst then = 0, else1 = 0, end = 0;
WRITE_UINT32(&then, $5);
Expand All @@ -194,16 +187,6 @@ ifstmt: if cond tTHEN '\n' stmtlist end tEND tIF {
(*g_lingo->_currentScript)[$1 + 1] = then; /* thenpart */
(*g_lingo->_currentScript)[$1 + 2] = else1; /* elsepart */
(*g_lingo->_currentScript)[$1 + 3] = end; /* end, if cond fails */
g_lingo->processIf(0, 0); }
| if cond tTHEN begin stmt end '\n' tELSE begin stmt end '\n' {
inst then = 0, else1 = 0, end = 0;
WRITE_UINT32(&then, $4);
WRITE_UINT32(&else1, $9);
WRITE_UINT32(&end, $11);
(*g_lingo->_currentScript)[$1 + 1] = then; /* thenpart */
(*g_lingo->_currentScript)[$1 + 2] = else1; /* elsepart */
(*g_lingo->_currentScript)[$1 + 3] = end; /* end, if cond fails */

g_lingo->processIf(0, 0); }
| if cond tTHEN '\n' stmtlist end begin elseifstmt end tEND tIF {
inst then = 0, else1 = 0, end = 0;
Expand All @@ -214,6 +197,19 @@ ifstmt: if cond tTHEN '\n' stmtlist end tEND tIF {
(*g_lingo->_currentScript)[$1 + 2] = else1; /* elsepart */
(*g_lingo->_currentScript)[$1 + 3] = end; /* end, if cond fails */
g_lingo->processIf(0, $9); }
| if cond tTHEN begin stmtoneliner end elsestmt end {
inst then = 0, else1 = 0, end = 0;
WRITE_UINT32(&then, $4);
WRITE_UINT32(&else1, $7);
WRITE_UINT32(&end, $8);
(*g_lingo->_currentScript)[$1 + 1] = then; /* thenpart */
(*g_lingo->_currentScript)[$1 + 2] = else1; /* elsepart */
(*g_lingo->_currentScript)[$1 + 3] = end; /* end, if cond fails */

g_lingo->processIf(0, 0); }
;
elsestmt: /* nothing */ { $$ = 0; }
| tNLELSE begin stmtoneliner { $$ = $2; }
;

elseifstmt: elseifstmt elseifstmt1
Expand Down Expand Up @@ -252,7 +248,7 @@ if: tIF {
g_lingo->code1(0); // Do not skip end
g_lingo->codeLabel(0); } // Mark beginning of the if() statement
;
elseif: tELSIF {
elseif: tNLELSIF {
inst skipEnd;
WRITE_UINT32(&skipEnd, 1); // We have to skip end to avoid multiple executions
$$ = g_lingo->code1(g_lingo->c_ifcode);
Expand Down

0 comments on commit 2415a4c

Please sign in to comment.