diff options
author | David Walter Seikel | 2012-02-01 23:37:17 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-02-01 23:37:17 +1000 |
commit | d094c72e1006346adf1c60760fe79e248f6f1d96 (patch) | |
tree | b028a0cddc9a796c9815f0cd9eb4c03a7d837e9b | |
parent | Parse and output lists. (diff) | |
download | SledjHamr-d094c72e1006346adf1c60760fe79e248f6f1d96.zip SledjHamr-d094c72e1006346adf1c60760fe79e248f6f1d96.tar.gz SledjHamr-d094c72e1006346adf1c60760fe79e248f6f1d96.tar.bz2 SledjHamr-d094c72e1006346adf1c60760fe79e248f6f1d96.tar.xz |
Parse and output for statements. Also, take care of ignorables on left parens of flow controls.
-rw-r--r-- | LuaSL/src/LuaSL_LSL_tree.h | 3 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_compile.c | 61 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_lemon_yaccer.y | 4 |
3 files changed, 64 insertions, 4 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index 33f860c..cff2bab 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h | |||
@@ -219,7 +219,7 @@ struct _LSL_Statement | |||
219 | Eina_Clist statement; // For block statement lists, this is the entry. | 219 | Eina_Clist statement; // For block statement lists, this is the entry. |
220 | LSL_Identifier *identifier; | 220 | LSL_Identifier *identifier; |
221 | LSL_Parenthesis *parenthesis; | 221 | LSL_Parenthesis *parenthesis; |
222 | LSL_Leaf *expressions; // A for statement will have three expressions, everything else has zero or one. | 222 | LSL_Leaf *expressions; // A for statement will have three expressions, and two semicolons, everything else has zero or one. |
223 | LSL_Block *block; | 223 | LSL_Block *block; |
224 | LSL_Statement *elseBlock; | 224 | LSL_Statement *elseBlock; |
225 | LSL_Type type; // Expression type. | 225 | LSL_Type type; // Expression type. |
@@ -395,6 +395,7 @@ typedef struct | |||
395 | void burnLeaf(void *data); | 395 | void burnLeaf(void *data); |
396 | LSL_Leaf *addBlock(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right); | 396 | LSL_Leaf *addBlock(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right); |
397 | LSL_Leaf *addCrement(LuaSL_compiler *compiler, LSL_Leaf *variable, LSL_Leaf *crement); | 397 | LSL_Leaf *addCrement(LuaSL_compiler *compiler, LSL_Leaf *variable, LSL_Leaf *crement); |
398 | LSL_Leaf *addFor(LuaSL_compiler *compiler, LSL_Leaf *lval, LSL_Leaf *flow, LSL_Leaf *left, LSL_Leaf *expr0, LSL_Leaf *stat0, LSL_Leaf *expr1, LSL_Leaf *stat1, LSL_Leaf *expr2, LSL_Leaf *right, LSL_Leaf *block); | ||
398 | LSL_Leaf *addFunction(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close); | 399 | LSL_Leaf *addFunction(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close); |
399 | LSL_Leaf *addFunctionBody(LuaSL_compiler *compiler, LSL_Leaf *function, LSL_Leaf *block); | 400 | LSL_Leaf *addFunctionBody(LuaSL_compiler *compiler, LSL_Leaf *function, LSL_Leaf *block); |
400 | LSL_Leaf *addFunctionCall(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close); | 401 | LSL_Leaf *addFunctionCall(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close); |
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index 0183599..c61f900 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c | |||
@@ -742,6 +742,23 @@ LSL_Leaf *addIfElse(LuaSL_compiler *compiler, LSL_Leaf *ifBlock, LSL_Leaf *elseB | |||
742 | return ifBlock; | 742 | return ifBlock; |
743 | } | 743 | } |
744 | 744 | ||
745 | LSL_Leaf *addFor(LuaSL_compiler *compiler, LSL_Leaf *lval, LSL_Leaf *flow, LSL_Leaf *left, LSL_Leaf *expr0, LSL_Leaf *stat0, LSL_Leaf *expr1, LSL_Leaf *stat1, LSL_Leaf *expr2, LSL_Leaf *right, LSL_Leaf *block) | ||
746 | { | ||
747 | LSL_Leaf **exprs = calloc(5, sizeof(LSL_Leaf *)); | ||
748 | |||
749 | if (exprs) | ||
750 | { | ||
751 | lval = addStatement(compiler, lval, flow, left, expr0, right, block, NULL); | ||
752 | exprs[0] = expr0; | ||
753 | exprs[1] = stat0; | ||
754 | exprs[2] = expr1; | ||
755 | exprs[3] = stat1; | ||
756 | exprs[4] = expr2; | ||
757 | lval->value.statementValue->expressions = (LSL_Leaf *) exprs; | ||
758 | } | ||
759 | return lval; | ||
760 | } | ||
761 | |||
745 | LSL_Leaf *addStatement(LuaSL_compiler *compiler, LSL_Leaf *lval, LSL_Leaf *flow, LSL_Leaf *left, LSL_Leaf *expr, LSL_Leaf *right, LSL_Leaf *block, LSL_Leaf *identifier) | 762 | LSL_Leaf *addStatement(LuaSL_compiler *compiler, LSL_Leaf *lval, LSL_Leaf *flow, LSL_Leaf *left, LSL_Leaf *expr, LSL_Leaf *right, LSL_Leaf *block, LSL_Leaf *identifier) |
746 | { | 763 | { |
747 | gameGlobals *game = compiler->game; | 764 | gameGlobals *game = compiler->game; |
@@ -784,6 +801,7 @@ LSL_Leaf *addStatement(LuaSL_compiler *compiler, LSL_Leaf *lval, LSL_Leaf *flow, | |||
784 | } | 801 | } |
785 | case LSL_FOR : | 802 | case LSL_FOR : |
786 | { | 803 | { |
804 | justOne = TRUE; | ||
787 | break; | 805 | break; |
788 | } | 806 | } |
789 | case LSL_IF : | 807 | case LSL_IF : |
@@ -861,6 +879,21 @@ LSL_Leaf *addStatement(LuaSL_compiler *compiler, LSL_Leaf *lval, LSL_Leaf *flow, | |||
861 | #endif | 879 | #endif |
862 | lval->value.statementValue = stat; | 880 | lval->value.statementValue = stat; |
863 | } | 881 | } |
882 | |||
883 | #if LUASL_DIFF_CHECK | ||
884 | if (left) | ||
885 | { | ||
886 | if (NULL == stat->ignorable) | ||
887 | stat->ignorable = calloc(3, sizeof(Eina_Strbuf *)); | ||
888 | else | ||
889 | stat->ignorable = realloc(stat->ignorable, 3 * sizeof(Eina_Strbuf *)); | ||
890 | if (stat->ignorable) | ||
891 | { | ||
892 | stat->ignorable[2] = left->ignorable; | ||
893 | left->ignorable = NULL; | ||
894 | } | ||
895 | } | ||
896 | #endif | ||
864 | } | 897 | } |
865 | 898 | ||
866 | return lval; | 899 | return lval; |
@@ -1427,6 +1460,10 @@ static void outputRawStatement(FILE *file, outputMode mode, LSL_Statement *state | |||
1427 | case LSL_FOR : | 1460 | case LSL_FOR : |
1428 | { | 1461 | { |
1429 | isBlock = TRUE; | 1462 | isBlock = TRUE; |
1463 | #if LUASL_DIFF_CHECK | ||
1464 | if ((statement->ignorable) && (statement->ignorable[1])) | ||
1465 | fwrite(eina_strbuf_string_get(statement->ignorable[1]), 1, eina_strbuf_length_get(statement->ignorable[1]), file); | ||
1466 | #endif | ||
1430 | fprintf(file, "%s", tokens[statement->type - lowestToken]->toKen); | 1467 | fprintf(file, "%s", tokens[statement->type - lowestToken]->toKen); |
1431 | break; | 1468 | break; |
1432 | } | 1469 | } |
@@ -1506,7 +1543,29 @@ static void outputRawStatement(FILE *file, outputMode mode, LSL_Statement *state | |||
1506 | } | 1543 | } |
1507 | } | 1544 | } |
1508 | 1545 | ||
1509 | if (statement->parenthesis) | 1546 | #if LUASL_DIFF_CHECK |
1547 | if ((statement->ignorable) && (statement->ignorable[2])) | ||
1548 | fwrite(eina_strbuf_string_get(statement->ignorable[2]), 1, eina_strbuf_length_get(statement->ignorable[2]), file); | ||
1549 | #endif | ||
1550 | if (LSL_FOR == statement->type) | ||
1551 | { | ||
1552 | LSL_Leaf **exprs = (LSL_Leaf **) statement->expressions; | ||
1553 | int i; | ||
1554 | |||
1555 | fprintf(file, "("); | ||
1556 | for (i = 0; i < 5; i++) | ||
1557 | { | ||
1558 | outputLeaf(file, mode, exprs[i]); | ||
1559 | if (i % 2) | ||
1560 | fprintf(file, ";"); | ||
1561 | } | ||
1562 | #if LUASL_DIFF_CHECK | ||
1563 | fprintf(file, "%s)", eina_strbuf_string_get(statement->parenthesis->rightIgnorable)); | ||
1564 | #else | ||
1565 | fprintf(file, ")"); | ||
1566 | #endif | ||
1567 | } | ||
1568 | else if (statement->parenthesis) | ||
1510 | outputRawParenthesisToken(file, mode, statement->parenthesis, ""); | 1569 | outputRawParenthesisToken(file, mode, statement->parenthesis, ""); |
1511 | else | 1570 | else |
1512 | outputLeaf(file, mode, statement->expressions); | 1571 | outputLeaf(file, mode, statement->expressions); |
diff --git a/LuaSL/src/LuaSL_lemon_yaccer.y b/LuaSL/src/LuaSL_lemon_yaccer.y index 1d28ec5..ba32692 100644 --- a/LuaSL/src/LuaSL_lemon_yaccer.y +++ b/LuaSL/src/LuaSL_lemon_yaccer.y | |||
@@ -68,8 +68,8 @@ statementList(A) ::= . { A = collectStatements(compiler, NULL, NULL); } | |||
68 | %nonassoc LSL_DO LSL_FOR LSL_IF LSL_JUMP LSL_RETURN LSL_STATE_CHANGE LSL_WHILE. | 68 | %nonassoc LSL_DO LSL_FOR LSL_IF LSL_JUMP LSL_RETURN LSL_STATE_CHANGE LSL_WHILE. |
69 | %nonassoc LSL_ELSE. | 69 | %nonassoc LSL_ELSE. |
70 | statement(A) ::= LSL_DO(F) block(B) LSL_WHILE(W) LSL_PARENTHESIS_OPEN(L) expr(E) LSL_PARENTHESIS_CLOSE(R) LSL_STATEMENT(S). { A = addStatement(compiler, S, F, L, E, R, B, W); } | 70 | statement(A) ::= LSL_DO(F) block(B) LSL_WHILE(W) LSL_PARENTHESIS_OPEN(L) expr(E) LSL_PARENTHESIS_CLOSE(R) LSL_STATEMENT(S). { A = addStatement(compiler, S, F, L, E, R, B, W); } |
71 | statement(A) ::= LSL_FOR(F) LSL_PARENTHESIS_OPEN(L) expr(E0) LSL_STATEMENT(S0) expr(E1) LSL_STATEMENT(S1) expr(E2) LSL_PARENTHESIS_CLOSE(R) block(B). { A = addStatement(compiler, NULL, F, L, E1, R, B, NULL); } // three expressions, two semi colons | 71 | statement(A) ::= LSL_FOR(F) LSL_PARENTHESIS_OPEN(L) expr(E0) LSL_STATEMENT(S0) expr(E1) LSL_STATEMENT(S1) expr(E2) LSL_PARENTHESIS_CLOSE(R) block(B). { A = addFor(compiler, NULL, F, L, E0, S0, E1, S1, E2, R, B); } |
72 | statement(A) ::= LSL_FOR(F) LSL_PARENTHESIS_OPEN(L) expr(E0) LSL_STATEMENT(S0) expr(E1) LSL_STATEMENT(S1) expr(E2) LSL_PARENTHESIS_CLOSE(R) statement(S). { A = addStatement(compiler, S, F, L, E1, R, NULL, NULL); } // three expressions, two semi colons | 72 | statement(A) ::= LSL_FOR(F) LSL_PARENTHESIS_OPEN(L) expr(E0) LSL_STATEMENT(S0) expr(E1) LSL_STATEMENT(S1) expr(E2) LSL_PARENTHESIS_CLOSE(R) statement(S). { A = addFor(compiler, S, F, L, E0, S0, E1, S1, E2, R, NULL); } |
73 | 73 | ||
74 | statement(A) ::= ifBlock(B). { A = B; } | 74 | statement(A) ::= ifBlock(B). { A = B; } |
75 | ifBlock(A) ::= ifBlock(B) elseBlock(E). { A = addIfElse(compiler, B, E); } | 75 | ifBlock(A) ::= ifBlock(B) elseBlock(E). { A = addIfElse(compiler, B, E); } |