From UBC Wiki

A math function evaluator (re-scoped)


Xindao Qi

What is the problem?

A math function evaluator, which parses and evaluates function expressions.

e.g. f(x) = (sin(2x+1))/(1+exp(tanh(1/log(x^2)))) and x=10

e.g. g(x) = 3+2*5+1/2

supported operators + - * / ^ ( ) sin cos tan sinh cosh tanh log exp

What is the something extra?

  • can handle expressions that cover most of operators of a typical calculator, including unary operators and operators of different precedence.

What did we learn from doing this?

  • translate a grammar to a recursive parser: it's almost line by line translation
  • evaluate tree recursively (almost implicitly)

Links to code etc