-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfir.c
47 lines (45 loc) · 901 Bytes
/
fir.c
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
#include<stdio.h>
#include<ctype.h>
void FIRST(char);
int count,n=0;
char prodn[10][10],first[10];
int main()
{
int i,choice;
char c,ch;
printf("No of productions:");
scanf("%d",&count);
printf("\nEnter %d productions epsilon =$:\n\n",count);
for(i=0;i<count;i++)
{
scanf("%s%c",prodn[i],&ch);
// printf("char=%c",ch);
}
do{
n=0;
printf("\nEnter element to find First Funciton of:");
scanf("%c",&c);
FIRST(c);
printf("\n FIRST(%c)={",c);
for(i=0;i<n;i++)
printf("%c",first[i]);
printf("}\n");
printf("press 1 to continue");
scanf("%d%c",&choice,&ch);
}
while(choice==1);
}
void FIRST(char c)
{
int j;
if(!(isupper(c)))first[n++]=c;
for(j=0;j<count;j++)
{
if(prodn[j][0]==c)
{
if(prodn[j][2]=='$') first[n++]='$';
else if(islower(prodn[j][2])) first[n++]=prodn[j][2];
else FIRST(prodn[j][2]);
}
}
}