-
Notifications
You must be signed in to change notification settings - Fork 2
/
indra.l.in
449 lines (389 loc) · 12.6 KB
/
indra.l.in
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
N [0-9]
L [a-zA-Z_]
H [a-fA-F0-9]
E [Ee][ -]?{N}
FS (f|F)
%e 10000
%n 4000
%p 5000
%top {
#include "linden_common.h"
}
%{
// Deal with the fact that lex/yacc generates unreachable code
#ifdef LL_WINDOWS
#pragma warning (disable : 4018) // warning C4018: signed/unsigned mismatch
#pragma warning (disable : 4702) // warning C4702: unreachable code
#endif // LL_WINDOWS
//#include "llmath.h"
#include "lscript_tree.h"
#include "lscript_typecheck.h"
#include "lscript_resource.h"
#include "indra.y.hpp"
//#include "lltimer.h"
//#include "indra_constants.h"
//#include "llagentconstants.h"
//#include "lllslconstants.h"
//#include "lluuid.h"
//#include "llassetstorage.h"
//#include "llpartdata.h"
//#include "llvehicleparams.h"
//#include "llpermissionsflags.h"
//#include "llfollowcamparams.h"
//#include "llparcelflags.h"
//#include "llregionflags.h"
//#include "lscript_http.h"
//#include "llclickaction.h"
//#include "llmediaentry.h"
// <FS:CR> Add OSSL constants for OS builds
//#ifdef OPENSIM
//#include "osslconstants.h"
//#endif // OPENSIM
// </FS:CR>
void count();
void line_comment();
void block_comment();
void parse_string();
#define YYLMAX 16384
#define YY_NEVER_INTERACTIVE 1 /* stops flex from calling isatty() */
#ifdef LL_WINDOWS
#define isatty(x) 0 /* hack for bug in cygwin flex 2.5.35 */
#endif
#ifdef ECHO
#undef ECHO
#endif
#define ECHO do { } while (0)
#define yyparse indra_parse
#define yyerror indra_error
#define yylval indra_lval
#define yy_create_buffer indra__create_buffer
#define yy_delete_buffer indra__delete_buffer
#define yy_flex_debug indra__flex_debug
#define yy_init_buffer indra__init_buffer
#define yy_flush_buffer indra__flush_buffer
#define yy_load_buffer_state indra__load_buffer_state
#define yy_switch_to_buffer indra__switch_to_buffer
#define yyin indra_in
#define yyleng indra_leng
#define yylex indra_lex
#define yylineno indra_lineno
#define yyout indra_out
#define yyrestart indra_restart
#define yytext indra_text
#define yywrap indra_wrap
#define yyalloc indra_alloc
#define yyrealloc indra_realloc
#define yyfree indra_free
int yylex( void );
int yyparse( void );
int yyerror(const char *fmt, ...);
%}
%%
"//" { gInternalLine ; gInternalColumn = 0; line_comment(); }
"/*" { block_comment(); }
"integer" { count(); return(INTEGER); }
"float" { count(); return(FLOAT_TYPE); }
"string" { count(); return(STRING); }
"key" { count(); return(LLKEY); }
"vector" { count(); return(VECTOR); }
"quaternion" { count(); return(QUATERNION); }
"rotation" { count(); return(QUATERNION); }
"list" { count(); return(LIST); }
"default" { count(); yylval.sval = new char[strlen(yytext) 1]; strcpy(yylval.sval, yytext); return(STATE_DEFAULT); }
"state" { count(); return(STATE); }
"event" { count(); return(EVENT); }
"jump" { count(); return(JUMP); }
"return" { count(); return(RETURN); }
"if" { count(); return(IF); }
"else" { count(); return(ELSE); }
"for" { count(); return(FOR); }
"do" { count(); return(DO); }
"while" { count(); return(WHILE); }
"state_entry" { count(); return(STATE_ENTRY); }
"state_exit" { count(); return(STATE_EXIT); }
"touch_start" { count(); return(TOUCH_START); }
"touch" { count(); return(TOUCH); }
"touch_end" { count(); return(TOUCH_END); }
"collision_start" { count(); return(COLLISION_START); }
"collision" { count(); return(COLLISION); }
"collision_end" { count(); return(COLLISION_END); }
"land_collision_start" { count(); return(LAND_COLLISION_START); }
"land_collision" { count(); return(LAND_COLLISION); }
"land_collision_end" { count(); return(LAND_COLLISION_END); }
"timer" { count(); return(TIMER); }
"listen" { count(); return(CHAT); }
"sensor" { count(); return(SENSOR); }
"no_sensor" { count(); return(NO_SENSOR); }
"control" { count(); return(CONTROL); }
"print" { count(); return(PRINT); }
"at_target" { count(); return(AT_TARGET); }
"not_at_target" { count(); return(NOT_AT_TARGET); }
"at_rot_target" { count(); return(AT_ROT_TARGET); }
"not_at_rot_target" { count(); return(NOT_AT_ROT_TARGET); }
"money" { count(); return(MONEY); }
"email" { count(); return(EMAIL); }
"run_time_permissions" { count(); return(RUN_TIME_PERMISSIONS); }
"changed" { count(); return(INVENTORY); }
"attach" { count(); return(ATTACH); }
"dataserver" { count(); return(DATASERVER); }
"moving_start" { count(); return(MOVING_START); }
"moving_end" { count(); return(MOVING_END); }
"link_message" { count(); return(LINK_MESSAGE); }
"on_rez" { count(); return(REZ); }
"object_rez" { count(); return(OBJECT_REZ); }
"remote_data" { count(); return(REMOTE_DATA); }
"http_response" { count(); return(HTTP_RESPONSE); }
"http_request" { count(); return(HTTP_REQUEST); }
"transaction_result" { count(); return(TRANSACTION_RESULT); }
"path_update" { count(); return(PATH_UPDATE); }
"experience_permissions" { count(); return(EXPERIENCE_PERMISSIONS); }
"experience_permissions_denied" { count(); return(EXPERIENCE_PERMISSIONS_DENIED); }
"." { count(); return(PERIOD); }
0[xX]{H} { count(); yylval.ival = strtoul(yytext, NULL, 0); return(INTEGER_CONSTANT); }
{N} { count(); yylval.ival = strtoul(yytext, NULL, 10); return(INTEGER_CONSTANT); }
"TRUE" { count(); yylval.ival = 1; return(INTEGER_TRUE); }
"FALSE" { count(); yylval.ival = 0; return(INTEGER_FALSE); }
"ZERO_VECTOR" { count(); return(ZERO_VECTOR); }
"ZERO_ROTATION" { count(); return(ZERO_ROTATION); }
"TOUCH_INVALID_VECTOR" { count(); return(TOUCH_INVALID_VECTOR); }
"TOUCH_INVALID_TEXCOORD" { count(); return(TOUCH_INVALID_TEXCOORD); }
<<< LSL KEYWORDS version >>>
<<< LSL KEYWORDS integer_constants >>>
<<< LSL KEYWORDS fp_constants >>>
<<< LSL KEYWORDS string_constants >>>
{L}({L}|{N})* { count(); yylval.sval = new char[strlen(yytext) 1]; strcpy(yylval.sval, yytext); return(IDENTIFIER); }
{N} {E} { count(); yylval.fval = (F32)atof(yytext); return(FP_CONSTANT); }
{N}*"."{N} ({E})?{FS}? { count(); yylval.fval = (F32)atof(yytext); return(FP_CONSTANT); }
{N} "."{N}*({E})?{FS}? { count(); yylval.fval = (F32)atof(yytext); return(FP_CONSTANT); }
L?\"(\\.|[^\\"])*\" { parse_string(); count(); return(STRING_CONSTANT); }
" " { count(); return(INC_OP); }
"--" { count(); return(DEC_OP); }
" =" { count(); return(ADD_ASSIGN); }
"-=" { count(); return(SUB_ASSIGN); }
"*=" { count(); return(MUL_ASSIGN); }
"/=" { count(); return(DIV_ASSIGN); }
"%=" { count(); return(MOD_ASSIGN); }
";" { count(); return(';'); }
"{" { count(); return('{'); }
"}" { count(); return('}'); }
"," { count(); return(','); }
"=" { count(); return('='); }
"(" { count(); return('('); }
")" { count(); return(')'); }
"-" { count(); return('-'); }
" " { count(); return(' '); }
"*" { count(); return('*'); }
"/" { count(); return('/'); }
"%" { count(); return('%'); }
"@" { count(); return('@'); }
":" { count(); return(':'); }
">" { count(); return('>'); }
"<" { count(); return('<'); }
"]" { count(); return(']'); }
"[" { count(); return('['); }
"==" { count(); return(EQ); }
"!=" { count(); return(NEQ); }
">=" { count(); return(GEQ); }
"<=" { count(); return(LEQ); }
"&" { count(); return('&'); }
"|" { count(); return('|'); }
"^" { count(); return('^'); }
"~" { count(); return('~'); }
"!" { count(); return('!'); }
"&&" { count(); return(BOOLEAN_AND); }
"||" { count(); return(BOOLEAN_OR); }
"<<" { count(); return(SHIFT_LEFT); }
">>" { count(); return(SHIFT_RIGHT); }
[ \t\v\n\f] { count(); }
. { /* ignore bad characters */ }
%%
LLScriptAllocationManager *gAllocationManager;
LLScriptScript *gScriptp;
// Prototype for the yacc parser entry point
int yyparse(void);
int yyerror(const char *fmt, ...)
{
gErrorToText.writeError(yyout, gLine, gColumn, LSERROR_SYNTAX_ERROR);
return 0;
}
//#define EMERGENCY_DEBUG_PRINTOUTS
//#define EMIT_CIL_ASSEMBLER
BOOL lscript_compile(const char* src_filename, const char* dst_filename,
const char* err_filename, BOOL compile_to_mono, const char* class_name, BOOL is_god_like)
{
BOOL b_parse_ok = FALSE;
BOOL b_dummy = FALSE;
U64 b_dummy_count = FALSE;
LSCRIPTType type = LST_NULL;
gInternalColumn = 0;
gInternalLine = 0;
gScriptp = NULL;
gErrorToText.init();
init_supported_expressions();
init_temp_jumps();
gAllocationManager = new LLScriptAllocationManager();
yyin = LLFile::fopen(std::string(src_filename), "r");
if (yyin)
{
yyout = LLFile::fopen(std::string(err_filename), "w");
// Reset the lexer's internal buffering.
yyrestart(yyin);
b_parse_ok = !yyparse();
if (b_parse_ok)
{
#ifdef EMERGENCY_DEBUG_PRINTOUTS
char compiled[256];
sprintf(compiled, "%s.pp", src_filename);
LLFILE* compfile;
compfile = LLFile::fopen(compiled, "w");
#endif
if(dst_filename)
{
gScriptp->setBytecodeDest(dst_filename);
}
gScriptp->mGodLike = is_god_like;
gScriptp->setClassName(class_name);
gScopeStringTable = new LLStringTable(16384);
#ifdef EMERGENCY_DEBUG_PRINTOUTS
gScriptp->recurse(compfile, 0, 4, LSCP_PRETTY_PRINT, LSPRUNE_INVALID, b_dummy, NULL, type, type, b_dummy_count, NULL, NULL, 0, NULL, 0, NULL);
#endif
gScriptp->recurse(yyout, 0, 0, LSCP_PRUNE, LSPRUNE_INVALID, b_dummy, NULL, type, type, b_dummy_count, NULL, NULL, 0, NULL, 0, NULL);
gScriptp->recurse(yyout, 0, 0, LSCP_SCOPE_PASS1, LSPRUNE_INVALID, b_dummy, NULL, type, type, b_dummy_count, NULL, NULL, 0, NULL, 0, NULL);
gScriptp->recurse(yyout, 0, 0, LSCP_SCOPE_PASS2, LSPRUNE_INVALID, b_dummy, NULL, type, type, b_dummy_count, NULL, NULL, 0, NULL, 0, NULL);
gScriptp->recurse(yyout, 0, 0, LSCP_TYPE, LSPRUNE_INVALID, b_dummy, NULL, type, type, b_dummy_count, NULL, NULL, 0, NULL, 0, NULL);
if (!gErrorToText.getErrors())
{
gScriptp->recurse(yyout, 0, 0, LSCP_RESOURCE, LSPRUNE_INVALID, b_dummy, NULL, type, type, b_dummy_count, NULL, NULL, 0, NULL, 0, NULL);
#ifdef EMERGENCY_DEBUG_PRINTOUTS
gScriptp->recurse(yyout, 0, 0, LSCP_EMIT_ASSEMBLY, LSPRUNE_INVALID, b_dummy, NULL, type, type, b_dummy_count, NULL, NULL, 0, NULL, 0, NULL);
#endif
if(TRUE == compile_to_mono)
{
gScriptp->recurse(yyout, 0, 0, LSCP_EMIT_CIL_ASSEMBLY, LSPRUNE_INVALID, b_dummy, NULL, type, type, b_dummy_count, NULL, NULL, 0, NULL, 0, NULL);
}
else
{
gScriptp->recurse(yyout, 0, 0, LSCP_EMIT_BYTE_CODE, LSPRUNE_INVALID, b_dummy, NULL, type, type, b_dummy_count, NULL, NULL, 0, NULL, 0, NULL);
}
}
delete gScopeStringTable;
gScopeStringTable = NULL;
#ifdef EMERGENCY_DEBUG_PRINTOUTS
fclose(compfile);
#endif
}
fclose(yyout);
fclose(yyin);
}
delete gAllocationManager;
delete gScopeStringTable;
return b_parse_ok && !gErrorToText.getErrors();
}
BOOL lscript_compile(char *filename, BOOL compile_to_mono, BOOL is_god_like = FALSE)
{
char src_filename[MAX_STRING];
sprintf(src_filename, "%s.lsl", filename);
char err_filename[MAX_STRING];
sprintf(err_filename, "%s.out", filename);
char class_name[MAX_STRING];
sprintf(class_name, "%s", filename);
return lscript_compile(src_filename, NULL, err_filename, compile_to_mono, class_name, is_god_like);
}
S32 yywrap()
{
#if defined(FLEX_SCANNER) && !defined(LL_WINDOWS)
// get gcc to stop complaining about lack of use of yyunput
(void) yyunput;
#endif
return(1);
}
void line_comment()
{
char c;
while ((c = yyinput()) != '\n' && c != 0 && c != EOF)
;
}
void block_comment()
{
char c1 = 0;
char c2 = yyinput();
while (c2 != 0 && c2 != EOF && !(c1 == '*' && c2 == '/')) {
if (c2 == '\n')
{
gInternalLine ;
gInternalColumn = 0;
}
else if (c2 == '\t')
gInternalColumn = 4 - (gInternalColumn % 8);
else
gInternalColumn ;
c1 = c2;
c2 = yyinput();
}
}
void count()
{
S32 i;
gColumn = gInternalColumn;
gLine = gInternalLine;
for (i = 0; yytext[i] != '\0'; i )
if (yytext[i] == '\n')
{
gInternalLine ;
gInternalColumn = 0;
}
else if (yytext[i] == '\t')
gInternalColumn = 4 - (gInternalColumn % 8);
else
gInternalColumn ;
}
void parse_string()
{
S32 length = (S32)strlen(yytext);
length = length - 2;
char *temp = yytext 1;
S32 i;
S32 escapes = 0;
S32 tabs = 0;
for (i = 0; i < length; i )
{
if (temp[i] == '\\')
{
escapes ;
i ;
if (temp[i] == 't')
tabs ;
}
}
S32 newlength = length - escapes tabs*3;
yylval.sval = new char[newlength 1];
char *dest = yylval.sval;
for (i = 0; i < length; i )
{
if (temp[i] == '\\')
{
i ;
// linefeed
if (temp[i] == 'n')
{
*dest = 10;
}
else if (temp[i] == 't')
{
*dest = ' ';
*dest = ' ';
*dest = ' ';
*dest = ' ';
}
else
{
*dest = temp[i];
}
}
else
{
*dest = temp[i];
}
}
yylval.sval[newlength] = 0;
}