Subsections


Summary

Operators combined with operands are called formulæ. Operators are monadic or dyadic. Monadic operators take a single operand, bind more tightly than dyadic operators and when combined are elaborated from right to left. Dyadic operators take two operands and have a priority of 1 to 9. Successive dyadic operators having the same priority are elaborated from left to right. Parentheses, or BEGIN and END, may be used to alter the order of elaboration.

A summary of all the operators described in this chapter, together with their priorities, can be found in chapter 13.

Here are some exercises which test you on what you have learned in this chapter. The exercises involving ABS and REPR will need to be written as small programs and compiled and run. In fact, it would be a good idea to write all the answers as small programs (or incorporate them all in one large program). Don't forget to use the print phrase with newline and newpage to separate your output.


Exercises

2.11
The following declarations are assumed to be in force for these exercises:
   INT i = 13, j = -4, k = 7;
   CHAR s = "s", t = "T";
   REAL x = -2.4, y = 2.7, z = 0.0
What is the value of each of the following formulæ? Ans[*]
(a)
(2 + 3) * (3 - 2)

(b)
j+i-k

(c)
3*ABS s

(d)
ABS"t"-ABS t

(e)
REPR(k**2)

(f)
ROUND(x**2-y/(x+1))

(g)
z**9

2.12
Because of the kind of arithmetic performed by the compiler, division of values of mode REAL by zero does not cause a program to fail (but see section 13.6.1). Write a program containing the phrases REAL z=0.0/0.0; and REAL iz=1/0; and see what happens. In practice, it's probably a good idea to check for division by zero. Ans[*]
2.13
Now try the phrase print(1%0). Ans[*]
2.14
What is wrong with the following formulæ? Ans[*]
(a)
[4-j]*3

(b)
(((3-j)*x+3)*x+5.6

(c)
ROUND "e"

(d)
ENTIER 4 + 3.0


Sian Mountbatten 2012-01-19