Class: ProgramNode

Inherits:
Object
  • Object
show all
Defined in:
lib/nodes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(statements) ⇒ ProgramNode

Returns a new instance of ProgramNode.



161
162
163
# File 'lib/nodes.rb', line 161

def initialize(statements)
  @statements = statements
end

Instance Attribute Details

#statementsObject (readonly)

Returns the value of attribute statements.



160
161
162
# File 'lib/nodes.rb', line 160

def statements
  @statements
end

Instance Method Details

#evaluateObject



165
166
167
168
169
170
171
172
173
# File 'lib/nodes.rb', line 165

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
  return result
end