Home

Awesome

Whitespace

A Codewars Kata

Whitespace is an esoteric programming language that uses only three characters:

Whitespace is an imperative, stack-based programming language, including features such as subroutines.

Each command in whitespace begins with an Instruction Modification Parameter (IMP).

IMPs

There are two types of data a command may be passed: numbers and labels.

Parsing Numbers

Parsing Labels

Input/Output

As stated earlier, there commands may read data from input or write to output.

Parsing Input

Whitespace will accept input either characters or integers. Due to the lack of an input stream mechanism, the input will be passed as a string to the interpreter function.

Writing Output

Commands

Notation: n specifies the parameter, [number] or [label].

Errors should be thrown for invalid numbers, labels, and heap addresses, or if there are not enough items on the stack to complete an operation (unless otherwise specified). In addition, an error should be thrown for unclean termination.

IMP [space] - Stack Manipulation

IMP [tab][space] - Arithmetic

IMP [tab][tab] - Heap Access

IMP [tab][line-feed] - Input/Output

IMP [line-feed] - Flow Control

Note that in Javascript and Coffeescript, the modulus operator is implemented differently than it was in the original Whitespace interpreter, which was influenced by it being defined in Haskell. Javascript and Coffeescript also lack integer division operations. There is no difference between Whitespace and Python in the same regard. Therefore, the Javascript and Coffeescript interpreters require a little extra attention in regard to the implementation in regard to integer division and the modulus operator (See: floored division in the Wikipedia article "Modulo operation".