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

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

ANTLR crifan 6356浏览 0评论

【问题】

在折腾:

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

的过程中,用ANTLRWorks 2.0编译运行Hello.g4,结果出现警告和错误。

先是解决了警告了:

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

但是还是有错误。

完整log为:

Compiling grammar files…

Arguments: [Hello, r, -tokens, -tree, -gui, D:\DevRoot\IndustrialMobileAutomation\HandheldDataSetter\ANTLR\projects\demo2Hello\Hello.tokens]

line 1:0 token recognition error at: ‘W’

line 1:1 token recognition error at: ‘S’

line 1:2 token recognition error at: ‘=’

line 1:3 token recognition error at: ‘3’

line 1:4 token recognition error at: ‘\r’

line 2:0 token recognition error at: ‘I’

line 2:1 token recognition error at: ‘D’

line 2:2 token recognition error at: ‘=’

line 2:3 token recognition error at: ‘2’

line 2:4 token recognition error at: ‘\r’

line 3:0 token recognition error at: ‘T’

line 3:1 token recognition error at: ‘_’

line 3:2 token recognition error at: ‘_’

line 3:3 token recognition error at: ‘0’

line 3:4 token recognition error at: ‘=’

line 3:5 token recognition error at: ‘1’

line 3:6 token recognition error at: ‘\r’

line 4:0 token recognition error at: ”’

line 4:6 token recognition error at: ”’

line 4:7 token recognition error at: ‘=’

line 4:8 token recognition error at: ‘1’

line 4:9 token recognition error at: ‘\r’

[@0,21:25=’hello’,<1>,4:1]

[@1,31:30='<EOF>’,<-1>,5:0]

line 5:0 missing ID at ‘<EOF>’

(r hello <missing ID>)

 

【解决过程】

1.不论是JDK 6 还是JDK 7,都试过了,都还是没用。

2.官网中也有人报告此错误:

Still seeing errors in STDErr after removing ErrorListeners

但是貌似木有给出解决办法,就close了。。。

3.后来试了试,把对应的

Generate listener取消选择

unselect generate listener

 

log为:

Arguments: [-o, D:\DevRoot\IndustrialMobileAutomation\HandheldDataSetter\ANTLR\projects\v2\demoHello, -encoding, GBK, -no-listener, -visitor, D:\DevRoot\IndustrialMobileAutomation\HandheldDataSetter\ANTLR\projects\v2\demoHello\Hello.g4]

结果问题依旧。

 

【总结】

未搞定。

最后是换用旧版本的1.x的antlrworks:

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

 


【后记 2013-03-14】

1.经过别人提示,去随便建立了个测试文件,比如叫

testInput.txt

内容很简单,为:

hello antlrV4

然后再去测试,然后把inputfile设置为此testInput.txt:

set inputfile as test input

然后就可以正常执行解析过程,显示出解析后的树形结构了:

with input test file now can show parse result tree

 

 

【总结2】

经过折腾antlr v3,得知,

antlr v3的IDE,antlrworks 1.x版本中,

对于测试内容的输入,支持两种方式:

  • 文本Text方式:粘贴要测试的文本即可
  • 输入文件input file:选择要作为测试输入的文件

相对来说,很人性化,很方便。

同时,支持单步调试,并且对于解析后的内容,也支持多种显示方式

  • 从顶到下的树状显示(含错误详细信息)
  • 左右方式的树状显示

而对于新的antlr v4的IDE,即此基于Netbeans的开发环境,

其功能,真的是弱爆了,不仅是输入内容方式,只支持文件输入,不支持文本输入,

而且解析后的内容,仅仅只是显示一个树状结构(即,此处弹出的(估计是基于java的swt)窗口)

而且其他更多调试方面的功能,基本都没有。

所以,从开发支持方面来说,antlr v4的基于Netbeans的这个IDE,基本上,属于绝对的不推荐。

除非以后,antlrworks 1.x版本中的各种调试功能,都加进来了,才值得考虑使用。

转载请注明:在路上 » 【已解决】ANTLRWorks 2.0编译Hello.g4文件结果出错:line 1:0 token recognition error at: ‘W’

发表我的评论
取消评论

表情

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

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (2)

  1. 遇到了相同的问题,后来自己解决了。仔细想一下为什么打开一个g4文件,选择Run in TestRig之后还需要input file。其实input file是一个输入文件。新建一个txt,输入hello xxx保存。然后将这个txt作为input file即可
    一叶知秋11年前 (2013-03-14)回复
    • 谢谢提示。 关于我要说的感慨,见更新后的帖子。
      crifan11年前 (2013-03-14)回复
87 queries in 0.188 seconds, using 22.15MB memory