I'm trying to implement a tree grammar that recognizes the goto
statement in BASIC with numbered code lines. So far I'm toying with
goto and print. My parser-lexer grammar looks like:
prog: stat+;
stat: expr NEWLINE -> expr
| NEWLINE ->
;
expr: INT^ instruction
;
instruction: 'goto'^ INT
| 'print'^ INT
;
As you can see, I'm building a tree whose first level are the numeric
line labels, and the children are BASIC instructions.
The tree grammar I'm trying has the following function:
@members {
HashMap labeledLines = new HashMap();
public void getLabels() {
CommonTree root = (CommonTree)input.getTreeSource();
for (int i = 0; i < root.getChildCount(); i++) {
labeledLines.put(root.getChild(i).getText(), i);
}
System.out.println(labeledLines);
}
}
My getLabels() function manages to get the (CommonTree) children index
i, of each labeled child. Next I'd like to use seek() to go to the
corresponding BufferedTreeNodeStream node. How can I translate the
child index 'i' into an index that is usable with seek?
Thanks
JH
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.