M4 (computer language)

M4 is a macro programming language that was developed by Brian Kernighan and Dennis Ritchie.

Application

A macro processor is a computer program that replaces strings within a text by other character strings. It allows, for example, the creation and use of recyclable text blocks in word processing programs.

History

Macro processors were widespread, were still written as computer programs mainly in assembler. In these early days of computer technology, programmers often had to use recurring text passages in their programs. Soon men began to develop simple ways to reuse text. It quickly became evident that one could reuse the text by not only, but also individual parts if necessary replace it and so was able to write complex macros. M4 was developed in 1977. It was the first macro language has been implemented with the Rational Fortran ( Ratfor ), and is now part of most Unix variants. A major application area is the autoconf tool of the GNU Project today. Earlier, it was also used sendmail for the configuration of the then popular MTA.

Properties

M4 has the following features:

  • Replacing 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 specific ( human or computer ) language; historically but it was designed to support the Ratfor dialect of Fortran. In addition, M4 is not merely a Turing -complete, but also a practical programming language.

Example

The following code fragment is a simple example which can be used, for example as part of a HTML library. It defines a macro, which automatically numbered chapters:

Divert (-1 ) define ( ` H2_COUNT ', 0) define ( ' H2 ', ` define ( ` H2_COUNT ', incr ( H2_COUNT ) ) ' dnl    `

H2_COUNT. $ 1 < / h2 > ' ) divert ( 1 ) dnl H2 ( Chapter One ) H2 ( Chapter Two ) H2 (Final ) M4 generated from the following text:

1 Chapter One < / h2 >

2 Chapter Two < / h2 >

3 Closing < / h2 > Free implementations

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

Credentials

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