-
Notifications
You must be signed in to change notification settings - Fork 0
/
符号表.h
149 lines (144 loc) · 2.5 KB
/
符号表.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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#pragma once
#include<iostream>
#include<map>
#include<fstream>
#include<string>
#include<queue>
#include<algorithm>
#include<vector>
#include<list>
#include<stack>
using namespace std;
class Cat_Table;
class I_Table;
class Token_Code //Token序列
{
public:
Token_Code()
{
this->type = ' ';
this->code = 0;
return;
}
Token_Code(char type, int code)
{
this->code = code;
this->type = type;
}
bool operator == (Token_Code k_var)
{
if (k_var.code == this->code && k_var.type == this->type)
return 1;
else
return 0;
}
char type; //类型
int code; //编码
};
class Quartion //四元式
{
friend ostream& operator<< (ostream& cout, Quartion Q);
public:
Quartion() { return; }
Quartion(string A, Token_Code B, Token_Code C, Token_Code D)
{
this->one = A;
this->two = B;
this->three = C;
this->four = D;
}
string one; //第一元
Token_Code two; //第二元
Token_Code three; //第三元
Token_Code four; //第四元
};
class Offset //地址
{
public:
Offset()
{
this->high = 0;
this->length = 0;
this->low = 0;
}
Offset(int low, int high)
{
this->low = low;
this->high = high;
this->length = high - low + 1;
}
int low; //地址起始
int high; //地址末
int length; //长度
};
class Cat_Table //变量类型的表各种类指向的表
{
public:
Cat_Table()
{
this->paralist = NULL;
this->type = 'V';
this->ptr = make_pair(0, 0);
}
Cat_Table(char type)
{
switch (type)
{
case 'F': {
this->paralist = new vector<I_Table*>;
this->ptr = make_pair(0, 0);
}break;
}
}
char type; //类型
pair<int, int> ptr; //层次号与偏移地址
int length; //长度
string con_val; //常数值
int parameter; //参数个数
int enter; //入口地址
int num; //函数编号
vector< I_Table*>* paralist; //参数列表
};
class I_Table //标识符表栏
{
public:
I_Table() { return; }
I_Table(int code,string name)
{
this->code = code;
this->name = name;
this->other = new Cat_Table;
temp = 0;
this->yn = 1;
}
string name; //名字
pair<char,int> type; //类型
string cat; //种类
int code; //编码
bool yn; //活跃信息
Cat_Table* other; //其余信息
bool temp; //是否临时变量
};
class Domain //域名类
{
public:
Domain(I_Table* T)
{
this->name = T->name;
this->type = T->type;
}
string name; //名字
pair<string,int> type; //类型
Offset ptr; //地址中包含了长度
};
class Struct_Table
{
public:
Struct_Table()
{
this->length = 0;
}
vector<Domain> Domain_List; //域名表
string name; //名字
int length; //结构体长度
};