Alex Rivera | Logout

How to generate AST from Java source-code?

Asked 2009-12-28T04:38:40.170
46

As far as I know, the only way to parse Java source-code into an AST (Abstract Syntax Tree) is to use the Java Compiler Tree API: com.sun.source.tree

I have two questions:

  1. What JDKs support com.sun.source.tree?
  2. Is there a portable replacement that works for all JDKs?
Edit
Report

1 Answer

9

You can possibly take the tools.jar and use it. javac is open source so you can just grab that code (assuming you can deal with the license). Antlr has grammars for Java as well.

answered 2009-12-28T04:46:15.393

Your Answer