tags:

views:

58

answers:

2

I have a string;

String allIn = "(50 > 100) AND (85< 100)";

Now I need to evaluate if the conditions inside are TRUE or FALSE, how can I do it?

In real the string will be a value from a field in my DB, where I will substitute different values and they will form a string as shown above.

+2  A: 

Take a look at the eval project

Bozho
I just glanced at it, but it looks like that only supports Java syntax, so he'd have to convert what he's using (SQL-ish?) to Java.
Jonathon
Seems what I need, will check it right now. Thank you Bozho
Adnan
+1 Best tool for this job
David Relihan
A: 

To me this looks like a "Compiler Design" question where you:

  • Parse the string into it's individual components using space, < > AND OR != as delimeters
  • Push on to the stack when you encounter a value
  • Pop from the stack when you encounter an operator and get next part of expression

But personally - I would go down the Eval route (as stated already) if at all possible - even if it means that you have to change the current syntax of the string or parse and convert the syntax:

https://eval.dev.java.net/

David Relihan