-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsymbolTable.cpp
More file actions
45 lines (39 loc) · 1.22 KB
/
symbolTable.cpp
File metadata and controls
45 lines (39 loc) · 1.22 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
#include "symbolTable.h"
bool SymbolTable::addName(const char* name, size_t nameLength, size_t ID, int typeFlag)
{
if(table.size() == 0)
return false;
std::pair<std::map<std::string, std::pair<size_t, int> >::iterator, bool> ret;
ret = table.back().insert(std::pair<std::string, std::pair<size_t, int> >(std::string(name, nameLength), std::pair<size_t, int>(ID, typeFlag)));
return ret.second;
}
bool SymbolTable::addScope()
{
table.push_back(std::map<std::string, std::pair<size_t, int> >());
return true;
}
bool SymbolTable::findName(const char* name, size_t nameLength, size_t& ID, int& typeFlag)
{
std::vector< std::map<std::string, std::pair<size_t, int> > >::reverse_iterator rit = table.rbegin();
std::map<std::string, std::pair<size_t, int> >::iterator ret;
for(; rit != table.rend(); ++rit)
{
ret = (*rit).find(std::string(name, nameLength));
if(ret == (*rit).end())
continue;
else
{
ID = ret->second.first;
typeFlag = ret->second.second;
return true;
}
}
return false;
}
bool SymbolTable::popScope()
{
if(table.size() == 0)
return false;
table.pop_back();
return true;
}