如何从Java源代码生成AST? [英] How to generate AST from Java source-code?

查看:425
本文介绍了如何从Java源代码生成AST?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,将Java源代码解析为AST(抽象语法树)的唯一方法是使用 Java Compiler Tree API :com.sun.source.tree

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


  1. 哪些JDK支持com.sun.source.tree?

  2. 适用于所有JDK?


推荐答案

您可以使用tools.jar并使用它。 javac是开源,因此您只需抓取该代码(假设您可以处理许可证)。 Antlr 也有Java的语法。

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.

这篇关于如何从Java源代码生成AST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