[英]Testing ANTLR Grammar
So I've been making a grammar in Eclipse with ANTLR v3.4 and I've made one that works and I want to make sure when I edit it everything still works. 所以我一直在使用ANTLR v3.4在Eclipse中制作语法,我已经制作了一个可行的语法,我想确保在编辑它时一切仍然有效。 I can go into the interpretter everytime but that seems like a huge waste of time.
我每次都可以进入解释器,但这似乎是浪费时间。
Questions: I've read about gunit but the link it gives to download gUnit: ( http://antlr.org/hudson/job/gUnit/org.antlr $gunit/lastSuccessfulBuild/ ) doesn't work. 问题:我已经阅读了关于gunit但是下载gUnit的链接:( http://antlr.org/hudson/job/gUnit/org.antlr $ gunit / lastSuccessfulBuild /)不起作用。 How can I get gUnit.
我怎样才能获得gUnit。 What is the best way to test grammars?
测试语法的最佳方法是什么? Is it actually gUnit or should I just do java tests like jUnit tests?
它实际上是gUnit还是我应该像jUnit测试一样进行java测试?
I recently completed two ANTLR3 assignments (I'm working on my Master's in Computer Science) using Eclipse. 我最近使用Eclipse完成了两项ANTLR3任务(我正在攻读计算机科学硕士学位)。 I found no single document that had a process for installing, configuring, writing, and debugging a grammar in Eclipse.
我发现没有一个文档有一个在Eclipse中安装,配置,编写和调试语法的过程。 So, after working through various issues, I found the easiest thing to do was to stay in Eclipse for testing.
因此,在解决了各种问题之后,我发现最简单的事情就是留在Eclipse中进行测试。
To use the process I have come to use (outlined below) you must first have the ANTLR IDE v2.1.2 installed. 要使用我开始使用的过程(如下所述),您必须先安装ANTLR IDE v2.1.2。 Add it right from inside Eclipse Indigo: http://antlrv3ide.sourceforge.net/updates .
从Eclipse Indigo中添加它: http : //antlrv3ide.sourceforge.net/updates 。 This site also has some useful doc on using the ANTLR IDE.
该站点还有一些关于使用ANTLR IDE的有用文档。 Once installed, the IDE has to be configured.
安装后,必须配置IDE。 Video tutorials are a bit out of date but helpful.
视频教程有点过时但很有帮助。 See a detailed how to guide on configuring ANTLR IDE in Eclipse .
查看有关如何在Eclipse中配置ANTLR IDE的详细指南。 The main configuration item is the java output folder.
主要配置项是java输出文件夹。 Do this in Eclipse by going to Windows, Preferences, ANTLR, Code Generator, check Project relative folder and in the Output folder name box type a folder name (mine is called "antlr-java", others use "generated").
在Eclipse中执行此操作,方法是转到Windows,首选项,ANTLR,代码生成器,检查项目相关文件夹,然后在输出文件夹名称框中键入文件夹名称(我的名称为“antlr-java”,其他人使用“generated”)。
Test/Debug Process for ANTLR in Eclipse Indigo with ANTLR IDE 使用ANTLR IDE在Eclipse Indigo中测试/调试ANTLR的过程
The question is old, but I'm leaving a reference for completeness: 问题是陈旧的,但我要留下完整性的参考:
For me, the gUnit was useless. 对我来说,gUnit毫无用处。 So I managed to find how test only the Lexer and then, only the parser.
所以我设法找到了如何只测试Lexer然后只测试解析器。
I answered it here: https://stackoverflow.com/a/53884851/976948
我在这里回答: https : //stackoverflow.com/a/53884851/976948
Basically, there are links for 2 articles about how to test it: 基本上,有2篇文章的链接有关如何测试它:
You can download gUnit there but I think there is no latest version... 你可以在那里下载gUnit ,但我认为没有最新版本......
Try Jarvana ... Latest version there is 3.4: http://repo1.maven.org/maven2/org/antlr/gunit/3.4/gunit-3.4.jar 试试Jarvana ...最新版本有3.4: http : //repo1.maven.org/maven2/org/antlr/gunit/3.4/gunit-3.4.jar
@Dave Newton is right. @Dave Newton是对的。 As of ANTLR v3.1, gUnit is included in the main ANTLR Tool jar as is stated there .
由于ANTLR V3.1中,gUnit包括在ANTLR工具主要水瓶中陈述存在 。
I didn't know for gUnit till now. 到目前为止我还不知道gUnit。 It looks great for grammar testing, but I think that JUnit tests will do their job to...
它看起来很适合语法测试,但我认为JUnit测试将完成他们的工作......
This is the first time I heard of gUinit and read up on it. 这是我第一次听说gUinit并阅读它。 (I don't use ANTLR much.) It sounds interesting, but half useless.
(我不太使用ANTLR。)听起来很有趣,但是一半没用。
My approach to validating grammars is to actually validate the the entire parser with "normal" unit tests. 我验证语法的方法是用“正常”单元测试来实际验证整个解析器。 The thing is, you should have unit tests in place anyway and the tests that check for grammar regression you just add it there.
问题是,无论如何你都应该进行单元测试,检查语法回归的测试只需将其添加到那里。 The thing is in my experience that most errors come in semantic analysis and reduction and not the grammar.
根据我的经验,大多数错误都来自语义分析和缩减,而不是语法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.