Relational ExpressionsExpressionsLogical Expressions

Logical Expressions

< expression > -> < logical term >
| < expression > || < logical term >
< logical term > -> < logical factor >
| < logical term > && < logical factor >
< logical factor > -> < relational expression >
| ! <relational expression>

Co provides the logical `and' ( && ), `or' ( || ) and `not' ( ! ) operators. In Co, these operators are actually applied to integers. They interpret their operands using the usual scheme: 0 represents `false' and any non-zero value represents `true'. The logical and relational operators of Co all produce the value 1 when the result of an operation is `true'.

The ! operator has the highest precedence among the logical operators followed by && and finally ||. Operators of equal precedence are grouped from left to right.

The && and || operators are evaluated lazily in Co. That is, if the first operand of an && operator is zero, a result of zero is returned without ever evaluating the second operand. Similarly, if the first operand of an || operator is non-zero, the second operand will not be evaluated.


Computer Science 434
Department of Computer Science
Williams College

Relational ExpressionsExpressionsLogical Expressions