I'm looking for suggestions of portable lightweight libraries written in C++
, that support mathematical and business rule expression and evaluation. I understand C++
doesn't provide such functionality in the STL
.
The basic requirement is as follows:
The expressions to be evaluated will be comprised of numbers and strings and variables either representing numbers or strings.
Some of the expressions are expected to be evaluated many times per second (1000-2000 times), hence there is a requirement for high performance evaluations of the expressions.
Originally the project at my company, we encode all the business rules as classes that derived from a base expression class. The problem is that this approach does not scale well as the number of expressions increases.
I've googled around, but most "libraries" I could find are pretty much simple examples of the shunting yard algorithm, most of the expression parsers, perform parsing and evaluation in the same step making them unsuitable for continuous reevaluations, and most only support numbers.
What I'm looking for:
- Library written in C++ (C++03 or C++11)
- Stable/production worthy
- Fast evaluations
- Portable (win32/linux)
- Any suggestions for building high performance business rules engine.
Example business rule:
'rule_result = (remaining_items < min_items) and (item == "beach ball")'
See the C++ Mathematical Expression Library outlined in this answer.
But, if you really want speed, consider compiling the expressions as C/C++ directly, then load them dynamically (shared objects/DLLs).
Have you considered generating your own parser with Bison + Flex? It uses a FSM-based LALR parser implementation that is fast and is easy to write, and supports evaluation of expressions while you're parsing them, as well as AST generation for repeated evaluation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With