Class: Esolang::Interpreters::Smallfuck
- Inherits:
-
BaseInterpreter
- Object
- BaseInterpreter
- Esolang::Interpreters::Smallfuck
- Defined in:
- lib/interpreters/smallfuck_interpreter.rb
Overview
The Smallfuck class represents an interpreter for the Smallfuck esoteric programming language.
Instance Method Summary collapse
-
#initialize(code, tape) ⇒ Smallfuck
constructor
Initializes a new instance of the Smallfuck interpreter.
-
#run ⇒ String
Executes the interpretation of the Smallfuck code.
Constructor Details
#initialize(code, tape) ⇒ Smallfuck
Initializes a new instance of the Smallfuck interpreter.
13 14 15 16 |
# File 'lib/interpreters/smallfuck_interpreter.rb', line 13 def initialize(code, tape) super(code.gsub(/[^<>\*\[\]]/, '')) @tape = tape.chars.map(&:to_i) end |
Instance Method Details
#run ⇒ String
Executes the interpretation of the Smallfuck code.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/interpreters/smallfuck_interpreter.rb', line 21 def run while running? do case command when '>' then move_right when '<' then move_left when '*' then flip when '[' then loop_begin when ']' then loop_end end @code_pointer += 1 end @tape.join end |