Leet (also stylized as L33t) is an esoteric programming language based loosely on Brainfuck, named for the resemblance of its source code to the symbolic language "L33t 5p34k" (leetspeak). It was designed by Stephen McGreal and Alex Mole with the stated goal of being as confusing as possible. The language is Turing-complete and supports self-modifying code. Software written in the language can make network connections and may therefore be used to write malware.
Language specification
The basic data unit of L33t is the unsigned byte (big-endian), which can represent ASCII values and numbers in the range 0–255.
The source code is written in "l33t 5p34k," and words are separated by spaces or carriage returns. The language uses 10 opcodes, and each word in the source code is translated into an opcode by adding all the digits in the word together (e.g., "l33t" = 3 + 3 = 6). It is not necessary to use anything but digits in the code.
The language uses a 64K block of memory and two pointers: a memory pointer and an instruction pointer. The L33t interpreter tokenizes all the words in the source to create a sequence of numerical opcodes and places them in order into the memory block, starting at byte 0. The instruction pointer increments until it encounters an END. The memory pointer starts at the first byte after the instructions. Memory "wraps": incrementing the memory and instruction pointers past 64K causes them to run around to byte 0, and vice versa.
Memory pointers can also be moved into the area of memory occupied by the instructions, so code can be self-modified at runtime. Similarly, the instruction pointer will continue incrementing or jumping until it encounters an END, so code can be generated at runtime and subsequently executed.
Opcodes
| Value | Opcode | Description |
|---|---|---|
| 0 | NOP | No operation, except to increment the instruction pointer. |
| 1 | WRT | Writes the ASCII values of the byte under the memory pointer to the current connection (see CON). Increments the instruction pointer. |
| 2 | RD | Reads a character from the current connection (see CON) and writes it to the byte currently under the memory pointer. Increments the instruction pointer. |
| 3 | IF | Moves the instruction pointer forward to the command following the matching EIF, if the byte under the memory pointer is equal to zero. If the byte does not equal zero, IF simply increments the instruction pointer. |
| 4 | EIF | Moves the instruction pointer backwards to the command following the matching IF, if the byte under the memory pointer is not equal to zero. If the byte does equal zero, EIF simply increments the instruction pointer. |
| 5 | FWD | Moves the memory pointer forward by (next word + 1) bytes. Adds 2 to the instruction pointer. |
| 6 | BAK | Moves the memory pointer backward by (next word + 1) bytes. Subtracts 2 from the instruction pointer. |
| 7 | INC | Increments the value of the byte under the memory pointer by (next word + 1). Adds 2 to the instruction pointer. |
| 8 | DEC | Decrements the value of the byte under the memory pointer by (next word + 1). Adds 2 to the instruction pointer. |
| 9 | CON | Reads the 6 bytes starting with the memory pointer (the first 4 bytes specifying an IP in the format 127.0.0.1, and the last 2 bytes combining to make a 16-bit port number) and opens a connection if possible. If a connection cannot be opened, L33t returns the error message: "h0s7 5uXz0r5! c4N'7 c0Nn3<7 l0l0l0l0l l4m3R !!!". If all 6 bytes read 0, L33t reverts to the local machine's stdin and stdout (the default setting upon starting a program). Increments the instruction pointer. |
| 10 | END | Closes all open connections and ends the program. The value 10 will not end the program if it is used as data for opcodes FWD, BAK, INC, or DEC. |
Interpreters
Several interpreters for the language have been written, including:
- Python — written by Alex Mole; does not support the CON opcode but is otherwise considered the "definitive" interpreter.
- Ruby — written by Eric Redmond; includes an implementation of CON.
- JavaScript — by Phil McCarthy, based on the Python interpreter but more interactive.
- C — interpreters written by Kuisma Salonen (for Linux) and by Alecs King.
- Perl 6 — by Gaal Yahas; notable for being the first interpreter to come with a debugger.
References
- Wikipedia: "Leet (programming language)"
- Esolang Wiki: "L33t"
- Official L33t programming language website