I have a need to evaluate user-defined logical expressions of arbitrary complexity on some PHP pages. Assuming that form fields are the primary variables, it would need to:
- substitute"varibles" for form fields values;
- handle comparison operators, minimally ==, <, <=, >= and > by symbol, name (eg eq, lt, le, ge, gt respectively);
- handle boolean operators not, and, or and possibly xor by name, symbol (eg !, &&, || and ^^ respectively);
- handle literal values for strings and numbers;
- be plaintext not XML (eg "firstname == '' or lastname == ''); and
- be reasonably performant.
Now in years gone by I've written recursive descent parsers that could build an expression tree and do this kind of thing but thats not a task I'm relishing in PHP so I'm hoping there are things out there that will at least get me some of the way there.
Suggestions?