-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypes.hpp
More file actions
executable file
·67 lines (54 loc) · 1.73 KB
/
Types.hpp
File metadata and controls
executable file
·67 lines (54 loc) · 1.73 KB
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
#ifndef _TYPES_HPP
#define _TYPES_HPP
#include <string>
#include <regex>
class Types {
private:
static const std::regex stringRegex;
static const std::regex intRegex;
static const std::regex languageElementRegex;
public:
enum TypeName {
OTHER, VARIABLE, OPERATOR, INT, DOUBLE, BOOLEAN, STRING, COMMALIST, OBJECT, LANGUAGEELEMENT, FUNCTION
};
static std::string getTypeName(TypeName t) {
if(t == INT) {
return "INT";
} else if( t == DOUBLE) {
return "DOUBLE";
} else if( t == BOOLEAN) {
return "BOOLEAN";
} else if( t == STRING) {
return "STRING";
} else if( t == COMMALIST) {
return "COMMALIST";
} else if( t == OBJECT) {
return "OBJECT";
} else if( t == OTHER) {
return "OTHER";
} else if(t == LANGUAGEELEMENT) {
return "LANGUAGEELEMENT";
} else {
return "TYPE UNKNOWN";
}
}
static TypeName determineType(std::string& token) {
if(&token==nullptr) return OTHER;
if(std::regex_match(token, stringRegex)) {
return STRING;
} else if(std::regex_match(token, intRegex)) {
return INT;
} else if(token.compare("true")==0 || token.compare("false")==0) {
return BOOLEAN;
} else if(isLanguageElement(token)) {
return LANGUAGEELEMENT;
} else {
return OTHER;
}
}
static bool isLanguageElement(std::string& s) {
if(s.compare("true")==0 || s.compare("false")==0 || s.compare("if") == 0 || s.compare("else")==0 || s.compare("then")==0 || s.compare("loop")==0 || s.compare("end")==0 || s.compare("output")==0 || s.compare("to")==0 || s.compare("from")==0) return false;
return std::regex_match(s, languageElementRegex);
}
};
#endif //_TYPES_HPP