-
Notifications
You must be signed in to change notification settings - Fork 2
/
SymbolTable.h
53 lines (37 loc) · 1 KB
/
SymbolTable.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
#ifndef SYMBOLTABLE_H
#define SYMBOLTABLE_H
/* Which of the favors of your Lord will you deny ? */
#include<bits/stdc++.h>
#include "ScopeTable.h"
using namespace std;
template <class T>
string to_str(T x)
{
stringstream ss;
ss<<x;
return ss.str();
}
class SymbolTable
{
ScopeTable* cur;
int bucket_size;
function<int(string)> func;
public:
template<typename T>
SymbolTable(int bucket_size,T func) /// constructor
{
this->bucket_size = bucket_size;
this->func = func;
cur = new ScopeTable(bucket_size,func);
}
~SymbolTable();
void enter_scope(); /// enter scope = push : create and push a new ScopeTable
void exit_scope(); /// exit scope = pop : remove the current ScopeTable
bool insert_symbol(SymbolInfo si);
bool remove_symbol(string key);
SymbolInfo* lookup(string key);
void print_current_scope(ofstream &out);
void print_all_scope(ofstream &out);
string getCurScopeTableId();
};
#endif // SYMBOLTABLE_H