Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logical operators priority with NAND, NOR, XNOR

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

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

I mean, considering as example the expression

A AND B NAND C

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.

Any suggestions?

like image 369
Manlio Avatar asked Nov 17 '11 13:11

Manlio


2 Answers

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++.

like image 55
BenC Avatar answered Oct 05 '22 14:10

BenC


operator precedence have to be defined by a language, and what you have here doesn't seem to be a formal language, in such cases it's often assumed to be evaluated as you read from left to right.

Though, you could use the same operator precedence as verilog , or look at wikipedia which has a small table precedence commonly used for logic operators

like image 20
nos Avatar answered Oct 05 '22 14:10

nos