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 Show 6 previous comments 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.