Skip to content
Official PYQ · 1992

GATE CS 1992 Q02 — Parsing (LL, LR)

Explain with AI

For a context free grammar, FOLLOW(A) is the set of terminals that can appear immediately to the right of non-terminal AA in some "sentential" form. We define two sets LFOLLOW(A) and RFOLLOW(A) by replacing the word "sentential" by "left sentential" and "right most sentential" respectively in the definition of FOLLOW (A).

Select all correct options
View worked solution

Answer: A;B

To understand the relationship between FOLLOW(A)FOLLOW(A), LFOLLOW(A)LFOLLOW(A), and RFOLLOW(A)RFOLLOW(A), let us analyze how terminals can appear to the right of a non-terminal AA under different derivations.

1. FOLLOW(A)FOLLOW(A) vs LFOLLOW(A)LFOLLOW(A) (May be different):

Consider the grammar:
S→ABS \to A B
A→aA \to a
B→bB \to b

  • All sentential forms: S⇒AB⇒Ab⇒abS \Rightarrow A B \Rightarrow A b \Rightarrow a b. Here, bb appears immediately to the right of AA in the sentential form AbA b. Thus, b∈FOLLOW(A)b \in FOLLOW(A).
  • Left-sentential forms: In a leftmost derivation, we must expand the leftmost non-terminal first: S⇒lmAB⇒lmaB⇒lmabS \Rightarrow_{lm} A B \Rightarrow_{lm} a B \Rightarrow_{lm} a b. The only left-sentential forms are ABA B and aBa B. In none of these does a terminal appear immediately to the right of AA. Thus, b∉LFOLLOW(A)b \notin LFOLLOW(A).

Since FOLLOW(A)≠LFOLLOW(A)FOLLOW(A) \neq LFOLLOW(A) in this case, Option A is correct.

2. FOLLOW(A)FOLLOW(A) vs RFOLLOW(A)RFOLLOW(A) (Always the same):

In any derivation where a terminal aa appears immediately to the right of AA (i.e., S⇒∗αAaβS \Rightarrow^* \alpha A a \beta), the symbols to the right of AA must eventually derive terminals. In a rightmost derivation, all non-terminals to the right of AA are expanded to terminals before AA itself is expanded. Thus, any sentential form of the type αAaβ\alpha A a \beta can always be reached via a rightmost derivation. Therefore, RFOLLOW(A)=FOLLOW(A)RFOLLOW(A) = FOLLOW(A) always holds, making Option B correct.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Parsing (LL, LR) questions