简体   繁体   English

用于解析逻辑表达式的Java库

[英]Java Library for Parsing Logical Expression

I am having a String like "A AND B OR C AND ( D OR E)". 我有一个类似“ A AND B OR C AND(D OR E)”的字符串。 I just want to parse the logical expression here, is there any Java Api for the same. 我只想在这里解析逻辑表达式,是否有相同的Java Api。

Here A,B,C... are in the form of string,string,string (ie key,value,operator) 这里的A,B,C ...是string,string,string(即键,值,运算符)的形式

First you will need to fix the grammar of the expression that you are going to accept. 首先,您需要修复将要接受的表达式的语法。 What you have written: 您写的是:

"A AND B OR C AND ( D OR E)" “ A AND B或C AND(D或E)”

is an example string of your language. 是您的语言的示例字符串。 So first you will need to define your language which can be defined using BNF . 因此,首先您需要定义可以使用BNF定义的语言。 This would give you complete understanding of the your own language. 这将使您完全了解自己的语言。

And then any aribitrary expression that you input need to be parsed. 然后,需要解析您输入的任何任意表达式。 You can create an expression tree 您可以创建一个表达式树

And finally you will need to evaluate the expression tree. 最后,您将需要评估表达式树。

A reasonable example of how it can be done is given in this article 本文给出了一个合理的示例

使用Spring Expression-支持AND OR NOT

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM