summaryrefslogtreecommitdiff
path: root/src/gamestate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gamestate.cpp')
-rw-r--r--src/gamestate.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/gamestate.cpp b/src/gamestate.cpp
index fcd3433..7649cac 100644
--- a/src/gamestate.cpp
+++ b/src/gamestate.cpp
@@ -1,5 +1,10 @@
1#include "gamestate.h" 1#include "gamestate.h"
2 2
3#include "game.h"
4
5#include "astleaf.h"
6#include "astleafliteral.h"
7
3GameState::GameState( Game *pGame ) : 8GameState::GameState( Game *pGame ) :
4 pGame( pGame ) 9 pGame( pGame )
5{ 10{
@@ -9,3 +14,70 @@ GameState::~GameState()
9{ 14{
10} 15}
11 16
17void GameState::parse( class AstBranch *pAst )
18{
19 if( pAst->getType() != AstNode::tScope )
20 throw Bu::ExceptionBase("Nope, nothing doing, you can't parse a non-scope AstBranch.");
21 parse( pAst->getNodeList() );
22}
23
24void GameState::callFunction( const Bu::String &sName )
25{
26 lsLocal.push( new Scope() );
27 pGame->getFunction( sName )->call( *this );
28 delete lsLocal.peekPop();
29}
30
31void GameState::parse( const AstBranch::NodeList &lCode )
32{
33 for( AstBranch::NodeList::const_iterator i = lCode.begin(); i; i++ )
34 {
35 switch( (*i)->getType() )
36 {
37 // tLeaf
38 case AstNode::tNot:
39 case AstNode::tComp:
40 case AstNode::tCompGt:
41 case AstNode::tCompLt:
42 case AstNode::tCompGtEq:
43 case AstNode::tCompLtEq:
44 case AstNode::tStore:
45 case AstNode::tAnd:
46 case AstNode::tOr:
47 case AstNode::tPlus:
48 case AstNode::tMinus:
49 case AstNode::tDivide:
50 case AstNode::tMultiply:
51 case AstNode::tPlusStore:
52 case AstNode::tMinusStore:
53 case AstNode::tDivideStore:
54 case AstNode::tMultiplyStore:
55 case AstNode::tNegate:
56 case AstNode::tIn:
57
58 // tLeafLiteral
59 case AstNode::tVarName:
60 lStack.push( dynamic_cast<const AstLeafLiteral *>(*i)->getValue() );
61 break;
62
63 case AstNode::tLiteral:
64 lStack.push( dynamic_cast<const AstLeafLiteral *>(*i)->getValue() );
65 break;
66
67 case AstNode::tFuncCall:
68 callFunction(
69 dynamic_cast<const AstLeafLiteral *>(*i)
70 ->getValue().getString()
71 );
72 break;
73
74 // tBranch
75 case AstNode::tScope:
76 case AstNode::tIf:
77 case AstNode::tForEach:
78 case AstNode::tWhile:
79 break;
80 }
81 }
82}
83