ANTLR 解析器挂在 proxy.handshake 调用上

发布于 2024-08-13 04:37:14 字数 1035 浏览 7 评论 0原文

我正在尝试让基本的 ECMAScript 解析器工作,并找到了 ECMAScript 3 的完整 ANTLR 语法,看起来编译正常并生成适当的 Lexer/Parser/Walker Java 文件。
(在 Eclipse 3.5 的 ANTLR IDE 插件 中运行)

但是,当实际尝试将它与一些简单的测试代码一起使用时(遵循ANTLR wiki 上的指南),它只是挂起尝试创建解析器:

CharStream MyChars = new ANTLRFileStream(FileName); // FileName is valid
ES3Lexer MyLexer = new ES3Lexer(MyChars);
CommonTokenStream MyTokens = new CommonTokenStream(MyLexer);
MyTokens.setTokenSource(MyLexer);
ES3Parser MyParser = new ES3Parser( MyTokens ); // hangs here
ES3Parser.program_return MyReturn = MyParser.program();

我已经将问题追踪到 ES3Parser 构造函数内部,它在其中调用函数 proxy.handshake() - 在此行之前我可以成功执行 System.out.println("text") 但之后我什么也没得到。

那么,我该如何找出它挂起的原因并停止它 - 或者甚至只是绕过这一部分(我可以/应该禁用调试吗?) - 只要它可以工作并允许我继续做有用的事情。

I am attempting to get a basic ECMAScript parser working, and found a complete ANTLR grammar for ECMAScript 3, which appears to compile ok and produces the appropriate Lexer/Parser/Walker Java files.
(Running inside ANTLR IDE plugin for Eclipse 3.5)

However, when actually trying to use it with some simple test code (following guide on ANTLR wiki), it just hangs when trying to create the parser:

CharStream MyChars = new ANTLRFileStream(FileName); // FileName is valid
ES3Lexer MyLexer = new ES3Lexer(MyChars);
CommonTokenStream MyTokens = new CommonTokenStream(MyLexer);
MyTokens.setTokenSource(MyLexer);
ES3Parser MyParser = new ES3Parser( MyTokens ); // hangs here
ES3Parser.program_return MyReturn = MyParser.program();

I've tracked down the problem to inside the ES3Parser constructor, where it's calling the function proxy.handshake() - before this line I can successfully do System.out.println("text") but after it I get nothing.

So, how do I go about finding out why it's hanging, and stopping it - or even just bypassing this section (can/should I disable debugging?) - so long as that lets it work and allows me to get on with doing useful stuff.

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

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

发布评论

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

评论(2

情未る 2024-08-20 04:37:15

Antlr 中有一个 -debug 选项,可以生成额外的代码,从而允许远程调试。当代码在调用时暂停时

dbg.Handshake();

,它正在等待远程调试器连接到它。在 AntlrWorks 中您可以使用 Run -->远程调试选项可连接到它并单步调试代码。

如果您不想使用远程调试功能,请从 ANTLR 选项文本框中删除 -debug 选项。

文件-->偏好设置 -->一般--> ANTLR 选项

There is a -debug option in Antlr that causes additional code to generated allowing for remote debugging. When the code pauses on the the

dbg.Handshake();

call, it is waiting for the remote debugger to connect to it. In AntlrWorks you can use the Run --> Remote Debug option to connect to it and step through the code.

If you don't wish to use the remote debugging functionality, remove the -debug option from the ANTLR options text box.

File --> Preferences --> General --> ANTLR Options

帝王念 2024-08-20 04:37:15

我通过在 ANTLR IDE 插件中禁用调试代码的生成解决了这个问题。

此设置位于“Windows”>“首选项> ANTLR>代码生成。

展开常规部分并取消选中调试选项:

https://www.bpsite.net/misc/eclipse-antlr-debug.png
(来源:bpsite.net

I solved this by disabling the generation of debug code within the ANTLR IDE plugin.

The setting for this is under Windows > Preferences > ANTLR > Code Generation.

Expand the General section and untick the debug option:

https://www.bpsite.net/misc/eclipse-antlr-debug.png
(source: bpsite.net)

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