是否有最佳方法/算法来消除 BOOL 或算术运算中不必要的额外括号
我有这个,我以编程方式构建了它:
(( cat1:bobo AND ( ( cat2:jojo ) OR ( cat2:coco ) ) ))
为了调试,我正在寻找一种好的方法,基本上可以将其减少到所需的最少括号数量:
cat1:bobo AND ( cat2:jojo OR cat2:coco )
我使用 C#,但如果你有好的技术,你就可以看到了,我会移植它。
I have this, I built it programmatically:
(( cat1:bobo AND ( ( cat2:jojo ) OR ( cat2:coco ) ) ))
For the sake of debugging, I am looking for a good method that would basically reduce it to least amount of parens needed:
cat1:bobo AND ( cat2:jojo OR cat2:coco )
I'm on C#, but if you have a good technique you've seen, I will port it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您将表达式解析为某种树结构,那么我过去采取的方法只是浏览树并删除仅作为其他节点容器的任何节点。
Assuming you're parsing the expression into some sort of tree structure, then the approach I've taken in the past is just to navigate through the tree and remove any nodes that are just a container for other nodes.
如果您以编程方式构建它,您就会拥有某种表达式树。 不是 AND- 或 OR- 节点的节点不必渲染括号
if you built it programmatically, you have an expression tree of some sort. nodes that aren't AND- or OR- nodes don't have to render parentheses