PorygonLang/src/Evaluator/BinaryEvaluation.cpp

31 lines
1.1 KiB
C++
Raw Normal View History

2019-05-23 16:50:09 +00:00
2019-05-24 13:31:11 +00:00
#include "../Script.hpp"
2019-05-23 16:50:09 +00:00
#include "EvaluationException.hpp"
#include "Evaluator.hpp"
#include "EvalValues/NumericEvalValue.hpp"
2019-05-23 16:50:09 +00:00
NumericEvalValue* Evaluator::EvaluateIntegerBinary(BoundBinaryExpression *expression) {
NumericEvalValue* leftValue = this -> EvaluateIntegerExpression(expression->GetLeft());
NumericEvalValue* rightValue = this -> EvaluateIntegerExpression(expression->GetRight());
2019-05-24 13:31:11 +00:00
NumericEvalValue* result;
2019-05-24 13:31:11 +00:00
switch (expression->GetOperation()){
case BoundBinaryOperation ::Addition:
result = leftValue -> operator+ (rightValue);
break;
case BoundBinaryOperation::Subtraction:
result = leftValue -> operator- (rightValue);
break;
case BoundBinaryOperation::Multiplication:
result = leftValue -> operator* (rightValue);
break;
case BoundBinaryOperation::Division:
result = leftValue -> operator/ (rightValue);
break;
2019-05-24 13:31:11 +00:00
default:
throw EvaluationException("Can't evaluate operation to numeric");
2019-05-24 13:31:11 +00:00
}
delete leftValue;
delete rightValue;
return result;
2019-05-24 13:31:11 +00:00
}