blob: 3491d276db13e978a13d39d35161b8dcf0fc8ab3 (
plain)
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
104
105
106
107
108
|
%{
#include <stdint.h>
#include <bu/string.h>
#include "parser.tab.h"
//#define YY_DECL int yylex( YYSTYPE *yylval, struct YYLTYPE *llocp, yyscan_t yyscanner )
//YY_DECL;
# define YY_USER_ACTION yylloc->last_column += yyleng;
%}
%option reentrant noyywrap nounput batch
%option bison-bridge bison-locations
%x sitname
%x comment
%x dqstr tdqstr tsqstr
%%
"<=" { return tokLtEq; }
">=" { return tokGtEq; }
"==" { return tokCmp; }
"+=" { return tokPlusAssign; }
"-=" { return tokMinusAssign; }
"*=" { return tokTimesAssign; }
"/=" { return tokDivideAssign; }
[-{}<>=+/*,();:.[\]] { return yytext[0]; }
game { return tokGame; }
global { return tokGlobal; }
function { return tokFunction; }
situation { return tokSituation; }
player { return tokPlayer; }
while { return tokWhile; }
for { return tokFor; }
each { return tokEach; }
do { return tokDo; }
in { return tokIn; }
if { return tokIf; }
then { return tokThen; }
else { return tokElse; }
command { return tokCommand; }
goto { return tokGoto; }
not { return tokNot; }
setup { return tokSetup; }
enter { return tokEnter; }
and { return tokAnd; }
or { return tokOr; }
true { yylval->bValue = true; return tokBool; }
false { yylval->bValue = false; return tokBool; }
null { return tokNull; }
"<<" { BEGIN( sitname ); }
<sitname>[- a-zA-Z0-9]+ { yylval->sValue = new Bu::String( yytext ); return tokSituationName; }
<sitname>">>" { BEGIN( INITIAL ); }
<sitname>. REJECT;
"//"[^\n]* {}
"/\*" { BEGIN( comment ); }
<comment>"\*/" { BEGIN( INITIAL ); }
<comment>. {}
[a-zA-Z_][a-zA-Z0-9_]* { yylval->sValue = new Bu::String( yytext ); return tokIdent; }
[1-9][0-9]* {
yylval->iValue = strtoll( yytext, NULL, 10 );
return tokInt;
}
0 {
yylval->iValue = 0;
return tokInt;
}
([1-9][0-9]*)?\.[0-9]* {
yylval->dValue = strtod( yytext, NULL );
return tokFloat;
}
\"\"\" { BEGIN( tdqstr ); yylval->sValue = new Bu::String(); }
<tdqstr>[^"]+ { (*yylval->sValue) += yytext; }
<tdqstr>\" { (*yylval->sValue) += yytext; }
<tdqstr>\"\"\" { BEGIN( INITIAL ); return tokString; }
\'\'\' { BEGIN( tsqstr ); yylval->sValue = new Bu::String(); }
<tsqstr>[^']+ { (*yylval->sValue) += yytext; }
<tsqstr>\' { (*yylval->sValue) += yytext; }
<tsqstr>\'\'\' { BEGIN( INITIAL ); return tokString; }
\" { BEGIN( dqstr ); yylval->sValue = new Bu::String(); }
<dqstr>[^"]+ { (*yylval->sValue) += yytext; }
<dqstr>\" { BEGIN( INITIAL ); return tokString; }
[ \t]+ {
yylloc->first_line = yylloc->last_line;
yylloc->first_column = yylloc->last_column+1;
}
\n+ {
yylloc->last_column = yylloc->first_column = 0;
yylloc->last_line+= yyleng;
yylloc->first_line = yylloc->last_line;
}
%%
|