https://github.com/phreppo/hile
Interpreter for the While language
https://github.com/phreppo/hile
interpreter semantics while
Last synced: 6 months ago
JSON representation
Interpreter for the While language
- Host: GitHub
- URL: https://github.com/phreppo/hile
- Owner: phreppo
- License: bsd-3-clause
- Created: 2018-11-08T19:03:30.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-12-20T17:53:23.000Z (over 6 years ago)
- Last Synced: 2024-08-15T09:54:56.867Z (over 1 year ago)
- Topics: interpreter, semantics, while
- Language: Haskell
- Homepage:
- Size: 132 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
- License: LICENSE
Awesome Lists containing this project
README
# hile
Interpreter written in Haskell for the While language described [here](http://www.cs.kun.nl/~hubbers/courses/sc_1718/materiaal/wiley.pdf). It builds the semantic function of the code and then applies it to the given state. In particular the interpreter performs a fixpoint calculation using the [Knaster–Tarski theorem](https://en.wikipedia.org/wiki/Knaster%E2%80%93Tarski_theorem) for calculating the semantics of the while construct. For further information see [this](http://www.cs.kun.nl/~hubbers/courses/sc_1718/materiaal/wiley.pdf).

To use the interpreter one may exploit the REPL function in the main or
```
stack ghci
```
and then the function `i` to interpret one program in one given state. For example:
```
i ("y:=1; while x != 1 do y:=y*x; x:=x-1","[x->7000]")
```
computes the factorial of 7000. The grammar of the language is:

The syntax is enriched with some syntactic sugar, always removed before interpreting the program:
| Sugar constructs |
| :-------------: |
| for |
| repeat |
| or |
| < |
| > |
| >= |
| != |
| ^ |
To build the executable you need [happy](https://www.haskell.org/happy/) installed, one parser generator for Haskell. To build the executable run:
```
./generateGrammar
stack build
```
To run the REPL mode use:
```
./i
```