Definition of the Interface Between the Compiler and a Preprocessor (2024)

Note: The Integrated Preprocessor is supported for native COBOL only.

Preprocessor Parameters

Three parameters are passed across the interface:

mode-flag Used to pass control information
buffer Used for text information (source lines and filenames)
response Used to indicate the type of source line in the buffer

Use the following data structure to pass these parameters:

 01 mode-flag pic 9(2) comp-x. 01 buffer pic x(n). 01 response. 03 response-status pic 9(2) comp-x. 03 response-code-1 pic 9(4) comp-x. 03 filler redefines response-code-1. 05 filler pic x. 05 resp-main pic 9(2) comp-x. 03 response-code-2 pic 9(4) comp-x. 03 filler redefines response-code-2. 05 filler pic x. 05 resp-more pic 9(2) comp-x.

The Initial Call

The initial call is made to the preprocessor at the point where the Compiler would normally open the source file. The mode-flag parameter is set to 0 and the name of the source file is placed in buffer. If the Compiler was able to locate the source file, the filename contains the full path and file extension. If it was not able to do so, the name is as specified on the command line. The preprocessor preserves the contents of the buffer in this initial call.

In addition, the initial call initiates a handshaking process so that the Compiler and preprocessor can determine their respective levels of support. This enables new functionality to be built into the preprocessor interface while at the same time ensuring that this new functionality is not made use of unless both the Compiler and preprocessor support it. The Compiler does not pass any information to the preprocessor unless it has been told that the preprocessor is able to process it; similarly the preprocessor should not make any requests of the Compiler unless it has been told that it can do so. The process has been designed so that older Compilers and preprocessors continue to work even though they do not take account of the handshaking process.

When the Compiler calls the preprocessor, response-code-2 is used to inform the preprocessor of its support level. When the preprocessor returns to the Compiler, it uses the same parameter for its support level. As features are added the support levels are incremented; each level includes the support in the levels before it. To ensure that old Compilers are supported, the value 8224 is a special case - it indicates that the parameter was not initialized and represents the "base level". Similarly, an old preprocessor that does not set a support level does not change the parameter value, so all values of 32767 or lower are treated as the "base level".

Features in the base levels are explained in the following sections. Features not in the base level are highlighted with a warning. The following is a summary:

Compiler support levels

response-code-2 Feature
8224 Base level
0 response-code-1 contains length of buffer
1 resp-main of 14 supported
2 Compiler understands preprocessor support level; and tells the preprocessor to abort
3 resp-main of 17 supported
4 resp-main of 18 supported

Preprocessor support levels

response-code-2 Feature
32767 or less Base level
32768 Compiler might tell the preprocessor to abort
32769 Support for conditional compilation.

Note: The preprocessor must accept and act on a MODE-FLAG value of 3 by returning source lines untouched and marked as original source lines. It must continue to do this while MODE-FLAG has this value.

Not base level: The Compiler puts the length of buffer in response-code-1. The preprocessor can return source lines up to this length. If response-code-2 is 8224 then the preprocessor should assume the length is 80 bytes.

The preprocessor should open the file and return zero in response-status to indicate success, or 255 to indicate a failure.

The operating system command line contains any directives to the preprocessor, terminated by spaces. These directives are specified in the Compiler command line, directives files or $SET statements and follow the PREPROCESS directive itself.

The directives are used to pass information from the command line to the integrated preprocessor and are defined by the designer of the preprocessor. The preprocessor should not expect the directives it receives to be separated by only one space character. The command line format matches that of the PREPROCESS directive and each preprocessor directive (including the first) can be preceded by one or more spaces.

Subsequent Calls

Subsequent calls request a line of source code until the preprocessor indicates that the last line has been reached.

In these calls, the Compiler sets mode-flag to 1 and response-status to 0, except as documented in the topic Handling COPY Statements. The preprocessor returns information in buffer, resp-main and resp-more as defined in the next section.

If there is an error, response-status should be set to a nonzero value (the remaining fields might be left undefined).

The first byte of response-code-1 and response-code-2 are reserved for future use and must always be set to zero on return.

The simplest way to achieve this is to set response-code-1 and response-code-2 to zero before setting resp-main and resp-more.

If you wish to modify the source code, you should note that the original source code lines should always be passed back before their replacement line(s). In addition, lines that are continued over several lines of source code must be treated as one block; it is not possible to modify part of the logical line.

Not base level: If the Compiler sets mode-flag to 2 then it is about to terminate before the preprocessor indicates that the end of the source has been reached. On this call the preprocessor should perform any clean-up operations it needs to do (such as deleting temporary work files). If the preprocessor is stacked, that is it invokes other preprocessors, it should also call the next preprocessor with the same parameter values and then CANCEL that preprocessor.
Definition of the Interface Between the Compiler and a Preprocessor (2024)

FAQs

What is the difference between the compiler and preprocessor? ›

