Class: BinaryexpressionNode

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

Direct Known Subclasses

ArithmeticNode, ComparisonNode, LogicalNode

Instance Method Summary collapse

Constructor Details

#initialize(lhs, op, rhs) ⇒ BinaryexpressionNode

Returns a new instance of BinaryexpressionNode.



194
195
196
197
198
# File 'lib/nodes.rb', line 194

def initialize(lhs, op, rhs)
  @lhs = lhs
  @op = op
  @rhs = rhs
end

Instance Method Details

#evaluate(scope) ⇒ Object



200
201
202
203
204
205
206
# File 'lib/nodes.rb', line 200

def evaluate(scope)
  rhs_value = @rhs.evaluate(scope)
  if @op == :fdiv && rhs_value == 0
    raise ZeroDivisionError,"Division by 0 not possible."
  end
  return @lhs.evaluate(scope).send(@op, rhs_value)
end