是否有一个实用程序可以在给定 ANTLR 语法的情况下生成匹配的字符串?
我有一个 ANTLR 语法,我想模糊我的解析器。
I have an ANTLR grammar and I would like to fuzz my parser.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我有一个 ANTLR 语法,我想模糊我的解析器。
I have an ANTLR grammar and I would like to fuzz my parser.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
您是否正在寻找 CFG 语法的生成? IE。语法接受的字符串的生成?这可能是检查语法正确性的好主意,但请记住,可接受的字符串集很可能是无限的。任何真正严重的错误应该已经在语法规范中显而易见,并且希望通过 LL-ness 检查。
我不知道 ANTLR 世界中有任何工具,对 (E)BNF 生成的快速谷歌搜索也没有揭示任何有用的东西。
然而,如果性能等不是问题,那么构建自己的生成器并不是很困难。 Prolog 会浮现在我的脑海中,有大量可用的文献,但如果你不想离开 Java,我怀疑自制是最好的选择。无论如何,这很有趣。
Are you looking for generation from a CFG grammar? Ie. the generation of strings that are accepted by the grammar? This could be a good idea to check for grammar correctness, but keep in mind that the set of accepted strings is most probably infinite. Any really bad bugs should already be apparent in the grammar specification, and hopefully by the checking of LL-ness.
I dont know of any tool in the ANTLR world, neither did a quick google search on (E)BNF generation reveal anything useful.
It is, however, not very difficult to roll your own generator if performance and such is not an issue. Prolog would spring to mind, there are loads of litterature available, but if you do not want to leave Java, i suspect homebrewing is the way to go. Its fun anyway.
假设您根据 ANTLR 语法生成了句子(标记字符串)。您认为为什么基于 ANTLR 的解析器会反对它们?
你真正要做的就是生成不太合法的字符串。因此,您需要一个可以生成错误字符串的生成器。
鉴于 ANTLR 从 ANTLR 语法生成一组过程,我认为使用生成的解析器生成句子生成器会很困难。您需要的是语法的显式模型。您已经可以使用这个:ANTLR 输入语法。
我看到的另一个复杂问题是从构成令牌定义的正则表达式生成合法的令牌。同样,您需要处理 ANTLR 输入才能执行此操作。
处理这两个问题在技术上似乎很简单。用作基础的最佳引擎可能是 ANTLR 前端,它显然解析 ANTLR 规范,因此必须保存 ANTLR 输入的某种表示。
Assume you generated sentences (strings of tokens) from your ANTLR grammar. Why do you think your ANTLR-based parser would object to them?
What you really have to do is to produce not-quite-legal strings. So, what you need is a generator that can produce erroneous strings.
Given that ANTLR generates a set of procedures from your ANTLR grammar, I think it would be difficult to produce a sentence-generator using the generated parser. What you need is the explicit model of the grammar. And this already available to you: the ANTLR input grammar.
An additional complication I see is generation of legal tokens from the regexes that make up the token definitions. Again, you'd need to process the ANTLR input to do this.
Processing both of these seem technically straightforward. The best engine to use as a foundation is likely the ANTLR front end, which obviously parses ANTLR specs, and so must hold some representation of the ANTLR input.
正在寻找类似的东西,发现 GramTest ,这似乎很合适,但不是 ANTLR 语法使用 BNF语法作为输入。
有关更多背景信息,请链接到以下博文:
Was looking for something similar and found GramTest, which seems to be suitable, but instead of ANTLR grammar uses BNF grammar as input.
For more background info they link to the following blogposts: