rpl.rb/lib/runner.rb
2021-12-07 16:03:03 +01:00

28 lines
573 B
Ruby

# frozen_string_literal: true
module Rpl
module Lang
class Runner
def initialize; end
def run_input( input, stack, dictionary )
input.each do |elt|
case elt[:type]
when :word
command = dictionary.lookup( elt[:value] )
if command.nil?
stack << { type: :name, value: "'#{elt[:value]}'" }
else
stack = command.call( stack )
end
else
stack << elt
end
end
[stack, dictionary]
end
end
end
end