The grammar S → aSa | bS | c is
(A) LL(1) but not LR(1)
(B) LR(1)but not LR(1)
(C) Both LL(1)and LR(1)
(D) Neither LL(1)nor LR(1)
Answer: (C)
Explanation:
First(aSa) = a First(bS) = b First(c) = c All are mutually disjoint i.e no common terminal between them, the given grammar is LL(1). As the grammar is LL(1) so it will also be LR(1) as LR parsers are more powerful then LL(1) parsers. and all LL(1) grammar are also LR(1) So option C is correct.
Below are more details.
A grammar is LL(1) if it is possible to choose the next production by looking at only the next token in the input string.
Formally, grammar G is LL(1) if and only if
For all productions A → α1 | α2 | ... | αn,
First(αi) ∩ First(αj) = ∅, 1 ≤ i,j ≤ n, i ≠ j.
For every non-terminal A such that First(A) contains ε,
First(A) ∩ Follow(A) = ∅
Source: https://s3-ap-southeast-1.amazonaws.com/erbuc/files/4147_870334aa-9922-4f78-9c2c-713e7a7f0d53.pdf
Quiz of this Question
Recommended Posts:
- GATE | GATE CS 2010 | Question 43
- GATE | GATE CS 2010 | Question 44
- GATE | GATE CS 2010 | Question 45
- GATE | GATE CS 2010 | Question 65
- GATE | GATE CS 2010 | Question 65
- GATE | GATE CS 2010 | Question 48
- GATE | GATE CS 2010 | Question 42
- GATE | GATE CS 2010 | Question 2
- GATE | GATE CS 2010 | Question 39
- GATE | GATE CS 2010 | Question 40
- GATE | GATE CS 2010 | Question 65
- GATE | GATE CS 2010 | Question 49
- GATE | GATE CS 2010 | Question 55
- GATE | GATE CS 2010 | Question 56
- GATE | GATE CS 2010 | Question 57
- GATE | GATE CS 2010 | Question 58
- GATE | GATE CS 2010 | Question 59
- GATE | GATE CS 2010 | Question 60
- GATE | GATE CS 2010 | Question 61
- GATE | GATE CS 2010 | Question 62

