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.


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:


import sys

def run(code, p = -1, pos = 0, reg = [], j = 0):
    if p == -1:
        for i in range(1,64):
        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 == ".":
        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)
                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()
raw_input("[Press Enter]")

Thanks for checking out BrainPy and happy coding!
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum