m4 (programming language)

from Wikipedia, the free encyclopedia

m4 is a macro - programming , by Brian Kernighan and Dennis Ritchie was developed.

application

A macro processor is a computer program that replaces character strings within a text with other character strings. It enables z. B. the creation and use of reusable text modules in word processing programs.

history

Macroprocessors were common when computer programs were mainly written in assembly language. In those early days of computer technology, programmers often had to use repetitive text passages in their programs. Soon people began to develop simple ways to reuse text. It quickly became apparent that you could not only reuse entire text passages, but also replace individual parts of it if necessary and thus write complex macros . M4 was developed in 1977. It was the first macro language that was used to implement Rational Fortran ( Ratfor ) and is now part of most Unix variants. A main area of ​​application today is the autoconf tool of the GNU project. It is also used to configure the widely used MTA sendmail .

properties

M4 offers the following functions:

  • Replace text
  • Substituting parameters
  • Inserting files
  • Manipulation of strings
  • Conditional expressions
  • Arithmetic expressions
  • Interface to the operating system
  • Diagnostic options for the programmer

Unlike most previous macro processors, M4 is not designed for any particular language (computer or human); however, historically it was developed to support the Ratfor dialect of Fortran . In addition to this, M4 is not only Turing-complete , but also practically a programming language.

example

The following code fragment is a simple example, e.g. B. can be used as part of an HTML library. It defines a macro which automatically numbers chapters:

divert(-1)
define(`H2_COUNT', 0)
define(`H2', `define(`H2_COUNT', incr(H2_COUNT))' dnl
  `<h2>H2_COUNT. $1</h2>')
divert(1)dnl
H2(Erstes Kapitel)
H2(Zweites Kapitel)
H2(Schluss)

M4 generates the following text from this:

<h2>1. Erstes Kapitel</h2>
<h2>2. Zweites Kapitel</h2>
<h2>3. Schluss</h2>

Free implementations

There is a GNU version of m4. FreeBSD , NetBSD and OpenBSD also provide their own implementations of the M4 language.

literature

  • Brian W. Kernighan and Dennis M. Ritchie: The M4 macro processor. Technical report , Bell Laboratories, Murray Hill, New Jersey, USA, 1977.
  • Kenneth J. Turner: Exploiting the m4 macro language. Technical Report CSM-126 , Department of Computing Science and Mathematics, University of Stirling, Scotland, September 1994.
  • René Seindal: GNU M4 Manual . GNU Press 2004.

Web links

Individual evidence

  1. http://wolfram.schneider.org/bsd/7thEdManVol2/m4/m4.pdf
  2. http://www.cs.stir.ac.uk/~kjt/research/pdf/expl-m4.pdf
  3. http://www.gnu.org/software/m4/manual/