Learn and practice Aptitude questions and answers with explanation for interview, competitive exam (Pariksha Corner )

Wednesday, January 22, 2020

The grammar S -> aSa | bS | c is

The grammar S -> aSa | bS | c is
ALL ( 1 ) but not LR ( 1 )
BLR ( 1 ) but not LL ( 1 )
CBoth LL ( 1 ) and LR ( 1 )
Dneither LL ( 1 ) nor LR ( 1 ).

Answer : Both LL ( 1 ) and LR ( 1 )

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 ? a1 | a2 | ... | an,
First(ai) n First(aj) = Ø, 1 = i,j = n, i ? j.
For every non-terminal A such that First(A) contains e,
First(A) n Follow(A) = Ø

Nithin K
answered Dec 7 '2016 at 20:38

All Comments

Post your answers here:

Post

Post your comments here:

Post

Categories