-
Notifications
You must be signed in to change notification settings - Fork 0
/
Expr.hpp
62 lines (53 loc) · 1.06 KB
/
Expr.hpp
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
#pragma once
#include <llvm/IR/Value.h>
#include <llvm/IR/LLVMContext.h>
#include <vector>
// base class for our AST (All syntax nodes will be based on this)
class Expr
{
public:
virtual ~Expr() = default;
};
class IntegerExpr : public Expr
{
private:
int m_val;
public:
IntegerExpr(int val) : m_val(val) {}
};
class RealNumberExpr : public Expr
{
private:
double m_val;
public:
RealNumberExpr(double val) : m_val(val) {}
double value() const { return m_val; }
};
class StringExpr : public Expr
{
private:
std::string m_val;
public:
StringExpr(std::string val) : m_val(val) {}
std::string value() const { return m_val; }
};
class FunctionExpr : public Expr
{
private:
std::vector<std::string> m_args;
std::string m_ret;
public:
FunctionExpr();
};
class ModuleExpr : public Expr
{
private:
std::string m_name;
std::vector<Expr*> m_children;
public:
ModuleExpr(std::string name) : m_name(name) {}
void addChild(Expr* child) {
m_children.emplace_back(child);
}
std::string name() const { return m_name; }
};