A real value v is represented in a binary floating-point format consisting of a sign bit s, a biased exponent e, and a significand S such that v=( - 1 )s·S·2e (see figure 7- 1).
The significand is always a non-negative value less than two. In Pascal-86, three
SIGN
BIT EXPONENT
TYPE TEMPREAL
SIGNIFICAND
1·1",,··· .", I,,··· ... ·'~I
--
BIT 1SIGN BIT
15 BITS
EXPON~NT
64 BITS
TYPE LDNGREAL
SIGNIFICAND
1·1",,··· ."' I,,··· ·~'I
--
BIT 1 SIGN11 BITS
BIT EXPONENT
52 BITS·
TYPE REAL
SIGNIFICAND
1·1 ~ ... "' I,,··· .'" I
1 8 BITS 23 BITS·
BIT
·So, the leading significand bit, is implicit for type REAL. Its value is always 1 unless the exponent is all zeros, in which case So is also o.
Figure 7-1. Pascal-86 Real Data Types 121539-34
Pascal-86 User's Guide Expressions and Statements
7-11
Expressions and Statements Pascal-86 User's Guide
7.2 Statements
Statements denote algorithmic actions, and are said to be executable. A statement may be prefixed by a label (followed by a colon), which can be referenced by GOTO statements (7.2.10). The following is an example of a labeled statement:
100: C := SGRT(SGR(A)+SGR(B»
Statements in Pascal can be classified as simple statements and structured state-ments. A simple statement contains no other statements; a structured statement contains embedded statements. Simple statements may be assignment statements, procedure statements, GO TO statements, or empty statements. Structured state-ments may be compound statestate-ments, IF statestate-ments, CASE statestate-ments, WHILE statements, REPEAT statements, FOR statements, or WITH statements.
An empty statement consists of no symbols and performs no action; unless it is labeled, it does not result in any compiled code. Empty statements may be useful as place-holders during top-down development and debugging.
Also, the existence of the empty statement means that if you inadvertently insert a semicolon between two statements where one is not needed (i.e., after the last state-ment in a sequence of statestate-ments), your program will still compile and run correctly.
Statements may also be classified according to function, as listed below:
Computing new values: assignment statement Procedure invocation: procedure statement Statement grouping: compound statement Conditional execution: IF and CASE statements
Repetitive execution (looping): WHILE, REPEAT, and FOR statements Identification of record names in references to record types: WITH statement Unconditional branching: GOTO statement
Pascal-86 User's Guide Expressions and Statements
The following sections describe the various Pascal statements in the order just given.
7.2.
1 Assignment StatementsThe assignment statement replaces the current value of a variable by a new value specified as an expression. Its syntax is:
variable . = expression where
variable expression
is an entire variable, a component of a structured variable, or a referenced variable.
must be assignment-compatible (5.3.4) with the type of the variable.
Note that variable may be of any type, including an array or record. Thus you may use a single assignment statement to transfer all the values of an array or record variable to another array or record variable, provided the types of the two variables are assignment-compatible.
If the selection of the variable involves the indexing of an array or the dereferencing of a pointer, then whether these actions precede or follow the evaluation of the expression is undefined.
Examples:
x • = y + z
p · = C1<=i) AND (i<100)
• = SQRCk) C i It j ) blue , 5UCC(c)]
7.2.2
Procedure StatementsA procedure statement specifies execution of the procedure denoted by the procedure identifier. The procedure statement may contain a list of arguments to be substituted in place of the corresponding parameters in the procedure declaration. The corre-spondence is established by the order of the items in the lists of arguments and parameters, respectively; the first argument matches the first parameter, and so on. The number of arguments must equal the number of parameters.
The order in which the arguments are evaluated and associated with their parameters is undefined, so you should make no assumptions about this order.
The syntax of a procedure statement is:
identifier [C argument [, argument]... )]
where identifier is a procedure identifier, and each argument is either an expression or a procedure or function identifier.
7-13
Expressions and Statements Pascal-86 User's Guide
Examples:
B u i 1 d T r e e
ProductCa)n)m)
BisectCfct)-1.0)+1.0)x)
7.2.3
Compound StatementsA compound statement specifies that its component statements are to be executed in the -sequence in which they appear. Thus a compound statement groups several state-ments into a single statement. The keywords BEGIN and END act as statement brackets.
The syntax of a compound statement is:
BEG I N statement [i statement]... END where
each statement is any statement described in this chapter.
You must always use a compound statement as the statement part of every block in your program. In other words, you must group the statements in each block into a single compound statement enclosed within BEGIN and END brackets.
Examples:
BEGIN Z:=Xi x:=Yi y:=z END BEG IN
EHD
RESETCf)i REWRITECg)i
WHILE MOT EOF(f) DO BEG IN
9 :=fti PUTCg)i GETCf) END
7 _2.4 IF Statements
A conditional statement (IF or CASE statement) selects for execution one of its component statements. The IF statement includes a Boolean expression, which it evaluates to determine whether to execute the first, or the optional second, compo-nent statement.
The syntax of the IF statement is:
I F expression THE N statement [E L 5 E statement]
The expression following the IF must be of type BOOLEAN; each statement may be any statement.
Pascal-86 User's Guide Expressions and Statements
NOTE
No semicolon is permitted between the first statement and the keyword ELSE.
If the Boolean expression has the value TRUE, the statement following the keyword THEN is executed. If the Boolean expression is FALSE, the action depends on the existence of the ELSE clause. If the ELSE clause is present, the statement following the keyword ELSE is executed; otherwise, an empty statement is executed (no action is performed).
The construct:
I F e 1 THE H I F e2 THE H s 1 E L S E s2
is equivalent to:
I F e1 THE H BEGIH
I F e2 THE H s 1 E L S E s2 EHD
In other words, the ELSE belongs to the most recent IF. To associate an ELSE with the first IF, you can enclose the second IF in a compound statement:
I F e1 THE H BEG I H
I F e2 THE H s1 EHD
E L S E s2
Examples:
IF x(1.5 THEN z:-x+y ELSE z:=1.5 IF p1()HIL THEH p1:=p1t.father
7.2.5
CASE StatementsThe CASE statement specifies the execution of one of a list of component statements, based on the value of an expression that serves as a selector. Each statement is prefixed by one or more constants, called case constants; the statement executed is the one whose case constant is equal to the current value of the selector.
If none of the case constants is equal to the value of the selector,
The syntax of the CASE statement is:
CAS E expression 0 F
[case-const [J case-const] .. . case-const [J case-const] .. . EIiD
statement i ] ...
statement [;]
7-15
Expressions and Statements Pascal-86 User's Guide
where expression must be of an ordinal type, each case-const must be distinct and of an ordinal type compatible with the expression, and each statement may be any Pascal statement. Restrictions on case constants in Pascal-86 are given in Appendix
c.
In the following examples, i is a variable of an integer type, x is a REAL variable, and operator is a variable of an enumerated type that may have the value plus, minus, or times:
CASE operator OF OF
P 1 us: x • = x + Y i x minus : x • = x -Y i
times: x • = X*Yi
EtiD EtiD
7 .2.6
WHILE StatementsThe repetitive statements (WHILE, REPEAT, and FOR) execute their component statements repeatedly. The WHILE statement executes its component statement repeatedly as long as a given condition remains satisfied. Each time through the loop, the condition is tested before the statement is executed. Thus the WHILE statement is most useful when the loop is not performed at all in some circumstances.
The syntax of the WHILE statement is:
W H I L E expression D 0 statement where
expression statement
must be a BOOLEAN expression.
may be any statement. Since only a single statement is allowed, you may wish to use a compound statement here.
The statement is repeatedly executed while, prior to each execution, the value of the BOOLEAN expression is TRUE. If its value is FALSE at the beginning, the state-ment is never executed at all.
The statement:
WHILE b DO s is equivalent to:
IF b THEti BEGlti Si
WHILE b DO s EtiD
Pascal-86 User's Guide Expressions and Statements
Examples: