forked from proglangclass/interpreter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotruby
More file actions
executable file
·41 lines (34 loc) · 756 Bytes
/
notruby
File metadata and controls
executable file
·41 lines (34 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env ruby -s
# NotRuby interpreter
$:.unshift File.expand_path("..", __FILE__)
require "interpreter"
require "readline"
if $h # -h option
abort <<USAGE
Usage:
./notruby # start REPL
./notruby file.rb
./notruby -e='code'
USAGE
end
# Eval some code
# $e = # -e option
if $e
Interpreter.new.eval($e)
elsif ARGV.first
Interpreter.new.eval(File.read(ARGV.first))
# Start the REPL, read-eval-print-loop, or interactive interpreter
else
puts "NotRuby REPL, CTRL+C to quit"
interpreter = Interpreter.new
loop do
line = Readline::readline(">> ")
Readline::HISTORY.push(line)
begin
result = interpreter.eval(line).ruby_value
puts "=> #{result.inspect}"
rescue => error
puts error
end
end
end