Class: ProgramNode
- Inherits:
-
Object
- Object
- ProgramNode
- Defined in:
- lib/nodes.rb
Overview
Root node for program. Stores statements and evaluates them.
Instance Attribute Summary collapse
-
#statements ⇒ Object
readonly
Returns the value of attribute statements.
Instance Method Summary collapse
- #evaluate ⇒ Object
-
#initialize(statements) ⇒ ProgramNode
constructor
A new instance of ProgramNode.
Constructor Details
#initialize(statements) ⇒ ProgramNode
Returns a new instance of ProgramNode.
205 206 207 |
# File 'lib/nodes.rb', line 205 def initialize(statements) @statements = statements end |
Instance Attribute Details
#statements ⇒ Object (readonly)
Returns the value of attribute statements.
204 205 206 |
# File 'lib/nodes.rb', line 204 def statements @statements end |
Instance Method Details
#evaluate ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/nodes.rb', line 209 def evaluate global_scope = Scope.new result = nil @statements.each do |statement| result = statement.evaluate(global_scope) return result.value if statement.is_a?(ReturnNode) end if result.is_a?(ReturnValue) return result.value else return result end end |