25 25 votes Consider the following statements. $S_1:$ Every $\text{SLR(1)}$ grammar is unambiguous but there are certain unambiguous grammars that are not $\text{SLR(1)}$. $S_2:$ For any context-free grammar, there is a parser that takes at most $O(n^3)$ time to parse a string of length $n$. Which one of the following options is correct? $S_1$ is true and $S_2$ is false $S_1$ is false and $S_2$ is true $S_1$ is true and $S_2$ is true $S_1$ is false and $S_2$ is false Compiler Design gatecse-2021-set1 compiler-design lr-parser one-mark + – Arjun 16.4k views answer comment Share Follow Print See all 8 Comments 8 8 Comments reply Show 5 previous comments Kiyoshi commented Jan 22, 2022 reply Follow flag Thanks @palashbehra5 0 0 replyShare KaranBais commented Feb 7, 2024 reply Follow flag For S2 is there no need to specify that the CFG is not ambiguous? 0 0 replyShare js__ commented Dec 1, 2025 reply Follow flag CYK is a Bottom-Up, Chart-Based, Dynamic-Programming Parser.Bottom-up → It builds larger structures from smaller substrings.Parser for Context-Free Grammars (CFGs).Requires grammar in CNF (Chomsky Normal Form).A membership parser → checks if a string belongs to the language. 2 2 replyShare Please log in or register to add a comment.
Best answer 41 41 votes Correct option is C. Both statements are correct. An unambiguous grammar is not necessarily $\text{SLR}(1).$ But every $\text{SLR}(1)$ grammar is unambiguous. We do have $\text{CYK}$ algorithm which takes $O(n^3)$ time (assuming size of the context-free grammar $|G|$ to be a constant) to parse any string of length $n$ using a context-free grammar $G.$ Ankur29 answered Feb 18, 2021 • edited May 1, 2021 by gatecse Ankur29 comment Share Follow See all 9 Comments 9 9 Comments reply amitkumar.chottu58 commented Feb 20, 2021 reply Follow flag for any cfg there is a parser, isn't this phrase is wrong because there is some ambiguous grammar for which no parsing algorithm exists. 0 0 replyShare amitkumar.chottu58 commented Feb 28, 2021 reply Follow flag @Ankur29 @Arjun in second statement its saying for any cfg,there is a parser, isnt this phrase wrong bcz we cant have parser for any grammar,coz grammar could be ambiguous. 0 0 replyShare Arjun commented Jun 12, 2021 reply Follow flag Does CYK algorithm work only for unambiguous grammar? 1 1 replyShare Vishal_kumar98 commented Nov 20, 2021 reply Follow flag That too when the grammar is in the form of CNF. 0 0 replyShare Pranavpurkar commented Dec 14, 2021 reply Follow flag @amitkumar.chottu58 Operator precedence (bottom up parser) can be applied on both ambiguous and unambiguous grammars. 2 2 replyShare robinofautumn commented Jan 25, 2023 i edited by robinofautumn Jan 25, 2023 reply Follow flag @Arjun @GO Classesi have a doubt in: For any context-free grammar, there is a parser that takes at most O(n^3) time to parse a string of length n.CYK algo is a membership algo→ it only checks if a string can be generated from a given grammar, but it has asked for parsing, we have to generate a string.so, can we use the term parsing and membership interchangeably? 1 1 replyShare Lovepreet sharma commented Jan 15, 2025 reply Follow flag Same question 0 0 replyShare Aryan_Sapra commented Jan 25, 2025 reply Follow flag The LR family of parsing methods only works with unambiguous grammars. Operator precedence is not from LR family. 0 0 replyShare S_Sandeep commented Jun 15 reply Follow flag @robinofautumn Checking if a string is generated by a grammar is the same as parsing right? 0 0 replyShare Please log in or register to add a comment.
3 3 votes ANS IS C, BOTH ARE TRUE STMT 1:- NO AMBIGUOUS GRAMMAR IS LR(k) STMT 2:- READ ABOUT CYK ALGORITHM https://en.wikipedia.org/wiki/CYK_algorithm Harshq answered Feb 27, 2021 Harshq comment Share Follow 0 reply Please log in or register to add a comment.