首页 > 代码库 > 文法规则写法

文法规则写法

#include<stdio.h>main(){    char n[100],n1[100],n2[100];    int i,i1=0,i2=0,j;    printf("请你输入字符串:\n");    gets(n);      for(i=0;i<n;i++)    {        j=(int) n[i];        n1[i]=n[100];        if((j>=65) && (j<=90)||(j>=90) && (j<=122))        {            n1[i1]=n[i];            i1++;        }        else{             while(i1!=0)            {               n1[i1]=\0;               if(strcmp(n1,"auto")==0||strcmp(n1,"int")==0||strcmp(n1,"double")==0||strcmp(n1,"long")==0||strcmp(n1,"char")==0||strcmp(n1,"float")==0||strcmp(n1,"short")==0||strcmp(n1,"signed")==0||strcmp(n1,"unsigned")==0||strcmp(n1,"struct")==0||strcmp(n1,"union")==0||strcmp(n1,"enum")==0||strcmp(n1,"static")==0||strcmp(n1,"switch")==0||strcmp(n1,"case")==0||strcmp(n1,"default")==0                         ||strcmp(n1,"break")==0||strcmp(n1,"register")==0||strcmp(n1,"const")==0||strcmp(n1,"volatile")==0||strcmp(n1,"typedef")==0||strcmp(n1,"extern")==0||strcmp(n1,"return")==0||strcmp(n1,"void")==0||strcmp(n1,"continue")==0||strcmp(n1,"do")==0||strcmp(n1,"while ")==0||strcmp(n1,"if")==0||strcmp(n1,"else")==0||strcmp(n1,"for")==0||strcmp(n1,"goto")==0||strcmp(n1,"sizeof")==0)             {               n1[i1]=);               printf("(1,");               puts(n1);               i1=0;               memset(n1,0,100);             }              else             {               n1[i1]=);               printf("(10,");               puts(n1);               i1=0;               memset(n1,0,100);             }           }          if((j>48)&& (j<57))         {             n2[i2]=n[i];             i2++;         }         else{               if((int) n[i-1]>48 && (int) n[i-1]<57)               {               n2[i2]=);               printf("(11,");               puts(n2);               i2=0;               memset(n2,0,100);               }         if(j==42||j==43||j==45||j==47||j==61||j==62||j==60)        {            if((int) n[i+1]==61)            {             switch (j)             {               case 60:                      printf("(21,%c=)",n[i]);                      printf("\n");                      break ;               case 62:                      printf("(24,%c=)",n[i]);                      printf("\n");                      break;              default :                      printf("(非法字符,%c)",n[i]);                      printf("\n");                      break;             }             i=i+1;            }            else            {             switch (j)             {               case 42:                      printf("(15,%c)",n[i]);                      printf("\n");                      break ;               case 43:                      printf("(13,%c)",n[i]);                      printf("\n");                      break;               case 45:                      printf("(14,%c)",n[i]);                      printf("\n");                      break;               case 60:                      printf("(20,%c)",n[i]);                      printf("\n");                      break;               case 61:                      printf("(25,%c)",n[i]);                      printf("\n");                      break;               case 62:                      printf("(24,%c)",n[i]);                      printf("\n");                      break;               default :                      printf("(非法字符,%c)",n[i]);                      printf("\n");                      break;             }            }        }        else if(j==32)        {        }        else if(j==33||j==44||j==46||j==58||j==59||j==63||j==44)        {            switch (j)             {               case 59:                      printf("(26,%c)",n[i]);                      printf("\n");                      break ;               default :                      printf("(非法字符,%c)",n[i]);                      printf("\n");                      break;             }        }        else if(j==34||j==35||j==38||j==39||j==40||j==41||j==123||j==124||j==125||j==126)        {            switch (j)             {               case 40:                      printf("(27,%c)",n[i]);                      printf("\n");                      break ;               case 41:                      printf("(28,%c)",n[i]);                      printf("\n");                      break ;               case 35:                      printf("(0,%c)",n[i]);                      printf("\n");                      break ;               default :                      printf("(非法字符,%c)",n[i]);                      printf("\n");                      break;             }        }        else        {            break;        }     }    }  }}

 

技术分享

 

技术分享

 技术分享

文法规则写法