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?

4 Answers
4

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.

Thanks for the very in depth, hybrid csci-english response!
–
PhilJul 31 '11 at 23:30

1

But int i = "hello" would be bad syntax too in most languages? I don't think there is one where you specify the type but do not have a syntax rule on what can follow?
–
NanneAug 1 '11 at 8:54

That's why I said arbitrary language. In the compiler I wrote, the grammar for assignment expressions looked like: [Type] [text] = [Value]. So it would be good syntax. I wouldn't be surprised if other, smarter languages had rules like int [text] = [int value], in which case it would be a syntactical issue.
–
JeremyAug 1 '11 at 12:26

I'm not sure which paradigm you have in mind, but int i = "hello" is both syntactically and semantically valid and is parsed and processed without a whimper of protest, at least in some contexts. Run it and see.
–
KrisMar 10 '14 at 8:14

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.

Actually, when talking about human language, there's a case for saying that spelling, and probably also punctuation, are none of these. The Serbian language can be written in Cyrillic or Roman letters, but when you change from one to the other you are not changing either the syntax or the morphology, simply the way that the words are written down on paper.
–
Colin FineJul 31 '11 at 23:20