They are not programmed, they learn from piles of text. That is literally how large language models work.