Build Antlr4 projects with eclipse java project template.

來源:互聯網
上載者:User

標籤:

from:https://shijinglu.wordpress.com/2015/01/22/build-antlr4-projects-with-eclipse-java-project-template/Posted on January 22, 2015 by shijinglu

Before taking any action, remember to install antlr4 plugin for eclipse, it can be easily found from “Eclipse Marketplace”.
1.Create an antlr4 project. This will create an simple “Hello” antlr4 project.


2.Add java project facet to the project.

3.Eclipse will 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.*;public class HelloRunner {public static void main( String[] args) throws Exception {// create a CharStream that reads from standard inputANTLRInputStream 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 lexerCommonTokenStream tokens = new CommonTokenStream(lexer);// create a parser that feeds off the tokens bufferHelloParser parser = 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.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.