Design of a single pass macro processor
I) Rule This design is based on the rule that all macro definitions should appear at the beginning of the program.
II) Format of defining a macro The format for defining a macro is as follows: MACRO (macro keyword …………………………….. (macro prototype
………………………………………. (start of macro body ………………………………………. ………………………………………. ………………………………………. (end of macro body
MEND (end of macro definition Example:
[pic]
Format of database of a single pass macro processor (Data structures used by a single pass macro processor)
A) Macro Name Table (MNT)
|Macro name |MDTP |#PP |#KP |KPTP |#EVS |
| | | | | | |
i) MNT is used for storing the macro names along with MDTP which indicates the location in MDT where the corresponding definition is stored. ii) MNT keeps track of the number of PPs and KPs for error handling. iii) MNT maintains a pointer to KPT called KPTP. iv) MNT also keeps track of the number of expansion variables required by the macro.
B) Macro Definition Table (MDT)
|Macro definition |
| |
i) MDT is used for storing the macro definitions along with MEND statement. ii) While storing the definition, the parameters and expansion variables are replaced by #n and EV#n respectively. iii) While performing macro expansion, #n and EV#n would be replaced by their values from APL and EVS respectively.
C) Keyword Parameter Table (KPT)
|Keyword