Class: WhileLoopNode

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

Overview

Loop Nodes

Instance Attribute Summary collapse

Attributes inherited from Node

#value

Instance Method Summary collapse

Methods inherited from Node

#to_s

Constructor Details

#initialize(condition, statement) ⇒ WhileLoopNode

Returns a new instance of WhileLoopNode.



248
249
250
251
# File 'lib/nodes/stmtnodes.rb', line 248

def initialize(condition, statement)
  @condition = condition
  super(statement)
end

Instance Attribute Details

#conditionObject

Returns the value of attribute condition.



246
247
248
# File 'lib/nodes/stmtnodes.rb', line 246

def condition
  @condition
end

Instance Method Details

#create_tree_entryObject



253
254
255
256
257
# File 'lib/nodes/stmtnodes.rb', line 253

def create_tree_entry
  result = set_up_scope_header
  result += "While Loop ran with #{@counter} iterations."
  TREE_ARRAY << result unless TREE_ARRAY[-1] == result
end

#evaluateObject



259
260
261
262
263
264
265
266
267
# File 'lib/nodes/stmtnodes.rb', line 259

def evaluate
  @counter = 0
  while @condition.evaluate
    @value.evaluate
    @counter += 1
  end
  create_tree_entry if PRINT_TREE_FLAG
  self.class
end