Humans taste using a mix of cells in the nose and tongue, these send information to the brain. in the nose these cells, called olfactory receptors are triggered by different chemicals in what you are eating, the cells in the tongue, called taste buds, also help distinguish different food.
Find out more here
A Robot does not have organic cells with which to detect chemicals, however their are other ways to work out the chemicals that something consists off. For this we use the emission / absorption spectrum of a chemical.
Just like objects having different colours due to if they absorb or reflect the light, gases reflect and absorb light the same. As such if you were to vaporise a solid into a gas and shine light through it, or heat it up so that it admits light, then you can see what chemicals are in the gas. you may do this at school by doing flame tests, where you burn chemicals over a Bunsen burner.
Above is an image of Emission spectra (The colours a gas emits when heated) and Absorption (The colours a gas absorbs) theses are the same colours for a given chemical, but are not always the same colour as the solid form.
Find out more by looking at the spectrometer simulator below.