[antlr-interest] ANTLR 3 output=AST for tree parser?

Kay Roepke kroepke at classdump.org
Sun Feb 25 17:08:47 PST 2007


On Feb 26, 2007, at 1:52 AM, Werner Lehmann wrote:

> for a few hours now I have been trying to get a tree parser out of  
> Terence's Java 1.5 grammar. I thought I was doing something wrong  
> being not very experienced with ANTLR. Is it true that ASTs are not  
> yet supported?

ASTs are supported, the thing that doesn't work is tree rewriting  
(i.e. having a tree parser output another tree by using rewrite rules  
in the tree grammar). There are a couple of examples in the examples- 
v3.tar.gz as well as in the Wiki on how to use tree output.

> I need to update my Java 1.4 parser (based on ANTLR 2.7.6) to Java  
> 1.5 and it seemed to be a good idea to use ANTLR3 and this new  
> grammar but maybe not so. By the way, the separate examples  
> download has a more recent version of Java.g. The version available  
> from the grammars list on the site is older and produces  
> uncompilable code which pushed me off track for some time.
>
> If ANTLR3 would not yet provide an AST should I then use the Java  
> 1.5 grammar created by Michael Studman or Michael Stahl (any  
> experience with either)?

I haven't used any of the Java grammars, but looking at Ter's it  
shows that that grammar simply isn't building trees. You could add  
the tree operators and/or rewrite rules yourself, and then write tree  
grammars to work with your tree. As tree building often depends on  
the thing you want to accomplish, that's probably the best way of  
doing it anyway.

> FranklinChen at cmu.edu wrote:
>> I noticed that output=AST for tree parsers in 3.0b6 isn't working
>> yet.  When will this be available?  I have large ANTLR 2 projects  
>> that
>> make extensive use of multiple passes gradually transforming an AST
>> until the final pass generates output, and I would like to convert
>> them to ANTLR 3.

As mentioned above, this isn't scheduled for 3.0 final, AFAIK. Ter  
wanted to finalize the stuff there is right now before adding new  
features.
I'd think that tree rewriting would come in 3.1 if there is a good  
way of unambiguously defining the process. I vividly remember going  
through the template output stuff with Ter a while ago, and that was  
hard enough to give right semantics to...

HTH,
-k
-- 
Kay Röpke
http://classdump.org/






More information about the antlr-interest mailing list