From 8fcf003634156078c906846ae723599c8d45b6dc Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Thu, 2 Feb 2012 01:01:59 +1000 Subject: Output crements properly. --- LuaSL/src/LuaSL_LSL_tree.h | 2 +- LuaSL/src/LuaSL_compile.c | 39 ++++++++++++++++++++++++++++++++++----- LuaSL/src/LuaSL_lemon_yaccer.y | 8 ++++---- 3 files changed, 39 insertions(+), 10 deletions(-) (limited to 'LuaSL/src') diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index cff2bab..931b6b9 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h @@ -394,7 +394,7 @@ typedef struct void burnLeaf(void *data); LSL_Leaf *addBlock(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right); -LSL_Leaf *addCrement(LuaSL_compiler *compiler, LSL_Leaf *variable, LSL_Leaf *crement); +LSL_Leaf *addCrement(LuaSL_compiler *compiler, LSL_Leaf *variable, LSL_Leaf *crement, LSL_Type type); 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); LSL_Leaf *addFunction(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close); LSL_Leaf *addFunctionBody(LuaSL_compiler *compiler, LSL_Leaf *function, LSL_Leaf *block); diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index 26efbd7..236b2a6 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c @@ -8,6 +8,7 @@ static LSL_Leaf *evaluateOperationToken(LSL_Leaf *content, LSL_Leaf *left, LSL_ static LSL_Leaf *eveluateParenthesisToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); static LSL_Leaf *evaluateStatementToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); static void outputBlockToken(FILE *file, outputMode mode, LSL_Leaf *content); +static void outputCrementsToken(FILE *file, outputMode mode, LSL_Leaf *content); static void outputFloatToken(FILE *file, outputMode mode, LSL_Leaf *content); static void outputFunctionToken(FILE *file, outputMode mode, LSL_Leaf *content); static void outputFunctionCallToken(FILE *file, outputMode mode, LSL_Leaf *content); @@ -90,10 +91,10 @@ LSL_Token LSL_Tokens[] = {LSL_ASSIGNMENT_DIVIDE, ST_ASSIGNMENT, "/=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken}, {LSL_ASSIGNMENT_PLAIN, ST_CONCATENATION, "=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken}, {LSL_DOT, ST_NONE, ".", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, - {LSL_DECREMENT_POST, ST_NONE, "--", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateOperationToken}, - {LSL_DECREMENT_PRE, ST_NONE, "--", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateOperationToken}, - {LSL_INCREMENT_POST, ST_NONE, "++", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateOperationToken}, - {LSL_INCREMENT_PRE, ST_NONE, "++", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateOperationToken}, + {LSL_DECREMENT_POST, ST_NONE, "--", LSL_RIGHT2LEFT | LSL_UNARY, outputCrementsToken, evaluateOperationToken}, + {LSL_DECREMENT_PRE, ST_NONE, "--", LSL_RIGHT2LEFT | LSL_UNARY, outputCrementsToken, evaluateOperationToken}, + {LSL_INCREMENT_POST, ST_NONE, "++", LSL_RIGHT2LEFT | LSL_UNARY, outputCrementsToken, evaluateOperationToken}, + {LSL_INCREMENT_PRE, ST_NONE, "++", LSL_RIGHT2LEFT | LSL_UNARY, outputCrementsToken, evaluateOperationToken}, {LSL_COMMA, ST_NONE, ",", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, {LSL_EXPRESSION, ST_NONE, "expression", LSL_NONE , NULL, NULL}, @@ -463,11 +464,13 @@ LSL_Leaf *addBlock(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL return lval; } -LSL_Leaf *addCrement(LuaSL_compiler *compiler, LSL_Leaf *variable, LSL_Leaf *crement) +LSL_Leaf *addCrement(LuaSL_compiler *compiler, LSL_Leaf *variable, LSL_Leaf *crement, LSL_Type type) { if ((variable) && (crement)) { + crement->value.identifierValue = variable->value.identifierValue; crement->basicType = variable->basicType; + crement->toKen = tokens[type - lowestToken]; } return crement; @@ -1608,6 +1611,32 @@ static void outputBlockToken(FILE *file, outputMode mode, LSL_Leaf *content) outputRawBlock(file, mode, content->value.blockValue); } +static void outputCrementsToken(FILE *file, outputMode mode, LSL_Leaf *content) +{ + if (content) + { + switch (content->toKen->type) + { + case LSL_DECREMENT_PRE : + case LSL_INCREMENT_PRE : + { + fprintf(file, "%s", content->toKen->toKen); + outputText(file, &(content->value.identifierValue->name), !(LSL_NOIGNORE & content->toKen->flags)); + break; + } + case LSL_DECREMENT_POST : + case LSL_INCREMENT_POST : + { + outputText(file, &(content->value.identifierValue->name), !(LSL_NOIGNORE & content->toKen->flags)); + fprintf(file, "%s", content->toKen->toKen); + break; + } + default : + break; + } + } +} + static void outputFloatToken(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 ba32692..b45c7d2 100644 --- a/LuaSL/src/LuaSL_lemon_yaccer.y +++ b/LuaSL/src/LuaSL_lemon_yaccer.y @@ -186,10 +186,10 @@ identifier(A) ::= identifier LSL_DOT LSL_IDENTIFIER(B). { A = checkVariable( identifier(A) ::= LSL_IDENTIFIER(B). { A = checkVariable(compiler, B); } %right LSL_DECREMENT_PRE LSL_INCREMENT_PRE LSL_DECREMENT_POST LSL_INCREMENT_POST. -expr(A) ::= identifier(B) LSL_DECREMENT_PRE(C). { A = addCrement(compiler, B, C); } -expr(A) ::= identifier(B) LSL_INCREMENT_PRE(C). { A = addCrement(compiler, B, C); } -expr(A) ::= LSL_DECREMENT_PRE(C) identifier(B). { A = addCrement(compiler, B, C); } -expr(A) ::= LSL_INCREMENT_PRE(C) identifier(B). { A = addCrement(compiler, B, C); } +expr(A) ::= identifier(B) LSL_DECREMENT_PRE(C). { A = addCrement(compiler, B, C, LSL_DECREMENT_POST); } +expr(A) ::= identifier(B) LSL_INCREMENT_PRE(C). { A = addCrement(compiler, B, C, LSL_INCREMENT_POST); } +expr(A) ::= LSL_DECREMENT_PRE(C) identifier(B). { A = addCrement(compiler, B, C, LSL_DECREMENT_PRE); } +expr(A) ::= LSL_INCREMENT_PRE(C) identifier(B). { A = addCrement(compiler, B, C, LSL_INCREMENT_PRE); } %nonassoc LSL_COMMA. -- cgit v1.1