Implements string evaluation and concat

This commit is contained in:
2019-05-25 16:15:20 +02:00
parent b536187593
commit 0205b92ae6
10 changed files with 123 additions and 6 deletions

View File

@@ -3,6 +3,7 @@
#include "EvaluationException.hpp"
#include "Evaluator.hpp"
#include "EvalValues/NumericEvalValue.hpp"
#include "EvalValues/StringEvalValue.hpp"
NumericEvalValue* Evaluator::EvaluateIntegerBinary(BoundBinaryExpression *expression) {
NumericEvalValue* leftValue = this -> EvaluateIntegerExpression(expression->GetLeft());
@@ -71,4 +72,17 @@ BooleanEvalValue* Evaluator::EvaluateBooleanBinary(BoundBinaryExpression* expres
default:
throw EvaluationException("Can't evaluate operation to boolean");
}
}
StringEvalValue* Evaluator::EvaluateStringBinary(BoundBinaryExpression* expression){
if (expression->GetOperation() != BoundBinaryOperation::Concatenation)
throw;
std::ostringstream strs;
auto left = this -> EvaluateStringExpression(expression->GetLeft());
strs << left->EvaluateString();
delete left;
auto right = this -> EvaluateExpression(expression->GetRight());
strs << right->EvaluateString();
delete right;
return new StringEvalValue(strs.str());
}