aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--parser.cpp4
-rw-r--r--tree.cpp13
-rw-r--r--tree.h3
3 files changed, 13 insertions, 7 deletions
diff --git a/parser.cpp b/parser.cpp
index d3a9bb7..968053d 100644
--- a/parser.cpp
+++ b/parser.cpp
@@ -114,7 +114,7 @@ Node* Parser::buildTree(Tree **tree, string term)
vector<string> *tmpLexer;
- vector<string> *lexerOutput = lexer(term);
+ vector<string> *lexerOutput = this->lexer(term);
for ( vector<string>::iterator termIter = lexerOutput->begin(); termIter != lexerOutput->end(); termIter++ ) {
priority = this->getPriority( (*termIter)[0] );
@@ -150,7 +150,7 @@ Node* Parser::buildTree(Tree **tree, string term)
}
}
else {
- tmpLexer = lexer( *termIter );
+ tmpLexer = this->lexer( *termIter );
if ( tmpLexer->size() == 1 ) {
operandStack->push(
diff --git a/tree.cpp b/tree.cpp
index ee45e57..340685f 100644
--- a/tree.cpp
+++ b/tree.cpp
@@ -1,21 +1,24 @@
#include "tree.h"
-#include <math.h>
Node::Node()
{
}
+template <class T>
+double Node::castSolve (Node *node) {
+ T *tmp = static_cast<T*>( node );
+ return tmp->solve();
+}
+
double Node::solve()
{
switch (this->type) {
case OPERAND_NODE: {
- OperandNode *tmp = static_cast<OperandNode*>( this );
- return tmp->solve();
+ return this->castSolve<OperandNode>( this );
}
case OPERATOR_NODE: {
- OperatorNode *tmp = static_cast<OperatorNode*>( this );
- return tmp->solve();
+ return this->castSolve<OperatorNode>( this );
}
}
}
diff --git a/tree.h b/tree.h
index 2a0bb84..b112dcb 100644
--- a/tree.h
+++ b/tree.h
@@ -16,6 +16,9 @@ class Node
public:
Node();
double solve();
+
+ template <class T>
+ double castSolve(Node*);
Node *leftChild;
Node *rightChild;