[antlr-interest] Tree Builder / Tree Parser Mismatch

Randall R Schulz rschulz at sonic.net
Tue Oct 9 07:02:25 PDT 2007


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