Class: Sol::Nodes
- Inherits:
-
Struct
- Object
- Struct
- Sol::Nodes
- Defined in:
- lib/sol/nodes.rb,
lib/sol/interpreter.rb
Overview
Collection of nodes each one representing an expression.
Instance Attribute Summary collapse
-
#nodes ⇒ Object
Returns the value of attribute nodes.
Instance Method Summary collapse
- #<<(node) ⇒ Object
-
#eval(context) ⇒ Object
This method is the “interpreter” part of our language.
Instance Attribute Details
#nodes ⇒ Object
Returns the value of attribute nodes
4 5 6 |
# File 'lib/sol/nodes.rb', line 4 def nodes @nodes end |
Instance Method Details
#<<(node) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/sol/nodes.rb', line 6 def <<(node) nodes << node return self end |
#eval(context) ⇒ Object
This method is the “interpreter” part of our language. All nodes know how to eval itself and returns the result of its evaluation by implementing the “eval” method. The “context” variable is the environment in which the node is evaluated (local variables, current class, etc.).
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sol/interpreter.rb', line 27 def eval(context) return_value = nil nodes.each do |node| return_value = node.eval(context) end # The last value evaluated in a method is the return value. Or null if node return_value || RuntimeModel::Runtime["null"] end |