Headache (lang that compiles to brainfuck)
C-like code in, brainfuck out.
Turing complete: yes · ●○○ easy · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
Headache is a language for writing brainfuck without writing brainfuck. It borrows most of its syntax from C, and its compiler, hac, turns a program into brainfuck that runs on any 8-bit brainfuck interpreter. It comes with its own brainfuck interpreter for debugging, and with an expander that turns 8-bit brainfuck into 16-bit or 32-bit brainfuck.
Read the story
The specification shows the brainfuck that hac makes from its Hello World. It is 394 commands long and never moves the pointer. One cell climbs to 72 for the H, prints it, and then moves up and down from letter to letter, 12 prints in all.
Because the target is 8-bit brainfuck, a byte is one cell. Arithmetic wraps at 256, and the specification says 0/0 gives 0.
The machine
This implementation runs the part of Headache that its wiki page shows, directly and without the brainfuck in between.
| Code | Does |
|---|---|
void main() { ... } | The program |
byte a; | Declare a variable, one cell that starts at 0 |
a = (10*6+3)/7; | Assign; * and / bind before + and - |
@"text\n"; | Print a string |
@a; | Print a byte in decimal |
/* ... */ | A comment |
The rest of the language is described only on its official wiki, so there are no loops, conditions, input or other functions.
Example
The arithmetic program.
The arithmetic program. Division rounds down and 0/0 gives 0, so c is 0 + 1 and d is 1 + 1 + 1.
A cell holds 0 to 255, so 200 and 100 make 44.
Patterns it teaches
- Turing tarpit: a C-like layer that hides the tarpit underneath.
See also
Brainfuck
Write your own in Run Convert a program from Headache (lang that compiles to brainfuck)
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: headache-lang-that-compiles-to-brainfuck.
Command line
shib run headache-lang-that-compiles-to-brainfuck -e 'void main() {
@"Hello World\n";
}'shib manual headache-lang-that-compiles-to-brainfuckSource
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org