How To Implement Follow Of An Expression in C



How To Implement Follow Of An Expression in C :-









1:  #include<stdio.h>  

2:  #include<string.h>
3:  int n,m=0,p,i=0,j=0;
4:  char a[10][10],f[10];
5:  void follow(char c);
6:  void first(char c);
7:  int main()
8:  {
9:       int i,z;
10:       char c,ch;
11:       printf("Enter the no.of productions:");
12:       scanf("%d",&n);
13:       printf("Enter the productions(epsilon=$):\n");
14:       for(i=0;i<n;i++)
15:            scanf("%s%c",a[i],&ch);
16:       do
17:       {
18:            m=0;
19:            printf("Enter the element whose FOLLOW is to be found:");
20:            scanf("%c",&c);
21:            follow(c);
22:            printf("FOLLOW(%c) = { ",c);
23:            for(i=0;i<m;i++)
24:                 printf("%c ",f[i]);
25:            printf(" }\n");
26:            printf("Do you want to continue(0/1)?");
27:            scanf("%d%c",&z,&ch);
28:       }
29:       while(z==1);
30:  }
31:  void follow(char c)
32:  {
33:       if(a[0][0]==c)f[m++]='$';
34:       for(i=0;i<n;i++)
35:       {
36:            for(j=2;j<strlen(a[i]);j++)
37:            {
38:                 if(a[i][j]==c)
39:                 {
40:                      if(a[i][j+1]!='\0')first(a[i][j+1]);
41:                      if(a[i][j+1]=='\0'&&c!=a[i][0])
42:                           follow(a[i][0]);
43:                 }
44:            }
45:       }
46:  }
47:  void first(char c)
48:  {
49:     int k;
50:           if(!(isupper(c)))f[m++]=c;
51:           for(k=0;k<n;k++)
52:           {
53:           if(a[k][0]==c)
54:           {
55:           if(a[k][2]=='$') follow(a[i][0]);
56:           else if(islower(a[k][2]))f[m++]=a[k][2];
57:           else first(a[k][2]);
58:           }
59:           }
60:  }

Comments

Popular posts from this blog

Listing/Delisting of an article in to an Assortment in SAP SCM Retail

How To Install LEX and YACC in Linux or Ubuntu

How to Create Live Search In Html Using Ajax Ad PhP - Google Live Search / Instant Search Code And Example