Advertisement
Guest User

tokenizer(fahim-5127)

a guest
Oct 19th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.96 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<ctype.h>
  4. #include<string.h>
  5. int main()
  6. {
  7.     FILE *fi,*fo,*fop,*fk ,*ftest1 ,*ftest2,*ftest3, *ftest4;
  8.     int flag=0,i=1 , l=0;
  9.     int k[9]={1,2,3,4,5,6,7,8,9};
  10.     char c,t,a[15],ch[15],file[20],d;
  11.     printf("Enter the file name : ");
  12.     scanf("%s",file);
  13.     fi=fopen(file,"r");
  14.     fo=fopen("inter.c","w");
  15.     ftest1=fopen("outputkeyword.txt","w");
  16.     ftest2=fopen("outputidentifier.txt","w");
  17.     ftest3=fopen("outputdelimmitiot.txt","w");
  18.     ftest4=fopen("outputoperator.txt","w");
  19.     fop=fopen("oper.c","r");
  20.     fk=fopen("key.c","r");
  21.     c=getc(fi);
  22. //  clrscr();
  23.     while(!feof(fi))
  24.     {
  25.         if(isalpha(c)||isdigit(c)||(c=='['||c==']'||c=='.'==1))
  26.             fputc(c,fo);
  27.         else
  28.         {
  29.          if(c=='\n')
  30.                {fprintf(fo,"\t  %p \n\t",k[l]);
  31.                l= l+1;}
  32.          else if (c == '=')
  33.                fprintf(fo,"");
  34.  
  35.  
  36.          else
  37.                fprintf(fo,"%c\t",c);
  38.          }
  39.         c=getc(fi);
  40.     }
  41.     fclose(fi);
  42.     fclose(fo);
  43.  
  44.     fi=fopen("inter.c","r");
  45.     printf("\t\tLEXICAL ANALYSIS \n");
  46.     fscanf(fi,"%s",a);
  47.     printf("\nline  : %d\n",i++);
  48.     while(!feof(fi))
  49.     {
  50.      if((strcmp(a,"$")==0))
  51.      {
  52.         printf("\nline  : %d\n",i++);
  53.         fscanf(fi,"%s",a);
  54.      }
  55.      fscanf(fop,"%s",ch);
  56.      while(!feof(fop))
  57.      {
  58.  
  59.         if(strcmp(ch,a)==0)
  60.         {
  61.          fscanf(fop,"%s",ch);
  62.          printf("\t\t%s\t:\t%s\n",a,ch);
  63.          if (a=="+" || a=="/" || a=="-" || a=="=" )
  64.             {fprintf(ftest4,"%s ", a);}
  65.          else{ fprintf(ftest3,"%s ", a);}
  66.  
  67.          flag=1;
  68.          }
  69.         fscanf(fop,"%s",ch);
  70.       }
  71.       rewind(fop);
  72.       fscanf(fk,"%s",ch);
  73.  
  74.  
  75.       while(!feof(fk))
  76.       {
  77.         if(strcmp(ch,a)==0)
  78.         {
  79.          fscanf(fk,"%s",ch);
  80.          printf("\t\t%s\t:\tkeyword\n",a);
  81.          fprintf(ftest1,"%s ", a);
  82.          flag=1;
  83.          }
  84.         fscanf(fk,"%s",ch);
  85.       }
  86.       rewind(fk);
  87.       if(flag==0)
  88.       {
  89.        if(isdigit(a[0]))
  90.         printf("\t\t%s\t:\tconstant\n",a);
  91.        else
  92.         printf("\t\t%s\t:\tidentifier\n",a);
  93.         fprintf(ftest2,"%s ", a);
  94.  
  95.  
  96.        }
  97.         flag=0;
  98.        fscanf(fi,"%s",a);
  99.     }
  100.     getch();
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement