开发者

Generate AST for Java with ANTLR

开发者 https://www.devze.com 2023-03-08 02:58 出处:网络
As far as I know, there are two mechanisms in ANTLR for building abstract syntax trees. I want to buil开发者_运维技巧d a AST for Java source files.

As far as I know, there are two mechanisms in ANTLR for building abstract syntax trees. I want to buil开发者_运维技巧d a AST for Java source files.

Question: There are so many grammar rules in Java.g (java specification), it's a large work if I specify the AST generating rules for every item in Java.g. So I wondering if there is a ready-made one, and where can I get it.


This Java 1.5 grammar1 from the ANTLR Wiki generates an AST and also provides a tree grammar2.

  1. Java.g
  2. JavaTreeParser.g

22 Aug 2014 - UPDATE

Since the original link appears to be dead, the grammar and tree grammar are available in a public Gist: https://gist.github.com/bkiers/741125a606954b24bbf4

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号