[antlr-interest] TreeParser: Qs about generated code
Terence Parr
parrt at jguru.com
Sat May 17 09:41:50 PDT 2003
On Saturday, May 17, 2003, at 07:24 AM, rustydstone wrote:
> 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).
If you say expr, ANTLR will parse it. Say '.' and it will acknowledge
that there is a child.
> 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.
Just parsing bookkeeping.
Ter
> Any ideas? Thanks
>
>
>
>
>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>
>
--
Co-founder, http://www.jguru.com
Creator, ANTLR Parser Generator: http://www.antlr.org
Co-founder, http://www.peerscope.com link sharing, pure-n-simple
Lecturer in Comp. Sci., University of San Francisco
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list