-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscanner.l
103 lines (56 loc) · 2.54 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
97
98
99
100
101
102
103
%option noyywrap nodefault
%x COMMENT
%{
#include "common.h"
#include "parser.tab.h"
int send_EOL = 1;
%}
%%
"/*" { BEGIN COMMENT; }
<COMMENT>"*/\n" { BEGIN INITIAL; }
<COMMENT>([^*]|\n)+|.
<COMMENT><<EOF>> { yyerror("Comment not terminated"); }
"//".*\n { /* ignore */ }
;/; |
^([ \t]*\n) |
[ \t] { /* ignore */ }
\{/[ \t]*\n { send_EOL = 0; return SYM_OB; }
;/[ \t]*\n { send_EOL = 0; return SYM_SC; }
\n { if(send_EOL) return EOL; else send_EOL = 1; }
"fn" { return CMD_FUNC; }
"main" { return CMD_MAIN; }
"read_line" { return CMD_SCAN; }
"println!" { return CMD_PRINT; }
"while" { return CMD_WHILE; }
"if" { return CMD_IF; }
"else" { return CMD_ELSE; }
"let" { return CMD_VAR; }
"\"" { return ASPA; }
"," { return COMMA; }
"=" { return OP_ATRIB; }
"+" { return OP_SUM; }
"-" { return OP_SUB; }
"*" { return OP_MULT; }
"/" { return OP_DIV; }
"%" { return OP_MOD; }
"==" { return OP_EQ; }
"!=" { return OP_DIFF; }
"<" { return OP_LT; }
">" { return OP_GT; }
"<=" { return OP_LTE; }
">=" { return OP_GTE; }
"&&" { return OP_AND; }
"||" { return OP_OR; }
"true" { yylval.tyInt=1; return TYPE_BOOL; }
"false" { yylval.tyInt=0; return TYPE_BOOL; }
[0-9]+(\.[0-9]*)? { yylval.tyInt = atof(yytext); return TYPE_INT; }
[a-zA-Z]+([a-zA-Z]|[0-9])* { yylval.tyString = strdup(yytext); return VAR; }
\".*\" { yylval.tyString = strdup(yytext); return VARP; }
"{" { return SYM_OB; }
"}" { return SYM_CB; }
"(" { return SYM_OP; }
")" { return SYM_CP; }
";" { return SYM_SC; }
<<EOF>> { yyterminate(); }
. { yyerror("Unexpected."); }
%%