Deadfish "self-interpreter"
Jump to navigation
Jump to search
Deadfish "self-interpreter" is a small Deadfish extension that supports interpreting Deadfish.
Syntax
Accumulator b is equivalent to Deadfish's accumulator, whereas accumulator a stores one character.
Instruction | Description |
---|---|
a |
input accumulator a |
i |
increment accumulator b |
d |
decrement accumulator b |
s |
square accumulator b |
o |
output accumulator b |
j |
jump back to the start of the program |
: |
if the character after : is equal to a, interpret that character, else, skip it.
|
Example programs
Deadfish interpreter
a:i:d:s:oj
"Truth-machine"
For input 0, input 0
, then 0
. For input 1, input i
, then j
, then 0
, then j
, then repeat inputting 0j
.
a:ioa:j
Implementations
Python
Implementation by User:JonoCode9374 and User:HungKhanh0106
acc = 0 input_acc = 0 def run(program): global acc, input_acc ip = 0 while ip < len(program): if acc == 256 or acc < 0: acc = 0 if program[ip] == "j": ip = 0; continue elif program[ip] == "i": acc += 1 elif program[ip] == "d": acc -= 1 elif program[ip] == "s": acc *= acc elif program[ip] == "o": print(acc) elif program[ip] == ":" and ord(program[ip + 1]) == input_acc: run(chr(input_acc)); ip += 2; continue elif program[ip] == "a": try: input_acc = ord(input(">"));except: continue ip += 1 while True: source = input(">> "); run(source)