class BfRb::Base
loads and interprets brainfuck code
Public Class Methods
new()
click to toggle source
initialize the interpreter
# File lib/bfrb.rb, line 8 def initialize @interpreter = Interpreter.new end
Public Instance Methods
load_file(file_path)
click to toggle source
load brainfuck code from a file and run it
# File lib/bfrb.rb, line 18 def load_file(file_path) code = File.open(file_path) { |f| f.read } run(code) end
repl()
click to toggle source
interactive read-evaluate-print loop
# File lib/bfrb.rb, line 24 def repl puts "For interpreter commands, type 'help'" while true puts "" print "bfrb> " input = gets.chomp case input when "help" repl_help when "exit", 24.chr puts "Exiting" break when "mem" puts "Cell: #{@interpreter.memory_counter} Value: #{@interpreter.current_memory}" when "clear" @interpreter.initialize_environment else @interpreter.run(input) end end end
repl_help()
click to toggle source
prints out a help message
# File lib/bfrb.rb, line 47 def repl_help puts "'exit' or Ctrl-X leaves the REPL" puts "'mem' displays the value in the current cell of memory" puts "'clear' clears everything from memory" puts "'help' displays this message" end
run(code)
click to toggle source
run the given brainfuck code
# File lib/bfrb.rb, line 13 def run(code) @interpreter.run(code) end