How to reference to the components of vec in shader programming?

A vector in shading language can be seen as different types of data. When it is take as color, it has 4 components: r, g, b, a; If take it as position, it has 4 components: x, y, z, w; If take it as texture, it has 4 components: s, t, p, q;