-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscanner.l
97 lines (80 loc) · 3.18 KB
/
scanner.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
%{
#include "auxlib.h"
#include "lyutils.h"
#define YY_USER_ACTION { scanner_useraction (); }
#define IGNORE(THING) { }
%}
%option 8bit
%option debug
%option ecs
%option nodefault
%option nounput
%option noyywrap
%option perf-report
%option verbose
%option warn
LETTER [A-Za-z_]
DIGIT [0-9]
CHAR ('([^\\'\n]|\\[\\'"0nt])')
STRING (\"([^\\"\n]|\\[\\'"0nt])*\")
INTEGER ({DIGIT}+)
NUMBER ({INTEGER})
IDENT ({LETTER}({LETTER}|{DIGIT})*)
NOTIDENT (({LETTER}|{DIGIT})*)
NOTCHAR ('([^\\'\n]|\\.)'?)
NOTSTRING (\"([^\\"\n]|\\.)*(\")?)
%%
"#".* { scanner_include(); }
[ \t]+ { IGNORE (white space) }
\n { scanner_newline(); }
void { return yylval_token(TOK_VOID); }
bool { return yylval_token(TOK_BOOL); }
char { return yylval_token(TOK_CHAR); }
int { return yylval_token(TOK_INT); }
string { return yylval_token(TOK_STRING); }
struct { return yylval_token(TOK_STRUCT); }
if { return yylval_token(TOK_IF); }
else { return yylval_token(TOK_ELSE); }
while { return yylval_token(TOK_WHILE); }
return { return yylval_token(TOK_RETURN); }
new { return yylval_token(TOK_NEW); }
false { return yylval_token(TOK_FALSE); }
true { return yylval_token(TOK_TRUE); }
null { return yylval_token(TOK_NULL); }
ord { return yylval_token(TOK_ORD); }
chr { return yylval_token(TOK_CHR); }
{NUMBER} { return yylval_token (TOK_INTCON); }
{IDENT} { return yylval_token (TOK_IDENT); }
{CHAR} { return yylval_token (TOK_CHARCON); }
{STRING} { return yylval_token (TOK_STRINGCON); }
"[]" { return yylval_token (TOK_NEWARRAY); }
"(" { return yylval_token ('('); }
")" { return yylval_token (')'); }
"[" { return yylval_token ('['); }
"]" { return yylval_token (']'); }
"{" { return yylval_token ('{'); }
"}" { return yylval_token ('}'); }
";" { return yylval_token (';'); }
"," { return yylval_token (','); }
"." { return yylval_token ('.'); }
"=" { return yylval_token ('='); }
"==" { return yylval_token (TOK_EQ); }
"!=" { return yylval_token (TOK_NE); }
"<" { return yylval_token (TOK_LT); }
"<=" { return yylval_token (TOK_LE); }
">" { return yylval_token (TOK_GT); }
">=" { return yylval_token (TOK_GE); }
"+" { return yylval_token ('+'); }
"-" { return yylval_token ('-'); }
"*" { return yylval_token ('*'); }
"/" { return yylval_token ('/'); }
"%" { return yylval_token ('%'); }
"!" { return yylval_token ('!'); }
{NOTIDENT} { scanner_badtoken (yytext);
return yylval_token (TOK_IDENT); }
{NOTCHAR} { scanner_badtoken (yytext);
return yylval_token (TOK_CHARCON); }
{NOTSTRING} { scanner_badtoken (yytext);
return yylval_token (TOK_STRINGCON); }
. { scanner_badchar (*yytext); }
%%