Implements while loop
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-06-28 13:28:39 +02:00
parent f7a6ff7d87
commit df79489d4d
9 changed files with 142 additions and 29 deletions

View File

@@ -48,6 +48,8 @@ namespace Porygon::Binder {
return this->BindNumericalForStatement(statement);
case ParsedStatementKind::GenericFor:
return this -> BindGenericForStatement(statement);
case ParsedStatementKind::While:
return this -> BindWhileStatement(statement);
case ParsedStatementKind::Break:
//TODO: Validate we're in a loop
return new BoundBreakStatement();
@@ -298,6 +300,18 @@ namespace Porygon::Binder {
return new BoundGenericForStatement(keyVariable, valueVariable, boundIterator, boundBlock);
}
BoundStatement *Binder::BindWhileStatement(const ParsedStatement *statement) {
auto whileStatement = (ParsedWhileStatement*)statement;
auto boundCondition = this -> BindExpression(whileStatement->GetCondition());
if (boundCondition->GetType()->GetClass() != TypeClass::Bool){
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::ConditionNotABool, statement->GetStartPosition(),
statement->GetLength());
return new BoundBadStatement();
}
auto boundBlock = this -> BindBlockStatement(whileStatement->GetBlock());
return new BoundWhileStatement(boundCondition, boundBlock);
}
/////////////////
// Expressions //
/////////////////
@@ -674,4 +688,5 @@ namespace Porygon::Binder {
return new BoundTableExpression((BoundBlockStatement *) block, tableType, expression->GetStartPosition(),
expression->GetLength());
}
}