• Keine Ergebnisse gefunden

Logical Blanks

Im Dokument PASCAL-a6 USER'S GUIDE (Seite 43-47)

RECORD REPEAT

3.2 Logical Blanks

Declarations, statements, and other constructs in Pascal are in free format; in other words, they are separated from one another by appropriate punctuation or blanks rather than by their positions in the input line. Thus you may extend a declaration or statement over several input lines and indent it for maximum readability and under-standability by inserting carriage returns and blanks. Continuation line markers (such as those used in FORTRAN programs) are not needed in Pascal.

Logical blanks are blank characters or blank substitutes that may separate symbols in a Pascal-86 program. The entities that can substitute for a blank are the carriage return character (CR), the line feed character (LF), and the comment. The following rules govern the use of I

1. Wherever a logical blank is permissible, a sequence of logical blanks is permissible.

2. If a symbol ends in a letter or digit, and the symbol immediately following it begins with a letter or digit, at least one logical blank is required to separate them.

3. Embedded logical blanks are not permitted within a keyword, punctuation symbol, identifier, integer, or real number. If such embedded logical blanks do appear, the separated parts become two distinct symbols.

4. One or more logical blanks are permitted, but not required, between any pair of symbols not fitting the cases covered in rules 2 and 3.

3.2.

1 Comments

A comment in Pascal is a sequence of characters enclosed between a left and a right comment bracketing symbol (and including those symbols). The compiler ignores comments in translating your source program into object code (except that it treats them as logical blanks), but it copies all comments verbatim into the print file along with the rest of your source program. Thus they provide a means for you to insert explanations into your program.

The left comment bracketing symbols are { and (*. The right comment bracketing symbols are } and *). Either right bracketing symbol may match either left brack-eting symbol.

3-3

Language Elements Pascal-86 User's Guide

Because the carriage return and line feed are part of the ASCII character set, comments are not limited to a single line. The following are all legal Pascal-86 comments:

{this is a comment}

<* this is also a comment

*>

<*this is a comment,

too }

3.3 Tokens

From section 3.2, it follows that a Pascal-86 source program compilation consists of a sequence of symbols called tokens, or entities indivisible by logical blanks, which may be separated from each other by logical blanks. A token in Pascal is a keyword or punctuation symbol as defined in 3.1, an identifier, an integer, a real number, or a string.

3.3.

1 Identifiers

Identifiers in a Pascal program are names used to denote modules, procedures, functions, constants, types, variables, parameters, and field designators. An identifier is a sequence of letters and/or digits, of which the first must be a letter.

An identifier may be up to 255 characters long. All characters are significant in distinguishing between identifiers.

For example, the following are all legal identifiers:

DirectorySearch

COLOR

P i

CARS4

You define identifiers in module and program headings, procedure and function declarations, constant definitions, type definitions, and variable declarations. In addition, certain predefined identifiers are part of the Pascal-86 language. These stand for predefined procedures and functions, predefined constants, and predefined types that you may use without defining them explicitly. Examples of predefined identifiers are INTEGER, REAL, MAXINT, ABS, READLN, and TEXT. Appendix F gives a complete list.

The association of an identifier with the object it represents must be unique within the scope of the definition or declaration. (Section 4.1.2 discusses scope.) For instance, if you define the identifier INCREMENT as the constant 1.0 in the outer level of a given procedure, you cannot later declare INCREMENT a REAL variable in the outer level of the same procedure.

The Pascal-86 keywords listed in section 3.1 are reserved words, i.e., you may not use them as identifiers. However, the directive FORWARD and the predefined identi-fiers are not reserved words, so you may use these names. If you use a predefined identifier in a declaration or definition, the effect is to redefine that identifier for the scope of your declaration or definition; thus the predefined meaning is not available within that scope. However, you can declare or define FOR WARD as an identifier and also use it in its Pascal-defined meaning as a directive as described in 6.5-the context determines which meaning is intended. The scope of a predefined identifier is the entire compilation less any block where it is redefined.

Pascal-86 User's Guide Language Elements

3.3.2

Integers

integer is the textual representation of a decimal, integer. It is therefore a sequence of decimal digi

A signed integer denotes a value of an integer type as defined in 5.3.1, preceded by an optional plus or minus sign. The integer part cannot contain embedded logical blanks, but logical blanks are permitted between the sign and the integer part. An unsigned integer denotes an integer value that is not preceded by a plus or minus sign.

The following examples are all legal signed integers. Note that the four signed integers in the top row all represent the same value.

1 0

3.3.3

Real Numbers

A literal real number is the textual representation of a decimal number that includes a fractional part-that is, one or more digits to the right of the decimal point-or a decimal scale factor, or both. A signed real number is a real number preceded by an optional plus or a minus sign. Thus a real number has one of these two forms:

[ sign] digits. digits[ E [sign] digits]

[ sign] digits E [ sign] digits where

sign digits

is a plus or a minus sign.

is a sequence of one or more decimal digits.

As the syntax shows, if a real number contains a decimal point, it must have at least one digit on each side of the decimal point; for example, - 1. and .5 are not legal real numbers.

A real number denotes a constant value of a real type as defined in 5.3.1. It is inter-preted as a floating-point number in scientific notation, where the E mbol means

"times 10 to the power. "

The following are all legal signed real numbers:

o . 1 5 E - 3 - 1 . 0

87.35E+

1E4932

0.456E+308 +9.231E-1023

3-5

Language Elements Pascal-86 User's Guide

3.3.4 Labels

A label is a sequence of decimal digits that marks a statement so that a GOTO statement may refer to it. It looks the same as a decimal integer, and is distinguished from other labels by its integral value. (For instance, the labels 5 and 005 are the same label and cannot be used in the same block. In standard label values must lie in the 0 to 9999, inclusive;

A label is distinguished from an integer constant by its context. If a sequence of digits appears in a label declaration, in a GOTO statement, or in the label position at the beginning of a statement, it is interpreted as a label; otherwise, it is considered an integer constant.

3.3.5 Character Strings

A literal string is a sequence of one or more characters enclosed by apostrophes.

Strings consisting of a single enclosed character denote constants of the predefined type CHAR (5.2.1). Strings consisting of n enclosed characters n> 1 denote constants of the PACKED ARRAY [l..n] OF CHAR (5.2.2).

Strings may contain any of the printable characters in the ASCII character set;

however, an apostrophe within a string must appear twice. The printable characters are all the characters with code values from 20H to 7FH inclusive, as defined in Appendix G.

The following are all legal strings. The first three are of type CHAR; the last two are of type PACKED ARRAY [1..16] OF CHAR.

1. 'A' 2. ' : ' 3. " "

4. '0 V E R FLO W ERR 0 R 5' 5. ' T his i s '

, a string'

CHAPTER 4

Im Dokument PASCAL-a6 USER'S GUIDE (Seite 43-47)