A simple scripting language in C++
Ferenc Szontágh
2025-04-18 e398a47fc9ef8ded356c56b5739808ce1192e3d2
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
52
53
54
55
56
57
58
// 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_; // ns
    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 getKind() 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; }
 
    std::string dump() const {
        std::string r = "\t\t  "+ kindToString(this->kind_) + " name: '" + name_ + "' \n\t\t\tContext: " + context_;
        r += " \n\t\t\tType: " + Symbols::Variables::TypeToString(value_.getType());
        r += " \n\t\t\tValue: '" + Symbols::Value::to_string(value_) + "'";
        return r;
    }
 
 
 
    // Templated getter
    template <typename T> T getAs() const { return std::get<T>(value_); }
};
 
}  // namespace Symbols
 
#endif