IMPLEMENTATION OF MACRO PROCESSOR
Aim: To write a C program to implement macro expansion.
- Get the statement from input file.
- From the line read, check if opcode is directive “MACRO” if so then number of macro “n” must be incremented.
- Repeat step 1 and 2 until end of file is encountered.
- Open ‘n’ number of files in write mode. These files will later hold body of ‘n’ macro respectively.
- Rewind the input file pointer
- If opcode is “macro”
- Enter macro name present in operand file field into array named “m”.
- Write line to expanded output file.
- Enter lines in body of each macro into corresponding files already opened in file.
- Write body of each macro to be expanded output file also until “MEND” is reached.
- Else if OPCODE is “CALL” the line must be a macro invocation statement so the macro body is retrieved from the corresponding file.
- Write all the remaining lines directly to expanded lines.