Antlr 问题:无法从 ANTLRWorks 获取 Antlr 工具来编译简单文件

发布于 2024-10-24 21:04:59 字数 1164 浏览 4 评论 0原文

这是语法文件:

grammar fred;
test    :   'fred';

这是启动该工具的批处理文件:

SET JAVA_HOME=C:\Program Files\Java\jdk1.6.0_24
SET PATH=%PATH%;%JAVA_HOME%\bin
SET ANTLR_HOME=c:/users/don/workspace/antlrAssign/lib/
java -cp %ANTLR_HOME%/antlr-3.3-complete.jar  antlr.Tool fred.g

这是结果:

ANTLR Parser Generator   Version 2.7.7 (20060906)   1989-2005
fred.g:1:1: unexpected token: grammar
error: Token stream error reading grammar(s):
fred.g:3:19: expecting ''', found 'r'
fred.g:1:1: rule grammar trapped:
fred.g:1:1: unexpected token: grammar
TokenStreamException: expecting ''', found 'r'

之前的帖子引用了“org.antlr.Tool”,但 3.3 jar 的位置如上。这个想法是创建树解析器的调试版本,根据文档,您必须使用命令行工具。

有人见过这个吗?我疯了吗?它有两行长,在文件的第一个单词处就消失了。

当然这是在antlrworks中编译的。

感谢您的帮助,我无法再对我的药物进行任何调整。

跟进:

我发现如果你使用 Run --> ANTLRWORKS 中的调试菜单选项它将生成树解析器的调试版本,但在我手中,命令行工具不会。生成的调试源位于生成的输出文件夹中。在 ANTLRWORKS 中,要获取非调试版本,请使用“生成”菜单选项。在 Eclipse 中使用树解析器的调试版本,启动测试工具并等待,然后通过在树语法解析器文件上运行远程调试与 ANTRWORKS 连接。它遍历了树的解析器,并给了我一个不匹配的树节点错误(不是解析器错误,这很好,因为我正在调试树解析器)。所以现在我只需要找出我还做过哪些愚蠢的事情。除了我之外还有其他人。

Here is the grammar file:

grammar fred;
test    :   'fred';

Here is the batch file to launch the tool:

SET JAVA_HOME=C:\Program Files\Java\jdk1.6.0_24
SET PATH=%PATH%;%JAVA_HOME%\bin
SET ANTLR_HOME=c:/users/don/workspace/antlrAssign/lib/
java -cp %ANTLR_HOME%/antlr-3.3-complete.jar  antlr.Tool fred.g

Here's the result:

ANTLR Parser Generator   Version 2.7.7 (20060906)   1989-2005
fred.g:1:1: unexpected token: grammar
error: Token stream error reading grammar(s):
fred.g:3:19: expecting ''', found 'r'
fred.g:1:1: rule grammar trapped:
fred.g:1:1: unexpected token: grammar
TokenStreamException: expecting ''', found 'r'

Prior postings refer to "org.antlr.Tool" but the 3.3 jar has it located as above. The idea was to create a debug version of a tree parser, and according to the documentation, you have to use the command line tool.

Has anyone seen this before? Am I nuts? It's two lines long and its dying on the first word in the file.

Of course this compiles in antlrworks.

Any help appreciated, I can't afford any more adjustments to my medications.

Follow up:

I found that if you use the Run --> Debug menu option in ANTLRWORKS it will produce a debug version of a tree parser, but in my hands the command line tool does not. The debug source produced lives in the output folder for generation. In ANTLRWORKS to get a non debug version use the Generate menu option. Using the debug version of the tree parser in eclipse, fire up the test harness and wait, then connect with ANTRWORKS via Run Remote Debug, on the treegrammar parser file. It walked through the parser for the tree and gave me a mismatched tree node error (not a parser error, which is good because I'm debugging the tree parser). So now I just need to find what other dumb thing I've done. HTH somebody besides me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

写下不归期 2024-10-31 21:04:59

之前的帖子引用了“org.antlr.Tool”,但 3.3 jar 的位置如上。

旧的 ANTLR 2.x Tool 类 (antlr.Tool) 仍然包含在 3.x 版本的 ANTLR 中,但您需要使用 ANTLR 3 .x Tool (位于:org.antlr.Tool)用于您的语法,因为它是 3.x 语法。

Prior postings refer to "org.antlr.Tool" but the 3.3 jar has it located as above.

The old ANTLR 2.x Tool class (antlr.Tool) is still included in the 3.x version(s) of ANTLR, but you need to use the ANTLR 3.x Tool (located: org.antlr.Tool) for your grammar since it is a 3.x grammar.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文