-
Notifications
You must be signed in to change notification settings - Fork 1
/
Token.h
194 lines (147 loc) · 4.11 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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#pragma once
#include "Kr/KrCommon.h"
enum Token_Kind
{
TOKEN_KIND_ERROR = 0,
TOKEN_KIND_SEMICOLON,
TOKEN_KIND_COLON,
TOKEN_KIND_COMMA,
TOKEN_KIND_DASH_ARROW,
TOKEN_KIND_DEREFERENCE,
TOKEN_KIND_PERIOD,
TOKEN_KIND_EQUALS,
TOKEN_KIND_OPEN_BRACKET,
TOKEN_KIND_CLOSE_BRACKET,
TOKEN_KIND_OPEN_CURLY_BRACKET,
TOKEN_KIND_CLOSE_CURLY_BRACKET,
TOKEN_KIND_OPEN_SQUARE_BRACKET,
TOKEN_KIND_CLOSE_SQUARE_BRACKET,
TOKEN_KIND_PLUS,
TOKEN_KIND_MINUS,
TOKEN_KIND_ASTERISK,
TOKEN_KIND_DIVISION,
TOKEN_KIND_REMAINDER,
TOKEN_KIND_COMPOUND_PLUS,
TOKEN_KIND_COMPOUND_MINUS,
TOKEN_KIND_COMPOUND_MULTIPLY,
TOKEN_KIND_COMPOUND_DIVIDE,
TOKEN_KIND_COMPOUND_REMAINDER,
TOKEN_KIND_BITWISE_SHIFT_RIGHT,
TOKEN_KIND_BITWISE_SHIFT_LEFT,
TOKEN_KIND_COMPOUND_BITWISE_SHIFT_RIGHT,
TOKEN_KIND_COMPOUND_BITWISE_SHIFT_LEFT,
TOKEN_KIND_BITWISE_AND,
TOKEN_KIND_BITWISE_XOR,
TOKEN_KIND_BITWISE_OR,
TOKEN_KIND_COMPOUND_BITWISE_AND,
TOKEN_KIND_COMPOUND_BITWISE_XOR,
TOKEN_KIND_COMPOUND_BITWISE_OR,
TOKEN_KIND_BITWISE_NOT,
TOKEN_KIND_LOGICAL_NOT,
TOKEN_KIND_LOGICAL_AND,
TOKEN_KIND_LOGICAL_OR,
TOKEN_KIND_RELATIONAL_GREATER,
TOKEN_KIND_RELATIONAL_LESS,
TOKEN_KIND_RELATIONAL_GREATER_EQUAL,
TOKEN_KIND_RELATIONAL_LESS_EQUAL,
TOKEN_KIND_COMPARE_EQUAL,
TOKEN_KIND_COMPARE_NOT_EQUAL,
TOKEN_KIND_REAL,
TOKEN_KIND_INTEGER,
TOKEN_KIND_STRING,
TOKEN_KIND_VAR,
TOKEN_KIND_CONST,
TOKEN_KIND_TRUE,
TOKEN_KIND_FALSE,
TOKEN_KIND_BYTE,
TOKEN_KIND_INT,
TOKEN_KIND_FLOAT,
TOKEN_KIND_BOOL,
TOKEN_KIND_DOUBLE_PERDIOD,
TOKEN_KIND_IF,
TOKEN_KIND_THEN,
TOKEN_KIND_ELSE,
TOKEN_KIND_FOR,
TOKEN_KIND_WHILE,
TOKEN_KIND_DO,
TOKEN_KIND_SIZE_OF,
TOKEN_KIND_TYPE_OF,
TOKEN_KIND_PROC,
TOKEN_KIND_STRUCT,
TOKEN_KIND_RETURN,
TOKEN_KIND_BREAK,
TOKEN_KIND_CONTINUE,
TOKEN_KIND_CAST,
TOKEN_KIND_VOID,
TOKEN_KIND_NULL,
TOKEN_KIND_IDENTIFIER,
TOKEN_KIND_END,
_TOKEN_KIND_COUNT
};
struct Token
{
Token_Kind kind;
String content;
size_t row;
size_t column;
size_t offset;
};
union Token_Value {
double real;
uint64_t integer;
struct
{
int64_t length;
uint8_t *data;
} string;
};
//
//
//
static inline String token_kind_string(Token_Kind kind)
{
static String strings[] = {"-unknown-",
";", ":",
",", "->",
"?", ".",
"=",
"(", ")",
"{", "}",
"[", "]",
"+", "-",
"*", "/",
"%",
"+=", "-=",
"*=", "/=",
"%=",
">>", "<<",
">>=", "<<=",
"&", "^",
"|",
"&=", "^=",
"|=",
"~",
"!", "&&", "||",
">", "<",
">=", "<=",
"==", "!=",
"real number", "integer number",
"string",
"var", "const",
"true", "false",
"byte", "int", "float",
"bool", "..",
"if", "then",
"else",
"for", "while",
"do",
"size_of", "type_of",
"proc", "struct",
"return", "break", "continue",
"cast",
"void", "null",
"identifier",
"-end-"};
static_assert(ArrayCount(strings) == _TOKEN_KIND_COUNT);
return strings[kind];
}