• Aucun résultat trouvé

PROGRAM MODIFICATION

DECLARE X FIXED, Y ENTRY, Z LABEL;

CHAPTER 9: PROGRAM MODIFICATION

a percent sign. (A comment or blank may appear just after the initial percent sign, but not before.) The percent sign 1S the beginning of the macro DECLARE statement.

This statement is used to declare the macro variables. All macro variables must be declared. The scope of macro variables is the entire source text. Each macro variable and macro label must have a unique naIrie.

THE MACRO DECLARE STATEMENT General format:

% DECLARE macro-declaration [, macro-declaration] ••• j

A "macro declaration" may be either of the following:

1. macro-variable-specification 2. (macro-variable-specification

[,macro-variable-specification] ••• ) attribute •••

A Hmacro variable specification" is of form:

identifier [attribute]

The "identifier" is the name of the macro variable to be declared. Attributes are associated with i t in the same way as for the execution time DECLARE statement.

In particular, the same rules apply for conflicting attributes. However, at most, one level of factoring is permitted. The following are the permissible attributes on a macro DECLARE statement:

FIXED

This specifies is an integer of precision.

that the macro variable implementation defined CHARACTER (decimal-integer-constant) This specifies that the variable is a fixed-length character string. The length is given by the decimal integer constant.

CHARACTER VARYING

No length may be given. This attribute specifies that the macro variable is a varying-length character string. The

length of the variable is defined as the

length of the last value assigned to it.

Initially the length is undefined.

(Storage is reserved for the variable as i t 1s needed.)

INITIAL

(optionally-signed-decimal-integer-constant)

This attribute may be given only to macro variables with the FIXED attribute.

The specified constant is a~signed to the macro variable(s) to which the attribute applies. The assignment is performed at the start of compile-time activity.

INITIAL (character-string-constant) This attribute may be given only to macro variables of character data type.

The specified constant is assigned to the macro variable(s) to which the attribute applies. The assignment is performed at the start of compile-time activity.

The first three attributes in the above list are data attributes. One and only one of these must apply to each macro variable.

MACRO EXPRESSIONS

Macro expressions may take one of the following forms:

1. [ + I - ] operand ({ + I - I / I

* }

operand]

2. operand II operand [ II operan~ •••

An operand appearing alone in form 1 or the operands in form 2 may be any of the permitted operands. Operands used with a sign or an arithmetic operator must be decimal integer constants or fixed macro variables. Expressions of form 2 may involve conversion from type integer to type character. The conversion is per-formed according to list-directed transmis-sion rules (see "List-Directed Specifi-cations," in Chapter 7) •

Macro expressions are subdivided into fixed and character expressions. Macro expressions involving macro variables that have not been assigned a value are in error.

Macro expressions exactly the same way expressions.

are evaluated in as execution-time

EXECUTABLE MACRO STATEMENTS

The 'executable macro statements are enu-merated below. Any executable macro state-ment may optionally be preceded by one or more labels, each consisting of an iden-tifier.

THE MACRO ASSIGNMENT STATEMENT General format:

%[ label :] ••• macro-variable macro-expression;

The statement causes the value of the macro expression to be assigned to the macro variable. If the expression is of fixed type, the variable on the left may be either of fixed or character type. If the expression is of character type, the varia-ble on the left must also be of character type unless the value of the expression is a string that contains a decimal integer constant, optionally signed, and with optional surrounding blanks. In this lat-ter case, the variable may be of fixed type.

All conversions implied in assignment are performed according to list-directed transmission rules (see "List-Directed Data Specificationsn) •

THE MACRO NULL STATEMENT General format:

% (label:] ••• ;

Macro null statements are used for plac-ing macro labels in the text.

THE MACRO GO TO STATEMENT General format:

% (label:] ••• GO TO label;

The macro label following the GO TO must appear on another macro statement in the source text. The execution of the macro GO TO statement is described below.

THE MACRO IF STATEMENT General format:

% [label:] ..•• IF macro-expression comparison-operator macro-expression THEN GO 'fa label;

The six "comparison operators" are list-ed in "Scalar Expressions,· in Chapter 3.

The relationship is evaluated to yield a true value or a false value in the same way as for the execution-time IF statement. If the relationship is true, the statement acts as a macro GO TO statement. If the relationship is false, the statement acts as a null statement.

The two macro expressions to be compared may be of differing data types. In this case, the exp:ression of character type is converted to an integer; i t must therefore represent a decimal integer, optionally signed and with optional surrounding blanks.

ACTION OF THE MACRO PROCESSOR

The way in which the macro processor creates program text from source text ~s

described below. Initially program text is nUll.

Initi.ally the macro DECLARE statement is processE!d to form a list of macro varia-bles. INITIAL values are assigned. The DECLARE statement is then deleted from the source t~ext.

After this, the source text is scanned sequentially, starting froIT: the beginning of the t~ext. The scan acts as follows:

If t:he name of a macro variable occurs in the source text delimited at each end by any of t:he special characters list'ed in Chapter 1, other than the break character, and is not within a character string, a comment., or a macro statement, then the scan behaves exactly as if the name had

been replaced by the current value of the macro variable i t represents, converted to a character string if necessary. The source text, however, remains unchanged.

The conceptually inserted value is not enclosed in quote marks. The value must not contain unmatched quotation marks or comment delimiters. If the name of a macro variable occurs within conceptually insert-ed text, then this name is, in turn, conceptually replaced by its value. (Thus the replacement of JIM by JIM+1 would cause the macro processor to go into an infinite loop.)

If the macro variable A currently con-tains the null string, i t may appear between the two characters of a composite operator, e.g., *A* or

,A=.

However, the

combinations /A* and *A/ are not allowable when A has null value.

If the scan encounters a percent sign, other than in a comment or character con-stant, a syntactically correct macro state-ment must follow. (Comments may be embed-ded in a macro statement as usual.) This macro statement is executed. If the state-ment involves a GO TO, the scan resumes at the designated statement. Otherwise, the scan resumes with the text following the statement just executed; the macro state-ment itself is replaced by a blank space.

All text passed added to program provisions:

over by the scan is text with the following 1. If a macro statement is encountered by the scan, none of the text from the opening percent sign up to, and including, the closing semicolon is added to program text.

2. The circumstances under which redUn-dant blanks or comments appear in

p~ogram text are individually defined for each implementation of PL/I.

Macro activity ends when the encounters the end of the source text.

program text then is compiled normally.

is impossible for the program text contain any macro statements.

scan The It to