We say that a grammar is ambiguous if there is a word
for which there is more than one parse tree. This is usually a
bad thing because it entails that there is more than one way to
interpret a word (i.e. it leads to semantical ambiguity).
As an example consider the following alternative grammar for
arithmetical expressions:
We define
where
is given by:
![]() |
![]() |
Each parse tree correspond to a different way to read the expression,
i.e. the first one corresponds to and the second one to
. Depending on which one is chosen an expression like
may evaluate to
or to
. Informally, we agree that
binds
more than
and hence the 2nd reading is the intended one.
This is actually achieved by the first grammar which only allows the 2nd reading: