PL/I preprocessor

Last updated

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.

Contents

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.

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. There are no BIT variables, but a BIT result may be obtained by comparison. The expression in %IF evaluates to BIT. All PL/I operators are allowed except exponentiation.

Preprocessor statements

 %IF preprocessor-expression  %THEN preprocessor unit1  %ELSE preprocessor-unit2 

The preprocessor-units can be any single preprocessor statement or a preprocessor DO-group.

Preprocessor procedures

A preprocessor procedure is a subroutine executed by the preprocessor. The procedure is delimited by %PROCEDURE and %END statements and can contain only preprocessor statements, without the leading %. It is invoked as a function reference from open code, outside of any preprocessor procedure, or from another preprocessor procedure, and returns a CHARACTER or FIXED value. When the procedure is invoked from open code the arguments are passed by name, that is they are interpreted as character strings delimited by commas or a right parenthesis, all leading, trailing, or embedded blanks are significant and considered part of the argument. [1] :pp.508–509

Preprocessor built-ins

These are the built-ins for IBM's PL/I for MVS and VM compiler. [2] :pp.404–406 There can be considerable difference in the built-ins provided among preprocessors of various PL/I compilers.

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. [3] The procedure would be called by coding the statement uwrite file(filename) from(varying_string) count(byte_count);Byte_count is optional and defaults to the length of varying_string if omitted.

%uwrite:procedurekeys(File,From,Count);dcl(File,From,Count,Number,Size)char;ifparmset(File)&parmset(From)then;elsedo;note('FILE and FROM must be specified!',12);return;end;ifparmset(Count)thenSize='min(length('||From||'), '||Count||')';elseSize='length('||From||')';Number=Counter();ans('do;');ans('dcl Count'||Number||' fixed bin (15);')skip;ans('Count'||Number||' = filewrite('||File||', ptradd(addr('||From||'), 2)'||', '||Size||');')skip;ans('end;')skip;%end;%actuwrite;

The statement uwrite file(file_name) from(var_str) count(64); generates the following:

do;dclCount00001fixedbin(15);Count00001=filewrite(file_name,ptradd(addr(var_str),2),min(length(var_str),64));end;

Evolution

A 1964 report on "NPL", [4] :pp.109–114 as PL/I was called at the time, provided that macro procedures, identified by the keyword MACRO, could use the complete facilities of the language. The following compile-time statements were allowed in open 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. [5] :pp.131–133 All mention of preprocessor procedures was omitted. The following compile-time statements were specified:

This language specification was again never implemented, however a 1966 revision of this manual restored preprocessor procedures with the now-current %PROCEDURE ... %END syntax and brought the specification close to what was actually included in PL/I(F). [6] :pp.132–139 [7] :pp.154–162 Fixed-length character variables were gone. New statements added were:

A single compile-time builtin, SUBSTR, was added.

Also in 1966 Robert Rosin published a pair of articles [8] [9] discussing development of the preprocessor. This development was based in a "SHARE XXVI Memo" from earlier the same year and a paper by Mark Elson. Rosin credits MAD as the only previous example of a macro processor in a high-level language.

See also

Related Research Articles

C (programming language) General-purpose programming language

C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, with a static type system. By design, C provides constructs that map efficiently to typical machine instructions. It has found lasting use in applications previously coded in assembly language. Such applications include operating systems and various application software for computer architectures that range from supercomputers to PLCs and embedded systems.

Fortran General-purpose programming language

Fortran is a general-purpose, compiled imperative programming language that is especially suited to numeric computation and scientific computing.

Macro (computer science) In computer science, a concise representation of a pattern

A macro in computer science is a rule or pattern that specifies how a certain input should be mapped to a replacement output. Applying a macro to an input is macro expansion. The input and output may be a sequence of lexical tokens or characters, or a syntax tree. Character macros are supported in software applications to make it easy to invoke common command sequences. Token and tree macros are supported in some programming languages to enable code reuse or to extend the language, sometimes for domain-specific languages.

PL/I is a procedural, imperative computer programming language developed and published by IBM. It is designed for scientific, engineering, business and system programming. It has been used by academic, commercial and industrial organizations since it was introduced in the 1960s, and is still used.

In computer science, a preprocessor is a program that processes its input data to produce output that is used as input to another program. The output is said to be a preprocessed form of the input data, which is often used by some subsequent programs like compilers. The amount and kind of processing done depends on the nature of the preprocessor; some preprocessors are only capable of performing relatively simple textual substitutions and macro expansions, while others have the power of full-fledged programming languages.

ALGOL W is a programming language. It is based on a proposal for ALGOL X by Niklaus Wirth and Tony Hoare as a successor to ALGOL 60. ALGOL W is a relatively simple upgrade of the original ALGOL 60, adding string, bitstring, complex number and reference to record data types and call-by-result passing of parameters, introducing the while statement, replacing switch with the case statement, and generally tightening up the language.

