81 81 votes Which of the following suffices to convert an arbitrary CFG to an LL(1) grammar? Removing left recursion alone Factoring the grammar alone Removing left recursion and factoring the grammar None of the above Compiler Design gatecse-2003 compiler-design parsing easy + – Kathleen 39.7k views answer comment Share Follow Print See all 4 Comments 4 4 Comments reply rajan commented Oct 12, 2016 reply Follow flag S->Sa/a here to convert into LL(1) need to be remove left recursive for this S->ab/a here to convert LL(1) remove left factoring then if i take a grammer which not having both left recursive and left factoring for example S->AB/a ;A->a,B->epsilon then but still not parse by LL(1) bcz it is ambiguous so for that we have to be fulfill all three condition then we can convert into LL(1) surely so D 8 8 replyShare chauhansunil20th commented Nov 29, 2018 reply Follow flag $S->A | B$ $A-> a$ $B-> a$ The above mentioned grammar has neither left recursion nor common prefixes, still it's not LL(1). (D) is the correct option! 13 13 replyShare Aks9639 commented Mar 15, 2019 reply Follow flag there is nothing so complicated they asked only ; if we take any random CFG then what happens? LL(1) parser not parse all D_CFG like ambiguous and left recursive CFG's etc. so we easily say option ( D ) should be correct. 0 0 replyShare Nitesh Singh 2 commented Jul 18, 2019 reply Follow flag LL(1) parser does not parse left recursive, ambiguous, non-deterministic grammar because they create conflict in parsing table for sure but these are necessary but not sufficient condition because even a DCFG is free from left recursion, ambiguous, non-determinism still for some reason the parsing table may contain conflict, and no matter how much we try, conflicts in LL(1) parsing table can never be removed for some grammars.. 8 8 replyShare Please log in or register to add a comment.
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-languageSo, Option $D$ is correct. monanshi answered Dec 11, 2015 • edited Oct 31, 2025 by Umesh Shelke monanshi comment Share Follow See all 24 Comments 24 24 Comments reply Show 21 previous comments rupesh17 commented Dec 30, 2020 reply Follow flag indra kumar sahu Amcodes Please read this explanation by @arjun sir….. https://gatecse.in/lr-parsing-part-2-language-of-ll-and-lr-grammars/ imp points- language of any LL(k) grammar is guaranteed to be a DCFL. But since language of LL(k) is a strict subset of the language of LL(k+1), for any finite kk, there exist SOME DCFL which cannot be generated by ANY LL(k) grammar. But it cannot generate all DCFLs. LL(1) can generate all regular languages. since regular grammer has right linear grammer(also left linear) Hence LL(1) always deterministic unambiguous CFG---YES Deterministic Unambiguous CFG always LL(1) ---No since it cannot generate all dcfl 5 5 replyShare ankit3009 commented Nov 8, 2021 reply Follow flag So, even if the CFG is unambiguous, left factored, and left recursion is removed, still, we can’t be assured that given CFG is LL(1) grammar because LL(1) can’t parse all possible DCFLs. Please correct if I’m wrong. 1 1 replyShare Pranavpurkar commented Nov 28, 2022 i edited by Pranavpurkar Nov 28, 2022 reply Follow flag @ankit3009It should be $LL(1)$ as all the languages generated by it will be $DCFL$ although it can’t generate all the $DCFL$ because of (LL(k) is a strict subset of the language of LL(k+1), for any finite k, there exist SOME DCFL which cannot be generated by ANY LL(k) grammar).check this -> https://gateoverflow.in/906/gate-cse-2003-question-16?show=389684#c389684 0 0 replyShare Please log in or register to add a comment.
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. Saumya answered Jan 21, 2015 Saumya comment Share Follow 0 reply Please log in or register to add a comment.
8 8 votes D. Removing left recursion and factoring the grammar do not suffice to convert an arbitrary CFG to LL(1) grammar. Vikrant Singh answered Jan 16, 2015 Vikrant Singh comment Share Follow See all 2 Comments 2 2 Comments reply srestha commented Dec 11, 2015 reply Follow flag why not C?Could u give me an example? 0 0 replyShare Subash M commented Jan 28, 2016 reply Follow flag If the Grammar is ambiguous, option C would fail. Removing Left factoring / Left recursion doesn't remove ambiguity in the grammar. 15 15 replyShare Please log in or register to add a comment.
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. Rajendra Dangwal answered Oct 19, 2016 Rajendra Dangwal comment Share Follow See all 6 Comments 6 6 Comments reply Show 3 previous comments Pranavpurkar commented Dec 27, 2022 reply Follow flag @Abhrajyoti00 That’s what i mentioned :) it is clearly not left factored. 1 1 replyShare Abhrajyoti00 commented Dec 27, 2022 reply Follow flag @Pranavpurkar Oh you mean not left factored = not removed left factor? 1 1 replyShare Pranavpurkar commented Dec 27, 2022 reply Follow flag @Abhrajyoti00 Yes! 1 1 replyShare Please log in or register to add a comment.
4 4 votes Answer is d . Removing left recursion and left factoring is necessary but not sufficent condition for LL(1) Dexter answered Apr 14, 2016 Dexter comment Share Follow 0 reply Please log in or register to add a comment.
1 1 vote An ambiguous grammar can't be LL(1). Removing left recursion and factoring the grammar not always guarantees the un-ambiguity of grammar. i.e. Ans (D) Prabhat Kumar Sing 1 answered Jan 7, 2018 Prabhat Kumar Sing 1 comment Share Follow 0 reply Please log in or register to add a comment.