Selector
Overview
Selector is a simple language created in April 2008 by User:EvincarOfAutumn.
It has ten signed unbounded integer data registers, one unbounded stack, basic looping, basic exception handling, and sufficient additive arithmetic operations to be considered Turing-complete. (Thanks to User:Ais523 for informing me that it is).
Each program consists of a series of blocks. All but one of these blocks are "locked" when execution begins. Unlocked blocks are executed in order from top to bottom, and the file is repeatedly executed until no unlocked blocks remain to execute. Only one register may be "selected" for write access at a time.
Source Requirements
Source is given in en-US.US_ASCII encoding. Commands are given in capital letters. All non-capital letters and whitespace are ignored in the source, as are the characters [
and ]
and all intermediate characters. Noncapitals separate commands from their parameters and commands from one another.
Commands
ALL
ALL identifier
Begins a block named identifier
.
Special Blocks
KNOB
Program entry point (short for "no block")NOSE
Exception: No selection where selection neededBAD
Exception: Block already deselectedBASE
Exception: Block already selected
PICK
PICK register
Selects the indicated register.
Registers
Each register has an initial value corresponding to its name.
ZERO
ONE
TWO
THREE
FOUR
FIVE
SIX
SEVEN
EIGHT
NINE
In addition, there is one special register named NOSE
. The statement PICK NOSE
deselects all registers. Its name is an abbreviation of "no selection". I swear.
MY
MY register
Subtracts the value of the indicated register from the selected one. Raises a NOSE
exception if no register is selected.
YOUR
YOUR register
Adds the value of the indicated register to the selected one. Raises a NOSE
exception if no register is selected.
GO
GO direction
Jumps in the given direction
.
GO Directions
FORWARD
If the selected register is zero, jumps to the matching GO BACK
. Otherwise a nop.
BACK
If the selected register is nonzero, jumps to the matching GO FORWARD
. Otherwise a nop.
ON
Jumps to the start of the next enabled block. This can wrap around the end of the program!
Note that a GO ON
is implicit at the end of every block.
OFF
Jumps to the start of the previous enabled block. This can wrap around the start of the program!
MAKE
MAKE action
Performs a stack operation.
MAKE Actions
PILE
Pushes the value of the selected register to the stack. If no register is selected, a value is pushed from standard input.
HOLE
Pops the value at the head of the stack into the selected register. If no register is selected, an ASCII value is popped to standard output, modulo 256 if the value is greater than 255.
LESS
LESS identifier
Disables a named block. Raises a BAD
exception if the block is already disabled.
MORE
MORE identifier
Enables a named block. Raises a BASE
exception if the block is already disabled.
BECOME
BECOME identifier
Swaps the current block and the indicated one, and jumps to the start of the now-current block.
ESCAPE
ESCAPE
Returns to the start of the last block to execute. In the case of exception-handlers or blocks called with a BECOME
statement, this is always the caller. Named subs right there!
Examples
These are almost the least-obfuscated possible programs. The interpreter supports all but the BECOME and ESCAPE statements, so the following programs are guaranteed to work. Not that the interpreter is getting posted in its unfinished state.
Cat
This is a simple cat program. It doesn't perform error checking of any kind, and it doesn't recognise EOFs. It just loops, outputting the lines that are input, until the program gets killed.
ALL KNOB GO FORWARD MAKE PILE MAKE HOLE GO BACK
Hello, world!
Anyway, I was too lazy to make a hello world, so the following program prints "Hello." instead.
ALL KNOB PICK NINE GO FORWARD PICK ZERO YOUR EIGHT PICK NINE MY ONE PICK NINE GO BACK PICK ZERO MAKE PILE PICK NOSE MAKE HOLE PICK ZERO YOUR EIGHT YOUR EIGHT YOUR EIGHT YOUR FIVE MAKE PILE PICK NOSE MAKE HOLE PICK ZERO YOUR SEVEN MAKE PILE MAKE PILE PICK NOSE MAKE HOLE MAKE HOLE PICK ZERO YOUR THREE MAKE PILE PICK NOSE MAKE HOLE PICK ZERO GO FORWARD MY ONE GO BACK PICK FIVE GO FORWARD PICK ZERO YOUR EIGHT PICK FIVE MY ONE GO BACK PICK ZERO YOUR SIX MAKE PILE PICK NOSE MAKE HOLE LESS KNOB