[antlr-interest] AST rewriting

Bernardo Elayda belayda at gmail.com
Wed Jul 2 14:29:11 PDT 2008


that has been my experience as well with tree rule rewrites.
the re-written node must be composed of pre-existing rule reference(no
parameters) or the construction of a new token.

-Bernardo


On Wed, Jul 2, 2008 at 2:06 PM, Gavin Lambert <antlr at mirality.co.nz> wrote:

> 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.)
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080702/8db23006/attachment.html 


More information about the antlr-interest mailing list