Take the 2-minute tour ×
English Language & Usage Stack Exchange is a question and answer site for linguists, etymologists, and serious English language enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

closed as off-topic by FumbleFingers, tchrist, David M, medica, Kris Mar 10 at 8:10

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions that can be answered using commonly-available references are off-topic. A list of these references can be found here: List of general references" – FumbleFingers, tchrist, David M, Kris
If this question can be reworded to fit the rules in the help center, please edit the question.

2  
I think you mean "punctuation" –  simchona Jul 31 '11 at 22:04
2  
Semantics and syntax. –  simchona Jul 31 '11 at 22:06
3  
This was already covered here. More at Colorless green ideas sleep furiously. –  prash Jul 31 '11 at 22:21

4 Answers 4

up vote 12 down vote accepted

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.

share|improve this answer
    
Thanks for the very in depth, hybrid csci-english response! –  Phil Jul 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? –  Nanne Aug 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. –  Jeremy Aug 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. –  Kris Mar 10 at 8:14

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.

share|improve this answer
1  
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 Fine Jul 31 '11 at 23:20
    
Punctuation does have meaning. Doesn't it? Punctuation does have meaning, doesn't it. –  KitFox Aug 1 '11 at 2:10

As far as computer science applies, simple answer is...

Syntax errors are those errors caused because you did not follow the rules of the language:

For C++

for (int i = 0; i < 10; i++) 
{ printf("%d\n", i) } // You forgot the semicolon

Semantics errors are those errors caused due to mispelling and such

For C++

for (int i = 0; i < 10; i++) 
{ priNtf("%d\n", i); } // You capitalized the "n"
share|improve this answer

Syntax is the symbology and grammar of a language, which tells you the rules for constructing well-formed sentences of the language. Semantics concerns what those statements mean.

# Ruby
if a and b
  foo()
end

-- Lua
if a and b then
  foo()
end

# C/C++/Java
if (a && b)
  foo();

# Python 
if a and b:
  foo()

These all mean the same thing, which is to say they have the same semantics, but they are described using slightly different syntax.

Some languages offer alternative syntaxes for commonly used language constructs. For instance, in Lua the following are exactly equivalent; i.e. they have identical semantics:

person.favorite = 'donut'
person['favorite'] = "donut"

As do the following:

function add(a,b) return a+b end
add = function(a,b) return a+b end
share|improve this answer

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