[antlr-interest] Tree Builder / Tree Parser Mismatch

Shmuel Siegel ssiegel at finjan.com
Tue Oct 9 08:06:34 PDT 2007


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.

-----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

-==--==--==--==--==--==--==--==--==--==--==--==--==--==--==-
looseImportList[ String unitName ]
returns [ CLText ct ]
@init {
  $ct = new CLText();
}
  : ( name
      {
        System.err.format("CB.lIL: name=\%s\%n", $name.text);
        $ct.add(noteImport(new CLImport($name.text)));
      }

  |   ^( CLImports interpretableName )
      {
        System.err.format("CB.lIL: interpretableName=\%s\%n",
                          $interpretableName.text);
        $ct.add(noteImport(new CLImport($interpretableName.text)));
      }
    ) *

    EOF
    {
      ...
    }
  ;
-==--==--==--==--==--==--==--==--==--==--==--==--==--==--==-


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.

Randall Schulz



More information about the antlr-interest mailing list