C Program for the Implementation of a Macro Processor | CS1207 - System Software Laboratory


AIM:

To write a "C" program for the implementation of a macro processor in CS1207 - System Software Lab.


SOURCE CODE:

#include<studio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
FILE *f1,*f2,*f3,*f4,*f5;
void main()
{
char lbl[20],opc[20],opr[20],mname[20],arg[20],check[20];char ch,dlbl[20],dopc[20],dopr[20];
int c;
clrscr();
f1=fopen("MACIN.DAT","r");
rewind(f1);
f2=fopen("NAMETAB.DAT","r");
rewind(f2);
f3=fopen("DEFTAB.DAT","r");
f4=fopen("EXPAND.DAT","w");
f5=fopen("ARGTAB.DAT","w");
while(!feof(f1))
{
l1:
fscanf(f1,"%s %s %s",lbl,opc,opr);
if(strcmp(opc,mname)==0)
c=1;
if(strcmp(opc,"MACRO")==0)
{
while(strcmp(opc,"MEND")!=0)
{
fscanf(f1,"%s%s%s",lbl,opc,opr);
continue;
}
goto l1;
}
rewind(f2);
rewind(f3);
fscanf(f2,"%s",mname);
if(strcmp(opc,mname)==0)
{
fprintf(f5," %s",opr);
rewind(f5);
while(!feof(f3))
{
fscanf(f3,"%s%s%s",dlbl,dopc,dopr);
if(strcmp(dopc,"MEND")!=0)
{
if(strcmp(dopc,"MACRO")==0)
{
continue;
}
if(strcmp(dopr,"=X'?1'")==0)
strcpy(dopr,"=X'F1'");
if(strcmp(dopr,"?2,X")==0)
strcpy(dopr,"BUFFER,X");
if(strcmp(dopr,"?3")==0)
strcpy(dopr,"LENGTH");
if(c==1)
{
fprintf(f4," %s\t%s\t%s\n",lbl,opc,opr);
c=0;
}
fprintf(f4," %s\t%s\t%s\n",dlbl,dopc,dopr);
}
}
goto l1;
}
fprintf(f4," %s\t%s\t%s\n",lbl,opc,opr);
}
fcloseall();
printf("\n INPUT\n\n Macro Program before expanded \n");
printf(" ---------------------------------\n");
f1=fopen("MACIN.DAT","r");
ch=fgetc(f1);
while(ch!=EOF)
{
printf("%c",ch);
ch=fgetc(f1);
}
printf("\n Definition Table \n");
printf(" ---------------------------------\n");
f2=fopen("DEFTAB.DAT","r");
ch=fgetc(f2);
while(ch!=EOF)
{
printf("%c",ch);
ch=fgetc(f2);
}
printf("\n Name Table \n");
printf(" ---------------------------------\n");
f3=fopen("NAMETAB.DAT","r");
ch=fgetc(f3);
while(ch!=EOF)
{
printf("%c",ch);
ch=fgetc(f3);
}
getch();
clrscr();
printf("\n\n OUTPUT\n\n Macro Program after expanded \n");
printf(" ---------------------------------\n\n");
f4=fopen("EXPAND.DAT","r");
ch=fgetc(f4);
while(ch!=EOF)
{
printf("%c",ch);
ch=fgetc(f4);
}
printf("\n Argument Table \n");
printf(" ---------------------------------\n\n");
f5=fopen("ARGTAB.DAT","r");
ch=fgetc(f5);
while(ch!=EOF)
{
printf("%c",ch);
ch=fgetc(f5);
}
fcloseall();
getch();
}

INPUT FILE:

MACIN.DAT
COPY    START    NULL
RDBUFF    MACRO   INDEV,BUFADR,RECLTH
NULL    CLEAR    X
NULL    CLEAR    A
NULL    CLEAR    S
NULL    +LDT    #4096
NULL    TD    =X'&INDEV'
NULL    JEQ    *-3
NULL    RD    =X'&INDEV'
NULL    COMPR    A,S
NULL    JEQ    *+11
NULL    STCH    BUFADR,X
NULL    TIXR    T
NULL    JLT    *-19
NULL    STX    RECLTH
NULL    MEND    NULL
FIRST    STL    RETADR
CLOOP    RDBUFF    F1,BUFFER,LENGTH
NULL    LDA    LENGTH
NULL    COMP    #0
NULL    JEQ    ENDFIL
EOF    BYTE    C'EOF'
THREE    WORD    3
RETADR    RESW    1
LENGTH    RESW    1
BUFFER    RESB    4096
NULL    END    FIRST

DEFTAB.DAT
COPY    START    NULL
RDBUFF    MACRO   &INDEV,&BUFADR,&RECLTH
NULL    CLEAR    X
NULL    CLEAR    A
NULL    CLEAR    S
NULL    +LDT    #4096
NULL    TD    =X'?1'
NULL    JEQ    *-3
NULL    RD    =X'?1'
NULL    COMPR    A,S
NULL    JEQ    *+11
NULL    STCH    ?2,X
NULL    TIXR    T
NULL    JLT    *-19
NULL    STX    ?3
NULL    MEND    NULL


NAMETAB.DAT
RDBUFF

OUTPUT:



Related Posts:
  • IMPLEMENTATION OF A MACRO PROCESSOR
Previous
Next Post »

3 comments

Write comments
Unknown
AUTHOR
November 7, 2013 at 9:05 PM delete

Pls give the program for to develop a program to implement a macro processor with recursive macro expansion

Reply
avatar

Still not found what you are looking for? Try again here.