Two Pass Macroprocessor
Two Pass Macroprocessor
MACROPROCESSOR
DEFINITION
AND
ALGORITHM
CONTENTS
Specification of Problem
Specification of databases
Algorithm
Flowchart
SPECIFICATION OF PROBLEM
SPECIFICATION OF DATABASES
Pass 1: The input macro source program.
The output macro source program to be used by Pass2.
Macro-Definition Table (MDT), to store the body of macro defns.
SPECIFICATION OF DATABASES
Pass 2: The input is from Pass1.
The output is expanded source to be given to
assembler.
PASS I - ALGORITHM
Pass1 of macro processor makes a line-by-line scan over its
input.
Set MDTC = 1 as well as MNTC = 1.
Read next line from input program.
If it is a MACRO pseudo-op, the entire macro definition except
this (MACRO) line is stored in MDT.
The name is entered into Macro Name Table along with a
pointer to the first location of MDT entry of the definition.
When the END pseudo-op is encountered all the macro-defns
have been processed, so control is transferred to pass2
Pass 1
MDTC<-1
MNTC<-1
PASS I - FLOWCHART
Read next
source card
MACRO
pseudoop?
Write copy of
source card
END
pseudoop?
Read next
source card
Read next
source card
Substitute
index
notation for
arguments
Go to Pass 2
MEND
pseudoop?
PASS II - ALGORITHM
This algorithm reads one line of i/p prog. at a time.
for each Line it checks if op-code of that line matches
any of the MNT entry.
When match is found (i.e. when call is pointer called
MDTF to corresponding macro defns stored in MDT.
The initial value of MDTP is obtained from MDT index
field of MNT entry.
PASS II - ALGORITHM
Reading proceeds from the MDT, as each successive
line is read, The values form the argument list one
substituted for dummy arguments indices in the macro
defn.
Reading MEND line in MDT terminates expansion of
macro & scanning continues from the input file.
When END pseudo-op encountered , the expanded
source program is given to the assembler
PASS II - FLOWCHART
Pass 2
Read next
source card
(copied by
pass 1)
Search MNT for match
with operation code
MACRO
name
found?
Write into
expanded
source card
file
No
Yes
END
pseudoop?
Yes
Supply expanded
source file to
assembler
processing
Yes
MEND
pseudoop?
No
Write
expanded
source card
No