Unambiguous grammars with different right and left hand derivations I read recently that for an unambiguous grammar the left hand derivation need not necessarily be equal to the right hand derivation. Can someone give an example of this?
Consider the following simple grammar:
$$
S\to AB \\
A\to a \\
B\to b
$$
Here is a leftmost derivation of $ab$:
$$
S\to AB \to aB \to ab
$$
Here is a rightmost derivation of $ab$:
$$
S \to AB \to Ab \to ab
$$
You can see that they look different. However, they correspond to the same parse tree:

More generally, each leftmost derivation corresponds to a parse tree, and this correspondence is a bijection; and the same holds for rightmost derivations. Therefore each leftmost derivation has a corresponding rightmost derivation, sharing the same parse tree.