How would I answer the following programming exercise? It's trying to emphasize the difference between semantics and syntax.

Write an English sentence that has correct syntax but has semantic errors.

  • This is a programming exercise? – Mitch Jun 11 '11 at 15:02
  • Yeah sorry it's one of the first ones. :) – kalaracey Jun 11 '11 at 15:04
  • 1
    I think correct grammar is "Write an English sentence that has ...". Since which is non-restrictive, the sentence given is telling you to write an English sentence--any old sentence you like--and claiming that all English sentences are syntactically correct but semantically wrong, which is obviously false. It should say "... that ..." in order to tie the second clause to the first, qualifying which kind of English sentence one is to write. – ErikE Jun 11 '11 at 23:09
  • Alright, I posted the original question, but I've edited it. Thanks. – kalaracey Jun 13 '11 at 13:49

The panda eats, shoots and leaves.

The syntax is correct: it relates an observation of a panda eating before shooting and leaving. However, the misplacement of the comma makes the sentence semantically incorrect, as the intention of the sentence should be that pandas eat shoots and leaves, not that this panda was shooting. (No offense to the Kung-Fu Panda, who may actually shoot.)

  • This is funny, but you haven't explained why it is syntactically correct, but semantically inaccurate. – Kit Z. Fox Jun 11 '11 at 14:53
  • Yeah, a case of premature execution. – Bill Jun 11 '11 at 15:02
  • 4
    That sentence is syntactically and semantically correct, even though its meaning may not be what was intended. "Shoots" can mean to "move suddenly and rapidly in a particular direction" and that would be consistent with leaving. Therefore, without reference to external information, there is no semantic problem here. In fact, what's funny about Lynne Truss's book title is that it does have a semantically viable interpretation. – Robusto Jun 11 '11 at 15:14
  • I've never encountered anyone simply saying "shoots" to indicate a rapid movement. It would typically be "shoots off". I would not consider the sentence "The panda shoots." to indicate it suddenly took off. – Bill Jun 11 '11 at 15:19
  • 3
    This sentence does not have any semantic errors. This sentence is a classic example of a syntactically ambigious sentence, but only if you ignore the comma (as you would if it were spoken). With the comma, it is not even syntactically ambiguous. By the logic you are using, you could consider any sentence to have "semantic errors" (e.g. "I like pizza" has semantic errors if I am trying to say I hate pizza). That's just not what a semantic error is. The classic syntactically correct and semantically bad sentence is Chomsky's "Colorless green ideas sleep furiously." – Kosmonaut Jun 11 '11 at 16:28

Noam Chomsky famously used the sentence "Colorless green ideas sleep furiously". The syntax is flawless, but it has no meaning.

| improve this answer | |
  • 1
    Well, this specific sentence has acquired a meta-meaning - you could use just the sentence, and many would recognize it as a pointer to Chomsky's Syntactic Structures. – Piskvor left the building Jun 12 '11 at 12:20
  • Not a meta-meaning, I think: just a (possibly misleading) reference. See C S Lewis' essay 'Bluspels and Flalansferes' (not online, as far as I know) – Tim Lymington Jun 13 '11 at 22:04

A rock smelled the color nine

The syntax of the sentence works just fine but the sentence has absolutely no meaning because rocks do not smell and, even if they could, they couldn't smell a color that doesn't exist.

But the form works with other words:

A cat smelled the blue fish

Related issues with English (which may or may not be next in your class) are sentences with an ambiguous meaning but perfectly fine syntax. My personal favorite is:

Time flies like an arrow; fruit flies like a banana.

Figuring out the double meaning here is left as an exercise to the reader.

| improve this answer | |
  • 3
    +1 for the fruit flies. That has always been a favorite of mine. – Kit Z. Fox Jun 11 '11 at 14:52
  • But the "fruit flies" example doesn't really have anything to do with the question... – Kosmonaut Jun 11 '11 at 16:34
  • @Kosmonaut: It is a related issue that I would expect to appear in the OP's short future if their teacher is talking about syntax and semantics. Ambiguity is in the same overall subject. If it would help, I can make the segue more explicit. – MrHen Jun 11 '11 at 19:27
  • 1
    @MrHen: I can understand mentioning it as a sidenote; I mostly disagree with the comment that the "fruit flies" portion warrants a +1. – Kosmonaut Jun 11 '11 at 20:57
  • Yeah, ambiguous meaning is hardly semantic error. It's not relevant to the question. – ErikE Jun 11 '11 at 23:11

Syntax just refers to the parts of the sentence: are they arranged correctly and are the components sufficient so as to deliver the meaning so as to be understood and not misinterpreted?

Put your hat on.

Put your hat on the table.

These mean different things. Adding "the table" to the first sentence changes the meaning entirely. The first sentence tells you to put the hat on your head (obviously), and the second adds a syntactical element to specify a different location.

Let's flip it around, and substitute a pronoun for "your hat":

Take it off.

Take it off the table.

These two sentences could mean the same thing. If you had just put your hat on my freshly varnished table, I might use the first sentence because the context (hat on table) would be obvious.

Semantics, on the other hand, refers to the meaning itself, irrespective of syntax (roughly speaking: there are different schools of thought regarding the intersections of syntax and semantics, and I do not mean to delve into those various permutations here). The words "white" and "black" when used to describe color have distinctly different meanings, but you could create a syntactically correct sentence that had semantic problems:

My mother's white cat is black.

If you were speaking strictly about color, this sentence would have a semantic conflict that could not be resolved.

  • 1
    +1 for having a correct example and attempting to explain what goes on. An even more obvious example of bad syntax might be something like "My is cat black mother's". – Kosmonaut Jun 11 '11 at 16:42

Here is a sentence that is syntactically correct, but semantically incorrect:

The green apple ate a juicy bug.

The syntax is correct. That means the sentence is well-formed and structured properly. It contains articles in the appropriate places, the adjectives precede the nouns, and the verb is correctly conjugated. The first letter is capitalized and the terminal punctuation mark is in the appropriate place.

The sentence is not semantically correct, though. Apples don't eat things, so it doesn't make sense.

In computer programming, it is critical to always be mindful of the difference between syntax and semantics. Just because you can make something work doesn't mean that it is correct, so you must remember to think about code both in terms of how it is written and what it is actually doing.

| improve this answer | |

While staring out of the window, his hat flew off.

Or something like this. Correct syntax, incorrect structure (not the hat was staring out of the window, but its nameless wearer)

Not the answer you're looking for? Browse other questions tagged or ask your own question.