⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bf.c

📁 数字信号处理实验
💻 C
字号:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <malloc.h>
#include <ctype.h>
#include <conio.h>

FILE *fp,*bp,*hp,*blzp,*bsfp,*jfp,*ysfp,*tsfhp,*szp,*wp,*wrongp,*allp;

char *blz[9]={"do","begin","else","end","if","then","var","while","int"};
char *ysf[15]={"+","-","*","/","==","=","<","<=",">",">=","+=","-=","*=","/=","!="};
char jf[8]={',',';','(',')','}','{','"','"'};
char hysf[8]={'+','-','*','/','=','<','>','!'};

int lookjf(char ch)
{int i;
 for(i=0;i<8;i++)
 if(ch==jf[i]) return 1;
 return 0;
}

int lookysf(char ch)
{int i;
 for(i=0;i<8;i++)
 if(ch==hysf[i]) return 1;
 return 0;
}

int lookblz(char *str)
{int i;
 for(i=0;i<=8;i++)
  if(strcmp(blz[i],str)==0) return  1;
 return 0;
}


void dkwb()
{ if((blzp=fopen("\\blz.txt","wt+"))==0)
  printf("can not open filewrite\n");
  if((bsfp=fopen("\\bsf.txt","wt+"))==0)
  printf("can not open filewrite\n");
  if((jfp=fopen("\\jf.txt","wt+"))==0)
  printf("can not open filewrite\n");
  if((ysfp=fopen("\\ysf.txt","wt+"))==0)
  printf("can not open filewrite\n");
  if((tsfhp=fopen("\\tsfh.txt","wt+"))==0)
  printf("can not open filewrite\n");
  if((szp=fopen("\\sz.txt","wt+"))==0)
  printf("can not open filewrite\n");
  if((wrongp=fopen("\\wrong.txt","wt+"))==0)
  printf("can not open filewrite\n");
  if((allp=fopen("\\all.txt","wt+"))==0)
  printf("can not open filewrite\n");
}

void ycl()
{char str=' ',strb;
 if((wp=fopen("d:\\ycl.txt","wt+"))==0)
  printf("can not open filewrite\n");

 if ((fp=fopen("d:\\ywj.txt","r"))==0)
  printf("can not open fileread\n");
  else
 {
  while(str!=EOF)
  {str=fgetc(fp);

    if(str==' ')
        {fputc(str,wp);
         ftell(wp);
         str=fgetc(fp);
         if(str==' ')
           {while(str==' ')
             {
              str=fgetc(fp);
              }
            }

         }

    if(str!='/')
      {
       fputc(str,wp);
       ftell(wp);
       }
       else
        {bp=fp;
         strb=fgetc(bp);
         if((strb!='*')&&(strb!='/'))
             {
               fputc(str,wp);
               ftell(wp);
               fputc(strb,wp);
               ftell(wp);

             }
          else
            {if(strb=='/')
              {while(strb!='\n'&&strb!=EOF)
                {str=fgetc(fp);
                 bp=fp;
                 strb=fgetc(bp);
                 }
                fputc('\n',wp);
                ftell(wp);
               }
             if(strb=='*')
               {
                str=fgetc(fp);
                str=fgetc(fp);
                while(str!='*'&&str!=EOF)
                {
                 str=fgetc(fp);
                 }
                if(str=='*')
                {bp=fp;
                 strb=fgetc(bp);
                 if(strb!='/')
                  {fputs("wrongzs",wrongp);
                   ftell(wrongp);
                   fputc('\n',wrongp);
                   printf("wrongzs end\n");
                   }
                 }
                 if(str==EOF)
                 fputs("wrongzs",wrongp);
                 ftell(wrongp);
                 fputc('\n',wrongp);
                 printf("wrongzs end\n");
                 }
                }
              }

         }
  }
}


char jfpd(char ch)
{
  while(lookjf(ch))
  {printf("<jf,%c>\n",ch);
   fputs("5  ",jfp);
   fputc(ch,jfp);
   ftell(jfp);
   fputc('\n',jfp);
   fputs("5  ",allp);
   fputc(ch,allp);
   ftell(allp);
   fputc('\n',allp);
   ch=fgetc(fp);
  }
  return ch;
}

