What is the difference between syntax and semantics? [closed]
As a computer scientist and a writing hobbyist, I really ought to know these terms' meanings for memory. Can anyone clarify the difference between syntax
and semantics
, and provide some examples? For example, where does punctuation fall? Spelling? What about sentence (or code) structure?
Solution 1:
I can only answer the computer question, although it has the exact same meaning for the English language. In short: Syntax is structure, and semantics is meaning.
Programming languages are written based on a grammar (just like English.) Grammars might say something like "If statements always have the form: if (condition) then (statement)." If you write something that follows the grammar perfectly, then it is syntactically correct, but may or may not be semantically correct, or semantically meaningful.
In some arbitrary simple language, the statement:
int i = "hello"
is syntactically correct, but not semantically correct, since it has no meaning even though it correctly follows the structure of the language.
A very common example is Chomsky's statement "Colorless green ideas sleep furiously", which follows the grammar of the English language but is semantically incorrect because it contains several contradictions -- colorless things cannot be green, for instance. You could of course argue this poetically to have some meaning (I would probably hate you), but that's beyond the scope of this discussion.
In English, "I no like!" is grammatically incorrect (syntactically incorrect), but is not semantically incorrect since it does imbue some meaning.
In coding, this is more muddy; it's hard to say whether a statement like "i (int) = 3" is semantically correct even though it's syntactically correct. There's really no meaning in this distinction, either. Generally, a statement has to be syntactically valid before it even has a chance of being semantically valid.
Solution 2:
Semantics is:
Semantics ... is the study of meaning. It focuses on the relation between signifiers, such as words, phrases, signs and symbols, and what they stand for, their denotata.
I think your confusion comes from the last phrase, that is, does puncutation come under "signs and symbols"? The answer is no, because, semantics deals with the meaning, so punctuation would not come under this, as punctuation does not have a meaning, and does not denote something.
Punctuation comes under, syntax, which is:
syntax ... is the study of the principles and rules for constructing sentences in natural languages.
Thus, in order to construct a sentences, you will need to follow certain rules, including rules for using punctuation. Punctuation comes under syntax.
What doe spelling come under? I would say, "morphology":
morphology is the identification, analysis and description of the structure of morphemes and other units of meaning in a language like words, affixes, and parts of speech and intonation/stress...
Thus, morphology, deals with how words are formed, and spelling would come under this.
Hope that helps.
All sources are from Wikipedia.