Class: Keisan::AST::CellAssignment

Inherits:
Object
  • Object
show all
Defined in:
lib/keisan/ast/cell_assignment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(assignment, context, lhs, rhs) ⇒ CellAssignment

Returns a new instance of CellAssignment.



6
7
8
9
10
11
# File 'lib/keisan/ast/cell_assignment.rb', line 6

def initialize(assignment, context, lhs, rhs)
  @assignment = assignment
  @context = context
  @lhs = lhs
  @rhs = rhs
end

Instance Attribute Details

#assignmentObject (readonly)

Returns the value of attribute assignment.



4
5
6
# File 'lib/keisan/ast/cell_assignment.rb', line 4

def assignment
  @assignment
end

#contextObject (readonly)

Returns the value of attribute context.



4
5
6
# File 'lib/keisan/ast/cell_assignment.rb', line 4

def context
  @context
end

#lhsObject (readonly)

Returns the value of attribute lhs.



4
5
6
# File 'lib/keisan/ast/cell_assignment.rb', line 4

def lhs
  @lhs
end

#rhsObject (readonly)

Returns the value of attribute rhs.



4
5
6
# File 'lib/keisan/ast/cell_assignment.rb', line 4

def rhs
  @rhs
end

Instance Method Details

#evaluateObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/keisan/ast/cell_assignment.rb', line 13

def evaluate
  lhs = lhs_evaluate_and_check_modifiable

  unless lhs.is_a?(Cell)
    raise Exceptions::InvalidExpression.new("Unhandled left hand side #{lhs} in assignment")
  end

  case assignment.compound_operator
  when :"||"
    evaluate_cell_or_assignment(context, lhs, rhs)
  when :"&&"
    evaluate_cell_and_assignment(context, lhs, rhs)
  else
    evaluate_cell_non_logical_assignment(context, lhs, rhs)
  end
end