-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathTokenizer.h
82 lines (68 loc) · 1.82 KB
/
Tokenizer.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
#pragma once
#include <unordered_map>
namespace expr
{
enum TokenType
{
TokenType_FloatLiteral = 256,
TokenType_IntegerLiteral,
TokenType_BooleanLiteral,
TokenType_Identifier,
TokenType_Float,
TokenType_Float2,
TokenType_Float3,
TokenType_Float4,
TokenType_Float2x2,
TokenType_Float3x3,
TokenType_Float4x4,
TokenType_Int,
TokenType_Int2,
TokenType_Int3,
TokenType_Int4,
TokenType_Uint,
TokenType_Uint2,
TokenType_Uint3,
TokenType_Uint4,
TokenType_Bool,
TokenType_Bool2,
TokenType_Bool3,
TokenType_Bool4,
TokenType_Equal,
TokenType_NotEqual,
TokenType_LessThanEqual,
TokenType_GreaterThanEqual,
TokenType_LogicAnd,
TokenType_LogicOr,
TokenType_BitshiftLeft,
TokenType_BitshiftRight,
TokenType_Increment,
TokenType_Decrement,
TokenTypeCount
};
class Tokenizer
{
public:
Tokenizer(const char* buffer, unsigned int bufLength);
bool Next();
void Undo();
inline int GetTokenType() { return m_curType; }
inline float GetFloatValue() { return m_floatValue; }
inline int GetIntValue() { return m_intValue; }
inline const char* GetIdentifier() { return m_curIdentifier; }
private:
bool m_isSymbol(char c);
bool m_isValidNumberEnd(char c);
bool m_readNumber();
private:
std::unordered_map<const char*, TokenType> m_keywords;
char m_curIdentifier[256];
int m_curType;
char m_prevIdentifier[256];
int m_prevType;
const char* m_tokenStart;
float m_floatValue;
int m_intValue;
const char* m_buffer;
const char* m_bufferEnd;
};
}