
A math expression parser with support for strings, vectors and matrices.
Many applications require the parsing of mathematical expressions. The main objective muparser is to provide a fast, easy and secure way of doing this. muparser is an extensible high performance math expression parser library written in C++. It works by transforming a mathematical expression into bytecode and precalculating constant parts of the expression. For best performance muparser allows parallelized evaluation of expressions with OpenMP. parallelized evaluation of expressions with OpenMP.
The library was designed with portability in mind and should compile on every standard compliant C++ compiler. The build system is based on CMake. The code runs on both 32 bit and 64 bit architechtures and has been tested using Visual Studio 2019, CLANG and GCC. Code samples are provided in order to help you understand its usage. The library is open source and distributed under the BSD - Clause 2 "Simplified" Licence . The source code archive of the last stable version is available for download here:
Download Latest muparser release
The muparser library is in "production" state. Code changes are kept to a minimum with little active development. The main focus is put on bug fixing and keeping the archive compatible with the current generation of C++ compilers.
This library is open source. Over the course of time many people have contributed in one way or another to the project. The complete list of contributors can be viewed at GitHub. Special thanks to Julien Schueller and Francis Giraldeau for setting up the CMake build system as well as Travis-CI and Appveyor integration. There would not be a CMake based build system without them.
Using muparser is pretty straightforward. The following example defines a parser variable named "a" and adds a user defined functions named "MyFunc". When using the parser, make sure that you don't forget to catch possible of type Parser::exception_type.
#include <iostream>
#include "muParser.h"
double MySqr(double a_fVal) { return a_fVal*a_fVal; }
int main(int argc, char *argv[])
{
try
{
double var_a = 1;
mu::Parser p;
p.DefineVar("a", &var_a);
p.DefineFun("MySqr", MySqr);
p.SetExpr("MySqr(a)*_pi+min(10,a)");
for (std::size_t a=0; a<100; ++a)
{
var_a = a; // Change value of variable a
std::cout << p.Eval() << std::endl;
}
}
catch (mu::Parser::exception_type &e)
{
std::cout << e.GetMsg() << std::endl;
}
return 0;
}
Those releases were shortlived and replaced within days due to several issues. Version 2.3.2 is the successor to version 2.2.6.