Class: Nodewrap::ByteDecoder::Expression::Infix

Inherits:
Nodewrap::ByteDecoder::Expression show all
Defined in:
lib/bytedecoder.rb

Instance Attribute Summary collapse

Attributes inherited from Nodewrap::ByteDecoder::Expression

#pc

Instance Method Summary collapse

Methods inherited from Nodewrap::ByteDecoder::Expression

#<=>, #fmt

Constructor Details

#initialize(pc, op, lhs, rhs) ⇒ Infix

Returns a new instance of Infix.



100
101
102
103
104
105
# File 'lib/bytedecoder.rb', line 100

def initialize(pc, op, lhs, rhs)
  super(pc)
  @op = op
  @lhs = lhs
  @rhs = rhs
end

Instance Attribute Details

#lhsObject (readonly)

Returns the value of attribute lhs.



97
98
99
# File 'lib/bytedecoder.rb', line 97

def lhs
  @lhs
end

#opObject (readonly)

Returns the value of attribute op.



96
97
98
# File 'lib/bytedecoder.rb', line 96

def op
  @op
end

#rhsObject (readonly)

Returns the value of attribute rhs.



98
99
100
# File 'lib/bytedecoder.rb', line 98

def rhs
  @rhs
end

Instance Method Details

#precedenceObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/bytedecoder.rb', line 111

def precedence
  case @op
  when :*, :/, :%
    return 2
  when '+'.intern, '-'.intern
    return 3
  when :<<, :>>
    return 4
  when :>, :>=, :<, :<=, :==, :===
    return 5
  else
    raise ArgumentError, "Unknown op: #{@op}"
  end
end

#to_sObject



107
108
109
# File 'lib/bytedecoder.rb', line 107

def to_s
  return "#{fmt(@lhs)} #{@op} #{fmt(@rhs)}"
end