[antlr-interest] repeating the parsing of a subtree
Claude Moulin
claude.moulin at hds.utc.fr
Sat Oct 24 11:09:17 PDT 2009
I never had a good solution to the problem that I resolved before using
(or rendering public) the getNodeIndex method of the
CommonTreeNodeStream
class.
I have the following tree:
^(REPEAT a = atom list = .)
Where list can be parsed with a specific rule: list_instructions.
atom returns an integer giving the number of times (maybe 0) the list of
instructions has to be executed.
The semantics of the instruction is then clear.
In the previous version of antlr I used the following interpreting Java
code:
{
for (int i = 0; i < $a.r ; i++) {
push(list);
list_instructions();
pop();
}
Where push and pop method are added to the tree parser:
private void push(CommonTree tree) {
int n = ((CommonTreeNodeStream)input).getNodeIndex(tree);
if (n >= 0)
((CommonTreeNodeStream)input).push(n);
}
private void pop() {
((CommonTreeNodeStream)input).pop();
}
In version 3.2 CommonTreeNodeStream has been updated and I no longer
understand how to parse a subtree of the AST when it is needed and
possibly several times. The problem was to find the index of a Tree root
in the AST representation.
Can someone give the solution?
Thank you
Claude
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091024/01eb95ff/attachment.html
More information about the antlr-interest
mailing list