77

What is the difference in meaning between 'semantics' and 'syntax'? What are they?

Also, what's the difference between things like "semantic website vs. normal website", "semantic social networking vs. normal social networking" etc.

4
  • 4
    "ARE semantics and syntax the same things?" Two nouns. Plural verb form. Plural pronouns. Parallel structure.
    – S.Lott
    Oct 16, 2008 at 21:10
  • 4
    That was syntax. Semantics didn't change, did it?
    – S.Lott
    Oct 17, 2008 at 1:09
  • i still don't get it, explain?
    – John
    Oct 17, 2008 at 3:00
  • 5
    @John: I asked you to change the syntax of your question -- spelling, word use, etc. The meaning of your question -- the semantics -- did not change. Everyone's understanding of your meaning stayed the same. The spelling of the words was the only change.
    – S.Lott
    Oct 17, 2008 at 12:55

9 Answers 9

125

Syntax is the grammar. It describes the way to construct a correct sentence. For example, this water is triangular is syntactically correct.

Semantics relates to the meaning. this water is triangular does not mean anything, though the grammar is ok.

Talking about the semantic web has become trendy recently. The idea is to enhance the markup (structural with HTML) with additional data so computer could make sense of the web pages more easily.

3
  • 1
    thanks! everyone else gave good answers too, but yours made the most sense to me
    – John
    Oct 16, 2008 at 20:17
  • 3
    And in HTML specifically, the "semantic web" is the idea that your HTML code should carry meaning. Don't use a table if you aren't actually showing tabular data. Use the tags that best explain the meaning of your document, not the ones that makes it look the way you want. That's what CSS is for.
    – jalf
    Jan 30, 2009 at 20:08
  • Semantic is about the bugs in the implementation logic. Right ? Oct 5, 2019 at 5:26
20

Syntax is the grammar of a language - the rules by which to form sentences or expressions.

Semantics is the meaning you are trying to express with your code.

1
  • 1
    Isn't that "semantics is the meaning you're expressing with your code"? A programmer might be trying to express something but not getting it right... what s/he is trying is in his/her head essentially.
    – einpoklum
    Jul 11, 2016 at 21:34
9

A program that is syntactically correct will compile and run.

A program that is semantically correct will actually do what you as the programmer intended it to do. i.e. it doesn't have any bugs in it.

Two programs written to perform the same task in different languages will use different syntaxes, but they would be the same semantically.

2
  • Sorry for nitpicking, but "semantically they could be the same." or "would be the same" ?
    – doubleOrt
    Jun 20, 2018 at 13:34
  • > "Two programs written to perform the same task in different languages will use different syntaxes, but they would be the same semantically." . The algorithms could be different right ? Even if the algorithm is same the program written in "c++" will have a different number and order of instructions than a program written in "c" . So the semantics vary . Is this correct ? Oct 5, 2019 at 5:25
6

If you are talking about web (rather than programming languages):

The syntax of the language is whatever the browser (or processing program) can legally recognize and handle, and render to you. For example, your browser can render HTML, while your API can parse XML trees.

Semantics involve what is actually being represented. There's a lot of buzz now about semantic webs and all that stuff, but it essentially means that each entity is also associated with some human-readable information or metadata, so that a certain tag would have a supposed meaning and refer you to it.

Social networks are the same story. You put knowledge in the links

1
  • thanks i like your answer too, I wish i could select TWO accepted answers
    – John
    Oct 16, 2008 at 20:18
4

"An ant ate an aunt." has a correct syntax, but will not make sense semantically. A syntax is a set of rules that can be combined to produce infinite number of gramatically valid sentences, but few, very few of which has a semantics.

2

Syntax is the word order of a sentence. In English it would be the subject-verb-object form.

Semantic is the meaning behind words. E.g: she ate a saw. The word saw doesn't match according to the meaning of the sentence. but it is grammatically correct. so its syntax is correct. =)

1

Specifically, semantic social networking means embedding the actual social relationships within the page markup. The standard format for doing this as defined by microformats is XFN, XHTML Friends Network. In regards to the semantic web in general, microformats should be the go-to guide for defining embedded semantic content.

0

Semantic web sites use the concept of the semantic web, which aims to bring meaning to web content by using special annotations to identify certain concepts in a page. This makes possible the automatic (by a computer, not a human) reasoning about the content, which improves its aggregation, extraction, indexing and searching.

0

Explanations above are vague on the semantics side, semantics could mean the different elements at disposition to build arguments of value(these being comprehensible, to end-user man and digestible to the machine).

Of course this puts semantics and the programmer-editor-writer-communicator in the middle: he decides on the semantics that should be ideally defined to his public, comprehended by his public, general convention by his public and digestible to the machine-computer. Semantics should be agreed upon, are conceptual, must be implementable to both sides.

Say footnotes, inline and block-quotes, titles and on and on to end up into a well-defined and finite list. Mediawiki, wikitext as an example fails in that perspective, defining syntax for elements of semantic meaning left undefined, no finite list agreed upon. "meaning by form" as additional of what a title as an example again carries as textual content. Example "This is a title" becomes only semantics integrated by the supposition within agreed upon semantics, and there can be more then one set of say "This is important and will be detailed"

Asciidoc and pandoc markup is quite different in it's semantics, regardless of how each translates this by convention of syntax to output formats.

Programming, output formats as html, pdf, epub can have consequentially meaning by form, by semantics, the syntax having disappeared as a temporary tool of translation, and as one more consequence thus the output can be scanned robotically for meaning, the champ of algorithms of 'grep': Google. Looking for the meaning of "what" in "What is it that is looked for" based upon whether a title or a footnote, or a link is considered.

Semantics, and there can be more then one layer, even the textual message carries (Chomsky) semantics thus could be translated as meaning by form, creating functional differences to anything else in the output chain, including a human being, the reader.

As a conclusion, programmers and academics should be integrated, no academic should be without knowledge of his tools, as any bread and butter carpenter. Programmers should be academics in the sense that the other end of the bridging they accomplish is the end user, the bridge... much so: semantics.

m.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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