More work on binder, implements basic literal expressions

This commit is contained in:
2019-05-21 20:59:26 +02:00
parent 2fe6f570ec
commit 80998eab14
7 changed files with 251 additions and 3 deletions

View File

@@ -2,5 +2,48 @@
#include "Binder.hpp"
BoundScriptStatement *Binder::Bind(ParsedScriptStatement *s) {
return nullptr;
auto binder = Binder();
auto statements = s->GetStatements();
vector<BoundStatement*> boundStatements (statements.size());
for (int i = 0; i < statements.size(); i++){
boundStatements[i] = binder.BindStatement(statements[i]);
}
return new BoundScriptStatement(boundStatements);
}
BoundStatement* Binder::BindStatement(ParsedStatement* statement){
switch (statement -> GetKind()) {
case ParsedStatementKind ::Script: throw; // This shouldn't happen.
case ParsedStatementKind ::Block: return this -> BindBlockStatement(statement);
case ParsedStatementKind ::Expression: return this -> BindExpressionStatement(statement);
}
}
BoundStatement *Binder::BindBlockStatement(ParsedStatement *statement) {
auto statements = ((ParsedBlockStatement*)statement)->GetStatements();
vector<BoundStatement*> boundStatements (statements.size());
for (int i = 0; i < statements.size(); i++){
boundStatements[i] = this -> BindStatement(statements[i]);
}
return new BoundBlockStatement(boundStatements);
}
BoundStatement *Binder::BindExpressionStatement(ParsedStatement *statement) {
auto exp = ((ParsedExpressionStatement*)statement)->GetExpression();
return new BoundExpressionStatement(this -> BindExpression(exp));
}
BoundExpression* Binder::BindExpression(ParsedExpression* expression){
switch (expression -> GetKind()){
case ParsedExpressionKind ::LiteralInteger:
return new BoundLiteralIntegerExpression(((LiteralIntegerExpression*)expression)->GetValue(), expression->GetStartPosition(), expression->GetLength());
case ParsedExpressionKind ::LiteralFloat:
return new BoundLiteralFloatExpression(((LiteralFloatExpression*)expression)->GetValue(), expression->GetStartPosition(), expression->GetLength());
case ParsedExpressionKind ::LiteralBool:
return new BoundLiteralBoolExpression(((LiteralBoolExpression*)expression)->GetValue(), expression->GetStartPosition(), expression->GetLength());
case ParsedExpressionKind ::Bad:
return new BoundBadExpression(expression->GetStartPosition(), expression-> GetLength());
}
}