PL/I preprocessor
![]() | This article includes a list of references, related reading, or external links, but its sources remain unclear because it lacks inline citations. (February 2012) |
The PL/I preprocessor is the preprocessor for the PL/I computer programming language. The preprocessor interprets a subset of the full PL/I language to perform source file inclusion, conditional compilation, and macro expansion.
The preprocessor language has a PL/I-like syntax with preprocessor statements and preprocessor procedures prefixed with a percent symbol (%). Listing-control statements, which supply formatting commands for the compiler listing, are usually considered preprocessor statements and also begin with '%'. Preprocessor statements are imbedded in and operate on input text. The input text is normally a PL/I program, but is agnostic to the grammar of PL/I, so the preprocessor can also be used independently to process other kinds of text files.
The preprocessor is not specified as part of standard PL/I, but most PL/I implementations accept the language of the IBM preprocessor.
Including files
The %INCLUDE preprocessor statement is used to include the text of another file, which may also contain preprocessor directives. The latest IBM compilers also provide an %XINCLUDE directive, which has the effect of including the specified file only if it has not already been included. %INSCAN and %XINSCAN operate similarly, except that the name of the file to be included is specified by a preprocessor expression.
Listing control
Listing control statements provide instructions for formatting both the listing generated by the preprocessor and the listing generated by the compiler.
- %PRINT; causes the printing of listings of the following text to be started or resumed.
- %NOPRINT; causes the printing of the listings of the following text to be suppressed.
- %PAGE; causes a new page to be started in the listings.
- %SKIP [(n)]; causes 'n' lines to be skipped in the listings. If 'n' is omitted the default is one line.
- %PUSH, %POP save and restore the current status of %PRINT/%NOPRINT on a pushdown stack and restore it, respectively.
Preprocessor operation
The preprocessor operates by scanning the input text and recognizing declared preprocessor names, also called preprocessor identifiers. The text is copied to the preprocessor output with the preprocessor names replaced with their current values. The name may represent a call to a preprocessor procedure (macro). Replacement text may be rescanned by the preprocessor for possible additional replacement.
Preprocessor data types
Preprocessor data may be declared to be CHARACTER, a character string with no maximum length, or FIXED an integer number of up to five decimal digits. A preprocessor builtin is a predefined procedure operating on preprocessor data. A preprocessor expression is an expression consisting only of preprocessor names, references to preprocessor procedures or builtins, and decimal or character constants.
Preprocessor statements
- %DECLARE establishes an identifier as a preprocessor variable, either CHARACTER or FIXED.
- %assignment assigns a value to a preprocessor identifier.
- %ACTIVATE makes a preprocessor identifier active, that is, eligible for replacement when encountered in the input text.
- %DEACTIVATE makes a preprocessor ineligible for replacement.
- %DO heads a preprocessor DO-group, which is used to group statements and possibly specify iteration. A preprocessor DO-group can contain any combination of preprocessor statements and input text.
- %PROCEDURE heads a preprocessor procedure, a set of preprocessor statements that functions as a macro returning a value when its name is encountered in the input text.
- %SELECT heads a preprocessor SELECT-group.
- %END terminates a preprocesor DO-group, SELECT-group, or preprocessor procedure.
- %GOTO (or %GO TO) causes the preprocessor to continue its scan at the specified preprocessor label, either a preprocessor statement or an arbitrary point in the input text.
- %IF controls the flow of the preprocessor scan according to the value of a preprocessor expression.
%IF preprocessor-expression %THEN preprocessor unit1 %ELSE preprocessor-unit2
The preprocessor-units can be any single preprocessor statement or a preprocessor DO-group.
- %ITERATE transfers control to the %END of the containing preprocessor DO-group, ending the current iteration and beginning the next if needed.
- %LEAVE terminates any remaining iterations of the containing preprocessor DO-group transfers control to the %END.
- %NOTE generates a user-specified preprocessor diagnostic message.
- %null is a preprocessor statement consisting only of an optional statement label and a ';'. It does nothing, but serves a a placeholder where a required statement is not needed.
- %REPLACE allows immediate replacement of a name by a character or fixed expression. name does not have to be a declared preprocessor identifier.
References
- IBM Corporation (October 2009). "Enterprise PL/I Language Reference (SC27-1460-09)". Retrieved Jan 19, 2012.
- Micro Focus International plc (2011). "Micro Focus Documentation: Open PL/I Macro Preprocessor". Retrieved Feb 14, 2012.
- Kednos Enterprises (2007). "Kednos PL/I for OpenVMS Systems Reference Manual". Retrieved Feb 14, 2012.