31.12.2013 Views

TOPS-20 PASCAL Language Manual - Bitsavers

TOPS-20 PASCAL Language Manual - Bitsavers

TOPS-20 PASCAL Language Manual - Bitsavers

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 />

You can use parentheses in any expression to force a particular order<br />

of evaluation, for example:<br />

Expression:<br />

Evaluates to:<br />

8 * 5 DIV 2 ... 4 16<br />

8 * 5 DIV (2 - 4) ····<strong>20</strong><br />

<strong>PASCAL</strong> evaluates the first expression according to the normal rules<br />

for precedence. First, it multiplies 8 by 5 and divides the result<br />

(40) by 2. Then, it subtracts 4 to get 16. The parentheses in the<br />

second expression, however, force <strong>PASCAL</strong> to subtract before<br />

multiplying or dividing. Hence, it subtracts 4 from 2, getting -2.<br />

Then, it divides -2 into 40, with -<strong>20</strong> as the result.<br />

Parentheses can also help to clarify an expression.<br />

could write the first example as follows:<br />

For instance, you<br />

«8 * 5) DIV 2) - 4<br />

The parentheses eliminate any confusion about how the expression is to<br />

be evaluated.<br />

3.2 SCOPE OF IDENTIFIERS<br />

The scope of an identifier is the part of the program in which you<br />

have access to the identifier. In a <strong>PASCAL</strong> program, the scope of a<br />

constant, type, variable, or subprogram identifier is the block in<br />

which the identifier is declared. Figure 3-1 illustrates the scope of<br />

identifiers declared at various levels.<br />

Declarations in the main program block specify global identifiers,<br />

which can be accessed in the main program and in all nested<br />

subprograms. For example, A and B in Figure 3-1 are global<br />

identifiers. They can be accessed from any level in the program.<br />

Declarations in subprogram blocks specify local identifiers. You can<br />

use a local identifier in the subprogram that contains its declaration<br />

and in all its nested subprograms. For example, the identifiers C and<br />

D are local to procedure Le~el lA and its nested subprograms Level 2A<br />

and Level 3A. You can USE~ C and D i 11 any 0 f these subprog rams, but<br />

not in the main program or in the subprograms Level_lB, Level_2B, and<br />

Level 2C.<br />

3-7

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

Saved successfully!

Ooh no, something went wrong!