A simple scripting language in C++
Ferenc Szontágh
2025-04-18 be8887e8061caad34d6fdfd32c6e4d7e3fca4b08
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SymbolFactory.hpp
#ifndef SYMBOL_FACTORY_HPP
#define SYMBOL_FACTORY_HPP
 
#include <memory>
#include <string>
 
#include "ConstantSymbol.hpp"
#include "FunctionSymbol.hpp"
#include "VariableSymbol.hpp"
 
namespace Symbols {
 
class SymbolFactory {
  public:
    static std::shared_ptr<Symbol> createVariable(const std::string & name, const Symbols::Value & value,
                                                  const std::string & context) {
        return std::make_shared<VariableSymbol>(name, value, context, value.getType());
    }
 
    static std::shared_ptr<Symbol> createVariable(const std::string & name, const Symbols::Value & value,
                                                  const std::string & context, Variables::Type type) {
        return std::make_shared<VariableSymbol>(name, value, context, type);
    }
 
    static std::shared_ptr<Symbol> createConstant(const std::string & name, const Symbols::Value & value,
                                                  const std::string & context) {
        return std::make_shared<ConstantSymbol>(name, value, context);
    }
 
    static std::shared_ptr<Symbol> createFunction(const std::string & name, const std::string & context,
                                                  const Symbols::FunctionParameterInfo & parameters = {}) {
        return std::make_shared<FunctionSymbol>(name, context, parameters);
    }
 
    static std::shared_ptr<Symbol> createFunction(const std::string & name, const std::string & context,
                                                  const Symbols::FunctionParameterInfo & parameters,
                                                  const std::string &                    plainBody) {
        return std::make_shared<FunctionSymbol>(name, context, parameters, plainBody);
    }
 
    static std::shared_ptr<Symbol> createFunction(const std::string & name, const std::string & context,
                                                  const Symbols::FunctionParameterInfo & parameters,
                                                  const std::string & plainBody, Symbols::Variables::Type returnType) {
        return std::make_shared<FunctionSymbol>(name, context, parameters, plainBody, returnType);
    }
 
    // Overloadok
    static std::shared_ptr<Symbol> createVariable(const std::string & name, int value, const std::string & context) {
        return createVariable(name, Symbols::Value(value), context, Symbols::Variables::Type::INTEGER);
    }
 
    static std::shared_ptr<Symbol> createVariable(const std::string & name, double value, const std::string & context) {
        return createVariable(name, Symbols::Value(value), context, Symbols::Variables::Type::DOUBLE);
    }
 
    static std::shared_ptr<Symbol> createVariable(const std::string & name, float value, const std::string & context) {
        return createVariable(name, Symbols::Value(value), context, Symbols::Variables::Type::FLOAT);
    }
 
    static std::shared_ptr<Symbol> createVariable(const std::string & name, const std::string & value,
                                                  const std::string & context) {
        return createVariable(name, Symbols::Value(value), context, Symbols::Variables::Type::STRING);
    }
 
    static std::shared_ptr<Symbol> createVariable(const std::string & name, bool value, const std::string & context) {
        return createVariable(name, Symbols::Value(value), context, Symbols::Variables::Type::BOOLEAN);
    }
};
 
}  // namespace Symbols
 
#endif