A simple scripting language in C++
Ferenc Szontágh
2025-04-19 c8f8dbada301cd66d8c40cd0bd8ea0e8ae669644
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
#ifndef IDENTIFIER_EXPRESSION_NODE_HPP
#define IDENTIFIER_EXPRESSION_NODE_HPP
 
#include "ExpressionNode.hpp"
#include "Symbols/SymbolContainer.hpp"
#include "Symbols/Value.hpp"
 
namespace Interpreter {
 
class IdentifierExpressionNode : public ExpressionNode {
    std::string name_;
 
  public:
    explicit IdentifierExpressionNode(std::string name) : name_(std::move(name)) {}
 
    Symbols::Value evaluate(Interpreter & /*interpreter*/) const override {
        const auto ns = Symbols::SymbolContainer::instance()->currentScopeName() + ".variables";
        if (Symbols::SymbolContainer::instance()->exists(name_, ns)) {
            return Symbols::SymbolContainer::instance()->get(ns, name_)->getValue();
        }
        throw std::runtime_error("Variable " + name_ + " does not exist in ns: " + ns);
    }
 
    std::string toString() const override { return name_; }
};
 
}  // namespace Interpreter
 
#endif  // IDENTIFIER_EXPRESSION_NODE_HPP