Initial layout for binder

This commit is contained in:
Deukhoofd 2019-05-21 18:09:08 +02:00
parent 2df4a71ed8
commit 1e5cd010a1
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
7 changed files with 89 additions and 9 deletions

6
src/Binder/Binder.cpp Normal file
View File

@ -0,0 +1,6 @@
#include "Binder.hpp"
BoundScriptStatement *Binder::Bind(ParsedScriptStatement *s) {
return nullptr;
}

14
src/Binder/Binder.hpp Normal file
View File

@ -0,0 +1,14 @@
#ifndef PORYGONLANG_BINDER_HPP
#define PORYGONLANG_BINDER_HPP
#include "../Parser/ParsedStatements/ParsedScriptStatement.hpp"
#include "BoundStatements/BoundStatement.hpp"
class Binder {
public:
static BoundScriptStatement* Bind(ParsedScriptStatement* s);
};
#endif //PORYGONLANG_BINDER_HPP

View File

@ -0,0 +1,49 @@
#include <utility>
#ifndef PORYGONLANG_BOUNDSTATEMENT_HPP
#define PORYGONLANG_BOUNDSTATEMENT_HPP
#include <vector>
using namespace std;
enum class BoundStatementKind{
Script,
Block,
};
class BoundStatement{
public:
virtual BoundStatementKind GetKind() = 0;
virtual ~BoundStatement() = default;
};
class BoundBlockStatement : public BoundStatement{
vector<BoundStatement*> _statements;
public:
explicit BoundBlockStatement(vector<BoundStatement*> statements){
_statements = std::move(statements);
}
~BoundBlockStatement() override {
for (auto s : _statements){
delete s;
}
_statements.clear();
}
BoundStatementKind GetKind() override{
return BoundStatementKind ::Block;
}
};
class BoundScriptStatement : public BoundBlockStatement{
public:
explicit BoundScriptStatement(vector<BoundStatement*> statements) : BoundBlockStatement(std::move(statements)){
}
BoundStatementKind GetKind() final{
return BoundStatementKind ::Script;
}
};
#endif //PORYGONLANG_BOUNDSTATEMENT_HPP

View File

@ -0,0 +1,16 @@
#ifndef PORYGONLANG_PARSEDSCRIPTSTATEMENT_HPP
#define PORYGONLANG_PARSEDSCRIPTSTATEMENT_HPP
#include "ParsedStatement.hpp"
class ParsedScriptStatement : public ParsedBlockStatement{
public:
explicit ParsedScriptStatement(vector<ParsedStatement*> statements) : ParsedBlockStatement(move(statements)){}
ParsedStatementKind GetKind() final{
return ParsedStatementKind ::Script;
}
};
#endif //PORYGONLANG_PARSEDSCRIPTSTATEMENT_HPP

View File

@ -1,5 +1,7 @@
#include <utility>
#include <utility>
#ifndef PORYGONLANG_PARSEDSTATEMENT_HPP
#define PORYGONLANG_PARSEDSTATEMENT_HPP
@ -49,15 +51,6 @@ public:
}
};
class ParsedScriptStatement : public ParsedBlockStatement{
public:
explicit ParsedScriptStatement(std::vector<ParsedStatement*> statements) : ParsedBlockStatement(statements){}
ParsedStatementKind GetKind() final{
return ParsedStatementKind ::Script;
}
};
class ParsedExpressionStatement : public ParsedStatement{
ParsedExpression* _expression;
public:

View File

@ -2,6 +2,7 @@
#include "Parser.hpp"
#include "UnaryOperatorKind.hpp"
#include "BinaryOperatorKind.hpp"
#include "ParsedScriptStatement.hpp"
ParsedScriptStatement* Parser::Parse() {

View File

@ -6,6 +6,7 @@
#include "ParsedStatements/ParsedStatement.hpp"
#include "../Script.hpp"
#include "ParsedScriptStatement.hpp"
enum class OperatorPrecedence {
No,