53 53 votes $A$ CFG $G$ is given with the following productions where $S$ is the start symbol, $A$ is a non-terminal and a and b are terminals.$S → aS \mid A$$A → aAb \mid bAa \mid \epsilon$For the string "$aabbaab$" how many steps are required to derive the string and how many parse trees are there?$6$ and $1$$6$ and $2$$7$ and $2$$4$ and $2$ Compiler Design gateit-2008 compiler-design parsing normal + – Ishrat Jahan 12.6k views answer comment Share Follow Print See all 6 Comments 6 6 Comments reply Show 3 previous comments panipuri commented Jan 16 reply Follow flag @nithin_9 small addition:Ambiguous grammar can be easily detected if it is both left and right recursive + it derives $pure\ terminal$ production also$S \rightarrow SS \ |\ a$ is ambiguous if grammar is just left and right recursive then it need not be ambiguous 0 0 replyShare dhawalphalak35 commented Aug 11 reply Follow flag @panipuri This is a major misconception. The only reliable test for ambiguity is whether some string generated by the grammar has more than one parse tree (or equivalently, more than one LMD/RMD). 0 0 replyShare panipuri commented Aug 11 reply Follow flag @dhawalphalak35okay give me a Grammar which is in the form i mentioned but is NON-AMBIGUOUS 0 0 replyShare Please log in or register to add a comment.
Best answer 63 63 votes $S\underset{1}{ \rightarrow} aS$ $\quad \underset{2}{\rightarrow} aA$ $ \quad \underset{3}{\rightarrow} aaAb$ $\quad \underset{4}{ \rightarrow} aabAab$ $\quad \underset{5}{ \rightarrow} aabbAaab$ $\quad \underset{6}{ \rightarrow} aabbaab$ Thus $6$ steps are needed and only one way to derive the string so only one parse tree. Correct Answer: $A$ Shreyans Dhankhar answered Oct 29, 2014 • edited Apr 30, 2019 by Naveen Kumar 3 Shreyans Dhankhar comment Share Follow See all 7 Comments 7 7 Comments reply Show 4 previous comments SomeEarth commented Jan 15, 2021 reply Follow flag if we look at the Non Terminal, A it is very much clear that we can produce only even length strings out of it. That means our given string which is $'aabbaab'$ (length =7) can not be derived by production $S \rightarrow A$ or solely with $A$. Hence we are bound to start our derivation with production: $S \rightarrow aS$. 1 1 replyShare LIKITH P commented Aug 20, 2021 reply Follow flag Grammar is unambiguous.So only one parse tree is present for a string. 9 9 replyShare Pranavpurkar commented Nov 28, 2022 reply Follow flag LIKITH P nice :) 1 1 replyShare Please log in or register to add a comment.
0 0 votes As the https://gateoverflow.in/3393/gate-it-2008-question-79?show=3398#a3398 answer as he did top-down if also did bottom-up we will use same no.of reductions to make it to S NOW_OR_NEVER answered May 21 NOW_OR_NEVER comment Share Follow 0 reply Please log in or register to add a comment.