Skip to content

Commit

Permalink
DIRECTOR: Lingo: Better error recovery and further work on if() state…
Browse files Browse the repository at this point in the history
…ments
  • Loading branch information
sev- committed Aug 3, 2016
1 parent 855db11 commit aa45e48
Show file tree
Hide file tree
Showing 8 changed files with 765 additions and 740 deletions.
974 changes: 485 additions & 489 deletions engines/director/lingo/lingo-gr.cpp

Large diffs are not rendered by default.

146 changes: 74 additions & 72 deletions engines/director/lingo/lingo-gr.h
Expand Up @@ -52,41 +52,42 @@
tDOWN = 268,
tELSE = 269,
tNLELSIF = 270,
tEND = 271,
tEXIT = 272,
tFRAME = 273,
tGLOBAL = 274,
tGO = 275,
tIF = 276,
tINTO = 277,
tLOOP = 278,
tMACRO = 279,
tMCI = 280,
tMCIWAIT = 281,
tMOVIE = 282,
tNEXT = 283,
tOF = 284,
tPREVIOUS = 285,
tPUT = 286,
tREPEAT = 287,
tSET = 288,
tTHEN = 289,
tTO = 290,
tWITH = 291,
tWHILE = 292,
tNLELSE = 293,
tGE = 294,
tLE = 295,
tGT = 296,
tLT = 297,
tEQ = 298,
tNEQ = 299,
tAND = 300,
tOR = 301,
tNOT = 302,
tCONCAT = 303,
tCONTAINS = 304,
tSTARTS = 305
tENDIF = 271,
tENDREPEAT = 272,
tEXIT = 273,
tFRAME = 274,
tGLOBAL = 275,
tGO = 276,
tIF = 277,
tINTO = 278,
tLOOP = 279,
tMACRO = 280,
tMCI = 281,
tMCIWAIT = 282,
tMOVIE = 283,
tNEXT = 284,
tOF = 285,
tPREVIOUS = 286,
tPUT = 287,
tREPEAT = 288,
tSET = 289,
tTHEN = 290,
tTO = 291,
tWITH = 292,
tWHILE = 293,
tNLELSE = 294,
tGE = 295,
tLE = 296,
tGT = 297,
tLT = 298,
tEQ = 299,
tNEQ = 300,
tAND = 301,
tOR = 302,
tNOT = 303,
tCONCAT = 304,
tCONTAINS = 305,
tSTARTS = 306
};
#endif
/* Tokens. */
Expand All @@ -103,48 +104,49 @@
#define tDOWN 268
#define tELSE 269
#define tNLELSIF 270
#define tEND 271
#define tEXIT 272
#define tFRAME 273
#define tGLOBAL 274
#define tGO 275
#define tIF 276
#define tINTO 277
#define tLOOP 278
#define tMACRO 279
#define tMCI 280
#define tMCIWAIT 281
#define tMOVIE 282
#define tNEXT 283
#define tOF 284
#define tPREVIOUS 285
#define tPUT 286
#define tREPEAT 287
#define tSET 288
#define tTHEN 289
#define tTO 290
#define tWITH 291
#define tWHILE 292
#define tNLELSE 293
#define tGE 294
#define tLE 295
#define tGT 296
#define tLT 297
#define tEQ 298
#define tNEQ 299
#define tAND 300
#define tOR 301
#define tNOT 302
#define tCONCAT 303
#define tCONTAINS 304
#define tSTARTS 305
#define tENDIF 271
#define tENDREPEAT 272
#define tEXIT 273
#define tFRAME 274
#define tGLOBAL 275
#define tGO 276
#define tIF 277
#define tINTO 278
#define tLOOP 279
#define tMACRO 280
#define tMCI 281
#define tMCIWAIT 282
#define tMOVIE 283
#define tNEXT 284
#define tOF 285
#define tPREVIOUS 286
#define tPUT 287
#define tREPEAT 288
#define tSET 289
#define tTHEN 290
#define tTO 291
#define tWITH 292
#define tWHILE 293
#define tNLELSE 294
#define tGE 295
#define tLE 296
#define tGT 297
#define tLT 298
#define tEQ 299
#define tNEQ 300
#define tAND 301
#define tOR 302
#define tNOT 303
#define tCONCAT 304
#define tCONTAINS 305
#define tSTARTS 306




#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
#line 65 "engines/director/lingo/lingo-gr.y"
#line 66 "engines/director/lingo/lingo-gr.y"
{
Common::String *s;
int i;
Expand All @@ -153,7 +155,7 @@ typedef union YYSTYPE
int narg; /* number of arguments */
}
/* Line 1529 of yacc.c. */
#line 157 "engines/director/lingo/lingo-gr.hpp"
#line 159 "engines/director/lingo/lingo-gr.hpp"
YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
Expand Down
30 changes: 15 additions & 15 deletions engines/director/lingo/lingo-gr.y
Expand Up @@ -56,9 +56,10 @@

extern int yylex();
extern int yyparse();
void yyerror(char *s) { error("%s at line %d col %d", s, Director::g_lingo->_linenumber, Director::g_lingo->_colnumber); }

using namespace Director;
void yyerror(char *s) { g_lingo->_hadError = true; warning("%s at line %d col %d", s, Director::g_lingo->_linenumber, Director::g_lingo->_colnumber); }


%}

