class Theta::Base
runs the interpreter
Public Class Methods
new()
click to toggle source
# File lib/theta.rb, line 7 def initialize @interpreter = Interpreter.new end
Public Instance Methods
load_file(file_path)
click to toggle source
load and run the given file
# File lib/theta.rb, line 12 def load_file(file_path) program = File.open(file_path) { |f| f.read } run program end
repl()
click to toggle source
start an interactive interpreter
# File lib/theta.rb, line 26 def repl puts "For interpreter commands, type 'help'" while true print "theta> " input = gets.chomp case input #when "clear" # puts "Resetting environment..." # @interpreter = Interpreter.new when "exit", 24.chr puts "Exiting..." return when "help" repl_help else begin output = @interpreter.run(input) rescue SyntaxError end if not output.nil? and not output.empty? output.each { |value| puts @interpreter.make_readable(value) } end end end end
repl_help()
click to toggle source
# File lib/theta.rb, line 52 def repl_help #puts "'clear' resets the environment" puts "'exit' or Ctrl-X will exit the interpreter" puts "'help' will display this message" end
run(program)
click to toggle source
run given code
# File lib/theta.rb, line 18 def run(program) output = @interpreter.run(program) if not output.nil? and not output.empty? output.each { |value| puts @interpreter.make_readable(value) } end end