Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - abstract syntax tree

I am currently looking for a Java 6/7 parser, which generates some (possibly standartized) form abstract syntax tree.

I have already found that ANTLR has a Java 6 grammar, but it seems, that it only generates parse tree, but not syntax tree. I have also read about Java Compiler API - but all the soources mentioned, that it is overdesigned and poorly documented (and I havent found, if it really generates the AST).

Do you know about any good parser library, with possibly as standardized output as possible?

Thanks

like image 653
malejpavouk Avatar asked Mar 05 '12 10:03

malejpavouk


1 Answers

Basically JavaCC and ANTLR are the best tools out there at the moment.

You can find a usable Java 6 grammar in the project's grammar repository. JavaCC is a bit oldschool, rarely updated, but easy to start with, Java-oriented, and generates the AST (search for JJTree). It's a bit, well... strange on the first sight, but you can get used to it.

Both tools have a nice IDE support (e.g., Eclipse plug-ins), but I think (based on your description) what you need is JavaCC. Give it a try.

like image 161
rlegendi Avatar answered Oct 29 '22 00:10

rlegendi