Find First and Follow of a Grammar C Program

C Program To Find First and Follow of a Grammar

Learn How To Find First and Follow of a Grammar in C Programming. There are two different C programs to find first and follow of Non-Terminals in a given Grammar.


The first of a grammar can be written using structures as well. Here, we have used Array data structure to calculate first and follow in C programming.

Must Read: Difference Between Compiler and Interpreter

What is First and Follow?

The First and Follow Sets are used in compiler designing process. The First set is used in LL parsers which are top – down parsers that read or interpret from Left to Right. The Follow set is used in LR parsers which are bottom – up parsers that read or interpret from Left to Right.

The LL parsers use leftmost derivations whereas the LR parsers use rightmost derivations. A predictive parser is constructed using first and follow sets that are associated with Grammar G.

Must Read: C Program For Recursive Descent Parsing


C Program To Find First of a Given Grammar using Array

Output

C Program To Find First and Follow of a Grammar using Array

C Program To Find Follow of a Grammar using Array

Output

C Program To Find Follow of a Grammar using Array

If you have any compilation error or doubts in this First and Follow program in C Language, let us know about it in the comment section below.

Tushar Soni

I am Tushar Soni, Co - Founder of CodingAlpha. I am a computer science student from India and passionate about Web Development and Programming. Connect with me on Facebook | LinkedIn | Google Plus

7 thoughts on “Find First and Follow of a Grammar C Program

  • October 9, 2016 at 4:41 pm
    Permalink

    Bottom-Up and To-Down Parsers uses follow and first functions to make a parsing tree from a given grammar G.

    Reply
  • October 9, 2016 at 5:29 pm
    Permalink

    This code finally works for computation of follow and first for designing my compiler.

    Reply
  • October 9, 2016 at 5:33 pm
    Permalink

    A switch case or a while loop would be much easier to understand. Do while confuses a lot.

    Reply
  • October 9, 2016 at 8:57 pm
    Permalink

    You can also use Extended Backus Naur Form to automatically calculate Follow and First of a Grammar.

    Reply
  • February 14, 2017 at 12:20 pm
    Permalink

    This program for follow is not working . It gives segmentation fault . Please Help. My code is similar to you . Input is
    8
    E=TA
    A=+TA
    A=$
    T=FB
    B=*FB
    B=$
    F=a
    F=(E)

    First I give E as input to find follow and then A it gives correct output for E but gives segementaton fault for A

    Reply
  • March 23, 2017 at 11:39 pm
    Permalink

    This is one of the best explanations of parsing with first and follow set program in c programming language. Thank you so much CodingAlpha team.

    Reply
  • April 20, 2017 at 10:17 am
    Permalink

    If we use the following for loop for(count = 1; count <= limit; count++) in this first of grammar c program, will it make any difference?

    Reply

Join The Discussion