-
Notifications
You must be signed in to change notification settings - Fork 1
/
node.h
139 lines (118 loc) · 3.26 KB
/
node.h
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <iostream>
#include <vector>
class NStatement;
class NExpression;
class NVariableDeclaration;
typedef std::vector<NStatement*> StatementList;
typedef std::vector<NExpression*> ExpressionList;
typedef std::vector<NVariableDeclaration*> VariableList;
class Node {
public:
virtual ~Node() {}
};
class NExpression : public Node {
};
class NStatement : public Node {
};
class NInteger : public NExpression {
public:
long long value;
NInteger(long long value) : value(value) { }
};
class NDouble : public NExpression {
public:
double value;
NDouble(double value) : value(value) { }
};
class NBool : public NExpression {
public:
bool value;
NBool(bool value) : value(value) { }
};
class NChar : public NExpression {
public:
char value;
NChar(char value) : value(value) {}
};
class NIdentifier : public NExpression {
public:
std::string name;
NIdentifier(const std::string& name) : name(name) { }
};
class NFunctionCall : public NExpression {
public:
const NIdentifier& id;
ExpressionList arguments;
NFunctionCall(const NIdentifier& id, ExpressionList& arguments) :
id(id), arguments(arguments) { }
NFunctionCall(const NIdentifier& id) : id(id) { }
};
class NBinaryOperator : public NExpression {
public:
int op;
NExpression& loperand;
NExpression& roperand;
NBinaryOperator(NExpression& loperand, int op, NExpression& roperand) :
loperand(loperand), roperand(roperand), op(op) { }
};
class NAssignment : public NExpression {
public:
NIdentifier& lvalue;
NExpression& rvalue;
NAssignment(NIdentifier& lvalue, NExpression& rvalue) :
lvalue(lvalue), rvalue(rvalue) { }
};
class NBlock : public NExpression {
public:
StatementList statements;
NBlock() { }
};
class NExpressionStatement : public NStatement {
public:
NExpression& expression;
NExpressionStatement(NExpression& expression) :
expression(expression) { }
};
class NVariableDeclaration : public NStatement {
public:
const NIdentifier& type;
NIdentifier& id;
NExpression *assignmentExpr;
NVariableDeclaration(const NIdentifier& type, NIdentifier& id) :
type(type), id(id) { }
NVariableDeclaration(const NIdentifier& type, NIdentifier& id, NExpression *assignmentExpr) :
type(type), id(id), assignmentExpr(assignmentExpr) { }
};
class NFunctionDeclaration : public NStatement {
public:
const NIdentifier& type;
const NIdentifier& id;
VariableList arguments;
NBlock& block;
NFunctionDeclaration(const NIdentifier& type, const NIdentifier& id,
const VariableList& arguments, NBlock& block) :
type(type), id(id), arguments(arguments), block(block) { }
};
class NArrayDeclaration : public NStatement{
public:
const NIdentifier& id;
const NIdentifier& type;
ExpressionList elements;
NArrayDeclaration(const NIdentifier& id, const NIdentifier& type,
ExpressionList& elements) :
id(id), type(type), elements(elements){}
};
class NRegisterDeclaration : public NStatement{
public:
const NIdentifier& type;
VariableList fields;
NRegisterDeclaration(const NIdentifier& type, VariableList fields) :
type(type), fields(fields){}
};
class NUnionDeclaration : public NStatement{
public:
const NIdentifier& type;
VariableList fields;
NUnionDeclaration(const NIdentifier& type, VariableList fields) :
type(type), fields(fields){}
};