blob: 70704b8ea0660830fbb018d124a8fe3b9cef6e45 (
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
%{
#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 sqstr 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; }
option { return tokOption; }
goto { return tokGoto; }
not { return tokNot; }
setup { return tokSetup; }
enter { return tokEnter; }
and { return tokAnd; }
or { return tokOr; }
return { return tokReturn; }
ignore { return tokIgnore; }
exists { return tokExists; }
delete { return tokDelete; }
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]*\n? {}
"/*" { BEGIN( comment ); }
<comment>"*/" { BEGIN( INITIAL ); }
<comment>[\n\r] {}
<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)?\.[0-9]* {
// printf("Parsing float: %s\n", yytext );
yylval->dValue = strtod( yytext, NULL );
// printf("Final float: %f\n", yylval->dValue );
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; }
\' { BEGIN( sqstr ); yylval->sValue = new Bu::String(); }
<sqstr>[^']+ { (*yylval->sValue) += yytext; }
<sqstr>\' { 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;
}
\r { }
. { throw Bu::ExceptionBase("Invalid character found '%s'", yytext ); }
%%
|