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
tree grammar TTreeParser;
options {
tokenVocab=T;
ASTLabelType=CommonTree;
}
parent: ^(parent_a B?) ;
parent_a: ^(PARENT A?) ;
grammar T;
options {
output=AST;
}
PARENT: 'P' ;
A: 'A' ;
B: 'B' ;
parent: parent_a B? -> ^(parent_a B?) ;
parent_a: PARENT A? -> ^(PARENT A?) ;
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en.