-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.h
More file actions
103 lines (89 loc) · 2.07 KB
/
main.h
File metadata and controls
103 lines (89 loc) · 2.07 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
/*
* @Copyright: minic
* @Author: David.Huangjunlang
* @Description: 主程序头文件
* @LastEditors: David.Huangjunlang
* @LastEditTime: 2020-04-29 02:47:12
* @FilePath: /minic/main.h
*/
#ifndef MAIN_H
#define MAIN_H
#include <stdio.h>
#include <string>
using namespace std;
// 枚举节点类型
typedef enum
{
StmtK,
ExpK
} NodeKind;
// 枚举 statement node 类型
typedef enum
{
ProgramK,
DeclK,
ParamlK,
LocdeclK,
StmtlK,
ArgsK,
FunK,
CompK,
ArrayK,
SelectK,
IteraK,
ExpressionK,
ReturnK,
CallK,
VarK
} StmtKind;
// 枚举 expression node 类型
typedef enum
{
IdK,
ConstK,
AssignK,
OpK
} ExpKind;
// 每一个节点最多有三个子节点
#define MAXCHILDREN 3
// 用于语法树的结构体
typedef struct node
{
node *nodeChild[MAXCHILDREN]; // 子节点
int lineno;
node *next; // 链表指针
NodeKind nodekind; // 节点类型
union {
StmtKind stmt;
ExpKind exp;
} kind; // statement & expression 节点类型细分
string op; // 运算符属性
string name; // 变量名属性
int type;
int val; // 常量属性
int isArray;
/*
* If isParameter is TRUE, then this node declares an actual parameter
* to a function.
*/
int isParameter;
/* If isGlobal is TRUE, then the variable is a global */
int isGlobal;
/* parameter count and local variable count*/
int param_size;
int local_size;
/* scope of the node */
int scope;
};
// 用于区分不同yacc 中token type 的变量
typedef struct
{
string m_id; // string 类型存储id 的名字
std::string m_reserved; // string 类型存储关键字
int m_num; // int 类型 存储常量值
std::string m_op; // string 类型 存储符号
node *m_node; // node 存储语句
} ytype;
// 定义 yacc 节点 token 类型
#define YYSTYPE ytype
#endif