aboutsummaryrefslogtreecommitdiff
path: root/src/ast.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-12-21 18:04:02 +0000
committerMike Buland <eichlan@xagasoft.com>2009-12-21 18:04:02 +0000
commitfb28f6800864176be2ffca29e8e664b641f33170 (patch)
treeba9180ac442939edc4eacbe1fdae93c5a7f87cee /src/ast.cpp
parent51e21a316be6e052251b3dfc7d671061ebd67cee (diff)
downloadbuild-fb28f6800864176be2ffca29e8e664b641f33170.tar.gz
build-fb28f6800864176be2ffca29e8e664b641f33170.tar.bz2
build-fb28f6800864176be2ffca29e8e664b641f33170.tar.xz
build-fb28f6800864176be2ffca29e8e664b641f33170.zip
m3 is copied into trunk, we should be good to go, now.
Diffstat (limited to 'src/ast.cpp')
-rw-r--r--src/ast.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/ast.cpp b/src/ast.cpp
new file mode 100644
index 0000000..03ed4b6
--- /dev/null
+++ b/src/ast.cpp
@@ -0,0 +1,98 @@
1#include "ast.h"
2
3#include "astleaf.h"
4#include "astbranch.h"
5
6Ast::Ast()
7{
8}
9
10Ast::~Ast()
11{
12}
13
14void Ast::addNode( AstNode::Type eType )
15{
16 switch( eType&AstNode::typeClassMask )
17 {
18 case AstNode::typeBranch:
19 {
20 AstBranch *pNode = new AstBranch( eType );
21 addNode( pNode );
22 sBranch.push( pNode );
23 }
24 break;
25
26 case AstNode::typeLeaf:
27 {
28 AstLeaf *pNode = new AstLeaf( eType );
29 addNode( pNode );
30 }
31 break;
32
33 default:
34 throw Bu::ExceptionBase("You got it wrong.");
35 break;
36 }
37}
38
39void Ast::addNode( AstNode::Type eType, int iVal )
40{
41 addNode( new AstLeaf( eType, iVal ) );
42}
43
44void Ast::addNode( AstNode::Type eType, float fVal )
45{
46 addNode( new AstLeaf( eType, fVal ) );
47}
48
49void Ast::addNode( AstNode::Type eType, bool bVal )
50{
51 addNode( new AstLeaf( eType, bVal ) );
52}
53
54void Ast::addNode( AstNode::Type eType, const Bu::FString &sVal )
55{
56 addNode( new AstLeaf( eType, sVal ) );
57}
58
59void Ast::addNode( AstNode::Type eType, const char *sVal )
60{
61 addNode( new AstLeaf( eType, sVal ) );
62}
63
64void Ast::addNode( AstNode *pNode )
65{
66 if( sBranch.isEmpty() )
67 lNode.append( pNode );
68 else
69 sBranch.peek()->addNode( pNode );
70}
71
72void Ast::openBranch()
73{
74 sBranch.peek()->addBranch();
75}
76
77void Ast::closeNode()
78{
79 sBranch.pop();
80}
81
82Ast::NodeList::const_iterator Ast::getNodeBegin() const
83{
84 return lNode.begin();
85}
86
87Bu::Formatter &operator<<( Bu::Formatter &f, const Ast &a )
88{
89 f << "Abstract Syntax Tree:";
90 f.incIndent();
91 f << f.nl;
92 for( Ast::NodeList::const_iterator i = a.getNodeBegin(); i; i++ )
93 f << **i << f.nl;
94 f << f.nl;
95 f.decIndent();
96 return f;
97}
98