-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflex.l
37 lines (35 loc) · 884 Bytes
/
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
%{
#include <string.h>
#include "node.h"
uint64_t line_no = 1;
%}
%option noyywrap
%option nounput
%option noinput
%%
[ \t] { ; }
^\/\/.*$ { ; }
\n { line_no++; }
if { return (IF); }
else { return (ELSE); }
while { return (WHILE); }
for { return (FOR); }
print { return (PRINT); }
println { return (PRINTLN); }
var { return (VARSTR); }
debug { return (DEBUG); }
function { return (FUNCTION); }
return { return (RETURN); }
"==" { return (EQ); }
"&&" { return (AND); }
"||" { return (OR); }
"**" { return (POWER); }
[A-Za-z][A-Za-z0-9]* { yylval.str = strdup(yytext);
return (VAR); }
[0-9]+ { yylval.val = atoi(yytext);
return (NUM); }
\"[^"]*\" { yytext[yyleng-1] = '\0';
yylval.str = strdup(&yytext[1]);
return (STRING); }
. { return (yytext[0]); }
%%