-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.l
239 lines (166 loc) · 3.97 KB
/
lexer.l
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
%option yylineno
%x MULTI_LINE_COMMENT
%{
#include "parser.tab.h"
%}
SIGN [-+]
DEC_DIGITS [0-9]+
HEX_PREFIX "0x"
HEX_DIGITS [0-9a-f]+
OCT_PREFIX "0o"
OCT_DIGITS [0-7]+
BIN_PREFIX "0b"
BIN_DIGITS [01]+
EXPONENT "e"
DECIMAL_POINT "."
SIGNED_INTEGER_SUFFIX "i"(8|16|32|64)
UNSIGNED_INTEGER_SUFFIX "u"(8|16|32|64)
REAL_SUFFIX "r"(32|64)
%%
"i8" {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return PRIM_TYPE_I8;
}
"i16" {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return PRIM_TYPE_I16;
}
"i32" {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return PRIM_TYPE_I32;
}
"i64" {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return PRIM_TYPE_I64;
}
"u8" {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return PRIM_TYPE_U8;
}
"u16" {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return PRIM_TYPE_U16;
}
"u32" {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return PRIM_TYPE_U32;
}
"u64" {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return PRIM_TYPE_U64;
}
"r32" {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return PRIM_TYPE_R32;
}
"r64" {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return PRIM_TYPE_R64;
}
"," {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return COMMA;
}
"=" {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return EQUALS;
}
";" {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return SEMICOLON;
}
"(" {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return LEFT_PAREN;
}
")" {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return RIGHT_PAREN;
}
"{" {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return LEFT_BRACE;
}
"}" {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return RIGHT_BRACE;
}
"\r" {
UPDATE_CURSOR_LOCATION_CARRIAGE_RETURN();
}
"\n" {
UPDATE_CURSOR_LOCATION_NEW_LINE();
}
[\t ] {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
}
"//"[^\r\n]* {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
}
"/*" {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
BEGIN(MULTI_LINE_COMMENT);
}
<MULTI_LINE_COMMENT>"\r" {
UPDATE_CURSOR_LOCATION_CARRIAGE_RETURN();
}
<MULTI_LINE_COMMENT>"\n" {
UPDATE_CURSOR_LOCATION_NEW_LINE();
}
<MULTI_LINE_COMMENT>. {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
}
<MULTI_LINE_COMMENT>"*/" {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
BEGIN(INITIAL);
}
[a-zA-Z_][a-zA-Z0-9_]* {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
yylval.string = string_from(yytext);
return IDENT;
}
"\""[^"]*"\"" {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
yylval.string = string_from(yytext);
return STR_LIT;
}
{SIGN}?{DEC_DIGITS}{SIGNED_INTEGER_SUFFIX}? {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return lit_parse_signed_integer(0, 10);
}
{DEC_DIGITS}{UNSIGNED_INTEGER_SUFFIX}? {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return lit_parse_unsigned_integer(0, 10);
}
{SIGN}?{HEX_PREFIX}{HEX_DIGITS}{SIGNED_INTEGER_SUFFIX}? {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return lit_parse_signed_integer(2, 16);
}
{HEX_PREFIX}{HEX_DIGITS}{UNSIGNED_INTEGER_SUFFIX}? {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return lit_parse_unsigned_integer(2, 16);
}
{SIGN}?{OCT_PREFIX}{OCT_DIGITS}{SIGNED_INTEGER_SUFFIX}? {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return lit_parse_signed_integer(2, 8);
}
{OCT_PREFIX}{OCT_DIGITS}{UNSIGNED_INTEGER_SUFFIX}? {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return lit_parse_unsigned_integer(2, 8);
}
{SIGN}?{BIN_PREFIX}{BIN_DIGITS}{SIGNED_INTEGER_SUFFIX}? {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return lit_parse_signed_integer(2, 2);
}
{BIN_PREFIX}{BIN_DIGITS}{UNSIGNED_INTEGER_SUFFIX}? {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return lit_parse_unsigned_integer(2, 2);
}
{SIGN}?{DEC_DIGITS}({DECIMAL_POINT}{DEC_DIGITS})?({EXPONENT}{SIGN}?{DEC_DIGITS})?{REAL_SUFFIX} {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
return lit_parse_real();
}
. {
UPDATE_CURSOR_LOCATION_SINGLE_LINE();
}
%%