Jump to content




Brainfuck interpreter


11 replies to this topic

#1 Mads

  • Members
  • 604 posts
  • LocationCopenhagen, Denmark

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!

#2 zekesonxx

  • Signature Abuser
  • 263 posts
  • LocationWhere you aren't

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*

#3 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 02 March 2013 - 07:30 AM

I can see why it's called brainfuck

#4 ETHANATOR360

  • Members
  • 423 posts
  • Locationyour hardrive

Posted 02 March 2013 - 08:58 AM

 Dlcruz129, on 02 March 2013 - 07:30 AM, said:

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

#5 Mads

  • Members
  • 604 posts
  • LocationCopenhagen, Denmark

Posted 02 March 2013 - 09:12 AM

You program in brainfuck, and this program runs the brainfuck code.

#6 1v2

  • Members
  • 89 posts
  • LocationAmsterdam

Posted 03 March 2013 - 10:42 PM

I wrote one in Python a while back.
https://www.youtube....h?v=YMx3EuKWhbo

#7 oeed

    Oversimplifier

  • Members
  • 2,095 posts
  • LocationAuckland, New Zealand

Posted 03 March 2013 - 11:37 PM

Ah Brainfuck... what ever was the point of it.

#8 BigSHinyToys

  • Members
  • 1,001 posts

Posted 04 March 2013 - 01:13 AM

 oeed, on 03 March 2013 - 11:37 PM, said:

Ah Brainfuck... what ever was the point of it.
Genetic algorithms become programmers themselves

#9 dissy

  • Members
  • 181 posts

Posted 04 March 2013 - 01:24 PM

 oeed, on 03 March 2013 - 11:37 PM, said:

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

#10 GopherAtl

  • Members
  • 888 posts

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.

#11 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 04 March 2013 - 08:00 PM

 dissy, on 04 March 2013 - 01:24 PM, said:

 oeed, on 03 March 2013 - 11:37 PM, said:

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!

#12 immibis

    Lua God

  • Members
  • 1,033 posts
  • LocationWellington, New Zealand

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users