A simple scripting language in C++
Ferenc Szontágh
2025-04-18 d092df5264f6e48f9d59650c092b8297382b1316
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
// VariableSymbol.hpp
#ifndef VARIABLE_SYMBOL_HPP
#define VARIABLE_SYMBOL_HPP
 
#include "BaseSymbol.hpp"
#include "Symbols/VariableTypes.hpp"
 
namespace Symbols {
 
class VariableSymbol : public Symbol {
  protected:
    Symbols::Variables::Type type_;
  public:
    VariableSymbol(const std::string & name, const Symbols::Value & value, const std::string & context,
                   Variables::Type type) :
        Symbol(name, value, context, Symbols::Kind::Variable),
        type_(type) {}
 
    Symbols::Kind kind() const override { return Symbols::Kind::Variable; }
 
    Variables::Type type() const { return type_; }
 
    std::string toString() const {
        std::string r = "VariableSymbol: " + name_ + " Type: " + Symbols::Variables::TypeToString(type_);
        if (type_ == Symbols::Variables::Type::INTEGER) {
            r += " Value: " + std::to_string(value_.get<int>());
        } else if (type_ == Symbols::Variables::Type::DOUBLE) {
            r += " Value: " + std::to_string(value_.get<double>());
        } else if (type_ == Symbols::Variables::Type::FLOAT) {
            r += " Value: " + std::to_string(value_.get<float>());
        } else if (type_ == Symbols::Variables::Type::STRING) {
            r += " Value: " + value_.get<std::string>();
        } else if (type_ == Symbols::Variables::Type::BOOLEAN) {
            r += " Value: " + std::to_string(value_.get<bool>());
        } else if (type_ == Symbols::Variables::Type::NULL_TYPE) {
            r += " Value: null";
        }
 
        return r;
    }
};
 
}  // namespace Symbols
 
#endif