User guide

4.3. COMMANDS 109
bgpm FROM,TO/K,UPB/K CIN:y, POS:y, NAT:y
This is an implementation of Chr i s toph er Strachey’s GPM macrogenerator. It takes
input from the FROM file if specified, otherwise it reads from the standard input stream.
The TO argument specifies the file to receive the macrogenerated result, otherwise this
is sent to the standard output stream. The UPB argument specified the amount of
memory that bgpm may use.
A macro call is enclosed in square brackets ([ and ] and contains arguments sep-
arated by backslash characters (\). The arguments are macro expanded as they are
read in. To avoid macro expansion text can be enclosed within nested quotation marks
({ and }). On reaching the close square bracket at the end of a mac ro call, the ze-
roth argument is looked up in the environment of defined macros and macrogeneration
continues from the beginning of its value. When the end of this value is reached the
expansion of the call is complete and macrogeneration continues from just after the
closing square bracket. While a macro call is being expanded, a parameter of the form
^n is replaced by a copy of the n
th
argument of the current call . The number n is given
as a sequence of decimal digits. The character ’‘’ introduces a comment cons i st i ng
of all remaining character of the current line followed by all white space characters
including newlines up to but not including the next non white space character. The
following macros are predefined.
[def\name\value]
This causes a macro with the given name and value to be declared.
[set\name\value]
This updates a named macro with a new value which may be truncated if necessary.
[eval\expression]
This evaluate the given integer expression consisting of numbers and the numeric
operators *, /, %, + and -. Parentheses may be used for grouping and spaces may
appear anywhere except within numbers.
[lquote]
[rquote]
These macros expand to the quotation marks { and } respectivel y.
[eof]
This macro generates the end of file symbol and can be used to terminate input
from the standard input stream.
A simple definition and call is the following.
[def\xxx\{arg0 is ^0, arg1 is ^1 and arg2 is ^2}]
[xxx\yyy\zzz]
This would generate:
arg0 is xxx, arg1 is yyy and arg2 is zzz
For an extremely obscure example see: BCPL/cintcode/perm.bgpm.