aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.h20
-rw-r--r--LuaSL/src/LuaSL_compile.c111
-rw-r--r--LuaSL/src/LuaSL_lemon_yaccer.y66
-rw-r--r--LuaSL/src/LuaSL_lexer.l30
4 files changed, 113 insertions, 114 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h
index 4b6e3c4..b73d3ac 100644
--- a/LuaSL/src/LuaSL_LSL_tree.h
+++ b/LuaSL/src/LuaSL_LSL_tree.h
@@ -1,6 +1,6 @@
1 1
2#ifndef __LSL_TREE_H__ 2#ifndef __LUASL_TREE_H__
3#define __LSL_TREE_H__ 3#define __LUASL_TREE_H__
4 4
5//#define LUASL_DEBUG 5//#define LUASL_DEBUG
6 6
@@ -289,7 +289,7 @@ typedef struct
289 LSL_Leaf *lval; 289 LSL_Leaf *lval;
290 int column, line; 290 int column, line;
291 LSL_Block *currentBlock; 291 LSL_Block *currentBlock;
292} LuaSL_yyparseParam; 292} LuaSL_compiler;
293 293
294 294
295#ifndef excludeLexer 295#ifndef excludeLexer
@@ -299,23 +299,23 @@ typedef struct
299 299
300void burnLeaf(LSL_Leaf *leaf); 300void burnLeaf(LSL_Leaf *leaf);
301LSL_Leaf *addFunction(LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close, LSL_Leaf *block); 301LSL_Leaf *addFunction(LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close, LSL_Leaf *block);
302LSL_Leaf *addOperation(LuaSL_yyparseParam *param, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right); 302LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right);
303LSL_Leaf *addParameter(LSL_Leaf *type, LSL_Leaf *newParam); 303LSL_Leaf *addParameter(LSL_Leaf *type, LSL_Leaf *newParam);
304LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval); 304LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval);
305LSL_Leaf *addState(LuaSL_yyparseParam *param, LSL_Leaf *identifier, LSL_Leaf *block); 305LSL_Leaf *addState(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf *block);
306LSL_Leaf *addStatement(LSL_Leaf *lval, LSL_Type type, LSL_Leaf *expr); 306LSL_Leaf *addStatement(LSL_Leaf *lval, LSL_Type type, LSL_Leaf *expr);
307LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf *expr); 307LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf *expr);
308LSL_Leaf *addVariable(LuaSL_yyparseParam *param, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *assignment, LSL_Leaf *expr); 308LSL_Leaf *addVariable(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *assignment, LSL_Leaf *expr);
309 309
310void beginBlock(LuaSL_yyparseParam *param, LSL_Leaf *block); 310void beginBlock(LuaSL_compiler *compiler, LSL_Leaf *block);
311LSL_Leaf *collectParameters(LSL_Leaf *list, LSL_Leaf *comma, LSL_Leaf *newParam); 311LSL_Leaf *collectParameters(LSL_Leaf *list, LSL_Leaf *comma, LSL_Leaf *newParam);
312void endBlock(LuaSL_yyparseParam *param, LSL_Leaf *block); 312void endBlock(LuaSL_compiler *compiler, LSL_Leaf *block);
313 313
314void *ParseAlloc(void *(*mallocProc)(size_t)); 314void *ParseAlloc(void *(*mallocProc)(size_t));
315void ParseTrace(FILE *TraceFILE, char *zTracePrompt); 315void ParseTrace(FILE *TraceFILE, char *zTracePrompt);
316void Parse(void *yyp, int yymajor, LSL_Leaf *yyminor, LuaSL_yyparseParam *param); 316void Parse(void *yyp, int yymajor, LSL_Leaf *yyminor, LuaSL_compiler *compiler);
317void ParseFree(void *p, void (*freeProc)(void*)); 317void ParseFree(void *p, void (*freeProc)(void*));
318 318
319 319
320#endif // __LSL_TREE_H__ 320#endif // __LUASL_LSL_TREE_H__
321 321
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c
index 030f140..583f940 100644
--- a/LuaSL/src/LuaSL_compile.c
+++ b/LuaSL/src/LuaSL_compile.c
@@ -209,9 +209,9 @@ void burnLeaf(LSL_Leaf *leaf)
209 } 209 }
210} 210}
211 211
212LSL_Leaf *addOperation(LuaSL_yyparseParam *param, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right) 212LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right)
213{ 213{
214 gameGlobals *game = param->game; 214 gameGlobals *game = compiler->game;
215 215
216 if (lval) 216 if (lval)
217 { 217 {
@@ -372,7 +372,7 @@ LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf
372 return lval; 372 return lval;
373} 373}
374 374
375LSL_Leaf *addState(LuaSL_yyparseParam *param, LSL_Leaf *identifier, LSL_Leaf *block) 375LSL_Leaf *addState(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf *block)
376{ 376{
377 LSL_State *result = calloc(1, sizeof(LSL_State)); 377 LSL_State *result = calloc(1, sizeof(LSL_State));
378 378
@@ -381,9 +381,9 @@ LSL_Leaf *addState(LuaSL_yyparseParam *param, LSL_Leaf *identifier, LSL_Leaf *bl
381 result->name = identifier->value.stringValue; 381 result->name = identifier->value.stringValue;
382 result->block = block; 382 result->block = block;
383 identifier->value.stateValue = result; 383 identifier->value.stateValue = result;
384 param->script.scount++; 384 compiler->script.scount++;
385 param->script.states = realloc(param->script.states, param->script.scount * sizeof(LSL_State *)); 385 compiler->script.states = realloc(compiler->script.states, compiler->script.scount * sizeof(LSL_State *));
386 param->script.states[param->script.scount - 1] = result; 386 compiler->script.states[compiler->script.scount - 1] = result;
387 } 387 }
388 388
389 return identifier; 389 return identifier;
@@ -429,7 +429,7 @@ LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf *
429 return lval; 429 return lval;
430} 430}
431 431
432LSL_Leaf *addVariable(LuaSL_yyparseParam *param, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *assignment, LSL_Leaf *expr) 432LSL_Leaf *addVariable(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *assignment, LSL_Leaf *expr)
433{ 433{
434 LSL_Identifier *result = calloc(1, sizeof(LSL_Identifier)); 434 LSL_Identifier *result = calloc(1, sizeof(LSL_Identifier));
435 435
@@ -446,38 +446,38 @@ LSL_Leaf *addVariable(LuaSL_yyparseParam *param, LSL_Leaf *type, LSL_Leaf *ident
446 identifier->basicType = type->basicType; 446 identifier->basicType = type->basicType;
447 result->value.basicType = type->basicType; 447 result->value.basicType = type->basicType;
448 } 448 }
449 if (param->currentBlock) 449 if (compiler->currentBlock)
450 { 450 {
451 param->currentBlock->vcount++; 451 compiler->currentBlock->vcount++;
452 param->currentBlock->variables = realloc(param->currentBlock->variables, param->currentBlock->vcount * sizeof(LSL_Identifier *)); 452 compiler->currentBlock->variables = realloc(compiler->currentBlock->variables, compiler->currentBlock->vcount * sizeof(LSL_Identifier *));
453 param->currentBlock->variables[param->currentBlock->vcount - 1] = result; 453 compiler->currentBlock->variables[compiler->currentBlock->vcount - 1] = result;
454 } 454 }
455 else 455 else
456 { 456 {
457 param->script.vcount++; 457 compiler->script.vcount++;
458 param->script.variables = realloc(param->script.variables, param->script.vcount * sizeof(LSL_Identifier *)); 458 compiler->script.variables = realloc(compiler->script.variables, compiler->script.vcount * sizeof(LSL_Identifier *));
459 param->script.variables[param->script.vcount - 1] = result; 459 compiler->script.variables[compiler->script.vcount - 1] = result;
460 } 460 }
461 } 461 }
462 462
463 return identifier; 463 return identifier;
464} 464}
465 465
466void beginBlock(LuaSL_yyparseParam *param, LSL_Leaf *block) 466void beginBlock(LuaSL_compiler *compiler, LSL_Leaf *block)
467{ 467{
468 LSL_Block *blok = malloc(sizeof(LSL_Block)); 468 LSL_Block *blok = malloc(sizeof(LSL_Block));
469 469
470 if (blok) 470 if (blok)
471 { 471 {
472 block->value.blockValue = blok; 472 block->value.blockValue = blok;
473 blok->outerBlock = param->currentBlock; 473 blok->outerBlock = compiler->currentBlock;
474 param->currentBlock = blok; 474 compiler->currentBlock = blok;
475 } 475 }
476} 476}
477 477
478void endBlock(LuaSL_yyparseParam *param, LSL_Leaf *block) 478void endBlock(LuaSL_compiler *compiler, LSL_Leaf *block)
479{ 479{
480 param->currentBlock = param->currentBlock->outerBlock; 480 compiler->currentBlock = compiler->currentBlock->outerBlock;
481} 481}
482 482
483static LSL_Leaf *evaluateLeaf(LSL_Leaf *leaf, LSL_Leaf *left, LSL_Leaf *right) 483static LSL_Leaf *evaluateLeaf(LSL_Leaf *leaf, LSL_Leaf *left, LSL_Leaf *right)
@@ -869,33 +869,33 @@ static void outputVariableToken(FILE *file, outputMode mode, LSL_Leaf *content)
869 fprintf(file, "%s", content->value.variableValue->name); 869 fprintf(file, "%s", content->value.variableValue->name);
870} 870}
871 871
872static void doneParsing(LuaSL_yyparseParam *param) 872static void doneParsing(LuaSL_compiler *compiler)
873{ 873{
874 gameGlobals *game = param->game; 874 gameGlobals *game = compiler->game;
875 875
876 if (param->ast) 876 if (compiler->ast)
877 { 877 {
878 FILE *out; 878 FILE *out;
879 char buffer[PATH_MAX]; 879 char buffer[PATH_MAX];
880 char outName[PATH_MAX]; 880 char outName[PATH_MAX];
881 char luaName[PATH_MAX]; 881 char luaName[PATH_MAX];
882 882
883 outputLeaf(stdout, OM_LSL, param->ast); 883 outputLeaf(stdout, OM_LSL, compiler->ast);
884 printf("\n"); 884 printf("\n");
885 evaluateLeaf(param->ast, NULL, NULL); 885 evaluateLeaf(compiler->ast, NULL, NULL);
886 printf("\n"); 886 printf("\n");
887 887
888 strcpy(outName, param->fileName); 888 strcpy(outName, compiler->fileName);
889 strcat(outName, "2"); 889 strcat(outName, "2");
890 strcpy(luaName, param->fileName); 890 strcpy(luaName, compiler->fileName);
891 strcat(luaName, ".lua"); 891 strcat(luaName, ".lua");
892 out = fopen(outName, "w"); 892 out = fopen(outName, "w");
893 if (out) 893 if (out)
894 { 894 {
895// int count; 895// int count;
896 outputLeaf(out, OM_LSL, param->ast); 896 outputLeaf(out, OM_LSL, compiler->ast);
897 fclose(out); 897 fclose(out);
898 sprintf(buffer, "diff %s %s", param->fileName, outName); 898 sprintf(buffer, "diff %s %s", compiler->fileName, outName);
899// count = system(buffer); 899// count = system(buffer);
900// PI("Return value of %s is %d", buffer, count); 900// PI("Return value of %s is %d", buffer, count);
901// if (0 != count) 901// if (0 != count)
@@ -906,7 +906,7 @@ static void doneParsing(LuaSL_yyparseParam *param)
906 out = fopen(luaName, "w"); 906 out = fopen(luaName, "w");
907 if (out) 907 if (out)
908 { 908 {
909 outputLeaf(out, OM_LUA, param->ast); 909 outputLeaf(out, OM_LUA, compiler->ast);
910 fclose(out); 910 fclose(out);
911 } 911 }
912 else 912 else
@@ -945,57 +945,56 @@ Eina_Bool compilerSetup(gameGlobals *game)
945Eina_Bool compileLSL(gameGlobals *game, char *script) 945Eina_Bool compileLSL(gameGlobals *game, char *script)
946{ 946{
947 Eina_Bool result = EINA_FALSE; 947 Eina_Bool result = EINA_FALSE;
948 LuaSL_yyparseParam param; 948 LuaSL_compiler compiler;
949 void *pParser = ParseAlloc(malloc); 949 void *pParser = ParseAlloc(malloc);
950 int yv; 950 int yv;
951 951
952// Parse the LSL script, validating it and reporting errors. 952// Parse the LSL script, validating it and reporting errors.
953// Just pass all constants and function names through to Lua, assume they are globals there. 953// Just pass all constants and function names through to Lua, assume they are globals there.
954 954
955 memset(&param, 0, sizeof(LuaSL_yyparseParam)); 955 memset(&compiler, 0, sizeof(LuaSL_compiler));
956 param.game = game; 956 compiler.game = game;
957 957
958 958 strncpy(compiler.fileName, script, PATH_MAX - 1);
959 strncpy(param.fileName, script, PATH_MAX - 1); 959 compiler.fileName[PATH_MAX - 1] = '\0';
960 param.fileName[PATH_MAX - 1] = '\0'; 960 compiler.file = fopen(compiler.fileName, "r");
961 param.file = fopen(param.fileName, "r"); 961 if (NULL == compiler.file)
962 if (NULL == param.file)
963 { 962 {
964 PE("Error opening file %s.", param.fileName); 963 PE("Error opening file %s.", compiler.fileName);
965 return FALSE; 964 return FALSE;
966 } 965 }
967 PI("Opened %s.", param.fileName); 966 PI("Opened %s.", compiler.fileName);
968 param.ast = NULL; 967 compiler.ast = NULL;
969 param.lval = calloc(1, sizeof(LSL_Leaf)); 968 compiler.lval = calloc(1, sizeof(LSL_Leaf));
970 // Text editors usually start counting at 1, even programmers editors. 969 // Text editors usually start counting at 1, even programmers editors.
971 param.column = 1; 970 compiler.column = 1;
972 param.line = 1; 971 compiler.line = 1;
973 972
974#ifdef LUASL_DEBUG 973#ifdef LUASL_DEBUG
975// yydebug= 5; 974// yydebug= 5;
976#endif 975#endif
977 if (yylex_init_extra(&param, &(param.scanner))) 976 if (yylex_init_extra(&compiler, &(compiler.scanner)))
978 return result; 977 return result;
979#ifdef LUASL_DEBUG 978#ifdef LUASL_DEBUG
980 yyset_debug(1, param.scanner); 979 yyset_debug(1, compiler.scanner);
981#endif 980#endif
982 yyset_in(param.file, param.scanner); 981 yyset_in(compiler.file, compiler.scanner);
983#ifdef LUASL_DEBUG 982#ifdef LUASL_DEBUG
984 ParseTrace(stdout, "LSL_lemon "); 983 ParseTrace(stdout, "LSL_lemon ");
985#endif 984#endif
986 // on EOF yylex will return 0 985 // on EOF yylex will return 0
987 while((yv = yylex(param.lval, param.scanner)) != 0) 986 while((yv = yylex(compiler.lval, compiler.scanner)) != 0)
988 { 987 {
989 Parse(pParser, yv, param.lval, &param); 988 Parse(pParser, yv, compiler.lval, &compiler);
990 if (LSL_SCRIPT == yv) 989 if (LSL_SCRIPT == yv)
991 break; 990 break;
992 param.lval = calloc(1, sizeof(LSL_Leaf)); 991 compiler.lval = calloc(1, sizeof(LSL_Leaf));
993 } 992 }
994 993
995 yylex_destroy(param.scanner); 994 yylex_destroy(compiler.scanner);
996 Parse (pParser, 0, param.lval, &param); 995 Parse (pParser, 0, compiler.lval, &compiler);
997 ParseFree(pParser, free); 996 ParseFree(pParser, free);
998 doneParsing(&param); 997 doneParsing(&compiler);
999 998
1000// Take the result of the parse, and convert it into Lua source. 999// Take the result of the parse, and convert it into Lua source.
1001// Each LSL script becomes a Lua state. 1000// Each LSL script becomes a Lua state.
@@ -1004,12 +1003,12 @@ Eina_Bool compileLSL(gameGlobals *game, char *script)
1004 1003
1005// Compile the Lua source by the Lua compiler. 1004// Compile the Lua source by the Lua compiler.
1006 1005
1007 if (NULL != param.file) 1006 if (NULL != compiler.file)
1008 { 1007 {
1009 fclose(param.file); 1008 fclose(compiler.file);
1010 param.file = NULL; 1009 compiler.file = NULL;
1011 } 1010 }
1012 burnLeaf(param.ast); 1011 burnLeaf(compiler.ast);
1013 1012
1014 return result; 1013 return result;
1015} 1014}
diff --git a/LuaSL/src/LuaSL_lemon_yaccer.y b/LuaSL/src/LuaSL_lemon_yaccer.y
index 3df7def..e62776b 100644
--- a/LuaSL/src/LuaSL_lemon_yaccer.y
+++ b/LuaSL/src/LuaSL_lemon_yaccer.y
@@ -2,7 +2,7 @@
2#include "LuaSL.h" 2#include "LuaSL.h"
3} 3}
4 4
5%extra_argument {LuaSL_yyparseParam *param} 5%extra_argument {LuaSL_compiler *compiler}
6 6
7%stack_size 1024 7%stack_size 1024
8 8
@@ -14,7 +14,7 @@
14// The start symbol, just coz we need one. 14// The start symbol, just coz we need one.
15 15
16// Lemon does not like the start symbol to be on the RHS, so give it a dummy start symbol. 16// Lemon does not like the start symbol to be on the RHS, so give it a dummy start symbol.
17program ::= script LSL_SCRIPT(A). { if (NULL != A) A->left = param->ast; param->ast = A; } 17program ::= script LSL_SCRIPT(A). { if (NULL != A) A->left = compiler->ast; compiler->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.
20 20
@@ -23,16 +23,16 @@ program ::= script LSL_SCRIPT(A). { if (NULL != A) A->left = param->ast; p
23// Basic script structure. 23// Basic script structure.
24 24
25%nonassoc LSL_SCRIPT. 25%nonassoc LSL_SCRIPT.
26script ::= script state(A). { if (NULL != A) A->left = param->ast; param->ast = A; } 26script ::= script state(A). { if (NULL != A) A->left = compiler->ast; compiler->ast = A; }
27script ::= script function(A). { if (NULL != A) A->left = param->ast; param->ast = A; } 27script ::= script function(A). { if (NULL != A) A->left = compiler->ast; compiler->ast = A; }
28script ::= script statement(A). { if (NULL != A) A->left = param->ast; param->ast = A; } 28script ::= script statement(A). { if (NULL != A) A->left = compiler->ast; compiler->ast = A; }
29script ::= . 29script ::= .
30 30
31// State definitions. 31// State definitions.
32 32
33%nonassoc LSL_BLOCK_OPEN LSL_BLOCK_CLOSE LSL_STATE. 33%nonassoc LSL_BLOCK_OPEN LSL_BLOCK_CLOSE LSL_STATE.
34stateBlock ::= LSL_BLOCK_OPEN functionList LSL_BLOCK_CLOSE. 34stateBlock ::= LSL_BLOCK_OPEN functionList LSL_BLOCK_CLOSE.
35state(S) ::= LSL_IDENTIFIER(I) stateBlock(B). { S = addState(param, I, B); } 35state(S) ::= LSL_IDENTIFIER(I) stateBlock(B). { S = addState(compiler, I, B); }
36 36
37// Function definitions. 37// Function definitions.
38 38
@@ -89,40 +89,40 @@ exprList ::= expr.
89exprList ::= . 89exprList ::= .
90 90
91%right LSL_BOOL_AND. 91%right LSL_BOOL_AND.
92expr(A) ::= expr(B) LSL_BOOL_AND(C) expr(D). { A = addOperation(param, B, C, D); } 92expr(A) ::= expr(B) LSL_BOOL_AND(C) expr(D). { A = addOperation(compiler, B, C, D); }
93%right LSL_BOOL_OR. 93%right LSL_BOOL_OR.
94expr(A) ::= expr(B) LSL_BOOL_OR(C) expr(D). { A = addOperation(param, B, C, D); } 94expr(A) ::= expr(B) LSL_BOOL_OR(C) expr(D). { A = addOperation(compiler, B, C, D); }
95 95
96%left LSL_BIT_AND LSL_BIT_XOR LSL_BIT_OR. 96%left LSL_BIT_AND LSL_BIT_XOR LSL_BIT_OR.
97expr(A) ::= expr(B) LSL_BIT_OR(C) expr(D). { A = addOperation(param, B, C, D); } 97expr(A) ::= expr(B) LSL_BIT_OR(C) expr(D). { A = addOperation(compiler, B, C, D); }
98expr(A) ::= expr(B) LSL_BIT_XOR(C) expr(D). { A = addOperation(param, B, C, D); } 98expr(A) ::= expr(B) LSL_BIT_XOR(C) expr(D). { A = addOperation(compiler, B, C, D); }
99expr(A) ::= expr(B) LSL_BIT_AND(C) expr(D). { A = addOperation(param, B, C, D); } 99expr(A) ::= expr(B) LSL_BIT_AND(C) expr(D). { A = addOperation(compiler, B, C, D); }
100 100
101%right LSL_EQUAL LSL_NOT_EQUAL. 101%right LSL_EQUAL LSL_NOT_EQUAL.
102expr(A) ::= expr(B) LSL_NOT_EQUAL(C) expr(D). { A = addOperation(param, B, C, D); } 102expr(A) ::= expr(B) LSL_NOT_EQUAL(C) expr(D). { A = addOperation(compiler, B, C, D); }
103expr(A) ::= expr(B) LSL_EQUAL(C) expr(D). { A = addOperation(param, B, C, D); } 103expr(A) ::= expr(B) LSL_EQUAL(C) expr(D). { A = addOperation(compiler, B, C, D); }
104%right LSL_LESS_THAN LSL_GREATER_THAN LSL_LESS_EQUAL LSL_GREATER_EQUAL. 104%right LSL_LESS_THAN LSL_GREATER_THAN LSL_LESS_EQUAL LSL_GREATER_EQUAL.
105expr(A) ::= expr(B) LSL_GREATER_EQUAL(C) expr(D). { A = addOperation(param, B, C, D); } 105expr(A) ::= expr(B) LSL_GREATER_EQUAL(C) expr(D). { A = addOperation(compiler, B, C, D); }
106expr(A) ::= expr(B) LSL_LESS_EQUAL(C) expr(D). { A = addOperation(param, B, C, D); } 106expr(A) ::= expr(B) LSL_LESS_EQUAL(C) expr(D). { A = addOperation(compiler, B, C, D); }
107expr(A) ::= expr(B) LSL_GREATER_THAN(C) expr(D). { A = addOperation(param, B, C, D); } 107expr(A) ::= expr(B) LSL_GREATER_THAN(C) expr(D). { A = addOperation(compiler, B, C, D); }
108expr(A) ::= expr(B) LSL_LESS_THAN(C) expr(D). { A = addOperation(param, B, C, D); } 108expr(A) ::= expr(B) LSL_LESS_THAN(C) expr(D). { A = addOperation(compiler, B, C, D); }
109 109
110%left LSL_LEFT_SHIFT LSL_RIGHT_SHIFT. 110%left LSL_LEFT_SHIFT LSL_RIGHT_SHIFT.
111expr(A) ::= expr(B) LSL_RIGHT_SHIFT(C) expr(D). { A = addOperation(param, B, C, D); } 111expr(A) ::= expr(B) LSL_RIGHT_SHIFT(C) expr(D). { A = addOperation(compiler, B, C, D); }
112expr(A) ::= expr(B) LSL_LEFT_SHIFT(C) expr(D). { A = addOperation(param, B, C, D); } 112expr(A) ::= expr(B) LSL_LEFT_SHIFT(C) expr(D). { A = addOperation(compiler, B, C, D); }
113 113
114%left LSL_SUBTRACT LSL_ADD LSL_CONCATENATE. 114%left LSL_SUBTRACT LSL_ADD LSL_CONCATENATE.
115expr(A) ::= expr(B) LSL_ADD(C) expr(D). { A = addOperation(param, B, C, D); } 115expr(A) ::= expr(B) LSL_ADD(C) expr(D). { A = addOperation(compiler, B, C, D); }
116expr(A) ::= expr(B) LSL_SUBTRACT(C) expr(D). { A = addOperation(param, B, C, D); } 116expr(A) ::= expr(B) LSL_SUBTRACT(C) expr(D). { A = addOperation(compiler, B, C, D); }
117%left LSL_DIVIDE LSL_MODULO LSL_MULTIPLY LSL_DOT_PRODUCT LSL_CROSS_PRODUCT. 117%left LSL_DIVIDE LSL_MODULO LSL_MULTIPLY LSL_DOT_PRODUCT LSL_CROSS_PRODUCT.
118expr(A) ::= expr(B) LSL_MULTIPLY(C) expr(D). { A = addOperation(param, B, C, D); } 118expr(A) ::= expr(B) LSL_MULTIPLY(C) expr(D). { A = addOperation(compiler, B, C, D); }
119expr(A) ::= expr(B) LSL_MODULO(C) expr(D). { A = addOperation(param, B, C, D); } 119expr(A) ::= expr(B) LSL_MODULO(C) expr(D). { A = addOperation(compiler, B, C, D); }
120expr(A) ::= expr(B) LSL_DIVIDE(C) expr(D). { A = addOperation(param, B, C, D); } 120expr(A) ::= expr(B) LSL_DIVIDE(C) expr(D). { A = addOperation(compiler, B, C, D); }
121 121
122%right LSL_BIT_NOT LSL_BOOL_NOT LSL_NEGATION. 122%right LSL_BIT_NOT LSL_BOOL_NOT LSL_NEGATION.
123expr(A) ::= LSL_BIT_NOT(B) expr(C). { A = addOperation(param, NULL, B, C); } 123expr(A) ::= LSL_BIT_NOT(B) expr(C). { A = addOperation(compiler, NULL, B, C); }
124expr(A) ::= LSL_BOOL_NOT(B) expr(C). { A = addOperation(param, NULL, B, C); } 124expr(A) ::= LSL_BOOL_NOT(B) expr(C). { A = addOperation(compiler, NULL, B, C); }
125expr(A) ::= LSL_SUBTRACT(B) expr(C). [LSL_NEGATION] { A = addOperation(param, NULL, B, C); } 125expr(A) ::= LSL_SUBTRACT(B) expr(C). [LSL_NEGATION] { A = addOperation(compiler, NULL, B, C); }
126 126
127// Types, typecasts, and expression reordering. 127// Types, typecasts, and expression reordering.
128 128
@@ -162,8 +162,8 @@ expr ::= identifier LSL_ASSIGNMENT_DIVIDE expr.
162expr ::= identifier LSL_ASSIGNMENT_PLAIN expr. 162expr ::= identifier LSL_ASSIGNMENT_PLAIN expr.
163 163
164// Hmm think this can have commas seperating the assignment parts. 164// Hmm think this can have commas seperating the assignment parts.
165statement(A) ::= type(B) identifier(C) LSL_ASSIGNMENT_PLAIN(D) expr(E) LSL_STATEMENT(F). { A = addStatement(F, LSL_IDENTIFIER, addVariable(param, B, C, D, E)); } 165statement(A) ::= type(B) identifier(C) LSL_ASSIGNMENT_PLAIN(D) expr(E) LSL_STATEMENT(F). { A = addStatement(F, LSL_IDENTIFIER, addVariable(compiler, B, C, D, E)); }
166statement(A) ::= type(B) identifier(C) LSL_STATEMENT(F). { A = addStatement(F, LSL_IDENTIFIER, addVariable(param, B, C, NULL, NULL)); } 166statement(A) ::= type(B) identifier(C) LSL_STATEMENT(F). { A = addStatement(F, LSL_IDENTIFIER, addVariable(compiler, B, C, NULL, NULL)); }
167 167
168%right LSL_DOT LSL_IDENTIFIER. 168%right LSL_DOT LSL_IDENTIFIER.
169identifier ::= identifier LSL_DOT LSL_IDENTIFIER. 169identifier ::= identifier LSL_DOT LSL_IDENTIFIER.
@@ -200,28 +200,28 @@ expr ::= LSL_ANGLE_OPEN expr LSL_COMMA expr LSL_COMMA expr LSL_ANGLE_CLOSE. [L
200 200
201%parse_accept 201%parse_accept
202{ 202{
203 gameGlobals *game = param->game; 203 gameGlobals *game = compiler->game;
204 204
205 PI("Parsing complete."); 205 PI("Parsing complete.");
206} 206}
207 207
208%parse_failure 208%parse_failure
209{ 209{
210 gameGlobals *game = param->game; 210 gameGlobals *game = compiler->game;
211 211
212 PE("Giving up. Parser is hopelessly lost!"); 212 PE("Giving up. Parser is hopelessly lost!");
213} 213}
214 214
215%stack_overflow 215%stack_overflow
216{ 216{
217 gameGlobals *game = param->game; 217 gameGlobals *game = compiler->game;
218 218
219 PE("Giving up. Parser stack overflow @ line %04d column %04d.", yypMinor->yy0->line, yypMinor->yy0->column); // Gotta love consistancy, if it ever happens. 219 PE("Giving up. Parser stack overflow @ line %04d column %04d.", yypMinor->yy0->line, yypMinor->yy0->column); // Gotta love consistancy, if it ever happens.
220} 220}
221 221
222%syntax_error 222%syntax_error
223{ 223{
224 gameGlobals *game = param->game; 224 gameGlobals *game = compiler->game;
225 225
226 PE("Syntax error @ line %04d column %04d.", yyminor.yy0->line, yyminor.yy0->column); 226 PE("Syntax error @ line %04d column %04d.", yyminor.yy0->line, yyminor.yy0->column);
227} 227}
diff --git a/LuaSL/src/LuaSL_lexer.l b/LuaSL/src/LuaSL_lexer.l
index 8a5e8ad..591dfdc 100644
--- a/LuaSL/src/LuaSL_lexer.l
+++ b/LuaSL/src/LuaSL_lexer.l
@@ -3,7 +3,7 @@
3#define excludeLexer 3#define excludeLexer
4#include "LuaSL.h" 4#include "LuaSL.h"
5 5
6int common(YYSTYPE *lval, char *text, LuaSL_yyparseParam *param, boolean checkIgnorable, int type); 6int common(YYSTYPE *lval, char *text, LuaSL_compiler *compiler, boolean checkIgnorable, int type);
7 7
8%} 8%}
9 9
@@ -12,7 +12,7 @@ int common(YYSTYPE *lval, char *text, LuaSL_yyparseParam *param, boolean checkIg
12%option noreject noyymore 12%option noreject noyymore
13%option backup debug perf-report perf-report verbose warn 13%option backup debug perf-report perf-report verbose warn
14%option align full 14%option align full
15%option extra-type="LuaSL_yyparseParam *" 15%option extra-type="LuaSL_compiler *"
16 16
17HEX [[:xdigit:]] 17HEX [[:xdigit:]]
18DECIMAL [[:digit:]] 18DECIMAL [[:digit:]]
@@ -113,7 +113,7 @@ STRING \"(\\.|[^\\"\n])*\"
113 113
114%% 114%%
115 115
116int common(YYSTYPE *lval, char *text, LuaSL_yyparseParam *param, boolean checkIgnorable, int type) 116int common(YYSTYPE *lval, char *text, LuaSL_compiler *compiler, boolean checkIgnorable, int type)
117{ 117{
118 char *p; 118 char *p;
119 119
@@ -121,33 +121,33 @@ int common(YYSTYPE *lval, char *text, LuaSL_yyparseParam *param, boolean checkIg
121 { 121 {
122 if ('\n' == *p) 122 if ('\n' == *p)
123 { 123 {
124 param->line++; 124 compiler->line++;
125 param->column = 1; 125 compiler->column = 1;
126 } 126 }
127 else 127 else
128 param->column++; 128 compiler->column++;
129 } 129 }
130 lval->token = tokens[type - lowestToken]; 130 lval->token = tokens[type - lowestToken];
131 lval->line = param->line; 131 lval->line = compiler->line;
132 lval->column = param->column; 132 lval->column = compiler->column;
133 133
134 if (checkIgnorable) 134 if (checkIgnorable)
135 { 135 {
136 lval->ignorableText = param->ignorableText; 136 lval->ignorableText = compiler->ignorableText;
137 param->ignorableText = NULL; 137 compiler->ignorableText = NULL;
138 } 138 }
139 else 139 else
140 { 140 {
141 if (param->ignorableText) 141 if (compiler->ignorableText)
142 { 142 {
143 int lenI = strlen(param->ignorableText); 143 int lenI = strlen(compiler->ignorableText);
144 int lenT = strlen(text); 144 int lenT = strlen(text);
145 145
146 param->ignorableText = realloc(param->ignorableText, lenI + lenT + 1); 146 compiler->ignorableText = realloc(compiler->ignorableText, lenI + lenT + 1);
147 sprintf(&(param->ignorableText[lenI]), "%s", text); 147 sprintf(&(compiler->ignorableText[lenI]), "%s", text);
148 } 148 }
149 else 149 else
150 param->ignorableText = strdup(text); 150 compiler->ignorableText = strdup(text);
151 } 151 }
152 152
153 return type; 153 return type;