[antlr-interest] AST rewriting

Bernardo Elayda belayda at gmail.com
Tue Jul 1 19:57:15 PDT 2008


>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.

I reviewed my own experiements with tree rewriting.  I found one can only
reference tokens and rules(which are trees). I think you'll need to approach
your rewrite in a different direction.

hth,
Bernardo
On Tue, Jul 1, 2008 at 2:45 PM, Bernardo Elayda <belayda at gmail.com> wrote:

> Hmmmm.....
> try this:
> def : ^(DEF name mylabel=expr) -> ^(DEF name $mylabel.token.value)
>
> Sometimes Antler 3.x has trouble figuring out where to get a value.  In
> theory, I agree with your original code that $expr.value should have worked.
> Let me know if it still doesn't work.  I've run into this issue myself, but
> I don't have any of my grammars here.  I'll have to check this later this
> evening.
>
> regards,
> Bernardo
>
>
> On Tue, Jul 1, 2008 at 10:24 AM, Alvaro Egana <alvarorama at gmail.com>
> wrote:
>
>> Bernardo,
>>
>> Thanks for yor quick answer. I did what you said but it didn't work. I
>> get the same error (about the undefined rule 'value').
>>
>> Alvaro
>>
>> 2008/7/1 Bernardo Elayda <belayda at gmail.com>:
>>  > Hi!
>> > Try this instead:
>> >
>> > def : ^(DEF name mylabel=expr) -> ^(DEF name $mylabel.value)
>> >
>> > hth,
>> > Bernardo Elayda
>> >
>> >
>> > ----------------------------
>> > def : ^(DEF name expr)
>> >      ;
>> > name : <<some rules>>;
>> >
>> >
>> > expr  returns [String value]
>> >      : <<some rules>>
>> >      ;
>> >
>> >
>> > I've been trying to do this rewrite:
>> >
>> > def : ^(DEF name expr) -> ^(DEF name $expr.value)
>> >
>> > (I'm writing a name resolver ...)
>> >
>> >
>> >
>> > But antlr complains saying there is a reference to an undefined rule
>> > 'value'.
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080701/b187ccb2/attachment-0001.html 


More information about the antlr-interest mailing list