From 809530889811445b7fca3a57ce38efee196d1c22 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Thu, 2 Feb 2012 01:55:44 +1000 Subject: Parse dot subbies. --- LuaSL/src/LuaSL_LSL_tree.h | 3 ++- LuaSL/src/LuaSL_compile.c | 36 ++++++++++++++++++++++++++++++++++-- LuaSL/src/LuaSL_lemon_yaccer.y | 4 ++-- 3 files changed, 38 insertions(+), 5 deletions(-) (limited to 'LuaSL/src') diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index 5e36c73..7791b10 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h @@ -211,6 +211,7 @@ struct _LSL_Parenthesis struct _LSL_Identifier // For variables and function parameters. { LSL_Text name; + const char *sub; LSL_Leaf value; }; @@ -411,7 +412,7 @@ LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf * LSL_Leaf *addVariable(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *assignment, LSL_Leaf *expr); LSL_Leaf *beginBlock(LuaSL_compiler *compiler, LSL_Leaf *block); -LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier); +LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf *dot, LSL_Leaf *sub); LSL_Leaf *collectArguments(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *comma, LSL_Leaf *arg); LSL_Leaf *collectParameters(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *comma, LSL_Leaf *newParam); LSL_Leaf *collectStatements(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *newStatement); diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index 0b56845..5fb3946 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c @@ -300,13 +300,19 @@ static LSL_Leaf *findVariable(LuaSL_compiler *compiler, const char *name) return var; } -LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier) +LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf *dot, LSL_Leaf *sub) { gameGlobals *game = compiler->game; + const char *search; + + if (dot) + search = identifier->value.identifierValue->name.text; + else + search = identifier->value.stringValue; if (identifier) { - LSL_Leaf *var = findVariable(compiler, identifier->value.stringValue); + LSL_Leaf *var = findVariable(compiler, search); if (var) { @@ -314,6 +320,26 @@ LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier) PI("Found %s!", identifier->value.stringValue); identifier->value.identifierValue = var->value.identifierValue; identifier->basicType = var->basicType; + if ((dot) && (sub)) + { + LSL_Identifier *id = calloc(1, sizeof(LSL_Identifier)); + + if (id) + { + memcpy(id, var->value.identifierValue, sizeof(LSL_Identifier)); + identifier->value.identifierValue = id; + if (LSL_ROTATION == var->toKen->type) + { + // TODO - check if it's one of x, y, z, or s. + } + if (LSL_VECTOR == var->toKen->type) + { + // TODO - check if it's one of x, y, or z. + } + identifier->value.identifierValue->sub = sub->value.stringValue; + identifier->basicType = OT_float; + } + } } else PE("NOT found %s @ line %d, column %d!", identifier->value.stringValue, identifier->line, identifier->column); @@ -1520,6 +1546,8 @@ static void outputRawStatement(FILE *file, outputMode mode, LSL_Statement *state fwrite(eina_strbuf_string_get(statement->ignorable[1]), 1, eina_strbuf_length_get(statement->ignorable[1]), file); #endif fprintf(file, "%s", tokens[statement->type - lowestToken]->toKen); + if (statement->identifier) + outputText(file, &(statement->identifier->name), FALSE); break; } case LSL_STATEMENT : @@ -1708,7 +1736,11 @@ static void outputIdentifierToken(FILE *file, outputMode mode, LSL_Leaf *content if (content) { if (LSL_IDENTIFIER == content->toKen->type) + { outputText(file, &(content->value.identifierValue->name), FALSE); + if (content->value.identifierValue->sub) + fprintf(file, ".%s", content->value.identifierValue->sub); + } else outputText(file, &(content->value.identifierValue->name), !(LSL_NOIGNORE & content->toKen->flags)); } diff --git a/LuaSL/src/LuaSL_lemon_yaccer.y b/LuaSL/src/LuaSL_lemon_yaccer.y index ad85337..565a431 100644 --- a/LuaSL/src/LuaSL_lemon_yaccer.y +++ b/LuaSL/src/LuaSL_lemon_yaccer.y @@ -182,8 +182,8 @@ statement(A) ::= type(T) LSL_IDENTIFIER(I) LSL_ASSIGNMENT_PLAIN(D) expr(E) LSL_S statement(A) ::= type(T) LSL_IDENTIFIER(I) LSL_STATEMENT(S). { A = addStatement(compiler, S, I, NULL, addVariable(compiler, T, I, NULL, NULL), NULL, NULL, I); } %right LSL_DOT LSL_IDENTIFIER LSL_FUNCTION_CALL LSL_VARIABLE. -identifier(A) ::= identifier LSL_DOT LSL_IDENTIFIER(B). { A = checkVariable(compiler, B); A->basicType = OT_float; } // Just a stub to get it to work for now. -identifier(A) ::= LSL_IDENTIFIER(B). { A = checkVariable(compiler, B); } +identifier(A) ::= identifier(I) LSL_DOT(D) LSL_IDENTIFIER(B). { A = checkVariable(compiler, I, D, B); } +identifier(A) ::= LSL_IDENTIFIER(B). { A = checkVariable(compiler, B, NULL, NULL); } %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, LSL_DECREMENT_POST); } -- cgit v1.1