fork download
  1. #include<stdio.h>
  2.  
  3. #include<string.h>
  4. typedef struct
  5. {
  6. char key[20];
  7. char val[20];
  8. }rule;
  9.  
  10. int main()
  11. {
  12. int i,j,k,l,m,n,stlen;
  13. char ip[20]={0},st[20]={0},prod[20][20]={{0}};
  14. char temp[10];
  15. int flag;
  16. rule dict[20]={{0},{0}};
  17. // printf("Enter no. of productions:");
  18. n=4;
  19.  
  20. // printf("Enter productions:\n");
  21.  
  22.  
  23. strcpy(dict[0].key,"E");
  24. strcpy(dict[0].val,"E+E");
  25.  
  26. strcpy(dict[1].key,"E");
  27. strcpy(dict[1].val,"E*E");
  28.  
  29. strcpy(dict[2].key,"E");
  30. strcpy(dict[2].val,"a");
  31.  
  32. strcpy(dict[3].key,"E");
  33. strcpy(dict[3].val,"i");
  34.  
  35.  
  36.  
  37.  
  38. // Define key and val pairs!
  39.  
  40. // for(i=0;i<n;i++)
  41. // {
  42. // printf("\n%s",prod[i]);
  43. // printf("\n%c\t%s",dict[i].key,dict[i].val);
  44. // }
  45. strcpy(ip,"i+i*a");
  46. printf("%d \n",strlen(ip));
  47.  
  48. for(i=0,j=0;i<5;i++)
  49. { printf("%s","hey");
  50. st[j]=ip[i];
  51. j++;
  52.  
  53. for(i=0;i<n;i++)
  54. { temp[0]=st[strlen(st)-1];
  55. temp[1]='\0';
  56. flag=1;
  57. if(strcmp(st,dict[i].val)==0 )
  58. {
  59.  
  60.  
  61. st[0]=dict[i].key[0];
  62. st[1]='\0';
  63. st[2]='\0';
  64. flag=0;
  65. printf("%s %s %s \n",st,ip,dict[i].val);
  66. }
  67.  
  68.  
  69. if(strcmp(temp,dict[i].val)==0&& flag!=0)
  70. {
  71. st[2]=dict[i].key[0];
  72. st[3]='\0';
  73. printf("%s %s %s \n",st,ip,dict[i].val);
  74. }
  75.  
  76.  
  77.  
  78.  
  79.  
  80. }
  81.  
  82. }
  83.  
  84.  
  85.  
  86. }
  87.  
  88.  
  89.  
  90.  
Success #stdin #stdout 0s 10320KB
stdin
Standard input is empty
stdout
5 
heyE       i+i*a        i