A tiny brainf**ck implementation in ~19 lines of Ruby, with a REPL. Inspired by Fogus uLithp blog post
It implements a brainf**ck interpreter with a cell size of 7 bytes
See the tinybf.rb file for implementation details.
The brainf**ck interpreter is just a Ruby class that evals expressions in Ruby string arrays, like so:
echo_handler = lambda {|i| print i}
get_handler = lambda { gets.chomp }
bf = Bf.new
bf.eval ['[', '<', '+', '.', '>', '+', '+']
#
��������
�
������������������ !"#$%&'()*+,-./0123456789:;<=>?@
#=> [64, 0]
In your shell use Ruby 1.9.2 to run the REPL:
ruby repl.rb
You'll then see a prompt:
>
Start typing brain**ck code:
Hello World program
>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-]
<.#>+++++++++++[<+++++>-]<.>++++++++[<+++>-]<.+++.------.--------.[-]>++++++++[
<++++>-]<+.[-]++++++++++.
When you want to leave the REPL, type exit
Have some fun...