|
Article on other languages:
|
m4 is a general purpose macro processor designed by Brian Kernighan and Dennis Ritchie. The name m4 stands for macro, i.e. m plus 4 characters.
UseA macro processor (or a preprocessor) is a text-replacement tool. Its chief use is to re-use text templates, typically in programming applications, but also in text editing, text processing applications. HistoryMacro processors were prevalent when assembly language programming was the common tool of programmers. In these early days of programming, the programmers noted that much of their program was repeated text. Simple means to re-use this text were invented. Programmers soon discovered that it was easier not only to reuse entire blocks of text, but also to substitute different values for similar parameters. This defined the usage range of macro processors. m4 was developed in 1977, based on ideas of Christopher Strachey. The distinguishing features of this style of macro preprocessing include the fact that it is free form, not line based (as typical for macro preprocessors designed for assembly language processing) and the high degree of re-expansion (e.g., a macro's arguments are expanded twice, once during scanning and once when they are interpolated). It was the original macro engine used to implement Rational Fortran, and is shipped with most Unix variants. One of the most widespread present-day uses is as part of the GNU Project's autoconf. It is also used in the configuration process of the widespread mail transfer agent sendmail. In general, it is very useful for code generation purposes, owing to its Turing completeness, but can be hard to debug. Featuresm4 offers these facilities:
Unlike most earlier macro processors, it is not targeted at any particular computer or human language; historically, however, it was developed for supporting the Ratfor dialect of Fortran. Unlike some other macro processors, m4 is Turing-complete as well as a practical programming language. ExampleThe following fragment is a simple example that could be part of an HTML generation library. It defines a macro to number sections automatically: define(`H2_COUNT', 0)dnl define(`H2', `define(`H2_COUNT', incr(H2_COUNT))'dnl `<h2>H2_COUNT. $1</h2>')dnl dnl H2(First Section) H2(Second Section) H2(Conclusion) After being processed with m4, the following text will be generated: <h2>1. First Section</h2> <h2>2. Second Section</h2> <h2>3. Conclusion</h2> Note the frequent use of dnl which deletes up to and including the newline, thus preventing many blank lines appearing in the output. Free software implementationsThere is a GNU version of m4. FreeBSD, NetBSD, and OpenBSD also provide independent implementations of the m4 language. Furthermore, the Heirloom Project Development Tools includes a free version of the m4 language, derived from OpenSolaris. See alsoReferences
External links |
This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License.
Mercedes Car
This site monitored by SitePinger.net