Header Ads Widget

Ambiguity

Ambiguity

A grammar is said to be ambiguous if there exists more than one leftmost derivation or more than one rightmost derivative or more than one parse tree for the given input string. If the grammar is not ambiguous then it is called unambiguous.

Example:

  1. S = aSb | SS  
  2. S = ∈  

For the string aabb, the above grammar generates two parse trees:

Ambiguity Ambiguity 1

If the grammar has ambiguity then it is not good for a compiler construction. No method can automatically detect and remove the ambiguity but you can remove ambiguity by re-writing the whole grammar without ambiguity.

Post a Comment

0 Comments