GNU macro processor - 2. Lexical and syntactic conventions

Go to the first, previous, next, last section, table of contents.

# 2. Lexical and syntactic conventions

As `m4` reads its input, it separates it into tokens. A token is either a name, a quoted string, or any single character, that is not a part of either a name or a string. Input to `m4` can also contain comments.

## 2.1 Names

A name is any sequence of letters, digits, and the character `_` (underscore), where the first character is not a digit. If a name has a macro definition, it will be subject to macro expansion (see section 3. How to invoke macros).

Examples of legal names are: ``foo'`, ``_tmp'`, and ``name01'`.

## 2.2 Quoted strings

A quoted string is a sequence of characters surrounded by the quotes ``` and `'`, where the number of start and end quotes within the string balances. The value of a string token is the text, with one level of quotes stripped off. Thus

    `'

is the empty string, and

    ``quoted''

is the string

    `quoted'

The quote characters can be changed at any time, using the builtin macro `changequote`. See section 7.2 Changing the quote characters for more information.

## 2.3 Other tokens

Any character, that is neither a part of a name, nor of a quoted string, is a token by itself.

## 2.4 Comments

Comments in `m4` are normally delimited by the characters ``#'` and newline. All characters between the comment delimiters are ignored, but the entire comment (including the delimiters) is passed through to the output--comments are not discarded by `m4`.

Comments cannot be nested, so the first newline after a ``#'` ends the comment. The commenting effect of the begin comment character can be inhibited by quoting it.

The comment delimiters can be changed to any string at any time, using the builtin macro `changecom`. See section 7.3 Changing comment delimiters for more information.

Go to the first, previous, next, last section, table of contents.