The present invention relates to novel pyrimidine and pyridine compounds of formula (I) or a pharmaceutical acceptable salt thereof, wherein R1, R2, R3, R4, R5, X, Y and G are as defined in the description, to pharmaceutical compositions containing them, a process for preparing them, and their use in therapy of a disease responsive to inhibition of FGFR, for example, cancer.