rpl.rb/lib/core/program.rb

23 lines
725 B
Ruby
Raw Normal View History

module Rpl
2021-12-07 15:50:58 +01:00
module Lang
module Core
module_function
2021-11-18 12:00:02 +01:00
2021-12-07 15:50:58 +01:00
# evaluate (run) a program, or recall a variable. ex: 'my_prog' eval
def eval( stack, dictionary )
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[program word name]] )
2021-11-18 12:00:02 +01:00
2021-12-07 15:50:58 +01:00
# we trim enclosing «»
preparsed_input = args[0][:type] == :word ? args[0][:value] : args[0][:value][1..-2]
parsed_input = Rpl::Lang::Parser.new.parse_input( preparsed_input )
2021-11-18 12:00:02 +01:00
stack, _dictionary = Rpl::Lang::Runner.new.run_input( parsed_input,
stack, dictionary )
2021-12-07 15:50:58 +01:00
# TODO: check that STO actually updates dictionary
2021-11-18 12:11:19 +01:00
2021-12-07 15:50:58 +01:00
stack
end
2021-11-18 12:00:02 +01:00
end
end
end