-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyntax_tree.h
More file actions
95 lines (84 loc) · 1.5 KB
/
syntax_tree.h
File metadata and controls
95 lines (84 loc) · 1.5 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
#ifndef SYNTAX_TREE_H
#define SYNTAX_TREE_H
#include "inter_code.h"
enum non_terminals {
Program = 286,
ExtDefList,
ExtDef,
ExtDecList,
Specifier,
StructSpecifier,
OptTag,
Tag,
VarDec,
FunDec,
VarList,
ParamDec,
CompSt,
StmtList,
Stmt,
DefList,
Def,
DecList,
Dec,
Exp,
Args,
Epsilon,
LOAD,
STORE,
DEC,
ADDRESS,
PARAM,
ARG,
CALL,
READ,
WRITE,
GOTO,
GE,
LE,
GEQ,
LEQ,
EQ,
NEQ
};
typedef struct Type_* Type;
typedef struct FieldList_* FieldList;
struct Type_ {
enum { FUNC, BASIC, ARRAY, STRUCTURE } kind;
union {
// 基本类型
int basic;
// 数组类型
struct { Type elem; int size; } array;
// 结构体类型
FieldList structure;
// 函数类型
struct { Type ret_type; FieldList params; int line_no; } func;
} u;
int size;
};
struct FieldList_ {
char* name;
Operand op;
Type type;
FieldList tail;
};
typedef int NODE_TYPE;
struct node;
typedef struct node_list {
struct node *head;
struct node *tail;
} node_list;
typedef struct node {
NODE_TYPE type;
int line_no;
char *val;
int product_no;
node_list child_nodes;
struct node *next;
Type syn;
Type inh;
} node;
node *create_node(NODE_TYPE node_type, int line_no, const char *val, int product_no, int child_num, ...);
void traverse(node *root, int depth);
#endif