from:https://shijinglu.wordpress.com/2015/01/22/build-antlr4-projects-with-eclipse-java-project-template/Posted on January, by Shijinglu
Before taking any action, remember to install ANTLR4 plugin for Eclipse, it can is easily found from "Eclipse Marketplace" .
1.Create an ANTLR4 project. This would create a simple "Hello" ANTLR4 project.
2.ADD Java project facet to the project.
3.Eclipse would automatically rebuild the project, see messages in the Console, pay attention to the default antlr-4.4- Complete.jar path.
4.Or You can move the ANTLR4 jar file to your comfortable directory and add it the eclipse build path from therein.
5.Add destination folder of generated Java files to the project as source folder.
6.ADD some code to test this project, <>
////import ANTLR ' s runtime librariesimport Org.antlr.v4.runtime.*;import org.antlr.v4.runtime.tree.*;p ublic class Hellorunner {public static void main (string[] args) throws Exception {//Create a Charstream this reads from standard INP Utantlrinputstream input = new Antlrinputstream (system.in);//Create a lexer that Feeds off of input charstreamhellolexer lexer = new Hellolexer (input);//Create a buffer of tokens pulled from the Lexerco Mmontokenstream tokens = new Commontokenstream (lexer);//Create a parser that feeds off the tokens Bufferhelloparser parse R = new Helloparser (tokens); Parsetree tree = PARSER.R (); Begin parsing at rule ' R ' system.out.println (Tree.tostringtree (parser));//Print Lisp-style Tree}}
7. Runt this Hellorunner.java as Java application
Build ANTLR4 projects with Eclipse Java project template.