Simple parser for JML

511 Views Asked by At

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.

1

There are 1 best solutions below

3
On BEST ANSWER

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 literal String s = "/*@"; to be the start of a JML spec.

Two well known parser generators for Java are:

  1. ANTLR
  2. JavaCC

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.