--yay
Brainfuck turned into a stack, with one register in between and every number written in hex.
Turing complete: unknown · ●○○ easy · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
--yay was made to be an easier, stack-based brainfuck. Numbers go onto the stack only through a register. A literal such as #41;, after the character escapes of HTML, sets the register to 0x41, and p pushes it. Branching is one command, ?, which skips the next character when the register is 0. A jump J goes to a position in the source counted in characters, so a loop has to know where it starts.
Read the story
The specification gives the Python interpreter, and this implementation runs the way it does. The register starts as None, so po on its own prints None.
The machine
| Char | Does |
|---|---|
#41; | Set the register to 0x41, which is 65 |
p P | Push the register; pop into it |
+ - | Add or take 1 from the top |
: | Duplicate the top |
. o | Pop and print a character or a number |
, i | Read a character's code or a line's number into the register |
? | Skip the next character if the register is 0 |
J | Pop x and go on at character x, counted from 0 |
q | Halt |
Every other character does nothing, so spaces and line breaks still count for J. The list in the specification says , works on the stack, but the interpreter puts the character in the register.
Example
The Hello world, on one line.
The Hello world, on one line. The l is pushed once, duplicated and printed twice.
The truth machine first pushes 18, the place of #1; in its own source. On 0 the ? skips the J, so it prints 0 and quits; on 1 it jumps to 18 and prints 1 forever.
Patterns it teaches
- Stack machines: one stack and one register, and the register is the only way in.
Further
See also
Stack-based
Write your own in Run Convert a program from --yay
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: yay.
Command line
shib run yay -e '#12;pi ?J #0; poq #1;po #12;pJ' --input '0'shib manual yaySource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/yay.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org