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

28 lines
597 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, dictionary = command.call( stack, dictionary )
end
else
stack << elt
end
end
[stack, dictionary]
end
end
end
end