JML 的简单解析器
我正在寻找一个用 Java 编写的能够读取 JML 的解析器。
基本上我希望解析器能够读取 JML 块并知道它属于哪个方法。
我一直在研究 OpenJML 项目,但仅仅项目设置就太多了。
I am looking for a parser written in Java capable of reading JML.
Basically I would like the parser to be able to read a JML block and know to which method it belongs to.
I've been looking at the OpenJML project, but just the project setup is too much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑您是否会找到一个完全符合您想要的功能,甚至接近您想要的功能的工具。
您可以编写一个“部分”Java 语法,扫描输入文件中的
//@ ...
和/*@ ... @*/
,后跟一个方法宣言。我所说的“部分”是指您没有在语义上解析输入源,而是仅在词汇级别上执行此操作(因此仅在标记上)。确保您考虑了字符串文字:您不希望文字String s = "/*@";
成为 JML 规范的开头。两个著名的 Java 解析器生成器是:
掌握其中任何一个都需要一些时间,特别是如果您是解析器生成器的新手,但一旦掌握了它的窍门,它实际上并不需要太多时间努力创建一个可以可靠地完成此任务的小型语法。
I doubt that you will find a tool that does exactly what you want, or even close to what you want.
You could write a "partial" Java grammar that scans an input file for
//@ ...
and/*@ ... @*/
directly followed by a method declaration. By "partial" I mean that you're not semantically parsing the input source, but perform this only on a lexical level (so tokens only). Make sure that you account for string literals: you wouldn't want the literalString s = "/*@";
to be the start of a JML spec.Two well known parser generators for Java are:
Getting to grips with either one will take a bit of time, especially if you're new to parser generators, but once you get the hang of it, it really is not much work to create a small grammar that could do this reliably.