Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Preprocessor
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Syntactic preprocessors== Syntactic preprocessors were introduced with the [[Lisp programming language|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 programming language|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 [[OCaml|Objective Caml]] programming language.<ref>[http://caml.inria.fr/pub/docs/manual-camlp4/manual007.html The Revised syntax] from The Caml language website</ref> 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 programming language|Lisp]] family of languages. While the languages, by themselves, are simple dynamically typed functional cores, the standard distributions of [[Scheme (programming language)|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 programming language|Lisp]] family of languages is the possibility of using macros to create an internal DSL. Typically, in a large [[Lisp programming language|Lisp]]-based project, a module may be written in a variety of such [[minilanguage]]s, one perhaps using a [[SQL]]-based dialect of [[Lisp programming language|Lisp]], another written in a dialect specialized for [[Graphical user interface|GUI]]s 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. <!-- Please provide an authoritative cite defining "general purpose(sic) preprocessor" and "general purpose template engine" or else remove this. ==Preprocessors as template engines== Any "general purpose preprocessor", like [[M4 (computer language)|M4]], can be used as a [[template processor|template engine]]. "General purpose preprocessors" and "general purpose template engines" are the same kind of softwares. --~~~ -->
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)