Implements if, elseif and else statements
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-06-08 14:25:15 +02:00
parent f4a3918947
commit e233616b8e
10 changed files with 187 additions and 2 deletions

View File

@@ -26,6 +26,7 @@ BoundStatement* Binder::BindStatement(ParsedStatement* statement){
case ParsedStatementKind::Assignment: return this -> BindAssignmentStatement(statement);
case ParsedStatementKind ::FunctionDeclaration: return this->BindFunctionDeclarationStatement(statement);
case ParsedStatementKind::Return: return this -> BindReturnStatement(statement);
case ParsedStatementKind::Conditional: return this -> BindConditionalStatement(statement);
case ParsedStatementKind::Bad: return new BoundBadStatement();
}
@@ -131,6 +132,21 @@ BoundStatement *Binder::BindReturnStatement(ParsedStatement* statement){
return new BoundReturnStatement(boundExpression);
}
BoundStatement *Binder::BindConditionalStatement(ParsedStatement* statement) {
auto conditionalStatement = (ParsedConditionalStatement*)statement;
auto boundCondition = this -> BindExpression(conditionalStatement -> GetCondition());
if (boundCondition->GetType() -> GetClass() != TypeClass::Bool){
this -> _scriptData -> Diagnostics -> LogError(DiagnosticCode::ConditionNotABool, statement->GetStartPosition(), statement->GetLength());
return new BoundBadStatement();
}
auto boundBlock = this -> BindStatement(conditionalStatement->GetBlock());
BoundStatement* elseStatement = nullptr;
if (conditionalStatement->GetElseStatement() != nullptr){
elseStatement = this -> BindStatement(conditionalStatement->GetElseStatement());
}
return new BoundConditionalStatement(boundCondition, boundBlock, elseStatement);
}
BoundExpression* Binder::BindExpression(ParsedExpression* expression){
switch (expression -> GetKind()){
case ParsedExpressionKind ::LiteralInteger:
@@ -351,3 +367,4 @@ BoundExpression *Binder::BindIndexExpression(IndexExpression *expression) {
auto resultType = shared_ptr<ScriptType>(indexer->GetType()->GetIndexedType(index->GetType().get()));
return new BoundIndexExpression(indexer, index, resultType, expression->GetStartPosition(), expression->GetLength());
}