Implements if, elseif and else statements
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -23,6 +23,7 @@ void Evaluator::EvaluateStatement(BoundStatement *statement) {
|
||||
case BoundStatementKind ::Assignment: return this -> EvaluateAssignmentStatement((BoundAssignmentStatement*)statement);
|
||||
case BoundStatementKind ::FunctionDeclaration: return this->EvaluateFunctionDeclarationStatement((BoundFunctionDeclarationStatement*)statement);
|
||||
case BoundStatementKind::Return: return this -> EvaluateReturnStatement((BoundReturnStatement*)statement);
|
||||
case BoundStatementKind::Conditional: return this -> EvaluateConditionalStatement((BoundConditionalStatement*)statement);
|
||||
|
||||
case BoundStatementKind::Bad:
|
||||
throw;
|
||||
@@ -76,6 +77,18 @@ void Evaluator::EvaluateReturnStatement(BoundReturnStatement* statement){
|
||||
this -> _returnValue = value;
|
||||
}
|
||||
|
||||
void Evaluator::EvaluateConditionalStatement(BoundConditionalStatement *statement) {
|
||||
auto condition = statement->GetCondition();
|
||||
if (EvaluateBoolExpression(condition) -> EvaluateBool()){
|
||||
this -> EvaluateStatement(statement->GetBlock());
|
||||
} else{
|
||||
auto elseStatement = statement -> GetElseStatement();
|
||||
if (elseStatement != nullptr){
|
||||
this->EvaluateStatement(elseStatement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
shared_ptr<EvalValue> Evaluator::EvaluateExpression(BoundExpression *expression) {
|
||||
auto type = expression -> GetType();
|
||||
switch (type->GetClass()){
|
||||
@@ -216,4 +229,5 @@ shared_ptr<EvalValue> Evaluator::EvaluateIndexExpression(BoundExpression *expres
|
||||
auto index = this -> EvaluateExpression(indexExpression->GetIndexExpression());
|
||||
auto indexable = this -> EvaluateExpression(indexExpression->GetIndexableExpression());
|
||||
return shared_ptr<EvalValue>(indexable -> IndexValue(index.get()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ class Evaluator {
|
||||
void EvaluateAssignmentStatement(BoundAssignmentStatement* statement);
|
||||
void EvaluateFunctionDeclarationStatement(BoundFunctionDeclarationStatement *statement);
|
||||
void EvaluateReturnStatement(BoundReturnStatement *statement);
|
||||
void EvaluateConditionalStatement(BoundConditionalStatement *statement);
|
||||
|
||||
shared_ptr<EvalValue> EvaluateExpression(BoundExpression* expression);
|
||||
shared_ptr<NumericEvalValue> EvaluateIntegerExpression(BoundExpression* expression);
|
||||
|
||||
Reference in New Issue
Block a user