04 How is a Whitespace program structured?

Whitespace is a command-oriented stack-based programming language that provides programmers with a stack and heap.

All operations operate internally on integers of arbitrary bit length. However, there is an option to output a character identified by its ASCII code value.

The commands and control statements consist of defined sequences of spaces (s), tab characters (t), and linefeed (l).

There is no syntax element to identify comments. Instead, comments, which themselves must not contain whitespaces, can be entered anywhere in the source code. The interpreter ignores all characters that have no meaning for it.


Commands are composed of sequences of spaces, tab stops and linefeeds. For example, t-s-s-s performs arithmetic addition of the top two elements on the stack. Data is represented in binary using spaces (0) and tabs (1), followed by a linefeed; thus, s-s-s-t-s-t-t-l is the binary number 0001011, which is 11 in decimal. All other characters are ignored and thus can be used for comments.

Code is written as an Instruction Modification Parameter (IMP) followed by the operation and a parameter if needed.

sStack Manipulation
t sArithmetic
t tHeap Access
lFlow Control
t lInput/Output

Stack manipulation

ssNumberPush the number onto the stack
sl sDuplicate the top item on the stack
sl tSwap the top two items on the stack
sl lDiscard the top item on the stack


t ss sAddition
t ss tSubtraction
t ss lMultiplication
t st sInteger Division
t st tModulo

Heap Access

t tsStore in heap
t tsRetrieve from heap

Flow Control

ls sLabelMark a location in the program
ls tLabelCall a subroutine
ls lLabelJump to a label
lt sLabelJump to a label if the top of the stack is zero
lt tLabelJump to a label if the top of the stack is negative
lt tEnd a subroutine and transfer control back to the caller
ll lEnd the program


t ls sOutput the character at the top of the stack
t ls tOutput the number at the top of the stack
t lt sRead a character and place it in the location given by the top of the stack
t lt tRead a number and place it in the location given by the top of the stack


While the commands use a three-valued place system, the data is mapped in the dual system: In the first place from the left, a “t” represents a negative number; a “l” represents a positive number. Further on, “t” stands for 1 and “l” for 0. The specification states that numbers can have any bit length, but compilers and interpreters can set a reasonable upper limit here. A datum is terminated by a line break.