edited by
2,522 views
8 votes
8 votes

As I know that LL(1) and LALR(1) grammars are incomperable ,but if a grammar is LL(1) then, it may be LALR(1) if the following conditions hold.

1.A ε-free LL(1) grammar is also a SLR(1) grammar and thus LALR(1) too.

2. A LL(1) grammar with symbols that have both empty and non-empty derivations is also a LALR(1) grammar.

3. A LL(1) grammar with symbols that have only the empty derivation may or may not be LALR(1).

can anyone explain each point with example. and what is this "non-empty derivation/empty derivation"?

edited by

1 Answer

4 votes
4 votes

1.A ε-free LL(1) grammar is also a SLR(1) grammar and thus LALR(1) too.

Since the grammar is LL(1), we can conclude that it is unambiguous, non-left recursive and left factored. 

Since it is unambiguous, therefore we will never reach a point while parsing where we’ll have 2 choices for reduction, therefore RR conflict of SLR(1) not possible.

Now we have to think that how will ε-free help us in avoiding SR conflict.

Since it is ε-free we’ll never reach a point where we are confused that whether we need to shift the terminal symbol or reduce ε to the non-terminal.

 

2. A LL(1) grammar with symbols that have both empty and non-empty derivations is also a LALR(1) grammar.

All logic stays the same as done in the 1st statement. Just one additional point it that here we can look ahead and make a decision whether to shift or reduce. Hence LALR(1).

 

3. A LL(1) grammar with symbols that have only the empty derivation may or may not be LALR(1).

Can anyone please give an example of such grammar. Will such grammar make any sense?

edited by

Related questions

2 votes
2 votes
1 answer
1
sripo asked Nov 10, 2018
3,238 views
Can you give an example which is not LL(1) but is CLR(1)
8 votes
8 votes
3 answers
2
Parshu gate asked Nov 13, 2017
15,433 views
Suppose we are given a grammar and asked to find the type of that grammar , what is the algorithm which needs to be followed for each of them? LL(1), OR LR(0) , OR CLR(1...