class BinaryParser::Expression

Public Class Methods

control_var(symbol) click to toggle source
# File lib/binary_parser/general_class/expression.rb, line 12
def self.control_var(symbol)
  Token::Variable::Control.new(symbol)
end
immediate(value) click to toggle source
# File lib/binary_parser/general_class/expression.rb, line 20
def self.immediate(value)
  Token::Immediate.new(value)
end
length_var(symbol) click to toggle source
# File lib/binary_parser/general_class/expression.rb, line 8
def self.length_var(symbol)
  Token::Variable::Length.new(symbol)
end
new(*args) click to toggle source
# File lib/binary_parser/general_class/expression.rb, line 94
def initialize(*args)
  raise BadManipulationError, "Expression is abstract class."
end
nextbits_var(length) click to toggle source
# File lib/binary_parser/general_class/expression.rb, line 16
def self.nextbits_var(length)
  Token::Variable::Nextbits.new(length)
end
value_var(symbol) click to toggle source
# File lib/binary_parser/general_class/expression.rb, line 4
def self.value_var(symbol)
  Token::Variable::Value.new(symbol)
end

Public Instance Methods

%(other) click to toggle source
# File lib/binary_parser/general_class/expression.rb, line 68
def %(other)
  binary_op(other, Token::Operator::Mod.instance)
end
*(other) click to toggle source
# File lib/binary_parser/general_class/expression.rb, line 60
def *(other)
  binary_op(other, Token::Operator::Mul.instance)
end
+(other) click to toggle source
# File lib/binary_parser/general_class/expression.rb, line 52
def +(other)
  binary_op(other, Token::Operator::Add.instance)
end
-(other) click to toggle source
# File lib/binary_parser/general_class/expression.rb, line 56
def -(other)
  binary_op(other, Token::Operator::Sub.instance)
end
/(other) click to toggle source
# File lib/binary_parser/general_class/expression.rb, line 64
def /(other)
  binary_op(other, Token::Operator::Div.instance)
end
binary_op(other, op) click to toggle source
# File lib/binary_parser/general_class/expression.rb, line 72
def binary_op(other, op)
  BinaryOperator.new(self, other, op)
end
coerce(other) click to toggle source
Calls superclass method
# File lib/binary_parser/general_class/expression.rb, line 44
def coerce(other)
  if other.is_a?(Integer)
    return Token::Immediate.new(other), self
  else
    super
  end
end
control_var?() click to toggle source
# File lib/binary_parser/general_class/expression.rb, line 32
def control_var?
  self.is_a?(Token::Variable::Control)
end
eval(&token_eval_proc) click to toggle source
# File lib/binary_parser/general_class/expression.rb, line 86
def eval(&token_eval_proc)
  to_rpn.eval(&token_eval_proc)
end
immediate?() click to toggle source
# File lib/binary_parser/general_class/expression.rb, line 40
def immediate?
  self.is_a?(Token::Immediate)
end
length_var?() click to toggle source
# File lib/binary_parser/general_class/expression.rb, line 28
def length_var?
  self.is_a?(Token::Variable::Length)
end
nextbits_var?() click to toggle source
# File lib/binary_parser/general_class/expression.rb, line 36
def nextbits_var?
  self.is_a?(Token::Variable::Nextbits)
end
to_exp(exp) click to toggle source
# File lib/binary_parser/general_class/expression.rb, line 76
def to_exp(exp)
  if exp.is_a?(Expression)
    exp
  elsif exp.is_a?(Integer)
    Token::Immediate.new(exp)
  else
    raise BadManipulationError, "Can't convert #{exp} into Expression."
  end
end
value_var?() click to toggle source
# File lib/binary_parser/general_class/expression.rb, line 24
def value_var?
  self.is_a?(Token::Variable::Value)
end
variable_tokens() click to toggle source
# File lib/binary_parser/general_class/expression.rb, line 90
def variable_tokens
  to_rpn.tokens.select{|token| token.is_a?(Token::Variable)}
end