BF interpreter
gustavderdrache
created: 2006-08-23 17:21:28
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
Re: BF interpreter
created: 2006-08-23 17:56:50

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

Oh, you mean that other BF!

Re: BF interpreter
created: 2006-08-25 06:45:40
See this thread
Re: BF interpreter
created: 2006-08-28 03:20:30

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]}
Re^2: BF interpreter
created: 2006-08-30 16:42:28

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

perlmonks.org content © perlmonks.org and gustavderdrache, ikegami, mtve, truedfx

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03