rpl.rb/lib/runner.rb

29 lines
597 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2021-11-10 11:01:26 +01:00
module Rpl
2021-12-07 15:50:58 +01:00
module Lang
class Runner
def initialize; end
2021-11-10 11:01:26 +01:00
def run_input( input, stack, dictionary )
2021-12-07 15:50:58 +01:00
input.each do |elt|
case elt[:type]
when :word
2021-12-08 16:38:46 +01:00
command = dictionary.lookup( elt[:value] )
2021-11-10 11:01:26 +01:00
2021-12-07 15:50:58 +01:00
if command.nil?
stack << { type: :name, value: "'#{elt[:value]}'" }
else
stack, dictionary = command.call( stack, dictionary )
2021-12-07 15:50:58 +01:00
end
2021-11-10 11:01:26 +01:00
else
2021-12-07 15:50:58 +01:00
stack << elt
2021-11-10 11:01:26 +01:00
end
end
2021-12-07 15:50:58 +01:00
[stack, dictionary]
end
2021-11-10 11:01:26 +01:00
end
end
end