Presentation is loading. Please wait.

Presentation is loading. Please wait.

Algorithm for One-pass Macro Processor

Similar presentations


Presentation on theme: "Algorithm for One-pass Macro Processor"— Presentation transcript:

1 Algorithm for One-pass Macro Processor
main () /* main program */ { EXPANDING = 0; /* definition case; a control variable for reading input record from input sources */ while (OPCODE != ‘END’) { GETLINE (line); /* get a next line (from expansion or definition); label, opcode, operands */ PROCESSLINE (line); /* define or expand a line after getting it; label, opcode, operands*/ } PROCESSLINE (line) search NAMTAB for line.opcode; if (found) EXPAND (line); /* expand macro definition with arguments from invocation */ else if DEFINE (line); /* put macro definition in DEFTAB */ else write the source line to expand file; CmpE Software Systems Prof. Weider Yu

2 Algorithm for One-pass Macro Processor
DEFINE (line) { enter line.label into NAMTAB; /* enter macro name into NAMTAB */ enter macro prototype into DEFTAB; /* the first declaration statement */ LEVEL = 1; while (LEVEL > 0) { GETLINE (line); /* get the next line of the macro definition */ if (line != comment line) { substitute positional notation for parameters; /* &param_1  ?1, etc. */ enter line into DEFTAB; if (OPCODE = ‘MACRO’) LEVEL = LEVEL +1; else if (OPCODE = ‘MEND’) LEVEL = LEVEL –1; } store pointers (label->begin and label->end) in NAMTAB; /* store macro def. begin and end pointers */ CmpE Software Systems Prof. Weider Yu

3 Algorithm for One-pass Macro Processor
EXPAND (line) { EXPANDING = 1; /* expansion case; ready to read input from DEFTAB*/ get the first line of macro definition (macro prototype) from DEFTAB; set up arguments (from macro invocation) in ARGTAB; write macro invocation to expanded file (output file) as a comment; while (OPCODE != MEND) { /* while not end of macro definition */ GETLINE (line); PROCESSLINE (line); } EXPANDING = 0; /* macro expansion is done */ GETLINE (line) if (EXPANDING = 1) { get next line of macro definition from DEFTAB; substitute arguments from ARGTAB for position notation; else read next line from input file; /* read the source program file */ CmpE Software Systems Prof. Weider Yu

4 One-pass Macro Processor Algorithm
A flow chart for the one-pass macro processor algorithm. 2 INPUT FILE READ (next line) 2 1 GETLINE READ (next line) MACRO PROCESSOR DEFTAB 5 SUBSTITUTE (arguments) 4 PROCESSLINE DEFINE ENTER (macro prototype/line) WRITE (source line) 3 5 EXPANDED FILE SEARCH 5 EXPAND ARGTAB NAMTAB ENTER (macro name) SET UP (arguments) CmpE Software Systems Prof. Weider Yu


Download ppt "Algorithm for One-pass Macro Processor"

Similar presentations


Ads by Google