Whi-L is an interpreter for the while language, a language primarily used in theoretical computer science. It also has a REPL for quick experimentation.
- Compile
Whi-l.hsusing ghc:
ghc Whi-l.hs
- For the REPL, just use the resulting executable:
Whi-l
- To execute a file, add the file path at the end, e.g.
Whi-l "examples/multiplyXandY.wh"
- Using the
--helpoption gives you a brief oveview as well
Whi-l --help
The while language has the following grammar
\n stands for a new line
Program
IndentedProgram
Statement
While
If
Ass
Skip
Expression
Boolean
Not
And
Or
Bigger
Smaller
Equals
Arithmetic
Plus
Minus
Number
Variables
Inline comments can be made by using "--", for example
x := 69 -- HAHA 69 so funny lol
- If a line only contains a comment with some space before the
--, that space is not allowed to contain tabs, because that would indicate the start of a subprogram. - A semicolon is only placed if there is following statement in the same subprogramm. Noticably, the last statement cannot end in a semicolon, as well as the last statement in the first block
B1of anif ... then B1 else B2. - The minus operation is right associative, so e.g. 1-1-1 = 1-(1-1) = 1-0 = 1, and not -1 as one might expect. This can be seen as a feature or as a bug ig, but adds to the cursedness of this language implementation.