HARSH
Add 1, double, and jump back. Everything else is left to you.
2018 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
HARSH is from 2018. It was made to test its creator's skill at memory allocation, with two design goals, to make arithmetic difficult and control flow a nightmare. The accumulator can only grow by 1 or double. The only real jump goes backwards, by as many characters as the accumulator holds. With 0 in it, b jumps to itself forever.
Read the story
Forward jumps are one character at a time. h skips one when the accumulator is exactly 30, and q asks the user whether to run the next command, which is also the only input.
The machine
| Char | Does |
|---|---|
a d o | Add 1; double; set to 0 |
u p | Push the accumulator and keep it; pop into it |
r | Move the top of the stack to the bottom |
h | Skip the next character if the accumulator is 30 |
q | Ask whether to run the next command |
b | Jump back as many characters as the accumulator holds |
c n | Print the accumulator as a character or a number |
e | End |
z | Run the command numbered by the accumulator, 1 for a up to 12 for e |
The specification's table says u pushes and p pops, and its text says the opposite. Its programs run only the way the table has it. q prints no question. It reads a line of input, and a line that starts with y means yes.
Example
The first is the second Hello World.
The first is the second Hello World. It pushes the codes of space, D, E, H, L, O, R and W once each, then rotates the stack to bring up each letter it needs. A pu pair reads the top and puts it back. The second is the truth machine. On no it skips the p, prints 0, builds 26 and ends at e. On yes it pops a 1, builds 30, and h skips the e, so nb prints 1 forever. The third puts 11 in the accumulator, and z runs command 11, which is n.
Patterns it teaches
- Stack machines: one stack that can only be pushed, popped and turned, so reading deep values means rotating.
Further
See also
Stack-based
Write your own in Run Convert a program from HARSH
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: harsh.
Command line
shib run harsh -e 'auuoqpnaaaaaaddaahepnb' --input 'n'shib manual harshSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/harsh.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org