Skip to content

Repository files navigation

hile

Interpreter written in Haskell for the While language described here. 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 for calculating the semantics of the while construct. For further information see this.

alt text

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:

alt text

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 installed, one parser generator for Haskell. To build the executable run:

./generateGrammar
stack build

To run the REPL mode use:

./i

About

Interpreter for the While language

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages