I have a quick implementation of the Brainfuck interpreter for Python in the GitHub repository . In a nutshell, however, you can save a dictionary where the keys are Brainfuck characters and the values โโare objects of a function (or method) and then sent to that. Something like that:
instructions = { '+': increment, '-': decrement, # Other functions } def run(tape): ch = next_token(tape) if ch in instructions: instructions[ch]()
(Not a real implementation, just a brief illustration.)
source share