-
Notifications
You must be signed in to change notification settings - Fork 1
/
visitor_ast.h
executable file
·268 lines (140 loc) · 4.79 KB
/
visitor_ast.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#ifndef COMPILADOR_2019_3_VISITOR_H
#define COMPILADOR_2019_3_VISITOR_H
#ifndef VISITOR_H_INCLUDED
#define VISITOR_H_INCLUDED
#include <iostream>
//#include "ast.h"
//#include "lexycal.h"
// AST NODES
class ASTNode;
class TokenNode;
class ProgramNode;
class VarDeclNode;
class IdListNode;
class FunctionListNode;
class FunctionNode;
class FormalListNode;
class TypeDeclNode;
class TypeNode;
class PointerNode;
class StmtListNode;
class StmtNode;
class IfNode;
class WhileNode;
class SwitchNode;
class BreakNode;
class PrintNode;
class ReadLnNode;
class ReturnNode;
class CaseBlockNode;
class ThrowNode;
class ExpListNode;
class TryNode;
class ExpNode;
class AssignNode;
class NameExpNode;
class PointerExpNode;
class AddressValNode;
class PointerValNode;
class ArrayNode;
class ArrayCallNode;
class CallNode;
class AdditionOPNode;
class MultiplicationOPNode;
class BooleanOPNode;
class NotNode;
class SignNode;
class VarStmtNode;
class PrimaryNode;
class VisitorAST {
public:
virtual ~VisitorAST() = default;
virtual void visit(ProgramNode *node) = 0;
virtual void visit(TypeNode *node) = 0;
virtual void visit(FunctionListNode *node) = 0;
virtual void visit(PointerNode *node) = 0;
virtual void visit(StmtListNode *node) = 0;
virtual void visit(IfNode *node) = 0;
virtual void visit(WhileNode *node) = 0;
virtual void visit(SwitchNode *node) = 0;
virtual void visit(BreakNode *node) = 0;
virtual void visit(PrintNode *node) = 0;
virtual void visit(ReadLnNode *node) = 0;
virtual void visit(ReturnNode *node) = 0;
virtual void visit(CaseBlockNode *node) = 0;
virtual void visit(ThrowNode *node) = 0;
virtual void visit(ExpListNode *node) = 0;
virtual void visit(TryNode *node) = 0;
virtual void visit(TokenNode *node) = 0;
virtual void visit(AssignNode *node) = 0;
virtual void visit(ArrayNode *node) = 0;
virtual void visit(CallNode *node) = 0;
virtual void visit(AdditionOPNode *node) = 0;
virtual void visit(MultiplicationOPNode *node) = 0;
virtual void visit(BooleanOPNode *node) = 0;
virtual void visit(NotNode *node) = 0;
virtual void visit(SignNode *node) = 0;
virtual void visit(ArrayCallNode *node) = 0;
virtual void visit(FormalListNode *node) = 0;
virtual void visit(IdListNode *node) = 0;
virtual void visit(PrimaryNode *node) = 0;
virtual void visit(VarStmtNode *node) = 0;
virtual void visit(FunctionNode *node) = 0;
virtual void visit(PointerExpNode *node) = 0;
virtual void visit(NameExpNode *node) = 0;
virtual void visit(VarDeclNode *node) = 0;
virtual void visit(TypeDeclNode *node) = 0;
virtual void visit(AddressValNode *node) = 0;
virtual void visit(PointerValNode *node) = 0;
virtual void visit(StmtNode *node) = 0;
};
class PrintAST : public VisitorAST {
private:
unsigned int level;
void printAST(const char *node_name);
void printLexemeAST(const char *node_name, const char *aux);
void up_level();
void down_level();
public:
PrintAST();
void visit(ProgramNode *node) override;
void visit(TypeNode *node) override;
void visit(FunctionListNode *node) override;
void visit(PointerNode *node) override;
void visit(StmtListNode *node) override;
void visit(IfNode *node) override;
void visit(WhileNode *node) override;
void visit(SwitchNode *node) override;
void visit(BreakNode *node) override;
void visit(PrintNode *node) override;
void visit(ReadLnNode *node) override;
void visit(ReturnNode *node) override;
void visit(CaseBlockNode *node) override;
void visit(ThrowNode *node) override;
void visit(ExpListNode *node) override;
void visit(TryNode *node) override;
void visit(TokenNode *node) override;
void visit(AssignNode *node) override;
void visit(ArrayNode *node) override;
void visit(CallNode *node) override;
void visit(AdditionOPNode *node) override;
void visit(MultiplicationOPNode *node) override;
void visit(BooleanOPNode *node) override;
void visit(NotNode *node) override;
void visit(SignNode *node) override;
void visit(ArrayCallNode *node) override;
void visit(FormalListNode *node) override;
void visit(IdListNode *node) override;
void visit(PrimaryNode *node) override;
void visit(VarStmtNode *node) override;
void visit(FunctionNode *node) override;
void visit(PointerExpNode *node) override;
void visit(NameExpNode *node) override;
void visit(VarDeclNode *node) override;
void visit(TypeDeclNode *node) override;
void visit(AddressValNode *node) override;
void visit(PointerValNode *node) override;
void visit(StmtNode *node) override;
};
#endif //VISITOR_H_INCLUDED
#endif //COMPILADOR_2019_3_VISITOR_H