AIM: Write a program to find First and Follow of any given grammar. ALGORITHM: If the first symbol in the R.H.S of the production is a Terminal then it can directly be included in the first set. If the first symbol in the R.H.S of the production is a Non-Terminal, then call the findfirst function again on that Non-Terminal. If the First of the new Non-Terminal contains an epsilon then we have to move to the next symbol of the original production which can again be a Terminal or a Non-Terminal. If a Non-Terminal on the R.H.S. of any production is followed immediately by a Terminal then it can immediately be included in the Follow set of that Non-Terminal. If a Non-Terminal on the R.H.S. of any production is followed immediately by a Non-Terminal, then the First Set of that new Non-Terminal gets included on the follow set of our original Non-Terminal. In case encountered an epsilon i.e. ” # ” then, move on to the next symbol in the production. If reached the end of a production while calculating follow, then the Follow set of that non-terminal will include the Follow set of the Non-Terminal on the L.H.S. of that production. This can easily be implemented by recursion. PROGRAM: #include #include #include void followfirst(char, int, int); void follow(char c); void findfirst(char, int, int); int count, n = 0; char calc_first[10][100]; char calc_follow[10][100]; int m = 0; // Stores the production rules char production[10][10]; char f[10], first[10]; int k; char ck; int e; int main(int argc, char **argv) { int jm = 0; int km = 0; int i, choice; char c, ch; count = 8; printf("Enter no. of production rules: "); scanf("%d",&count); printf("Enter the production rules\n"); for(int k=0;k