People in the lab are very enthusiastic about what they do. The environment is very stimulating and soon you realize that most of the limits are those in your head.
Clafer Parser in Java
Our reference Clafer implementation has been coded in Haskell, which allowed for quick development of the prototype. This page describes how to generate Clafer parser in Java, as it is a more mainstream language. The input grammar file is the same as for Haskell implementation. We use BNF Converter to generate scanner, parser and a skeleton of interpreter. Using a single grammar file, it can generate code for several languages, including C, C++, Java, Haskell.
Limitation
The generated parser uses brackets for establishing hierarchies of features in Clafer models. In the reference implementation of Clafer, the layout resolver inserts brackets automatically if the model uses Off-side Rule (whitespace indentation) [Wikipedia]. To overcome this limitation, one should implement a layout resolver and inject it between lexer and parser. A Stack Overflow discussion explains how to do that.
Generating Clafer Parser in Java
- Install BNFC
Instruction on how to install and use the software is available here. You might find BNFC in some Linux distributions: Debian, Ubuntu, Arch. - Install JLex
JLex is a lexer generator. You can download it from here. It is a single file that you should put into some directory, e.g. /opt/java/JLex. Compile it with javac Main.java in that directory. - Install Cup
Cup is a parser generator. You can download it from here. It is a compressed package that contains source and class files. Unpack it into some directory, e.g. /opt/java/Cup. - Obtain Clafer Grammar
You can download it from the repository [CF]. Go to the directory with downloaded file. - Generate Input Files for JLex and Cup
bnfc -m -java1.5 clafer.cf
If the command fails, make sure to that Cup and JLex are visible for java compiler by executing
export CLASSPATH=.:/opt/java/Cup:/opt/java - Generate the Code
make - Build the Test Implementation
javac clafer/Test.java - Test the Implementation
Download Clafer model of the Linux Kernel [ZIP]. Unpack it to clafer directory by running:
unzip linux-2.6.32.zip
Test the implementation
java clafer/Test < linux.cfr
| Attachment | Size |
|---|---|
| clafer-java.tar.gz | 51.21 KB |


