在Java中的布尔防爆pression评价 [英] Boolean Expression Evaluation in Java

查看:294
本文介绍了在Java中的布尔防爆pression评价的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一个相对简单的方法来评估在Java中的布尔前pressions(与编写解析器相比),我不希望使用JEP库。

I'm looking for a relatively simpler (when compared with writing a parser) way to evaluate boolean expressions in Java, and I do not want to use the JEP library.

我有一个字符串的前pression,如:(X> 4 || X - 8;放大器;&安培; P> 6)和我的目标是替换值的变量。

I have a String expression like: (x > 4 || x < 8 && p > 6) and my aim is to replace the variables with values.

有没有用,我可以评价这个前pression的方式?

Is there a way by which I can evaluate this expression?

请记住,这可能是深任何级别所以写一个解析器将是非常复杂的。

Bear in mind that this can be any level deep so writing a parser would be very complex.

推荐答案

您可以使用脚本引擎中的的Java6 和选择任何流行的脚本语言如斯卡拉红宝石,的的Python Groovy的和的的Javascript 。不是所有你必须​​做的就是确保要评估前pression是正确的语言。 Groovy是可能是最简单和将整合最好的。

You could use the scripting engine in Java6 and the choose any of the popular scripting languages like Scala, Ruby, Python, Groovy, and Javascript. Than all you have to do is make sure the expression you want to evaluate is in the right language. Groovy is probably the easiest and will integrate best.

我已成功地用于提供能力,就像在一个受欢迎的小号preadsheet应用公式/计算列的特征此方法。

I have used this method successfully for a feature offering capabilities much like a formula / calculated column in a popular spreadsheet application.

这篇关于在Java中的布尔防爆pression评价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