Expand All @@ -74,7 +75,7 @@ using namespace Director;
%token<i> INT
%token<f> FLOAT
%token<s> BLTIN ID STRING HANDLER
%token tDOWN tELSE tNLELSIF tEND tEXIT tFRAME tGLOBAL tGO tIF tINTO tLOOP tMACRO
%token tDOWN tELSE tNLELSIF tENDIF tENDREPEAT tEXIT tFRAME tGLOBAL tGO tIF tINTO tLOOP tMACRO
%token tMCI tMCIWAIT tMOVIE tNEXT tOF tPREVIOUS tPUT tREPEAT tSET tTHEN tTO
%token tWITH tWHILE tNLELSE
%token tGE tLE tGT tLT tEQ tNEQ tAND tOR tNOT
Expand All @@ -93,20 +94,20 @@ using namespace Director;

program: program nl programline
| programline
| error '\n' { yyerrok; }
;

nl: '\n' {
g_lingo->_linenumber++;
g_lingo->_colnumber = 1;
}

programline:
programline: /* empty */
| defn
| func
| macro
| asgn { g_lingo->code1(g_lingo->c_xpop); }
| stmt
| error { yyerrok; }
;

asgn: tPUT expr tINTO ID {
Expand Down Expand Up @@ -137,7 +138,7 @@ stmt: stmtoneliner
// statements
// end repeat
//
| repeatwhile '(' cond ')' stmtlist end tEND tREPEAT {
| repeatwhile '(' cond ')' stmtlist end tENDREPEAT {
inst body = 0, end = 0;
WRITE_UINT32(&body, $5);
WRITE_UINT32(&end, $6);
Expand All @@ -148,7 +149,7 @@ stmt: stmtoneliner
// statements
// end repeat
//
| repeatwith '=' expr end tTO expr end stmtlist end tEND tREPEAT {
| repeatwith '=' expr end tTO expr end stmtlist end tENDREPEAT {
inst init = 0, finish = 0, body = 0, end = 0, inc = 0;
WRITE_UINT32(&init, $3);
WRITE_UINT32(&finish, $6);
Expand All @@ -164,7 +165,7 @@ stmt: stmtoneliner
// statements
// end repeat
//
| repeatwith '=' expr end tDOWN tTO expr end stmtlist end tEND tREPEAT {
| repeatwith '=' expr end tDOWN tTO expr end stmtlist end tENDREPEAT {
inst init = 0, finish = 0, body = 0, end = 0, inc = 0;
WRITE_UINT32(&init, $3);
WRITE_UINT32(&finish, $7);
Expand All @@ -178,14 +179,14 @@ stmt: stmtoneliner
(*g_lingo->_currentScript)[$1 + 5] = end; } /* end, if cond fails */
;

ifstmt: if cond tTHEN nl stmtlist end tEND tIF {
ifstmt: if cond tTHEN nl stmtlist end tENDIF {
inst then = 0, end = 0;
WRITE_UINT32(&then, $5);
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 nl stmtlist end tNLELSE stmtlist end tEND tIF {
| if cond tTHEN nl stmtlist end tNLELSE stmtlist end nl tENDIF {
inst then = 0, else1 = 0, end = 0;
WRITE_UINT32(&then, $5);
WRITE_UINT32(&else1, $8);
Expand All @@ -194,7 +195,7 @@ ifstmt: if cond tTHEN nl 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, 0); }
| if cond tTHEN nl stmtlist end begin elseifstmt end nl tEND tIF {
| if cond tTHEN nl stmtlist end begin elseifstmt end nl tENDIF {
inst then = 0, else1 = 0, end = 0;
WRITE_UINT32(&then, $5);
WRITE_UINT32(&else1, $7);
Expand Down Expand Up @@ -292,9 +293,8 @@ begin: /* nothing */ { $$ = g_lingo->_currentScript->size(); }
;
end: /* nothing */ { g_lingo->code1(STOP); $$ = g_lingo->_currentScript->size(); }
;
stmtlist: /* nothing */ { $$ = g_lingo->_currentScript->size(); }
| stmtlist nl
| stmtlist stmt
stmtlist: stmtlist nl stmt
| stmt
;

expr: INT {
Expand Down Expand Up @@ -426,7 +426,7 @@ gotomovie: tOF tMOVIE STRING { $$ = $3; }
// See also:
// on keyword
defn: tMACRO ID { g_lingo->_indef = true; }
begin argdef nl argstore stmtlist {
begin argdef nl argstore stmtlist nl {
g_lingo->code2(g_lingo->c_constpush, (inst)0); // Push fake value on stack
g_lingo->code1(g_lingo->c_procret);
g_lingo->define(*$2, $4, $5);
Expand All @@ -435,7 +435,7 @@ defn: tMACRO ID { g_lingo->_indef = true; }
argdef: /* nothing */ { $$ = 0; }
| ID { g_lingo->codeArg($1); $$ = 1; }
| argdef ',' ID { g_lingo->codeArg($3); $$ = $1 + 1; }
| argdef nl ',' ID { g_lingo->codeArg($4); $$ = $1 + 1; }
| argdef nl ',' ID { g_lingo->codeArg($4); $$ = $1 + 1; }
;
argstore: /* nothing */ { g_lingo->codeArgStore(); }
;
Expand Down

0 comments on commit aa45e48

Please sign in to comment.