1

I want to develop a class/method that takes as input a string of this format: "((true | false) & (!false & false))", and returns true or false, accordingly (in this case false).

How should I proceed?

4
  • So you want to take a boolean expression in the form of a string and parse it? Commented Nov 2, 2015 at 13:53
  • Yepp, basically that. Commented Nov 2, 2015 at 13:57
  • Note that this is bitwise boolean evaluation. Boolean AND and OR are represented by && and || respectively. Commented Nov 2, 2015 at 13:57
  • You're totally right, but in this case, I am interested in a regular AND/OR evaluation. But, yes to be correct I have to change the symbols. Commented Nov 2, 2015 at 14:19

1 Answer 1

3

if performance is not the issue AND you're really sure that the boolean expression is safe (security reasons), you can launch a full-blown JavaScript engine and evaluate the expression

like described in the following question.

Sign up to request clarification or add additional context in comments.

2 Comments

And Here another good example
Thank you Funtik! Actually I guess the performance will be an issue, for me. Adding just a small note, that might complicate a bit the problem, is that I am going to implement this in Salesforce(I don't know if you're familiar with), that uses Apex as the propietary language. Apex, is a Java-like language, and I thought that I could get a solution adaptable to Apex, but I appreciate your answer, so thank you. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.