Preprocessor

from Wikipedia, the free encyclopedia

A preprocessor (rarely also a precompiler ) is a computer program that prepares input data and forwards it to another program for further processing. The preprocessor is often used by compilers or interpreters to convert an input text and to process the result in the actual program.

Many programming languages, for example the programming language C and the text typesetting program TeX, have macro processors as preprocessors, which significantly expand the possibilities of the respective language to increase the readability of program texts and to structure and modularize projects. PHP - a common scripting language for generating web pages  - can be seen as a preprocessor for HTML .

In the field of CAD design, CAM and finite element simulation , a preprocessor is often used to prepare the designed component for further processing. This includes, for example, work steps such as combination with another component, division into segments, grid generation , conversion to another coordinate system , etc.

Programming language preprocessors

The C preprocessor

The preprocessor of the C language makes the following changes to the program text, among other things, before the actual C compiler compiles the program:

  • Replacing Trigraph sequences such as ??=, ??(, ??)by symbols like #, {, }(not with K & R standard)
  • \Combining physical to logical source text lines (removing the line separator sequences) (not with the K&R standard)
  • Replace comments with spaces
  • Replacement of predefined or #definedefined macros
  • Conditional Compilation of rows between #if, #ifdef, #ifndef, #elifand #endifare, and #ifcan also handle simple constant arithmetic expressions and comparison operators
  • Recursive insertion and processing of files using an #includeinstruction

In addition to simple macro replacement, the conditional translation using #if, #ifdefand is #ifndefan important feature of the C preprocessor: The developer can use it to control which sections of the program text are fed to the compiler and thus show or hide debug program code or adaptations for different processors or operating systems make.

The FreeBASIC preprocessor

The syntax of the FreeBASIC preprocessor is similar to that of C. It interprets statements such as #if, #endif, #ifdef, #else, #define and #include similar or the same as in C. In addition, options such as #include once (no repeated smuggling) and #macro… #endmacro (multi-line macro) made available.

The TeX preprocessor

The capabilities of the preprocessor built into the TeX typesetting system are essentially limited to the definition of macros for combining formatting commands. Based on this, more extensive preprocessors (more precisely: macro collections) have been developed for sometimes very special areas of application in order to make the use of TeX more comfortable for the user. The most prominent representative is LaTeX , other examples are ConTeXt , BibTeX and MusiXTeX .

The programming language PHP

PHP is a scripting language mainly used to create dynamic web pages or web applications . When the web server receives a request, it reads a PHP file. If the file contains PHP start and end marks such as <?phpand ?>, the text between these marks is interpreted as a PHP program , executed and the output of the program is sent to the web browser.

A page showing the current time could look like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:>
 <head>
   <title>Aktuelle Uhrzeit</title>
 </head>
 <body>
  <h1>Aktuelle Uhrzeit</h1>
  <p><?php print strftime('Jetzt ist es %H Uhr, %M Minuten und %S Sekunden'); ?></p>
 </body>
</html>

The PHP preprocessor converts this e.g. B. to in

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
 <head>
   <title>Aktuelle Uhrzeit&lt;/title>
 </head>
 <body>
  <h1>Aktuelle Uhrzeit</h1>
  <p>Jetzt ist es 22 Uhr, 04 Minuten und 55 Sekunden</p>
 </body>
</html>
The dynamic website in the browser (excerpt)

The content of such a page can therefore be changed dynamically. PHP actually behaves like a preprocessor, since the original text is changed and only then sent to the browser .

Preprocessor for CAD, CAM and FEM

A component designed in a CAD system that is to be simulated using the finite element method must first be covered with a grid . Often, additional boundary conditions have to be specified for the simulation, for example that one side of the component is firmly clamped / connected, or speed and axis for a rotational movement. A preprocessor program that prepares the designed component for further processing is usually used for such information. The preprocessor must be able to read in the CAD format of the design program as well as be able to output the input format of the FE solver . The preprocessor then offers input masks for corresponding information. The tasks of a preprocessor include:

  • Combination of the component with another component
  • Division of the component into segments
  • Grid generation
  • Grid adjustment
  • Convert to another coordinate system

See also

Web links

Wiktionary: preprocessor  - explanations of meanings, word origins, synonyms, translations

Individual evidence

  1. Helmut Herold, Michael Klar, Susanne Klar: C ++, UML and Design Patterns . Basics and practice of object orientation. Addison-Wesley, Munich 2005, ISBN 3-8273-2267-7 , pp. 21 ( limited preview in Google Book search).
  2. British Standards Institute (ed.): The C Standard - BS ISO / IEC 9899: 1999 . John Wiley & Sons, 2003, ISBN 0-470-84573-2 . Sections 5.1.1.2, 5.2.4.2.1 f., 6.10 ff.
  3. Command reference on the topic of "preprocessors" on freebasic-portal.de (German)
  4. Official LaTeX project page on latex-project.org (English)
  5. List of TeX Frequently Asked Questions ( Memento of the original from August 21, 2010 in the Internet Archive ) Info: The archive link was automatically inserted and not yet checked. Please check the original and archive link according to the instructions and then remove this notice. on tex.ac.uk (English) @1@ 2Template: Webachiv / IABot / www.tex.ac.uk