-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathToken.h
112 lines (88 loc) · 1.98 KB
/
Token.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
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
#ifndef _EXCELFORMULAPARSER_H__
#define _EXCELFORMULAPARSER_H__
#include <string>
using std::string;
namespace ExcelFormula
{
class Token{
public:
enum TokenType
{
Operand,
Function,
Subexpression,
Argument,
OperatorPrefix,
OperatorInfix,
OperatorPostfix,
Whitespace,
Unknown
};
enum TokenSubtype
{
Nothing,
Start,
Stop,
Text,
Number,
Logical,
Error,
Range,
Math,
Concatenation,
Intersection,
Union
};
public:
/**
* Default constructor, generate a empty token
*/
Token();
/**
* @param const char* string value of the token
* @param TokenType type of the token
*/
Token(const char*, TokenType);
/**
* @param const char* string value of the token
* @param TokenType type of the token
* @param TokenSubType subtype of the token
*/
Token(const char*, TokenType, TokenSubtype);
bool operator==(Token& token);
//! retrieve the token value
const char* getValue() {return m_value.c_str();}
const string& getStrValue() {return m_value;}
//! set the token value
void setValue(const char* value) {
m_value = value;
}
TokenType getType() {return m_type;}
void setType(TokenType type) {
m_type = type;
}
TokenSubtype getSubtype() {return m_subtype;}
void setSubtype(TokenSubtype subtype){
m_subtype = subtype;
}
//! get printable token string
const string getPrintableString();
//! duplicate a another token
Token* clone();
private:
string m_value;
//string m_printableStr; //string used to print
TokenType m_type;
TokenSubtype m_subtype;
}; //class Token
//! manage token alloc and free
class TokenAllocer
{
public:
static Token* getToken();
static Token* getToken(const char* szValue, Token::TokenType type);
static Token* getToken(const char* szValue, Token::TokenType type, Token::TokenSubtype subtype);
static void freeToken(Token*);
};
};
#endif