From 2b51cab943a6177bf0f1fd359242d03e44fe8046 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Wed, 1 Feb 2012 22:50:34 +1000 Subject: Parse and output lists. --- LuaSL/src/LuaSL_LSL_tree.h | 1 + LuaSL/src/LuaSL_compile.c | 39 +++++++++++++++++++++++++++++++++++++-- LuaSL/src/LuaSL_lemon_yaccer.y | 2 +- 3 files changed, 39 insertions(+), 3 deletions(-) (limited to 'LuaSL/src') diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index b5dff7a..33f860c 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h @@ -399,6 +399,7 @@ LSL_Leaf *addFunction(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identi LSL_Leaf *addFunctionBody(LuaSL_compiler *compiler, LSL_Leaf *function, LSL_Leaf *block); LSL_Leaf *addFunctionCall(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close); LSL_Leaf *addIfElse(LuaSL_compiler *compiler, LSL_Leaf *ifBlock, LSL_Leaf *elseBlock); +LSL_Leaf *addList(LSL_Leaf *left, LSL_Leaf *list, LSL_Leaf *right); LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right); LSL_Leaf *addParameter(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *newParam); LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval); diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index eada67f..0183599 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c @@ -13,6 +13,7 @@ static void outputFunctionToken(FILE *file, outputMode mode, LSL_Leaf *content); static void outputFunctionCallToken(FILE *file, outputMode mode, LSL_Leaf *content); static void outputIntegerToken(FILE *file, outputMode mode, LSL_Leaf *content); static void outputIdentifierToken(FILE *file, outputMode mode, LSL_Leaf *content); +static void outputListToken(FILE *file, outputMode mode, LSL_Leaf *content); static void outputParameterListToken(FILE *file, outputMode mode, LSL_Leaf *content); static void outputParenthesisToken(FILE *file, outputMode mode, LSL_Leaf *content); static void outputStateToken(FILE *file, outputMode mode, LSL_Leaf *content); @@ -101,7 +102,7 @@ LSL_Token LSL_Tokens[] = {LSL_FLOAT, ST_NONE, "float", LSL_NONE, outputFloatToken, evaluateFloatToken}, {LSL_INTEGER, ST_NONE, "integer", LSL_NONE, outputIntegerToken, evaluateIntegerToken}, {LSL_KEY, ST_NONE, "key", LSL_NONE, outputStringToken, NULL}, - {LSL_LIST, ST_NONE, "list", LSL_NONE, NULL, NULL}, + {LSL_LIST, ST_NONE, "list", LSL_NONE, outputListToken, NULL}, {LSL_ROTATION, ST_NONE, "rotation", LSL_NONE, NULL, NULL}, {LSL_STRING, ST_NONE, "string", LSL_NONE, outputStringToken, NULL}, {LSL_VECTOR, ST_NONE, "vector", LSL_NONE, NULL, NULL}, @@ -672,6 +673,14 @@ LSL_Leaf *addFunctionCall(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Le return identifier; } +LSL_Leaf *addList(LSL_Leaf *left, LSL_Leaf *list, LSL_Leaf *right) +{ + left = addParenthesis(left, list, LSL_LIST, right); + left->toKen = tokens[LSL_LIST - lowestToken]; + left->basicType = OT_list; + return left; +} + LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval) { LSL_Parenthesis *parens = calloc(1, sizeof(LSL_Parenthesis)); @@ -1237,7 +1246,7 @@ static LSL_Leaf *eveluateParenthesisToken(LSL_Leaf *content, LSL_Leaf *left, LSL if (content) { - if (LSL_PARAMETER_LIST != content->value.parenthesis->type) + if ((LSL_PARAMETER_LIST != content->value.parenthesis->type) && (LSL_LIST != content->value.parenthesis->type)) result = evaluateLeaf(content->value.parenthesis->contents, left, right); } return result; @@ -1610,6 +1619,32 @@ static void outputIdentifierToken(FILE *file, outputMode mode, LSL_Leaf *content } } +static void outputListToken(FILE *file, outputMode mode, LSL_Leaf *content) +{ + if (content) + { + LSL_Parenthesis *parens = content->value.parenthesis; + + if (parens->contents) + { + LSL_FunctionCall *call = parens->contents->value.functionCallValue; + LSL_Leaf *param = NULL; + + // TODO - should output it's own ignorable here. + fprintf(file, "["); + EINA_INARRAY_FOREACH((&(call->params)), param) + { + outputLeaf(file, mode, param); + } +#if LUASL_DIFF_CHECK + fprintf(file, "%s]", eina_strbuf_string_get(parens->rightIgnorable)); +#else + fprintf(file, "]"); +#endif + } + } +} + static void outputParameterListToken(FILE *file, outputMode mode, LSL_Leaf *content) { if (content) diff --git a/LuaSL/src/LuaSL_lemon_yaccer.y b/LuaSL/src/LuaSL_lemon_yaccer.y index 72d328c..1d28ec5 100644 --- a/LuaSL/src/LuaSL_lemon_yaccer.y +++ b/LuaSL/src/LuaSL_lemon_yaccer.y @@ -202,7 +202,7 @@ expr(A) ::= LSL_INTEGER(B). { B->basicType = OT_integer; A = B; } %nonassoc LSL_KEY. expr(A) ::= LSL_KEY(B). { B->basicType = OT_key; A = B; } %nonassoc LSL_LIST. -expr(A) ::= LSL_BRACKET_OPEN(B) exprList LSL_BRACKET_CLOSE. [LSL_BRACKET_OPEN] { B->basicType = OT_list; A = B; } // Probably need a specific addList(). +expr(A) ::= LSL_BRACKET_OPEN(L) exprList(E) LSL_BRACKET_CLOSE(R). [LSL_BRACKET_OPEN] { A = addList(L, E, R); } %nonassoc LSL_ROTATION. // Uses the same symbol for less than, greater than, and the rotation / vector delimiters. expr ::= LSL_LESS_THAN expr LSL_COMMA expr LSL_COMMA expr LSL_COMMA expr LSL_GREATER_THAN. [LSL_ANGLE_OPEN] -- cgit v1.1