Class: Yadriggy::Binary
- Includes:
- AstHelper
- Defined in:
- lib/yadriggy/ast.rb,
lib/yadriggy/ast_value.rb
Overview
Binary expression.
Instance Attribute Summary collapse
-
#left ⇒ ASTnode
readonly
The left operand.
-
#op ⇒ Symbol
readonly
The operator.
-
#right ⇒ ASTnode
readonly
The right operand.
Attributes inherited from ASTnode
Class Method Summary collapse
Instance Method Summary collapse
-
#accept(evaluator) ⇒ void
A method for Visitor pattern.
- #const_value ⇒ Object
- #const_value_in_class(klass) ⇒ Object
-
#initialize(sexp) ⇒ Binary
constructor
A new instance of Binary.
- #value ⇒ Object
- #value_in_class(klass) ⇒ Object
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
#left ⇒ ASTnode (readonly)
Returns the left operand.
655 656 657 |
# File 'lib/yadriggy/ast.rb', line 655 def left @left end |
#op ⇒ Symbol (readonly)
Returns the operator.
657 658 659 |
# File 'lib/yadriggy/ast.rb', line 657 def op @op end |
#right ⇒ ASTnode (readonly)
Returns the right operand.
659 660 661 |
# File 'lib/yadriggy/ast.rb', line 659 def right @right end |
Class Method Details
.tag ⇒ Object
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.
674 675 676 |
# File 'lib/yadriggy/ast.rb', line 674 def accept(evaluator) evaluator.binary(self) end |
#const_value ⇒ Object
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 |
#value ⇒ Object
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 |