• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
June 24, 2022 |10.8K Views

First and Follow in Compiler Design

  Share   Like
Description
Discussion

In this video, we will be covering what are first() & follow() in compiler design in detail In compiler design, the sets of first and follow are required by the parser to identify and apply the appropriate production rules at the proper position. In Top-Down parsers, the sets of FIRST and FOLLOW help in determining which production is to be applied and when. Backtracking is needed in many cases of Syntax Analysis phase, which is very complicated to implement practically. Problem of Backtracking can be resolved by finding out the FIRST() set. In Bottom-Down parsers, the sets of FIRST and FOLLOW help in identifying when the reduction should be applied. Backtracking is needed in many cases of the Syntax Analysis phase, which is very complicated to implement practically. Problem of Backtracking can be resolved by finding out FIRST() set. If the first symbol of the production in RHS is: a terminal (including NULL), then include it directly in FIRST() set a non-terminal, then call the FIRST() function on that non-terminal and include those elements in the FIRST() set The functions FOLLOW() and FIRST() are both involved while calculating FOLLOW() Set of any given Non-Terminal. If following any variable you have: 1) Terminal: Then write it as it is, in the follow set 2) Non-Terminal: Then write the elements of its FIRST() set 3) Last element of RHS: Then write FOLLOW() of LHS FOLLOW() set will never contain NULL. FOLLOW() of starting symbol will at least contain $. First & Follow in Compiler design: https://www.geeksforgeeks.org/why-first-and-follow-in-compiler-design/