RubyGems.org

brainfucktt

0.1.0

# Brainfucktt A [Brainfuck][brainfuck] interpreter built in [Ruby][ruby] using [Treetop][treetop]. Brainfuck is an eight-instruction turing-clomplete programming language created in 1993 by Urban Müller, based on the more formal programming language [P′′][p''] created by Corrado Böhm in 1964. It is designed to challenge and amuse programmers, and is not made to be suitable for practical use. ## Install ### Bundler: `gem 'brainfucktt'` ### RubyGems: `gem install brainfucktt` ## Brainfuck Instructions `>` Increment the data pointer (to point to the next cell to the right). `<` Decrement the data pointer (to point to the next cell to the left). `+` Increment (increase by one) the byte at the data pointer. `-` Decrement (decrease by one) the byte at the data pointer. `.` Output the byte at the data pointer as an ASCII encoded character. `,` Accept one byte of input, storing its value in the byte at the data pointer. `[` If the byte at the data pointer is zero, then instead of moving the instruction pointer forward to the next command, jump it forward to the command after the matching `]` command. `]` If the byte at the data pointer is nonzero, then instead of moving the instruction pointer forward to the next command, jump it back to the command after the matching `[` command. ### Comments Any character besides one of the 8 instructions above is not parsed and will be regarded as a comment. ## Usage ### Running ```ruby require 'brainfucktt' # "Hello World!" written in Brainfuck code = '++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.' Brainfucktt.run(code) ``` ### Parsing ```ruby require 'brainfucktt' # "Hello World!" written in Brainfuck code = '++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.' parser = Brainfucktt.parse(code) # Print out the AST of the code p parser.tree # Run the code within Ruby parser.run ``` ### StringIO Sometimes you do now want to use STDIN or STDOUT for the I/O of the Brainfuck program. To do that, you must use the stdlib `stringio`: ```ruby require 'brainfucktt' require 'stringio' # "Hello World!" written in Brainfuck code = '++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.' output = StringIO.new Brainfucktt.run(code, output: output) p output.string # => "Hello World!\n" ``` ## Copyright Copyright © 2012 Ryan Scott Lewis <ryan@rynet.us>. The MIT License (MIT) - See LICENSE for further details. [brainfuck]: http://www.muppetlabs.com/~breadbox/bf/ [ruby]: http://ruby-lang.org [treetop]: http://treetop.rubyforge.org [p'']: http://en.wikipedia.org/wiki/P%E2%80%B2%E2%80%B2

installgem install brainfucktt -v 0.1.0
Authors

Ryan Scott Lewis

2,794 total downloads 876 for this version
Owners

5815438e3cb72c2e4104e835861f26b2

Gemfile
gem 'brainfucktt', '~> 0.1.0'
Versions
  1. 0.1.2 December 6, 2012 (12 KB)
  2. 0.1.1 December 6, 2012 (10 KB)
  3. 0.1.0 December 6, 2012 (11.5 KB)