From cfa0ff5e6a45ce2d17fe18a09268acb2c0eb6724 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 18 Dec 2011 00:45:12 -0700 Subject: The basic structure is complete. --- src/parser.y | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) (limited to 'src/parser.y') diff --git a/src/parser.y b/src/parser.y index e2f8b6d..95bd00d 100644 --- a/src/parser.y +++ b/src/parser.y @@ -37,6 +37,8 @@ void yyerror( YYLTYPE *llocp, yyscan_t yyscanner, const char *error ) %token tokGame %token tokFunction %token tokSituation +%token tokSetup +%token tokEnter %token tokWhile %token tokFor %token tokEach @@ -47,6 +49,13 @@ void yyerror( YYLTYPE *llocp, yyscan_t yyscanner, const char *error ) %token tokNot %token tokCommand %token tokPlayer +%token tokLtEq +%token tokGtEq +%token tokCmp +%token tokPlusAssign +%token tokMinusAssign +%token tokTimesAssign +%token tokDivideAssign %token tokSituationName %token tokIdent %token tokGoto @@ -60,7 +69,9 @@ void yyerror( YYLTYPE *llocp, yyscan_t yyscanner, const char *error ) %token eos 0 "end of stream" -%right '=' +%right tokNot +%right '=' tokPlusAssign tokMinusAssign tokTimesAssign tokDivideAssign +%right tokLtEq tokGtEq tokCmp %left tokIn %left '(' ')' '[' ']' %left '*' '/' @@ -89,9 +100,21 @@ bodyDecl: | bodyDecl function ; -situation: tokSituation tokSituationName { printf("Read situtaion: %s\n", (*$2).getStr() ); } '{' cmpltExprList '}' +situation: tokSituation tokSituationName { printf("Read situtaion: %s\n", (*$2).getStr() ); } '{' situationMembers '}' ; +situationMembers: + | situationMembers situationModeFunc + | situationMembers commandDecl + ; + +situationModeFunc: situationMode '{' cmpltExprList '}' + ; + +situationMode: tokSetup + | tokEnter + ; + function: tokFunction tokIdent '(' ')' '{' '}' ; @@ -109,15 +132,24 @@ ifnext: | tokElse tokIf '{' cmpltExprList '}' ifnext ; +varRef: tokIdent + | tokPlayer '.' tokIdent + | tokSituation '.' tokIdent + ; + expr: tokInt | tokFloat | tokString | tokBool | tokNull - | tokIdent + | tokIdent '(' listValues ')' + | varRef + | varRef '=' expr + | varRef tokPlusAssign expr + | varRef tokMinusAssign expr + | varRef tokTimesAssign expr + | varRef tokDivideAssign expr | tokSituationName - | tokSituation '.' tokIdent - | tokPlayer '.' tokIdent | expr '+' expr | expr '-' expr | expr '/' expr @@ -129,7 +161,7 @@ expr: tokInt | '[' listValues ']' | '{' '}' | '{' dictValues '}' -/* | tokNot expr */ + | tokNot expr ; listValues: expr -- cgit v1.2.3