Whitespace (programming language)
Whitespace is a relatively young esoteric programming language . In contrast to common programming languages, the commands and control instructions consist of defined sequences of spaces, tabs and line breaks (English Whitespaces ). Besides this obvious quirk, Whitespace uses the usual dual system only for data; the program code is represented in a three-digit system of digits (“l”, “t”, “u” or “s”, “t”, “l”).
syntax
The commands and control statements consist of defined sequences of spaces (l), horizontal tab characters (t) and line breaks (u).
There is no syntax element for marking 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
The commands can be roughly divided into five areas:
character | meaning |
---|---|
l | Stack access |
tl | Arithmetic functions |
dd | Heap memory access |
u | Loops, jumps, conditions |
do | Input / output of values |
A detailed description of the individual commands including expected parameters can be found on the website mentioned below.
Data
While the commands use a three-value system of digits, the data are represented in the dual system: In the first position from the left, a t stands for a negative number; a l for a positive. In the following, t stands for 1 and l for 0. The specification states that numbers can have any bit length, but the compiler and interpreter can set a sensible upper limit here. A date is terminated by a line break.
language
Whitespace is an imperative , stack-based programming language that provides programmers with a stack and heap.
All operations work internally on integers of any bit length. However, it is possible to output a character that is identified by its ASCII code value (outchar).
History and background
Whitespace was developed by Edwin Brady and Chris Morris in late 2002 . Slashdot reported on this programming language on April 1, 2003. In mid-2003, with the completion of a whitespace interpreter in whitespace, the language left the nursery. Bjarne Stroustrup had already mentioned the idea in a draft for C ++ 2000 five years earlier . His basic idea was that mathematicians usually write a space instead of the mark . In C ++ 2000, you could assign the meaning of multiplication to this space.
Whitespace shows a certain similarity to Python programs and make files, because there tab characters at the beginning of the line control the program flow. Most other programming languages ignore whitespaces. For the human observer, however, they serve a useful structuring that can make the program code easier to read.
According to the inventors, advantages are that mass printouts of source texts save ink and that spies who have stolen the code cannot decipher it. However, there are still problems if you want to re-enter the code after printing.
Whitespace is particularly suitable for hiding program code in normal text, similar to steganography . An example of this can be found in a contribution to the International Obfuscated C Code Contest .
Hello World
The “ Hello, world! "-Program:
lllullltlltllluttlllltulllttlltltuttlllltlulllttlttlluttllllttulllttlttlluttllll
tllulllttlttttuttlllltltullltlttlluttllllttlullltllllluttlllltttullltttltttuttll
lltlllulllttlttttuttlllltlltullltttlltluttlllltltlulllttlttlluttlllltlttulllttll
tlluttllllttllullltlllltuttllllttltulllttltuttlllltttlullltltluttllllttttullllut
tllllluulllltulultttlulutlltlutullllltutlllululltuullltluuuu
Development environments
The editor Vim offers syntax highlighting for whitespace by default, which significantly simplifies programming. However, this runs counter to a design goal of the language of using as little ink as possible when printing. There is a mode for Emacs at the web links .
The "Hello, world!" can be converted to proper whitespace using one of the following scripts:
#!/bin/sh
sed "s/ //g;s|//.*||g;s/\\n//g" $1 | tr -d '\n' | sed "s/l/ /g;s/t/\t/g;s/u/\n/g"
#!/bin/sh
sed "s|//.*||g" < $1 | tr -d " \t\n" | tr ltu " \t\n"
sed is a Unix tool for editing text.
Whitespace assembler
Since dealing with trinary coded machine commands is relatively laborious, an equivalent assembler dialect is often used:
// "Hello, world!" in den Speicher schreiben
lllu // push 0 // Speicherstelle 0
llltlltlllu // push 'H' // Zeichen 'H'
ttl // store // in den Speicher
llltu // push 1 // ...
lllttlltltu // push 'e'
ttl // store
llltlu // push 2
lllttlttllu // push 'l'
ttl // store
[…]
lllttllu // push 12
llltlllltu // push '!'
ttl // store
lllttltu // push 13
lllttltu // push \r
ttl // store
llltttlu // push 14
llltltlu // push \n
ttl // store
lllttttu // push 15
llllu // push 0
ttl // store
// Ausgabe-Schleife:
llllu // push 0
ulllltu // 1: // /Schleife
lul // dup // | --.
ttt // pop // | --- Spitze des Stacks untersuchen
lul // dup // | --'
utlltlu // jz 2 // | ----> bei 0 sind wir fertig
tull // outchar // | ----> Ausgabe
llltu // push 1 // | --._. Speicherstelle hochzaehlen
tlll // add // | --'
ululltu // jmp 1 // \naechster Durchlauf
ullltlu // 2: //
uuu // halt // ende
literature
- Oliver Lau: Hexenwerk - A plea for esoteric programming languages : In: c't , 22/2007, pp. 192–199.
Web links
- The Whitespace Homepage ( Memento from April 26, 2015 in the Internet Archive )
- Tutorial on compsoc.dur.ac.uk
- Emacs mode on compsoc.dur.ac.uk
- Whitespace interpreter
Individual evidence
- ^ New Whitespace-Only Programming Language , Slashdot, April 1, 2003
- ^ Bjarne Stroustrup: Generalizing Overloading for C ++ 2000 . (PDF) 1998