Class: Yadriggy::ForLoop

Inherits:
ASTnode show all
Includes:
AstHelper
Defined in:
lib/yadriggy/ast.rb

Overview

For statement.

Instance Attribute Summary collapse

Attributes inherited from ASTnode

#parent, #usertype

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AstHelper

#has_tag?, #to_node, #to_nodes

Methods inherited from ASTnode

#add_child, #add_children, #const_value, #const_value_in_class, #get_context_class, #get_receiver_object, #is_proc?, #pretty_print, #root, #source_location, #source_location_string, #value, #value_in_class

Constructor Details

#initialize(sexp) ⇒ ForLoop

Returns a new instance of ForLoop.



1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
# File 'lib/yadriggy/ast.rb', line 1120

def initialize(sexp)
  if sexp[1][0] == :var_field
    @vars = [ to_node(sexp[1][1]) ]
  else
    @vars = to_nodes(sexp[1])
  end
  @set = to_node(sexp[2])
  @body = Exprs.make(sexp[3])
  add_children(@vars)
  add_child(@set)
  add_child(@body)
end

Instance Attribute Details

#bodyASTnode (readonly)

Returns the loop body.

Returns:



1116
1117
1118
# File 'lib/yadriggy/ast.rb', line 1116

def body
  @body
end

#setASTnode (readonly)

Returns the elements.

Returns:



1113
1114
1115
# File 'lib/yadriggy/ast.rb', line 1113

def set
  @set
end

#varsArray<ASTnode> (readonly)

Returns the variables.

Returns:

  • (Array<ASTnode>)

    the variables.



1110
1111
1112
# File 'lib/yadriggy/ast.rb', line 1110

def vars
  @vars
end

Class Method Details

.tagObject



1118
# File 'lib/yadriggy/ast.rb', line 1118

def self.tag() :for end

Instance Method Details

#accept(evaluator) ⇒ void

This method returns an undefined value.

A method for Visitor pattern.

Parameters:

  • evaluator (Eval)

    the visitor of Visitor pattern.



1136
1137
1138
# File 'lib/yadriggy/ast.rb', line 1136

def accept(evaluator)
  evaluator.for_loop(self)
end