Content deleted Content added
Peter Flass (talk | contribs) →Preprocessor statements: procedure information |
→Evolution: %THEN and %ELSE |
||
(39 intermediate revisions by 17 users not shown) | |||
Line 1:
{{
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 (computer science)|macro expansion]].
The preprocessor language has a PL/I-like syntax with preprocessor statements and preprocessor procedures prefixed with a [[percent sign|percent symbol]] (<code>%</code>). Listing-control statements, which supply formatting commands for the [[compiler]] listing, are usually considered preprocessor statements and also begin with
The preprocessor is not specified as part of standard PL/I, but most PL/I implementations accept the language of the IBM preprocessor.
Line 8:
==Including files==
The
==Listing control==
Line 15:
Listing control statements provide instructions for formatting both the listing generated by the preprocessor and the listing generated by the compiler.
*
*
*
*
*
==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'' ([[
===Preprocessor data types===
Preprocessor data may be declared to be <code>CHARACTER</code>, a character string with no maximum length, or <code>FIXED</code> an integer number of up to five decimal digits. A ''preprocessor builtin'' is a predefined procedure operating on preprocessor data.
===Preprocessor statements===
*
*%assignment assigns a value to a preprocessor identifier.
*
*
*
*
*
*
*
*
<pre>
%IF preprocessor-expression
%THEN preprocessor unit1
%ELSE preprocessor-unit2
</pre>
The preprocessor-units can be any single preprocessor statement or a preprocessor {{code|DO}}-group.
*
*
*
*{{code|%null}} is a preprocessor statement consisting only of an optional statement label and a
*
A preprocessor procedure is a [[subroutine]] executed by the preprocessor. The procedure is delimited by <code>%PROCEDURE</code> and <code>%END</code> statements and can contain only preprocessor statements, without the leading
==Preprocessor
These are the
*
*
*
*
*
*
==Example==
The following example for IBM PL/I for OS/2 illustrates the use of a preprocessor procedure to implement a C-like write statement for PL/I.<ref>{{cite web|last=Sturm|first=Eberhard|title=UIO-Makros für Builtin-Funktionen fileread und filewrite|url=
<syntaxhighlight lang="rexx" line highlight="1,25,26">
%uwrite:
procedure keys (File, From, Count);
Line 93:
|| ');') skip;
ans ('end;') skip;
%end;
%act uwrite;
</syntaxhighlight>
The statement {{code|uwrite file(file_name) from(var_str) count(64);}} generates the following:
<syntaxhighlight lang="rexx">
do;
dcl Count00001 fixed bin (15);
Count00001 = filewrite(file_name, ptradd(addr(var_str), 2), min(length(var_str), 64));
end;
</syntaxhighlight>
==Evolution==
A 1964 report on "NPL",<ref>{{cite book|last=IBM Corporation|title=NPL Technical Report|year=1964|url=http://bitsavers.informatik.uni-stuttgart.de/pdf/ibm/360/pli/320-0908_NPL_Technical_Report_Dec64.pdf}}</ref>{{rp|pp.109–114}} as PL/I was called at the time, provided that macro procedures, identified by the keyword <code>MACRO</code>, could use the complete facilities of the language. The following compile-time statements were allowed in open code:
* <code>%DECLARE</code> – both fixed-length and varying character strings were defined.
* <code>%<var>assignment</var></code>
* <code>%<var>null statement</var></code>
* <code>%IF <var>compile_time_comparison</var> THEN <var>unit</var> [ELSE <var>unit</var>]</code> – this causes one or the other <var>unit</var> to be included in the source.
* <code>%GOTO</code>
"NPL" as defined in this manual was never implemented.
In 1965 an update to IBM's ''PL/I Language specification'' defined an even less ambitious preprocessor language.<ref>{{cite book|last=IBM Corporation|title=IBM Operating System/360 PL/I: Language Specifications (C28-6571-1)|year=1965|url=http://bitsavers.informatik.uni-stuttgart.de/pdf/ibm/360/pli/C28-6571-1_PL_I_Language_Specifications_Jul65.pdf}}</ref>{{rp|pp.131–133}} All mention of preprocessor procedures was omitted. The following compile-time statements were specified:
* <code>%DECLARE</code>
* <code>%<var>assignment</var></code>
* <code>%<var>null statement</var></code>
* <code>%IF <var>compile_time_comparison</var> THEN GOTO <var>label</var></code> – No <code>ELSE</code> clause was defined.
* <code>%GOTO</code>
This language specification was again never implemented, however a 1966 revision of this manual restored preprocessor procedures with the now-current {{code|%PROCEDURE ... %END}} syntax and brought the specification close to what was actually included in PL/I(F).<ref>{{cite book|last=IBM Corporation|title=IBM Operating System/360 PL/I: Language Specifications (C28-6571-3)|year=1966|url=http://bitsavers.informatik.uni-stuttgart.de/pdf/ibm/360/pli/C28-6571-3_PL_I_Language_Specifications_Jul66.pdf}}</ref>{{rp|pp.132–139}}<ref>{{cite book|last=IBM Corporation|title=IBM System/360 PL/I Reference Manual (C28-8201-3)|year=1969|url=http://bitsavers.informatik.uni-stuttgart.de/pdf/ibm/360/pli/C28-8201-1_PLIrefMan_Jan69.pdf}}</ref>{{rp|pp.154–162}} Fixed-length character variables were gone. New statements added were:
* <code>%ACTIVATE</code>
* <code>%DEACTIVATE</code>
* <code>%DO [<var>preprocessor_variable</var> = <var>preprocessor_expression</var> TO <var>preprocessor_expression</var> [BY <var>preprocessor_expression</var>]]</code>
* <code>RETURN</code> in a compile-time procedure only.
* <code>%INCLUDE</code>
* <code>%IF</code> – the <code>%IF <var>compile_time_comparison</var> %THEN <var>unit</var> [%ELSE <var>unit</var>]</code> was restored.
A single compile-time builtin, <code>SUBSTR</code>, was added.
Also in 1966 Robert Rosin published a pair of articles<ref>{{cite journal|last=Rosin|first=Robert|title=PL/I Macro Processor - Progress Report|journal=PL/I Bulletin|date=August 1966|issue=2|url=http://www.iron-spring.com/PLI_Bulletins/PLI_Bulletin_2.pdf|access-date=January 22, 2013}}</ref><ref>{{cite journal|last=Rosin|first=Robert|title=Macros in PL/I|journal=PL/I Bulletin|date=August 1966|issue=2|url=http://www.iron-spring.com/PLI_Bulletins/PLI_Bulletin_2.pdf|access-date=January 22, 2013}}</ref> discussing development of the preprocessor. This development was based in a "[[SHARE (computing)|SHARE]] XXVI Memo" from earlier the same year and a paper by Mark Elson. Rosin credits [[MAD (programming language)|MAD]] as the only previous example of a macro processor in a high-level language.
==See also==
*
==References==
Line 103 ⟶ 143:
==External links==
*{{cite web
|url = http://publibfp.boulder.ibm.com/
|title = Enterprise PL/I Language Reference (SC27-1460-09): Chapter 21. Preprocessor Facilities
|author = IBM Corporation
|date = October 2009
|
}}
Line 114 ⟶ 154:
|title = Micro Focus Documentation: Open PL/I Macro Preprocessor
|author = Micro Focus International plc
|
|
}}
Line 122 ⟶ 162:
|title = Kednos PL/I for OpenVMS Systems Reference Manual: Chapter 10 Preprocessor
|author = Kednos Enterprises
|
|
}}
*{{cite web
|url = https://sites.google.com/site/plipreproc/
|title = PL/I Preprocessor Wiki
|author = Peter Flass
| year = 2010
|access-date = 2017-12-06
}} Comparison of preprocessor features
{{DEFAULTSORT:PL I preprocessor}}
[[Category:PL/I programming language family]]
[[Category:IBM software]]
|