简体   繁体   中英

Java Library for Parsing Logical Expression

I am having a String like "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.

Here A,B,C... are in the form of string,string,string (ie key,value,operator)

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)"

is an example string of your language. So first you will need to define your language which can be defined using 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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