逻辑运算符具有NAND,NOR,XNOR的优先级 [英] Logical operators priority with NAND, NOR, XNOR
问题描述
我已经在网上搜索了,但是没有找到解决该问题的方法.
I've searched the web but I've found no solution to this problem.
运算符NAND
,NOR
和XNOR
的逻辑优先级是什么?
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
(因为NOR
是NOT-OR
并且XNOR
是NOT-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屋!