tags:

views:

33

answers:

1

I have a string (R(46 - 9900)) AND ( NOT (R(48 - 9900))) where R denotes Range . If you evaluate the expression it results in R(46-47) , considering the logical operators (AND,NOT).

I have a requirement where I need to parse such a string and evaluate it to a correct result . I have to use C++ as a programming tool to achieve this result .

Can anyone suggest a few guide lines as to how do I proceed on this ?

A: 

I'm reposting Aftershock's answer to your question the first time you posted it, since it was a good answer and it didn't deserve to be deleted:


You have to write a small interpreter. There are many ways to do it . Here is one. Here is pattern for it: http://en.wikipedia.org/wiki/Interpreter_pattern

This can help too: http://ryanfarley.com/blog/archive/2004/08/19/966.aspx That is about the intersection of data ranges but the problem is similar.

You may also use an operator precedense parser: http://en.wikipedia.org/wiki/Operator-precedence_parser


Paul R