-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsymbolItem.h
78 lines (75 loc) · 1.54 KB
/
symbolItem.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
#pragma once
#ifndef SYMBOLITEM_H
#define SYMBOLITEM_H
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;
class symbolItem {
public:
string name;
int kind; //var const function array
int type; //int char void
int constInt;
char constChar;
int length; //数组长度 对于函数用于记录这个函数有多少变量(参数+局部变量+临时)
vector<int> parameterTable; //参数类型
int addr; //地址
symbolItem(string s, int add = 0, int k = 0, int t = 0, int ci = 0, char cc = ' ', int l = 0) :
name(s), kind(k), type(t), constInt(ci), constChar(cc), length(l), addr(add) {
parameterTable = vector<int>();
}
symbolItem() {}
void output() {
cout << name << " ";
switch (type) {
case 1:
cout << "int ";
break;
case 2:
cout << "char ";
break;
case 3:
cout << "void ";
break;
}
switch (kind) {
case 1:
cout << "var ";
break;
case 2:
cout << "const ";
if (type == 1) {
cout << constInt << " ";
}
else if (type == 2) {
cout << constChar << " ";
}
break;
case 3:
cout << "func ";
cout << "parameters: (";
for (int i = 0; i < parameterTable.size(); i++) {
if (parameterTable[i] == 1) {
cout << "int ";
}
else {
cout << "char ";
}
}
cout << ")" << " 参数个数: " << length << " ";
break;
case 4:
cout << "array ";
cout << length << " ";
break;
}
cout << "addr: " << addr;
cout << "\n";
}
void insert(int t) {
parameterTable.push_back(t);
}
};
#endif // !SYMBOLITEM_H