Consider two grammars πΊ1 and πΊ2 with the production rules given below: πΊ1:β¦
2025
Consider two grammars πΊ1 and πΊ2 with the production rules given below:
Β Β Β Β πΊ1: π β ππ πΈ π‘βππ π | ππ πΈ π‘βππ π πππ π π | π
Β Β Β Β Β Β Β Β Β Β πΈ β π
Β Β Β Β πΊ2: π β ππ πΈ π‘βππ π | π
Β Β Β Β Β Β Β Β Β Β Β π β ππ πΈ π‘βππ π πππ π π | π
Β Β Β Β Β Β Β Β Β Β Β πΈ βΒ π
where ππ,π‘βππ,πππ π, π, π, π are the terminals. Which of the following option(s) is/are CORRECT?
- A.
πΊ1 is not πΏπΏ(1) and πΊ2 is πΏπΏ(1).
- B.
πΊ1 is πΏπΏ(1) and πΊ2 is not πΏπΏ(1).
- C.
πΊ1 and πΊ2 are not πΏπΏ(1).
- D.
πΊ1 and πΊ2 are ambiguous.
Attempted by 107 students.
Show answer & explanation
Correct answer: C, D
C: Both not LL(1)
Gβ: Common prefix if E then S in two S-productions β FIRST overlap on if.
Gβ: S-productions if E then S and M (FIRST(M) includes if) β overlap on if.
D: Both ambiguous
Gβ: Classic dangling else (e.g., if b then if b then a else a has 2 parse trees).
Gβ: Similar recursive structure allows multiple if-else pairings for same string.
A video solution is available for this question β log in and enroll to watch it.