- Eclipse 4.3 (Kepler)
- XText 2.5.x/2.6
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
*.g4
extension will be opened by the ANTLR 4 Editor. So, just open a
*.g4
file and play with it
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技术分享 搭建antlr4.2.2开发环境 - cyxinda - JAVA技术分享](http://img0.ph.126.net/1Ijc4MfT9rMHGHrf5taL3g==/1622421765861155187.jpg)
2,可以根据.g文件自动生成图形化的文法结构:
![搭建antlr4.2.2开发环境 - cyxinda - JAVA技术分享 搭建antlr4.2.2开发环境 - cyxinda - JAVA技术分享](http://img0.ph.126.net/CTk4Z123BP3erXnvoId9Pw==/4940448791325816231.jpg)