This is an interpreter for the imperative toy language IMP from the course Formal Methods and Functional Programming at ETH Zürich. It is published under the MIT license.
To start the REPL, just run impli with no arguments. Pass the path of an IMP source file as argument to interpret it. Directly execute a statement with the --command option or print its AST with --ast. Select the structural small-step semantics with --structural and set the verbosity level of the REPL with --verbose LEVEL (or interactively with :set verbose LEVEL). In the initial state all variables are uninitialized with zero and no procedure is defined. Find some sample programs in docs/examples/.
Build artifacts for macOS, Linux, and Windows are available under GitHub Releases. You can download the latest version directly using curl. Replace BINARY with the OS appropriate binary name found on the releases page, for example impli-aarch64-darwin for Apple Silicon or impli-x86_64-windows.exe for x86 Windows.
curl -Lo impli https://github.com/bfeitknecht/impli/releases/latest/download/BINARYYou may need to modify execution privileges and remove the quarantine attribute on macOS.
chmod +x impli
xattr -d com.apple.quarantine impliThe most apparent deviations from the specifications are that parentheses are not required for arithmetic or boolean operations in expressions, and sequential composition in statements. Additionally, the write-only placeholder variable _ allows discarding of values. It can only be used on the lefthandside of variable definitions. For complete specification of the syntax refer to the EBNF.
The table below depicts the correspondence between semantics functions defined in the lectures and according functions in this project for state. For an overview of all natural semantics inference rules, check out the paper.
| FMFP | impli |
|---|---|
IMP.State.initial |
|
IMP.State.getVar state x |
|
IMP.State.setVar state x n |
|
IMP.Semantics.Natural.run s state |
|
IMP.Semantics.Structural.step (Source s, state) |
|
IMP.Semantics.Structural.run s state |
|
n |
|
IMP.Expression.evaluate a state |
|
IMP.Expression.evaluate b state |
Both semantics run in any monad providing IMP.Effect.MonadIMP (input, output, choice, havoc). Some extensions behave as follows:
breakimmediately exits the innermost enclosing loop. Abreakoutside a loop is rejected before execution.time sevaluates to the number of small-step transitions of executings(reads and havocs yield zero, choices go left), limited to one million steps.timeout s after a endexecutes at mostasmall-step transitions ofs. It andalternateare delegated to the structural semantics when interpreting with natural semantics.parcombines the states of both branches executed independently under natural semantics, and interleaves the branches at every step under structural semantics.