2012-12-05 19:32:43 +00:00
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
{
|
2012-12-06 17:41:16 +00:00
|
|
|
if(!this->children_set)
|
|
|
|
{
|
|
|
|
children.push_back(left);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-05 19:32:43 +00:00
|
|
|
this->children[0] = left;
|
2012-12-06 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(children.size() == 2)
|
|
|
|
children_set = true;
|
2012-12-05 19:32:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BasicExpression::set_right_operand(ASTNode * right)
|
|
|
|
{
|
2012-12-06 17:41:16 +00:00
|
|
|
if(!this->children_set)
|
|
|
|
{
|
|
|
|
children.push_back(right);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->children[1] = right;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(children.size() == 2)
|
|
|
|
children_set = true;
|
2012-12-05 19:32:43 +00:00
|
|
|
}
|
|
|
|
|
2012-12-06 17:41:16 +00:00
|
|
|
SenchaObject BasicExpression::evaluate()
|
2012-12-05 19:32:43 +00:00
|
|
|
{
|
2012-12-06 17:41:16 +00:00
|
|
|
|
2012-12-05 19:32:43 +00:00
|
|
|
if(oper == "+")
|
|
|
|
{
|
2012-12-06 17:41:16 +00:00
|
|
|
return SenchaObject(static_cast<ASTExpression *>(children[0])->evaluate() + static_cast<ASTExpression *>(children[1])->evaluate());
|
2012-12-05 19:32:43 +00:00
|
|
|
}
|
|
|
|
|
2012-12-06 17:41:16 +00:00
|
|
|
return SenchaObject();
|
2012-12-05 19:32:43 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 20:31:06 +00:00
|
|
|
BasicExpression::BasicExpression(ASTNode * parent) {
|
|
|
|
this->parent = parent;
|
2012-12-06 17:41:16 +00:00
|
|
|
children_set = false;
|
2012-12-05 19:32:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BasicExpression::~BasicExpression() {
|
|
|
|
// TODO Auto-generated destructor stub
|
|
|
|
// TODO free children memory
|
|
|
|
}
|
|
|
|
|
2012-12-06 17:41:16 +00:00
|
|
|
|
|
|
|
std::string BasicExpression::debug()
|
|
|
|
{
|
|
|
|
std::string debug_note = "Basic expression:\n";
|
|
|
|
debug_note += "left operand: \n";
|
|
|
|
debug_note += this->children[0]->debug();
|
|
|
|
debug_note += "\nright operand:\n" + this->children[1]->debug() +"\n###\n";
|
|
|
|
return debug_note;
|
|
|
|
}
|