24.11.2014 Views

Open Watcom FORTRAN 77 Language Reference

Open Watcom FORTRAN 77 Language Reference

Open Watcom FORTRAN 77 Language Reference

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Expressions<br />

As is the case with arithmetic operators, we must define rules in order to evaluate logical expressions.<br />

Again we define rules of precedence for logical operators which dictate the evaluation sequence of logical<br />

expressions. The following lists the logical operators in order of precedence.<br />

1. .NOT. (highest precedence)<br />

2. .AND.<br />

3. .OR.<br />

4. .EQV., .NEQV. and .XOR. (lowest precedence)<br />

For example, in the expression<br />

A .OR. B .AND. C<br />

the .AND. operator has higher precedence than the .OR. operator so B and C are combined first using the<br />

.AND. operator. The result is then combined with A using the .OR. operator.<br />

Parentheses can be used to alter the sequence of evaluation of logical expressions. If in the previous<br />

example we had written<br />

(A .OR. B) .AND. C<br />

then A and B would have been combined first.<br />

7.4.2 Rules for Forming Logical Expressions<br />

Logical primaries are the building blocks for logical expressions. They are one of the following.<br />

1. logical or integer constant<br />

2. symbolic logical or integer constant<br />

3. logical or integer variable reference<br />

4. logical or integer array element reference<br />

5. logical or integer function reference<br />

6. relational expression<br />

7. ( logical or integer expression )<br />

As was done with arithmetic expressions, a grammar can be defined which dictates the precedence relation<br />

among logical operators.<br />

The .NOT. logical operator has highest precedence. We define a logical factor as:<br />

1. logical primary<br />

2. .NOT. logical primary<br />

Next in the precedence hierarchy is the .AND. operator. We define a logical term as:<br />

1. logical factor<br />

2. logical term .AND. logical factor<br />

A logical term is simply a sequence of logical factors, each separated by the .AND. operator. Rule (2)<br />

specifies that the logical factors are combined from left to right.<br />

Next is the .OR. operator. We define a logical disjunct as:<br />

Logical Expressions 183

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!