Class: Rubic::Interpreter
- Inherits:
-
Object
- Object
- Rubic::Interpreter
- Defined in:
- lib/rubic/interpreter.rb
Constant Summary collapse
- DEFAULT_GLOBAL_VARS =
{ :not => -> (a) { !a }, :eq? => -> (a, b) { a.equal? b }, :true => true, :false => false, :nil => [], }
Instance Method Summary collapse
- #evaluate(str) ⇒ Object
-
#initialize ⇒ Interpreter
constructor
A new instance of Interpreter.
Constructor Details
#initialize ⇒ Interpreter
Returns a new instance of Interpreter.
16 17 18 19 20 21 22 |
# File 'lib/rubic/interpreter.rb', line 16 def initialize @parser = Parser.new @global = Environment.new DEFAULT_GLOBAL_VARS.each {|k, v| @global[k] = v } builtins = Rubic::Builtin.constants.map {|c| Rubic::Builtin.const_get(c) } builtins.each {|ext| @global.extend(ext) } end |
Instance Method Details
#evaluate(str) ⇒ Object
24 25 26 27 |
# File 'lib/rubic/interpreter.rb', line 24 def evaluate(str) seq = @parser.parse(str) execute_sequence(seq, @global) end |