[antlr-interest] Tree parser eats up DOWN node when navigating optional child node

Junkman j at junkwallah.org
Tue Aug 3 19:48:12 PDT 2010


Greetings,

I am seeing an interesting behavior in generated tree parsers.

This is an example grammar fragment:

--------------------------------------------
tree grammar TTreeParser;

...

parent: ^(parent_a B?) ;
parent_a: ^(PARENT A?) ;
--------------------------------------------

The intent is for parent_a to match a PARENT node optionally with the
child node A, while parent is to match a PARENT node that can also have
child node B as well as child node A.

But parent rule throws up recognition exception when fed this tree:

^(PARENT B)

The problem is parent_a consumes the DOWN node before B instead of
skipping it.

The following tree also causes the exception for parent:

^(PARENT A B)

In this case, parent_a, after consuming A, expects <UP> when there is
still another sibling node - B.

It looks like a discrepancy in the rewrite rule interpretation - when
used to produce tree, the rules work as expected/intended.

I am looking for insight/suggestion to get the tree parser work as
intended.  Attached are example grammars and generated code plus test
driver to demonstrate the issue I'm having.

Thanks for any help,

Jay


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: TTreeParser.g
Url: http://www.antlr.org/pipermail/antlr-interest/attachments/20100803/f1977bd2/attachment.pl 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: T.g
Url: http://www.antlr.org/pipermail/antlr-interest/attachments/20100803/f1977bd2/attachment-0001.pl 


More information about the antlr-interest mailing list