Class: Esolang::Interpreters::Boolfuck
- Inherits:
-
BaseInterpreter
- Object
- BaseInterpreter
- Esolang::Interpreters::Boolfuck
- Defined in:
- lib/interpreters/boolfuck_interpreter.rb
Overview
The Boolfuck class represents an interpreter for the Boolfuck esoteric programming language.
Instance Method Summary collapse
-
#initialize(code, input = '') ⇒ Boolfuck
constructor
Initializes a new instance of the Boolfuck interpreter.
-
#run ⇒ String
Executes the interpretation of the Boolfuck code.
Constructor Details
#initialize(code, input = '') ⇒ Boolfuck
Initializes a new instance of the Boolfuck interpreter.
13 14 15 16 17 18 |
# File 'lib/interpreters/boolfuck_interpreter.rb', line 13 def initialize(code, input = '') super(code.gsub(/[^,\.;<>\+\[\]]/, '')) @input = chars_to_bits(input) @output = [] @tape = Hash.new(0) end |
Instance Method Details
#run ⇒ String
Executes the interpretation of the Boolfuck code.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/interpreters/boolfuck_interpreter.rb', line 23 def run while running? do case command when ',' then input_to_tape when ';' then tape_to_output_array when '>' then move_right when '<' then move_left when '+' then flip when '[' then loop_begin when ']' then loop_end end @code_pointer += 1 end translate_output_bits_to_chars end |