compute function

Result compute(
  1. String input, {
  2. ComputeContext context = const DefaultComputeContext(),
})

Takes an input expression and returns its result.

It does the following:

  • Does a lexical analysis by splitting the expression in tokens (lexing)
  • Sorts the tokens and removes parenthesis to turn the expression in Reverse Polish Notation
  • Creates a tree from this RPN
  • Computes the tree

We give the context throughout all of the process, we take all relevant data like constants from it and can change the output.

Implementation

Result compute(String input,
    {ComputeContext context = const DefaultComputeContext()}) {
  return rpnToComputable(
          toRPN(separateTokens(input, context: context), context: context),
          context: context)
      .compute(context);
}