diff options
-rw-r--r-- | demo.stage | 10 | ||||
-rw-r--r-- | src/parser.l | 5 | ||||
-rw-r--r-- | src/parser.y | 40 |
3 files changed, 36 insertions, 19 deletions
@@ -1,8 +1,12 @@ | |||
1 | 1 | ||
2 | game | 2 | game.title = "Demo game"; |
3 | { | 3 | game.author = "Mike Buland"; |
4 | title = "Demo game"; | 4 | game.version = 1; |
5 | game.revision = 0; | ||
6 | game.start = <<start>>; | ||
5 | 7 | ||
8 | global | ||
9 | { | ||
6 | command: "take" item | 10 | command: "take" item |
7 | { | 11 | { |
8 | if item in situation.items then | 12 | if item in situation.items then |
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 |