---- Pseudocode for Macro Processor COP 3601: Introduction to Systems Software Handles nested definitions? Handles nested invocations? Macro Processor Pseudocode BEGIN initialize Scnt, Indx, and Level to 0 Expanding <-- FALSE WHILE Opcode <> "END" BEGIN Getline Processline END {While} END {Main Program} Getline: BEGIN IF Expanding Nextline <-- Mactab[Indx] substitute arguments from Argtab for positional notation increment Indx ELSE Nextline <-- Sourcecode[Scnt] increment Scnt ENDIF END {Getline} Processline: BEGIN Breakup Nextline Xsearch Macnames for Opcode IF found Expand ELSE IF Level > 0 add Nextline to Mactab ELSE IF Opcode = "MACRO" Define ELSE append Nextline to expanded source file ENDIF ENDIF ENDIF END {Processline} Expand: BEGIN Expanding <-- TRUE get the macro prototype statement from Mactab Note: Indx (retrieved under xsearch) points into Mactab set up Argtab from the prototype argument list append Nextline as a comment to expanded source file WHILE Indx <> end of Macro body BEGIN Getline Processline END {While} Expanding <-- FALSE END {Expand} Define: BEGIN Insert Opcode,Indx into Macnames {components of a Macnames entry are macro-name, starting-index, ending-index (TBD)} add Nextline to Mactab Level <-- 1 WHILE Level > 0 BEGIN Getline IF Nextline is not a comment substitute positional notation for parameters Processline IF Opcode = "MACRO" Level <-- Level + 1 ELSE IF Opcode = "MEND" Level <-- Level - 1 ENDIF ENDIF ENDIF END {While} update Macnames entry by inserting Indx {ending-index} END {Define}