Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<ctype.h>
- #include<string.h>
- int main()
- {
- FILE *fi,*fo,*fop,*fk ,*ftest1 ,*ftest2,*ftest3, *ftest4;
- int flag=0,i=1 , l=0;
- int k[9]={1,2,3,4,5,6,7,8,9};
- char c,t,a[15],ch[15],file[20],d;
- printf("Enter the file name : ");
- scanf("%s",file);
- fi=fopen(file,"r");
- fo=fopen("inter.c","w");
- ftest1=fopen("outputkeyword.txt","w");
- ftest2=fopen("outputidentifier.txt","w");
- ftest3=fopen("outputdelimmitiot.txt","w");
- ftest4=fopen("outputoperator.txt","w");
- fop=fopen("oper.c","r");
- fk=fopen("key.c","r");
- c=getc(fi);
- // clrscr();
- while(!feof(fi))
- {
- if(isalpha(c)||isdigit(c)||(c=='['||c==']'||c=='.'==1))
- fputc(c,fo);
- else
- {
- if(c=='\n')
- {fprintf(fo,"\t %p \n\t",k[l]);
- l= l+1;}
- else if (c == '=')
- fprintf(fo,"");
- else
- fprintf(fo,"%c\t",c);
- }
- c=getc(fi);
- }
- fclose(fi);
- fclose(fo);
- fi=fopen("inter.c","r");
- printf("\t\tLEXICAL ANALYSIS \n");
- fscanf(fi,"%s",a);
- printf("\nline : %d\n",i++);
- while(!feof(fi))
- {
- if((strcmp(a,"$")==0))
- {
- printf("\nline : %d\n",i++);
- fscanf(fi,"%s",a);
- }
- fscanf(fop,"%s",ch);
- while(!feof(fop))
- {
- if(strcmp(ch,a)==0)
- {
- fscanf(fop,"%s",ch);
- printf("\t\t%s\t:\t%s\n",a,ch);
- if (a=="+" || a=="/" || a=="-" || a=="=" )
- {fprintf(ftest4,"%s ", a);}
- else{ fprintf(ftest3,"%s ", a);}
- flag=1;
- }
- fscanf(fop,"%s",ch);
- }
- rewind(fop);
- fscanf(fk,"%s",ch);
- while(!feof(fk))
- {
- if(strcmp(ch,a)==0)
- {
- fscanf(fk,"%s",ch);
- printf("\t\t%s\t:\tkeyword\n",a);
- fprintf(ftest1,"%s ", a);
- flag=1;
- }
- fscanf(fk,"%s",ch);
- }
- rewind(fk);
- if(flag==0)
- {
- if(isdigit(a[0]))
- printf("\t\t%s\t:\tconstant\n",a);
- else
- printf("\t\t%s\t:\tidentifier\n",a);
- fprintf(ftest2,"%s ", a);
- }
- flag=0;
- fscanf(fi,"%s",a);
- }
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement