-
Notifications
You must be signed in to change notification settings - Fork 0
/
script_scanner.l
34 lines (31 loc) · 932 Bytes
/
script_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
%{
#include <cstdio>
#include <iostream>
using namespace std;
#include "script_parser.tab.h"
%}
%option outfile="script_scanner.c" header-file="script_scanner.h"
%option reentrant
%option bison-bridge
%option extra-type="struct pass_to_bison*"
%%
[\n] { yyextra->line++; }
[ \t] ;
var { return VAR; }
if { return IF; }
else { return ELSE; }
print { return PRINT; }
[0-9]+ { yylval->ival = new ScriptInteger(yytext); return INT; }
[a-zA-Z0-9]+ { yylval->token = strdup(yytext); return TOKEN; }
["]([^"]|(\\\"))*["] {yytext[strlen(yytext)-1] = '\0';yylval->sval = new ScriptString(yytext+1); return STRING;}
[+] { return ADD; }
[\[] { return LBRACKET; }
[\]] { return RBRACKET; }
; { return SCOLIN; }
= { return ASSIGN; }
[{] { return LBRACE; }
[}] { return RBRACE; }
[(] { return LPAREN; }
[)] { return RPAREN; }
. ;
%%