From 21bcc5ba96159d9b00d59e92ffc16078a0f4c4ed Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Thu, 2 Feb 2012 12:59:47 +1000 Subject: Partially implement parsing/outputting rotations and vectors. --- LuaSL/src/LuaSL_LSL_tree.h | 1 + LuaSL/src/LuaSL_compile.c | 36 ++++++++++++++++++++++++++++++------ LuaSL/src/LuaSL_lemon_yaccer.y | 15 ++++++--------- 3 files changed, 37 insertions(+), 15 deletions(-) (limited to 'LuaSL/src') diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index 8be8afd..ca91ff0 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h @@ -421,6 +421,7 @@ LSL_Leaf *addNumby(LSL_Leaf *numby); 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); +LSL_Leaf *addRotVec(LSL_Leaf *left, LSL_Leaf *list, LSL_Leaf *right); LSL_Leaf *addState(LuaSL_compiler *compiler, LSL_Leaf *state, LSL_Leaf *identifier, LSL_Leaf *block); 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); LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf *expr); diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index 2d5878f..cf9d767 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c @@ -104,9 +104,9 @@ LSL_Token LSL_Tokens[] = {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, outputListToken, NULL}, - {LSL_ROTATION, ST_NONE, "rotation", LSL_NONE, NULL, NULL}, + {LSL_ROTATION, ST_NONE, "rotation", LSL_NONE, outputListToken, NULL}, {LSL_STRING, ST_NONE, "string", LSL_NONE, outputStringToken, NULL}, - {LSL_VECTOR, ST_NONE, "vector", LSL_NONE, NULL, NULL}, + {LSL_VECTOR, ST_NONE, "vector", LSL_NONE, outputListToken, NULL}, // Types names. {LSL_TYPE_FLOAT, ST_NONE, "float", LSL_NONE, NULL, NULL}, @@ -724,6 +724,18 @@ LSL_Leaf *addList(LSL_Leaf *left, LSL_Leaf *list, LSL_Leaf *right) return left; } +LSL_Leaf *addRotVec(LSL_Leaf *left, LSL_Leaf *list, LSL_Leaf *right) +{ + LSL_Type type = LSL_ROTATION; + opType otype = OT_rotation; + + // TODO - count the members of list to see if it's a vector. + left = addParenthesis(left, list, type, right); + left->toKen = tokens[type - lowestToken]; + left->basicType = otype; + return left; +} + LSL_Leaf *addNumby(LSL_Leaf *numby) { LSL_Numby *num = calloc(1, sizeof(LSL_Numby)); @@ -1820,18 +1832,30 @@ static void outputListToken(FILE *file, outputMode mode, LSL_Leaf *content) { LSL_FunctionCall *call = parens->contents->value.functionCallValue; LSL_Leaf *param = NULL; + const char *ig = ""; // TODO - should output it's own ignorable here. - fprintf(file, "["); + switch (parens->type) + { + case LSL_LIST : fprintf(file, "["); break; + case LSL_ROTATION : + case LSL_VECTOR : fprintf(file, "<"); + default : break; + } 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, "]"); + ig = eina_strbuf_string_get(parens->rightIgnorable); #endif + switch (parens->type) + { + case LSL_LIST : fprintf(file, "%s]", ig); break; + case LSL_ROTATION : + case LSL_VECTOR : fprintf(file, "%s>", ig); + default : break; + } } } } diff --git a/LuaSL/src/LuaSL_lemon_yaccer.y b/LuaSL/src/LuaSL_lemon_yaccer.y index d2731d8..8b6c3d7 100644 --- a/LuaSL/src/LuaSL_lemon_yaccer.y +++ b/LuaSL/src/LuaSL_lemon_yaccer.y @@ -196,21 +196,18 @@ expr(A) ::= LSL_INCREMENT_PRE(C) identifier(B). { A = addCrement(compiler, // Values. %nonassoc LSL_FLOAT. -expr(A) ::= LSL_FLOAT(B). { A = addNumby(B); } +expr(A) ::= LSL_FLOAT(B). { A = addNumby(B); } %nonassoc LSL_INTEGER. -expr(A) ::= LSL_INTEGER(B). { A = addNumby(B); } +expr(A) ::= LSL_INTEGER(B). { A = addNumby(B); } %nonassoc LSL_KEY. -expr(A) ::= LSL_KEY(B). { B->basicType = OT_key; A = B; } +expr(A) ::= LSL_KEY(B). { B->basicType = OT_key; A = B; } %nonassoc LSL_LIST. expr(A) ::= LSL_BRACKET_OPEN(L) exprList(E) LSL_BRACKET_CLOSE(R). [LSL_BRACKET_OPEN] { A = addList(L, E, R); } -%nonassoc LSL_ROTATION. +%nonassoc LSL_ROTATION LSL_VECTOR. // 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] +expr(A) ::= LSL_LESS_THAN(L) exprList(E) LSL_GREATER_THAN(R). [LSL_ANGLE_OPEN] { A = addRotVec(L, E, R); } %nonassoc LSL_STRING. -expr(A) ::= LSL_STRING(B). { B->basicType = OT_string; A = B; } -%nonassoc LSL_VECTOR. -expr ::= LSL_VECTOR. -expr ::= LSL_LESS_THAN expr LSL_COMMA expr LSL_COMMA expr LSL_GREATER_THAN. [LSL_ANGLE_OPEN] +expr(A) ::= LSL_STRING(B). { B->basicType = OT_string; A = B; } // Parser callbacks. -- cgit v1.1