Syntax = Grammar

Section: Communicating with Language
...Subsection: Syntax = Grammar

To learn any new language, one must not only learn the words and their meanings, but also the rules describing how words can be combined to form valid sentences. The syntax of a language is a set of rules governing the formation of grammatically correct sentences. In a natural language like German, one must understand the rules regarding adjective endings and verb placement. In a computer language, one must understand the structure of each instruction and the proper use of punctuation.

The sentences in a computer language are frequently called program statements, and errors in the formation of statements, i.e. grammatical errors, are called syntax errors. A program that contains one or more syntax errors will not execute.

For example, a simple declarative English sentence has the following form:

article noun verb article noun.

If we agree that the word the is a particular instance of article, cat and milk are instances of noun, and drinks is an instance of verb, then the sentence

The cat drinks the milk.

is syntactically correct. So is

The milk drinks the cat.

It's certainly true that the computer which is our brain would be quite confused if we heard the above sentence. Our brain does not reject the sentence based on improper syntax, but rather on what we know about the meanings of the individual words in the sentence.

Q. 1
Which of the following sentences contain one or more syntax errors based on the grammatical rule above?

  1. The cat drinks the milk
  2. The drinks milk cat the.
  3. The cat drinks milk.


Punctuation is an important part of the syntax of a computer language, and it must be used properly. Common punctuation symbols are {, }, (, ), ", and ;.


Suzanne Menzel; menzel@cs.indiana.edu