Best way to parse Java in Java

会有一股神秘感。 提交于 2019-11-30 14:19:46

Janino can parse, compile and execute Java code.

Antlr has a grammar file for Java. See this.

You may be looking for something like ANTLR: http://www.antlr.org/

Eclipse exposes the Syntax Tree of it's own Java compiler. You can simply access the elements.

See here.

JavaCC has a Java 1.5 grammar including generics.

the tokens are probably more fine-grained then what I want

Your first requirement is to get an accurate parse, and you will realistically only get that from an existing parser. What you do with the result is up to you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!