-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSymTable.cpp
More file actions
56 lines (46 loc) · 1.18 KB
/
SymTable.cpp
File metadata and controls
56 lines (46 loc) · 1.18 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
#include "SymTable.h"
SymTable::SymTable(string name, SymTable* pred) {
this->scopeName = name;
this->pred= pred;
}
void SymTable::addVar(string type, string name, string kind) {
if (ids.count(name)) {
cout << "Eroare: Id " << name << " este deja definit in scope " << scopeName << endl;
return;
}
IdInfo info(type, name, kind);
ids[name] = info;
}
bool SymTable::existsId(string name) {
return ids.count(name) > 0;
}
IdInfo* SymTable::findId(string name) {
if (ids.count(name)) {
return &ids[name];
}
if (pred != NULL) {
return pred->findId(name);
}
return NULL;
}
SymTable* SymTable::getPred() {
return pred;
}
void SymTable::print(ofstream& file) {
file << "Scope: " << scopeName << endl;
if (pred) {
file << "(Predecesor: " << pred->scopeName << ")" << endl;
}
if (ids.empty()) {
file << " [Empty scope]" << endl;
} else {
for ( auto& pair : ids) {
file << " Name: " << pair.first
<< " Type: " << pair.second.type
<< " Kind: " << pair.second.kind << endl;
}
}
}
SymTable::~SymTable() {
ids.clear();
}