aboutsummaryrefslogtreecommitdiff
path: root/include/parser/ast_node.hpp
blob: 6539cf64e00a30b8f70822ef90815d3b707c99fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef AST_NODE_H
#define AST_NODE_H

#include "node_type.hpp"

#include <string>
#include <vector>
#include <memory>

class ASTNode {
public:
    int line;
    int column;

    virtual ~ASTNode() = default;
};

class Program : public ASTNode {
public:
    std::vector<std::unique_ptr<ASTNode>> declarations;
};

class Declaration : public ASTNode {
public:
    std::string type;
    std::string var_name;
    std::unique_ptr<ASTNode> value; 

    Declaration(std::string type, std::string var_name, std::unique_ptr<ASTNode> value = nullptr) : type(type), var_name(var_name), value(std::move(value)) {}
};

class Assignment : public ASTNode {
public:
    std::string variable_name;
    std::unique_ptr<ASTNode> value;

    Assignment(std::string var, std::unique_ptr<ASTNode> val) : variable_name(var), value(std::move(val)) {}
};

class NumberLiteral : public ASTNode {
public:
    double value;

    NumberLiteral(double val) : value(val) {}
};

class StringLiteral : public ASTNode {
public:
    std::string value;
    
    StringLiteral(std::string val) : value(val) {}
};

class Identifier : public ASTNode {
public:
    std::string name;
    
    Identifier(std::string name) : name(name) {}
};

class BinaryOp : public ASTNode {
public:
    std::unique_ptr<ASTNode> left;
    std::string value;
    std::unique_ptr<ASTNode> right;

    BinaryOp(std::unique_ptr<ASTNode> left, std::string value, std::unique_ptr<ASTNode> right) : left(std::move(left)), value(std::move(value)), right(std::move(right)) {}
};

#endif