Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Brainf*ck interpreter

by Juerd (Abbot)
on Dec 16, 2001 at 22:00 UTC ( #132368=snippet: print w/replies, xml ) Need Help??
Description: This is an interpreter for the (in)famous, but turing-complete, Brainf*ck programming language.
Update 200112161916+0100: s/*ck/g

#!/usr/bin/perl -s # |bf; bf $file; bf -e=,
a(qw%]} [while($p[$p]){ -$p[$p]-- +$p[$p]++
,$p[$p]=ord(getc) .print(chr($p[$p])) <$p--
;/g}eval; # by Juerd <>, 2001

2;0 juerd@ouranos:~$ ./bf -e='++++++++[>++++++++<-]+++++[>>+++++<<-]>>

Replies are listed 'Best First'.
Re: Brainf*ck interpreter
by mtve (Deacon) on May 09, 2002 at 13:34 UTC

    Can't stop after last perlgolf.

    #!/usr/bin/perl -s # |bf; bf $file; bf -e=; $|++;$/=$a;$_=$e||<>;%a=qw%[ while($p[$p]){ , $p[$p]=ord(getc) . print+chr$p[$p] < $p-- > $p++ + $p[$p]++ - $p[$p]-- ] }%;s/./$a{$& };/g;eval

    "Please shoot me" (C) Jay Tilton

    Update on August 10, 2002: another 14 bytes

    #!/usr/bin/perl -s # |bf; bf $file; bf -e=; $_=($/=$e)||<>;$p=w;%a=qw%[ while($$p){ ] } . print+chr$ , $$p=ord(getc); + ++$ - --$ < chop > $p=w.%;$|=s/./$a{$&}\$p;/g;eval

    Update on May 19, 2004: Rick Klement's wonderful solution to PCLP#2.5 Polish golf

    $_.=qw(++ }while$ -- ++$ $$p=shift; --$ print$ ${)[$p%60%8].'$p+0;'while$p=ord getc;eval

      Brainfuck interpreters must discard unknown characters. Yours doesn't.

      - Yes, I reinvent wheels.
      - Spam: Visit eurotraQ.

        I think it does - unknown chars are replaced with noop ';'

        Dear Juerd, can I put "(C) Juerd & Mtve" on it?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://132368]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (2)
As of 2016-10-25 03:41 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (313 votes). Check out past polls.