Module: Trxl::Multitive2

Defined in:
lib/trxl/trxl_grammar.rb

Instance Method Summary collapse

Instance Method Details

#eval(env = Environment.new) ⇒ Object



3382
3383
3384
3385
3386
3387
3388
# File 'lib/trxl/trxl_grammar.rb', line 3382

def eval(env = Environment.new)
  # left associative evaluation
  multitives(env).inject(exponential.eval(env)) do |operand, next_op|
    op = (next_op[0].text_value == '/' ? (operand ? operand.to_f : nil) : operand)
    next_op[0].apply(op, next_op[1])
  end
end

#multitives(env = Environment.new) ⇒ Object



3390
3391
3392
# File 'lib/trxl/trxl_grammar.rb', line 3390

def multitives(env = Environment.new)
  tail.elements.map { |e| [ e.multitive_op, e.exponential.eval(env) ] }
end