1 / 4

Algorithm for One-pass Macro Processor

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’) {

diata
Télécharger la présentation

Algorithm for One-pass Macro Processor

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 220 - Software Systems

  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 220 - Software Systems

  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 220 - Software Systems

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

More Related