Class: Keisan::AST::Node

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

Direct Known Subclasses

Block, Cell, Hash, Literal, Parent

Instance Method Summary collapse

Instance Method Details

#!Object



103
104
105
# File 'lib/keisan/ast/node.rb', line 103

def !
  UnaryLogicalNot.new(self)
end

#%(other) ⇒ Object



97
98
99
100
101
# File 'lib/keisan/ast/node.rb', line 97

def %(other)
  Modulo.new(
    [self, other.to_node]
  )
end

#&(other) ⇒ Object



123
124
125
# File 'lib/keisan/ast/node.rb', line 123

def &(other)
  BitwiseAnd.new([self, other.to_node])
end

#*(other) ⇒ Object



85
86
87
88
89
# File 'lib/keisan/ast/node.rb', line 85

def *(other)
  Times.new(
    [self, other.to_node]
  )
end

#**(other) ⇒ Object



119
120
121
# File 'lib/keisan/ast/node.rb', line 119

def **(other)
  Exponent.new([self, other.to_node])
end

#+(other) ⇒ Object



73
74
75
76
77
# File 'lib/keisan/ast/node.rb', line 73

def +(other)
  Plus.new(
    [self, other.to_node]
  )
end

#+@Object



111
112
113
# File 'lib/keisan/ast/node.rb', line 111

def +@
  self
end

#-(other) ⇒ Object



79
80
81
82
83
# File 'lib/keisan/ast/node.rb', line 79

def -(other)
  Plus.new(
    [self, UnaryMinus.new(other.to_node)]
  )
end

#-@Object



115
116
117
# File 'lib/keisan/ast/node.rb', line 115

def -@
  UnaryMinus.new(self)
end

#/(other) ⇒ Object



91
92
93
94
95
# File 'lib/keisan/ast/node.rb', line 91

def /(other)
  Times.new(
    [self, UnaryInverse.new(other.to_node)]
  )
end

#<(other) ⇒ Object



143
144
145
# File 'lib/keisan/ast/node.rb', line 143

def <(other)
  LogicalLessThan.new([self, other.to_node])
end

#<=(other) ⇒ Object



147
148
149
# File 'lib/keisan/ast/node.rb', line 147

def <=(other)
  LogicalLessThanOrEqualTo.new([self, other.to_node])
end

#>(other) ⇒ Object



135
136
137
# File 'lib/keisan/ast/node.rb', line 135

def >(other)
  LogicalGreaterThan.new([self, other.to_node])
end

#>=(other) ⇒ Object



139
140
141
# File 'lib/keisan/ast/node.rb', line 139

def >=(other)
  LogicalGreaterThanOrEqualTo.new([self, other.to_node])
end

#^(other) ⇒ Object



127
128
129
# File 'lib/keisan/ast/node.rb', line 127

def ^(other)
  BitwiseXor.new([self, other.to_node])
end

#and(other) ⇒ Object



159
160
161
# File 'lib/keisan/ast/node.rb', line 159

def and(other)
  LogicalAnd.new([self, other.to_node])
end

#coerce(other) ⇒ Object



52
53
54
# File 'lib/keisan/ast/node.rb', line 52

def coerce(other)
  [other.to_node, self]
end

#deep_dupObject



20
21
22
# File 'lib/keisan/ast/node.rb', line 20

def deep_dup
  dup
end

#differentiate(variable, context = nil) ⇒ Object



44
45
46
# File 'lib/keisan/ast/node.rb', line 44

def differentiate(variable, context = nil)
  raise Exceptions::NonDifferentiableError.new
end

#equal(other) ⇒ Object



151
152
153
# File 'lib/keisan/ast/node.rb', line 151

def equal(other)
  LogicalEqual.new([self, other.to_node])
end

#evaluate(context = nil) ⇒ Object



36
37
38
# File 'lib/keisan/ast/node.rb', line 36

def evaluate(context = nil)
  value(context)
end

#evaluate_assignments(context = nil) ⇒ Object



40
41
42
# File 'lib/keisan/ast/node.rb', line 40

def evaluate_assignments(context = nil)
  self
end

#evaluated(context = nil) ⇒ Object



32
33
34
# File 'lib/keisan/ast/node.rb', line 32

def evaluated(context = nil)
  deep_dup.evaluate(context)
end

#false?Boolean

Returns:



69
70
71
# File 'lib/keisan/ast/node.rb', line 69

def false?
  !true?
end

#not_equal(other) ⇒ Object



155
156
157
# File 'lib/keisan/ast/node.rb', line 155

def not_equal(other)
  LogicalNotEqual.new([self, other.to_node])
end

#or(other) ⇒ Object



163
164
165
# File 'lib/keisan/ast/node.rb', line 163

def or(other)
  LogicalOr.new([self, other.to_node])
end

#replace(variable, replacement) ⇒ Object



48
49
50
# File 'lib/keisan/ast/node.rb', line 48

def replace(variable, replacement)
  self
end

#simplified(context = nil) ⇒ Object



24
25
26
# File 'lib/keisan/ast/node.rb', line 24

def simplified(context = nil)
  deep_dup.simplify(context)
end

#simplify(context = nil) ⇒ Object



28
29
30
# File 'lib/keisan/ast/node.rb', line 28

def simplify(context = nil)
  self
end

#to_cellObject



60
61
62
# File 'lib/keisan/ast/node.rb', line 60

def to_cell
  AST::Cell.new(self)
end

#to_nodeObject



56
57
58
# File 'lib/keisan/ast/node.rb', line 56

def to_node
  self
end

#true?Boolean

Will only return False for AST::Boolean(false) and AST::Null

Returns:



65
66
67
# File 'lib/keisan/ast/node.rb', line 65

def true?
  true
end

#unbound_functions(context = nil) ⇒ Object



12
13
14
# File 'lib/keisan/ast/node.rb', line 12

def unbound_functions(context = nil)
  Set.new
end

#unbound_variables(context = nil) ⇒ Object



8
9
10
# File 'lib/keisan/ast/node.rb', line 8

def unbound_variables(context = nil)
  Set.new
end

#value(context = nil) ⇒ Object



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

def value(context = nil)
  raise Exceptions::NotImplementedError.new
end

#well_defined?(context = nil) ⇒ Boolean

Returns:



16
17
18
# File 'lib/keisan/ast/node.rb', line 16

def well_defined?(context = nil)
  unbound_variables(context).empty? && unbound_functions(context).empty?
end

#|(other) ⇒ Object



131
132
133
# File 'lib/keisan/ast/node.rb', line 131

def |(other)
  BitwiseOr.new([self, other.to_node])
end

#~Object



107
108
109
# File 'lib/keisan/ast/node.rb', line 107

def ~
  UnaryBitwiseNot.new(self)
end