fbpx
Wikipedia

Preprocessor

In computer science, a preprocessor (or precompiler)[1] 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. 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.

A common example from computer programming is the processing performed on source code before the next step of compilation. In some computer languages (e.g., C and PL/I) there is a phase of translation known as preprocessing. It can also include macro processing, file inclusion and language extensions.

Lexical preprocessors

Lexical preprocessors are the lowest-level of preprocessors as they only require lexical analysis, that is, they operate on the source text, prior to any parsing, by performing simple substitution of tokenized character sequences for other tokenized character sequences, according to user-defined rules. They typically perform macro substitution, textual inclusion of other files, and conditional compilation or inclusion.

C preprocessor

The most common example of this is the C preprocessor, which takes lines beginning with '#' as directives. The C preprocessor does not expect its input to use the syntax of the C language. Some languages take a different approach and use built-in language features to achieve similar things. For example:

  • Instead of macros, some languages use aggressive inlining and templates.
  • Instead of includes, some languages use compile-time imports that rely on type information in the object code.
  • Some languages use if-then-else and dead code elimination to achieve conditional compilation.

Other lexical preprocessors

Other lexical preprocessors include the general-purpose m4, most commonly used in cross-platform build systems such as autoconf, and GEMA, an open source macro processor which operates on patterns of context.

Syntactic preprocessors

Syntactic preprocessors were introduced with the Lisp family of languages. Their role is to transform syntax trees according to a number of user-defined rules. For some programming languages, the rules are written in the same language as the program (compile-time reflection). This is the case with Lisp and OCaml. Some other languages rely on a fully external language to define the transformations, such as the XSLT preprocessor for XML, or its statically typed counterpart CDuce.

Syntactic preprocessors are typically used to customize the syntax of a language, extend a language by adding new primitives, or embed a domain-specific programming language (DSL) inside a general purpose language.

Customizing syntax

A good example of syntax customization is the existence of two different syntaxes in the Objective Caml programming language.[2] Programs may be written indifferently using the "normal syntax" or the "revised syntax", and may be pretty-printed with either syntax on demand.

Similarly, a number of programs written in OCaml customize the syntax of the language by the addition of new operators.

Extending a language

The best examples of language extension through macros are found in the Lisp family of languages. While the languages, by themselves, are simple dynamically typed functional cores, the standard distributions of Scheme or Common Lisp permit imperative or object-oriented programming, as well as static typing. Almost all of these features are implemented by syntactic preprocessing, although it bears noting that the "macro expansion" phase of compilation is handled by the compiler in Lisp. This can still be considered a form of preprocessing, since it takes place before other phases of compilation.

Specializing a language

One of the unusual features of the Lisp family of languages is the possibility of using macros to create an internal DSL. Typically, in a large Lisp-based project, a module may be written in a variety of such minilanguages, one perhaps using a SQL-based dialect of Lisp, another written in a dialect specialized for GUIs or pretty-printing, etc. Common Lisp's standard library contains an example of this level of syntactic abstraction in the form of the LOOP macro, which implements an Algol-like minilanguage to describe complex iteration, while still enabling the use of standard Lisp operators.

The MetaOCaml preprocessor/language provides similar features for external DSLs. This preprocessor takes the description of the semantics of a language (i.e. an interpreter) and, by combining compile-time interpretation and code generation, turns that definition into a compiler to the OCaml programming language—and from that language, either to bytecode or to native code.

General purpose preprocessor

Most preprocessors are specific to a particular data processing task (e.g., compiling the C language). A preprocessor may be promoted as being general purpose, meaning that it is not aimed at a specific usage or programming language, and is intended to be used for a wide variety of text processing tasks.

M4 is probably the most well known example of such a general purpose preprocessor, although the C preprocessor is sometimes used in a non-C specific role. Examples:

  • using C preprocessor for JavaScript preprocessing.[3][4]
  • using C preprocessor for devicetree processing within the Linux kernel.[5]
  • using M4 (see on-article example) or C preprocessor[6] as a template engine, to HTML generation.
  • imake, a make interface using the C preprocessor, written for the X Window System but now deprecated in favour of automake.
  • grompp, a preprocessor for simulation input files for GROMACS (a fast, free, open-source code for some problems in computational chemistry) which calls the system C preprocessor (or other preprocessor as determined by the simulation input file) to parse the topology, using mostly the #define and #include mechanisms to determine the effective topology at grompp run time.

See also

References

  1. ^ "What is a precompiler?".
  2. ^ The Revised syntax from The Caml language website
  3. ^ Show how to use C-preprocessor on JavaScript files. by T. Snyder.
  4. ^ "The C Preprocessor in Javascript?". espresso-mode.
  5. ^ "Kernel/Git/Stable/Linux.git - Linux kernel stable tree".
  6. ^ Show how to use C-preprocessor as template engine. "Using a C preprocessor as an HTML authoring tool" by J. Korpela, 2000.

External links

  • Programming from the bottom up
  • The Generic PreProcessor
  • Gema, the General Purpose Macro Processor
  • The PIKT piktc text, script, and configuration file preprocessor
  • pyexpander, a python based general purpose macro processor
  • minimac, a minimalist macro processor
  • Java Comment Preprocessor

