rpl.rb/lib/core/program.rb

24 lines
709 B
Ruby
Raw Normal View History

2021-12-07 16:09:17 +01:00
# frozen_string_literal: true
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-11-18 12:11:19 +01:00
[stack, dictionary]
2021-12-07 15:50:58 +01:00
end
2021-11-18 12:00:02 +01:00
end
end
end