Class: EleetScript::Interpreter
- Inherits:
-
Object
- Object
- EleetScript::Interpreter
- Defined in:
- lib/lang/interpreter.rb
Instance Attribute Summary collapse
-
#memory ⇒ Object
readonly
Returns the value of attribute memory.
Instance Method Summary collapse
- #eval(code, show_nodes = false) ⇒ Object
- #eval_with_context(code, context) ⇒ Object
-
#initialize(memory = nil) ⇒ Interpreter
constructor
A new instance of Interpreter.
- #load(file_name) ⇒ Object
Constructor Details
#initialize(memory = nil) ⇒ Interpreter
Returns a new instance of Interpreter.
7 8 9 10 11 |
# File 'lib/lang/interpreter.rb', line 7 def initialize(memory = nil) @parser = Parser.new @memory = memory || Memory.new @memory.bootstrap(self) end |
Instance Attribute Details
#memory ⇒ Object (readonly)
Returns the value of attribute memory.
6 7 8 |
# File 'lib/lang/interpreter.rb', line 6 def memory @memory end |
Instance Method Details
#eval(code, show_nodes = false) ⇒ Object
13 14 15 16 17 |
# File 'lib/lang/interpreter.rb', line 13 def eval(code, show_nodes = false) nodes = @parser.parse(code) puts nodes if show_nodes nodes.eval(@memory.root_namespace) end |
#eval_with_context(code, context) ⇒ Object
19 20 21 22 |
# File 'lib/lang/interpreter.rb', line 19 def eval_with_context(code, context) nodes = @parser.parse(code) nodes.eval(context) end |
#load(file_name) ⇒ Object
24 25 26 27 28 |
# File 'lib/lang/interpreter.rb', line 24 def load(file_name) if File.exists?(file_name) eval(File.read(file_name)) end end |