39,651 views
81 81 votes

Which of the following suffices to convert an arbitrary CFG to an LL(1) grammar?

  1. Removing left recursion alone
  2. Factoring the grammar alone
  3. Removing left recursion and factoring the grammar
  4. None of the above

11 Answers

Best answer
92 92 votes

$LL(1)$ parser is top down parser.

For top down parsers, the grammar should be unambiguous, deterministic and should not be left recursive.

All the $3$ conditions must be satisfied for $LL(1)$ parsers.

Now, even if all $3$ conditions are satisfied we cannot get an $LL(1)$ or even $LL(k)$ (for any $k$) grammar for even a $DCFG. $This is because there are $DCFLs $ which does not have an $LL(k)$ grammar (see ref below). On the other hand for any $DCFL,$ we can always have an $LR(1)$ grammar.

http://mathoverflow.net/questions/31733/can-i-have-an-ll-grammar-for-every-deterministic-context-free-language

So, Option $D$ is correct.

• edited by
14 14 votes
LL(1) properties:

1. Un ambiguous

2. Not left recursive

3. Deterministic

I think C does not make the CFG unambiguous all the time.
8 8 votes

D. Removing left recursion and factoring the grammar do not suffice to convert an arbitrary CFG to LL(1) grammar.

6 6 votes
Yes Option D is correct.

But even if the grammar satisfies all three conditions: non left recursive, deterministic and unambiguous even then it may not be LL(1).

E.g.

S -> aAa / ^

A -> abS / ^

Here ^ is epsilon.

This grammar satisfies all three conditions but still not LL(1) because predict set for S -> aAa and S -> ^  is not disjoint.
4 4 votes
Answer is d . Removing left recursion and left factoring is necessary but not sufficent condition for LL(1)
Answer:
Position:
Show:

Related questions

33 33 votes
4 answers 4 answers
16.8k
16.8k views
Kathleen asked Sep 16, 2014
16,761 views
Assume that the SLR parser for a grammar G has $n_1$ states and the LALR parser for G has $n_2$ states. The relationship between $n_1$ and $n_2$ is$n_1$ is necessarily le...
61 61 votes
5 answers 5 answers
14.9k
14.9k views
Kathleen asked Sep 17, 2014
14,869 views
A program consists of two modules executed sequentially. Let $f_1(t)$ and $f_2(t)$ respectively denote the probability density functions of time taken to execute the two ...
50 50 votes
3 answers 3 answers
30.3k
30.3k views
Kathleen asked Sep 17, 2014
30,302 views
Consider the grammar shown below. $S \rightarrow C \ C$$C \rightarrow c \ C \mid d$This grammar isLL(1)SLR(1) but not LL(1)LALR(1) but not SLR(1)LR(I) but not LALR(1)
44 44 votes
4 answers 4 answers
20.8k
20.8k views
Kathleen asked Sep 17, 2014
20,764 views
Consider the grammar shown below$S \rightarrow i E t S S’ \mid a$$S’ \rightarrow e S \mid \epsilon$$E \rightarrow b$In the predictive parse table, $M,$ of this grammar, t...