Reputation: 41
I am trying to construct an AST using the latest version of ANTLR (v4), i found a couple of links here in stack-overflow and also on the net, that shows you how to do it for a simple grammars. However, i wanted an AST for the Java.g4 grammar (Java language). Currently , i was following the approached recommended here (https://codevomit.wordpress.com/2015/04/25/antlr4-project-with-maven-tutorial-episode-3/). However based on this approach, i needed to label all the production rules that have alternatives.
Hence, i would greatly appreciate it if someone informed me if there is a different alternative for building an AST using ANTLR4 or if there is an already labeled java.g4 grammar.
Upvotes: 0
Views: 1266
Reputation: 6001
All of the subrule alternates do not need to be labeled. Label just those alternates where generation of a discrete context object is desired. Really just the statement
, expression
, and (maybe) primary
rules warrant labeling.
Labeling itself is trivial.
Upvotes: 1