From fa5db92c5ee7be17a1dbfc04c4a978c2725138ff Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Tue, 17 Jan 2012 16:38:32 +1000 Subject: Check variables, though not looking up function parameters yet. --- LuaSL/src/LuaSL_LSL_tree.h | 1 + LuaSL/src/LuaSL_compile.c | 11 +++++++++++ LuaSL/src/LuaSL_lemon_yaccer.y | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index dee6263..2c2bfa6 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h @@ -286,6 +286,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); void beginBlock(LuaSL_compiler *compiler, LSL_Leaf *block); +LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier); LSL_Leaf *collectParameters(LSL_Leaf *list, LSL_Leaf *comma, LSL_Leaf *newParam); void endBlock(LuaSL_compiler *compiler, LSL_Leaf *block); diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index 65a8089..6d82fb6 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c @@ -230,6 +230,17 @@ static LSL_Leaf *findVariable(LuaSL_compiler *compiler, const char *name) return var; } +LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier) +{ + gameGlobals *game = compiler->game; + LSL_Leaf *var = findVariable(compiler, identifier->value.stringValue); + + if (NULL == var) + PE("NOT Found %s!", identifier->value.stringValue); + + return var; +} + LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right) { gameGlobals *game = compiler->game; diff --git a/LuaSL/src/LuaSL_lemon_yaccer.y b/LuaSL/src/LuaSL_lemon_yaccer.y index 560c6ab..d5a6751 100644 --- a/LuaSL/src/LuaSL_lemon_yaccer.y +++ b/LuaSL/src/LuaSL_lemon_yaccer.y @@ -167,7 +167,7 @@ statement(A) ::= type(B) LSL_IDENTIFIER(C) LSL_STATEMENT(F). { A = addStatem %right LSL_DOT LSL_IDENTIFIER. identifier ::= identifier LSL_DOT LSL_IDENTIFIER. -identifier(A) ::= LSL_IDENTIFIER(B). { A = B; } +identifier(A) ::= LSL_IDENTIFIER(B). { A = checkVariable(compiler, B); } %right LSL_DECREMENT_PRE LSL_INCREMENT_PRE LSL_DECREMENT_POST LSL_INCREMENT_POST. expr ::= identifier LSL_DECREMENT_PRE. -- cgit v1.1