Added AST constructors
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
# Fetches all files for the binary #
|
||||
file (GLOB ASTSources src/*.cpp inc/*.h)
|
||||
add_library(AST STATIC ${ASTSources})
|
||||
add_library(AST STATIC src/NodeTypes.cpp src/AST.cpp)
|
||||
|
||||
# Adds the headers in the current directory #
|
||||
target_include_directories (
|
||||
|
||||
@@ -1,23 +1,34 @@
|
||||
#include <LXC.h>
|
||||
|
||||
#include <NodeBase.h>
|
||||
#include <Token.h>
|
||||
|
||||
namespace LXC::AST
|
||||
{
|
||||
// Will be replaced later to account for things like namespaces //
|
||||
typedef std::string Identifier;
|
||||
|
||||
// Foward declares so it can be used in VarDecl //
|
||||
class VarAssignment;
|
||||
|
||||
class FunctionCall final : public NodeValue
|
||||
{
|
||||
public:
|
||||
FunctionCall(Identifier& functionName, std::vector<std::unique_ptr<NodeValue>>& arguments);
|
||||
|
||||
private:
|
||||
// The name of the function //
|
||||
Identifier m_FuncName;
|
||||
|
||||
// The arguments of the function //
|
||||
std::vector<std::unique_ptr<Node>> m_Arguments;
|
||||
std::vector<std::unique_ptr<NodeValue>> m_Arguments;
|
||||
};
|
||||
|
||||
class IntLiteral final : public NodeValue
|
||||
{
|
||||
public:
|
||||
IntLiteral(std::string& value);
|
||||
|
||||
private:
|
||||
// Yes numbers are stored as strings //
|
||||
std::string m_NumberValue;
|
||||
@@ -25,9 +36,12 @@ namespace LXC::AST
|
||||
|
||||
class Operation final : public NodeValue
|
||||
{
|
||||
public:
|
||||
Operation(std::unique_ptr<NodeValue>& left, Lexer::Token::TokenType operand, std::unique_ptr<NodeValue>& right);
|
||||
|
||||
private:
|
||||
// The sides of the operation //
|
||||
std::unique_ptr<Node> m_Lhs, m_Rhs;
|
||||
std::unique_ptr<NodeValue> m_Lhs, m_Rhs;
|
||||
|
||||
// The operand of the operation //
|
||||
Lexer::Token::TokenType m_Operand;
|
||||
@@ -35,6 +49,10 @@ namespace LXC::AST
|
||||
|
||||
class VarDeclaration final : public Node
|
||||
{
|
||||
public:
|
||||
VarDeclaration(Identifier& name);
|
||||
VarDeclaration(Identifier& name, std::unique_ptr<VarAssignment>& value);
|
||||
|
||||
private:
|
||||
// The name of the variable //
|
||||
Identifier m_Name;
|
||||
@@ -45,6 +63,9 @@ namespace LXC::AST
|
||||
|
||||
class VarAssignment final : public Node
|
||||
{
|
||||
public:
|
||||
VarAssignment(Identifier& name, std::unique_ptr<NodeValue>& value);
|
||||
|
||||
private:
|
||||
// The name of the variable //
|
||||
Identifier m_Name;
|
||||
@@ -55,6 +76,9 @@ namespace LXC::AST
|
||||
|
||||
class VarAccess final : public NodeValue
|
||||
{
|
||||
public:
|
||||
VarAccess(Identifier& name);
|
||||
|
||||
private:
|
||||
// The name of the variable //
|
||||
Identifier m_Name;
|
||||
@@ -62,9 +86,12 @@ namespace LXC::AST
|
||||
|
||||
class IfBranch final : public Node
|
||||
{
|
||||
public:
|
||||
IfBranch(std::unique_ptr<NodeValue>& condition, std::vector<std::unique_ptr<Node>>& body);
|
||||
|
||||
private:
|
||||
// The condition of the branch //
|
||||
std::unique_ptr<Node> m_Condition;
|
||||
std::unique_ptr<NodeValue> m_Condition;
|
||||
|
||||
// The body of the if-statement //
|
||||
std::vector<std::unique_ptr<Node>> m_Body;
|
||||
@@ -72,6 +99,9 @@ namespace LXC::AST
|
||||
|
||||
class ReturnStatement final : public Node
|
||||
{
|
||||
public:
|
||||
ReturnStatement(std::unique_ptr<NodeValue>& value);
|
||||
|
||||
private:
|
||||
// The value to return (nullable) //
|
||||
std::unique_ptr<NodeValue> m_ReturnValue;
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
#include <LXC.h>
|
||||
|
||||
#include <NodeTypes.h>
|
||||
|
||||
namespace LXC::AST
|
||||
{
|
||||
FunctionCall::FunctionCall (Identifier& functionName, std::vector<std::unique_ptr<NodeValue>>& arguments)
|
||||
: NodeValue(NodeType::FunctionCall), m_FuncName(std::move(functionName)), m_Arguments(std::move(arguments))
|
||||
{}
|
||||
|
||||
IntLiteral::IntLiteral(std::string& value)
|
||||
: NodeValue(NodeType::IntLiteral), m_NumberValue(std::move(value))
|
||||
{}
|
||||
|
||||
Operation::Operation(std::unique_ptr<NodeValue>& left, Lexer::Token::TokenType operand, std::unique_ptr<NodeValue>& right)
|
||||
: NodeValue(NodeType::Operation), m_Lhs(std::move(left)), m_Operand(operand), m_Rhs(std::move(right))
|
||||
{}
|
||||
|
||||
VarDeclaration::VarDeclaration(Identifier& name)
|
||||
: Node(NodeType::Var_Declare), m_Name(std::move(name)), m_Value(nullptr)
|
||||
{}
|
||||
|
||||
VarDeclaration::VarDeclaration(Identifier& name, std::unique_ptr<VarAssignment>& value)
|
||||
: Node(NodeType::Var_Declare), m_Name(std::move(name)), m_Value(std::move(value))
|
||||
{}
|
||||
|
||||
VarAssignment::VarAssignment(Identifier& name, std::unique_ptr<NodeValue>& value)
|
||||
: Node(NodeType::Var_Assign), m_Value(std::move(value))
|
||||
{}
|
||||
|
||||
VarAccess::VarAccess(Identifier& name)
|
||||
: NodeValue(NodeType::Var_Access), m_Name(std::move(m_Name))
|
||||
{}
|
||||
|
||||
IfBranch::IfBranch(std::unique_ptr<NodeValue>& condition, std::vector<std::unique_ptr<Node>>& body)
|
||||
: Node(NodeType::IfBranch), m_Condition(std::move(condition)), m_Body(std::move(body))
|
||||
{}
|
||||
|
||||
ReturnStatement::ReturnStatement(std::unique_ptr<NodeValue>& value)
|
||||
: Node(NodeType::ReturnVal), m_ReturnValue(std::move(m_ReturnValue))
|
||||
{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user