RubyGems Navigation menu

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 . 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

Gemfile:
=

instalar:
=

Versões:

  1. 0.1.2 December 06, 2012 (12 KB)
  2. 0.1.1 December 06, 2012 (10 KB)
  3. 0.1.0 December 06, 2012 (11,5 KB)

Runtime Dependencies (3):

polyglot ~> 0.3
treetop ~> 1.4
version ~> 1.0

Development Dependencies (8):

at ~> 0.1
fuubar ~> 1.1
github-markup ~> 0.7
guard-rspec ~> 2.1
guard-yard ~> 2.0
rake ~> 10.0
rb-fsevent ~> 0.9
redcarpet ~> 2.2.2

Donos:

Autores:

  • Ryan Scott Lewis

SHA 256 checksum:

=

Total de downloads 11.891

Desta versão 3.583

Versão lançada:

Licenças:

N/A

Versão Requerida do Ruby: Nenhum

Links: