#include <symboltable.hpp>
Public Member Functions | |
SymbolTable () | |
Constructor. | |
virtual | ~SymbolTable () |
Destructor. | |
void | openScope () |
Open a new scope. | |
void | closeScope () |
Close current scope. | |
unsigned int | currentLevel () const |
Get the current scope level. | |
T * | retrieve (const std::string &id) |
Check if an identifier is declared. | |
void | enter (const std::string &id, T *newEntry) |
Insert identifier into current scope. | |
Private Attributes | |
std::vector< std::map< std::string, T * > * > | Scopes |
unsigned int | CurrentLevel |
Simple template class for the symbol tabels that we use. It provides scoping functionality and stores an identifier an a pointer to an object for each symbol tabel entry. The symbol table opens a global scope, scope 0 on creation. Usage example:
SymbolTable<IdEntry> symbol_table; // create a new symbol table with IdEntries symbol_table.enter( "bob", new IdEntry( whatever params IdEntry has ) ); IdEntry *entry = symbol_table.retrieve( "bob" ); // fetch the item we just inserted
SymbolTable will delete all entries added with enter when either the added entry goes out of scope or when the symbol table is deleted. The symbol table starts out in scope level 0 which represents the global scope.
Definition at line 116 of file symboltable.hpp.
|
Constructor. Default constructor |
|
Destructor. Destroys the object and all the objects in de symbol table. |
|
Close current scope. All identifiers in the current scope level will be removed from the symbol table.
Definition at line 60 of file symboltable.cpp. |
|
Insert identifier into current scope.
Definition at line 102 of file symboltable.cpp. |
|
Check if an identifier is declared.
Definition at line 83 of file symboltable.cpp. |