-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtokens.h
39 lines (28 loc) · 758 Bytes
/
tokens.h
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 TOKENS_H
#define TOKENS_H
#include <string>
#include <vector>
namespace Math_Interpreter {
enum class TokenType {
NUMBER,
PLUS,
MINUS,
MULTIPLY,
DIVIDE,
LPAREN,
RPAREN,
EOF_
};
class Token {
public:
TokenType type;
double value;
Token(TokenType type) : type(type) {}
Token(TokenType type, double value) : type(type), value(value) {}
explicit operator bool() const; // returns true if type != TokenType::EOF_ else returns false
std::string str() const;
operator std::string() const; // this will call str(), this is just to make kind of like a "__repr__" function in Python
};
void print_tokens(const std::vector<Token>& tokens);
} // namespace Math_Interpreter
#endif // TOKENS_H