Every day, we consume a variety of things, each with its own unique flavor due to the different chemical compounds they contain.
Sweetness is closely associated with sugars. Many fruits and vegetables contain sugars like glucose, fructose, maltose, and sucrose, all of which are sweet. Sucrose, in particular, is intensely sweet and is found in sugarcane and sugar beets. Some substances are not sweet themselves but taste sweet in the mouth. For example, starch is not sweet, but when broken down by amylase in saliva, it converts into maltose and glucose, which are sweet.
Sourness is almost always associated with acids—acetic acid, malic acid, citric acid, tartaric acid, among others, are organic acids commonly found in plants. Grapes, for instance, contain a lot of tartaric acid, while lemons are practically warehouses of citric acid.
Bitterness is a taste that people generally dislike, yet many plants are bitter. Most Chinese herbal medicines, for instance, are unbearably bitter, hence the saying “Good medicine tastes bitter.” Bitterness is often caused by the presence of alkaloids. Famous herbs like Huanglian contain a lot of berberine alkaloid. Quinine bark, used to treat malaria, is another “bitter medicine” due to its bitter quinine alkaloid.
Spiciness has a more complex origin. Chili peppers are spicy because they contain capsaicin. Tobacco is spicy due to nicotine. Radishes are also spicy because they contain volatile mustard oil.
Astringency is largely due to tannic acid. Persimmons, for example, contain a lot of tannic acid, which can make them so astringent that they make your mouth feel puckered. Other foods like olives, tea leaves, and pears also contain tannic acid, giving them a slight astringent taste.