rpl.rb/lib/runner.rb

27 lines
501 B
Ruby
Raw Normal View History

2021-11-10 11:01:26 +01:00
# coding: utf-8
module Rpn
class Runner
def initialize; end
def run_input( stack, dictionary, input )
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