A simpler macro processor
Jr. William A. Ward · Purdue University Press eBooks · 2002
design objective for this macro processor is to be as pov.erful as fOssible arrl yet remain siniple to use arrl implanent. It w:lS developed primarily to manipulate canputer prograns mere the processor takes a sJtI1bol table plus a prcgran template containing macros and prodoces a 5p;!cific progran. '!his approach is applied to the macro processor itself; the algorithm consists of a portable Fbrtran 66 version of the processor plus a program template of the processor. The macro processor template may be run through the portable macro processor to produce a version tailored to the local computing envirol1llent. In particular, it is easy to produce a Fortran 77 version of the macro processor. 1. THE WlCRO PROCESSOR A macro processor is a tool to substitute values from a s}mbol table into a text. Thus, if rY\.TE has the value 'JULY 10, 1983' am PLACE has the value 'HONG KONG' then the text fragment IlZ'!..'I'ELlNE: $DATE, $PLACE. THIS CBSERVER••• WJuld be transformed into m'IELINE: JULY 10, 1983, HeN; I ssible Wiile ranaining simple to use and implanent. It is expressly designed to manipulate Fortran cooe althoLgh it is suitable for general text processing:. 'Ihe tw:l ingredients of macro processing are the s:rmbol table arrl the input text. This processor has a very snall initial s~bol table (mostly consisting of processor option swi tches) so the input text contains the information to build the s~bol table. The facilities are of four kirrls: (1) slbstitution of text, (2) 'manipulation of the s~bol table (3) control of the sibstitution, and (4) other:s (e.g. comnents, .processor options). 'Ihe processor is keyed to tw:> special characters: $, the slbstitution prefiX and *., -the directive prefix. 'Ihe input has lines of text with processor ccmnands embedded in them. Each line is first ocanned for substitution and these are made. '!he line is then scanne::1. for directives (the *, must be the first non-blank character) and these are executed. If a substitution involves multiple lines then each line is processe:::J as toolgh it were input. 'Ibis allows for irrlefinite nesting of substitutions Which may include control directives. 'Ihe algorithn contains a complete user's guide for the macro processor so we limit further description here to canpact tabular sunmary of the faciliti-es~ Table 1 arrl the processor options, Table 2. principal dra1o.backs to a PJrtable macro processor in Fortran are (1) characters must be store:::J one per Ord and (2) the Fortran r/o packages are . usually very inefficient. input/output of the macro processo.r is isolated in the short routines IOERRr-t, IOLIST, IOPAGE, ICROLN, and ICWRLN. These may be replaced by more efficient, machine deFEndent routines wi. thout rnoch difficulty. Storing one character per wrd and using Fortran 66 makes the macro processor inefficient in space. These inefficiencies are not very signif~cant for short texts or occasional !JSe but beccrne irnp::>rtant with heavy use. For this rea'son a prOjran template of the macro processor is inclu:ie::l so the p:>rtable Fb~tr~n 66 version can produce a version Which uses the character data t)'Fe faCilities of Fortran 77. Other tailoring, soch as resettirg standard unit nunbers, can be made at the same time. details of this procooure are given in the user's manual. '!able 1 below sunmarizes the facilities of the simple macro processor. Table 2 lists its options. The nature and use of the processor is, perhaps, best seen from the simple example application in the ,!ext section. (