[antlr-interest] Building an AST for Java

John Ridgway john at jacelridge.com
Sat Apr 19 11:56:40 PDT 2008


I have a version of the Java.g grammar that produces an AST.  It is  
going to go up on the Antlr web-site soon, but it's not there yet.   
You are welcome to use it, with the same licensing restrictions as  
Antlr itself.  I'll e-mail stuff directly to you in a separate e-mail  
if you would like.  Just e-mail me privately.  This goes for anyone  
else who might want such a thing.

I actually build the AST and have a tree grammar that outputs Java  
code.  The combination has successfully parsed and recreated the  
entire JDK 1.5 source tree.

Peace
- John


On Apr 19, 2008, at 2:41 PM, Dan Delorey wrote:

> I've been having quite a bit of trouble generating an AST for Java.  
> I started by trying to modify the Java.g posted by Ter. I have also  
> tried using the one posted by Dieter Habelitz. In both cases I'm  
> having the same problem, though.
>
> That is, I can't seem to modify the grammar so that it doesn't  
> require backtracking. With backtracking, however, critical (for my  
> purposes) parts of the AST are missing. For example, the branches  
> that should be generated by the following code:
>
> f.getName().length()
>
> Is incomplete. I can get either the f.getName() function call in the  
> tree or the length() function call, but not both.
>
> So far I have tried using rule scopes, global scopes, parameters,  
> return values, and standard rewrite rules. I'm really confused that  
> this is so hard for me. Could anyone give me some guidance?
>
> Thanks,
> Dan



More information about the antlr-interest mailing list