rendered paste body#include<iostream>
#include<string>
#include"SymbolTable.h"
#include<assert.h>
namespace RITCS4 {
SymbolTable::SymbolTable() {
_table = new map<std::string, int>();
}
void SymbolTable::declare( string name, int init = 0 ) {
assert(!contains(name));
_table.insert(pair(name,init));
}
void SymbolTable::set( string name, int val ) {
assert(contains(name));
_table[name] = val;
}
int SymbolTable::get( string name ) {
assert(contains(name));
return _table[name];
}
unsigned int SymbolTable::size() const {
assert(_table.size() >= 0);
return _table.size();
}
bool SymbolTable::contains( string name ) const {
map<String, int>::iterator iter = _table.find(name);
if(iter != _table.end()) {
return 1;
} else {
return 0;
}
}
void SymbolTable::dump( std::ostream &out ) const {
std::map<string,int>::iterator iter;
for(iter = _table.begin(); iter != _table.end; iter++) {
out << iter->first << ": " << iter->second;
}
}