I'm sure there must be something like this somewhere but I can't seem to find anything useful on here or Google. I had hoped Boost might have something but alas not.
What I'm after is a lightweight library that can take a string from the user, for example "y=2x+3"
and parse it returning an object or function which returns y
when given x
.
Can anybody recommend something for this? (Worst case I could write one myself but no point reinventing the wheel and all.)
Things which can be assumed if necessary;
- Preset variable names
- Number of variables fixed
MuParser is all you ever could wish for. You can even define custom operators, store and evaluate the expressions in binary form, etc... Written in C++, bindings for C and C# (and maybe even other languages).