Skip to content

Develop a parser for arbitrary expressions in the calc engine #526

@mcooley

Description

@mcooley

Problem Statement
Currently, Calculator executes all operations in immediate mode--press an operator, get a new answer. For multiple scenarios, it would be useful for the user to enter an expression like "(5 + 2) * 3" and have Calculator parse and compute the result.

Evidence or User Insights
Several proposed features could leverage this work:

Proposal
Add code and tests to the calc engine to parse mathematical expressions as strings.

Goals

  • A developer can use the CalcManager library to convert an expression into a numerical result
  • Expressions support order of operations, e.g. "(5 + 2) * 3" = 21
  • Expressions support evaluation of functions, e.g. "sqrt(4)"
    • Functions are implemented for as many existing calculator operators as possible
    • Each function has a thoughtful name informed by similar systems
  • Expressions are evaluated using the arbitrary-precision engine
  • When invalid expressions are passed to the engine, error information is returned which could be used to construct a helpful error message
  • Parsing and evaluation is deterministic, and ideally not locale-dependent
  • The parser can find expressions embedded in natural language sentences with loose syntax (e.g. "what is the square root of sin(3 - 2)" evaluates to "what is the square root of [expression tree]"), for future use in voice input scenarios

Non-Goals

  • Integrate expression parsing with the Calculator UI (tracked by other issues)
  • Natural language intent recognition, e.g. "what is the square root of 4" evaluating to "sqrt(4)"

Requested Assignment
I'm happy to help with this, but would be great for someone else to implement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions