编译 ANTLRWorks 生成的类文件
我正在使用 ANTLRWorks 创建 ANTLR 语法。 我有一个有效的语法,并且还生成了解析器和词法分析器源文件。 我还尝试调试生成的代码,并且输出与调试器输出中的预期一致。
但是,当我尝试调用调试器生成的 __Test__ 类时,控制台中没有出现任何内容。 我已经正确设置了类路径,因为我可以使用相同的类路径成功编译 __Test__.java 。
会有什么问题呢? 有没有关于使用antlr和antlrworks编写和编译示例解析器的明确教程?
I am using ANTLRWorks to create ANTLR grammars. I have a valid grammar and the parser and lexer source files are generated as well. I have also tried debugging the generated code and the output is as expected in the debugger output.
But when I try to invoke the __Test__ class generated by the debugger nothing is coming up in the console. I have properly set up the classpath as I can successfully compile the __Test__.java with the same classpath.
What would be the problem? Is there any clear tutorial for writing and compiling a sample parser with antlr and antlrworks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您期望控制台上出现什么?
看看这个项目。 ANTLRWorks 生成的解析器位于此处。 从 POM 中的依赖关系可以看出,您需要确保 antlr 在类路径中。 然后使用解析器,如 此类。
这应该足以让你的东西正常工作。
What do you expect on the console to come up?
Have a look at this project. The ANTLRWorks generated parser is here. As you can see from the dependencies in the POM you need to make sure antlr is in the classpath. Then you use the parser as shown in this class.
That should be enough to get your stuff working as well.
ANTLRWorks 生成测试类,用于创建返回 ANTLRWorks 的套接字连接,因此它们无法从控制台使用。 您可以编辑生成的测试类以不使用调试端口(套接字连接)选项。
要编辑的行是:
您可以将其更改为:
它使用调试侦听器对象而不是端口,“null”意味着您没有为其提供调试侦听器,因此调试输出将被忽略。 您可以编写自己的调试侦听器以将消息打印到控制台。
有关详细信息,请参阅 ANTLR 文档:http://www.antlr.org/api/ Java/命名空间.html
ANTLRWorks generates test classes that create a socket connection back to ANTLRWorks, so they aren't usable from the console. You can edit the generated test class to not use the debug port (socket connection) option.
The line to edit is:
You can change it to:
which uses a debug listener object instead of a port, and the "null" means you're not giving it a debug listener, so debug output is ignored. You could write your own debug listener to print out messages to the console.
See the ANTLR documentation for more information: http://www.antlr.org/api/Java/namespaces.html