SmaCC: Shift/Reduce Conflict

Mathieu Suen mathk.sue at gmail.com
Mon Apr 23 11:50:59 UTC 2007


Hi,

On Apr 23, 2007, at 11:51 AM, Alexandre Bergel wrote:

> FunctionDefinition :
> 	Id Arguments "{"
> 	ExpressionList
> 	"}" {SPFunction new name: '1'; arguments: ('2' select: [:o| (o  
> isKindOf: SmaCCToken) not]); expressions: '4'};
>
> Arguments : "(" ArgumentList ")" {'2'};
>
> ArgumentList : ArgumentList "," Id
> 		| Id
> 		| ;
>
> ExpressionList:
> 	Expression ExpressionList
> 	| ;
> 	
> Expression :
> 		FunctionCall				
> 	   | VariableDefinition
> 	   | Id "=" ExpressionWithValue {SPAssignment new name: '1';  
> expression: '3'}
>         | Expression "+" Number 	{SPAddition new left: '1'; right:  
> '3'}
>         | Expression "-" Number 	{SPMinus new left: '1'; right: '3'}
>         | Number {'1'};
>

I suggest you to create a rule for the assignment.
You can write something like

Assignment :
	Id "=" Expression;


> FunctionCall :
> 	Id ArgumentsInCall 	{SPFunctionCall new name: '1'; arguments: '2'};
>
> ArgumentsInCall :
> 	"(" ArgumentsListInCall ")" {'2' select: [:o| (o isKindOf:  
> SmaCCToken) not]};
> 	
> ArgumentsListInCall :
> 	ArgumentsListInCall "," Expression
> 	| Expression
> 	| ;
> 	
> VariableDefinition :
> 	"var" Id {SPVariableDefinition new name: '2'};
> 		
> ExpressionWithValue :				
>         ExpressionWithValue "+" Number 	{SPAddition new left: '1';  
> right: '3'}
>         | ExpressionWithValue "-" Number 	{SPMinus new left: '1';  
> right: '3'}
>         | Number {'1'};



ExpressionWithValue always end up with a Number which is not what  
your example saw.
Shift/Reduce dose not matter
You can still parse the expression and you have some rule to say if  
you want to follow the longer rule or not (ie. Shift or reduce).
By default you SmaCC do a shift. Look at the tutorial pane in the UI  
of SmaCC.


HTH

	Math





More information about the Squeak-dev mailing list