How to generate AST from Java source-code?

compiler-construction, java, parsing

Solution

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.

Problem

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: - What JDKs support com.sun.source.tree? - Is there a portable replacement that works for all JDKs?

Original source

Related problems