aspose file tools*
The moose likes Beginning Java and the fly likes Evaluating boolean string expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Evaluating boolean string expression" Watch "Evaluating boolean string expression" New topic
Author

Evaluating boolean string expression

David Irwin
Ranch Hand

Joined: Mar 25, 2004
Posts: 82
All,

Suppose I have the following saved in a string variable:



and I want to evaluate this expression. Is there a simple way for Java to input this string, parse it, and evaluate the expression? Or will I have to build a custom parser to evaluate this?

Thanks,
Dave
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

You will have to do it yourself -- or use an existing library that does it. There are a number of Java scripting libraries available. One is called "BeanShell", but there are others. Also check out "Groovy".


[Jess in Action][AskingGoodQuestions]
David Irwin
Ranch Hand

Joined: Mar 25, 2004
Posts: 82
Thanks...after looking at BeanShell it may do exactly what I need by calling BeanShell from within my application.
David Irwin
Ranch Hand

Joined: Mar 25, 2004
Posts: 82
I used BeanShell's "Interpreter" class to do exactly what I needed. Thanks for the reference.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

You're welcome!
alexandre brillant
Greenhorn

Joined: Jun 03, 2004
Posts: 5
There's also JFormula which is more compact and faster, you can plug any functions or symbols easily :

http://www.japisoft.com/formula/index.html

You can write (true&&true)||false but also ( true and true ) or false

Best regards
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Evaluating boolean string expression
 
Similar Threads
Operator precedence and postfix operators
Evaluate a boolean variable / differences
Doubts in EL
Does (a=true) from if (a=true) evaluates to true ...
Difference betwen reference variable & object