#include #include #include"SymbolTable.h" #include namespace RITCS4 { SymbolTable::SymbolTable() { _table = new map(); } 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::iterator iter = _table.find(name); if(iter != _table.end()) { return 1; } else { return 0; } } void SymbolTable::dump( std::ostream &out ) const { std::map::iterator iter; for(iter = _table.begin(); iter != _table.end; iter++) { out << iter->first << ": " << iter->second; } }