flat assembler
Message board for the users of flat assembler.

Index > Projects and Ideas > Brainfuck Interpreter

Author
Thread Post new topic Reply to topic
Pinecone_



Joined: 28 Apr 2008
Posts: 180
Pinecone_ 31 Aug 2009, 04:10
This is based on my Befunge interpreter.


Bugs:

  • Silently exits if no script is passed on the command line.


I mostly posted this here to add a link to this in my Esoteric Programming Challenges topic


Description:
Download
Filename: Brainfuck.zip
Filesize: 334.1 KB
Downloaded: 1021 Time(s)

Post 31 Aug 2009, 04:10
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 31 Aug 2009, 07:38
Dumb question, but can't you (or someone, I mean) write an interpreter for Brainf*** in Befunge?? Smile
Post 31 Aug 2009, 07:38
View user's profile Send private message Visit poster's website Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 6115
Location: Poland
MHajduk 31 Aug 2009, 07:56
rugxulo wrote:
Dumb question, but can't you (or someone, I mean) write an interpreter for Brainf*** in Befunge?? Smile
I guess that it would be easier to write Befunge interpreter in Brainf*ck. Wink
Post 31 Aug 2009, 07:56
View user's profile Send private message Visit poster's website Reply with quote
Pinecone_



Joined: 28 Apr 2008
Posts: 180
Pinecone_ 31 Aug 2009, 09:58
rugxulo wrote:
Dumb question, but can't you (or someone, I mean) write an interpreter for Brainf*** in Befunge?? Smile
Now there's a good idea for a challenge! Very Happy I dont think it will be very hard, but optimizing might be.
Post 31 Aug 2009, 09:58
View user's profile Send private message Reply with quote
TmX



Joined: 02 Mar 2006
Posts: 841
Location: Jakarta, Indonesia
TmX 31 Aug 2009, 13:19
This thread is awesome... Very Happy

Anyway, would it be hard to write one for Whitespace ?
Post 31 Aug 2009, 13:19
View user's profile Send private message Reply with quote
Pinecone_



Joined: 28 Apr 2008
Posts: 180
Pinecone_ 01 Sep 2009, 06:47
That should be pretty simple. I'll make one later tonight, submit it to this board and add whitespace to the list of esoteric languages in the Esoteric Programming Challenges! thread.

Edit: Probably not tonight. I have a fair few assignments piled up that i need to do. Ill get around to it sometime.
Post 01 Sep 2009, 06:47
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
Location: In your JS exploiting you and your system
revolution 01 Sep 2009, 14:56
MHajduk wrote:
I guess that it would be easier to write Befunge interpreter in Brainf*ck.
Hmm, how would you emulate the Befunge "?" operator in brainfuck?
Post 01 Sep 2009, 14:56
View user's profile Send private message Visit poster's website Reply with quote
Fanael



Joined: 03 Jul 2009
Posts: 168
Fanael 01 Sep 2009, 18:00
revolution wrote:
Hmm, how would you emulate the Befunge "?" operator in brainfuck?
Hmm, how would you emulate the Befunge operator "?" in assembly language? Brainfuck is Turing-complete (and so is assembly language), so PRNG can be implemented.
Post 01 Sep 2009, 18:00
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
Location: In your JS exploiting you and your system
revolution 01 Sep 2009, 22:21
But Turing-completeness has nothing to do with non-deterministic outputs. PRNGs are only possible with non-deterministic inputs as seeds. The only source of input for brainfuck is the keyboard. So that makes it impossible to implement a PRNG automatically like Befunge can.
Post 01 Sep 2009, 22:21
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 02 Sep 2009, 00:53
Nthern wrote:

http://esolangs.org/wiki/Talk:Befunge

I think I have done just that (proven that a Befunge-93 interpreter which can hold arbitrary integers in the stack is TC). I didn't implement a Minsky machine, but rather an interpreter of classic dbfi style brainfuck. First I modified mtve's befunge interpreters in perl and c to handle arbitrary bignums in the stack (new sources here and here). My brainfuck interpreter in befunge is here. It stores the code as one bignum and the brainfuck tape as another bignum. It also uses some self-modification, and stores a temporary integer in the codespace; however, it does not write bignums to the codespace. Hence, the implementations of "[" and "]" have to jump through some hoops to allow arbitrarily deep nestings. A much faster brainfuck interpreter in befunge could be written if one kept track of the nesting count by storing the number in a codespace location, but my intention was to prove TC for this dialect(?) of befunge, so I had to allow arbitrarily deep nestings. The perl code was just for debugging the befunge code (plus, it's super easy to add bignums to perl), so use the c code to try this out.
Compile the befunge interpreter:
> gcc -O3 -o bigbef_me bigbef_me.c -lgmp
Try some brainfuck code that prints out a single "$":
> echo -n '++++++[>++++++<-]>.!' | ./bigbef_me brainfuck.bf
Try your favorite brainfuck code:
> echo -n '!' | cat 99bottles.b - | ./bigbef_me brainfuck.bf
Try a brainfuck interpreter double-stack:
> echo -n '!++++++[>++++++<-]>.!' | cat dbfi.b - | ./bigbef_me brainfuck.bf
--Nthern 19:20, 20 September 2007 (UTC)
Very nice work, dude! It's a shame the original Befunge-93 was defined to use finite values in its stack, but it seems it was common to set limits like that in esolanguages back in the day, instead of just making implementations that don't allow infinite values. Anyways, this is a great achievement in itself, even if it requires a special dialect. --Keymaker 20:12, 20 September 2007 (UTC)


It seems to work on simple programs, but longer ones (quine.b) seem to be either really slow or hang on my DJGPP compile. Whatever. If anybody tests this (or writes their own, preferably NOT in B98), I'm interested in your comments.

P.S. The 80x25 limit might be a hindrance (e.g. 30000 cell size in Brainf***), but even an interpreter for smaller (500 byte) programs might still be interesting. (Or maybe just put it on the stack, who knows.)
Post 02 Sep 2009, 00:53
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.