[antlr-interest] TreeParser: Qs about generated code
rustydstone
rustydstone at yahoo.com
Sat May 17 07:24:04 PDT 2003
Simple grammar:
expr returns [Object o] {
[...]
| #(UNARY_MINUS e:expr) {o = il.unaryMinus(e);}
[...]
;
The respective generated TreeParser code looks like the following:
1 case UNARY_MINUS:
2 {
3 AST __t25 = _t;
4 AST tmp20_AST_in = (AST)_t;
5 match(_t,UNARY_MINUS);
6 _t = _t.getFirstChild();
7 e = _t==ASTNULL ? null : (AST)_t;
// I'd like to avoid the call on line 8 since I'm calculating the
// result myself on line 12
8 expr(_t);
9 _t = _retTree;
10 _t = __t25;
11 _t = _t.getNextSibling();
12 o = il.unaryMinus(e);
13 break;
14 }
Questions:
1) I thought when I say "#(UNARY_MINUS e:expr)" instead of
"#(UNARY_MINUS e=expr)", ANTL would not bother calculating expr (since
the AST itself is requested, not the value of the expr). Is there a
way to tell ANTL that I will walk this part of the tree and calculate
the result myself?
2) Lines 9, 10, 11 seem a bit strange. Not sure I understand the
meaning of this.
Any ideas? Thanks
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list