0

I would like to parse a Java boolean expression like this ('Q1.A1' are just variable names):

(Q1.A1 > 3 && Q1.A2 < 5) || (Q1.A1.Q2.A3 < 5 && Q1.A2.Q5 >= 0)

This expression will be loaded from a database and then compiled and executed in my program. "Q1.A1" etc. should be references to simple object with INT property:

so that when value of that object changes the whole expression changes.

I was looking of the best way of doing this as well as finding variables in that string, cause simple Sting.contains() is not enough (Q1.A1 is a variable but also part of another variable name).

I have been looking into This problem but I don't know how to find variables in given string.

Community
  • 1
  • 1
  • for parsing you could just read next character and see, if its a special character(`<>()`...) or a number. if its a number, then check, if you already parsing a variable, if not, that should be a regular number – JohnnyAW Apr 04 '17 at 11:38
  • 1
    Possible duplicate of [Is there an eval() function in Java?](http://stackoverflow.com/questions/2605032/is-there-an-eval-function-in-java) – csirmazbendeguz Apr 04 '17 at 11:42

0 Answers0