Overview - Integrated Preprocessor Interface
Language preprocessors (also known as precompilers) are used to convert non-standard COBOL, or non-COBOL code embedded in COBOL, into a form that the Compiler can process.
A non-integrated preprocessor takes as input a source file, reads and parses it, and produces a modified source file which is then passed as input to the COBOL compiler. This has the following disadvantages:
- There are two steps involved in compiling a program
- There can be no integration between the Compiler and editor; for example if an error occurs during compilation there is no possibility of the editor highlighting the original source line in error
- Listing output and debugging tools do not show the original source program
These factors can significantly lengthen the development cycle.
The Integrated Preprocessor Interface overcomes these problems by enabling the preprocessor to mark the relationship between the original source code and the modified form. Although the Compiler will actually process the modified COBOL, it will only ever show the original code.
The Integrated Preprocessor Interface enables a preprocessor to read source files and pass modified source lines to the Compiler. This makes the interface completely general purpose. The disadvantage of this approach is that the preprocessor itself has to handle COBOL constructs such as continuation, copybook expansion and the effects of REPLACE and REPLACING. Micro Focus provides the CP preprocessor, which can handle REPLACE and REPLACING, although this does require that COPY statements conform to normal COBOL syntax rules. If, by comparison, the Compiler read source files and passed single tokens to the preprocessor, restrictions such as the format of a token and the syntax of a COPY (or equivalent) statement would be imposed.
The underlying code that is actually compiled might be significantly different from the original. You might therefore notice that:
- The debugger cannot query a data item, as the data item does not exist in the underlying code.
- The debugger does not reference lines that were modified by the preprocessor, as the compiler does not process these lines and is unaware of their contents.
- An accurate cross reference listing is not produced by the XREF Compiler because information for code inserted by the preprocessor is not shown, even if the original source line referenced the same data items.
- Certain directives, most notably FLAG and language switches such as MF, cause the
Compiler to reject or flag code produced by a preprocessor, whether integrated or
not. The Integrated Preprocessor Interface eases the task of preventing such problems
by:
- Never flagging lines inserted by a preprocessor
- Enabling the preprocessor to query Compiler directive settings.
A preprocessor can generate lines containing $SET statements to switch directive settings, but this might cause problems, especially if your code uses names for data items that conflict with reserved words in the language selected by the preprocessor.
A supplied preprocessor reads and expands source files (including copybooks), and returns additional information to other preprocessors in the stack about the effect of REPLACE and REPLACING.