Class: Yadriggy::Binary

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

Overview

Binary expression.

Direct Known Subclasses

Assign, Dots

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, #get_context_class, #get_receiver_object, #is_proc?, #pretty_print, #root, #source_location, #source_location_string

Constructor Details

#initialize(sexp) ⇒ Binary

Returns a new instance of Binary.



663
664
665
666
667
668
669
# File 'lib/yadriggy/ast.rb', line 663

def initialize(sexp)
  @left = to_node(sexp[1])
  @op = sexp[2]	# symbol
  @right = to_node(sexp[3])
  add_child(@left)
  add_child(@right)
end

Instance Attribute Details

#leftASTnode (readonly)

Returns the left operand.

Returns:



655
656
657
# File 'lib/yadriggy/ast.rb', line 655

def left
  @left
end

#opSymbol (readonly)

Returns the operator.

Returns:

  • (Symbol)

    the operator.



657
658
659
# File 'lib/yadriggy/ast.rb', line 657

def op
  @op
end

#rightASTnode (readonly)

Returns the right operand.

Returns:



659
660
661
# File 'lib/yadriggy/ast.rb', line 659

def right
  @right
end

Class Method Details

.tagObject



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

def self.tag() :binary 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.



674
675
676
# File 'lib/yadriggy/ast.rb', line 674

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

#const_valueObject



364
365
366
# File 'lib/yadriggy/ast_value.rb', line 364

def const_value()
  send_op_to_value(@left.const_value, @right.const_value)
end

#const_value_in_class(klass) ⇒ Object



368
369
370
371
# File 'lib/yadriggy/ast_value.rb', line 368

def const_value_in_class(klass)
  send_op_to_value(@left.const_value_in_class(klass),
                   @right.const_value_in_class(klass))
end

#valueObject



355
356
357
# File 'lib/yadriggy/ast_value.rb', line 355

def value()
  send_op_to_value(@left.value, @right.value)
end

#value_in_class(klass) ⇒ Object



359
360
361
362
# File 'lib/yadriggy/ast_value.rb', line 359

def value_in_class(klass)
  send_op_to_value(@left.value_in_class(klass),
                   @right.value_in_class(klass))
end