Build ANTLR4 projects with Eclipse Java project template.

Source: Internet
Author: User
Tags lexer

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.