[antlr-interest] Building an AST for Java

Dan Delorey antlr at deloreyfamily.org
Tue Apr 22 10:24:52 PDT 2008


I just wanted to follow up back on the list to thank John and endorse the
grammar. This does successfully solve the problem I was encountering. I have
not yet had time to dig in deep enough to figure out why my grammar was
losing parts of the AST during back tracking and John's is not. I will reply
again if I figure that out.

I also wanted to make sure we got on the list that this grammar requires
ANTLR 3.1 beta. I have been able to use it in the bundled mac ANTLRWorks
version 1.2 beta (after changing to VMOptions in Info.plist to allow more
heap space...).

Thanks, John!

On Sat, Apr 19, 2008 at 12:56 PM, John Ridgway <john at jacelridge.com> wrote:

> 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
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080422/948ffb85/attachment.html 


More information about the antlr-interest mailing list