Question: Give: #include SymbolTable.h #include #include using namespace std; #define NUM_BUCK 500 struct Node { Node(const string& id, int lineNum, int scope) { m_id = id;
Give:
#include "SymbolTable.h" #include using namespace std; #define NUM_BUCK 500
struct Node { Node(const string& id, int lineNum, int scope) { m_id = id; m_line = lineNum; m_scope = scope; } string m_id; int m_line; int m_scope; };
int hashFunc(const string &id) { int total = 0; for (int i = 0; i int index = (total % NUM_BUCK); return(index); } class SymbolTableImpl { public: SymbolTableImpl() { m_AtScope = 0; } ~SymbolTableImpl(); void enterScope(); bool exitScope(); bool declare(const string& id, int lineNum); int find(const string& id); private: list SymbolTableImpl::~SymbolTableImpl() { } void SymbolTableImpl::enterScope() { m_AtScope++; } bool SymbolTableImpl::exitScope() { if (m_AtScope == 0) return false; for (int j = 0; j else n++; } } m_AtScope--; return true; } bool SymbolTableImpl::declare(const string& id, int lineNum) { int slot = hashFunc(id); list Node* n = new Node(id, lineNum, m_AtScope); if (b->empty()) { b->push_front(*n); return true; } for (list b->push_front(*n); return true; } int SymbolTableImpl::find(const string& id) { if (id.empty()) return -1; int slot = hashFunc(id); list for (list return -1; } //*********** SymbolTable functions ************** // For the most part, these functions simply delegate to SymbolTableImpl's // functions. SymbolTable::SymbolTable() { m_impl = new SymbolTableImpl; } SymbolTable::~SymbolTable() { delete m_impl; } void SymbolTable::enterScope() { m_impl->enterScope(); } bool SymbolTable::exitScope() { return m_impl->exitScope(); } bool SymbolTable::declare(const string& id, int lineNum) { return m_impl->declare(id, lineNum); } int SymbolTable::find(const string& id) const { return m_impl->find(id); } How do I write a distructor for SymbolTableImpl
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
