[antlr-interest] Tree parser eats up DOWN node when navigating optional child node
Junkman
j at junkwallah.org
Wed Aug 4 09:53:09 PDT 2010
I am re-sending with the demo files in a zip archive because the java
file attachments may have been stripped (security filter?) from the
previous submission.
Junkman wrote:
> 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 --------------
A non-text attachment was scrubbed...
Name: TreeParserDemo.zip
Type: application/x-zip-compressed
Size: 4789 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20100804/5adbb732/attachment.bin
More information about the antlr-interest
mailing list