A little brainfuck compiler I found from the past (a long long time ago).
Usage: ./compiler.py [FILE]
This program breaks if something is not as it is supposed. There are no compiler errors... bullshit in, bullshit out.
Every program begins with the declaration of all variables. You put them into parantheses ()
.
i.e.
(a, b, c, d)
…
Commands:
set <var> <num>
- initialise a variable with a given numbersetchar <var> "<char>"
- initialise a variable with a given charactermov <var> <var>
- Move a value from one variable to another, resetting the first variable to zerocpy <var> <var>
- Copy the value from one variable to anotheradd <var> <var>
- Add the first variable to the second ("add a b" <=> "b = a + b")raw <bf-code>
- Insert raw brainfuck codeprint_raw <var>
- Print the ASCII-value of a variableprint_text "<string>"
- Print text (\n
is a line break)print_num_1 <var>
- Print the variable as a one digit decimal numberprint_num <var>
- Print the variable as a decimal numberif <var>
- Execute code untilendif
, if the variable is not zeroif_clr <var>
- Execute code untilendif
, if the variable is not zero and then set the variable to zeroif= <var> <var>
- Execute code untilendif
, if the variables are equalwhile <var>
- Execute code untilendwhile
until the variable is zeroendif
- seeif
endwhile
- seeif
incr <var>
- Increment variabledecr <var>
- Decrement variablegetchr <var>
- Read a character from input intovar
(exactly identically to,
in brainfuck)chr_to_int <var>
- Subtract 48 from variable, to convert an ASCII-number to an integerdiv <var> <var>
- Divides "first / second" writing the result into "first"mod <var> <var>
- Modulo. warning: I am too lazy to test thismult <var> <var>
- Multiplicates "first * second" writing the result into "first"
You can see examples under examples/
()
print_text "Hello World!\n"