AMDG Richard L. Aurbach wrote:
I am looking for some code to handle simple expression evaluation -- cases like "a | b | c", or "(a + b)/2", where 'a', 'b', and 'c' are named constants that I can evaluate by lookup. I.e., code to evaluate simple expressions to produce integer results.
I'm looking for something light-weight and easy to use -- something that justifies a decision to look elsewhere rather than writing the 10-million-and-first simple evaluator. (I know that lots of folks have written this type of code as a homework assignment in a data structures course. As it happens, I don't have an old assignment to look up and am hoping to spare the time doing it now :-) )
I didn't see anything in the boost library that didn't appear to be incredible overkill, but I'm happy to be proven wrong about that.
Anyway, I would be very interested in some suggestions (using boost or otherwise) that can help me implement run-time evaluation of simple expressions without a major investment in the size or complexity of my application.
Take a look at Spirit. This example is similar to what you are trying to achieve. http://www.boost.org/doc/libs/1_35_0/libs/spirit/example/fundamental/phoenix... You can use Spirit's symbol table class: http://www.boost.org/doc/libs/1_35_0/libs/spirit/doc/symbols.html In Christ, Steven Watanabe