diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2011-12-18 00:56:43 -0700 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2011-12-18 00:56:43 -0700 |
| commit | 1368849e36e1b5ecd0d595b713ca73f9d88da38b (patch) | |
| tree | 856bd29ef562f8310d5a1c6c950e100851f96a3a /src | |
| parent | cfa0ff5e6a45ce2d17fe18a09268acb2c0eb6724 (diff) | |
| download | stage-1368849e36e1b5ecd0d595b713ca73f9d88da38b.tar.gz stage-1368849e36e1b5ecd0d595b713ca73f9d88da38b.tar.bz2 stage-1368849e36e1b5ecd0d595b713ca73f9d88da38b.tar.xz stage-1368849e36e1b5ecd0d595b713ca73f9d88da38b.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/parser.l | 5 | ||||
| -rw-r--r-- | src/parser.y | 40 |
2 files changed, 29 insertions, 16 deletions
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 @@ | |||
| 29 | [-{}<>=+/*,();:.[\]] { return yytext[0]; } | 29 | [-{}<>=+/*,();:.[\]] { return yytext[0]; } |
| 30 | 30 | ||
| 31 | game { return tokGame; } | 31 | game { return tokGame; } |
| 32 | global { return tokGlobal; } | ||
| 32 | function { return tokFunction; } | 33 | function { return tokFunction; } |
| 33 | situation { return tokSituation; } | 34 | situation { return tokSituation; } |
| 34 | player { return tokPlayer; } | 35 | player { return tokPlayer; } |
| @@ -66,6 +67,10 @@ null { return tokNull; } | |||
| 66 | yylval->iValue = strtoll( yytext, NULL, 10 ); | 67 | yylval->iValue = strtoll( yytext, NULL, 10 ); |
| 67 | return tokInt; | 68 | return tokInt; |
| 68 | } | 69 | } |
| 70 | 0 { | ||
| 71 | yylval->iValue = 0; | ||
| 72 | return tokInt; | ||
| 73 | } | ||
| 69 | 74 | ||
| 70 | ([1-9][0-9]*)?\.[0-9]* { | 75 | ([1-9][0-9]*)?\.[0-9]* { |
| 71 | yylval->dValue = strtod( yytext, NULL ); | 76 | 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 ) | |||
| 35 | %} | 35 | %} |
| 36 | 36 | ||
| 37 | %token tokGame | 37 | %token tokGame |
| 38 | %token tokGlobal | ||
| 38 | %token tokFunction | 39 | %token tokFunction |
| 39 | %token tokSituation | 40 | %token tokSituation |
| 40 | %token tokSetup | 41 | %token tokSetup |
| @@ -78,22 +79,26 @@ void yyerror( YYLTYPE *llocp, yyscan_t yyscanner, const char *error ) | |||
| 78 | %left '-' '+' | 79 | %left '-' '+' |
| 79 | 80 | ||
| 80 | %% | 81 | %% |
| 81 | input: gameDecl bodyDecl | 82 | input: gameDecls globalDecl bodyDecl |
| 82 | ; | 83 | ; |
| 83 | 84 | ||
| 84 | gameDecl: tokGame '{' gameExprList '}' | 85 | gameDecls: |
| 86 | | gameDecls tokGame '.' tokIdent '=' literal ';' | ||
| 87 | ; | ||
| 88 | |||
| 89 | globalDecl: tokGlobal '{' globalExprList '}' | ||
| 85 | ; | 90 | ; |
| 86 | 91 | ||
| 87 | gameExprList: | 92 | globalExprList: |
| 88 | | gameExprList cmpltGameExpr | 93 | | globalExprList cmpltGlobalExpr |
| 89 | ; | 94 | ; |
| 90 | 95 | ||
| 91 | cmpltGameExpr: gameExpr ';' | 96 | cmpltGlobalExpr: globalExpr ';' |
| 92 | | commandDecl | 97 | | commandDecl |
| 93 | ; | 98 | ; |
| 94 | 99 | ||
| 95 | gameExpr: tokIdent '=' expr | 100 | globalExpr: tokIdent '=' expr |
| 96 | ; | 101 | ; |
| 97 | 102 | ||
| 98 | bodyDecl: | 103 | bodyDecl: |
| 99 | | bodyDecl situation | 104 | | bodyDecl situation |
| @@ -137,11 +142,15 @@ varRef: tokIdent | |||
| 137 | | tokSituation '.' tokIdent | 142 | | tokSituation '.' tokIdent |
| 138 | ; | 143 | ; |
| 139 | 144 | ||
| 140 | expr: tokInt | 145 | literal: tokInt |
| 141 | | tokFloat | 146 | | tokFloat |
| 142 | | tokString | 147 | | tokString |
| 143 | | tokBool | 148 | | tokBool |
| 144 | | tokNull | 149 | | tokNull |
| 150 | | tokSituationName | ||
| 151 | ; | ||
| 152 | |||
| 153 | expr: literal | ||
| 145 | | tokIdent '(' listValues ')' | 154 | | tokIdent '(' listValues ')' |
| 146 | | varRef | 155 | | varRef |
| 147 | | varRef '=' expr | 156 | | varRef '=' expr |
| @@ -149,7 +158,6 @@ expr: tokInt | |||
| 149 | | varRef tokMinusAssign expr | 158 | | varRef tokMinusAssign expr |
| 150 | | varRef tokTimesAssign expr | 159 | | varRef tokTimesAssign expr |
| 151 | | varRef tokDivideAssign expr | 160 | | varRef tokDivideAssign expr |
| 152 | | tokSituationName | ||
| 153 | | expr '+' expr | 161 | | expr '+' expr |
| 154 | | expr '-' expr | 162 | | expr '-' expr |
| 155 | | expr '/' expr | 163 | | expr '/' expr |
