diff options
| author | Cori Barker <coribarker2@gmail.com> | 2026-03-07 18:33:21 +0000 |
|---|---|---|
| committer | Cori Barker <coribarker2@gmail.com> | 2026-03-07 18:33:21 +0000 |
| commit | 50a51df0404ee4f057fbc19657672d1c7d3eef68 (patch) | |
| tree | 9cb9ed4572a357448f2b78c4ac0add7eaf6a1e7e /src/symbol_table.cpp | |
| parent | 6761fdd434a7e54551fe28398361f9eed5268406 (diff) | |
removed implementations of symbol table related classes, need to fix the parser to use the new AST node classes then i can write the symbol table classes and refactor the lexer and parser to use the symbol table
Diffstat (limited to 'src/symbol_table.cpp')
| -rw-r--r-- | src/symbol_table.cpp | 89 |
1 files changed, 0 insertions, 89 deletions
diff --git a/src/symbol_table.cpp b/src/symbol_table.cpp deleted file mode 100644 index 81ff474..0000000 --- a/src/symbol_table.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include "symbol_table.hpp" - -#include <iostream> - -SymbolTable::SymbolTable() : scopes(std::vector<Scope>), current_scope(nullptr), scope_level(0), global_scope(nullptr) {} - -SymbolTable::~SymbolTable() {} - -void SymbolTable::enterScope(std::string scope_name) { - Scope scope = Scope(scope_name, scope_level, current_scope); - scopes.push_back(scope*); - - this->current_scope = scope*; - this->scope_level ++; -} - -void SymbolTable::exitScope() { - parent_scope = getParentScope(); - this->current_scope = parent_scope - - this->scope_level --; -} - -Scope* SymbolTable::getCurrentScope() { - return this->current_scope; -} - -Scope* SymbolTable::getGlobalScope() { - return this->global_scope; -} - -int SymbolTable::getScopeLevel() { - return this->scope_level; -} - -void SymbolTable::insert(Symbol symbol) { - if (this->current_scope == nullptr) { - // error - } - - this->current_scope->define(symbol); -} - -Symbol* SymbolTable::lookup(std::string name) { - current_scope = getCurrentScope(); - symbol = current_scope->lookup(name); - - while (symbol == nullptr) { - current_scope = current_scope->getParentScope(); - if (current_scope == nullptr) { - return nullptr; - } - - symbol = current_scope->lookup(name); - } - - return symbol; -} - -Symbol* SymbolTable::lookupCurrentScope(std::string name) { - current_scope = getCurrentScope(); - return current_scope->lookup(name); -} - -bool SymbolTable::isDeclared(std::string name) { - symbol == this->lookup(name); - return (symbol != nullptr); -} - -bool SymbolTable::isDeclaredInCurrentScope(std::string name) { - symbol == this->lookupCurrentSceop(name); - return (symbol != nullptr); -} - -void display() { - std::cout << this->toString(); -} - -std::string toString() { - std::string indent; - std::string result; - - for (const Scope& i : this->scopes) { - indent += (" " * i->getScopeLevel()); - result += (indent + '\n' + i->toString()); - } - - return result; -} |