What is the difference between Compiler and Preprocessor? The preprocessor modifies the source code for the compiler. It performs different commands. The compiler translates this preprocessed program into machine-readable code.

What is preprocessing in a compiler? ›

Preprocessing manipulates the text of a source file, usually as a first phase of translation that is initiated by a compiler invocation. Common tasks accomplished by preprocessing are macro substitution, testing for conditional compilation directives, and file inclusion.

What is a preprocessor in the compilation process? ›

We can consider a preprocessor as a compilation process, which runs when the developer runs the program. It is a pre-process of execution of a program using c/c++ language. To initialize a process of preprocessor commands, it's mandated to define with a hash symbol (#).

What is preprocessor and what are the functions of preprocessor? ›

In computer science, a preprocessor (or precompiler) is a program that processes its input data to produce output that is used as input in 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.

What is the difference between processor and preprocessor? ›

A preprocessor is functionally similar just that they check code, instruct the compiler before compilation wherease processor execute optimum code according to its instruction set.

What is the difference between a compiler and a language processor? ›

The language processor that reads the complete source program written in high-level language as a whole in one go and translates it into an equivalent program in machine language is called a Compiler. Example: C, C++, C#. In a compiler, the source code is translated to object code successfully if it is free of errors.

What is preprocessing in simple words? ›

Data preprocessing, a component of data preparation, describes any type of processing performed on raw data to prepare it for another data processing procedure. It has traditionally been an important preliminary step for the data mining process.

What are the 4 stages of compiling? ›

Knowing how compilation works can be very helpful both when writing code and when debugging. Compiling a C program is a multi-stage process. At an overview level, the process can be split into four separate stages: Preprocessing, compilation, assembly, and linking.

Why is preprocessing needed? ›

Preprocessing is essential for cleaning and organizing data, making it suitable for modeling. Common techniques like normalization and dimensionality reduction improve model performance. For tabular data, preprocessing handles missing values, outliers, and categorical variables.

What is the use of preprocessor in compiler design? ›

Pre-Processor: The pre-processor removes all the #include directives by including the files called file inclusion and all the #define directives using macro expansion. It performs file inclusion, augmentation, macro-processing, etc.

What is the primary purpose of a compiler in C programming? ›

A compiler is a software that converts the source code to the object code. In other words, we can say that it converts the high-level language to machine/binary language. Moreover, it is necessary to perform this step to make the program executable.

What are the four types of preprocessor directives? ›

There are 4 Main Types of Preprocessor Directives:
  • Macros.
  • File Inclusion.
  • Conditional Compilation.
  • Other directives.
Jan 9, 2024

What is the difference between a compiler and a preprocessor? ›

The preprocessor is a part of the compiler which performs preliminary operations (conditionally compiling code, including files etc...) to your code before the compiler sees it. These transformations are lexical, meaning that the output of the preprocessor is still text.

Why are preprocessor required? ›

Preprocessor directives, such as #define and #ifdef , are typically used to make source programs easy to change and easy to compile in different execution environments. Directives in the source file tell the preprocessor to take specific actions.

What are the advantages of preprocessor? ›

With preprocessors, you can write less code and avoid repetition by utilizing the syntax and features. Additionally, you can split your code into multiple files and reuse them with imports or extends, allowing for better organization and modularity.

What is the difference between a compiler and a CPU? ›

Compiler is a translator program that converts high-level language program into machine language. The CPU (central processing unit) can directly understand its own machine language.

What is the difference between compiler and assembler in computer? ›

The difference between compiler and assembler is that a compiler is used to convert high-level programming language code into machine language code. On the other hand, an assembler converts assembly level language code into machine language code. Both these terms are relevant in context to program execution.

What is the difference between a compiler and an interpreter? ›

Compiler: A compiler translates code from a high-level programming language into machine code before the program runs. Interpreter: An interpreter translates code written in a high-level programming language into machine code line-by-line as the code runs.

What is the difference between compiler preprocessor assembler and loader linker? ›

A compiler takes our source code and generates the corresponding assembly code. An assembler converts the assembly code to the machine code. A linker merges all the machine-code modules referenced in our code, whereas a loader moves the executable to RAM and lets it be executed by a CPU.

Top Articles
Latest Posts
Article information

Author: Rev. Porsche Oberbrunner

Last Updated:

Views: 5589

Rating: 4.2 / 5 (53 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Rev. Porsche Oberbrunner

Birthday: 1994-06-25

Address: Suite 153 582 Lubowitz Walks, Port Alfredoborough, IN 72879-2838

Phone: +128413562823324

Job: IT Strategist

Hobby: Video gaming, Basketball, Web surfing, Book restoration, Jogging, Shooting, Fishing

Introduction: My name is Rev. Porsche Oberbrunner, I am a zany, graceful, talented, witty, determined, shiny, enchanting person who loves writing and wants to share my knowledge and understanding with you.