summaryrefslogtreecommitdiff
path: root/src/gamebuilder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gamebuilder.cpp')
-rw-r--r--src/gamebuilder.cpp88
1 files changed, 87 insertions, 1 deletions
diff --git a/src/gamebuilder.cpp b/src/gamebuilder.cpp
index bfeffec..857c348 100644
--- a/src/gamebuilder.cpp
+++ b/src/gamebuilder.cpp
@@ -19,7 +19,8 @@ GameBuilder::GameBuilder() :
19 pCurRoot( NULL ), 19 pCurRoot( NULL ),
20 pCurCmd( NULL ), 20 pCurCmd( NULL ),
21 pCurFnc( NULL ), 21 pCurFnc( NULL ),
22 pCurSit( NULL ) 22 pCurSit( NULL ),
23 iStackHeight( 0 )
23{ 24{
24 pGame = new Game(); 25 pGame = new Game();
25} 26}
@@ -49,6 +50,15 @@ void GameBuilder::parse( const Bu::String &sFile )
49 fclose( in ); 50 fclose( in );
50} 51}
51 52
53void GameBuilder::endCmpltExpr()
54{
55 while( iStackHeight > 0 )
56 {
57 addNode( AstNode::tPop );
58 }
59 iStackHeight = 0;
60}
61
52void GameBuilder::setLiteral( const Variable &v ) 62void GameBuilder::setLiteral( const Variable &v )
53{ 63{
54 vLiteral = v; 64 vLiteral = v;
@@ -91,9 +101,12 @@ void GameBuilder::endFunctionParams()
91void GameBuilder::endFunction() 101void GameBuilder::endFunction()
92{ 102{
93 //sio << "Function ended: " << *pCurRoot << sio.nl; 103 //sio << "Function ended: " << *pCurRoot << sio.nl;
104
105 pCurNode->addNode( new AstLeafLiteral( Variable::tNull ) );
94 pCurFnc->setAst( pCurRoot ); 106 pCurFnc->setAst( pCurRoot );
95 pCurRoot = pCurNode = NULL; 107 pCurRoot = pCurNode = NULL;
96 pGame->hFunction.insert( pCurFnc->getName(), pCurFnc ); 108 pGame->hFunction.insert( pCurFnc->getName(), pCurFnc );
109 iStackHeight = 0;
97} 110}
98 111
99void GameBuilder::beginSituation( const Bu::String &sName, Situation::InputType tInput ) 112void GameBuilder::beginSituation( const Bu::String &sName, Situation::InputType tInput )
@@ -123,6 +136,7 @@ void GameBuilder::endSituation()
123 136
124void GameBuilder::addNode( AstNode::Type iType ) 137void GameBuilder::addNode( AstNode::Type iType )
125{ 138{
139 stackMod( iType );
126 switch( iType&AstNode::tTypeMask ) 140 switch( iType&AstNode::tTypeMask )
127 { 141 {
128 case AstNode::tBranch: 142 case AstNode::tBranch:
@@ -145,6 +159,7 @@ void GameBuilder::addLiteral( const Variable &v )
145 setLiteral( v ); 159 setLiteral( v );
146 if( pCurNode ) 160 if( pCurNode )
147 { 161 {
162 stackMod( AstNode::tLeafLiteral );
148 pCurNode->addNode( new AstLeafLiteral( v ) ); 163 pCurNode->addNode( new AstLeafLiteral( v ) );
149 } 164 }
150} 165}
@@ -153,6 +168,7 @@ void GameBuilder::addVarRef( const Bu::String &sName, ScopeId sid )
153{ 168{
154 if( pCurNode ) 169 if( pCurNode )
155 { 170 {
171 stackMod( AstNode::tVarName );
156 pCurNode->addNode( new AstLeafLiteral( AstNode::tVarName, Variable::newVariableName( sName, sid ) ) ); 172 pCurNode->addNode( new AstLeafLiteral( AstNode::tVarName, Variable::newVariableName( sName, sid ) ) );
157 } 173 }
158} 174}
@@ -161,10 +177,78 @@ void GameBuilder::addFuncCall( const Bu::String &sName )
161{ 177{
162 if( pCurNode ) 178 if( pCurNode )
163 { 179 {
180 stackMod( AstNode::tFuncCall );
164 pCurNode->addNode( new AstLeafLiteral( AstNode::tFuncCall, sName ) ); 181 pCurNode->addNode( new AstLeafLiteral( AstNode::tFuncCall, sName ) );
165 } 182 }
166} 183}
167 184
185void GameBuilder::stackMod( AstNode::Type iType )
186{
187 switch( iType )
188 {
189 case AstNode::tNot:
190 case AstNode::tNegate:
191 case AstNode::tSwap:
192 break;
193
194 case AstNode::tComp:
195 case AstNode::tCompGt:
196 case AstNode::tCompLt:
197 case AstNode::tCompGtEq:
198 case AstNode::tCompLtEq:
199 case AstNode::tStore:
200 case AstNode::tAnd:
201 case AstNode::tOr:
202 case AstNode::tPlus:
203 case AstNode::tMinus:
204 case AstNode::tDivide:
205 case AstNode::tMultiply:
206 case AstNode::tPlusStore:
207 case AstNode::tMinusStore:
208 case AstNode::tDivideStore:
209 case AstNode::tMultiplyStore:
210 case AstNode::tIn:
211 case AstNode::tGoto:
212 case AstNode::tStoreRev:
213 case AstNode::tReturn: // return doesn't pop anything, but it counts as it.
214 case AstNode::tAppend:
215 case AstNode::tPop:
216 case AstNode::tIndex:
217 iStackHeight--;
218 break;
219
220 case AstNode::tInsert:
221 iStackHeight -= 2;
222 break;
223
224 case AstNode::tLeafLiteral:
225 case AstNode::tVarName:
226 case AstNode::tLiteral:
227 case AstNode::tFuncCall:
228 iStackHeight++;
229 break;
230
231 case AstNode::tBranch:
232 break;
233
234 case AstNode::tScope:
235 break;
236
237 case AstNode::tIf:
238 iStackHeight--;
239 break;
240
241 case AstNode::tForEach:
242 iStackHeight -= 2;
243 break;
244
245 case AstNode::tWhile:
246 iStackHeight -= 1;
247 break;
248
249 }
250}
251
168void GameBuilder::beginGlobal() 252void GameBuilder::beginGlobal()
169{ 253{
170 bGlobal = true; 254 bGlobal = true;
@@ -219,6 +303,7 @@ void GameBuilder::closeCommand()
219 pCurSit->csLocal.addCommand( pCurCmd ); 303 pCurSit->csLocal.addCommand( pCurCmd );
220 } 304 }
221 pCurCmd = NULL; 305 pCurCmd = NULL;
306 iStackHeight = 0;
222} 307}
223 308
224void GameBuilder::beginOption( const Bu::String &sValue ) 309void GameBuilder::beginOption( const Bu::String &sValue )
@@ -237,5 +322,6 @@ void GameBuilder::closeOption()
237 //pCurCmd->print(); 322 //pCurCmd->print();
238 pCurSit->csLocal.addCommand( pCurCmd ); 323 pCurSit->csLocal.addCommand( pCurCmd );
239 pCurCmd = NULL; 324 pCurCmd = NULL;
325 iStackHeight = 0;
240} 326}
241 327