[antlr-interest] Tree Builder / Tree Parser Mismatch

Randall R Schulz rschulz at sonic.net
Tue Oct 9 08:46:46 PDT 2007


On Tuesday 09 October 2007 08:06, Shmuel Siegel wrote:
> I believe that the rewrites are not cumulative but rather last one
> wins. If you extracted the second alternative (with its rewrite) to a
> subrule, you should get what you want.

Thank you. I knew it had to be something straightforward and I tried to 
find the answer in TDAR's sections on tree building and parsing, but I 
just couldn't tease it out.

The new rules, which work as I want, are these:

looseImportList
	:	looseImport *
		EOF
	;

looseImport
	:	name
	->	^( CLImports name )

	|	( Open CLImports interpretableName Close )
	->	^( CLImports interpretableName )
	;


Randall Schulz


> -----Original Message-----
> From: antlr-interest-bounces at antlr.org
> [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Randall R
> Schulz Sent: Tuesday, October 09, 2007 4:02 PM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Tree Builder / Tree Parser Mismatch
>
> Hi,
>
> I am seeing something I cannot explain and would like some other
> pairs of eyes to help me spot what I'm doing wrong.
>
>
> Here is a tree-building parser rule:
>
> -==--==--==--==--==--==--==--==--==--==--==--==--==--==--==-
> looseImportList
>
>   : ( name
>   :
>     | ( '(' CLImports interpretableName ')' )
>
>       {
>         System.err.format("CP.lIL: interpretableName=\%s\%n",
>                           $interpretableName.text);
>       }
>     ->  ^( CLImports interpretableName )
>     ) *
>
>     EOF
>   ;
> -==--==--==--==--==--==--==--==--==--==--==--==--==--==--==-
>
>
> Here is the corresponding rule from the second-pass tree parser
>
> -==--==--==--==--==--==--==--==--==--==--==--==--==--==--==-
> ...
> -==--==--==--==--==--==--==--==--==--==--==--==--==--==--==-
>
>
> When I supply input with four occurrences of second alternatives (the
> parenthesized one) I see four of the "CP.lIL..." diagnostic messages.
> But the second pass shows only one "CB.lIL..." diagnostic trace, the
> one for the last of the four input forms.
>
> What am I missing?
>
> Thanks.


More information about the antlr-interest mailing list