Google Search

Sunday, June 5, 2011

IMPLEMENTATION OF MACRO PROCESSOR :write a C program to implement macro expansion.


IMPLEMENTATION OF MACRO PROCESSOR


Aim:                To write a C program to implement macro expansion.

Algorithm:

  1. Get  the statement from input file.
  2. From  the line read, check if opcode is directive “MACRO” if so then number of macro “n” must be incremented.
  3. Repeat step 1 and  2 until end of file is encountered.
  4. Open ‘n’ number of files in write mode. These files will later hold body of ‘n’ macro respectively.
  5. Rewind the input file pointer
  6. If opcode is “macro”
  7. Enter macro name present in operand file field into array named “m”.
  8. Write line to expanded output file.
  9. Enter lines in body of each macro into corresponding files already opened in file.
  10. Write body of each macro to be expanded output file also until “MEND” is reached.
  11. Else if  OPCODE is “CALL” the line must be a macro invocation statement so the macro body is retrieved from the corresponding file.
  12. Write all the remaining lines directly to expanded lines.

1 comments:

Madhusudan Dad said...

what about actual implementation in c?

Post a Comment