Hello, Spud again. Today I made a super small BrainF*ck interpreter, that I call BrainPy. BrainPy is small, and fast, and is meant to be as portable as possible. BrainPy can be used on any machine with python 2.7 and can easily be adapted for other versions of python.
[Download]
To run a BrainPy file follow these steps.
1.) Get some BrainF*ck code and paste it into notepad.
2.) Save the code as "NAME_HERE.bp" in the same directory as BrainPy.py
3.) Navigate to the BrainPy directory in cmd or another shell.
4.) Type "ptyhon BrainPy.py NAME_HERE.bp" in the shell and press enter
5.) Press enter when the program is over
For those of you who don't want to download BrainPy, here's the source code:
Code:
Thanks for checking out BrainPy and happy coding!
~Spud2451
[Download]
To run a BrainPy file follow these steps.
1.) Get some BrainF*ck code and paste it into notepad.
2.) Save the code as "NAME_HERE.bp" in the same directory as BrainPy.py
3.) Navigate to the BrainPy directory in cmd or another shell.
4.) Type "ptyhon BrainPy.py NAME_HERE.bp" in the shell and press enter
5.) Press enter when the program is over
For those of you who don't want to download BrainPy, here's the source code:
Code:
import sys
def run(code, p = -1, pos = 0, reg = [], j = 0):
if p == -1:
for i in range(1,64):
reg.append(0)
code = list(code)
while p < len(code)-1:
p += 1
c = code[p]
if c == "+":
reg[pos] += 1
if c == "-":
reg[pos] -= 1
if c == ">":
pos += 1
if c == "<":
pos -= 1
if c == ".":
sys.stdout.write(chr(reg[pos]))
if c == ",":
reg[pos] = ord(sys.stdin.read(1))
if c == "[":
if reg[pos]:
temp = p
while reg[pos] > 0:
p = temp
p, pos, reg = run(code,p,pos,reg)
else:
k = 1
j = code[p]
while j != "]" or k != 0:
p += 1
j = code[p]
if j == "[":
k += 1
if j == "]":
k -= 1
if c == "]":
return p, pos, reg
fh = open(sys.argv[1])
code = fh.read()
fh.close()
run(code)
raw_input("[Press Enter]")
Thanks for checking out BrainPy and happy coding!
~Spud2451