-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathToken.hpp
More file actions
157 lines (122 loc) · 4.82 KB
/
Token.hpp
File metadata and controls
157 lines (122 loc) · 4.82 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#ifndef EXPRINTER_TOKEN_HPP
#define EXPRINTER_TOKEN_HPP
#include <string>
class Token {
public:
Token();
Token(std::string tok);
bool &eof() { return _eof; }
bool &eol() { return _eol; }
bool eof() const { return _eof; }
bool eol() const { return _eol; }
bool isOpenParen() const { return _symbol == '('; }
bool isCloseParen() const { return _symbol == ')'; }
bool isOpenBracket() const { return _symbol == '{'; }
bool isCloseBracket() const { return _symbol == '}'; }
bool isOpenSquareBracket() const { return _symbol == '['; }
bool isCloseSquareBracket() const { return _symbol == ']'; }
void symbol(char c) { _symbol = c; }
char symbol() { return _symbol; }
void relExp(std::string exp) { _relExp = exp; }
std::string getRelOp() const { return _relExp; }
bool isRelGT() const { return _relExp == ">"; } //done
bool isRelLT() const { return _relExp == "<"; } //done
bool isRelGTE() const { return _relExp == ">="; } //done
bool isRelLTE() const { return _relExp == "<="; } //done
bool isRelEQ() const { return _relExp == "=="; } //done
bool isRelNotEQ() const { return _relExp == "!="; } //done
bool isRelEQML() const { return _relExp == "<>"; } //done
bool isRelAssign() const { return _relExp == "="; }
bool isRelOp() const {
return
_relExp != "" && (
isRelGT() ||
isRelLT() ||
isRelGTE() ||
isRelLTE() ||
isRelEQ() ||
isRelNotEQ() ||
isRelEQML() ||
isRelAssign() //needs to be taken out
);
}
bool isCompOp() const { return isRelOp() && !isRelAssign(); }
bool isColon() const { return _symbol == ':'; }
bool isSemiColon() const { return _symbol == ';'; }
bool isAssignmentOperator() const { return _relExp == "="; }
bool isMultiplicationOperator() const { return _symbol == '*'; }
bool isAdditionOperator() const { return _symbol == '+'; }
bool isSubtractionOperator() const { return _symbol == '-'; }
bool isModuloOperator() const { return _symbol == '%'; }
bool isDivisionOperator() const { return _symbol == '/'; }
bool isComma() const { return _symbol == ','; }
bool isArithmeticOperator() const {
return isMultiplicationOperator() ||
isAdditionOperator() ||
isSubtractionOperator() ||
isModuloOperator() ||
isDivisionOperator();
}
bool isName() const { return _name.length() > 0; }
std::string getName() const { return _name; }
void setName(std::string n) { _name = n; }
bool isKeyword() const {
return _keyword.length() > 0;
}
std::string getKeyword() const { return _keyword; }
bool isString() const { return _str.length() > 0; }
std::string getString() const {
return _str;
}
void setString(std::string str) {
_str = str;
}
void setKeyword(std::string keyword) {
_keyword = keyword;
}
bool isPrint() const { return _keyword == "print"; }
bool isFor() const { return _keyword == "for"; }
bool isIf() const { return _keyword == "if"; }
bool isElIf() const { return _keyword == "elif"; }
bool isElse() const { return _keyword == "else"; }
bool isIndent() const { return _keyword == "INDENT";}
bool isDedent() const { return _keyword == "DEDENT";}
bool isAnd() const { return _keyword == "and"; }
bool isOr() const { return _keyword == "or"; }
bool isNot() const { return _keyword == "not"; }
bool isIn() const { return _keyword == "in"; }
bool isRange() const { return _keyword == "range"; }
bool isFunc() const { return _keyword == "def"; }
bool isLen() const { return _keyword == "len"; }
bool isPeriod() const { return _keyword == "."; }
bool isReturn() const { return _keyword == "return";}
bool isAppend() const { return _keyword == "append";}
bool isPop() const { return _keyword == "pop"; }
bool isFloat() const { return _isFloat; }
float getFloat() const { return _float; }
void setFloat(float f) {
_float = f;
_isFloat = true;
}
bool &isWholeNumber() { return _isWholeNumber; }
bool isWholeNumber() const { return _isWholeNumber; }
int getWholeNumber() const { return _wholeNumber; }
void setWholeNumber(int n) {
_wholeNumber = n;
isWholeNumber() = true;
}
void print() const;
void dumpData() const;
private:
std::string _name;
std::string _relExp;
std::string _keyword;
std::string _str;
bool _eof, _eol;
bool _isFloat;
bool _isWholeNumber;
char _symbol;
float _float;
int _wholeNumber;
};
#endif //EXPRINTER_TOKEN_HPP