preprocessor, this, article, needs, additional, citations, verification, please, help, improve, this, article, adding, citations, reliable, sources, unsourced, material, challenged, removed, find, sources, news, newspapers, books, scholar, jstor, february, 201. This article needs additional citations for verification Please help improve this article by adding citations to reliable sources Unsourced material may be challenged and removed Find sources Preprocessor news newspapers books scholar JSTOR February 2013 Learn how and when to remove this template message In computer science a preprocessor or precompiler 1 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 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 A common example from computer programming is the processing performed on source code before the next step of compilation In some computer languages e g C and PL I there is a phase of translation known as preprocessing It can also include macro processing file inclusion and language extensions Contents 1 Lexical preprocessors 1 1 C preprocessor 1 2 Other lexical preprocessors 2 Syntactic preprocessors 2 1 Customizing syntax 2 2 Extending a language 2 3 Specializing a language 3 General purpose preprocessor 4 See also 5 References 6 External linksLexical preprocessors EditLexical preprocessors are the lowest level of preprocessors as they only require lexical analysis that is they operate on the source text prior to any parsing by performing simple substitution of tokenized character sequences for other tokenized character sequences according to user defined rules They typically perform macro substitution textual inclusion of other files and conditional compilation or inclusion C preprocessor Edit Main article C preprocessor The most common example of this is the C preprocessor which takes lines beginning with as directives The C preprocessor does not expect its input to use the syntax of the C language Some languages take a different approach and use built in language features to achieve similar things For example Instead of macros some languages use aggressive inlining and templates Instead of includes some languages use compile time imports that rely on type information in the object code Some languages use if then else and dead code elimination to achieve conditional compilation Other lexical preprocessors Edit Other lexical preprocessors include the general purpose m4 most commonly used in cross platform build systems such as autoconf and GEMA an open source macro processor which operates on patterns of context Syntactic preprocessors EditSyntactic preprocessors were introduced with the Lisp family of languages Their role is to transform syntax trees according to a number of user defined rules For some programming languages the rules are written in the same language as the program compile time reflection This is the case with Lisp and OCaml Some other languages rely on a fully external language to define the transformations such as the XSLT preprocessor for XML or its statically typed counterpart CDuce Syntactic preprocessors are typically used to customize the syntax of a language extend a language by adding new primitives or embed a domain specific programming language DSL inside a general purpose language Customizing syntax Edit A good example of syntax customization is the existence of two different syntaxes in the Objective Caml programming language 2 Programs may be written indifferently using the normal syntax or the revised syntax and may be pretty printed with either syntax on demand Similarly a number of programs written in OCaml customize the syntax of the language by the addition of new operators Extending a language Edit The best examples of language extension through macros are found in the Lisp family of languages While the languages by themselves are simple dynamically typed functional cores the standard distributions of Scheme or Common Lisp permit imperative or object oriented programming as well as static typing Almost all of these features are implemented by syntactic preprocessing although it bears noting that the macro expansion phase of compilation is handled by the compiler in Lisp This can still be considered a form of preprocessing since it takes place before other phases of compilation Specializing a language Edit One of the unusual features of the Lisp family of languages is the possibility of using macros to create an internal DSL Typically in a large Lisp based project a module may be written in a variety of such minilanguages one perhaps using a SQL based dialect of Lisp another written in a dialect specialized for GUIs or pretty printing etc Common Lisp s standard library contains an example of this level of syntactic abstraction in the form of the LOOP macro which implements an Algol like minilanguage to describe complex iteration while still enabling the use of standard Lisp operators The MetaOCaml preprocessor language provides similar features for external DSLs This preprocessor takes the description of the semantics of a language i e an interpreter and by combining compile time interpretation and code generation turns that definition into a compiler to the OCaml programming language and from that language either to bytecode or to native code General purpose preprocessor EditMain article General purpose macro processor Most preprocessors are specific to a particular data processing task e g compiling the C language A preprocessor may be promoted as being general purpose meaning that it is not aimed at a specific usage or programming language and is intended to be used for a wide variety of text processing tasks See also C preprocessor Other uses M4 is probably the most well known example of such a general purpose preprocessor although the C preprocessor is sometimes used in a non C specific role Examples using C preprocessor for JavaScript preprocessing 3 4 using C preprocessor for devicetree processing within the Linux kernel 5 using M4 see on article example or C preprocessor 6 as a template engine to HTML generation imake a make interface using the C preprocessor written for the X Window System but now deprecated in favour of automake grompp a preprocessor for simulation input files for GROMACS a fast free open source code for some problems in computational chemistry which calls the system C preprocessor or other preprocessor as determined by the simulation input file to parse the topology using mostly the define and include mechanisms to determine the effective topology at grompp run time See also EditDirective programming Language construct that specifies how a compiler should process its input Metaprogramming Programming paradigm Macros Rule for substituting a set input with a set output Source to source compiler also known as Transpiler Translator of computer source code Sass stylesheet language Stylesheet language Stylus stylesheet language Stylesheet preprocessor language Less stylesheet language Dynamic stylesheet language Snippet programming Small region of re usable source code machine code or text Template engine Software designed to combine templates with a data model to produce result documents The C preprocessor Macro preprocessor used in the C C and Objective C programming languages The OCaml preprocessor pretty printer The PL I preprocessor The Windows software trace preprocessor General purpose macro processor Macro processor that is not tied to or integrated with a particular language or piece of software References Edit What is a precompiler The Revised syntax from The Caml language website Show how to use C preprocessor on JavaScript files JavaScript is Not Industrial Strength by T Snyder The C Preprocessor in Javascript espresso mode Kernel Git Stable Linux git Linux kernel stable tree Show how to use C preprocessor as template engine Using a C preprocessor as an HTML authoring tool by J Korpela 2000 External links Edit Look up preprocessor in Wiktionary the free dictionary DSL Design in Lisp Programming from the bottom up The Generic PreProcessor Gema the General Purpose Macro Processor The PIKT piktc text script and configuration file preprocessor pyexpander a python based general purpose macro processor minimac a minimalist macro processor Java Comment Preprocessor Retrieved from https en wikipedia org w index php title Preprocessor amp oldid 1127941052, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.