From 162e7843bb3475a08eae13b2464092d72560eb9a Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Mon, 30 Jan 2012 16:35:11 +1000 Subject: Remove the else if stuff, and empty function lists. Add the else precedence hack back in. --- LuaSL/src/LuaSL_lemon_yaccer.y | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'LuaSL/src/LuaSL_lemon_yaccer.y') diff --git a/LuaSL/src/LuaSL_lemon_yaccer.y b/LuaSL/src/LuaSL_lemon_yaccer.y index e15078b..78aa349 100644 --- a/LuaSL/src/LuaSL_lemon_yaccer.y +++ b/LuaSL/src/LuaSL_lemon_yaccer.y @@ -40,7 +40,8 @@ state(S) ::= LSL_STATE_CHANGE LSL_IDENTIFIER(I) stateBlock(B). { S = addState( %nonassoc LSL_PARAMETER LSL_PARAMETER_LIST LSL_FUNCTION. functionList(A) ::= functionList(B) functionBody(C). { A = collectStatements(compiler, B, C); } functionList(A) ::= functionBody(C). { A = collectStatements(compiler, NULL, C); } -functionList(A) ::= . { A = collectStatements(compiler, NULL, NULL); } +// No such thing as a function list with no functions. +//functionList(A) ::= . { A = collectStatements(compiler, NULL, NULL); } functionBody(A) ::= function(F) block(B). { A = addFunctionBody(compiler, F, B); } // addFunctionBody has an implied addStatement(compiler, NULL, LSL_FUNCTION, NULL, B, NULL, NULL); @@ -48,7 +49,6 @@ parameterList(A) ::= parameterList(B) LSL_COMMA(C) parameter(D). { A = collectP parameterList(A) ::= parameter(D). { A = collectParameters(compiler, NULL, NULL, D); } parameterList(A) ::= . { A = collectParameters(compiler, NULL, NULL, NULL); } parameter(A) ::= type(B) LSL_IDENTIFIER(C). { A = addParameter(compiler, B, C); } -// Causes a conflict when it's an empty parameterList with calling the same type of function. function(A) ::= LSL_IDENTIFIER(C) LSL_PARENTHESIS_OPEN(D) parameterList(E) LSL_PARENTHESIS_CLOSE(F). { A = addFunction(compiler, NULL, C, D, E, F); } function(A) ::= type(B) LSL_IDENTIFIER(C) LSL_PARENTHESIS_OPEN(D) parameterList(E) LSL_PARENTHESIS_CLOSE(F). { A = addFunction(compiler, B, C, D, E, F); } @@ -62,9 +62,10 @@ block(A) ::= beginBlock(L) statementList(B) LSL_BLOCK_CLOSE(R). { A = addBlock( statementList(A) ::= statementList(B) statement(C). { A = collectStatements(compiler, B, C); } // This causes infinite loops (and about 150 conflicts) with - if () single statement; //statementList(A) ::= statement(C). { A = collectStatements(compiler, NULL, C); } +// Yes, you can have an empty block. statementList(A) ::= . { A = collectStatements(compiler, NULL, NULL); } -%nonassoc LSL_DO LSL_FOR LSL_ELSE_IF LSL_IF LSL_JUMP LSL_RETURN LSL_STATE_CHANGE LSL_WHILE. +%nonassoc LSL_DO LSL_FOR LSL_IF LSL_JUMP LSL_RETURN LSL_STATE_CHANGE LSL_WHILE. %nonassoc LSL_ELSE. statement(A) ::= LSL_DO(F) block(B) LSL_WHILE(W) LSL_PARENTHESIS_OPEN(L) expr(E) LSL_PARENTHESIS_CLOSE(R) LSL_STATEMENT(S). { A = addStatement(compiler, S, F->toKen->type, L, E, R, B, W); } statement(A) ::= LSL_FOR(F) LSL_PARENTHESIS_OPEN(L) expr(E0) LSL_STATEMENT(S0) expr(E1) LSL_STATEMENT(S1) expr(E2) LSL_PARENTHESIS_CLOSE(R) block(B). { A = addStatement(compiler, NULL, F->toKen->type, L, E1, R, B, NULL); } // three expressions, two semi colons @@ -73,8 +74,8 @@ statement(A) ::= LSL_FOR(F) LSL_PARENTHESIS_OPEN(L) expr(E0) LSL_STATEMENT(S0) e statement(A) ::= ifBlock(B). { A = B; } ifBlock ::= ifBlock LSL_ELSE block. ifBlock ::= ifBlock LSL_ELSE statement. -ifBlock(A) ::= LSL_IF(F) LSL_PARENTHESIS_OPEN(L) expr(E) LSL_PARENTHESIS_CLOSE(R) block(B). /*[LSL_ELSE]*/ { A = addStatement(compiler, NULL, F->toKen->type, L, E, R, B, NULL); } // optional else, optional else if -ifBlock(A) ::= LSL_IF(F) LSL_PARENTHESIS_OPEN(L) expr(E) LSL_PARENTHESIS_CLOSE(R) statement(S). /*[LSL_ELSE]*/ { A = addStatement(compiler, S, F->toKen->type, L, E, R, NULL, NULL); } // optional else, optional else if +ifBlock(A) ::= LSL_IF(F) LSL_PARENTHESIS_OPEN(L) expr(E) LSL_PARENTHESIS_CLOSE(R) block(B). [LSL_ELSE] { A = addStatement(compiler, NULL, F->toKen->type, L, E, R, B, NULL); } // optional else, optional else if +ifBlock(A) ::= LSL_IF(F) LSL_PARENTHESIS_OPEN(L) expr(E) LSL_PARENTHESIS_CLOSE(R) statement(S). [LSL_ELSE] { A = addStatement(compiler, S, F->toKen->type, L, E, R, NULL, NULL); } // optional else, optional else if statement(A) ::= LSL_JUMP(F) LSL_IDENTIFIER(I) LSL_STATEMENT(S). { A = addStatement(compiler, S, F->toKen->type, NULL, NULL, NULL, NULL, I); } statement(A) ::= LSL_RETURN(F) expr(E) LSL_STATEMENT(S). { A = addStatement(compiler, S, F->toKen->type, NULL, E, NULL, NULL, NULL); } @@ -175,6 +176,7 @@ expr(A) ::= identifier(B) LSL_ASSIGNMENT_PLAIN(C) expr(D). { A = addOperation(c // Hmm think this can have commas seperating the assignment parts, or is that only in C?. If so, best to separate them when converting to Lua, as it uses that syntax for something else. // Well, not in OpenSim at least, nor in SL. So we are safe. B-) +// On the other hand, it might be legal to have comma separated bits in a for loop - for ((i = 1), (j=1); ... statement(A) ::= type(T) LSL_IDENTIFIER(I) LSL_ASSIGNMENT_PLAIN(D) expr(E) LSL_STATEMENT(S). { A = addStatement(compiler, S, LSL_IDENTIFIER, NULL, addVariable(compiler, T, I, D, E), NULL, NULL, I); } statement(A) ::= type(T) LSL_IDENTIFIER(I) LSL_STATEMENT(S). { A = addStatement(compiler, S, LSL_IDENTIFIER, NULL, addVariable(compiler, T, I, NULL, NULL), NULL, NULL, I); } -- cgit v1.1