Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lambdacasserole/haha-parser

Unofficial, handwritten parser aimed at transpilation of the HAHA language.
https://github.com/lambdacasserole/haha-parser

education formal-methods formal-verification hoare-logic parser verification

Last synced: 12 days ago
JSON representation

Unofficial, handwritten parser aimed at transpilation of the HAHA language.

Awesome Lists containing this project

README

        

# Hoare Advanced Homework Assistant Parser
Unofficial, handwritten parser aimed at transpilation of the HAHA language.

![Logo](assets/logo.svg)

## Overview
This is a from-scratch implementation of a parser for the language of the [Hoare Advanced Homework Assistant \(HAHA\)](http://haha.mimuw.edu.pl/). Most language constructs are supported, but there are currently some limitations (see below). This implementation does not draw on any of the files originally shipped with HAHA, and is entirely handwritten (i.e. was not generated by a parser generator). I needed this working quickly and at the time grappling with the likes of ANTLR just wasn't worth it.

This parser is primarily aimed at the transpilation of simple HAHA program to other languages (such as Java, C, C++ etc.) and is therefore currently missing many features.

## Installation
You can pull this package into your Maven project straight from here using JitPack. Add JitPack as a repository first:

```


jitpack.io
https://jitpack.io

```

Then add this project as a dependency:

```


com.github.lambdacasserole
haha-parser
v1.2

```

## Quickstart
See below for some code that'll get you started quite quickly parsing HAHA code.

```java
import java.io.File;
import java.io.IOException;

import com.sauljohnson.haha.parser.*;
import com.sauljohnson.haha.parser.model.Program;

import org.apache.commons.io.FileUtils;

public class QuickHahaParserTest {

/**
* The application entry point.
*
* @param args the command-line arguments to the application
*/
public static void main(String[] args) {
try {
// Read in source code.
String source = FileUtils.readFileToString(new File("my_file.haha"));

// Tokenize source.
Tokenizer tokenizer = new HahaTokenizer();
Token[] tokens = tokenizer.tokenize(source);

// Filter out empty statements (i.e. consecutive punctuators).
TokenStreamTransformer emptyStatementFilter = new ConsecutiveTokenFilter(TokenType.PUNCTUATOR);
TokenStream tokenStream = emptyStatementFilter.transform(new TokenStream(tokens));

// Parse program.
Program result = Program.parse(streamTransformer.transform(tokenStream));

// TODO: Interact with the resulting parse tree here.
} catch (IOException e) {
e.printStackTrace(); // File read error.
} catch (TokenizationException e) {
e.printStackTrace(); // Tokenizer error.
} catch (ParseException e) {
e.printStackTrace(); // Parser error.
}
}
}

```

## Limitations
This parser is currently subject to some limitations:
* Parsing does not descend all the way to the expression level. Conditional/loop predicates and the right-hand side of assignments are all left unparsed.
* Predicates, axioms, invariants, preconditions, and postconditions are left unparsed.

## Contributing
For most intents and purposes, this project is considered to fulfil its original use case. Bug fixes and suggestions are welcome, however, from any member of the community.

## Acknowledgements
A big thank you to the team at the [University of Warsaw](https://mimuw.edu.pl/en) behind [HAHA](http://haha.mimuw.edu.pl/). This really is an awesome tool for teaching software verification! By name, they're:
* [Tadeusz Sznuk](http://www.mimuw.edu.pl/~tsznuk/)
* Jacek Chrząszcz
* [Aleksy Schubert](http://www.mimuw.edu.pl/~alx/)
* Jakub Zakrzewski