Class: Plurimath::Math::Evaluation::ExpressionParser

Inherits:
Object
  • Object
show all
Defined in:
lib/plurimath/math/evaluation/expression_parser.rb

Overview

Resolves operator precedence over the flat token sequences stored in Formula#value, delegating node evaluation back to the evaluator.

Standard recursive-descent precedence ladder — each level parses its operands at the next-tighter level, so the operands of ‘+`/`-` are whole multiplicative expressions, and so on down to single operands:

parse_additive -> parse_multiplicative -> parse_unary
  -> parse_power -> parse_operand

Instance Method Summary collapse

Constructor Details

#initialize(evaluator, tokens) ⇒ ExpressionParser

Returns a new instance of ExpressionParser.



15
16
17
18
19
# File 'lib/plurimath/math/evaluation/expression_parser.rb', line 15

def initialize(evaluator, tokens)
  @evaluator = evaluator
  @tokens = tokens
  @index = 0
end

Instance Method Details

#parseObject



21
22
23
24
25
26
# File 'lib/plurimath/math/evaluation/expression_parser.rb', line 21

def parse
  result = parse_additive
  evaluator.unsupported(current) unless eof?

  result
end