Class: Esolang::Interpreters::Ook

Inherits:
Brainfuck show all
Defined in:
lib/interpreters/ook_interpreter.rb

Overview

The Ook class represents an interpreter for the Ook! esoteric programming language, which is translated to Brainfuck for execution.

Instance Method Summary collapse

Constructor Details

#initialize(code, input = '') ⇒ Ook

Initializes a new instance of the Ook interpreter.

Parameters:

  • code (String)

    The Ook code to interpret.

  • input (String) (defaults to: '')

    The input for the Ook program (optional).



14
15
16
17
# File 'lib/interpreters/ook_interpreter.rb', line 14

def initialize(code, input = '')
  super(translate_to_brainfuck(code), input)
  @input = input
end

Instance Method Details

#runString

Executes the interpretation of the Ook code.

Returns:

  • (String)

    The result of the Ook interpretation.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/interpreters/ook_interpreter.rb', line 22

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 increment
    when '-' then decrement
    when '[' then loop_begin
    when ']' then loop_end
    when '?' then banana
    end

    @code_pointer += 1
  end

  translate_output_bytes_to_chars
end