Many of the processed foods that you buy today come with an ingredient label that lists "artificial flavors" as one of the key ingredients. Artificial flavors are simply chemical mixtures that mimic a natural flavor in some way.
Anything that we smell has to contain some sort of volatile chemical — a chemical that evaporates and enters a person's nose (See question 139 for details). The evaporated chemical comes in contact with sensory cells in the nose and activates them. In the case of taste, a chemical has to activate the taste buds. Taste is a fairly crude sense -- there are only four values that your tongue can sense (sweet, salty, sour, bitter) -- while the nose can sense thousands of different odors. Therefore most artificial flavors have both taste and smell components.
Any natural flavor is normally quite complex, with dozens or hundreds of chemicals interacting to create the taste/smell. But it turns out that many flavors — particularly fruit flavors -- have just one or a few dominant chemical components that carry the bulk of the taste/smell signal. Many of these chemicals are called esters. For example, the ester called Octyl Acetate (CH3COOC8H17) is a fundamental component in orange flavor. The ester called isoamyl acetate (CH3COOC5H11) is a fundamental component of banana flavor. If you add these esters to a product, the product will taste, to some degree, like orange or banana. To make more realistic flavors you add other chemicals in the correct proportions to get closer and closer to the real thing. You can do that by trial and error or by chemical analysis of the real thing.
There are hundreds of chemicals known to be flavoring agents. It's interesting that they are normally mixed to create "known" tastes. People make artificial grape, cherry, orange, banana, apple, etc. flavors, but it is very rare to mix up something that no one has ever tasted before. But it can and does happen occasionally — take Juicy Fruit gum as an example!
Here are several interesting links: