-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathast.h
executable file
·100 lines (81 loc) · 1.83 KB
/
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
#ifndef AST_H
#define AST_H
enum {
BE_LT, BE_LTE,
BE_GT, BE_GTE,
BE_EQ, BE_NEQ,
BE_ADD, BE_SUB,
BE_MUL, BE_DIV,
K_NUM, K_CALL,
E_ASSIGN, VAR_NAME,
ARRAY_ACCESS, RETURN,
WHILE, IF_THEN,
COMPOUND, PARAM,
FUNCTION, VAR_DECL
} kind;
struct list; // forward declaration
typedef struct AST AST;
struct AST
{
int lineno_;
int kind_; // kind of the ast node
int type_; // type of the ast node
struct symtab* M; // to keep track of methods
struct symtab* V; // to keep track of variables
union {
int val_;
struct {
AST* lhs_;
AST* rhs_;
} be;
struct {
char* name_;
struct list* args_;
} call;
struct {
AST* to_;
AST* expr_;
} assign;
struct {
char* name_;
} variable;
struct {
char* name_;
AST* expr_;
} access;
struct {
AST* expr_;
} ret;
struct {
AST* expr_;
AST* stmt_;
} while_loop;
struct {
AST* expr_;
AST* if_stmt_;
AST* else_stmt_;
} if_then;
struct {
struct list* decls_;
struct list* stmts_;
} compound;
struct {
int type_spec_;
char* name_;
int ref_;
} param;
struct {
int ret_type_;
char* name_;
struct list* params_;
AST* body_;
} function;
struct {
int type_spec_;
char* name_;
int size_;
int ref_;
} var_decl;
} d;
};
#endif