[antlr-interest] [newbie] AST Rewriting

Eric researcher0x00 at gmail.com
Mon Mar 19 13:07:50 PDT 2012


FYI - See official notification about trees and AST for ANTLR 4.x (Honey
Badger).

http://antlr.markmail.org/search/?q=Reduction%20in%20code%20base%20after%20yanking%20AST%20stuff#query:Reduction%20in%20code%20base%20after%20yanking%20AST%20stuff+page:1+mid:txxyma2rkgao3wmi+state:results

Wouldn't want to get someone in trouble over an e-mail from some unknown
person.
Just so you know, I don't talk with Ter, I just pay attention to the site
including the wiki, blog, shares, this forum, and the code at github.

Eric


On Mon, Mar 19, 2012 at 3:26 PM, Robin <diabeteman at gmail.com> wrote:

> Hey !
>
> Also note that ANTLR 4.x will no longer be supporting tree rewrites in the
>> grammar; currently ANTLR 3.x be will the last version to support them.
>>
>
> I wasn't aware of that and it changes a lot of stuff about the project
> behind all this :)
>
>
> Since you already know how to get the AST, all you have to do now is
>> treat the AST as any n-ary tree and manipulate.
>>
>> Instead of jumping right into your problem, take some time to write a
>> tree walker, a print routine, and some search routines, i.e. find text,
>> find node type, return a node, return a branch with children, etc.. You
>> will need to write them because they will help you understand trees and for
>> debugging.
>>
>> Next you will need to understand the basic methods in the tree API,
>> basically the BaseTree, and CommonTree classes.
>> If you take a look at the previous post "Help with compressin​g trees
>> and custom nodes" you will find some C# examples I give for using them.
>>
>
> Thanks for the advice. It looks like I have some homework :P
>
>
> I'll try to write a simple tree walker that only prints stuff and once I
> get comfortable with this, I'll see if I have more questions :>
>
> --robin
>
>
> On Mon, Mar 19, 2012 at 7:04 AM, Robin <diabeteman at gmail.com> wrote:
>>
>>> Hello list :)
>>>
>>> I am trying to rewrite an AST (by filtering out most of the nodes). From
>>> what i could read on antlr wiki and some interesting forums & other
>>> medias,
>>> you can do this with tree grammars and tree operators "->".
>>>
>>> The grammar I use to generate AST is here
>>> http://www.antlr.org/grammar/1207932239307/Java1_5Grammars and here is
>>> my
>>> test rig http://pastebin.com/LeR4miVu
>>>
>>> I modified JavaTreeParser.g and added the options output = AST; and
>>> rewrite
>>> = true; Also, just for testing purposes, I added "->" at the end of each
>>> rule in order to filter out all of the nodes. Here is what it looks like
>>> http://pastebin.com/u6UG7fEB
>>>
>>> The problem is that in my test rig, the returned tree is not rewrited at
>>> all.
>>>
>>> I am sure I'm doing something wrong. Could you help ?
>>>
>>> Thanks in advance,
>>> Robin
>>>
>>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>>> Unsubscribe:
>>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>>
>>
>>
>


More information about the antlr-interest mailing list