MExpr is a powerful C++ library designed to parse and evaluate human-like arithmetic expressions with advanced features.

Features

Implicit Multiplications

The library understands implicit multiplication patterns, allowing expressions like 3xy^2 without explicit * operators.

Abstract Syntax Tree (AST) Manipulation

MExpr builds a complete AST that can be:

Bytecode Compilation

For repeated evaluations, expressions can be compiled to bytecode, significantly improving performance for:

Custom Functions

Define custom functions with full support for:

Example Usage

MExpr expr("-3xy^2 - 3(xy + 3)(-5x + y)");
expr.setVariable("x", 2.0);
expr.setVariable("y", 3.0);
double result = expr.evaluate();

Technical Implementation

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.

Use Cases

Performance

MExpr is designed for performance, with benchmarks showing: