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

【问题】

在折腾:

【记录】搭建ANTLR v4开发环境

的过程中,运行

grun Hello r -tree

结果无任何输出:

D:\DevRoot\IndustrialMobileAutomation\HandheldDataSetter\ANTLR\projects\demoHello>grun Hello r -tree

D:\DevRoot\IndustrialMobileAutomation\HandheldDataSetter\ANTLR\projects\demoHello>java org.antlr.v4.runtime.misc.TestRig Hello r -tree

【解决过程】

1.故意去把grun.bat改为:    

java org.antlr.v4.runtime.misc.TestRig $*

结果的确会出错:

D:\DevRoot\IndustrialMobileAutomation\HandheldDataSetter\ANTLR\projects\demoHello>java org.antlr.v4.runtime.misc.TestRig $*

java org.antlr.v4.runtime.misc.TestRig GrammarName startRuleName

[-tokens] [-tree] [-gui] [-ps file.ps] [-encoding encodingname]

[-trace] [-diagnostics] [-SLL]

[input-filename(s)]

Use startRuleName='tokens' if GrammarName is a lexer grammar.

Omitting input-filename makes rig read from stdin.

Exception in thread "main" java.lang.NullPointerException

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at org.antlr.v4.runtime.misc.TestRig.process(TestRig.java:157)

at org.antlr.v4.runtime.misc.TestRig.main(TestRig.java:142)

但是很明显,可以看到其用法了。

2.所以自己手动试了试:

java org.antlr.v4.runtime.misc.TestRig Hello r –tree

但是结果还是无任何输出。

3.又试了试:

java org.antlr.v4.runtime.misc.TestRig Hello r –trace

结果也是无输出。

4.后来是,把当前的JDK7卸载了,重新安装JDK6,结果问题依旧,还是无任何输出:

D:\DevRoot\IndustrialMobileAutomation\HandheldDataSetter\ANTLR\projects\demoHello>java -version

java version "1.6.0_37"

Java(TM) SE Runtime Environment (build 1.6.0_37-b06)

Java HotSpot(TM) Client VM (build 20.12-b01, mixed mode, sharing)

D:\DevRoot\IndustrialMobileAutomation\HandheldDataSetter\ANTLR\projects\demoHello>java org.antlr.v4.Tool

ANTLR Parser Generator Version 4.0

-o ___ specify output directory where all output is generated

-lib ___ specify location of grammars, tokens files

-atn generate rule augmented transition network diagrams

-encoding ___ specify grammar file encoding; e.g., euc-jp

-message-format ___ specify output style for messages in antlr, gnu, vs2005

-long-messages show exception details when available for errors and warnings

-listener generate parse tree listener (default)

-no-listener don't generate parse tree listener

-visitor generate parse tree visitor

-no-visitor don't generate parse tree visitor (default)

-package ___ specify a package/namespace for the generated code

-depend generate file dependencies

-D<option>=value set/override a grammar-level option

-Werror treat warnings as errors

-XdbgST launch StringTemplate visualizer on generated code

-XdbgSTWait wait for STViz to close before continuing

-Xforce-atn use the ATN simulator for all predictions

-Xlog dump lots of logging info to antlr-timestamp.log

D:\DevRoot\IndustrialMobileAutomation\HandheldDataSetter\ANTLR\projects\demoHello>dir

Volume in drive D has no label.

Volume Serial Number is CECE-859F

Directory of D:\DevRoot\IndustrialMobileAutomation\HandheldDataSetter\ANTLR\projects\demoHello

01/22/2013 05:55 PM <DIR> .

01/22/2013 05:55 PM <DIR> ..

01/22/2013 03:49 PM 235 Hello.g4

1 File(s) 235 bytes

2 Dir(s) 226,168,115,200 bytes free

D:\DevRoot\IndustrialMobileAutomation\HandheldDataSetter\ANTLR\projects\demoHello>antlr4 Hello.g4

D:\DevRoot\IndustrialMobileAutomation\HandheldDataSetter\ANTLR\projects\demoHello>java org.antlr.v4.Tool Hello.g4

D:\DevRoot\IndustrialMobileAutomation\HandheldDataSetter\ANTLR\projects\demoHello>javac Hello*.java

D:\DevRoot\IndustrialMobileAutomation\HandheldDataSetter\ANTLR\projects\demoHello>grun Hello r -tree

D:\DevRoot\IndustrialMobileAutomation\HandheldDataSetter\ANTLR\projects\demoHello>java org.antlr.v4.runtime.misc.TestRig Hello r -tree

Terminate batch job (Y/N)?

^C

D:\DevRoot\IndustrialMobileAutomation\HandheldDataSetter\ANTLR\projects\demoHello>grun Hello r -gui

D:\DevRoot\IndustrialMobileAutomation\HandheldDataSetter\ANTLR\projects\demoHello>java org.antlr.v4.runtime.misc.TestRig Hello r -gui

Terminate batch job (Y/N)?

D:\DevRoot\IndustrialMobileAutomation\HandheldDataSetter\ANTLR\projects\demoHello>

【总结】

实在不知道何故,所以只能另外再去试试antlr的ide了:

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


【后记 2013-07-05】

1.后续已经解决了,如何测试语法是否正确,可以输入测试内容的问题。

详见: 【记录】搭建ANTLR v4开发环境



发表评论

电子邮件地址不会被公开。 必填项已用*标注

无觅相关文章插件,快速提升流量