[antlr-interest] AST rewriting

Gavin Lambert antlr at mirality.co.nz
Wed Jul 2 14:06:26 PDT 2008


At 14:57 2/07/2008, Bernardo Elayda wrote:
> >def : ^(DEF name expr) -> ^(DEF name $expr.value)
>I tried some additional experiments.  I don['t think you can 
>access the attribute 'value' in the context of a tree rewrite.

Have you tried this:

def : ^(DEF name expr) -> ^(DEF name {$expr.value}) ;

(Not sure if that's right either, but I have seen some examples 
using something similar.)

Having said that, AST nodes can usually only be tokens -- you 
can't add a raw string to it.  So you'll probably need to do 
something like this instead:

def : ^(DEF name expr) -> ^(DEF name STRING[$expr.value]) ;

(Not entirely sure about that syntax, but it's something like 
that.)



More information about the antlr-interest mailing list