Consider the grammar:

S β†’ aSbS | bSaS | πœ–

  • Show that this grammar is ambiguous by constructing two different left most derivations for the sentence abab.
  • Construct the corresponding right most derivations for abab.
  • Construct the corresponding parse tree for abab.
  • What language does this grammar generate?
Added 2 years ago
Active
Viewed 1474
Ans

 

Right most derivations for abab:

Case 1:

S β†’ aSbS

  β†’ aSb             (applying S β†’ πœ–) 

  β†’ abSaSb       (applying S β†’ bSaS)

  β†’ abSab         (applying S β†’ πœ–)

  β†’ abab            (applying S β†’ πœ–)  

Case 2:

S β†’ aSbS

  β†’ aSbaSbS     (applying S β†’ aSbS)

  β†’ aSbaSb        (applying S β†’ πœ–)

  β†’ aSbab         (applying S β†’ πœ–)

  β†’ abab           (applying S β†’ πœ–)

 



Related Questions