1 Natural Languages

A programming language is in many ways like a natural language. It has a vocabulary and a grammar. The vocabulary is the collection of those “basic words” from which we can compose “sentences” in our language. A sentence in a programming language is an expression or a function; the language’s grammar dictates how to form complete sentences from words. Programmers use the terminology syntax to refer to the vocabularies and grammars of programming languages.

Not all grammatical sentences are meaningful—neither in natural languages such as English nor in a programming language such as Java. For example, the English sentence “the cat is round” is a meaningful sentence, but “the brick is a car” makes no sense, even though it is completely grammatical. To determine whether or not a sentence is meaningful, we must check certain properties of the phrases. In the programming language world, this context-sensitive checking is often explained why functions—mathematical functions or functions in a programming language.

Our eventual goal is to explain what sentences mean or, as we say in the world of programming languages, their semantics. As a child you grow into your native language and you grasp its meaning intuitively. As a student of a foreign language, say English, you learn to translate sentences and phrases from the foreign language into your native language. Once you have acquired vocabulary, you learn to relate new foreign sentences to old ones and you thus explain their meaning. Lastly, when you are able to acquire new vocabulary in this intuitive and “embedded” manner, you also pick up idioms and you learn to speak like a native in the foreign language. You begin to understand the pragmatics of the language.