MExpr is a powerful C++ library designed to parse and evaluate human-like arithmetic expressions with advanced features.
The library understands implicit multiplication patterns, allowing expressions like 3xy^2 without explicit * operators.
MExpr builds a complete AST that can be:
For repeated evaluations, expressions can be compiled to bytecode, significantly improving performance for:
Define custom functions with full support for:
MExpr expr("-3xy^2 - 3(xy + 3)(-5x + y)");
expr.setVariable("x", 2.0);
expr.setVariable("y", 3.0);
double result = expr.evaluate();
The parser uses a recursive descent approach with operator precedence climbing for efficient parsing. The bytecode compiler generates optimized stack-based instructions for fast evaluation.
MExpr is designed for performance, with benchmarks showing: