From 1368849e36e1b5ecd0d595b713ca73f9d88da38b Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 18 Dec 2011 00:56:43 -0700 Subject: Minor tweaks. Now the game metadata can be read without reading anything else from the file, making it much easier to report info about a game rapidly. --- src/parser.l | 5 +++++ src/parser.y | 40 ++++++++++++++++++++++++---------------- 2 files changed, 29 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/parser.l b/src/parser.l index 841c5e6..9e031eb 100644 --- a/src/parser.l +++ b/src/parser.l @@ -29,6 +29,7 @@ [-{}<>=+/*,();:.[\]] { return yytext[0]; } game { return tokGame; } +global { return tokGlobal; } function { return tokFunction; } situation { return tokSituation; } player { return tokPlayer; } @@ -66,6 +67,10 @@ null { return tokNull; } yylval->iValue = strtoll( yytext, NULL, 10 ); return tokInt; } +0 { + yylval->iValue = 0; + return tokInt; +} ([1-9][0-9]*)?\.[0-9]* { yylval->dValue = strtod( yytext, NULL ); diff --git a/src/parser.y b/src/parser.y index 95bd00d..ef9d10b 100644 --- a/src/parser.y +++ b/src/parser.y @@ -35,6 +35,7 @@ void yyerror( YYLTYPE *llocp, yyscan_t yyscanner, const char *error ) %} %token tokGame +%token tokGlobal %token tokFunction %token tokSituation %token tokSetup @@ -78,22 +79,26 @@ void yyerror( YYLTYPE *llocp, yyscan_t yyscanner, const char *error ) %left '-' '+' %% -input: gameDecl bodyDecl +input: gameDecls globalDecl bodyDecl ; -gameDecl: tokGame '{' gameExprList '}' +gameDecls: + | gameDecls tokGame '.' tokIdent '=' literal ';' + ; + +globalDecl: tokGlobal '{' globalExprList '}' ; -gameExprList: - | gameExprList cmpltGameExpr - ; +globalExprList: + | globalExprList cmpltGlobalExpr + ; -cmpltGameExpr: gameExpr ';' - | commandDecl - ; +cmpltGlobalExpr: globalExpr ';' + | commandDecl + ; -gameExpr: tokIdent '=' expr - ; +globalExpr: tokIdent '=' expr + ; bodyDecl: | bodyDecl situation @@ -137,11 +142,15 @@ varRef: tokIdent | tokSituation '.' tokIdent ; -expr: tokInt - | tokFloat - | tokString - | tokBool - | tokNull +literal: tokInt + | tokFloat + | tokString + | tokBool + | tokNull + | tokSituationName + ; + +expr: literal | tokIdent '(' listValues ')' | varRef | varRef '=' expr @@ -149,7 +158,6 @@ expr: tokInt | varRef tokMinusAssign expr | varRef tokTimesAssign expr | varRef tokDivideAssign expr - | tokSituationName | expr '+' expr | expr '-' expr | expr '/' expr -- cgit v1.2.3