Class: Keisan::AST::MultiLine
Instance Attribute Summary
Attributes inherited from Parent
#children
Instance Method Summary
collapse
Methods inherited from Parent
#==, #deep_dup, #freeze, #initialize, #is_constant?, #replace, #traverse, #unbound_functions
Methods inherited from Node
#!, #%, #&, #*, #**, #+, #+@, #-, #-@, #/, #<, #<<, #<=, #>, #>=, #>>, #^, #and, #coerce, #contains_a?, #deep_dup, #differentiate, #differentiated, #equal, #evaluated, #false?, #is_constant?, #not_equal, #or, #replace, #replaced, #simplified, #to_cell, #to_node, #traverse, #true?, #unbound_functions, #well_defined?, #|, #~
Instance Method Details
#evaluate(context = nil) ⇒ Object
13
14
15
16
17
|
# File 'lib/keisan/ast/multi_line.rb', line 13
def evaluate(context = nil)
context ||= Context.new
@children = children.map {|child| child.evaluate(context)}
@children.last
end
|
#evaluate_assignments(context = nil) ⇒ Object
9
10
11
|
# File 'lib/keisan/ast/multi_line.rb', line 9
def evaluate_assignments(context = nil)
self
end
|
#simplify(context = nil) ⇒ Object
19
20
21
|
# File 'lib/keisan/ast/multi_line.rb', line 19
def simplify(context = nil)
evaluate(context)
end
|
#to_s ⇒ Object
40
41
42
|
# File 'lib/keisan/ast/multi_line.rb', line 40
def to_s
children.map(&:to_s).join(";")
end
|
#unbound_variables(context = nil) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/keisan/ast/multi_line.rb', line 23
def unbound_variables(context = nil)
context ||= Context.new
defined_variables = Set.new
children.inject(Set.new) do |unbound_vars, child|
if child.is_a?(Assignment) && child.is_variable_definition?
line_unbound_vars = unbound_variables_for_line_variable_assignment(context, child, unbound_vars, defined_variables)
if line_unbound_vars.empty?
defined_variables.add(child.variable_name)
end
unbound_vars | line_unbound_vars
else
unbound_vars | (child.unbound_variables(context) - defined_variables)
end
end
end
|
#value(context = nil) ⇒ Object
4
5
6
7
|
# File 'lib/keisan/ast/multi_line.rb', line 4
def value(context = nil)
context ||= Context.new
evaluate(context).value(context)
end
|