Fiary
Fiary

Reputation: 203

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 build 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.

Upvotes: 2

Views: 2133

Answers (1)

Bart Kiers
Bart Kiers

Reputation: 170308

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

Upvotes: 3

Related Questions