逻辑运算符具有NAND,NOR,XNOR的优先级 [英] Logical operators priority with NAND, NOR, XNOR

查看:1133
本文介绍了逻辑运算符具有NAND,NOR,XNOR的优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在网上搜索了,但是没有找到解决该问题的方法.

I've searched the web but I've found no solution to this problem.

运算符NANDNORXNOR的逻辑优先级是什么?

What is the logical priority for operators NAND, NOR and XNOR?

我的意思是,以表达式为例

I mean, considering as example the expression

A AND B NAND C

应该首先评估哪个运算符?
显然NAND可以翻译为NOT-AND(因为NORNOT-OR并且XNORNOT-XOR),但是

which operator should be evaluated first?
Obviously NAND can be translated as NOT-AND (as NOR is NOT-OR and XNOR is NOT-XOR), but

(A AND B) NAND C != A AND (B NAND C) = A AND NOT(B AND C)

根据我的研究,此类表达式没有定义的优先级,因此我认为最简单的解决方案是根据运算符在表达式中出现的顺序来求值,但我可能是错的.

According to my researches there's no a defined priority for such an expression, so I think the simplest solution is to evaluate the operators according to the order they appear in the expression, but I may be wrong.

有什么建议吗?

推荐答案

这实际上取决于您的优先级规则.如果没有顺序(没有优先级规则或所有具有相同重要性的顺序),则应从左至右求解. 此处是C ++的示例.

This actually depends on your precedence rules. If there is no order (no precedence rules or everything of the same importance), it should be solved left to right. Here is an example with C++.

这篇关于逻辑运算符具有NAND,NOR,XNOR的优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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