A preprocessor is a program that takes text and performs lexical conversions on it. The conversions may include macro substitution, conditional inclusion, and inclusion of other files.
The C programming language has a preprocessor that performs the following transformations:
- Replaces trigraphss with equivalents.
- Concatenates source lines.
- Replaces comments with whitespace.
- Reacts to lines starting with an octothorp (#), performing macro substitution, file inclusion, conditional inclusion, and other transformations.
Other preprocessors include m4 and Oracle Pro*C. The m4 preprocessor is general-purpose; Oracle Pro*C converts embedded PL/SQL into C.
Preprocessing can be quite cumbersome in incremental parsing or incremental lexical analysis because changes to preprocessing rules can affect the entire text to be preprocessed.
A typical example in C is:
C Example
\r\n#include
The preprocessor replaces the line #include <stdio.h>
with the system header file of that name, which facilitates use of the printf()
function.