char zmpd(char ch)
{int i=0;
 char n;
 char letter[20];
 while (isalnum(ch)!=0||ch=='_')
 {
  letter[i]=ch;
  i++;
  ch=fgetc(fp);
  if(isalnum(ch)==0&&!lookjf(ch)&&ch!='_'&&isspace(ch)==0&&ch!=EOF)
  {
   while(isspace(ch)==0&&!lookjf(ch)&&ch!=EOF)
    {
     letter[i]=ch;
     i++;
     ch=fgetc(fp);
    }
   letter[i]='\0';
   printf("<wrongletter,%s>\n",letter);
   fputs("wrongletter  ",wrongp);
   fputs(letter,wrongp);
   ftell(wrongp);
   fputc('\n',wrongp);
   return ch;
  }
 }
 letter[i]='\0';
 if(lookblz(letter))
   {printf("<blz,%s>\n",letter);
    fputs("1  ",blzp);
    fputs(letter,blzp);
    ftell(blzp);
    fputc('\n',blzp);
    fputs("1  ",allp);
    fputs(letter,allp);
    ftell(allp);
    fputc('\n',allp);
   }
   else
      {printf("<bsf,%s>\n",letter);
       fputs("2  ",bsfp);
       fputs(letter,bsfp);
       ftell(bsfp);
       fputc('\n',bsfp);
       fputs("2  ",allp);
       fputs(letter,allp);
       ftell(allp);
       fputc('\n',allp);
       }
 return(ch);
}


char szpd(char ch)
{
 int i=0;
 char num[20];
 while((isdigit(ch)!=0)||(ch=='.'))
 {
  num[i]=ch;
  i++;
  ch=fgetc(fp);
  if(isdigit(ch)==0&&!lookjf(ch)&&ch!='.'&&isspace(ch)==0&&ch!=EOF)
  {
    while(isspace(ch)==0&&!lookjf(ch)&&ch!=EOF)
    {
     num[i]=ch;
     i++;
     ch=fgetc(fp);
    }
   num[i]='\0';
   printf("<wrongnum,%s>\n",num);
   fputs("wrongnum  ",wrongp);
   fputs(num,wrongp);
   ftell(wrongp);;
   fputc('\n',wrongp);
   return ch;
  }

 }
 num[i]='\0';
 if(num[i-1]=='.')
 {printf("<wrongnum,%s>\n",num);
   fputs("wrongnum  ",wrongp);
   fputs(num,wrongp);
   ftell(wrongp);;
   fputc('\n',wrongp);
  return ch;
  }
 printf("<num,%s>\n",num);
 fputs("3  ",szp);
 fputs(num,szp);
 ftell(szp);
 fputc('\n',szp);
 fputs("3  ",allp);
 fputs(num,allp);
 ftell(allp);
 fputc('\n',allp);
 return ch;
}

char ysfpd(char ch)
{char strb;
 char ysf[3];
 ysf[0]=ch;
 strb=fgetc(fp);
 if(strb=='=')
  {ysf[1]='=';
   ysf[2]='\0';
   printf("<ysf,%s>\n",ysf);
   fputs("4  ",ysfp);
   fputs(ysf,ysfp);
   ftell(ysfp);
   fputc('\n',ysfp);
   fputs("4  ",allp);
   fputs(ysf,allp);
   ftell(allp);
   fputc('\n',allp);
   ch=fgetc(fp);
   return ch;
  }

 ysf[1]='\0';
 printf("<ysf,%s>\n",ysf);
 fputs("4  ",ysfp);
 fputs(ysf,ysfp);
 ftell(ysfp);
 fputc('\n',ysfp);
 fputs("4  ",allp);
 fputs(ysf,allp);
 ftell(allp);
 fputc('\n',allp);
 return strb;
}

char tsfhpd(char ch)
{
 int i=0;
 char other[20];

 if(isspace(ch)!=0)
 {
  ch=fgetc(fp);
  return ch;
 }

 while((isspace(ch)==0)&&!lookjf(ch)&&ch!=EOF)
  {
   other[i]=ch;
   i++;
   ch=fgetc(fp);
  }
  other[i]='\0';
  printf("<--,%s>\n",other);
  fputs("6  ",tsfhp);
  fputs(other,tsfhp);
  ftell(tsfhp);
  fputc('\n',tsfhp);
  fputs("6  ",allp);
  fputs(other,allp);
  ftell(tsfhp);
  fputc('\n',allp);
  return (ch);
 }



main (char *argv[])
{ char str,c;
  argv[0]="\\ycl.txt";
  dkwb();
  ycl();
  if ((fp=fopen(argv[0],"r"))==0) printf("can not open filekk\n");
    else{
         str =fgetc(fp);
         while(str!=EOF)
          {if(lookjf(str)) str=jfpd(str);
            else
              if((isalpha(str)!=0)||str=='_') str=zmpd(str);
                else
                  if(isdigit(str)!=0) str=szpd(str);
                    else
                      if(lookysf(str)) str=ysfpd(str);
                         else
                         str=tsfhpd(str);
           }
         }

  getch();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -