搭建antlr4.2.2开发环境

来源:互联网 发布:linux lcd驱动移植 编辑:程序博客网 时间:2024/06/14 05:50

1:kepler版本的eclipse安装maven:http://download.eclipse.org/technology/m2e/releases/1.0/1.0.0.20110607-2117
2:编辑pom.xml,加入如下依赖: 
  <dependencies>
  <dependency>
  <groupId>org.antlr</groupId>
  <artifactId>antlr4-runtime</artifactId>
  <version>4.2.2</version>
  </dependency>
  <dependency>
  <groupId>org.antlr</groupId>
  <artifactId>antlr4</artifactId>
  <version>4.2.2</version>
</dependency>
  </dependencies>
3:安装antlr4.2.2的eclipse插件(参考:https://github.com/jknack/antlr4ide)
1,插件安装环境:
  • Eclipse 4.3 (Kepler)
  • XText 2.5.x/2.6
 2,安装:

ANTLR 4 IDE isn't available in the Eclipse Market Place yet, so you MUST installed in the old way. Please follow these instructions:

  • Open Eclipse Kepler (4.3)
  • Go to: Help > Install New Software...
  • You need to Install XText 2.5.x/2.6
  • Copy and paste this url: http://download.eclipse.org/modeling/tmf/xtext/updates/composite/releases/ in theWork with text field
  • Hit Enter
  • Choose XText 2.5.4. NOTE: DON'T confuse with Xtend, you must choose Xtext
  • Now, copy and paste this url: http://dl.bintray.com/jknack/antlr4ide in the Work with text field
  • Choose: ANTLR 4 SDK IDE. NOTE: If you don't see it, please unmark the Group items by category option
  • Click: Next and follow the normal Eclipse installation procedure
3,使用:
The new IDE is very simple to use all the files with a *.g4 extension will be opened by the ANTLR 4 Editor. So, just open a *.g4 file and play with it
4,产生代码:

Code is automatically generated on save if the grammar is valid. You can turn off this feature by going to: Window > Preferences > ANTLR 4 > Tool and uncheck the "Tool is activated" option. From there you can configure a couple more of options.

You can find the generated code in the target/generated-sources/antlr4 (same directory as antlr4-maven-plugin)

5,手动产生代码:

You can fire a code generation action by selecting a *.g4 file from the Package Explorer, right click: Run As > ANTLR 4.

A default ANTLR 4 launch configuration will be created. You can modify the generated launch configuration by going to: Run > External Tools > External Tools Configurations... from there you will see the launch configuration and how to set or override code generation options

4:插件的使用:

1,可以自动生成语法树:

搭建antlr4.2.2开发环境 - cyxinda - JAVA技术分享
 

2,可以根据.g文件自动生成图形化的文法结构:

搭建antlr4.2.2开发环境 - cyxinda - JAVA技术分享
 


原创粉丝点击