From 46d60a794170489f4db8fdd3be5f8ee373b397ec Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 21 Jun 2016 11:50:08 +0200 Subject: DIRECTOR: Lingo: Implement 'repeat while' control keyword --- engines/director/lingo/lingo-gr.y | 46 +++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 19 deletions(-) (limited to 'engines/director/lingo/lingo-gr.y') diff --git a/engines/director/lingo/lingo-gr.y b/engines/director/lingo/lingo-gr.y index 8d205b8ae1..8e4f96dcf9 100644 --- a/engines/director/lingo/lingo-gr.y +++ b/engines/director/lingo/lingo-gr.y @@ -74,10 +74,10 @@ using namespace Director; %token FLOAT %token VAR STRING %token tIF tELSE tEND tFRAME tGO tINTO tLOOP tMCI tMCIWAIT tMOVIE tNEXT tOF tPREVIOUS -%token tPUT tSET tTHEN tTO +%token tPUT tREPEAT tSET tTHEN tTO tWHILE %token tGE tLE tGT tLT tEQ tNEQ -%type asgn cond expr if end stmtlist +%type asgn cond expr if end stmtlist while %type gotoframe gotomovie %right '=' @@ -120,6 +120,31 @@ stmt: expr { g_lingo->code1(g_lingo->c_xpop); } (*g_lingo->_currentScript)[$1 + 1] = then; /* thenpart */ (*g_lingo->_currentScript)[$1 + 2] = else1; /* elsepart */ (*g_lingo->_currentScript)[$1 + 3] = end; } /* end, if cond fails */ + // repeat while (expression = TRUE) + // statements + // end repeat + // + | while '(' cond ')' stmtlist end tEND tREPEAT { + inst body, end; + WRITE_LE_UINT32(&body, $5); + WRITE_LE_UINT32(&end, $6); + (*g_lingo->_currentScript)[$1 + 1] = body; /* body of loop */ + (*g_lingo->_currentScript)[$1 + 2] = end; } /* end, if cond fails */ + ; + +cond: expr { g_lingo->code1(STOP); } + | expr '=' expr { g_lingo->code2(g_lingo->c_eq, STOP); } + | '(' cond ')' + ; +while: tREPEAT tWHILE { $$ = g_lingo->code3(g_lingo->c_whilecode, STOP, STOP); } + ; +if: tIF { $$ = g_lingo->code1(g_lingo->c_ifcode); g_lingo->code3(STOP, STOP, STOP); } + ; +end: /* nothing */ { g_lingo->code1(STOP); $$ = g_lingo->_currentScript->size(); } + ; +stmtlist: /* nothing */ { $$ = g_lingo->_currentScript->size(); } + | stmtlist '\n' + | stmtlist stmt ; expr: INT { g_lingo->code1(g_lingo->c_constpush); inst i; WRITE_LE_UINT32(&i, $1); $$ = g_lingo->code1(i); }; @@ -139,19 +164,6 @@ expr: INT { g_lingo->code1(g_lingo->c_constpush); inst i; WRITE_LE_UINT32(& | '(' expr ')' { $$ = $2; } ; -cond: expr { g_lingo->code1(STOP); } - | expr '=' expr { g_lingo->code2(g_lingo->c_eq, STOP); } - | '(' cond ')' - ; -if: tIF { $$ = g_lingo->code1(g_lingo->c_ifcode); g_lingo->code3(STOP,STOP,STOP); } - ; -end: /* nothing */ { g_lingo->code1(STOP); $$ = g_lingo->_currentScript->size(); } - ; -stmtlist: /* nothing */ { $$ = g_lingo->_currentScript->size(); } - | stmtlist '\n' - | stmtlist stmt - ; - func: tMCI STRING { g_lingo->code1(g_lingo->c_mci); g_lingo->codeString($2->c_str()); delete $2; } | tMCIWAIT VAR { g_lingo->code1(g_lingo->c_mciwait); g_lingo->codeString($2->c_str()); delete $2; } | tPUT expr { g_lingo->code1(g_lingo->c_printtop); } @@ -185,10 +197,6 @@ gotomovie: tOF tMOVIE STRING { $$ = $3; } | tTO tMOVIE STRING { $$ = $3; } ; -// repeat while (expression = TRUE) -// statements -// end repeat -// // repeat with index = start to end // statements // end repeat -- cgit v1.2.3