Example ambiguous grammar

⟨SENTENCE⟩    → ⟨NOUN-PHRASE⟩⟨VERB-PHRASE⟩
⟨NOUN-PHRASE⟩ → ⟨CMPLX-NOUN⟩ | ⟨CMPLX-NOUN⟩⟨PREP-PHRASE⟩
⟨VERB-PHRASE⟩ → ⟨CMPLX-VERB⟩ | ⟨CMPLX-VERB⟩⟨PREP-PHRASE⟩
⟨PREP-PHRASE⟩ → ⟨PREP⟩⟨CMPLX-NOUN⟩
⟨CMPLX-NOUN⟩  → ⟨ARTICLE⟩⟨NOUN⟩
⟨CMPLX-VERB⟩  → ⟨VERB⟩ | ⟨VERB⟩⟨NOUN-PHRASE⟩
⟨ARTICLE⟩     → a | the
⟨NOUN⟩        → boy | girl | flower
⟨VERB⟩        → touches | likes | sees
⟨PREP⟩        → with


Here is one derivation:

1.  ⟨SENTENCE⟩ → ⟨NOUN-PHRASE⟩⟨VERB-PHRASE⟩ →
2.  ⟨CMPLX-NOUN⟩⟨VERB-PHRASE⟩ →
3.  ⟨ARTICLE⟩⟨NOUN⟩⟨VERB-PHRASE⟩ →
4.  The ⟨NOUN⟩⟨VERB-PHRASE⟩ →
5.  The girl ⟨VERB-PHRASE⟩ →
6.  The girl ⟨CMPLX-VERB⟩⟨PREP-PHRASE⟩ →
7.  The girl ⟨VERB⟩⟨NOUN-PHRASE⟩⟨PREP-PHRASE⟩ →
8.  The girl touches ⟨NOUN-PHRASE⟩⟨PREP-PHRASE⟩ →
9.  The girl touches ⟨CMPLX-NOUN⟩⟨PREP-PHRASE⟩ →
10. The girl touches ⟨ARTICLE⟩⟨NOUN⟩⟨PREP-PHRASE⟩ →
11. The girl touches the ⟨NOUN⟩⟨PREP-PHRASE⟩ →
12. The girl touches the boy ⟨PREP-PHRASE⟩ →
13. The girl touches the boy ⟨PREP⟩⟨CMPLX-NOUN⟩ →
14. The girl touches the boy with ⟨CMPLX-NOUN⟩ →
15. The girl touches the boy with ⟨ARTICLE⟩⟨NOUN⟩ →
16. The girl touches the boy with the ⟨NOUN⟩ →
17. The girl touches the boy with the flower

Here is another leftmost derivation:

1.  ⟨SENTENCE⟩ → ⟨NOUN-PHRASE⟩⟨VERB-PHRASE⟩ →
2.  ⟨CMPLX-NOUN⟩⟨VERB-PHRASE⟩ →
3.  ⟨ARTICLE⟩⟨NOUN⟩⟨VERB-PHRASE⟩ →
4.  The ⟨NOUN⟩⟨VERB-PHRASE⟩ →
5.  The girl ⟨VERB-PHRASE⟩ →
6.  The girl ⟨CMPLX-VERB⟩ →
7.  The girl ⟨VERB⟩⟨NOUN-PHRASE⟩ →
8.  The girl touches ⟨NOUN-PHRASE⟩ →
9.  The girl touches ⟨CMPLX-NOUN⟩⟨PREP-PHRASE⟩ →
10. The girl touches ⟨ARTICLE⟩⟨NOUN⟩⟨PREP-PHRASE⟩ →
11. The girl touches the ⟨NOUN⟩⟨PREP-PHRASE⟩ →
12. The girl touches the boy ⟨PREP-PHRASE⟩ →
13. The girl touches the boy ⟨PREP⟩⟨CMPLX-NOUN⟩ →
14. The girl touches the boy with ⟨CMPLX-NOUN⟩ →
15. The girl touches the boy with ⟨ARTICLE⟩⟨NOUN⟩ →
16. The girl touches the boy with the ⟨NOUN⟩ →
17. The girl touches the boy with the flower

These derivations differ at step 6. In the first you have a verb-phrase that combines a verb with a preposition, so the preposition is modifying the verb (she is using the flower to touch the boy). In the second derivation, the verb isn’t modified by the preposition. Instead the preposition comes with the noun (so the boy has the flower).