Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
The stupid question is the question not asked
 
PerlMonks  

BF interpreter

by gustavderdrache (Acolyte)
on Aug 23, 2006 at 21:21 UTC ( #569217=obfuscated: print w/ replies, xml ) Need Help??

A friend of mine, EnragedTux, wrote a BF interpreter in Perl. He wanted to shorten it up, and I came up with this. He told me to say that he helped out. :)
#!/usr/bin/perl open P,shift;%p=('>',sub{$p++},'<',sub{$p--},'+',sub{$p[$p]++},'-', sub{$p[$p]--},'.',sub{print chr$p[$p]},',',sub{$p[$p]=ord getc},'[' ,sub{&c} ,);sub p{ exists$p{$_[0]}&&&{$p{$_[0]}}}p getc P until eof P; sub c{push@c,getc P until$c[@c-1]eq']';do{p$_ for@c}while$p[$p]}
"If you go on with this nuclear arms race, all you are going to do is make the rubble bounce" -- Winston Churchill

Comment on BF interpreter
Download Code
Re: BF interpreter
by ikegami (Pope) on Aug 23, 2006 at 21:56 UTC

    Awesome! I'll give this to my GF tonight.

    Oh, you mean that other BF!

Re: BF interpreter
by mtve (Chaplain) on Aug 25, 2006 at 10:45 UTC
Re: BF interpreter
by truedfx (Monk) on Aug 28, 2006 at 07:20 UTC

    Nice. You can make it a little bit shorter by not giving p any arguments, and by using ARGV:

    #!/usr/bin/perl $/=\1;%p=('>',sub{$p++},'<',sub{$p--},'+',sub{$p[$p]++},'-',sub{$p[ $p]--},'.',sub{print chr$p[$p]},',',sub{$p[$p]=ord<>},'[',sub{&c}); sub p{exists$p{$_}&&&{$p{$_}}}p while<>;sub c{push@c,<>.!1until$c[@ c-1]eq']';do{p for@c}while$p[$p]}

      Wow, awesome.

      Wouldn't have come up with that one.

      "If you go on with this nuclear arms race, all you are going to do is make the rubble bounce" -- Winston Churchill

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://569217]
Approved by chargrill
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2014-04-20 18:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (486 votes), past polls