C preprocessor Macro preprocessor used in the C, C++, and Objective-C programming languages

The C preprocessor is the macro preprocessor for the C, Objective-C and C++ computer programming languages. The preprocessor provides the ability for the inclusion of header files, macro expansions, conditional compilation, and line control.

In computing, a polyglot is a computer program or script written in a valid form of multiple programming languages, which performs the same operations or output independent of the programming language used to compile or interpret it.

Job Control Language (JCL) is a name for scripting languages used on IBM mainframe operating systems to instruct the system on how to run a batch job or start a subsystem.

In computing, a line number is a method used to specify a particular sequence of characters in a text file. The most common method of assigning numbers to lines is to assign every line a unique number, starting at 1 for the first line, and incrementing by 1 for each successive line.

In computer programming, a directive or pragma is a language construct that specifies how a compiler should process its input. Directives are not part of the grammar of a programming language, and may vary from compiler to compiler. They can be processed by a preprocessor to specify compiler behavior, or function as a form of in-band parameterization.

MBASIC is the Microsoft BASIC implementation of BASIC for the CP/M operating system. MBASIC is a descendant of the original Altair BASIC interpreters that were among Microsoft's first products. MBASIC was one of the two versions of BASIC bundled with the Osborne 1 computer. The name "MBASIC" is derived from the disk file name MBASIC.COM of the BASIC interpreter.

HP Time-Shared BASIC is a BASIC programming language interpreter for Hewlett-Packard's HP 2000 line of minicomputer-based time-sharing computer systems. TSB is historically notable as the platform that released the first public versions of the game Star Trek.

The computer programming languages C and Pascal have similar times of origin, influences, and purposes. Both were used to design their own compilers early in their lifetimes. The original Pascal definition appeared in 1969 and a first compiler in 1970. The first version of C appeared in 1972.

In computer programming, a one-pass compiler is a compiler that passes through the parts of each compilation unit only once, immediately translating each part into its final machine code. This is in contrast to a multi-pass compiler which converts the program into one or more intermediate representations in steps between source code and machine code, and which reprocesses the entire compilation unit in each sequential pass.

ML/1 is a powerful general-purpose macro processor.

S-algol is a computer programming language derivative of ALGOL 60 developed at the University of St Andrews in 1979 by Ron Morrison and Tony Davie. The language is a modification of ALGOL to contain orthogonal data types that Morrison created for his PhD thesis. Morrison would go on to become professor at the university and head of the department of computer science. The S-algol language was used for teaching at the university at an undergraduate level until 1999. It was also the language taught for several years in the 1980s at a local school in St. Andrews, Madras College. The computer science text Recursive Descent Compiling describes a recursive descent compiler for S-algol, implemented in S-algol.

CMS EXEC, or EXEC, is an interpreted, command procedure control, computer scripting language used by the CMS EXEC Processor supplied with the IBM Virtual Machine/Conversational Monitor System (VM/CMS) operating system.

In 1979, Honeywell Information Systems announced a new programming language for their time-sharing service named TEX, an acronym for the Text Executive text processing system. TEX was a first generation scripting language, developed around the time of AWK and used by Honeywell initially as an in-house system test automation tool.

Rexx Command/scripting/programming language

Rexx is a programming language that can be interpreted or compiled. It was developed at IBM by Mike Cowlishaw. It is a structured, high-level programming language designed for ease of learning and reading. Proprietary and open source Rexx interpreters exist for a wide range of computing platforms; compilers exist for IBM mainframe computers.

References

  1. IBM Corporation (2005). Enterprise PL/I for z/OS PL/I for AIX WebSphere Developer for zSeries PL/I for Windows Language Reference (PDF).
  2. IBM Corporation (1995). IBM PL/I for MVS & VM Language Reference.
  3. Sturm, Eberhard. "UIO-Makros für Builtin-Funktionen fileread und filewrite" . Retrieved January 22, 2012.
  4. IBM Corporation (1964). NPL Technical Report (PDF).
  5. IBM Corporation (1965). IBM Operating System/360 PL/I: Language Specifications (C28-6571-1) (PDF).
  6. IBM Corporation (1966). IBM Operating System/360 PL/I: Language Specifications (C28-6571-3) (PDF).
  7. IBM Corporation (1969). IBM System/360 PL/I Reference Manual (C28-8201-3) (PDF).
  8. Rosin, Robert (August 1966). "PL/I Macro Processor - Progress Report" (PDF). PL/I Bulletin (2). Retrieved January 22, 2013.
  9. Rosin, Robert (August 1966). "Macros in PL/I" (PDF). PL/I Bulletin (2). Retrieved January 22, 2013.