50 lines
936 B
C++
50 lines
936 B
C++
|
/*
|
||
|
* BasicExpression.cpp
|
||
|
*
|
||
|
* Created on: Dec 5, 2012
|
||
|
* Author: attero
|
||
|
*/
|
||
|
|
||
|
#include "BasicExpression.h"
|
||
|
|
||
|
void BasicExpression::set_operator(std::string op)
|
||
|
{
|
||
|
this->oper = op;
|
||
|
}
|
||
|
|
||
|
void BasicExpression::set_left_operand(ASTNode * left)
|
||
|
{
|
||
|
this->children[0] = left;
|
||
|
this->left = static_cast<ASTExpression *>(children[0]);
|
||
|
}
|
||
|
|
||
|
void BasicExpression::set_right_operand(ASTNode * right)
|
||
|
{
|
||
|
this->children[1] = right;
|
||
|
this->right = static_cast<ASTExpression *>(children[1]);
|
||
|
}
|
||
|
|
||
|
virtual int BasicExpression::evaluate()
|
||
|
{
|
||
|
if(oper == "+")
|
||
|
{
|
||
|
return left->evaluate() + right->evaluate();
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
BasicExpression::BasicExpression() {
|
||
|
// initialize pointers
|
||
|
this->add_children(0);
|
||
|
this->add_children(0);
|
||
|
left = static_cast<ASTExpression *>(children[0]);
|
||
|
right = static_cast<ASTExpression *>(children[1]);
|
||
|
}
|
||
|
|
||
|
BasicExpression::~BasicExpression() {
|
||
|
// TODO Auto-generated destructor stub
|
||
|
// TODO free children memory
|
||
|
}
|
||
|
|