Generate AST for Java with ANTLR
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.
Java.g
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
精彩评论