最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【记录】尝试使用ANTLRWorks 2.0去进行ANTLR开发

ANTLR crifan 4789浏览 0评论

【背景】

在折腾:

【未解决】antlr v4中运行grun Hello r -tree,结果无输出

的过程中,无果,cmd下面用grun还是无任何输出。

所以现在接着去试试,使用antlrworks 2.0去试试。


1.之前从:

http://tunnelvisionlabs.com/products/antlrworks

下载到最新的antlrworks:

2013-01-16-antlrworks-2.0-b1.zip

2.解压后,找到,当前适合x64的win7的执行文件:

2013-01-16-antlrworks-2.0-b1\antlrworks2\bin\antlrworks264.exe

运行。

3.然后一点点去试试。

创建一个Hello.g4文件,内容为:

// Define a grammar called Hello
grammar Hello;
r  : 'hello' ID ;       // match keyword hello followed by an identifier
ID : [a-z]+ ;           // match lower-case identifiers
WS : [ \t\n]+ -> skip ; // skip spaces, tabs, newlines

 

4.然后去:

Run->Generate Recognizer

run generate recognizer

选择输出路径,默认即选择当前的文件夹了:

choose output directory

 

接着去:

features wizard features

advanced wizard

然后得到输出:

Arguments: [-o, D:\DevRoot\IndustrialMobileAutomation\HandheldDataSetter\ANTLR\projects\demo2Hello, -atn, -encoding, GBK, -listener, -visitor, -XdbgST, D:\DevRoot\IndustrialMobileAutomation\HandheldDataSetter\ANTLR\projects\demo2Hello\Hello.g4]

5.看到编码是设置的是GBK,所以自己试了试,自己手动用Notepad++将其改为UTF-8

结果其输出的结果中,还是GBK。

注:后来的后来,无意中从About中看到的信息是:

Product Version: ANTLRWorks2 20130112-0412fbb77e2b

Java: 1.7.0_11; Java HotSpot(TM) 64-Bit Server VM 23.6-b04

Runtime: Java(TM) SE Runtime Environment 1.7.0_11-b21

System: Windows 7 version 6.1 running on amd64; GBK; en_US (antlrworks2)

User directory: C:\Users\CLi\AppData\Roaming\.antlrworks2\dev

Cache directory: C:\Users\CLi\AppData\Roaming\.antlrworks2\dev\var\cache

所以才猜测,此处的GBK,应该是检测到当前系统默认的编码,而不是当前文件所使用的编码。

6.然后又折腾了,去运行:

run in testrig

设置Start Rule为r,即程序的入口处,类似于C代码中的main函数:

testrig options

然后就可以看到输出效果了,会弹出窗口显示出运行结果。但是结果出错了。

7.详细折腾过程,参见:

【已解决】ANTLRWorks 2.0编译g4文件出现警告:warning: Supported source version ‘RELEASE_6’ from annotation processor

【未解决】ANTLRWorks 2.0编译Hello.g4文件结果出错:line 1:0 token recognition error at: ‘W’

 

【总结】

后来实在不行,只有换用旧版本的antlrworks 1.5去试试了:

【记录】尝试使用ANTLRWorks 1.5开发

转载请注明:在路上 » 【记录】尝试使用ANTLRWorks 2.0去进行ANTLR开发

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.174 seconds, using 22.13MB memory