-
Notifications
You must be signed in to change notification settings - Fork 0
/
compiler-tokens.l
50 lines (43 loc) · 1.37 KB
/
compiler-tokens.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
%option noyywrap
%option yylineno
%{
#include "botscript.h"
#include "compiler-parser.tab.h"
#define TOK( x ) yylval.token = x; return x
%}
D [0-9]
L [A-Za-z_]
%%
"if" { TOK( TIF ); }
"else" { TOK( TELSE ); }
"return" { TOK( TRETURN ); }
"nil" { TOK( TNIL ); }
"or" { TOK( TOR ); }
"and" { TOK( TAND ); }
"for" { TOK( TFOR ); }
"in" { TOK( TIN ); }
"==" { TOK( TEQUAL ); }
"!=" { TOK( TNEQUAL ); }
"=" { TOK( TASSIGN ); }
"{" { TOK( TLBRACE ); }
"}" { TOK( TRBRACE ); }
"[" { TOK( TLBRACKET ); }
"]" { TOK( TRBRACKET ); }
"." { TOK( TSUBSCRIPT ); }
":" { TOK( TCOLON ); }
"," { TOK( TCOMMA ); }
"+=" { TOK( TADD_ASSIGN ); }
"+" { TOK( TADD ); }
">=" { TOK( TGTE ); }
"<=" { TOK( TGTE ); }
">" { TOK( TGT ); }
"<" { TOK( TLT ); }
{L}+({L}|{D})* { yylval.sval = new string( yytext, yyleng ); return TIDENTIFIER; }
#.*$ ; // Comment
(\t|\ ) ; // Ignore whitespace
\r?\n? { TOK( TENDL ); }
\"[^"]*\" { yylval.sval = new string( yytext, yyleng ); return TSTRING; }
-?{D}+\.{D}+ { yylval.dval = atof( yytext ); return TDOUBLE; }
-?{D}+ { yylval.ival = atoi( yytext ); return TINTEGER; }
. ;
%%