A simple scripting language in C++
Ferenc Szontágh
2025-04-14 d7cd4947b37a168034e9fca2501d98553fdcc137
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SymbolContainer.hpp
#ifndef SYMBOL_CONTAINER_HPP
#define SYMBOL_CONTAINER_HPP
 
#include "SymbolTable.hpp"
 
namespace Symbols {
 
class SymbolContainer {
    std::shared_ptr<SymbolTable> globalScope_;
    std::shared_ptr<SymbolTable> currentScope_;
 
public:
    SymbolContainer() {
        globalScope_ = std::make_shared<SymbolTable>();
        currentScope_ = globalScope_;
    }
 
    void enterScope() {
        currentScope_ = std::make_shared<SymbolTable>(currentScope_);
    }
 
    void leaveScope() {
        if (currentScope_->getParent()) {
            currentScope_ = currentScope_->getParent();
        }
    }
 
    void define(const std::string& ns, const SymbolPtr& symbol) {
        currentScope_->define(ns, symbol);
    }
 
    SymbolPtr resolve(const std::string& ns, const std::string& name) const {
        return currentScope_->get(ns, name);
    }
 
    bool exists(const std::string& ns, const std::string& name) const {
        return currentScope_->exists(ns, name);
    }
 
    std::vector<SymbolPtr> listNamespace(const std::string& ns) const {
        return currentScope_->listAll(ns);
    }
 
    std::shared_ptr<SymbolTable> getGlobalScope() const { return globalScope_; }
    std::shared_ptr<SymbolTable> getCurrentScope() const { return currentScope_; }
};
 
} // namespace Symbols
 
#endif