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.
|
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.) |
|||||||||||||||
|
|
Noam Chomsky famously used the sentence "Colorless green ideas sleep furiously". The syntax is flawless, but it has no meaning. |
|||||||||||
|
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:
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:
Figuring out the double meaning here is left as an exercise to the reader. |
|||||||||||||||
|
|
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?
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":
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:
If you were speaking strictly about color, this sentence would have a semantic conflict that could not be resolved. |
|||||
|
|
Here is a sentence that is syntactically correct, but semantically incorrect:
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. |
||||
|
|
Or something like this. Correct syntax, incorrect structure (not the hat was staring out of the window, but its nameless wearer) |
||||
|
|
This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.