26 26 votes Remove left-recursion from the following grammar: $S \rightarrow Sa \mid Sb \mid a \mid b$Consider the following grammar: $S \rightarrow aSbS\mid bSaS \mid \epsilon$ Construct all possible parse trees for the string abab. Is the grammar ambiguous? Compiler Design gatecse-2001 compiler-design grammar descriptive + – Kathleen 6.1k views answer comment Share Follow Print See 1 comment 1 1 comment reply arpit.jha commented Aug 20, 2024 reply Follow flag The grammar in A is making Language : (a+b)+ positive closure 0 0 replyShare Please log in or register to add a comment.
Best answer 44 44 votes $S \rightarrow aS'\mid bS'$ $S' \rightarrow aS' \mid bS' \mid \epsilon$ $S \rightarrow aSbS \rightarrow abS \rightarrow abaSbS \rightarrow ababS \rightarrow abab$ $S \rightarrow aSbS \rightarrow abSaSbS \rightarrow abaSbS \rightarrow ababS \rightarrow abab$ The above two derivations corresponds to two different parse trees and hence the grammar is ambiguous. Pooja Palod answered Aug 5, 2015 • edited Jan 1, 2018 by joshi_nitish Pooja Palod comment Share Follow See all 3 Comments 3 3 Comments reply Chhotu commented Jan 1, 2018 reply Follow flag Two derivation so it is ambiguous Gammer is ambiguous. But above statement requires Refer --> Option(A) for https://gateoverflow.in/711/gate2001-1-18 ping @kenzou 0 0 replyShare joshi_nitish commented Jan 1, 2018 reply Follow flag @Chhotu, its edited now. 0 0 replyShare mohithjagalmohanan commented Jan 30, 2020 reply Follow flag Or the answer can be simplified as: S$\rightarrow$aS|bS|a|b 2 2 replyShare Please log in or register to add a comment.
6 6 votes Remove left-recursion from the following grammar: a) so by the basic rule==> b) left side parsing: S->aSbS->abS->abaSbS>ababS->abab right side parsing:S->aSbS->abSaSbS->abaSbS->ababS->abab so it is ambiguous jaiganeshcse94 answered Aug 10, 2016 jaiganeshcse94 comment Share Follow See all 2 Comments 2 2 Comments reply Franz Kafka commented Nov 16, 2024 reply Follow flag I'm not able to see what's written here.Is it just me ? 0 0 replyShare razvardhan commented Dec 31, 2024 reply Follow flag TURN OFF THE DARK MODE 1 1 replyShare Please log in or register to add a comment.
2 2 votes Grammar is Ambiguous Surya013 answered Jul 13, 2025 Surya013 comment Share Follow 0 reply Please log in or register to add a comment.