For a grammar

  • A string is ambiguous if it has more than one leftmost derivation or parse tree.
  • The grammar is ambiguous if it generates at least one ambiguous string

Info

A context-free language can have both ambiguous and non-ambiguous representation. Though some languages are inherently ambiguous and have no non-ambiguous representation.

For example, the grammar is ambiguous. Given , we can parse it either as or ambuguous grammar example.webp

Common Sources of Ambiguity