About the parser
Many applications require the parsing of mathematical expressions.
The main objective of this library is to provide a fast and easy 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.
The library was designed with portability in mind and should compile on every
standard compliant C++ compiler. Wrapper for C and C#
exist. The parser archive contains ready to use project and makefiles files for a variety of
platforms. The code runs on both 32 bit and
64 bit architechtures and has been tested using MS VC++ V8.0
and GCC V4.4.1. Code samples are provided in order to help you understand its
usage. The library is open source and distributed under
the MIT license.
Before I go on, I'd like to thank SourceForge for hosting this project. This
pages would not exist without the webspace provided by them and of course I'd like
to thank CodeProject for hosting the original
math parser
article.
Support this project
muParser is free software and anyone can use it free of charge for commercial and noncommercial purposes. If you wish you can support this project by making a small donation:
A project like muParser requires permanent maintanence in order to adopt to new platforms, new compiler version and for fixing bugs. So if you are using the library and find it useful i would like to encourage you to make a donation in order to help keeping the project up to date. I can officially guarantee that you make my day by donating even a small amount of money. In a way this is a "Wow the people actually really appreciate what i'm doing" kind of thing and that's whats driving me and ultimately this is what is keeping this project alive.
Release Notes
Rev 2.0.0: Official release planned for mid 2011
The next version will be V2.0.0. There have been lots of internal changes so this
will be a major release. Originally this was intended to be V1.36 but starting
with the next version I will use a version scheme that is compatible with the SONAME
version numbers as used by GNU/Linux. Downstream package maintainers had to deal
with problems related to broken ABI compatibility in the past originating from incompatible
version shemes. This change will make life easier for Linux package maintainers and people
using the library. Version 2.0.0 will introduce if-then-else conditionals with lazy evaluation.
Expressions can now have multiple comma separated subexpressions and you can retrieve all results of
these subexpressions. It will add a bulk mode for evaluating large numbers of equations at once
and it will add a compiler switch to activate OpenMP support for the bulk mode.
The parsing engine was rewritten and the low level bytecode is now using unions internally to
represent the tokens in the reverse polish notation of an expression. The official release is
planned for Summer 2011 but a prerelease is already available via svn:
svn co https://muparser.svn.sourceforge.net/svnroot/muparser/trunk muparser
I encourage early adopters to report back any bugs/issues they find when working with the
prerelease version but please do not use the prerelease as the base for binary distributions.
It may still be subject to minor changes!
Rev 1.34: 04.09.2010
This is the second service release of 2010.
- Changes
- The prefix needed for parsing hex values is now "0x" and no longer "$".
- AddValIdent reintroduced into the DLL interface.
- New features
- The associativity of binary operators can now be changed. The pow operator is now right associative.
(This is what mathematica is using)
- Seperator can now be used outside of functions. This allows compund expressions like:
"a=10,b=20,c=a*b" The last "argument" will be taken as the return value
- Bugfixes
- The copy constructor did not copy binary operator definitions. Those were lost in the copied parser
instance.
- Mixing special characters and alphabetic characters in binary operator names led to inconsistent parsing
behaviour when parsing expressions like "a ++ b" and "a++b" when "++" is defined as a binary operator.
Binary operators must now consist entirely of special characters or of alphabetic ones.
( original bug report)
- User defined operators were not exactly handled like built in operators. This led to inconsistencies
in expression evaluation when using them. The results differed due to slightly different precedence
rules.
- Using empty string arguments ("") would cause a crash of muParser
Rev 1.32: 30.01.2010
This is a service release to fix problems with modern compilers.
- Changes
- Added a function for retrieving the Version number of muparser.
- example3 renamed to example2
- Project files for bcb and msvc6 removed (include the source directly into your projects)
- Project files for msvc2003, msvc2005 and msvc2008 added
- Bugfixes
- Deprecated feature warnings removed for gcc
- example1 changed to get rid of memory leaks. Added code for memory leak detection (VisualStudio only)
- Changes to allow compilation with msvc10 beta2
- gcc versions >4.0 were not able to run with a customized locale (resulted in std::bad_cast exception)
Rev 1.30: 09.06.2008
This is a service release with minor extensions and bugfixes.
- Changes
- Epsilon of the numerical differentiation algorithm changed to allow greater accuracy.
- New features
- Setting thousands separator and decimal separator is now possible
- Bugfixes
- The dll interface did not provide a callback for functions without any arguments.
Rev 1.28: 02.07.2007
- Library changes
- Interface for the dynamic library changed and extended to create an interface using pure C functions only.
- mupInit() removed
- New features
- Functions without parameters added
- Build system
- MSVC7 Project files removed in favor of MSVC8.
- Bugfixes
- The dynamic library did not build on other systems than linux due to a misplaced
preprocessor definition. This is fixed now.
Rev 1.2: 14.04.2005
First of all the interface has changed so this version is not backwards compatible.
After receiving a couple of questions about it, this version features support for user defined binary operators. Consequently the built in operators can now be turned off, thus you can deactivate them and write complete customized parser subclasses that only contain the functionality you want. Other new feature is the introduction of callback functions taking string arguments, implicit generation of
variables and the Assignement operator.
- Functionality
- Interface changes
- New member function:
DefineOprt
For
adding user defined binary operators.
- New member function:
EnableBuiltInOprt(bool)
Enables/Disables
built in binary operators.
- New member function:
AddValIdent(...)
to add callbacks for custom value recognition functions.
- Removed:
SetVar()
, SetConst()
.
- Renamed: Most interface functions have been renamed
- Changed: The type for multiargument callbacks
multfun_type
has changed.
It no longer takes a std::vector as input.
- Internal changes
- new class muParserTokenReader.h encapsulates the token identification and token assignement.
- Internal handling of function callbacks unified as a result the performance of the bytecode evaluation
increased.