[antlr-interest] Rewrite Problem; Rule terminates without exception.

Michael Ernst chiptv at web.de
Sun Mar 16 10:54:10 PDT 2008


Hi Terence,

A little subset of my grammar:

grammar Test;

options {	output=AST;
	}
	
expressionStatement 
	:	expression ';'!
	;
	
expression
	:	(orExpression ADDITION_ASSIGNMENT) => a=orExpression
ADDITION_ASSIGNMENT expression ->  ^(ASSIGNMENT $a ^(PLUS $a expression))
	|	orExpression
	;
	
orExpression 
	:	IDENTIFIER;
	
assignmentOperator
	:	ASSIGNMENT
	|	ADDITION_ASSIGNMENT
	;
	
ASSIGNMENT 		:	'=';
ADDITION_ASSIGNMENT 	:	'+=';
PLUS 			:	'+';
	

IDENTIFIER
	: ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
	;
	
WS  :  (' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;}
    ;


The resulting tree "a += b;": (ASSIGNMENT a (PLUS b))


Regards
Michael


On Mar 16, 2008, at 6:57 AM, Michael Ernst wrote:

> Hi,
>
> I could solve the problem by using syntactic prdicates, but there  
> is still a
> problem. When I rewrite the tree and referencing the label twice, I  
> get no
> tree duplicate attached to the tree. I thought I could duplicate  
> nodes and
> trees by referencing them more than one time in a rewrite rule  
> (Chapter 7;
> Duplicating Nodes and Trees (sample: dump : INT -> INT INT ;)).

Hi Michael,

That should work; either something else is going on or it's a bug;  
can you narrow it down to a simple rule like that that doesnt' work?
Ter



More information about the antlr-interest mailing list