NOTES revision 1590
1234852Sbaptm4 - macro processor 2234852Sbapt 3234852SbaptPD m4 is based on the macro tool distributed with the software 4234852Sbapttools (VOS) package, and described in the "SOFTWARE TOOLS" and 5234852Sbapt"SOFTWARE TOOLS IN PASCAL" books. It has been expanded to include 6234852Sbaptmost of the command set of SysV m4, the standard UN*X macro processor. 7234852Sbapt 8234852SbaptSince both PD m4 and UN*X m4 are based on SOFTWARE TOOLS macro, 9234852Sbaptthere may be certain implementation similarities between 10234852Sbaptthe two. The PD m4 was produced without ANY references to m4 11234852Sbaptsources. 12234852Sbapt 13234852Sbaptwritten by: Ozan S. Yigit 14234852Sbapt 15234852SbaptReferences: 16234852Sbapt 17234852Sbapt Software Tools distribution: macro 18234852Sbapt 19234852Sbapt Kernighan, Brian W. and P. J. Plauger, SOFTWARE 20234852Sbapt TOOLS IN PASCAL, Addison-Wesley, Mass. 1981 21234852Sbapt 22234852Sbapt Kernighan, Brian W. and P. J. Plauger, SOFTWARE 23234852Sbapt TOOLS, Addison-Wesley, Mass. 1976 24234852Sbapt 25234852Sbapt Kernighan, Brian W. and Dennis M. Ritchie, 26234852Sbapt THE M4 MACRO PROCESSOR, Unix Programmer's Manual, 27234852Sbapt Seventh Edition, Vol. 2, Bell Telephone Labs, 1979 28234852Sbapt 29234852Sbapt System V man page for M4 30234852Sbapt 31234852Sbapt 32234852SbaptImplementation Notes: 33234852Sbapt 34234852Sbapt[1] PD m4 uses a different (and simpler) stack mechanism than the one 35234852Sbapt described in Software Tools and Software Tools in Pascal books. 36234852Sbapt The triple stack thing is replaced with a single stack containing 37234852Sbapt the call frames and the arguments. Each frame is back-linked to a 38234852Sbapt previous stack frame, which enables us to rewind the stack after 39234852Sbapt each nested call is completed. Each argument is a character pointer 40234852Sbapt to the beginning of the argument string within the string space. 41234852Sbapt The only exceptions to this are (*) arg 0 and arg 1, which are 42234852Sbapt the macro definition and macro name strings, stored dynamically 43234852Sbapt for the hash table. 44234852Sbapt 45234852Sbapt . . 46234852Sbapt | . | <-- sp | . | 47234852Sbapt +-------+ +-----+ 48234852Sbapt | arg 3 ------------------------------->| str | 49234852Sbapt +-------+ | . | 50 | arg 2 --------------+ . 51 +-------+ | 52 * | | | 53 +-------+ | +-----+ 54 | plev | <-- fp +---------------->| str | 55 +-------+ | . | 56 | type | . 57 +-------+ 58 | prcf -----------+ plev: paren level 59 +-------+ | type: call type 60 | . | | prcf: prev. call frame 61 . | 62 +-------+ | 63 | <----------+ 64 +-------+ 65