-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSymbolTable.cpp
58 lines (56 loc) · 1.45 KB
/
SymbolTable.cpp
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
#include "SymbolTable.h"
void SymbolTable::run(string filename)
{
smatch m;
regex assign_regex("ASSIGN ([a-z][\\w]*) (.*)");
regex lookup_regex("LOOKUP ([a-z][\\w]*)");
SplayTree *splay = new SplayTree();
ifstream file(filename);
string tmp = "";
while (getline(file, tmp))
{
if (searchKey(tmp) == "ins")
{
InsertFunc(tmp, splay->root, splay->level);
}
else if (regex_match(tmp, m, assign_regex))
{
AssignFunc(m, splay->root, splay->level);
}
else if (searchKey(tmp) == "be")
{
splay->level++;
}
else if (searchKey(tmp) == "e")
{
splay->level--;
if (splay->level < 0)
{
Destructor(splay->root);
delete splay;
throw UnknownBlock();
}
deleteNode(splay->root, splay->level + 1);
}
else if (regex_match(tmp, m, lookup_regex))
{
LookUpFunc(m, splay->root, splay->level);
}
else if (searchKey(tmp) == "prt")
{
PrintFunc(splay->root);
}
else
throw InvalidInstruction(tmp); //delete all(leak)
}
if (splay->level > 0)
{
Destructor(splay->root);
throw UnclosedBlock(splay->level);
delete splay;
}
file.close();
Destructor(splay->root);
delete splay;
//delete all(leak)
}