The yellow hypergiant stars (YHGs) are extremely luminous and massive objects whose general properties are poorly known. Only two of this kind of star show massive circumstellar envelopes, IRC+10420 and AFGL2343. We aim to study the chemistry of the circumstellar envelopes around these two sources, by comparison with well known AGB stars and protoplanetary nebulae. We also estimate the abundances of the observed molecular species. We have performed single-dish observations of different transitions for twelve molecular species. We have compared the ratio of the intensities of the molecular transitions and of the estimated abundances in AFGL2343 and IRC+10420 with those in O-rich and C-rich AGB stars and protoplanetary nebulae. Both YHGs, AFGL2343, and IRC+10420, have been found to have an O-rich chemistry similar to that in O-rich AGB stars, though for AFGL2343 the emission of most molecules compared with 13CO lines is relatively weak. Clear differences with the other evolved sources appear when we compare the line intensity corrected for distance and the profile widths which are, respectively, very intense and very wide in YHGs. The abundances obtained for IRC+10420 agree with those found in AGB stars, but in general those found in AFGL2343, except for 13CO, are too low. This apparently low molecular abundance in AFGL2343 could be due to the fact that these molecules are present only in an inner region of the shell where the mass is relatively low.