diff options
author | David Walter Seikel | 2012-01-17 10:47:26 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-17 10:47:26 +1000 |
commit | d3356bf6e8eeadd3afbd9db2e59621d50dbefb63 (patch) | |
tree | 5e52784bca7368e07e8c49cf094ccdcce2332149 | |
parent | Parser now understands state, function, and variable derlarations. Including... (diff) | |
download | SledjHamr-d3356bf6e8eeadd3afbd9db2e59621d50dbefb63.zip SledjHamr-d3356bf6e8eeadd3afbd9db2e59621d50dbefb63.tar.gz SledjHamr-d3356bf6e8eeadd3afbd9db2e59621d50dbefb63.tar.bz2 SledjHamr-d3356bf6e8eeadd3afbd9db2e59621d50dbefb63.tar.xz |
Actually make state work. lol
-rw-r--r-- | LuaSL/src/LuaSL_LSL_tree.c | 24 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_LSL_tree.h | 4 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_lemon_yaccer.y | 4 |
3 files changed, 23 insertions, 9 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.c b/LuaSL/src/LuaSL_LSL_tree.c index e37f794..af6e02f 100644 --- a/LuaSL/src/LuaSL_LSL_tree.c +++ b/LuaSL/src/LuaSL_LSL_tree.c | |||
@@ -15,6 +15,7 @@ static void outputIntegerToken(FILE *file, LSL_Leaf *content); | |||
15 | static void outputParameterToken(FILE *file, LSL_Leaf *content); | 15 | static void outputParameterToken(FILE *file, LSL_Leaf *content); |
16 | static void outputParameterListToken(FILE *file, LSL_Leaf *content); | 16 | static void outputParameterListToken(FILE *file, LSL_Leaf *content); |
17 | static void outputParenthesisToken(FILE *file, LSL_Leaf *content); | 17 | static void outputParenthesisToken(FILE *file, LSL_Leaf *content); |
18 | static void outputStateToken(FILE *file, LSL_Leaf *content); | ||
18 | static void outputStatementToken(FILE *file, LSL_Leaf *content); | 19 | static void outputStatementToken(FILE *file, LSL_Leaf *content); |
19 | static void outputVariableToken(FILE *file, LSL_Leaf *content); | 20 | static void outputVariableToken(FILE *file, LSL_Leaf *content); |
20 | 21 | ||
@@ -119,7 +120,7 @@ LSL_Token LSL_Tokens[] = | |||
119 | {LSL_PARAMETER, ST_NONE, "parameter", LSL_NONE, outputParameterToken, NULL, NULL}, | 120 | {LSL_PARAMETER, ST_NONE, "parameter", LSL_NONE, outputParameterToken, NULL, NULL}, |
120 | {LSL_PARAMETER_LIST, ST_NONE, "plist", LSL_NONE, outputParameterListToken, NULL, NULL}, | 121 | {LSL_PARAMETER_LIST, ST_NONE, "plist", LSL_NONE, outputParameterListToken, NULL, NULL}, |
121 | {LSL_FUNCTION, ST_NONE, "function", LSL_NONE, outputFunctionToken, NULL, NULL}, | 122 | {LSL_FUNCTION, ST_NONE, "function", LSL_NONE, outputFunctionToken, NULL, NULL}, |
122 | {LSL_STATE, ST_NONE, "state", LSL_NONE, NULL, NULL, NULL}, | 123 | {LSL_STATE, ST_NONE, "state", LSL_NONE, outputStateToken, NULL, NULL}, |
123 | {LSL_SCRIPT, ST_NONE, "", LSL_NONE, NULL, NULL, NULL}, | 124 | {LSL_SCRIPT, ST_NONE, "", LSL_NONE, NULL, NULL, NULL}, |
124 | 125 | ||
125 | {LSL_UNKNOWN, ST_NONE, "unknown", LSL_NONE, NULL, NULL, NULL}, | 126 | {LSL_UNKNOWN, ST_NONE, "unknown", LSL_NONE, NULL, NULL, NULL}, |
@@ -362,19 +363,21 @@ LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf | |||
362 | return lval; | 363 | return lval; |
363 | } | 364 | } |
364 | 365 | ||
365 | LSL_Leaf *addState(LuaSL_yyparseParam *param, char *name, LSL_Leaf *state) | 366 | LSL_Leaf *addState(LuaSL_yyparseParam *param, LSL_Leaf *identifier, LSL_Leaf *block) |
366 | { | 367 | { |
367 | LSL_State *result = calloc(1, sizeof(LSL_State)); | 368 | LSL_State *result = calloc(1, sizeof(LSL_State)); |
368 | 369 | ||
369 | if (result) | 370 | if ((identifier) && (result)) |
370 | { | 371 | { |
371 | result->name = name; | 372 | result->name = identifier->value.stringValue; |
373 | result->block = block; | ||
374 | identifier->value.stateValue = result; | ||
372 | param->script.scount++; | 375 | param->script.scount++; |
373 | param->script.states = realloc(param->script.states, param->script.scount * sizeof(LSL_State *)); | 376 | param->script.states = realloc(param->script.states, param->script.scount * sizeof(LSL_State *)); |
374 | param->script.states[param->script.scount - 1] = result; | 377 | param->script.states[param->script.scount - 1] = result; |
375 | } | 378 | } |
376 | 379 | ||
377 | return state; | 380 | return identifier; |
378 | } | 381 | } |
379 | 382 | ||
380 | LSL_Leaf *addStatement(LSL_Leaf *lval, LSL_Type type, LSL_Leaf *expr) | 383 | LSL_Leaf *addStatement(LSL_Leaf *lval, LSL_Type type, LSL_Leaf *expr) |
@@ -829,6 +832,17 @@ static void outputParenthesisToken(FILE *file, LSL_Leaf *content) | |||
829 | } | 832 | } |
830 | } | 833 | } |
831 | 834 | ||
835 | static void outputStateToken(FILE *file, LSL_Leaf *content) | ||
836 | { | ||
837 | if (content) | ||
838 | { | ||
839 | LSL_State *state = content->value.stateValue; | ||
840 | |||
841 | fprintf(file, "%s", state->name); | ||
842 | outputLeaf(file, state->block); | ||
843 | } | ||
844 | } | ||
845 | |||
832 | static void outputStatementToken(FILE *file, LSL_Leaf *content) | 846 | static void outputStatementToken(FILE *file, LSL_Leaf *content) |
833 | { | 847 | { |
834 | if (content) | 848 | if (content) |
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index 4113454..e9fddb7 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h | |||
@@ -254,6 +254,7 @@ struct _LSL_Function | |||
254 | struct _LSL_State | 254 | struct _LSL_State |
255 | { | 255 | { |
256 | char *name; | 256 | char *name; |
257 | LSL_Leaf *block; | ||
257 | LSL_Function **handlers; | 258 | LSL_Function **handlers; |
258 | }; | 259 | }; |
259 | 260 | ||
@@ -282,7 +283,6 @@ typedef struct | |||
282 | LSL_Leaf *lval; | 283 | LSL_Leaf *lval; |
283 | int column, line; | 284 | int column, line; |
284 | LSL_Block *currentBlock; | 285 | LSL_Block *currentBlock; |
285 | LSL_Leaf *currentFunction; | ||
286 | } LuaSL_yyparseParam; | 286 | } LuaSL_yyparseParam; |
287 | 287 | ||
288 | 288 | ||
@@ -296,7 +296,7 @@ LSL_Leaf *addFunction(LuaSL_yyparseParam *param, LSL_Leaf *type, LSL_Leaf *ident | |||
296 | 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); |
297 | LSL_Leaf *addParameter(LuaSL_yyparseParam *param, LSL_Leaf *type, LSL_Leaf *newParam); | 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); | 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); | 299 | LSL_Leaf *addState(LuaSL_yyparseParam *param, LSL_Leaf *identifier, LSL_Leaf *block); |
300 | 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); |
301 | 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); | 302 | LSL_Leaf *addVariable(LuaSL_yyparseParam *param, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *assignment, LSL_Leaf *expr); |
diff --git a/LuaSL/src/LuaSL_lemon_yaccer.y b/LuaSL/src/LuaSL_lemon_yaccer.y index f79c228..f90b236 100644 --- a/LuaSL/src/LuaSL_lemon_yaccer.y +++ b/LuaSL/src/LuaSL_lemon_yaccer.y | |||
@@ -23,7 +23,7 @@ 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. |
26 | script ::= script state. | 26 | script ::= script state(A). { if (NULL != A) A->left = param->ast; param->ast = A; } |
27 | script ::= script function(A). { if (NULL != A) A->left = param->ast; param->ast = A; } | 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 ::= . |
@@ -32,7 +32,7 @@ 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(S) ::= LSL_IDENTIFIER(I) stateBlock(B). { S = addState(param, I->value.stringValue, B); } | 35 | state(S) ::= LSL_IDENTIFIER(I) stateBlock(B). { S = addState(param, I, B); } |
36 | 36 | ||
37 | // Function definitions. | 37 | // Function definitions. |
38 | 38 | ||