diff options
Diffstat (limited to '')
-rw-r--r-- | LuaSL/src/LuaSL_LSL_tree.c | 188 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_LSL_tree.h | 59 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_lemon_yaccer.y | 51 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_lexer.l | 4 |
4 files changed, 242 insertions, 60 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.c b/LuaSL/src/LuaSL_LSL_tree.c index c593378..e37f794 100644 --- a/LuaSL/src/LuaSL_LSL_tree.c +++ b/LuaSL/src/LuaSL_LSL_tree.c | |||
@@ -10,9 +10,13 @@ static LSL_Leaf *evaluateOperationToken(LSL_Leaf *content, LSL_Leaf *left, LSL_ | |||
10 | static LSL_Leaf *eveluateParenthesisToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); | 10 | static LSL_Leaf *eveluateParenthesisToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); |
11 | static LSL_Leaf *evaluateStatementToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); | 11 | static LSL_Leaf *evaluateStatementToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); |
12 | static void outputFloatToken(FILE *file, LSL_Leaf *content); | 12 | static void outputFloatToken(FILE *file, LSL_Leaf *content); |
13 | static void outputFunctionToken(FILE *file, LSL_Leaf *content); | ||
13 | static void outputIntegerToken(FILE *file, LSL_Leaf *content); | 14 | static void outputIntegerToken(FILE *file, LSL_Leaf *content); |
15 | static void outputParameterToken(FILE *file, LSL_Leaf *content); | ||
16 | static void outputParameterListToken(FILE *file, LSL_Leaf *content); | ||
14 | static void outputParenthesisToken(FILE *file, LSL_Leaf *content); | 17 | static void outputParenthesisToken(FILE *file, LSL_Leaf *content); |
15 | static void outputStatementToken(FILE *file, LSL_Leaf *content); | 18 | static void outputStatementToken(FILE *file, LSL_Leaf *content); |
19 | static void outputVariableToken(FILE *file, LSL_Leaf *content); | ||
16 | 20 | ||
17 | LSL_Token LSL_Tokens[] = | 21 | LSL_Token LSL_Tokens[] = |
18 | { | 22 | { |
@@ -95,7 +99,7 @@ LSL_Token LSL_Tokens[] = | |||
95 | {LSL_TYPE_VECTOR, ST_NONE, "vector", LSL_NONE, NULL, NULL, NULL}, | 99 | {LSL_TYPE_VECTOR, ST_NONE, "vector", LSL_NONE, NULL, NULL, NULL}, |
96 | 100 | ||
97 | // Then the rest of the syntax tokens. | 101 | // Then the rest of the syntax tokens. |
98 | {LSL_IDENTIFIER, ST_NONE, "identifier", LSL_NONE, NULL, NULL, NULL}, | 102 | {LSL_IDENTIFIER, ST_NONE, "identifier", LSL_NONE, outputVariableToken, NULL, NULL}, |
99 | 103 | ||
100 | {LSL_LABEL, ST_NONE, "@", LSL_NONE, NULL, NULL, NULL}, | 104 | {LSL_LABEL, ST_NONE, "@", LSL_NONE, NULL, NULL, NULL}, |
101 | 105 | ||
@@ -112,8 +116,9 @@ LSL_Token LSL_Tokens[] = | |||
112 | 116 | ||
113 | {LSL_BLOCK_CLOSE, ST_NONE, "}", LSL_NONE, NULL, NULL, NULL}, | 117 | {LSL_BLOCK_CLOSE, ST_NONE, "}", LSL_NONE, NULL, NULL, NULL}, |
114 | {LSL_BLOCK_OPEN, ST_NONE, "{", LSL_NONE, NULL, NULL, NULL}, | 118 | {LSL_BLOCK_OPEN, ST_NONE, "{", LSL_NONE, NULL, NULL, NULL}, |
115 | {LSL_PARAMETER, ST_NONE, "parameter", LSL_NONE, NULL, NULL, NULL}, | 119 | {LSL_PARAMETER, ST_NONE, "parameter", LSL_NONE, outputParameterToken, NULL, NULL}, |
116 | {LSL_FUNCTION, ST_NONE, "function", LSL_NONE, NULL, NULL, NULL}, | 120 | {LSL_PARAMETER_LIST, ST_NONE, "plist", LSL_NONE, outputParameterListToken, NULL, NULL}, |
121 | {LSL_FUNCTION, ST_NONE, "function", LSL_NONE, outputFunctionToken, NULL, NULL}, | ||
117 | {LSL_STATE, ST_NONE, "state", LSL_NONE, NULL, NULL, NULL}, | 122 | {LSL_STATE, ST_NONE, "state", LSL_NONE, NULL, NULL, NULL}, |
118 | {LSL_SCRIPT, ST_NONE, "", LSL_NONE, NULL, NULL, NULL}, | 123 | {LSL_SCRIPT, ST_NONE, "", LSL_NONE, NULL, NULL, NULL}, |
119 | 124 | ||
@@ -179,7 +184,6 @@ LSL_Token **tokens = NULL; | |||
179 | int lowestToken = 999999; | 184 | int lowestToken = 999999; |
180 | 185 | ||
181 | 186 | ||
182 | /* Not actually used, but it might be some day. | ||
183 | static LSL_Leaf *newLeaf(LSL_Type type, LSL_Leaf *left, LSL_Leaf *right) | 187 | static LSL_Leaf *newLeaf(LSL_Type type, LSL_Leaf *left, LSL_Leaf *right) |
184 | { | 188 | { |
185 | LSL_Leaf *leaf = calloc(1, sizeof(LSL_Leaf)); | 189 | LSL_Leaf *leaf = calloc(1, sizeof(LSL_Leaf)); |
@@ -193,7 +197,6 @@ static LSL_Leaf *newLeaf(LSL_Type type, LSL_Leaf *left, LSL_Leaf *right) | |||
193 | 197 | ||
194 | return leaf; | 198 | return leaf; |
195 | } | 199 | } |
196 | */ | ||
197 | 200 | ||
198 | void burnLeaf(LSL_Leaf *leaf) | 201 | void burnLeaf(LSL_Leaf *leaf) |
199 | { | 202 | { |
@@ -278,14 +281,76 @@ LSL_Leaf *addOperation(LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right) | |||
278 | return lval; | 281 | return lval; |
279 | } | 282 | } |
280 | 283 | ||
281 | LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Leaf *rval) | 284 | LSL_Leaf *addParameter(LuaSL_yyparseParam *param, LSL_Leaf *type, LSL_Leaf *identifier) |
285 | { | ||
286 | LSL_Identifier *result = calloc(1, sizeof(LSL_Identifier)); | ||
287 | |||
288 | if ( (identifier) && (result)) | ||
289 | { | ||
290 | result->name = identifier->value.stringValue; | ||
291 | identifier->value.variableValue = result; | ||
292 | identifier->token = tokens[LSL_PARAMETER - lowestToken]; | ||
293 | identifier->left = type; | ||
294 | if (type) | ||
295 | { | ||
296 | identifier->basicType = type->basicType; | ||
297 | result->value.basicType = type->basicType; | ||
298 | } | ||
299 | } | ||
300 | return identifier; | ||
301 | } | ||
302 | |||
303 | LSL_Leaf *collectParameters(LuaSL_yyparseParam *param, LSL_Leaf *list, LSL_Leaf *comma, LSL_Leaf *newParam) | ||
304 | { | ||
305 | LSL_Leaf *newList = newLeaf(LSL_PARAMETER_LIST, NULL, NULL); | ||
306 | |||
307 | if (newList) | ||
308 | { | ||
309 | newList->left = list; | ||
310 | newList->value.listValue = newParam; | ||
311 | if ((list) && (list->value.listValue)) | ||
312 | { | ||
313 | list->value.listValue->right = comma; | ||
314 | } | ||
315 | } | ||
316 | |||
317 | return newList; | ||
318 | } | ||
319 | |||
320 | LSL_Leaf *addFunction(LuaSL_yyparseParam *param, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close, LSL_Leaf *block) | ||
321 | { | ||
322 | LSL_Function *func = calloc(1, sizeof(LSL_Function)); | ||
323 | |||
324 | if (func) | ||
325 | { | ||
326 | if (identifier) | ||
327 | { | ||
328 | char *temp = identifier->value.stringValue; | ||
329 | |||
330 | identifier->token = tokens[LSL_FUNCTION - lowestToken]; | ||
331 | identifier->value.functionValue = func; | ||
332 | identifier->value.functionValue->name = temp; | ||
333 | identifier->value.functionValue->block = block; | ||
334 | func->type = type; | ||
335 | if (type) | ||
336 | identifier->basicType = type->basicType; | ||
337 | else | ||
338 | identifier->basicType = OT_nothing; | ||
339 | func->params = addParenthesis(open, params, LSL_PARAMETER_LIST, close); | ||
340 | } | ||
341 | } | ||
342 | return identifier; | ||
343 | } | ||
344 | |||
345 | LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval) | ||
282 | { | 346 | { |
283 | LSL_Parenthesis *parens = malloc(sizeof(LSL_Parenthesis)); | 347 | LSL_Parenthesis *parens = malloc(sizeof(LSL_Parenthesis)); |
284 | 348 | ||
285 | if (parens) | 349 | if (parens) |
286 | { | 350 | { |
287 | parens->left = lval; | 351 | parens->left = lval; |
288 | parens->expression = expr; | 352 | parens->contents = expr; |
353 | parens->type = type; | ||
289 | parens->right = rval; | 354 | parens->right = rval; |
290 | if (lval) | 355 | if (lval) |
291 | { | 356 | { |
@@ -297,6 +362,21 @@ LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Leaf *rval) | |||
297 | return lval; | 362 | return lval; |
298 | } | 363 | } |
299 | 364 | ||
365 | LSL_Leaf *addState(LuaSL_yyparseParam *param, char *name, LSL_Leaf *state) | ||
366 | { | ||
367 | LSL_State *result = calloc(1, sizeof(LSL_State)); | ||
368 | |||
369 | if (result) | ||
370 | { | ||
371 | result->name = name; | ||
372 | param->script.scount++; | ||
373 | param->script.states = realloc(param->script.states, param->script.scount * sizeof(LSL_State *)); | ||
374 | param->script.states[param->script.scount - 1] = result; | ||
375 | } | ||
376 | |||
377 | return state; | ||
378 | } | ||
379 | |||
300 | LSL_Leaf *addStatement(LSL_Leaf *lval, LSL_Type type, LSL_Leaf *expr) | 380 | LSL_Leaf *addStatement(LSL_Leaf *lval, LSL_Type type, LSL_Leaf *expr) |
301 | { | 381 | { |
302 | LSL_Statement *stat = malloc(sizeof(LSL_Statement)); | 382 | LSL_Statement *stat = malloc(sizeof(LSL_Statement)); |
@@ -319,7 +399,8 @@ LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf * | |||
319 | if (parens) | 399 | if (parens) |
320 | { | 400 | { |
321 | parens->left = lval; | 401 | parens->left = lval; |
322 | parens->expression = expr; | 402 | parens->contents = expr; |
403 | parens->type = LSL_TYPECAST_OPEN; | ||
323 | parens->right = rval; | 404 | parens->right = rval; |
324 | if (lval) | 405 | if (lval) |
325 | { | 406 | { |
@@ -336,6 +417,57 @@ LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf * | |||
336 | return lval; | 417 | return lval; |
337 | } | 418 | } |
338 | 419 | ||
420 | LSL_Leaf *addVariable(LuaSL_yyparseParam *param, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *assignment, LSL_Leaf *expr) | ||
421 | { | ||
422 | LSL_Identifier *result = calloc(1, sizeof(LSL_Identifier)); | ||
423 | |||
424 | if ( (identifier) && (result)) | ||
425 | { | ||
426 | result->name = identifier->value.stringValue; | ||
427 | identifier->value.variableValue = result; | ||
428 | identifier->left = type; | ||
429 | identifier->right = assignment; | ||
430 | if (assignment) | ||
431 | assignment->right = expr; | ||
432 | if (type) | ||
433 | { | ||
434 | identifier->basicType = type->basicType; | ||
435 | result->value.basicType = type->basicType; | ||
436 | } | ||
437 | if (param->currentBlock) | ||
438 | { | ||
439 | param->currentBlock->vcount++; | ||
440 | param->currentBlock->variables = realloc(param->currentBlock->variables, param->currentBlock->vcount * sizeof(LSL_Identifier *)); | ||
441 | param->currentBlock->variables[param->currentBlock->vcount - 1] = result; | ||
442 | } | ||
443 | else | ||
444 | { | ||
445 | param->script.vcount++; | ||
446 | param->script.variables = realloc(param->script.variables, param->script.vcount * sizeof(LSL_Identifier *)); | ||
447 | param->script.variables[param->script.vcount - 1] = result; | ||
448 | } | ||
449 | } | ||
450 | |||
451 | return identifier; | ||
452 | } | ||
453 | |||
454 | void beginBlock(LuaSL_yyparseParam *param, LSL_Leaf *block) | ||
455 | { | ||
456 | LSL_Block *blok = malloc(sizeof(LSL_Block)); | ||
457 | |||
458 | if (blok) | ||
459 | { | ||
460 | block->value.blockValue = blok; | ||
461 | blok->outerBlock = param->currentBlock; | ||
462 | param->currentBlock = blok; | ||
463 | } | ||
464 | } | ||
465 | |||
466 | void endBlock(LuaSL_yyparseParam *param, LSL_Leaf *block) | ||
467 | { | ||
468 | param->currentBlock = param->currentBlock->outerBlock; | ||
469 | } | ||
470 | |||
339 | static LSL_Leaf *evaluateLeaf(LSL_Leaf *leaf, LSL_Leaf *left, LSL_Leaf *right) | 471 | static LSL_Leaf *evaluateLeaf(LSL_Leaf *leaf, LSL_Leaf *left, LSL_Leaf *right) |
340 | { | 472 | { |
341 | LSL_Leaf *result = NULL; | 473 | LSL_Leaf *result = NULL; |
@@ -601,7 +733,10 @@ static LSL_Leaf *eveluateParenthesisToken(LSL_Leaf *content, LSL_Leaf *left, LSL | |||
601 | LSL_Leaf *result = NULL; | 733 | LSL_Leaf *result = NULL; |
602 | 734 | ||
603 | if (content) | 735 | if (content) |
604 | result = evaluateLeaf(content->value.parenthesis->expression, left, right); | 736 | { |
737 | if (LSL_PARAMETER_LIST != content->value.parenthesis->type) | ||
738 | result = evaluateLeaf(content->value.parenthesis->contents, left, right); | ||
739 | } | ||
605 | return result; | 740 | return result; |
606 | } | 741 | } |
607 | 742 | ||
@@ -653,18 +788,43 @@ static void outputFloatToken(FILE *file, LSL_Leaf *content) | |||
653 | fprintf(file, "%g", content->value.floatValue); | 788 | fprintf(file, "%g", content->value.floatValue); |
654 | } | 789 | } |
655 | 790 | ||
791 | static void outputFunctionToken(FILE *file, LSL_Leaf *content) | ||
792 | { | ||
793 | if (content) | ||
794 | { | ||
795 | LSL_Function *func = content->value.functionValue; | ||
796 | |||
797 | outputLeaf(file, func->type); | ||
798 | fprintf(file, "%s", func->name); | ||
799 | outputLeaf(file, func->params); | ||
800 | outputLeaf(file, func->block); | ||
801 | } | ||
802 | } | ||
803 | |||
656 | static void outputIntegerToken(FILE *file, LSL_Leaf *content) | 804 | static void outputIntegerToken(FILE *file, LSL_Leaf *content) |
657 | { | 805 | { |
658 | if (content) | 806 | if (content) |
659 | fprintf(file, "%d", content->value.integerValue); | 807 | fprintf(file, "%d", content->value.integerValue); |
660 | } | 808 | } |
661 | 809 | ||
810 | static void outputParameterToken(FILE *file, LSL_Leaf *content) | ||
811 | { | ||
812 | if (content) | ||
813 | fprintf(file, "%s", content->value.parameterValue->name); | ||
814 | } | ||
815 | |||
816 | static void outputParameterListToken(FILE *file, LSL_Leaf *content) | ||
817 | { | ||
818 | if (content) | ||
819 | outputLeaf(file, content->value.listValue); | ||
820 | } | ||
821 | |||
662 | static void outputParenthesisToken(FILE *file, LSL_Leaf *content) | 822 | static void outputParenthesisToken(FILE *file, LSL_Leaf *content) |
663 | { | 823 | { |
664 | if (content) | 824 | if (content) |
665 | { | 825 | { |
666 | fprintf(file, "%s", content->token->token); | 826 | fprintf(file, "%s", content->token->token); |
667 | outputLeaf(file, content->value.parenthesis->expression); | 827 | outputLeaf(file, content->value.parenthesis->contents); |
668 | outputLeaf(file, content->value.parenthesis->right); | 828 | outputLeaf(file, content->value.parenthesis->right); |
669 | } | 829 | } |
670 | } | 830 | } |
@@ -680,6 +840,13 @@ static void outputStatementToken(FILE *file, LSL_Leaf *content) | |||
680 | } | 840 | } |
681 | } | 841 | } |
682 | 842 | ||
843 | static void outputVariableToken(FILE *file, LSL_Leaf *content) | ||
844 | { | ||
845 | if (content) | ||
846 | fprintf(file, "%s", content->value.variableValue->name); | ||
847 | } | ||
848 | |||
849 | |||
683 | static void convertLeaf2Lua(FILE *file, LSL_Leaf *leaf) | 850 | static void convertLeaf2Lua(FILE *file, LSL_Leaf *leaf) |
684 | { | 851 | { |
685 | if (leaf) | 852 | if (leaf) |
@@ -705,7 +872,6 @@ static void doneParsing(LuaSL_yyparseParam *param) | |||
705 | char buffer[PATH_MAX]; | 872 | char buffer[PATH_MAX]; |
706 | char outName[PATH_MAX]; | 873 | char outName[PATH_MAX]; |
707 | char luaName[PATH_MAX]; | 874 | char luaName[PATH_MAX]; |
708 | int count; | ||
709 | 875 | ||
710 | outputLeaf(stdout, param->ast); | 876 | outputLeaf(stdout, param->ast); |
711 | printf("\n"); | 877 | printf("\n"); |
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index b547976..4113454 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h | |||
@@ -2,7 +2,7 @@ | |||
2 | #ifndef __LSL_TREE_H__ | 2 | #ifndef __LSL_TREE_H__ |
3 | #define __LSL_TREE_H__ | 3 | #define __LSL_TREE_H__ |
4 | 4 | ||
5 | #define LUASL_DEBUG | 5 | //#define LUASL_DEBUG |
6 | 6 | ||
7 | 7 | ||
8 | #include <stddef.h> // So we can have NULL defined. | 8 | #include <stddef.h> // So we can have NULL defined. |
@@ -218,8 +218,9 @@ struct _LSL_Leaf | |||
218 | struct _LSL_Parenthesis | 218 | struct _LSL_Parenthesis |
219 | { | 219 | { |
220 | LSL_Leaf *left; | 220 | LSL_Leaf *left; |
221 | LSL_Leaf *expression; | 221 | LSL_Leaf *contents; |
222 | LSL_Leaf *right; | 222 | LSL_Leaf *right; |
223 | LSL_Type type; | ||
223 | }; | 224 | }; |
224 | 225 | ||
225 | struct _LSL_Identifier // For variables and function parameters. | 226 | struct _LSL_Identifier // For variables and function parameters. |
@@ -237,30 +238,32 @@ struct _LSL_Statement | |||
237 | struct _LSL_Block | 238 | struct _LSL_Block |
238 | { | 239 | { |
239 | LSL_Block *outerBlock; | 240 | LSL_Block *outerBlock; |
240 | LSL_Statement *statements; | 241 | LSL_Statement **statements; |
241 | LSL_Identifier *scopeVariables; | 242 | LSL_Identifier **variables; // Those variables in this scope. |
243 | int scount, vcount; | ||
242 | }; | 244 | }; |
243 | 245 | ||
244 | struct _LSL_Function | 246 | struct _LSL_Function |
245 | { | 247 | { |
246 | char *name; | 248 | char *name; |
247 | LSL_Block block; | 249 | LSL_Leaf *type; |
248 | LSL_Identifier *parameters; | 250 | LSL_Leaf *params; |
249 | LSL_Type type; // Return type. | 251 | LSL_Leaf *block; |
250 | }; | 252 | }; |
251 | 253 | ||
252 | struct _LSL_State | 254 | struct _LSL_State |
253 | { | 255 | { |
254 | char *name; | 256 | char *name; |
255 | LSL_Function *handlers; | 257 | LSL_Function **handlers; |
256 | }; | 258 | }; |
257 | 259 | ||
258 | struct _LSL_Script | 260 | struct _LSL_Script |
259 | { | 261 | { |
260 | char *name; | 262 | char *name; |
261 | LSL_Function *functions; | 263 | LSL_Function **functions; |
262 | LSL_State *states; | 264 | LSL_State **states; |
263 | LSL_Identifier *variables; | 265 | LSL_Identifier **variables; |
266 | int fcount, scount, vcount; | ||
264 | }; | 267 | }; |
265 | 268 | ||
266 | // Define the type for flex and lemon. | 269 | // Define the type for flex and lemon. |
@@ -268,15 +271,18 @@ struct _LSL_Script | |||
268 | 271 | ||
269 | typedef struct | 272 | typedef struct |
270 | { | 273 | { |
271 | void *scanner; // This should be of type yyscan_t, which is typedef to void * anyway, but that does not get defined until LuaSL_lexer.h, which depends on this struct being defined first. | 274 | void *scanner; // This should be of type yyscan_t, which is typedef to void * anyway, but that does not get defined until LuaSL_lexer.h, which depends on this struct being defined first. |
272 | int argc; | 275 | int argc; |
273 | char **argv; | 276 | char **argv; |
274 | char fileName[PATH_MAX]; | 277 | char fileName[PATH_MAX]; |
275 | FILE *file; | 278 | FILE *file; |
276 | LSL_Leaf *ast; | 279 | LSL_Leaf *ast; |
277 | char *ignorableText; | 280 | LSL_Script script; |
278 | LSL_Leaf *lval; | 281 | char *ignorableText; |
279 | int column, line; | 282 | LSL_Leaf *lval; |
283 | int column, line; | ||
284 | LSL_Block *currentBlock; | ||
285 | LSL_Leaf *currentFunction; | ||
280 | } LuaSL_yyparseParam; | 286 | } LuaSL_yyparseParam; |
281 | 287 | ||
282 | 288 | ||
@@ -286,11 +292,18 @@ typedef struct | |||
286 | 292 | ||
287 | 293 | ||
288 | void burnLeaf(LSL_Leaf *leaf); | 294 | void burnLeaf(LSL_Leaf *leaf); |
289 | LSL_Leaf *addExpression(LSL_Leaf *exp); | 295 | LSL_Leaf *addFunction(LuaSL_yyparseParam *param, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close, LSL_Leaf *block); |
290 | LSL_Leaf *addOperation(LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right); | 296 | LSL_Leaf *addOperation(LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right); |
291 | LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Leaf *rval); | 297 | LSL_Leaf *addParameter(LuaSL_yyparseParam *param, LSL_Leaf *type, LSL_Leaf *newParam); |
298 | LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval); | ||
299 | LSL_Leaf *addState(LuaSL_yyparseParam *param, char *name, LSL_Leaf *state); | ||
292 | LSL_Leaf *addStatement(LSL_Leaf *lval, LSL_Type type, LSL_Leaf *expr); | 300 | LSL_Leaf *addStatement(LSL_Leaf *lval, LSL_Type type, LSL_Leaf *expr); |
293 | LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf *expr); | 301 | LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf *expr); |
302 | LSL_Leaf *addVariable(LuaSL_yyparseParam *param, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *assignment, LSL_Leaf *expr); | ||
303 | |||
304 | void beginBlock(LuaSL_yyparseParam *param, LSL_Leaf *block); | ||
305 | LSL_Leaf *collectParameters(LuaSL_yyparseParam *param, LSL_Leaf *list, LSL_Leaf *comma, LSL_Leaf *newParam); | ||
306 | void endBlock(LuaSL_yyparseParam *param, LSL_Leaf *block); | ||
294 | 307 | ||
295 | void *ParseAlloc(void *(*mallocProc)(size_t)); | 308 | void *ParseAlloc(void *(*mallocProc)(size_t)); |
296 | void ParseTrace(FILE *TraceFILE, char *zTracePrompt); | 309 | void ParseTrace(FILE *TraceFILE, char *zTracePrompt); |
diff --git a/LuaSL/src/LuaSL_lemon_yaccer.y b/LuaSL/src/LuaSL_lemon_yaccer.y index d24f1a9..f79c228 100644 --- a/LuaSL/src/LuaSL_lemon_yaccer.y +++ b/LuaSL/src/LuaSL_lemon_yaccer.y | |||
@@ -12,8 +12,8 @@ | |||
12 | %default_destructor {burnLeaf($$);} | 12 | %default_destructor {burnLeaf($$);} |
13 | 13 | ||
14 | // The start symbol, just coz we need one. | 14 | // The start symbol, just coz we need one. |
15 | // Lemon does not like the start symbol to be on the RHS, so give it a dummy start symbol. | ||
16 | 15 | ||
16 | // Lemon does not like the start symbol to be on the RHS, so give it a dummy start symbol. | ||
17 | program ::= script LSL_SCRIPT(A). { if (NULL != A) A->left = param->ast; param->ast = A; } | 17 | program ::= script LSL_SCRIPT(A). { if (NULL != A) A->left = param->ast; param->ast = A; } |
18 | 18 | ||
19 | // Various forms of "space". The lexer takes care of them for us. | 19 | // Various forms of "space". The lexer takes care of them for us. |
@@ -24,7 +24,7 @@ program ::= script LSL_SCRIPT(A). { if (NULL != A) A->left = param->ast; p | |||
24 | 24 | ||
25 | %nonassoc LSL_SCRIPT. | 25 | %nonassoc LSL_SCRIPT. |
26 | script ::= script state. | 26 | script ::= script state. |
27 | script ::= script function. | 27 | script ::= script function(A). { if (NULL != A) A->left = param->ast; param->ast = A; } |
28 | script ::= script statement(A). { if (NULL != A) A->left = param->ast; param->ast = A; } | 28 | script ::= script statement(A). { if (NULL != A) A->left = param->ast; param->ast = A; } |
29 | script ::= . | 29 | script ::= . |
30 | 30 | ||
@@ -32,25 +32,26 @@ script ::= . | |||
32 | 32 | ||
33 | %nonassoc LSL_BLOCK_OPEN LSL_BLOCK_CLOSE LSL_STATE. | 33 | %nonassoc LSL_BLOCK_OPEN LSL_BLOCK_CLOSE LSL_STATE. |
34 | stateBlock ::= LSL_BLOCK_OPEN functionList LSL_BLOCK_CLOSE. | 34 | stateBlock ::= LSL_BLOCK_OPEN functionList LSL_BLOCK_CLOSE. |
35 | state ::= LSL_IDENTIFIER stateBlock. | 35 | state(S) ::= LSL_IDENTIFIER(I) stateBlock(B). { S = addState(param, I->value.stringValue, B); } |
36 | 36 | ||
37 | // Function definitions. | 37 | // Function definitions. |
38 | 38 | ||
39 | %nonassoc LSL_PARAMETER LSL_FUNCTION. | 39 | %nonassoc LSL_PARAMETER LSL_PARAMETER_LIST LSL_FUNCTION. |
40 | functionList ::= functionList function. | 40 | functionList ::= functionList function. |
41 | functionList ::= . | 41 | functionList ::= . |
42 | 42 | ||
43 | parameter ::= type LSL_IDENTIFIER. | 43 | parameterList(A) ::= parameterList(B) LSL_COMMA(C) parameter(D). { A = collectParameters(param, B, C, D); } |
44 | parameterList ::= parameterList LSL_COMMA parameter. | 44 | parameterList(A) ::= parameter(D). { A = collectParameters(param, NULL, NULL, D); } |
45 | parameterList ::= parameter. | 45 | parameterList(A) ::= . { A = collectParameters(param, NULL, NULL, NULL); } |
46 | parameterList ::= . | 46 | parameter(A) ::= type(B) LSL_IDENTIFIER(C). { A = addParameter(param, B, C); } |
47 | function ::= LSL_IDENTIFIER LSL_PARENTHESIS_OPEN parameterList LSL_PARENTHESIS_CLOSE funcBlock. // Causes a conflict when it's an empty parameterList with calling the same type of function. | 47 | // Causes a conflict when it's an empty parameterList with calling the same type of function. |
48 | function ::= type LSL_IDENTIFIER LSL_PARENTHESIS_OPEN parameterList LSL_PARENTHESIS_CLOSE funcBlock. | 48 | function(A) ::= LSL_IDENTIFIER(C) LSL_PARENTHESIS_OPEN(D) parameterList(E) LSL_PARENTHESIS_CLOSE(F) funcBlock(G). { A = addFunction(param, NULL, C, D, E, F, G); } |
49 | function(A) ::= type(B) LSL_IDENTIFIER(C) LSL_PARENTHESIS_OPEN(D) parameterList(E) LSL_PARENTHESIS_CLOSE(F) funcBlock(G). { A = addFunction(param, B, C, D, E, F, G); } | ||
49 | 50 | ||
50 | // Blocks. | 51 | // Blocks. |
51 | 52 | ||
52 | block ::= funcBlock. | 53 | block(A) ::= funcBlock(B). { A = B; } |
53 | block ::= statement. | 54 | block(A) ::= statement(B). { A = B; } |
54 | funcBlock ::= LSL_BLOCK_OPEN statementList LSL_BLOCK_CLOSE. | 55 | funcBlock ::= LSL_BLOCK_OPEN statementList LSL_BLOCK_CLOSE. |
55 | 56 | ||
56 | // Various forms of statement. | 57 | // Various forms of statement. |
@@ -66,7 +67,8 @@ statement ::= LSL_FOR LSL_PARENTHESIS_OPEN expr LSL_STATEMENT expr LSL_STATEMENT | |||
66 | 67 | ||
67 | ifBlock ::= ifBlock LSL_ELSE block. | 68 | ifBlock ::= ifBlock LSL_ELSE block. |
68 | ifBlock ::= block. | 69 | ifBlock ::= block. |
69 | statement ::= LSL_IF LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE ifBlock. [LSL_ELSE] // The [LSL_ELSE] part causes a conflict. | 70 | // The [LSL_ELSE] part causes a conflict. |
71 | statement ::= LSL_IF LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE ifBlock. [LSL_ELSE] | ||
70 | 72 | ||
71 | statement ::= LSL_JUMP LSL_IDENTIFIER LSL_STATEMENT. | 73 | statement ::= LSL_JUMP LSL_IDENTIFIER LSL_STATEMENT. |
72 | statement ::= LSL_RETURN expr LSL_STATEMENT. | 74 | statement ::= LSL_RETURN expr LSL_STATEMENT. |
@@ -126,24 +128,25 @@ expr(A) ::= LSL_SUBTRACT(B) expr(C). [LSL_NEGATION] { A = addOperation(NULL, B | |||
126 | 128 | ||
127 | %right LSL_TYPECAST_OPEN LSL_TYPECAST_CLOSE. | 129 | %right LSL_TYPECAST_OPEN LSL_TYPECAST_CLOSE. |
128 | %nonassoc LSL_TYPE_FLOAT LSL_TYPE_INTEGER LSL_TYPE_KEY LSL_TYPE_LIST LSL_TYPE_ROTATION LSL_TYPE_STRING LSL_TYPE_VECTOR. | 130 | %nonassoc LSL_TYPE_FLOAT LSL_TYPE_INTEGER LSL_TYPE_KEY LSL_TYPE_LIST LSL_TYPE_ROTATION LSL_TYPE_STRING LSL_TYPE_VECTOR. |
129 | type ::= LSL_TYPE_FLOAT. | 131 | type(A) ::= LSL_TYPE_FLOAT(B). { B->basicType = OT_float; A = B; } |
130 | type ::= LSL_TYPE_INTEGER. | 132 | type(A) ::= LSL_TYPE_INTEGER(B). { B->basicType = OT_integer; A = B; } |
131 | type ::= LSL_TYPE_KEY. | 133 | type(A) ::= LSL_TYPE_KEY(B). { B->basicType = OT_key; A = B; } |
132 | type ::= LSL_TYPE_LIST. | 134 | type(A) ::= LSL_TYPE_LIST(B). { B->basicType = OT_list; A = B; } |
133 | type ::= LSL_TYPE_ROTATION. | 135 | type(A) ::= LSL_TYPE_ROTATION(B). { B->basicType = OT_rotation; A = B; } |
134 | type ::= LSL_TYPE_STRING. | 136 | type(A) ::= LSL_TYPE_STRING(B). { B->basicType = OT_string; A = B; } |
135 | type ::= LSL_TYPE_VECTOR. | 137 | type(A) ::= LSL_TYPE_VECTOR(B). { B->basicType = OT_vector; A = B; } |
136 | 138 | ||
137 | %left LSL_ANGLE_OPEN LSL_ANGLE_CLOSE. | 139 | %left LSL_ANGLE_OPEN LSL_ANGLE_CLOSE. |
138 | %nonassoc LSL_BRACKET_OPEN LSL_BRACKET_CLOSE. | 140 | %nonassoc LSL_BRACKET_OPEN LSL_BRACKET_CLOSE. |
139 | %nonassoc LSL_PARENTHESIS_OPEN LSL_PARENTHESIS_CLOSE LSL_EXPRESSION. | 141 | %nonassoc LSL_PARENTHESIS_OPEN LSL_PARENTHESIS_CLOSE LSL_EXPRESSION. |
140 | 142 | ||
141 | expr(A) ::= LSL_PARENTHESIS_OPEN(B) expr(C) LSL_PARENTHESIS_CLOSE(D). { A = addParenthesis(B, C, D); } | 143 | expr(A) ::= LSL_PARENTHESIS_OPEN(B) expr(C) LSL_PARENTHESIS_CLOSE(D). { A = addParenthesis(B, C, LSL_EXPRESSION, D); } |
142 | expr(A) ::= LSL_PARENTHESIS_OPEN(B) type(C) LSL_PARENTHESIS_CLOSE(D) expr(E). { A = addTypecast(B, C, D, E); } | 144 | expr(A) ::= LSL_PARENTHESIS_OPEN(B) type(C) LSL_PARENTHESIS_CLOSE(D) expr(E). { A = addTypecast(B, C, D, E); } |
143 | 145 | ||
144 | // Function call. | 146 | // Function call. |
145 | 147 | ||
146 | expr ::= LSL_IDENTIFIER LSL_PARENTHESIS_OPEN exprList LSL_PARENTHESIS_CLOSE. // Casuses a conflict when exprList is empty with a function definition with no type and no parameters. | 148 | // Causes a conflict when exprList is empty with a function definition with no type and no parameters. |
149 | expr ::= LSL_IDENTIFIER LSL_PARENTHESIS_OPEN exprList LSL_PARENTHESIS_CLOSE. | ||
147 | 150 | ||
148 | // Variables and dealing with them. | 151 | // Variables and dealing with them. |
149 | 152 | ||
@@ -159,8 +162,8 @@ expr ::= identifier LSL_ASSIGNMENT_DIVIDE expr. | |||
159 | expr ::= identifier LSL_ASSIGNMENT_PLAIN expr. | 162 | expr ::= identifier LSL_ASSIGNMENT_PLAIN expr. |
160 | 163 | ||
161 | // Hmm think this can have commas seperating the assignment parts. | 164 | // Hmm think this can have commas seperating the assignment parts. |
162 | statement ::= type LSL_IDENTIFIER LSL_ASSIGNMENT_PLAIN expr LSL_STATEMENT. | 165 | statement(A) ::= type(B) LSL_IDENTIFIER(C) LSL_ASSIGNMENT_PLAIN(D) expr(E) LSL_STATEMENT(F). { A = addStatement(F, LSL_IDENTIFIER, addVariable(param, B, C, D, E)); } |
163 | statement ::= type LSL_IDENTIFIER LSL_STATEMENT. | 166 | statement(A) ::= type(B) LSL_IDENTIFIER(C) LSL_STATEMENT(F). { A = addStatement(F, LSL_IDENTIFIER, addVariable(param, B, C, NULL, NULL)); } |
164 | 167 | ||
165 | %right LSL_DOT LSL_IDENTIFIER. | 168 | %right LSL_DOT LSL_IDENTIFIER. |
166 | identifier ::= identifier LSL_DOT LSL_IDENTIFIER. | 169 | identifier ::= identifier LSL_DOT LSL_IDENTIFIER. |
diff --git a/LuaSL/src/LuaSL_lexer.l b/LuaSL/src/LuaSL_lexer.l index afc99ce..4dde0ac 100644 --- a/LuaSL/src/LuaSL_lexer.l +++ b/LuaSL/src/LuaSL_lexer.l | |||
@@ -74,8 +74,8 @@ STRING \"(\\.|[^\\"\n])*\" | |||
74 | 74 | ||
75 | /* Other symbols. */ | 75 | /* Other symbols. */ |
76 | "@" %{ return common(yylval, yytext, yyextra, TRUE, LSL_LABEL); %} | 76 | "@" %{ return common(yylval, yytext, yyextra, TRUE, LSL_LABEL); %} |
77 | "{" %{ return common(yylval, yytext, yyextra, TRUE, LSL_BLOCK_OPEN); %} | 77 | "{" %{ beginBlock(yyextra, yylval); return common(yylval, yytext, yyextra, TRUE, LSL_BLOCK_OPEN); %} |
78 | "}" %{ return common(yylval, yytext, yyextra, TRUE, LSL_BLOCK_CLOSE); %} | 78 | "}" %{ endBlock(yyextra, yylval); return common(yylval, yytext, yyextra, TRUE, LSL_BLOCK_CLOSE); %} |
79 | ";" %{ return common(yylval, yytext, yyextra, TRUE, LSL_STATEMENT); %} | 79 | ";" %{ return common(yylval, yytext, yyextra, TRUE, LSL_STATEMENT); %} |
80 | 80 | ||
81 | /* Type keywords. */ | 81 | /* Type keywords. */ |