-
Notifications
You must be signed in to change notification settings - Fork 0
/
SymbolTypes.hpp
39 lines (31 loc) · 1.2 KB
/
SymbolTypes.hpp
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
#ifndef SYMBOLTYPES_HPP
#define SYMBOLTYPES_HPP
class String : public std::string {
public:
String()
: std::string() {}
String(const char *start, const char *end)
: std::string(start, end) {}
String(const std::string& str)
: std::string(str) {}
};
enum class ExpI { None, BoolT, IntT, RealT, StringT, ArrayT, Array2T, RecordT, SubroutineT };
const std::unordered_map<std::string,ExpI> ExpI_types{
{ "Boolean", ExpI::BoolT },
{ "Integer", ExpI::IntT },
{ "Real", ExpI::RealT },
{ "Char", ExpI::StringT },
{ "String", ExpI::StringT }
};
using BoolT = bool;
using IntT = int;
using RealT = double;
using StringT = String;
using RecordT = std::pair<std::vector<std::pair<std::string,ExpI>>,bool>; // second field is true for definition, false for object
using SubroutineT = std::pair<std::vector<std::pair<std::string,ExpI>>,ExpI>;
using ArrayT = std::vector<ExpI>;
using Array2T = std::vector<std::variant<ExpI,ArrayT>>;
using ExpT = std::variant<std::monostate,BoolT,IntT,RealT,StringT,ArrayT,Array2T,RecordT,SubroutineT>;
using SymbolT = std::variant<std::monostate,ExpT,ExpI>;
std::ostream& operator<<(std::ostream& os, const ExpT& expr);
#endif // SYMBOLTYPES_HPP