最新消息:20210917 已从crifan.com换到crifan.org

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

ANTLR crifan 3871浏览 0评论

背景

想要使用ANTLR的IDE,即ANTLRWorks去开发ANTLR。

最新的官网

http://www.antlr.org/

所找到的:

http://tunnelvisionlabs.com/products/demo/antlrworks

只能下载到最新的ANTLRWorks2,经过尝试,很不好用。都没有调试功能。

所以才打算换用之前旧的1.5版本的。

下载ANTLRWorks 1.5

1.截至2013-01-24,之前的

http://www.antlr.org/works/

http://www.antlr.org/download/

http://www.antlr.org/download/antlrworks-1.5.zip

等地址,全都失效了。即找不到1.5版本的antlrworks了。

2.最多的也只是从:

https://github.com/antlr/antlrworks/tags

找到对应的ANTLRWorks 1.5的源码:

https://github.com/antlr/antlrworks/archive/antlrworks-1.5.zip

但是也不会编译,无法运行。

3. 后来好不容易,从:

http://download.openpkg.org/components/cache/antlr/

找到了我们所要的:

 antlrworks-1.5.jar 05-Jan-2013 23:57 2.6M

使用ANTLRWorks 1.5

下载到之后antlrworks-1.5.jar

双击运行即可:

antlrworks 1.5

选择是ANTLR 3的语法:

antlr 3 grammar g

使用创建向导,新建一个语法:

 

new grammar wizard

 

然后就可以看到新建好的语法文件了:

new created grammar

然后拷贝一个别人的代码:

grammar ExprSimple;

options {
	output = AST;
	ASTLabelType = CommonTree; // type of $stat.tree ref etc...
}

INT		:	'0'..'9'+ ;
NEWLINE	:	'\r'? '\n' ;
WS		:	(' '|'\t')+ {skip();} ;

prog	:	stat+ ;

stat	:	expr NEWLINE	-> expr
		;
	
expr	:	multExpr (('+'^|'-'^) multExpr)*
		;

multExpr:	atom ('*'^ atom)* ;

atom	:	INT
		|	'('! expr ')'!
		;

变成:

writed full code

然后就可以去调试了。

先去保存当前新建的文件:

file save as for g file

saved g file

使用ANTLRWorks去调试语法文件

1.Run->Debug

run debug

结果编译出错,详细过程参见:

【已解决】ANTLRWorks 1.5编译代码出错:Compiler failed with result code 1

 

2. 再次debug:

second debug

可以看到,Start Rule是INT:

start rule is INT

 

3. 所以,改为对应的,此处的起始需要执行的地方,即prog,再写上测试语句。

并且,通过Notepad++,看到当前.g文件是CRLF:

g file is cr lf

所以,再选择为Windows的CR LF:

input test code and prog cr lf

然后OK。还是会出错。先不管。

4. 然后再去切换到对应的Debugger界面,然后再去点Debug:

choose debuger tab click debug

begin to debug

结果却出错:

Cannot launch the debuggerTab Time-out waiting to connet to the remote parser

详细折腾过程参见:

【未解决】ANTLRWorks调试出错:Cannot launch the debuggerTab. Time-out waiting to connect to the remote parser

 

5.后来的后来,折腾N次之后,终于在折腾:

【已解决】ANTLRWorks 1.5编译代码出错:Compiler failed with result code 1

的过程中,确定了:

当前antlrworks 1.5,和当前环境:

64位win7+64位的JDK7,不兼容,

需要使用更低的,比如

antlrworks-1.4.3.jar

antlrworks-1.4.2.jar

antlrworks-1.4.jar

antlrworks-1.3.jar

antlrworks-1.2.2.jar

都是可以正常使用的。

 

【总结】

antlrworks 1.5的兼容性有点问题,需要换用更低版本的,1.4或1.3或1.2系列版本的,都是可以正常使用的。

转载请注明:在路上 » 【记录】尝试使用ANTLRWorks 1.5开发

发表我的评论
取消评论

表情

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

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

网友最新评论 (1)

    100 queries in 0.181 seconds, using 23.40MB memory