symbol_table.hpp (644B)
1 #pragma once 2 3 class SymbolTable { 4 public: 5 explicit SymbolTable(); 6 ~SymbolTable() = default; 7 void enterScope(std::string scope_name); 8 void exitScope(); 9 Scope* getCurrentScope(); 10 Scope* getGlobalScope(); 11 int getScopeLevel(); 12 void insert(Symbol symbol); 13 Symbol* lookup(std::string name); 14 Symbol* lookupCurrentScope(std::string name); 15 bool isDeclared(std::string name); 16 bool isDeclaredInCurrentScope(std::string name); 17 void display(); 18 std::string toString(); 19 20 private: 21 std::vector<std::unique_ptr<Scope>> scopes; 22 Scope* current_scope; 23 int scope_level; 24 Scope* global_scope; 25 };