-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflex.l
292 lines (254 loc) · 10.6 KB
/
flex.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
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
%top{
// Java SE 17 language Flex description
// Reference: https://docs.oracle.com/javase/specs/jls/se17/html/jls-3.html
}
%option nodefault
%option noyywrap
%{
#include "bison.tab.h"
%}
Input {InputElement}*
InputElement {WhiteSpace}|{Comment}|{Token}
Token {Identifier}|{Keyword}|{Literal}|{Separator}|{Operator}
LineTerminator \r\n|[\n\r]
AnyCharacter [^\r\n]
WhiteSpace [ \t\f]|{LineTerminator}
Comment "//"{AnyCharacter}*|"/*"({AnyCharacter}|{LineTerminator})*"*/"
Identifier {IdentifierStart}{IdentifierPart}*
IdentifierStart [A-Za-z]|_|"\$"
IdentifierPart {IdentifierStart}|[0-9]
Keyword {ReservedKeyword}
ReservedKeyword {AbstractKeyword}|{ContinueKeyword}|{ForKeyword}|{NewKeyword}|{SwitchKeyword}|{AssertKeyword}|{DefaultKeyword}|{IfKeyword}|{PackageKeyword}|{SynchronizedKeyword}|{BooleanKeyword}|{DoKeyword}|{GotoKeyword}|{PrivateKeyword}|{ThisKeyword}|{BreakKeyword}|{DoubleKeyword}|{ImplementsKeyword}|{ProtectedKeyword}|{ThrowKeyword}|{ByteKeyword}|{ElseKeyword}|{ImportKeyword}|{PublicKeyword}|{ThrowsKeyword}|{CaseKeyword}|{EnumKeyword}|{InstanceofKeyword}|{ReturnKeyword}|{TransientKeyword}|{CatchKeyword}|{ExtendsKeyword}|{IntKeyword}|{ShortKeyword}|{TryKeyword}|{CharKeyword}|{FinalKeyword}|{InterfaceKeyword}|{StaticKeyword}|{VoidKeyword}|{ClassKeyword}|{FinallyKeyword}|{LongKeyword}|{StrictfpKeyword}|{VolatileKeyword}|{ConstKeyword}|{FloatKeyword}|{NativeKeyword}|{SuperKeyword}|{WhileKeyword}|{UnderlineKeyword}|{VarKeyword}|{YieldKeyword}|{PermitsKeyword}|{SealedKeyword}|{NonSealedKeyword}|{RecordKeyword}
AbstractKeyword abstract
ContinueKeyword continue
ForKeyword for
NewKeyword new
SwitchKeyword switch
AssertKeyword assert
DefaultKeyword default
IfKeyword if
PackageKeyword package
SynchronizedKeyword synchronized
BooleanKeyword boolean
DoKeyword do
GotoKeyword goto
PrivateKeyword private
ThisKeyword this
BreakKeyword break
DoubleKeyword double
ImplementsKeyword implements
ProtectedKeyword protected
ThrowKeyword throw
ByteKeyword byte
ElseKeyword else
ImportKeyword import
PublicKeyword public
ThrowsKeyword throws
CaseKeyword case
EnumKeyword enum
InstanceofKeyword instanceof
ReturnKeyword return
TransientKeyword transient
CatchKeyword catch
ExtendsKeyword extends
IntKeyword int
ShortKeyword short
TryKeyword try
CharKeyword char
FinalKeyword final
InterfaceKeyword interface
StaticKeyword static
VoidKeyword void
ClassKeyword class
FinallyKeyword finally
LongKeyword long
StrictfpKeyword strictfp
VolatileKeyword volatile
ConstKeyword const
FloatKeyword float
NativeKeyword native
SuperKeyword super
WhileKeyword while
UnderlineKeyword _
VarKeyword var
YieldKeyword yield
PermitsKeyword permits
SealedKeyword sealed
NonSealedKeyword non-sealed
RecordKeyword record
Literal {IntegerLiteral}|{FloatingPointLiteral}|{BooleanLiteral}|{CharacterLiteral}|{StringLiteral}|{NullLiteral}
IntegerLiteral {DecimalIntegerLiteral}|{HexIntegerLiteral}|{OctalIntegerLiteral}|{BinaryIntegerLiteral}
DecimalIntegerLiteral {DecimalNumeral}{IntegerTypeSuffix}?
HexIntegerLiteral {HexNumeral}{IntegerTypeSuffix}?
OctalIntegerLiteral {OctalNumeral}{IntegerTypeSuffix}?
BinaryIntegerLiteral {BinaryNumeral}{IntegerTypeSuffix}?
IntegerTypeSuffix l|L
DecimalNumeral 0|[1-9](({DecimalDigit}|_)*{DecimalDigit})?
DecimalDigit [0-9]
HexNumeral 0[xX]{HexDigits}
HexDigit [0-9a-fA-F]
HexDigits {HexDigit}|{HexDigit}({HexDigit}|_)*{HexDigit}
OctalNumeral 0({OctalDigit}|_)*{OctalDigit}
OctalDigit [0-7]
BinaryNumeral 0[bB]({BinaryDigit}|{BinaryDigit}({BinaryDigit}|_)*{BinaryDigit})
BinaryDigit [01]
FloatingPointLiteral {DecimalFloatingPointLiteral}|{HexadecimalFloatingPointLiteral}
DecimalFloatingPointLiteral {FloatingPointDigits}\.{FloatingPointDigits}?{ExponentPart}?{FloatTypeSuffix}?|\.{FloatingPointDigits}{ExponentPart}?{FloatTypeSuffix}?|{FloatingPointDigits}{ExponentPart}{FloatTypeSuffix}?|{FloatingPointDigits}{ExponentPart}?{FloatTypeSuffix}
FloatingPointDigits {DecimalDigit}|{DecimalDigit}({DecimalDigit}|_)*{DecimalDigit}
ExponentPart [eE][+-]?{FloatingPointDigits}
FloatTypeSuffix [fFdD]
HexadecimalFloatingPointLiteral {HexSignificand}{BinaryExponent}{FloatTypeSuffix}?
HexSignificand {HexNumeral}\.?|0[xX]{HexDigits}?\.{HexDigits}
BinaryExponent [pP][+-]?{FloatingPointDigits}
BooleanLiteral true|false
/* [^\r\n] stands for {AnyCharacter} */
CharacterLiteral \'([^\r\n'\\]|{EscapeSequence})\'
EscapeSequence \\b|\\s|\\t|\\n|\\f|\\r|\\\"|\\\'|\\\\|{OctalEscape}|{UnicodeEscape}
OctalEscape \\{OctalDigit}{1,2}|\\{ZeroToThree}{OctalDigit}{2}
UnicodeEscape \\u+{HexDigit}{4}
ZeroToThree [0-3]
/* [^\r\n] stands for {AnyCharacter} */
StringLiteral \"([^\r\n"\\]|{EscapeSequence})*\"|{TextBlock}
TextBlock \"\"\"[ \t\f]*{LineTerminator}({AnyCharacter}|{EscapeSequence}|{LineTerminator})*\"\"\"
NullLiteral null
Separator [(){}[\];,.@]|{TripleDotSeparator}|{DoubleColonSeparator}
Operator [=><!~?:+\-*^%|&/]|{ArrowOperator}|{EqualOperator}|{GreaterThanOrEqualOperator}|{LessThanOrEqualOperator}|{NotEqualOperator}|{BooleanAndOperator}|\|{BooleanOrOperator}|{IncrementOperator}|{DecrementOperator}|{ShiftLeftOperator}|{ShiftRightOperator}|{ShiftRightArithmeticOperator}|{AddAssignmentOperator}|{MinusAssignmentOperator}|{MultiplyAssignmentOperator}|{DivideAssignmentOperator}|{AndAssignmentOperator}|{OrAssignmentOperator}|{XorAssignmentOperator}|{ModAssignmentOperator}|{ShiftLeftAssignmnetOperator}|{ShiftRightAssignmentOperator}|{ShiftRightArithmeticAssignmentOperator}
TripleDotSeparator "..."
DoubleColonSeparator ::
ArrowOperator ->
EqualOperator ==
GreaterThanOrEqualOperator >=
LessThanOrEqualOperator <=
NotEqualOperator !=
BooleanAndOperator &&
BooleanOrOperator \|\|
IncrementOperator \+\+
DecrementOperator --
ShiftLeftOperator <<
ShiftRightOperator >>
ShiftRightArithmeticOperator >>>
AddAssignmentOperator \+=
MinusAssignmentOperator -=
MultiplyAssignmentOperator \*=
DivideAssignmentOperator \/=
AndAssignmentOperator &=
OrAssignmentOperator \|=
XorAssignmentOperator \^=
ModAssignmentOperator %=
ShiftLeftAssignmnetOperator <<=
ShiftRightAssignmentOperator >>=
ShiftRightArithmeticAssignmentOperator >>>=
%%
{WhiteSpace}|{Comment} { /* No op. */ }
/* {ReservedKeyword} printlnCurrentToken(); */
{AbstractKeyword} { return AbstractKeyword; }
{ContinueKeyword} { return ContinueKeyword; }
{ForKeyword} { return ForKeyword; }
{NewKeyword} { return NewKeyword; }
{SwitchKeyword} { return SwitchKeyword; }
{AssertKeyword} { return AssertKeyword; }
{DefaultKeyword} { return DefaultKeyword; }
{IfKeyword} { return IfKeyword; }
{PackageKeyword} { return PackageKeyword; }
{SynchronizedKeyword} { return SynchronizedKeyword; }
{BooleanKeyword} { return BooleanKeyword; }
{DoKeyword} { return DoKeyword; }
{GotoKeyword} { return GotoKeyword; }
{PrivateKeyword} { return PrivateKeyword; }
{ThisKeyword} { return ThisKeyword; }
{BreakKeyword} { return BreakKeyword; }
{DoubleKeyword} { return DoubleKeyword; }
{ImplementsKeyword} { return ImplementsKeyword; }
{ProtectedKeyword} { return ProtectedKeyword; }
{ThrowKeyword} { return ThrowKeyword; }
{ByteKeyword} { return ByteKeyword; }
{ElseKeyword} { return ElseKeyword; }
{ImportKeyword} { return ImportKeyword; }
{PublicKeyword} { return PublicKeyword; }
{ThrowsKeyword} { return ThrowsKeyword; }
{CaseKeyword} { return CaseKeyword; }
{EnumKeyword} { return EnumKeyword; }
{InstanceofKeyword} { return InstanceofKeyword; }
{ReturnKeyword} { return ReturnKeyword; }
{TransientKeyword} { return TransientKeyword; }
{CatchKeyword} { return CatchKeyword; }
{ExtendsKeyword} { return ExtendsKeyword; }
{IntKeyword} { return IntKeyword; }
{ShortKeyword} { return ShortKeyword; }
{TryKeyword} { return TryKeyword; }
{CharKeyword} { return CharKeyword; }
{FinalKeyword} { return FinalKeyword; }
{InterfaceKeyword} { return InterfaceKeyword; }
{StaticKeyword} { return StaticKeyword; }
{VoidKeyword} { return VoidKeyword; }
{ClassKeyword} { return ClassKeyword; }
{FinallyKeyword} { return FinallyKeyword; }
{LongKeyword} { return LongKeyword; }
{StrictfpKeyword} { return StrictfpKeyword; }
{VolatileKeyword} { return VolatileKeyword; }
{ConstKeyword} { return ConstKeyword; }
{FloatKeyword} { return FloatKeyword; }
{NativeKeyword} { return NativeKeyword; }
{SuperKeyword} { return SuperKeyword; }
{WhileKeyword} { return WhileKeyword; }
{UnderlineKeyword} { return '_'; }
{VarKeyword} { return VarKeyword; }
{YieldKeyword} { return YieldKeyword; }
{PermitsKeyword} { return PermitsKeyword; }
{SealedKeyword} { return SealedKeyword; }
{NonSealedKeyword} { return NonSealedKeyword; }
{RecordKeyword} { return RecordKeyword; }
/* {Literal} printlnCurrentTokenWithName("literal"); */
{Literal} { return Literal; }
/* {Identifier} printlnCurrentTokenWithName("identifier"); */
{Identifier} { return Identifier; }
/* {Separator}|{Operator} printlnCurrentToken(); */
{TripleDotSeparator} { return TripleDotSeparator; }
{DoubleColonSeparator} { return DoubleColonSeparator; }
{ArrowOperator} { return ArrowOperator; }
{EqualOperator} { return EqualOperator; }
{GreaterThanOrEqualOperator} { return GreaterThanOrEqualOperator; }
{LessThanOrEqualOperator} { return LessThanOrEqualOperator; }
{NotEqualOperator} { return NotEqualOperator; }
{BooleanAndOperator} { return BooleanAndOperator; }
{BooleanOrOperator} { return BooleanOrOperator; }
{IncrementOperator} { return IncrementOperator; }
{DecrementOperator} { return DecrementOperator; }
{ShiftLeftOperator} { return ShiftLeftOperator; }
{ShiftRightOperator} { return ShiftRightOperator; }
{ShiftRightArithmeticOperator} { return ShiftRightArithmeticOperator; }
{AddAssignmentOperator} { return AddAssignmentOperator; }
{MinusAssignmentOperator} { return MinusAssignmentOperator; }
{MultiplyAssignmentOperator} { return MultiplyAssignmentOperator; }
{DivideAssignmentOperator} { return DivideAssignmentOperator; }
{AndAssignmentOperator} { return AndAssignmentOperator; }
{OrAssignmentOperator} { return OrAssignmentOperator; }
{XorAssignmentOperator} { return XorAssignmentOperator; }
{ModAssignmentOperator} { return ModAssignmentOperator; }
{ShiftLeftAssignmnetOperator} { return ShiftLeftAssignmnetOperator; }
{ShiftRightAssignmentOperator} { return ShiftRightAssignmentOperator; }
{ShiftRightArithmeticAssignmentOperator} { return ShiftRightArithmeticAssignmentOperator; }
/* (?s:.) printlnCurrentTokenWithName("unknown"); */
(?s:.) { return yytext[0]; } // Other single character tokens and undefined ones fall into this rule.
%%
/*
void printlnCurrentToken() {
printlnMonuple(yytext);
}
void printlnCurrentTokenWithName(const char* name) {
printlnCouple(name, yytext);
}
void printlnMonuple(const char* first) {
printfln("%s", first);
}
void printlnCouple(const char* first, const char* second) {
printfln("%s %s", first, second);
}
void printfln(const char* format, ...) {
va_list args;
va_start(args, format);
vprintf(format, args);
va_end(args);
printf("\n");
}
*/