A simple scripting language in C++
Ferenc Szontágh
2025-04-17 36ec04c00fa540fcee0f2cff1f7b81dd8a98101a
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
#ifndef VARIABLE_TYPES_HPP
#define VARIABLE_TYPES_HPP
 
#include <cstdint>
#include <string>
#include <unordered_map>
 
namespace Symbols::Variables {
 
enum class Type : std::uint8_t { INTEGER, DOUBLE, FLOAT, STRING, BOOLEAN, NULL_TYPE, UNDEFINED_TYPE };
 
const std::unordered_map<std::string, Type> StringToTypeMap = {
    { "int",       Type::INTEGER        },
    { "double",    Type::DOUBLE         },
    { "float",     Type::FLOAT          },
    { "string",    Type::STRING         },
    { "bool",      Type::BOOLEAN        },
    { "boolean",   Type::BOOLEAN        },
    { "null",      Type::NULL_TYPE      },
 
    { "undefined", Type::UNDEFINED_TYPE },
};
const std::unordered_map<Type, std::string> StypeToStringMap = {
    { Type::INTEGER,        "int"        },
    { Type::DOUBLE,         "double"     },
    { Type::FLOAT,          "float"      },
    { Type::STRING,         "string"     },
    { Type::BOOLEAN,        "bool"       },
    { Type::NULL_TYPE,      "null"       },
    { Type::UNDEFINED_TYPE, "undeffined" },
};
 
inline static std::string TypeToString(Symbols::Variables::Type type) {
    if (StypeToStringMap.find(type) != StypeToStringMap.end()) {
        return StypeToStringMap.at(type);
    }
    return "null";
};
 
inline static Type StringToType(const std::string & type) {
    if (StringToTypeMap.find(type) != StringToTypeMap.end()) {
        return StringToTypeMap.at(type);
    }
    return Type::NULL_TYPE;
};
 
};  // namespace Symbols::Variables
#endif  // VARIABLE_TYPES_HPP