TS_CPP
An efficient & easy to use implementation of a Symbol table used in most compilers
Loading...
Searching...
No Matches
SymbolTable.h
1#ifndef TS_SYMBOLTABLE_H
2#define TS_SYMBOLTABLE_H
3
4#include <vector>
5#include "unordered_map"
6#include "string"
7
8#include "TSConfig.h"
9#include "Entry.h"
10
11namespace TS_CPP{
12
18{
19public:
20
28 SymbolTable(int id, int* entryId, const std::string& tableName);
29
36 SymbolTable(int id, int* entryId);
37
44
49 int getId() const;
50
55 std::string getTableName() const;
56
62 Entry* createNewEntry(const std::string& lexeme);
63
69 Entry* getEntry(int entryId);
70
76 Entry* searchEntry(const std::string& lexeme);
77
83 bool deleteEntry(const std::string& lexeme);
84
90 bool deleteEntry(int entryId);
91
97 int getTableEntriesSize() const;
98
104 void _addTableEntriesSize(int size);
105
111 int _getDisplacement() const;
112
119 AttributeValue* getAttribute(const std::string& attributeName);
120
121
128 void setNumericAttribute(const std::string& attributeName, long long value);
129
130
137 void setStringAttribute(const std::string& attributeName, const char* value);
138
144 std::vector<Entry*>& _getEntriesStorage();
145
146
147private:
148
150 int id;
151
153 int* entryId;
154
156 std::string tableName;
157
159 std::vector<Entry*> storage;
160
162 std::unordered_map<std::string, int> lexemeToPos;
163
165 std::unordered_map<int, int> idToPos;
166
168 std::unordered_map<std::string,AttributeValue*> attributes;
169
171 int displacement = 0;
172
174 int tableEntriesSize = 0;
175
176 bool deleteEntryByPos(int pos);
177};
178
179}
180
181#endif //TS_SYMBOLTABLE_H
Definition Entry.h:19
std::vector< Entry * > & _getEntriesStorage()
int _getDisplacement() const
AttributeValue * getAttribute(const std::string &attributeName)
int getTableEntriesSize() const
Entry * createNewEntry(const std::string &lexeme)
void _addTableEntriesSize(int size)
void setNumericAttribute(const std::string &attributeName, long long value)
SymbolTable(int id, int *entryId, const std::string &tableName)
bool deleteEntry(const std::string &lexeme)
Entry * searchEntry(const std::string &lexeme)
void setStringAttribute(const std::string &attributeName, const char *value)
Entry * getEntry(int entryId)
std::string getTableName() const