-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSymbolTable.h
More file actions
68 lines (60 loc) · 1.68 KB
/
SymbolTable.h
File metadata and controls
68 lines (60 loc) · 1.68 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
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef SYMBOL_TABLE_H
#define SYMBOL_TABLE_H
#include <map>
#include <string>
#include "SymbolTableEntry.h"
using namespace std;
class SYMBOL_TABLE
{
private:
std::map<string, SYMBOL_TABLE_ENTRY> hashTable;
public:
//Constructor
SYMBOL_TABLE( ) { }
// Add SYMBOL_TABLE_ENTRY x to this symbol table.
// If successful, return true; otherwise, return false.
bool addEntry(SYMBOL_TABLE_ENTRY x)
{
// Make sure there isn't already an entry with the same name
map<string, SYMBOL_TABLE_ENTRY>::iterator itr;
if ((itr = hashTable.find(x.getName())) == hashTable.end())
{
hashTable.insert(make_pair(x.getName(), x));
return(true);
}
else return(false);
}
bool changeEntry(SYMBOL_TABLE_ENTRY x)
{
// Make sure the entry we want to change in the symbol table
// is actually in the symbol table.
map<string, SYMBOL_TABLE_ENTRY>::iterator itr;
if ((itr = hashTable.find(x.getName())) != hashTable.end())
{
hashTable.erase(itr);
hashTable.insert(make_pair(x.getName(), x));
return true;
}
else return(false);
}
// If a SYMBOL_TABLE_ENTRY with name theName is
// found in this symbol table, then return its type info;
// otherwise, return undefined.
TYPE_INFO findEntry(string theName)
{
TYPE_INFO info = {UNDEFINED, NOT_APPLICABLE, NOT_APPLICABLE, false};
map<string, SYMBOL_TABLE_ENTRY>::iterator itr;
if ((itr = hashTable.find(theName)) == hashTable.end())
return(info);
else return(itr->second.getTypeInfo());
}
int getNumEntries()
{
return(hashTable.size());
}
bool find_param(string theName)
{
return hashTable[theName].getParam();
}
};
#endif // SYMBOL_TABLE_H