SYNTAX - syntax accepted by the BPP preprocessor.

Description:

Below we define the syntax for BPP directives. Each directive must begin on a new line with the "#" in column 1 of the line.

Preliminary Definitions:

TOKEN    <- [A-Za-z0-9_.][A-Za-z0-9_.]*
TEXT     <- | ARB_STUFF <cr> | ARB_STUFF '*' <cr> TEXT
ARGLIST  <- TOKEN | TOKEN ',' ARGLIST

Define:

There are two forms of macro definition, one with substitutable arguments and one without. With no arguments, the form is

#define TOKEN TEXT

If substitutable arguments are required, the form is

#define TOKEN(ARGLIST) TEXT

With the first form, all occurrences of TOKEN will be replaced by TEXT when BPP processes subsequent text. With the second form, if TOKEN(ARGLIST) is encountered it will be replaced with a modified version of TEXT. Whenever a token is encountered in TEXT that matches one of the tokens in the ARGLIST of the definition of TOKEN, the text is replaced with the corresponding argument supplied in the B program. For example, consider the following definition.

#define max(x,y) ((x) > (y) ? (x) : (y))

The macro call

x = max(y+2, z%3);

would be expanded to

x = ((y+2) > (z%3) ? (y+2) : (z%3));

Undefining Macros:

A macro may be "undefined" using the "#undef TOKEN" command, as in

#undef max

The given macro's definition is forgotten. Note that it is not necessary to supply the macro's argument list, if any.

#ifdef and Friends:

The commands described below can be used for conditionally deleting parts of the text being processed.

#ifdef TOKEN
#ifndef TOKEN
#elseif TOKEN
#else
#endif

"#ifdef TOKEN" tells BPP not to include text if TOKEN is undefined. "#ifndef TOKEN" will not include text if TOKEN is defined. "#else" and "#elseif TOKEN" are intended to complement "#ifdef" and "#ifndef" directives. The "#endif" directive ends the most recent if-else block.

"#ifdef" and its friends may be used in nested constructions.

File Inclusion:

This is done with a command of the form

#include FILENAME

FILENAME is a standard GCOS cat/file string, or a pathname enclosed in angle brackets as in <zit.h>. If the angle brackets are present, a search is performed as specified by the user-provided search rules (see "expl bpp") or the default search rules. The current default is to search under "b/manif".

BPP also recognizes the method of file inclusion used in B.

Token Delimiters:

Occasionally it is desirable to concatenate some text to the text resulting from a macro expansion. This is done by separating the macro from the text by a special delimiter character '\'. The default value of this character may be changed with the "#delimc" directive

#delimc CHAR

where CHAR is any character. If no character is supplied, this feature is disabled.

If a delimiter character is defined all occurrences of the delimiter will be stripped from the text, except those that are escaped and inside a string. Inside a string, a delimiter may be escaped in the usual way by preceding it with a '*'. By placing a macro call between two occurrences of the delimiter character, it is possible to have a macro call expanded inside a string. Thus

#define MONTH July
x = "The 1st of \MONTH\";

would be expanded to

x = "The 1st of July";

Notes:

Comments, as defined by B, are stripped out by BPP. Any line beginning with '#' but which is not recognized as one of the above directives is simply treated as text.

See Also:

expl bpp

Copyright © 1996, Thinkage Ltd.