Fwd: [antlr-interest] Jump over nodes in tree construction
Bryan Ewbank
ewbank at gmail.com
Wed Mar 16 03:32:57 PST 2005
[[Sending this to the list so that it's in the collective]]
Another option that should work with a bit less C++ goo...
/**
* first alternative discards extra EXPR node;
* second alternative is passthru.
*/
unbrace_expr!
: ( EXPR ) => #( EXPR e1:. ) { ## = #e1; }
| e2:. { ## = #e2; }
;
As a side question, might you prefer a recursive definition to remove
redundant nodes from the tree?
/**
* first alternative rips out all EXPR nodes;
* second alternative restores one level of same.
*/
unbrace_expr!
: ( EXPR ) => #( EXPR e1:unbrace_expr ) { ## = #e1; }
| e2:. { ## = #( #[EXPR,"EXPR]", #e2); }
;
Hope this helps. I've learned that if I see getType() or
getFirstChild() in my C++, it means I need to refactor some of that
into ANTLR.
On Tue, 15 Mar 2005 06:11:08 +0000, marc schellens
<m_schellens at hotmail.com> wrote:
> unbrace_expr!
> : ex:expr
> {
> // remove last pair of braces
> if( #ex->getType()==EXPR)
> #unbrace_expr= #( NULL, ex->getFirstChild());
> else
> #unbrace_expr= #( NULL, ex);
> }
More information about the antlr-interest
mailing list