sencha-lang/Sencha-lang/AST/WhileNode.cpp

49 lines
775 B
C++
Raw Normal View History

/*
* WhileNode.cpp
*
* Created on: Dec 10, 2012
* Author: attero
*/
#include "WhileNode.h"
2012-12-10 11:37:29 +00:00
WhileNode::WhileNode(ASTNode * parent) {
// TODO Auto-generated constructor stub
2012-12-10 11:37:29 +00:00
this->parent = parent;
}
WhileNode::~WhileNode() {
// TODO Auto-generated destructor stub
}
2012-12-10 11:37:29 +00:00
void WhileNode::add_condition(ASTExpression * expression)
{
children.push_back(expression);
}
void WhileNode::add_body(ASTStatement * statement)
{
body = statement;
}
std::string WhileNode::debug()
{
std::string debug_note = "While";
return debug_note;
}
void WhileNode::execute()
{
while(evaluate_condition())
{
body->execute();
}
}
bool WhileNode::evaluate_condition()
{
auto condition = static_cast<ASTExpression * >(children[0])->evaluate();
return condition.is_true();
}