-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathast.h
More file actions
132 lines (115 loc) · 3.54 KB
/
ast.h
File metadata and controls
132 lines (115 loc) · 3.54 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
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
#ifndef AST_H
#define AST_H
#define AST_TY_X \
X(X_NUM) \
X(X_MUL) \
X(X_ADD) \
X(X_REL) \
X(X_AND) \
X(X_OR) \
X(X_UNARY) \
X(X_ID) \
X(X_ASSIGN) \
X(X_STRING_LITERAL) \
X(X_ACTUALS) \
X(X_EXPS) \
X(X_BLOCK) \
X(X_EMPTY) \
X(X_BREAK) \
X(X_FUNC) \
X(X_RETURN) \
X(X_FOR) \
X(X_IF) \
X(X_IFELSE) \
X(X_ELSE) \
X(X_TID) \
X(X_NID) \
X(X_VAR) \
X(X_PROGRAM) \
X(X_FNID) \
X(X_ELSEIF) \
X(X_PARAMS) \
X(X_PARAMS2) \
X(X_FORMALS) \
X(X_FORMALSEMPTY) \
X(X_PARDECL) \
X(X_ACTUALS2) \
X(X_ACTUALS3) \
X(X_FACTUALSX) \
X(X_UNARYNOT) \
X(X_RELC) \
enum AstTy {
#define X(INP) INP,
AST_TY_X
#undef X
};
// R Rou
struct fR {
char* ident;
struct Ast* r;
};
struct fL {
char* ident;
struct Ast* r;
};
// Full Routine, Used for Binary
struct fF {
char* ident;
struct Ast* l;
struct Ast* r;
};
// Single Routine, used for single factors
struct fS {
char* ident;
};
// Single Routine, Used for Indiviudal AST NODES WITH NO CHILDREN
struct singleN{
struct Ast* s;
};
// Triple Routine, Includes Middle Child
struct fT {
char* ident;
struct Ast* l;
struct Ast* m;
struct Ast* r;
};
struct forNode {
char* ident;
char* l2;
struct Ast* l;
struct Ast* r;
};
struct extraChild{
struct Ast* child;
};
union astOpt {
struct fR fr; // Right
struct fL fl; // Left
struct fF ff; // Full
struct fS fs; // Single
struct singleN sn;
struct fT ft; // Middle
struct forNode fornode; // For
struct extraChild fc;
};
struct Ast {
enum AstTy ty;
int lineno;
int length;
int capacity;
int childflag;
char* idtransfer;
char* sig;
enum AstTy parentty;
struct Record* symbol;
union astOpt payload;
};
// Global Variable for YYParse
extern struct Ast* program;
// pretty printing functions
void pShowAst(struct Ast* program);
void pSemanticsAst(struct Ast* program);
char const* pShowAstTy(enum AstTy ty);
void myTypeCheck(struct Ast* program);
void myTypeGet(struct Ast* program);
#endif