Showing posts with label brainfuck interpreter. Show all posts
Showing posts with label brainfuck interpreter. Show all posts

Thursday, December 11, 2008

Oh, also

The previous post embeds the code which I've hosted on Google Code or whatever the kids are calling it nowadays. Thus, whenever I update the code, that magic box will automagically contain the updated file.
The project page can be found here.

I suck at svn, so I'm likely to break something soon. Never used it before, so it took me a little to figure out how to even get the gosh damn thing up.

pybrain4.py - First release

Well, here it is. It can be imported into an interactive python session, or run from the command line with something like:
python pybrain4.py file.b

Additional documentation can be found by calling it with the '-h' or '--help' flags.
Among other things, I'll work on trying to speed it up a bit.

Also, this has only been tested on OS X Leopard with Python 2.6. Compatibility will almost surely be broken with 3.0, but should probably work in 2.5.
Let me know if you have any problems.



Some Brainfuck programs to try out:

Took a while, but...

Pybrain v. 4, my poorly written Brainfuck interpreter, is a success!

Yes, Pybrain v. 1 - 3 did not work. Version 3, the lengthiest, had 177 lines of code. Version 4 currently has 61. It's not complete yet, as I still have to add support for running it as a standalone script and executing a given file instead of just strings from the Python interpreter. Once I polish it up a bit, I suppose I'll post it here.

Version 3 was a complete rewrite (as was the later version 4), and was very object-oriented. Given that resounding failure, I'm not sure that was the best way to go. Perhaps choice of programming paradigm should not be based on one's ability to work bad, stupid puns into the program (e.g. naming the cell class BrainCells).

Tuesday, December 9, 2008

I am a complete idiot and I suck at not being a complete idiot

Turns out the problem causing the infinite loop in the Brainfuck interpreter was, well, an infinite loop. I know, I know, it must've been hard for me to catch. Please hold the applause.

I had forgotten to implement the somewhat important part where, you know, the while loop actually works. I had forgotten to add a check to see if the current cell is 0, thus making the loop somewhat useless.

Now I'll go try some other code and probably find new bugs.
Oh boy.