Cool has four binary arithmetic operations: +, -, *, /. The syntax is
expr1 <op> expr2To evaluate such an expression first expr1 is evaluated and then expr2. The result of the operation is the result of the expression.
The static types of the two sub-expressions must be Int. The static type of the entire arithmetic expression is also Int. Cool has only integer division.
Cool has three comparison operations: <, <=, =. These comparisons may be applied to subexpressions of any types, subject to the following rules:
In principle, there is nothing wrong with permitting equality tests between, for example, Bool and Int. However, such a test must always be false and almost certainly indicates some sort of programming error. The Cool type checking rules catch such errors at compile-time instead of waiting until runtime.
On non-basic objects, equality is decided via pointer equality (i.e., whether the memory addresses of the objects are the same). Equality is defined for void: two void values are equal and a void value is never equal to a non-void value. See the operational semantics rules for more informaiton.
Finally, there is one unary arithmetic and one unary logical operator.