diff options
author | Mike Buland <eichlan@xagasoft.com> | 2011-12-27 00:32:12 -0700 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2011-12-27 00:32:12 -0700 |
commit | 40e08192a08f55b5090d5ef28f48c74613e2e5a0 (patch) | |
tree | 352817365ce93d8d022cc1e04f5a411ce0df2b01 /src/parser.y | |
parent | f33fdd93ef93fdbb0e6b3a8e2ecb80b78f1b2816 (diff) | |
download | stage-40e08192a08f55b5090d5ef28f48c74613e2e5a0.tar.gz stage-40e08192a08f55b5090d5ef28f48c74613e2e5a0.tar.bz2 stage-40e08192a08f55b5090d5ef28f48c74613e2e5a0.tar.xz stage-40e08192a08f55b5090d5ef28f48c74613e2e5a0.zip |
Wow, a whole lot of code builds now.
Diffstat (limited to 'src/parser.y')
-rw-r--r-- | src/parser.y | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/src/parser.y b/src/parser.y index 7993927..fbada5a 100644 --- a/src/parser.y +++ b/src/parser.y | |||
@@ -80,10 +80,10 @@ void yyerror( YYLTYPE *llocp, yyscan_t yyscanner, GameBuilder &, const char *err | |||
80 | 80 | ||
81 | %right tokNot | 81 | %right tokNot |
82 | %right '=' tokPlusAssign tokMinusAssign tokTimesAssign tokDivideAssign | 82 | %right '=' tokPlusAssign tokMinusAssign tokTimesAssign tokDivideAssign |
83 | %right tokLtEq tokGtEq tokCmp | ||
84 | %left '-' '+' | 83 | %left '-' '+' |
85 | %left '*' '/' | 84 | %left '*' '/' |
86 | %left tokIn tokAnd tokOr | 85 | %left tokIn tokAnd tokOr |
86 | %right '<' '>' tokLtEq tokGtEq tokCmp | ||
87 | %left '(' ')' '[' ']' | 87 | %left '(' ')' '[' ']' |
88 | 88 | ||
89 | %% | 89 | %% |
@@ -146,17 +146,40 @@ cmpltExprList: | |||
146 | 146 | ||
147 | cmpltExpr: expr ';' | 147 | cmpltExpr: expr ';' |
148 | | tokGoto '(' expr ')' ';' | 148 | | tokGoto '(' expr ')' ';' |
149 | | tokIf expr tokThen '{' cmpltExprList '}' ifnext | 149 | | ifbase |
150 | | tokFor tokEach forIterator tokIn expr tokDo '{' cmpltExprList '}' | 150 | | tokFor tokEach forIterator tokIn expr tokDo '{' cmpltExprList '}' |
151 | | tokWhile expr tokDo '{' cmpltExprList '}' | 151 | | tokWhile { |
152 | bld.addNode( AstNode::tWhile ); | ||
153 | bld.addNode( AstNode::tScope ); | ||
154 | } expr { | ||
155 | bld.closeNode(); | ||
156 | bld.addNode( AstNode::tScope ); | ||
157 | } tokDo '{' cmpltExprList '}' { | ||
158 | bld.closeNode(); bld.closeNode(); | ||
159 | } | ||
152 | ; | 160 | ; |
153 | 161 | ||
154 | forIterator: tokIdent | 162 | forIterator: tokIdent |
155 | | tokIdent ':' tokIdent | 163 | | tokIdent ':' tokIdent |
156 | 164 | ||
165 | ifbase: tokIf { | ||
166 | bld.addNode( AstNode::tIf ); | ||
167 | bld.addNode( AstNode::tScope ); | ||
168 | } expr { | ||
169 | bld.closeNode(); | ||
170 | bld.addNode( AstNode::tScope ); | ||
171 | } tokThen '{' cmpltExprList '}' { | ||
172 | bld.closeNode(); | ||
173 | } ifnext { | ||
174 | bld.closeNode(); | ||
175 | } | ||
176 | ; | ||
177 | |||
157 | ifnext: | 178 | ifnext: |
158 | | tokElse '{' cmpltExprList '}' | 179 | | tokElse { bld.addNode( AstNode::tScope ); } '{' cmpltExprList '}' { |
159 | | tokElse tokIf '{' cmpltExprList '}' ifnext | 180 | bld.closeNode(); |
181 | } | ||
182 | | tokElse { bld.addNode( AstNode::tScope ); } ifbase | ||
160 | ; | 183 | ; |
161 | 184 | ||
162 | varRef: tokIdent { bld.addVarRef( *($1) ); } | 185 | varRef: tokIdent { bld.addVarRef( *($1) ); } |
@@ -177,17 +200,22 @@ expr: literal | |||
177 | | tokIdent '(' listValues ')' | 200 | | tokIdent '(' listValues ')' |
178 | | varRef | 201 | | varRef |
179 | | varRef '=' expr { bld.addNode( AstNode::tStore ); } | 202 | | varRef '=' expr { bld.addNode( AstNode::tStore ); } |
180 | | varRef tokPlusAssign expr | 203 | | varRef tokPlusAssign expr |
181 | | varRef tokMinusAssign expr | 204 | | varRef tokMinusAssign expr |
182 | | varRef tokTimesAssign expr | 205 | | varRef tokTimesAssign expr |
183 | | varRef tokDivideAssign expr | 206 | | varRef tokDivideAssign expr |
184 | | expr '+' expr { printf(" + plus\n"); } | 207 | | expr '+' expr { bld.addNode( AstNode::tPlus ); } |
185 | | expr '-' expr { printf(" + minus\n"); } | 208 | | expr '-' expr { bld.addNode( AstNode::tMinus ); } |
186 | | expr '/' expr { printf(" + divide\n"); } | 209 | | expr '/' expr { bld.addNode( AstNode::tDivide ); } |
187 | | expr '*' expr { printf(" + times\n"); } | 210 | | expr '*' expr { bld.addNode( AstNode::tMultiply ); } |
188 | | expr tokAnd expr | 211 | | expr tokAnd expr |
189 | | expr tokOr expr | 212 | | expr tokOr expr |
190 | | expr tokIn expr | 213 | | expr tokIn expr |
214 | | expr tokCmp expr { bld.addNode( AstNode::tComp ); } | ||
215 | | expr '<' expr { bld.addNode( AstNode::tCompLt ); } | ||
216 | | expr '>' expr { bld.addNode( AstNode::tCompGt ); } | ||
217 | | expr tokLtEq expr { bld.addNode( AstNode::tCompLtEq ); } | ||
218 | | expr tokGtEq expr { bld.addNode( AstNode::tCompGtEq ); } | ||
191 | | '(' expr ')' | 219 | | '(' expr ')' |
192 | | expr '[' expr ']' | 220 | | expr '[' expr ']' |
193 | | '[' ']' | 221 | | '[' ']' |