Created
May 27, 2013 23:45
-
-
Save giovaneliberato/5659598 to your computer and use it in GitHub Desktop.
Basic brainfuck interpreter written in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
salt = 65 | |
def incr(): | |
compiled[pointer] += 1 | |
def decr(): | |
compiled[pointer] -= 1 | |
def fw(): | |
global pointer | |
pointer += 1 | |
def bw(): | |
global pointer | |
pointer -= 1 | |
def print_v(): | |
result = '' | |
for i in compiled: | |
result += unichr(i + salt) if i > -1 else '0' | |
print('... %s' %result) | |
functions = {"+": incr, "-": decr, ">": fw, "<":bw, ".": print_v} | |
while(1): | |
compiled = [-1] | |
pointer = 0 | |
code = raw_input('-> ') | |
[compiled.append(-1) for char in code if char not in '.[]+-<'] | |
try: | |
[functions[char]() for char in code] | |
except: | |
print("!!! error") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment