-
Notifications
You must be signed in to change notification settings - Fork 1
/
norms.h
147 lines (122 loc) · 3.43 KB
/
norms.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
140
141
142
143
144
145
146
147
#pragma once
#include <iostream>
#include <vector>
#include <string>
class CodeGenContext;
class NStatement;
class NExpression;
class NVariableDeclaration;
typedef std::vector<NStatement*> StatementList;
typedef std::vector<NExpression*> ExpressionList;
typedef std::vector<NVariableDeclaration*> VariableList;
enum SType {
kNORM,
kNEXPRESSION,
kNSTATEMENT,
kNIDENTIFIER,
kNMETHODCALL,
kNBINARYOPERATOR,
kNBLOCK,
kNNEGEXPRESSION,
kNEXPRESSIONSTATEMENT,
kNVARIABLEDECLARATION,
kNFUNCTIONDECLARATION,
};
class Norm {
public:
virtual ~Norm() {}
virtual SType stype() const { return stype_; }
private:
SType stype_;
};
class NExpression : public Norm {
public:
virtual SType stype() const { return stype_; }
private:
SType stype_;
};
class NStatement : public Norm {
public:
virtual SType stype() const { return stype_; }
private:
SType stype_;
};
class NIdentifier : public NExpression {
public:
std::string name;
SType stype_;
NIdentifier(const std::string& name) : name(name), stype_(kNIDENTIFIER) {}
virtual SType stype() const { return stype_; }
};
class NMethodCall : public NExpression {
public:
const NIdentifier& id;
ExpressionList arguments;
SType stype_;
NMethodCall(const NIdentifier& id, ExpressionList& arguments) :
id(id), arguments(arguments), stype_(kNMETHODCALL) {}
NMethodCall(const NIdentifier& id) : id(id), stype_(kNMETHODCALL) {}
virtual SType stype() const { return stype_; }
};
class NBinaryOperator : public NExpression {
public:
NExpression& lhs;
int op;
NExpression& rhs;
SType stype_;
NBinaryOperator(NExpression& lhs, int op, NExpression& rhs) :
lhs(lhs), op(op), rhs(rhs), stype_(kNBINARYOPERATOR) {}
virtual SType stype() const { return stype_; }
};
class NBlock : public NExpression {
public:
StatementList statements;
SType stype_;
NBlock() : stype_(kNBLOCK) {}
virtual SType stype() const { return stype_; }
};
class NNegExpression : public NExpression {
public:
NExpression& exp;
bool negated;
SType stype_;
NNegExpression(NExpression& exp, bool negated) :
exp(exp), negated(negated), stype_(kNNEGEXPRESSION) {}
virtual SType stype() const { return stype_; }
};
class NExpressionStatement : public NStatement {
public:
NExpression& expression;
SType stype_;
NExpressionStatement(NExpression& expression) :
expression(expression),
stype_(kNEXPRESSIONSTATEMENT) {}
virtual SType stype() const { return stype_; }
};
class NVariableDeclaration : public NStatement {
public:
const NIdentifier& type;
NIdentifier& id;
NExpression *assignmentExpr;
SType stype_;
NVariableDeclaration(const NIdentifier& type, NIdentifier& id) :
type(type), id(id), stype_(kNVARIABLEDECLARATION) {}
NVariableDeclaration(const NIdentifier& type, NIdentifier& id,
NExpression *assignmentExpr) :
type(type), id(id), assignmentExpr(assignmentExpr),
stype_(kNVARIABLEDECLARATION) {}
virtual SType stype() const { return stype_; }
};
class NFunctionDeclaration : public NStatement {
public:
const NIdentifier& type;
const NIdentifier& id;
VariableList arguments;
NBlock& block;
SType stype_;
NFunctionDeclaration(const NIdentifier& type, const NIdentifier& id,
const VariableList& arguments, NBlock& block) :
type(type), id(id), arguments(arguments), block(block),
stype_(kNFUNCTIONDECLARATION) {}
virtual SType stype() const { return stype_; }
};