Class: OperatorNode

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

Instance Method Summary collapse

Constructor Details

#initialize(op, *args) ⇒ OperatorNode

Returns a new instance of OperatorNode.



144
145
146
147
148
149
# File 'lib/code_generator.rb', line 144

def initialize op, *args
  @value = op
  @children = args
  @expr1 = @children[0]
  @expr2 = @children[1]
end

Instance Method Details

#columnObject



177
178
179
180
181
182
183
# File 'lib/code_generator.rb', line 177

def column
  c1 = @expr1.column
  c2 = @expr1.column
  return c1 if c1 != 'base'
  return c2 if c2 != 'base'
  'base'
end

#error_msgObject



164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/code_generator.rb', line 164

def error_msg
  case @value
  when :gteq  then 'to be greater than or equal to'
  when :lteq  then 'to be less than or equal to'
  when :neq   then 'to not equal'
  when :eq    then 'to be equal to'
  when :gt    then 'to be greater than'
  when :lt    then 'to be less than'
  when :plus  then 'plus'
  when :match then 'to match'
  end
end

#genObject



185
186
187
# File 'lib/code_generator.rb', line 185

def gen
  operation.gen
end

#operationObject



151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/code_generator.rb', line 151

def operation
  case @value
  when :gteq, :lteq, :neq, :eq, :gt, :lt
    ComparisonExpr.new @value, @expr1, @expr2
  when :plus
    MathExpr.new @value, @expr1, @expr2
  when :match
    MatchExpr.new @expr1, @expr2
  when :and
    AndExpr.new @expr1, @expr2
  end
end