#include "gamestate.h" #include "game.h" #include "astleaf.h" #include "astleafliteral.h" GameState::GameState( Game *pGame ) : pGame( pGame ) { } GameState::~GameState() { } void GameState::parse( class AstBranch *pAst ) { if( pAst->getType() != AstNode::tScope ) throw Bu::ExceptionBase("Nope, nothing doing, you can't parse a non-scope AstBranch."); parse( pAst->getNodeList() ); } void GameState::callFunction( const Bu::String &sName ) { lsLocal.push( new Scope() ); pGame->getFunction( sName )->call( *this ); delete lsLocal.peekPop(); } void GameState::parse( const AstBranch::NodeList &lCode ) { for( AstBranch::NodeList::const_iterator i = lCode.begin(); i; i++ ) { switch( (*i)->getType() ) { // tLeaf case AstNode::tNot: case AstNode::tComp: case AstNode::tCompGt: case AstNode::tCompLt: case AstNode::tCompGtEq: case AstNode::tCompLtEq: case AstNode::tStore: case AstNode::tAnd: case AstNode::tOr: case AstNode::tPlus: case AstNode::tMinus: case AstNode::tDivide: case AstNode::tMultiply: case AstNode::tPlusStore: case AstNode::tMinusStore: case AstNode::tDivideStore: case AstNode::tMultiplyStore: case AstNode::tNegate: case AstNode::tIn: // tLeafLiteral case AstNode::tVarName: lStack.push( dynamic_cast(*i)->getValue() ); break; case AstNode::tLiteral: lStack.push( dynamic_cast(*i)->getValue() ); break; case AstNode::tFuncCall: callFunction( dynamic_cast(*i) ->getValue().getString() ); break; // tBranch case AstNode::tScope: case AstNode::tIf: case AstNode::tForEach: case AstNode::tWhile: break; } } }