【记录】继续折腾如何使用在Eclipse中调试Antlr项目

【背景】

之前已经折腾了:

【记录】使用Eclipse开发Antlr:如何调试antlr项目

但是没搞定。

下面继续折腾。


1。后来,经过后续折腾,发现:

都使用3.3版本的话:

  • 代码编译时导入3.3的库:
    • 右击antlr项目->Properties->Java Build Path->Libraries->Add External JARs->添加antlr-3.3-complete.jar
    • JARs and class folders on the build path added 3.3 antlr jar_thumb
  • 以及选择3.3作为解析库:
    • Window->Preferences->ANTLR->Builder->Installed Packages->Add->选择antlr-3.3-complete.jar->出现 ANTLR Parser Generator Version 3.3 Nov 30,2010 12:50:56
    • ANTLR Parser Generator Version 3.3_thumb

结果重新去:

Project->Clean

后,重新右击antlr项目,去:

Build Project,

结果会出错:

ANTLR Parser Generator 3.3 Nov 30, 2010 12:50:56.
Using project classpath: Yes.
Grammar: D:\DevRoot\android\android_root\HartEddl\HartEddl.g
error(10): internal error: Exception expecting ‘*’, found ‘8’@org.antlr.grammar.v2.ANTLRLexer.nextToken(ANTLRLexer.java:346): unexpected stream error from parsing /HartEddl/HartEddl.g
error(150): grammar file /HartEddl/HartEddl.g has no rules
error(10): internal error: /HartEddl/HartEddl.g : java.lang.IllegalStateException: java.lang.NullPointerException
org.deved.antlride.runtime.AntlrErrorListener$DynamicToken.invokeMethod(AntlrErrorListener.java:59)
org.deved.antlride.runtime.AntlrErrorListener$DynamicToken.getLine(AntlrErrorListener.java:64)
org.deved.antlride.runtime.AntlrErrorListener.report(AntlrErrorListener.java:131)
org.deved.antlride.runtime.AntlrErrorListener.message(AntlrErrorListener.java:113)
org.deved.antlride.runtime.AntlrErrorListener.error(AntlrErrorListener.java:103)
org.antlr.tool.ErrorManager.syntaxError(ErrorManager.java:803)
org.antlr.grammar.v2.AssignTokenTypesWalker.reportError(AssignTokenTypesWalker.java:110)
org.antlr.grammar.v2.AssignTokenTypesWalker.grammar(AssignTokenTypesWalker.java:223)
org.antlr.tool.CompositeGrammar.assignTokenTypes(CompositeGrammar.java:335)
org.antlr.Tool.process(Tool.java:451)
org.deved.antlride.runtime.Tool2.main(Tool2.java:24)
3 errors

BUILD FAIL
Total time: 302 milliseconds

internal error Exception expecting  found  org.antlr.grammar.v2.ANTLRLexer.nextToken_thumb

很明显,是3.3的版本,此处无法正常编译。

而都换成3.5版本的:

ANTLR Parser Generator Version 3.5_thumb

JARs and class folders on the build path added 3.5 antlr jar_thumb

至少是可以编译成功的:

ANTLR Parser Generator 3.5 ${buildNumber}.
Using project classpath: Yes.
Grammar: D:\DevRoot\android\android_root\HartEddl\HartEddl.g
BUILD SUCCESSFUL
Total time: 1 second

但是,就会出现上面的错误:

当去Debug(Java)时,就会出现:

unable to connect to ANTLR Debugger,Connection refused: connect

的错误。

2.再都去换成3.4的试试,结果也是可以正常编译的:

ANTLR Parser Generator 3.4 Jul 19, 2011 11:35:12.
Using project classpath: Yes.
Grammar: D:\DevRoot\android\android_root\HartEddl\HartEddl.g
BUILD SUCCESSFUL
Total time: 1 second

然后再去试试Debug(Java)和Run(Java),结果错误依旧:

debug无输出

run出现之前的错误。

3.再去:

http://www.antlr3.org/download/

下载一个3.2的:

antlr-3.2.jar

结果最后和3.3一样,编译就出错:

ANTLR Parser Generator 3.2 Sep 23, 2009 12:02:23.
Using project classpath: Yes.
Grammar: D:\DevRoot\android\android_root\HartEddl\HartEddl.g
error(10): internal error: Exception expecting ‘*’, found ‘8’@org.antlr.grammar.v2.ANTLRLexer.nextToken(ANTLRLexer.java:347): unexpected stream error from parsing /HartEddl/HartEddl.g
error(150): grammar file /HartEddl/HartEddl.g has no rules
error(10): internal error: /HartEddl/HartEddl.g : java.lang.IllegalStateException: java.lang.NullPointerException
org.deved.antlride.runtime.AntlrErrorListener$DynamicToken.invokeMethod(AntlrErrorListener.java:59)
org.deved.antlride.runtime.AntlrErrorListener$DynamicToken.getLine(AntlrErrorListener.java:64)
org.deved.antlride.runtime.AntlrErrorListener.report(AntlrErrorListener.java:131)
org.deved.antlride.runtime.AntlrErrorListener.message(AntlrErrorListener.java:113)
org.deved.antlride.runtime.AntlrErrorListener.error(AntlrErrorListener.java:103)
org.antlr.tool.ErrorManager.syntaxError(ErrorManager.java:805)
org.antlr.grammar.v2.AssignTokenTypesWalker.reportError(AssignTokenTypesWalker.java:110)
org.antlr.grammar.v2.AssignTokenTypesWalker.grammar(AssignTokenTypesWalker.java:223)
org.antlr.tool.CompositeGrammar.assignTokenTypes(CompositeGrammar.java:334)
org.antlr.Tool.process(Tool.java:450)
org.deved.antlride.runtime.Tool2.main(Tool2.java:24)
3 errors

BUILD FAIL
Total time: 334 milliseconds

4.不过,关于-debug参数的事情,倒是搞清楚了,就是和antlrworks中Run->Debug一样,都是:

如果加了-debug参数,则生成的Parser就变成DebugParser了。

此处,即,如果选上了-debug参数:

enable debug to generate debug parser_thumb

则生成的parser,此处为HartEddlParser.java中,就是DebugParser了:

@SuppressWarnings("all")
public class HartEddlParser extends DebugParser {
	public static final String[] tokenNames = new String[] {

如果没有选上上述的-debug,则生成的就是不带Debug的Parser:

@SuppressWarnings("all")
public class HartEddlParser extends Parser {
	public static final String[] tokenNames = new String[] {

5.又去试了很多,从:

debug as java application then can choose_thumb

然后会出现对话框,让你选择使用哪个。

试了:

try Interp org antlr tool but no output_thumb

try GrammarSpelunker org antlr tool but no output_thumb

均没有输出。

6.又试了:

choose Tool - org antlr gunit swingui_thumb

结果出现了个gUnitEditor:

show gUnitEditor_thumb

然后打开已有的g文件:

open an existed g file grammar_thumb

选择对应入口的rule,且设置好对应的输入是一个文件,输出是AST:

choose main entry rule of startParse_thumb

然后点击Run,但是出错了:

after set input test file then run but fail_thumb

说是lexer没有找到。

但是还是不知道如何设置此lexer。

7.



发表评论

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

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