-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtraverseTree.h
More file actions
92 lines (56 loc) · 2.19 KB
/
traverseTree.h
File metadata and controls
92 lines (56 loc) · 2.19 KB
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
#include "AST.h"
/* There are 8 statements which contain { } brackets. Each pair of bracket can express a scope */
typedef enum { CLASS_scope, FUNC_scope, DO_scope, WHILE_scope, FOR_scope, IF_scope, COMPOUND_scope } SCOPETYPE;
/* start scope and end scope used for make the linked list */
struct Scope *startScope, *endScope;
/* store the class name and function name to make a symbol table*/
char* currentClassName;
char* currentFuncName;
/* count down the number of statements in each scope */
struct Scope {
/* type */
SCOPETYPE type;
/* number of the scope type */
int do_num;
int while_num;
int for_num;
int if_num;
int compound_num;
/* parent and children */
struct Scope* parent;
struct Scope* child;
};
struct Scope* createNewScope(SCOPETYPE type, struct Scope* parent);
void deleteScope(struct Scope** endScope);
int getScopeNum(SCOPETYPE type, struct Scope* parent);
/* avoid some warning from the terminal */
int yylex();
int yyparse();
void visitProgram(struct Program* program);
void visitClass(struct Class* _class);
void visitMember(struct Member* member);
void visitVarDecl(struct VarDecl* decl);
void visitMethodDecl(struct MethodDecl* decl);
void visitMethodDef(struct MethodDef* decl);
void visitClassMethod(struct ClassMethodDef* def);
void visitmainFunc(struct MainFunc* mainfunc);
void visitParam(struct Param* param);
void visitIdent(struct Ident* ident);
void visitType(struct Type* type);
void visitCompoundStmt(struct CompoundStmt* comp);
void visitStmt(struct Stmt* stmt);
void visitExprStmt(struct ExprStmt* exprstmt);
void visitAssignStmt(struct AssignStmt* assign);
void visitReturnStmt(struct RetStmt* retstmt);
void visitWhileStmt(struct WhileStmt* whilestmt);
void visitDoStmt(struct DoStmt* dostmt);
void visitForStmt(struct ForStmt* forstmt);
void visitIfStmt(struct IfStmt* ifstmt);
void visitExpr(struct Expr* expr);
void visitOperExpr(struct OperExpr* operexpr);
void visitRefExpr(struct RefExpr* ref);
void visitRefVarExpr(struct RefVarExpr* ref);
void visitRefCallExpr(struct RefCallExpr* ref);
void visitIdentExpr(struct IdentExpr* identexpr);
void visitCallExpr(struct CallExpr* callexpr);
void visitArg(struct Arg* arg);