next up previous contents
Next: Cost of Arithmetic Operators Up: Simple Input / Output Previous: Operator Precedence

 

Precedence Example

The precedence is worked out as follows

  1. in an expression find the operator(s) with the tightest binding.
  2. if there are more than one occurrence of this operator then the separate instances are evaluated left to right.
  3. place the first executed subexpression in brackets to signify this.
  4. continue with the second and subsequent subexpressions.
  5. move to next most tightest binding operator and follow the same procedure.

It is easy to make mistakes by forgetting the implications of precedence. The following expression,

    x = a+b/5.0-c**d+1*e

is equivalent to

    x = ((a+(b/5.0))-(c**d))+1*e

The following procedure has been followed to parenthesise the expression,

Likewise, the following expression,

    .NOT.A.OR.B.EQV.C.AND.D.OR..NOT.E

is equivalent to

    ((.NOT.A).OR.B).EQV.((C.AND.D).OR.(.NOT.E))

here,

Parentheses can be added to any expression to modify the order of evaluation.

Now try this question gif

Return to corresponding overview page gif


next up previous contents
Next: Cost of Arithmetic Operators Up: Simple Input / Output Previous: Operator Precedence

©University of Liverpool, 1997
Wed May 28 20:20:27 BST 1997
Not for commercial use.