Module: Trxl::Additive2

Defined in:
lib/trxl/trxl_grammar.rb

Instance Method Summary collapse

Instance Method Details

#additives(env = Environment.new) ⇒ Object



3244
3245
3246
# File 'lib/trxl/trxl_grammar.rb', line 3244

def additives(env = Environment.new)
  tail.elements.map { |e| [ e.additive_op, e.multitive.eval(env) ] }
end

#eval(env = Environment.new) ⇒ Object



3237
3238
3239
3240
3241
3242
# File 'lib/trxl/trxl_grammar.rb', line 3237

def eval(env = Environment.new)
  # left associative evaluation
  additives(env).inject(multitive.eval(env)) do |result, next_op|
    next_op[0].apply(result, next_op[1])
  end
end