I always think this joke is more of a linguistics/grammar joke than programming. The kid resolves the ambiguity in the ellipsis incorrectly, but why is this a programmer joke?
Yes the joke is definitely on human language and not on programming but I think programmer can be relate here. At least I feel this joke is made in every computer science ground class ever.
I heard this joke in Spanish, but the meaning is a bit different. Eggs is a colloquial/slang term for testicles (like balls in English), so "if you have eggs" means "if you dare".
For a serious reoly, I think the expression "If they have eggs, buy two" is redundant. If they didn't have eggs, the kid just can't and won't buy any eggs.
I think the proper command would be, "Please buy 1 bottle of milk and two eggs." That way, the kid won't be confused and it's still a proper valid command.
Unfortunately though, the sentence is ambiguous even to non-programmers. It is unknown whether the if condition applies to
buying two eggs (buy two eggs)
buying two bottles of milk (buy two bottles instead)