Added logical and and or binary operations

This commit is contained in:
2019-05-25 13:30:20 +02:00
parent ce3be6a039
commit 4a4a71ca73
5 changed files with 140 additions and 7 deletions

View File

@@ -32,15 +32,12 @@ EvalValue *Evaluator::EvaluateExpression(BoundExpression *expression) {
auto type = expression -> GetType();
switch (type->GetClass()){
case TypeClass ::Number: return this -> EvaluateIntegerExpression(expression);
case TypeClass ::Bool: return this -> EvaluateBoolExpression(expression);
default: throw;
}
}
NumericEvalValue* Evaluator::EvaluateIntegerExpression(BoundExpression *expression) {
auto exprType = expression->GetType();
if (exprType->GetClass() != TypeClass::Number){
throw EvaluationException("Can't evaluate expression as integer, it will not return a number.");
}
switch (expression->GetKind()){
case BoundExpressionKind ::LiteralInteger: return new IntegerEvalValue(((BoundLiteralIntegerExpression*)expression)->GetValue());
case BoundExpressionKind ::LiteralFloat: return new FloatEvalValue(((BoundLiteralFloatExpression*)expression)->GetValue());
@@ -53,8 +50,18 @@ NumericEvalValue* Evaluator::EvaluateIntegerExpression(BoundExpression *expressi
}
}
EvalValue* Evaluator::EvaluateBoolExpression(BoundExpression *expression) {
return nullptr;
BooleanEvalValue* Evaluator::EvaluateBoolExpression(BoundExpression *expression) {
switch (expression->GetKind()) {
case BoundExpressionKind::LiteralBool: return new BooleanEvalValue(((BoundLiteralBoolExpression*)expression)->GetValue());
case BoundExpressionKind::Unary:break;
case BoundExpressionKind::Binary: return this -> EvaluateBooleanBinary((BoundBinaryExpression*)expression);
case BoundExpressionKind::Bad:
case BoundExpressionKind::LiteralInteger:
case BoundExpressionKind::LiteralFloat:
case BoundExpressionKind::LiteralString:
throw;
}
}
EvalValue* Evaluator::EvaluateStringExpression(BoundExpression *expression) {