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.
INT i = 13, j = -4, k = 7; CHAR s = "s", t = "T"; REAL x = -2.4, y = 2.7, z = 0.0What is the value of each of the following formulæ? Ans
(2 + 3) * (3 - 2)
j+i-k
3*ABS s
ABS"t"-ABS t
REPR(k**2)
ROUND(x**2-y/(x+1))
z**9
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. Ansprint(1%0)
. Ans[4-j]*3
(((3-j)*x+3)*x+5.6
ROUND "e"
ENTIER 4 + 3.0