Two Pass Macro Processor
The design of a macro processor generally is machine independent. A macro instruction is a set of statements which is used to write shorthand version of a program. Whenever a macro is invoked, the macro processor replaces it with the corresponding sequence of statements (expanding
). Generally, a MP does not perform analysis of the text. So it can be considered as machine independent. The output of MP is generally fed to assembler, compiler, OS command language for analysis. Talking about the design there are one-pass and two-pass MPs. In One-pass MP, Macro must be defined before its invocation. Three Data structures are there: NAMTAB, DEFTAB, and ARGTAB. In typical two-pass MP, First pass processes all macro definitions and second pass expands all macro invocations. ELENA, m4, m5, ML/I are some examples of macro-processors. The MP is designed to perform four basic tasks: recognize the macro definition, save macro definition, recognize the macro call and expand the call.