aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.h4
-rw-r--r--LuaSL/src/LuaSL_compile.c49
-rw-r--r--LuaSL/src/LuaSL_lemon_yaccer.y7
3 files changed, 55 insertions, 5 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h
index c22ceae..41435ff 100644
--- a/LuaSL/src/LuaSL_LSL_tree.h
+++ b/LuaSL/src/LuaSL_LSL_tree.h
@@ -191,6 +191,7 @@ struct _LSL_Identifier // For variables and function parameters.
191 191
192struct _LSL_Statement 192struct _LSL_Statement
193{ 193{
194 Eina_Clist statement;
194 LSL_Leaf *expressions; // For things like a for statement, might hold three expressions. 195 LSL_Leaf *expressions; // For things like a for statement, might hold three expressions.
195 LSL_Type type; // Expression type. 196 LSL_Type type; // Expression type.
196}; 197};
@@ -198,7 +199,7 @@ struct _LSL_Statement
198struct _LSL_Block 199struct _LSL_Block
199{ 200{
200 LSL_Block *outerBlock; 201 LSL_Block *outerBlock;
201// Eina_Hash *statements; // Probably should be some sort of eina list. 202 Eina_Clist statements;
202 Eina_Hash *variables; // Those variables in this scope. 203 Eina_Hash *variables; // Those variables in this scope.
203 LSL_Function *function; // A pointer to the function if this block is a function. 204 LSL_Function *function; // A pointer to the function if this block is a function.
204}; 205};
@@ -334,6 +335,7 @@ LSL_Leaf *addVariable(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identi
334void beginBlock(LuaSL_compiler *compiler, LSL_Leaf *block); 335void beginBlock(LuaSL_compiler *compiler, LSL_Leaf *block);
335LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier); 336LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier);
336LSL_Leaf *collectParameters(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *comma, LSL_Leaf *newParam); 337LSL_Leaf *collectParameters(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *comma, LSL_Leaf *newParam);
338LSL_Leaf *collectStatements(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *newStatement);
337void endBlock(LuaSL_compiler *compiler, LSL_Leaf *block); 339void endBlock(LuaSL_compiler *compiler, LSL_Leaf *block);
338 340
339void *ParseAlloc(void *(*mallocProc)(size_t)); 341void *ParseAlloc(void *(*mallocProc)(size_t));
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c
index 29c45f3..b1efddd 100644
--- a/LuaSL/src/LuaSL_compile.c
+++ b/LuaSL/src/LuaSL_compile.c
@@ -7,6 +7,7 @@ static LSL_Leaf *evaluateNoToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *ri
7static LSL_Leaf *evaluateOperationToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); 7static LSL_Leaf *evaluateOperationToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right);
8static LSL_Leaf *eveluateParenthesisToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); 8static LSL_Leaf *eveluateParenthesisToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right);
9static LSL_Leaf *evaluateStatementToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); 9static LSL_Leaf *evaluateStatementToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right);
10static void outputBlockToken(FILE *file, outputMode mode, LSL_Leaf *content);
10static void outputFloatToken(FILE *file, outputMode mode, LSL_Leaf *content); 11static void outputFloatToken(FILE *file, outputMode mode, LSL_Leaf *content);
11static void outputFunctionToken(FILE *file, outputMode mode, LSL_Leaf *content); 12static void outputFunctionToken(FILE *file, outputMode mode, LSL_Leaf *content);
12static void outputIntegerToken(FILE *file, outputMode mode, LSL_Leaf *content); 13static void outputIntegerToken(FILE *file, outputMode mode, LSL_Leaf *content);
@@ -129,7 +130,7 @@ LSL_Token LSL_Tokens[] =
129 {LSL_STATEMENT, ST_NONE, ";", LSL_NOIGNORE, outputStatementToken, evaluateStatementToken}, 130 {LSL_STATEMENT, ST_NONE, ";", LSL_NOIGNORE, outputStatementToken, evaluateStatementToken},
130 131
131 {LSL_BLOCK_CLOSE, ST_NONE, "}", LSL_NONE, NULL, NULL}, 132 {LSL_BLOCK_CLOSE, ST_NONE, "}", LSL_NONE, NULL, NULL},
132 {LSL_BLOCK_OPEN, ST_NONE, "{", LSL_NONE, NULL, NULL}, 133 {LSL_BLOCK_OPEN, ST_NONE, "{", LSL_NONE, outputBlockToken, NULL},
133 {LSL_PARAMETER, ST_NONE, "parameter", LSL_NONE, outputIdentifierToken, NULL}, 134 {LSL_PARAMETER, ST_NONE, "parameter", LSL_NONE, outputIdentifierToken, NULL},
134 {LSL_PARAMETER_LIST, ST_NONE, "plist", LSL_NONE, outputParameterListToken, NULL}, 135 {LSL_PARAMETER_LIST, ST_NONE, "plist", LSL_NONE, outputParameterListToken, NULL},
135 {LSL_FUNCTION, ST_NONE, "function", LSL_NONE, outputFunctionToken, NULL}, 136 {LSL_FUNCTION, ST_NONE, "function", LSL_NONE, outputFunctionToken, NULL},
@@ -547,6 +548,7 @@ LSL_Leaf *addStatement(LSL_Leaf *lval, LSL_Type type, LSL_Leaf *expr)
547 { 548 {
548 stat->type = type; 549 stat->type = type;
549 stat->expressions = expr; 550 stat->expressions = expr;
551 eina_clist_element_init(&(stat->statement));
550 if (lval) 552 if (lval)
551 lval->value.statementValue = stat; 553 lval->value.statementValue = stat;
552 } 554 }
@@ -554,6 +556,31 @@ LSL_Leaf *addStatement(LSL_Leaf *lval, LSL_Type type, LSL_Leaf *expr)
554 return lval; 556 return lval;
555} 557}
556 558
559LSL_Leaf *collectStatements(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *statement)
560{
561 if (NULL == list)
562 {
563 list = newLeaf(LSL_BLOCK_OPEN, NULL, NULL);
564 if (list)
565 {
566 list->value.blockValue = compiler->currentBlock; // Maybe NULL.
567 }
568 }
569
570 if (list)
571 {
572 if (statement)
573 {
574 if (list->value.blockValue)
575 {
576 eina_clist_add_tail(&(list->value.blockValue->statements), &(statement->value.statementValue->statement));
577 }
578 }
579 }
580
581 return list;
582}
583
557LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf *expr) 584LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf *expr)
558{ 585{
559 addParenthesis(lval, expr, LSL_TYPECAST_OPEN, rval); 586 addParenthesis(lval, expr, LSL_TYPECAST_OPEN, rval);
@@ -604,6 +631,7 @@ void beginBlock(LuaSL_compiler *compiler, LSL_Leaf *block)
604 631
605 if (blok) 632 if (blok)
606 { 633 {
634 eina_clist_init(&(blok->statements));
607 blok->variables = eina_hash_stringshared_new(burnLeaf); 635 blok->variables = eina_hash_stringshared_new(burnLeaf);
608 block->value.blockValue = blok; 636 block->value.blockValue = blok;
609 blok->outerBlock = compiler->currentBlock; 637 blok->outerBlock = compiler->currentBlock;
@@ -933,6 +961,25 @@ static void outputLeaf(FILE *file, outputMode mode, LSL_Leaf *leaf)
933 } 961 }
934} 962}
935 963
964static void outputBlockToken(FILE *file, outputMode mode, LSL_Leaf *content)
965{
966 if (content)
967 {
968 fprintf(file, "\n{\n");
969 if (content->value.blockValue)
970 {
971 LSL_Statement *statement = NULL;
972
973 EINA_CLIST_FOR_EACH_ENTRY(statement, &(content->value.blockValue->statements), LSL_Statement, statement)
974 {
975 outputLeaf(file, mode, statement->expressions);
976 fprintf(file, ";\n");
977 }
978 }
979 fprintf(file, "}\n");
980 }
981}
982
936static void outputFloatToken(FILE *file, outputMode mode, LSL_Leaf *content) 983static void outputFloatToken(FILE *file, outputMode mode, LSL_Leaf *content)
937{ 984{
938 if (content) 985 if (content)
diff --git a/LuaSL/src/LuaSL_lemon_yaccer.y b/LuaSL/src/LuaSL_lemon_yaccer.y
index 54af56d..881bdaf 100644
--- a/LuaSL/src/LuaSL_lemon_yaccer.y
+++ b/LuaSL/src/LuaSL_lemon_yaccer.y
@@ -54,13 +54,14 @@ function(A) ::= type(B) LSL_IDENTIFIER(C) LSL_PARENTHESIS_OPEN(D) parameterList(
54 54
55block(A) ::= funcBlock(B). { A = B; } 55block(A) ::= funcBlock(B). { A = B; }
56block(A) ::= statement(B). { A = B; } 56block(A) ::= statement(B). { A = B; }
57funcBlock ::= LSL_BLOCK_OPEN statementList LSL_BLOCK_CLOSE. 57funcBlock(A) ::= LSL_BLOCK_OPEN statementList(B) LSL_BLOCK_CLOSE. { A = B; }
58 58
59// Various forms of statement. 59// Various forms of statement.
60 60
61%nonassoc LSL_STATEMENT. 61%nonassoc LSL_STATEMENT.
62statementList ::= statementList statement. 62statementList(A) ::= statementList(B) statement(C). { A = collectStatements(compiler, B, C); }
63statementList ::= . 63//statementList(A) ::= statement(C). { A = collectStatements(compiler, NULL, C); }
64statementList(A) ::= . { A = collectStatements(compiler, NULL, NULL); }
64 65
65%nonassoc LSL_DO LSL_FOR LSL_ELSE_IF LSL_IF LSL_JUMP LSL_RETURN LSL_STATE_CHANGE LSL_WHILE. 66%nonassoc LSL_DO LSL_FOR LSL_ELSE_IF LSL_IF LSL_JUMP LSL_RETURN LSL_STATE_CHANGE LSL_WHILE.
66%nonassoc LSL_ELSE. 67%nonassoc LSL_ELSE.