Class: BefungeInterpreter

Inherits:
Object
  • Object
show all
Includes:
Operations
Defined in:
lib/befunge_interpreter.rb

Overview

This is the top-level class containing everything needed to interpret befunge code. Intialize with a string location of a filename and an array of flags and then call BefungeInterpreter#interpret. This will run the befunge code. TODO: Implement flags - debugging mode, animation mode.

Constant Summary

Constants included from Operations

Operations::DIRECTIONS, Operations::DIRECTIONS_MAP, Operations::DIRECTION_OPS, Operations::MATH_OPS, Operations::OPERATORS, Operations::OPERATORS_MAP

Instance Method Summary collapse

Methods included from Operations

#change_dir, #duplicate_stack_top, #end_program, #get_call, #get_user_input_char, #get_user_input_int, #greater_than, #left_right, #logical_not, #operate!, #pop_and_discard, #pop_and_display_char, #pop_and_display_int, #push_ascii_value, #push_num, #put_call, #rand_direction, #string_mode, #swap_stack_top, #trampoline, #up_down

Constructor Details

#initialize(file, flags) ⇒ BefungeInterpreter

Returns a new instance of BefungeInterpreter.



9
10
11
12
13
14
15
16
# File 'lib/befunge_interpreter.rb', line 9

def initialize(file, flags)
  @code_map = CodeMap.new(file)
  @flags = flags
  @stack = Stack.new
  @string_mode = false
  @computing = true
  @return_string = ''
end

Instance Method Details

#interpretObject



18
19
20
# File 'lib/befunge_interpreter.rb', line 18

def interpret
  operate_and_step while @computing
end