Consider the following context-free grammar where the set of terminals is {a, b, c, d, f}. S → d a T | R f T → a S | b a T | ϵ R → c a T R | ϵ The following is a partially-filled LL(1) parsing table. Which one of the following choices represents the correct combination for the numbered cells in the parsing table ("blank" denotes that the corresponding cell is empty)?
Consider the following context-free grammar where the set of terminals is {a, b, c, d, f}. S → d a T | R f T → a S | b a T | ϵ R → c a T R | ϵ The following is a partially-filled LL(1) parsing table. Which one of the following choices represents the correct combination for the numbered cells in the parsing table ("blank" denotes that the corresponding cell is empty)? Correct Answer (1) S → R f (2) S → R f (3) T → ϵ (4) T → ϵ
Answer: Option 1
Explanation:
For LL1 parsing we need to calculate first and follow set for all Non-terminals in the grammar.
|
Non-Terminal |
First Set |
|
S |
{d, c, f} |
|
T |
(a, b, ϵ} |
|
R |
{c, ϵ} |
|
Non-Terminal |
Follow Set |
|
S |
{c, f, $} |
|
T |
{c, f, $} |
|
R |
{f} |
at 1: S->Rf will be stored.
at 2: again S-> Rf will be stored.
Because in first set(Rf) = c,f
at 3:T-> ϵ will be stored.
at 4: again T-> ϵ will be stored.
Because first set(T) = {a, b, ϵ}, In the column for 'a' and 'b' corresponding matching Rules are mentioned But first set also contains ϵ then ϵ-corresponding Rules will be filled according to follow set(T) = { c, f, $} in the LL1 table.