Class: Plurimath::Math::Evaluation::ExpressionParser
- Inherits:
-
Object
- Object
- Plurimath::Math::Evaluation::ExpressionParser
- 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
-
#initialize(evaluator, tokens) ⇒ ExpressionParser
constructor
A new instance of ExpressionParser.
- #parse ⇒ Object
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
#parse ⇒ Object
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 |