Saturday 17 September 2011

SINGLE PASS MACRO PROCESSOR


SINGLE PASS MACRO PROCESSOR
AIM:
To implement a single pass macro processor in C language.
ALGORITHM:
1. Get the statement from the input file
2. If the statement has the directive “MACRO”, then the number of macro “n” will be
incremented by 1
3. Repeat the steps 1 and 2 until an end of file is encountered
4. Open “n” number of macro files in write mode and rewind the input file pointer
5. If the directive is “MACRO” then, do the following
5.1 Enter the macro name present in the operand field
5.2 Write the line to the expanded output file
5.3 Enter the lines in the body of each macro in to the corresponding files already opened
in step 4
5.4 Write the body of each macro to the expanded output file until a “MEND” is reached
6. Write the remaining lines directly to the expanded file.
MACROIN.DAT
M1 MACRO **
** LDA N1
** ADD N2
** STA N3
** MEND **
M2 MACRO **
** LDA N1
** SUB N2
** STA N4
** MEND **
M3 MACRO **
** LDA N1
** MUL N2
** STA N5
** MEND **
** START 1000
** M3 **
** M2 **
** M1 **
** END **

RESULT:
Thus a single pass macro processor is implemented in C language.

1 comments:

Post a Comment