# Whitespace

Whitespace with syntax highlighting

Whitespace, designed in 2003 by Edwin Brady and Chris Morris, is an esoteric programming language that uses only whitespace as syntax. Everything other than spaces, tabs, or linefeeds is ignored. Whitespace got a brief moment of fame when it was posted on Slashdot on April 1st, 2003. Most people took it as an April Fool's joke, which it wasn't.

## Commands

### IMP

There are different types of commands in Whitespace, and they all have different Instruction Modification Parameters (IMP). You have to do IMP first, then command, then parameters if necessary. The parameters end with a linefeed.

IMP Command
[Tab][LF] I/O
[Space] Stack Manipulation
[Tab][Space] Arithmetic
[LF] Flow control
[Tab][Tab] Heap access

### Numbers

To input numbers, first there's a sign. A space is positive, a tab is negative. Then you need to input the numbers in binary. A space is 0, a tab is 1.

### I/O

So let's take some inputs and outputs.

Commands Parameters Meaning
[Tab][Space] - Read a character and place it in the location given by the top of the stack
[Tab][Tab] - Read a number and place it in the location given by the top of the stack
[Space][Space] - Output the character at the top of the stack
[Space][Tab] - Output the number at the top of the stack

Basically, all you need to remember is first, [Tab] for input, [Space] for output, and second, [Space] for character, [Tab] for number.

### Stack manipulation

Of course, you need to actually do stuff with the stack.

Commands Parameters Meaning
[Space] Number Push number on the top of the stack
[LF][Space] - Duplicate the top item on the stack
[LF][Tab] - Swap the top two items on the stack
[LF][LF] - Discard the top item on the stack
[Tab][Space] Number Copy the nth item on the stack (given by the argument) onto the top of the stack (v0.3)
[Tab][LF] Number Slide n items off the stack, keeping the top item (v0.3)

### Arithmetic

Of course, you actually need to do something with the top of the stack.
Arithmetic commands operate on the top two items on the stack, and replace them with the result of the operation. The top item is considered to be left of the operator.

Command Parameters Meaning
[Space][Tab] - Subtraction
[Space][LF] - Multiplication
[Tab][Space] - Integer Division
[Tab][Tab] - Modulo

### Flow Control

Of course, you need to have jumps, subroutines, those stuff.

Commands Parameters Meaning
[Space][Space] Label Mark a location in the program
[Space][Tab] Label Call a subroutine
[Space][LF] Label Jump unconditionally to a label
[Tab][Space] Label Jump to a label if the top of the stack is zero
[Tab][Tab] Label Jump to a label if the top of the stack is negative
[Tab][LF] - End a subroutine and transfer control back to the caller
[LF][LF] - Ends the program

### Heap Access

If you need to store something on a place other than the stack, like the input, if you were wondering where it was going. The address is the top of the stack.

Command Parameters Meaning
[Space] - Store
[Tab] - Retrieve

## Examples

### Cat program

```[LF][Space][Space][Space][LF]
[Space][Space][Space][Tab][LF]
[Tab][LF][Tab][Space]
[Space][Space][Space][Tab][LF]
[Tab][Tab][Tab]
[Tab][LF][Space][Space]
[Space][Space][Space][Tab][LF]
[LF][Tab][Space][Tab][LF]
[LF][Space][LF][Space][LF]
[LF][Space][Space][Tab][LF]
[LF][LF][LF]
```

### Hello, world!

```Hello,[Space]world![Space][Space][Tab][Space][Space][Tab][Space][Space][Space][LF]
[Tab][LF][Space][Space]
[Space][Space][Space][Tab][Tab][Space][Space][Tab][Space][Tab][LF]
[Tab][LF][Space][Space]
[Space][Space][Space][Tab][Tab][Space][Tab][Tab][Space][Space][LF]
[Tab][LF][Space][Space]
[Space][Space][Space][Tab][Tab][Space][Tab][Tab][Space][Space][LF]
[Tab][LF][Space][Space]
[Space][Space][Space][Tab][Tab][Space][Tab][Tab][Tab][Tab][LF]
[Tab][LF][Space][Space]
[Space][Space][Space][Tab][Space][Tab][Tab][Space][Space][LF]
[Tab][LF][Space][Space]
[Space][Space][Space][Tab][Space][Space][Space][Space][Space][LF]
[Tab][LF][Space][Space]
[Space][Space][Space][Tab][Tab][Tab][Space][Tab][Tab][Tab][LF]
[Tab][LF][Space][Space]
[Space][Space][Space][Tab][Tab][Space][Tab][Tab][Tab][Tab][LF]
[Tab][LF][Space][Space]
[Space][Space][Space][Tab][Tab][Tab][Space][Space][Tab][Space][LF]
[Tab][LF][Space][Space]
[Space][Space][Space][Tab][Tab][Space][Tab][Tab][Space][Space][LF]
[Tab][LF][Space][Space]
[Space][Space][Space][Tab][Tab][Space][Space][Tab][Space][Space][LF]
[Tab][LF][Space][Space]
[LF][LF][LF]
```

### Truth-machine

```[Space][Space][Space][LF]
[Space][LF][Space]
[Tab][LF][Tab][Tab]
[Tab][Tab][Tab]
[LF][Tab][Space][Space][LF]
[LF][Space][Space][Tab][LF]
[Space][Space][Space][Tab][LF]
[Tab][LF][Space][Tab]
[LF][Space][LF][Tab][LF]
[LF][Space][Space][Space][LF]
[Space][Space][Space][LF]
[Tab][LF][Space][Tab]
[LF][LF][LF]
```