0

Show that the following grammar is ambiguous. (To show that a grammar is ambiguous, you must demonstrate that it can generate two parse trees for the same string.) `

`person::= woman|man
    woman::= willma|betty|empty
    man::=fred|barney|empty

below is what I did.
person
  |
woman
  |
willma
  |
woman
  |
betty
  |
woman
  |
empty
----------
person
  |
 man
  |
fred
  |
 man
  |
barney
  |
 man
  |
empty
  • No, sorry, it's wrong. You cannot derive from , according to your grammar, or from . However, you are right in that the grammar is ambiguous for , and one derivation is via the other is via . I'm assuming you want to try to work the solution out for yourself, if you can. – Jeffrey Kegler Mar 15 '15 at 04:54
  • @JeffreyKegler here the change, New Post:_italic_ **bold** `code` ** person / \ woman man | | willma fred | | betty barney | | empty empty** – Sammy Smith Mar 15 '15 at 18:38
  • @Sammy_Smith -- Sorry, I could not follow the format in your new attempt. IIRC, Stackoverflow does not allow the same formatting in comments as in questions. You might try editing your original, adding a note that it is edited. – Jeffrey Kegler Mar 16 '15 at 18:55

1 Answers1

0

empty could be a leaf under both man and woman and is thus ambiguous. It should be a direct child of person.

person::= woman|man|empty
woman::= willma|betty
man::=fred|barney
faester
  • 14,886
  • 5
  • 45
  • 56