Example 5.10
The grammar in Example 5.4, with productions S → aSb|SS|λ, is ambiguous. The
sentence aabb has the two derivation trees shown in Figure 5.4.
Figure 5.4
Ambiguity is a common feature of natural languages, where it is tolerated
and dealt with in a variety of ways. In programming languages, where there
should be only one interpretation of each statement, ambiguity must be removed
when possible. Often we can achieve this by rewriting the grammar in an
equivalent, unambiguous form.
Example 5.11
Consider the grammar G = (V, T, E, P) with
and productions
Précédent

- 181/532

Suivant