class Keisan::AST::Node
Public Instance Methods
!()
click to toggle source
# File lib/keisan/ast/node.rb, line 134 def ! UnaryLogicalNot.new(self) end
%(other)
click to toggle source
# File lib/keisan/ast/node.rb, line 128 def %(other) Modulo.new( [self, other.to_node] ) end
&(other)
click to toggle source
# File lib/keisan/ast/node.rb, line 154 def &(other) BitwiseAnd.new([self, other.to_node]) end
*(other)
click to toggle source
# File lib/keisan/ast/node.rb, line 116 def *(other) Times.new( [self, other.to_node] ) end
**(other)
click to toggle source
# File lib/keisan/ast/node.rb, line 150 def **(other) Exponent.new([self, other.to_node]) end
+(other)
click to toggle source
# File lib/keisan/ast/node.rb, line 104 def +(other) Plus.new( [self, other.to_node] ) end
+@()
click to toggle source
# File lib/keisan/ast/node.rb, line 142 def +@ self end
-(other)
click to toggle source
# File lib/keisan/ast/node.rb, line 110 def -(other) Plus.new( [self, UnaryMinus.new(other.to_node)] ) end
-@()
click to toggle source
# File lib/keisan/ast/node.rb, line 146 def -@ UnaryMinus.new(self) end
/(other)
click to toggle source
# File lib/keisan/ast/node.rb, line 122 def /(other) Times.new( [self, UnaryInverse.new(other.to_node)] ) end
<(other)
click to toggle source
# File lib/keisan/ast/node.rb, line 182 def <(other) LogicalLessThan.new([self, other.to_node]) end
<<(other)
click to toggle source
# File lib/keisan/ast/node.rb, line 166 def <<(other) BitwiseLeftShift.new([self, other.to_node]) end
<=(other)
click to toggle source
# File lib/keisan/ast/node.rb, line 186 def <=(other) LogicalLessThanOrEqualTo.new([self, other.to_node]) end
>(other)
click to toggle source
# File lib/keisan/ast/node.rb, line 174 def >(other) LogicalGreaterThan.new([self, other.to_node]) end
>=(other)
click to toggle source
# File lib/keisan/ast/node.rb, line 178 def >=(other) LogicalGreaterThanOrEqualTo.new([self, other.to_node]) end
>>(other)
click to toggle source
# File lib/keisan/ast/node.rb, line 170 def >>(other) BitwiseRightShift.new([self, other.to_node]) end
^(other)
click to toggle source
# File lib/keisan/ast/node.rb, line 158 def ^(other) BitwiseXor.new([self, other.to_node]) end
and(other)
click to toggle source
# File lib/keisan/ast/node.rb, line 198 def and(other) LogicalAnd.new([self, other.to_node]) end
coerce(other)
click to toggle source
# File lib/keisan/ast/node.rb, line 83 def coerce(other) [other.to_node, self] end
contains_a?(klass)
click to toggle source
# File lib/keisan/ast/node.rb, line 48 def contains_a?(klass) case klass when Array klass.any? do |k| traverse do |node| node.is_a?(k) end end else traverse do |node| node.is_a?(klass) end end end
deep_dup()
click to toggle source
# File lib/keisan/ast/node.rb, line 20 def deep_dup dup end
differentiate(variable, context = nil)
click to toggle source
# File lib/keisan/ast/node.rb, line 67 def differentiate(variable, context = nil) raise Exceptions::NonDifferentiableError.new end
differentiated(variable, context = nil)
click to toggle source
# File lib/keisan/ast/node.rb, line 71 def differentiated(variable, context = nil) deep_dup.differentiate(variable, context) end
equal(other)
click to toggle source
# File lib/keisan/ast/node.rb, line 190 def equal(other) LogicalEqual.new([self, other.to_node]) end
evaluate(context = nil)
click to toggle source
# File lib/keisan/ast/node.rb, line 36 def evaluate(context = nil) value(context) end
evaluate_assignments(context = nil)
click to toggle source
# File lib/keisan/ast/node.rb, line 63 def evaluate_assignments(context = nil) self end
evaluated(context = nil)
click to toggle source
# File lib/keisan/ast/node.rb, line 32 def evaluated(context = nil) deep_dup.evaluate(context) end
false?()
click to toggle source
# File lib/keisan/ast/node.rb, line 100 def false? !true? end
is_constant?()
click to toggle source
# File lib/keisan/ast/node.rb, line 206 def is_constant? false end
not_equal(other)
click to toggle source
# File lib/keisan/ast/node.rb, line 194 def not_equal(other) LogicalNotEqual.new([self, other.to_node]) end
or(other)
click to toggle source
# File lib/keisan/ast/node.rb, line 202 def or(other) LogicalOr.new([self, other.to_node]) end
replace(variable, replacement)
click to toggle source
# File lib/keisan/ast/node.rb, line 75 def replace(variable, replacement) self end
replaced(variable, replacement)
click to toggle source
# File lib/keisan/ast/node.rb, line 79 def replaced(variable, replacement) deep_dup.replace(variable, replacement) end
simplified(context = nil)
click to toggle source
# File lib/keisan/ast/node.rb, line 24 def simplified(context = nil) deep_dup.simplify(context) end
simplify(context = nil)
click to toggle source
# File lib/keisan/ast/node.rb, line 28 def simplify(context = nil) self end
to_cell()
click to toggle source
# File lib/keisan/ast/node.rb, line 91 def to_cell AST::Cell.new(self) end
to_node()
click to toggle source
# File lib/keisan/ast/node.rb, line 87 def to_node self end
traverse(&block)
click to toggle source
Takes a block, and does a DFS down the AST
, evaluating the received block at each node, passing in the node as the single argument. If the block returns a truthy value at any point, the DFS ends and the return value is percolated up the tree.
# File lib/keisan/ast/node.rb, line 44 def traverse(&block) block.call(self) end
true?()
click to toggle source
Will only return False for AST::Boolean(false) and AST::Null
# File lib/keisan/ast/node.rb, line 96 def true? true end
unbound_functions(context = nil)
click to toggle source
# File lib/keisan/ast/node.rb, line 12 def unbound_functions(context = nil) Set.new end
unbound_variables(context = nil)
click to toggle source
# File lib/keisan/ast/node.rb, line 8 def unbound_variables(context = nil) Set.new end
value(context = nil)
click to toggle source
# File lib/keisan/ast/node.rb, line 4 def value(context = nil) raise Exceptions::NotImplementedError.new end
well_defined?(context = nil)
click to toggle source
# File lib/keisan/ast/node.rb, line 16 def well_defined?(context = nil) unbound_variables(context).empty? && unbound_functions(context).empty? end
|(other)
click to toggle source
# File lib/keisan/ast/node.rb, line 162 def |(other) BitwiseOr.new([self, other.to_node]) end
~()
click to toggle source
# File lib/keisan/ast/node.rb, line 138 def ~ UnaryBitwiseNot.new(self) end