2021-12-07 16:03:03 +01:00
|
|
|
# frozen_string_literal: true
|
2021-11-10 11:01:26 +01:00
|
|
|
|
2021-11-23 13:10:03 +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
|
|
|
|
2021-12-07 16:03:03 +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
|
|
|
|
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 = command.call( stack )
|
|
|
|
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
|