Question: Ambiguous Grammars Some programming languages have if expressions: :: = + | = | * | if then else | | | ( ) Thus

Ambiguous Grammars Some programming languages have if expressions: ::=+|=|*| if then else |||() Thus one can write: (if x =0 then 1 else 10* x )+ y However the grammar above is ambiguous. Show all five parse trees for the string if 1=2 then 3 else 4*5+6 For each one, indicate what the computed result would be. In the next step, Ill ask you to write an unambiguous grammar that accepts the same language. But doing so is tricky. So first, find whats wrong with the following (three)solutions. For each one, indicate if there are false negatives (strings that are not accepted, even though they should be), false positives (strings that are accepted, even though they should not be) or ambiguous parses (strings for which there is more than one parse tree). You must give concrete examples. (Concrete examples have no nonterminals in them.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!