Ambiguity
. A Grammar can have more than one parse tree for a string
Consider grammar
string string + string
| string - string
| 0 | 1 | . | 9
. String 9-5+2 has two parse trees
A grammar is said to be an ambiguous grammar if there is some string that it can generate in more than one way (i.e., the string has more than one parse tree or more than one leftmost derivation). A language is inherently ambiguous if it can only be generated by ambiguous grammars.
For example, consider the following grammar:
string string + string
| string - string
| 0 | 1 | . | 9
In this grammar, the string 9-5+2 has two possible parse trees as shown in the next slide. |