[sldev] Re: SLDev Digest, Vol 6, Issue 50

Argent Stonecutter secret.argent at gmail.com
Thu Jun 14 23:26:48 PDT 2007


>
> Unfortunately, the patched grammar is now too greedy when it tries to
> fold constant expressions:
>
> x = x - 5 - 5; // becomes x = x - (5-5) becomes x = x - 0

Ah.

There's not a clean fix for that, you need to have it create the  
parse tree and fold constant expressions at run time. Not as  
straightforward as I thought. Have to drop back to just handling the  
"-x" case.

Don't discard the lex patch! The lex file has several wrong solutions  
to try and fix various symptoms in lex instead of yacc, and it  
basically comes down to "knocking '-' off and fixing the other broken  
stuff".

Instead, drop most of the indra.y patch.

Here's the minimum patch, try it.

-------------- next part --------------
--- indra.y.orig	2007-06-15 01:22:24.000000000 -0500
+++ indra.y	2007-06-15 01:23:43.000000000 -0500
@@ -143,6 +143,8 @@
 %type <assignable>		simple_assignable
 %type <assignable>		simple_assignable_no_list
 %type <constant>		constant
+%type <ival>			integer_constant
+%type <fval>			fp_constant
 %type <assignable>		special_constant
 %type <assignable>		vector_constant
 %type <assignable>		quaternion_constant
@@ -352,30 +354,50 @@
 	;
 
 constant
-	: INTEGER_CONSTANT																
+	: integer_constant
 	{
 		$$ = new LLScriptConstantInteger(gLine, gColumn, $1);
 		gAllocationManager->addAllocation($$);
 	}
-	| INTEGER_TRUE																	
+	| fp_constant
 	{
-		$$ = new LLScriptConstantInteger(gLine, gColumn, $1);
+		$$ = new LLScriptConstantFloat(gLine, gColumn, $1);
 		gAllocationManager->addAllocation($$);
 	}
-	| INTEGER_FALSE																	
+	| STRING_CONSTANT
 	{
-		$$ = new LLScriptConstantInteger(gLine, gColumn, $1);
+		$$ = new LLScriptConstantString(gLine, gColumn, $1);
 		gAllocationManager->addAllocation($$);
 	}
-	| FP_CONSTANT																	
+	;
+
+fp_constant
+	: FP_CONSTANT
 	{
-		$$ = new LLScriptConstantFloat(gLine, gColumn, $1);
-		gAllocationManager->addAllocation($$);
+		$$ = $1;
 	}
-	| STRING_CONSTANT
+	| '-' FP_CONSTANT
 	{
-		$$ = new LLScriptConstantString(gLine, gColumn, $1);
-		gAllocationManager->addAllocation($$);
+		$$ = -$1;
+	}
+	;
+
+integer_constant
+	: INTEGER_CONSTANT
+	{
+		$$ = $1;
+	}
+	| INTEGER_TRUE
+	{
+		$$ = $1;
+	}
+	| INTEGER_FALSE
+	{
+		$$ = $1;
+	}
+	| '-' INTEGER_CONSTANT
+	{
+		$$ = -$2;
 	}
 	;
 


More information about the SLDev mailing list