summaryrefslogtreecommitdiff
path: root/evaluator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'evaluator.cpp')
-rw-r--r--evaluator.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/evaluator.cpp b/evaluator.cpp
new file mode 100644
index 0000000..1356258
--- /dev/null
+++ b/evaluator.cpp
@@ -0,0 +1,40 @@
+#include "evaluator.h"
+
+#include "value.h"
+
+evaluator::evaluator(const char * display_name) :
+ m_display_name(display_name)
+ { }
+
+value *
+evaluator::evaluate(
+ value * l,
+ value * r)
+{
+ return new tree_value(this, l, r);
+}
+
+std::string
+evaluator::to_string()
+{
+ return m_display_name;
+}
+
+add_evaluator::add_evaluator() :
+ evaluator("+")
+ { }
+
+value *
+add_evaluator::evaluate(
+ float_value * l,
+ float_value * r)
+{
+ float_value * new_val;
+ if (!l->m_has_value || !r->m_has_value) {
+ return this->evaluator::evaluate(l, r);
+ }
+
+ new_val = new float_value();
+ new_val->set_value(l->m_value + r->m_value);
+ return new_val;
+}