Added AST constructors

This commit is contained in:
Pasha Bibko
2025-07-23 14:50:38 +01:00
parent 3550b015c9
commit 69e7b0e6c1
3 changed files with 76 additions and 5 deletions

View File

@@ -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;