-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfollowSet.cpp
More file actions
62 lines (60 loc) · 1.75 KB
/
followSet.cpp
File metadata and controls
62 lines (60 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include<stdio.h>
#include <cctype>
#include <conio.h>
#include <cstring>
int main()
{
int np,i,j,k,temp;
char prods[10][10],follow[10][10],Imad[10][10],f;
printf("enter no. of productions\n");
scanf("%d",&np);
printf("enter grammar\n");
for(i=0;i<np;i++)
{
scanf("%s",&prods[i]);
}
for(i=0; i<np; i++)
{
if(i==0)
{
printf("Follow(%c) = $\n",prods[0][0]);//Rule1
}
for(j=3;prods[i][j]!='\0';j++)
{
int temp2=j;
//Rule-2: production A->xBb then everything in first(b) is in follow(B)
if(prods[i][j] >= 'A' && prods[i][j] <= 'Z')
{
if((strlen(prods[i])-1)==j)
{
printf("Follow(%c)=Follow(%c)\n",prods[i][j],prods[i][0]);
}
temp=i;
f=prods[i][j];
if(!isupper(prods[i][j+1])&&(prods[i][j+1]!='\0'))
printf("Follow(%c)=%c\n",f,prods[i][j+1]);
if(isupper(prods[i][j+1]))
{
for(k=0;k<np;k++)
{
if(prods[k][0]==prods[i][j+1])
{
if(!isupper(prods[k][3]))
repeat:
{
printf("Follow(%c)=%c\n",f,prods[k][3]);
}
else
{
i=k;
j=2;
goto repeat;
}
}}}
i=temp;
}
j=temp2;
}
}
getch();
}