-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoken.hpp
85 lines (72 loc) · 1.54 KB
/
token.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
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
#ifndef __TOKEN_H__
#define __TOKEN_H__
#include <inttypes.h>
#include <string>
namespace math {
extern uint8_t OpPrecedence[];
enum SymType : uint8_t {
null,
numeric,
op,
str,
brakets
};
enum TokenType : uint8_t {
opPlus,
opMinus,
opMulti,
opDiv,
opPower,
opSqrt,
funcSin,
funcCos,
funcTan,
numLiteral,
numVar,
openBrakets,
closeBrakets,
symEqual,
symSemicolon
};
struct Token {
Token(const long double& val) : type(TokenType::numLiteral), value(val) {}
Token(const std::string& name) : type(numVar), var(name.c_str()) {}
Token(const char* name) : type(numVar), var(name) {}
Token(const TokenType& t) : type(t), value(0) {}
TokenType type;
union {
long double value;
const char* var;
};
};
static bool tokenIsFunc(const Token& token) {
if (token.type == funcSin ||
token.type == funcCos ||
token.type == funcTan)
return true;
return false;
}
static bool tokenIsOp(const Token& token) {
if (token.type == opPlus ||
token.type == opMinus ||
token.type == opMulti ||
token.type == opDiv ||
token.type == opPower ||
token.type == opSqrt)
return true;
return false;
}
static bool tokenIsSign(const Token& token) {
if (token.type == opPlus ||
token.type == opMinus)
return true;
return false;
}
static bool tokenIsBrakets(const Token& token) {
if (token.type == openBrakets ||
token.type == closeBrakets)
return true;
return false;
}
}
#endif // __TOKEN_H__