Beebles
A two-stack language whose interpreter hates its job and may quit if you do not flatter it.
2012 · Turing complete: with unbounded memory · ●○○ easy · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
Beebles is a stack language from 2012, and Beebles is also the name of its interpreter. The specification says the interpreter really hates its job. It gets angry at code without comments, at two commands on one line, at more than 30 numbers on a stack, at swearing and at nop. It gets happier when you push primes, use loops and write I love Beebles in a comment. Angry enough, it ends the program with one line, Beebles got angry and crashed the program.
Read the story
The specification gives no rule for the moods, only chances. This implementation leaves them out, so Beebles never quits on its own. The specification counts the language as bounded because of the limit of 30 numbers; this implementation has no limit.
The machine
Every command ends in a semicolon. There are two stacks of bytes, and one of them is current.
| Command | Does |
|---|---|
push n | Push n |
pop | Pop the top |
outc outi | Print the top as a character or as a number |
getc | Read a character and push it |
add n | Push the top plus n, keeping the top below it |
flip | Make the other stack current |
kick | Move the top to the other stack |
label n goto n | Mark a place; jump there if the top is not 0 |
kill | End the program |
rem text nop | A comment; nothing |
Numbers wrap at 256, so add 255 takes one away. There is no other way to subtract.
Example
A string goes on the stack backwards behind a 0.
A string goes on the stack backwards behind a 0. The loop prints and pops until the 0 is on top.
A cat. goto 1 jumps forward past kill while the character read is not 0, and getc pushes 0 at the end of the input.
The Hello World program pushes the primes from 2 to 17 on the second stack to please Beebles. Its last loop prints them too, as 7 control characters after Hello, World! and a line feed. The 99 bottles of beer program prints all 100 verses. It counts down with add 255 and kicks each new number to the other stack.
Patterns it teaches
- Stack machines: two stacks, and
kickmoves a value between them. - Hostile design: an interpreter with moods, which this implementation leaves out.
Further
See also
Stack-based
Write your own in Run Convert a program from Beebles
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: beebles.
Command line
shib run beebles program.txtThe program is long; save it as program.txt first.
shib manual beeblesSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/beebles.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org