This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Mads's profile picture

Brainfuck interpreter

Started by Mads, 02 March 2013 - 03:56 AM
Mads #1
Posted 02 March 2013 - 04:56 AM
Yes, I know this isn't Lua.

This is a Brainfuck interpreter, that I wrote in C++. It works beautifully, both with and without whitespaces.

Usage:

BF [-d] <path to brainfuck file>
If the -d option will enable debugging, which at the end shows you the data in all cells and more.

You can see the code here, if you wanna compile yourself. It doesn't need any additional libraries, so just do "g++ <filename> -o BF", or "mingw32-g++.exe <filename> -o BF.exe" on Windows.

If you are on Windows, and you don't wanna compile, here is a 32-bit EXE.

This is a sample programme to test addition:

,>, 
[<+>-]
<.

Please leave some feedback!
zekesonxx #2
Posted 02 March 2013 - 05:53 AM
Damn I was about to applaud you for making a Brainfuck interpreter in Lua.

Oh well. *clapy clapy clapy*
Dlcruz129 #3
Posted 02 March 2013 - 07:30 AM
I can see why it's called brainfuck
ETHANATOR360 #4
Posted 02 March 2013 - 08:58 AM
I can see why it's called brainfuck
WHAT!! have you ever seen its syntax!?!
on topic" i dont get the point of this do you program in c++ and it translates to brainfuck or the other way around
Mads #5
Posted 02 March 2013 - 09:12 AM
You program in brainfuck, and this program runs the brainfuck code.
1v2 #6
Posted 03 March 2013 - 10:42 PM
I wrote one in Python a while back.
https://www.youtube....h?v=YMx3EuKWhbo
oeed #7
Posted 03 March 2013 - 11:37 PM
Ah Brainfuck… what ever was the point of it.
BigSHinyToys #8
Posted 04 March 2013 - 01:13 AM
Ah Brainfuck… what ever was the point of it.
Genetic algorithms become programmers themselves
dissy #9
Posted 04 March 2013 - 01:24 PM
Ah Brainfuck… what ever was the point of it.

The back of my business cards contain a brainfuck program that outputs my cell phone number. The front of the cards only have my work number displayed. This serves to rule out phone calls from all the non-geeks I do not wish to speak with :D/>
GopherAtl #10
Posted 04 March 2013 - 02:06 PM
brainfuck interpreters are absurdly simple. Here, threw this one together.

http://pastebin.com/zfDizZWb

tested with this hello world program from wikipedia
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
The file program loader just strips everything that's not "<>[].,+-", so you can add spacing, comments (but not comments with "<>[].,+-"!), etc and it will just ignore them.
Dlcruz129 #11
Posted 04 March 2013 - 08:00 PM
Ah Brainfuck… what ever was the point of it.

The back of my business cards contain a brainfuck program that outputs my cell phone number. The front of the cards only have my work number displayed. This serves to rule out phone calls from all the non-geeks I do not wish to speak with :D/>/>

Smart!
immibis #12
Posted 05 March 2013 - 12:07 PM
OP: You don't seem to handle [ correctly if the cell is 0 the first time around the loop. You execute the loop instead of skipping over it.

For example:

[>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.>>>++++++++[<++++>-]
<.>>>++++++++++[<+++++++++>-]<---.<<<<.+++.------.--------.>>+.]
will print "Hello World!" instead of nothing.