IMPLEMENTATION OF A MACRO PROCESSOR
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
void main()
{
char
n,n1,c1,i,oper[20],opd[20],iopd[20],ilab[20];
char
fn[10][10],m[20][3];
FILE
*fp1,*fp2,*p[5];
clrscr();
printf("\nImplementation
of A Macro Processor:");
printf("\n------------------------------------\n\n");
n=0;
fp1=fopen("macin.txt","r");
while(!feof(fp1))
{
fscanf(fp1,"%s%s%s",ilab,iopd,oper);
if(strcmp(iopd,"macro")==0)
n++;
}
printf("No.Of.Macros
= %d\n",n);
n1=n;
printf("Enter
the text filename: ");
for(i=0;i<n;i++)
{
scanf("%s",fn[i]);
p[i]=fopen(fn[i],"w");
}
n=0;
rewind(fp1);
while(!feof(fp1))
{
fscanf(fp1,"%s%s%s",ilab,iopd,oper);
if(strcmp(iopd,"macro")==0)
{
strcpy(m[n],oper);
fscanf(fp1,"%s%s%s",ilab,iopd,oper);
while(strcmp(iopd,"mend")!=0)
{
fprintf(p[n],"%s %s
%s\n",ilab,iopd,oper);
fscanf(fp1,"%s%s%s",ilab,iopd,oper);
}
fclose(p[n]);
n++;
}
}
for(i=0;i<n1;i++)
p[i]=fopen(fn[i],"r");
fp2=fopen("macout.txt","w");
rewind(fp1);
fscanf(fp1,"%s%s%s",ilab,iopd,oper);
while(!feof(fp1))
{
if(strcmp(iopd,"call")==0)
{
for(i=0;i<n1;i++)
{
if(strcmp(m[i],oper)==0)
{
rewind(p[i]);
fscanf(p[i],"%s%s%s",ilab,iopd,oper);
while(!feof(p[i]))
{
fprintf(fp2,"%s %s
%s\n",ilab,iopd,oper);
c1=1;
fscanf(p[i],"%s%s%s",ilab,iopd,oper);
}
break;
}
}
}
if(c1!=1)
fprintf(fp2,"%s %s
%s\n",ilab,iopd,oper);
c1=0;
fscanf(fp1,"%s%s%s",ilab,iopd,oper);
}
fprintf(fp2,"%s
%s %s\n",ilab,iopd,oper);
printf("\nProgram
Completed Successfully...");
getch();
}
OUTPUT:
Implementation of A Macro Processor:
------------------------------------------------
No.Of.Macros = 2
Enter the text filename: macin
macout
Program Completed Successfully...
INPUT FILE:
MACIN.TXT
** macro m1
** move a,b
** mend --
** macro m2
** lda b
** mend --
** start 1000
** lda a
** call m1
** call m2
** add a,b
OUTPUT FILE:
MACOUT.TXT
** macro m1
** move a,b
** mend --
** macro m2
** lda b
** mend --
** start 1000
** lda a
** move a,b
** lda b
** add a,b
No comments:
Post a Comment
Thanks for your valuable comments