-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.h
266 lines (259 loc) · 8.56 KB
/
lexer.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#pragma once
#include "util.h"
// keywords
#define TK_ADD_HANDLER 0
#define TK_ADDRESS_OF 1
#define TK_ALIAS 2
#define TK_AND 3
#define TK_AND_ALSO 4
#define TK_AS 5
#define TK_BOOLEAN 6
#define TK_BY_REF 7
#define TK_BYTE 8
#define TK_BY_VAL 9
#define TK_CALL 10
#define TK_CASE 11
#define TK_CATCH 12
#define TK_CBOOL 13
#define TK_CBYTE 14
#define TK_CCHAR 15
#define TK_CDATE 16
#define TK_CDBL 17
#define TK_CDEC 18
#define TK_CHAR 19
#define TK_CINT 20
#define TK_CLASS 21
#define TK_CLNG 22
#define TK_COBJ 23
#define TK_CONST 24
#define TK_CONTINUE 25
#define TK_CSBYTE 26
#define TK_CSHORT 27
#define TK_CSNG 28
#define TK_CSTR 29
#define TK_CTYPE 30
#define TK_CUINT 31
#define TK_CULONG 32
#define TK_CUSHORT 33
#define TK_DATE 34
#define TK_DECIMAL 35
#define TK_DECLARE 36
#define TK_DEFAULT 37
#define TK_DELEGATE 38
#define TK_DIM 39
#define TK_DIRECT_CAST 40
#define TK_DO 41
#define TK_DOUBLE 42
#define TK_EACH 43
#define TK_ELSE 44
#define TK_ELSE_IF 45
#define TK_END 46
#define TK_END_IF 47
#define TK_ENUM 48
#define TK_ERASE 49
#define TK_ERROR 50
#define TK_EVENT 51
#define TK_EXIT 52
#define TK_FALSE 53
#define TK_FINALLY 54
#define TK_FOR 55
#define TK_FOR_EACH_NEXT 56
#define TK_FRIEND 57
#define TK_FUNCTION 58
#define TK_GET 59
#define TK_GET_TYPE 60
#define TK_GET_XML_NAMESPACE 61
#define TK_GLOBAL 62
#define TK_GO_SUB 63
#define TK_GO_TO 64
#define TK_HANDLES 65
#define TK_IF 66
#define TK_IMPLEMENTS 67
#define TK_IMPORTS 68
#define TK_IN 69
#define TK_INHERITS 70
#define TK_INTEGER 71
#define TK_INTERFACE 72
#define TK_IS 73
#define TK_IS_NOT 74
#define TK_LET 75
#define TK_LIB 76
#define TK_LIKE 77
#define TK_LONG 78
#define TK_LOOP 79
#define TK_ME 80
#define TK_MOD 81
#define TK_MODULE 82
#define TK_MUST_INHERIT 83
#define TK_MUST_OVERRIDE 84
#define TK_MY_BASE 85
#define TK_MY_CLASS 86
#define TK_NAMESPACE 87
#define TK_NARROWING 88
#define TK_NEW 89
#define TK_NEXT 90
#define TK_NOT 91
#define TK_NOTHING 92
#define TK_NOT_INHERITABLE 93
#define TK_NOT_OVERRIDABLE 94
#define TK_OBJECT 95
#define TK_OF 96
#define TK_ON 97
#define TK_OPERATOR 98
#define TK_OPTION 99
#define TK_OPTIONAL 100
#define TK_OR 101
#define TK_OR_ELSE 102
#define TK_OUT 103
#define TK_OVERLOADS 104
#define TK_OVERRIDABLE 105
#define TK_OVERRIDES 106
#define TK_PARAM_ARRAY 107
#define TK_PARTIAL 108
#define TK_PRIVATE 109
#define TK_PROPERTY 110
#define TK_PROTECTED 111
#define TK_PUBLIC 112
#define TK_RAISE_EVENT 113
#define TK_READ_ONLY 114
#define TK_REDIM 115
#define TK_REM 116
#define TK_REMOVE_HANDLER 117
#define TK_RESUME 118
#define TK_RETURN 119
#define TK_SBYTE 120
#define TK_SELECT 121
#define TK_SET 122
#define TK_SHADOWS 123
#define TK_SHARED 124
#define TK_SHORT 125
#define TK_SINGLE 126
#define TK_STATIC 127
#define TK_STEP 128
#define TK_STOP 129
#define TK_STRING 130
#define TK_STURCTURE 131
#define TK_SUB 132
#define TK_SYNCLOCK 133
#define TK_THEN 134
#define TK_THROW 135
#define TK_TO 136
#define TK_TRUE 137
#define TK_TRY 138
#define TK_TRY_CAST 139
#define TK_TYPE_OF_IS 140
#define TK_UINTEGER 141
#define TK_ULONG 142
#define TK_USHORT 143
#define TK_USING 144
#define TK_VARIANT 145
#define TK_WEND 146
#define TK_WHEN 147
#define TK_WHILE 148
#define TK_WIDENING 149
#define TK_WITH 150
#define TK_WITH_EVENTS 151
#define TK_WRITE_ONLY 152
#define TK_XOR 153
#define TK_POUND_ELSE 154
#define TK_IDENTIFIER 155
// symbols
#define TK_LEFT_SQUARE 156
#define TK_RIGHT_SQUARE 167
#define TK_LEFT_PARENTHESIS 168
#define TK_RIGHT_PARENTHESIS 169
#define TK_LEFT_BRACKET 170
#define TK_RIGHT_BRACKET 180
#define TK_MULTIPLY_EQUAL 190
#define TK_ASTERISK 191
#define TK_DIVIDE_EQUAL 192
#define TK_SLASH 193
#define TK_ADD_EQUAL 194
#define TK_PLUS 195
#define TK_HAT_EQUAL 196
#define TK_HAT 197
#define TK_MINUS_EQUAL 198
#define TK_MINUS 199
#define TK_ASSIGNMENT 200
#define TK_EXCLAMATION 201
#define TK_AND_EQUAL 202
#define TK_CONCAT 203
#define TK_COLON 204
#define TK_SEMI_COLON 205
#define TK_SHIFT_LEFT 206
#define TK_NOT_EQUAL 207
#define TK_LESS_OR_EQUAL 208
#define TK_LEFT_ANGLE 209
#define TK_SHIFT_RIGHT 210
#define TK_GREATER_OR_EQUAL 211
#define TK_RIGHT_ANGLE 212
#define TK_COMMA 213
#define TK_DOT 214
#define TK_BACKSLASH 215
#define TK_NUMBER 216
#define TK_COMMENT 217
#define TK_NEWLINE 218
// form attributes
#define TK_APPEARANCE 219
#define TK_AUTOREDRAW 220
#define TK_BACKCOLOR 221
#define TK_BORDERSTYLE 222
#define TK_CAPTION 223
#define TK_CLIPCONTROLS 224
#define TK_CONTROLBOX 225
#define TK_DRAWMODE 226
#define TK_DRAWSTYLE 227
#define TK_DRAWWIDTH 228
#define TK_ENABLED 229
#define TK_FILLCOLOR 230
#define TK_FILLSTYLE 231
#define TK_FONT 232
#define TK_FONTTRANSPARENT 233
#define TK_FORECOLOR 234
#define TK_HASDC 235
#define TK_HEIGHT 236
#define TK_HELPCONTEXTID 237
#define TK_ICON 238
#define TK_KEYPREVIEW 239
#define TK_LEFT 240
#define TK_LINKMODE 241
#define TK_LINKTOPIC 242
#define TK_MAXBUTTON 243
#define TK_MDICHILD 244
#define TK_MINBUTTON 245
#define TK_MOUSEICON 246
#define TK_MOUSEPOINTER 247
#define TK_MOVEABLE 248
#define TK_NEGOTIATEMENU 249
#define TK_OLEDROPMODE 250
#define TK_PALETTE 251
#define TK_PALETTEMODE 252
#define TK_PICTURE 253
#define TK_RIGHTTOLEFT 254
#define TK_SCALEHEIGHT 255
#define TK_SCALELEFT 256
#define TK_SCALEMODE 257
#define TK_SCALETOP 258
#define TK_SCALEWIDTH 259
#define TK_SHOWINTASKBAR 260
#define TK_STARTUPPOSITION 261
#define TK_TAG 262
#define TK_TOP 263
#define TK_VISIBLE 264
#define TK_WHATSTHISBUTTON 265
#define TK_WIDTH 266
#define TK_WINDOWSTATE 267
typedef struct Token {
int type;
int num;
char *string;
int strlen;
bool hasValue;
} Token;
Token *readKeyword(const char *p, int *pos);
Token *readString(const char *p, int *pos);
Token *readSymbol(const char *p, int *pos);
Token *readNumber(const char *p, int *pos);
int getTokenType(const Vector *vec, int index);
bool isSymbol(char p);
Vector *lex(char *addr);