A0A0
A0A0 is a queue-based, self-modifying programming language created by User:Snowyowl in 2013.
It is named after a commonly used pair of commands. When the name is read aloud, it should ideally be sung in a major third.
Language overview
Each line of code in the source of an A0A0 program represents a queue of commands. Commands consist of a single letter and a signed integer, which is the argument for that command and also the only datatype. To interpret a command, the interpreter works in the following order:
- Pop one command from the current line.
- Execute that command.
- If the command was not a
G
(goto) command, go to the next line.
(Note: this might be obvious, but given that several commands can alter the content of the current line, it's important to be specific.)
Any unrecognised commands have no effect (it should be assumed that they are reserved for future use even when they aren't). Spaces and tabs are ignored, but newlines are not.
For any signed integer n, the commands that take n as an argument are:
Control | |
An | Appends a copy of the entire current line to the line n below it. |
Cn | Clears all commands from the line n below the current line. |
Gn | Goto the line n below this one, instead of continuing automatically to the next line. G1 has no net effect and can be used as a no-op.
|
Vn | Sets the argument of the next command on the current line to n. Note that the value of n is linked to the operand; its initial value will only take effect if no operand exists when executing the command. |
Operations
All operations change the value of the operand. The operand is the argument of the first | |
Sn | Adds n to the operand. |
Dn | Subtracts n from the operand. |
Mn | Multiplies the the operand by n. |
Ln | Sets the operand to 1 if it is larger than n, -1 if it is smaller, and 0 if it is equal to n. |
I/O | |
In | Reads an integer from standard input and sets the operand to it.
If n is 0, reads an integer in base 10. If n is 1, reads a single character and returns its ASCII value. Any other arguments produce undefined behaviour. |
On | Writes the value of n to standard output as a base-10 integer. |
Pn | Writes the ASCII character corresponding to n mod 256 to standard output. |
The initial program code is padded in both directions by an infinite number of empty lines. Whenever the program encounters an empty line, it immediately terminates. (Hence the practicality of "padding lines", that do nothing useful but also do not cause the program to terminate.)
Execution starts at the first line by default; however, if any line starts with a >
symbol, execution starts at that line instead. (This allows debuggers to output the program state formatted as A0A0 source code.)
Sample Programs
"Hello, world!"
P72 P101 P108 P108 P111 P44 P32 P119 P111 P114 P108 P100 P33
cat
A0 A0 A0 C3 G1 G1 A0 A0 I1 V0 P0 A0 A0 A1 G-3 G-3 A0 G-3
This program shows one way of creating a loop in A0A0. Only the third line deals with input and output; the rest of the program serves to form a loop.
Implementations
- Ruby interpreter (dead link) by User:Andkerosine
- Java interpreter by KotlinIsCool