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

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

问题描述

据我所知,将 Java 源代码解析为 AST(抽象语法树)的唯一方法是使用 Java 编译器树 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天全站免登陆