A simple scripting language in C++
Ferenc Szontágh
2025-04-15 3895272a7f238c9aef0b584bd3b10b900445245d
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
// BaseSymbol.hpp
#ifndef BASE_SYMBOL_HPP
#define BASE_SYMBOL_HPP
 
#include <string>
 
#include "SymbolKind.hpp"
#include "Value.hpp"
 
namespace Symbols {
 
class Symbol {
  protected:
    std::string   name_;
    Value         value_;
    std::string   context_;
    Symbols::Kind kind_;
 
  public:
    Symbol(const std::string & name, const Value & value, const std::string & context, Symbols::Kind type) :
        name_(name),
        value_(value),
        context_(context),
        kind_(type) {}
 
    virtual ~Symbol() = default;
 
    // Polimorf azonosító
    virtual Symbols::Kind kind() const = 0;
 
    // Getterek
    const std::string & name() const { return name_; }
 
    const std::string & context() const { return context_; }
 
    Symbols::Kind type() const { return kind_; }
 
    // Virtuális getter/setter a value-hoz
    virtual const Value & getValue() const { return value_; }
 
    virtual void setValue(const Value & value) { value_ = value; }
 
    // Templated getter
    template <typename T> T getAs() const { return std::get<T>(value_); }
};
 
}  // namespace Symbols
 
#endif