fart/parser/nodes.cc
Josh Holtrop 20017370f0 added expression production to grammar, changed grammar refs from number to expression, added BinOpNode class, currently segfaulting :(
git-svn-id: svn://anubis/fart/branches/scene-file-scripting@315 7f9b0f55-74a9-4bce-be96-3c2cd072584d
2010-09-28 20:39:42 +00:00

47 lines
807 B
C++

#include <stdlib.h>
#include <vector>
#include <iostream>
#include "nodes.h"
using namespace std;
void Node::addChildren(refptr<Node> other)
{
if (other.isNull())
return;
for (vector< refptr<Node> >::const_iterator it = other->m_children.begin();
it != other->m_children.end();
it++)
{
addChild(*it);
}
}
Node::~Node()
{
}
double BinOpNode::getNumber()
{
double o = one->getNumber();
double t = two->getNumber();
switch (m_op)
{
case '*':
return o * t;
case '/':
return o / t;
case '+':
return o + t;
case '-':
return o - t;
default:
cerr << "Error: BinOpNode created with op '" << m_op << "'" << endl;
exit(-3);
}
}