Section 1.16 Formal and Natural Languages
Note 1.16.1.
This is a topic that is useful to understand but not necessary to know in order to learn Python.
Natural languages are the languages that people speak, such as English, Spanish, and French. They were not designed by people (although people try to impose some order on them); they evolved naturally.
Formal languages are languages that are designed by people for specific applications. For example, the notation that mathematicians use is a formal language that is particularly good at denoting relationships among numbers and symbols. Chemists use a formal language to represent the chemical structure of molecules. And most importantly:
Programming languages are formal languages that have been designed to express computations.
There are two aspects that make up the syntax of a language:
When you read a sentence in English or a statement in a formal language, you have to figure out what the structure of the sentence is (although in a natural language you do this subconsciously). This process is called parsing.
For example, when you hear the sentence, “The other shoe fell”, you understand that the other shoe is the subject and fell is the verb. Once you have parsed a sentence, you can figure out what it means. That is the semantics of the sentence. Assuming that you know what a shoe is and what it means to fall, you will understand the general implication of this sentence.
Although formal and natural languages have many features in common — tokens, structure, syntax, and semantics — there are many differences:
People who grow up speaking a natural language—all of us—often have a hard time adjusting to formal languages. In some ways, the difference between formal and natural language is like the difference between poetry and prose, but more so:
Here are some suggestions for reading programs (and other formal languages). First, remember that formal languages are much more dense than natural languages, so it takes longer to read them. Also, the structure is very important, so it is usually not a good idea to read from top to bottom, left to right. Instead, learn to parse the program in your head, identifying the tokens and interpreting the structure. Finally, the details matter. Little things like spelling errors and bad punctuation, which you can get away with in natural languages, can make a big difference in a formal language.
Check your understanding
Checkpoint 1.16.3.
The differences between natural and formal languages include:
natural languages can be parsed while formal languages cannot.
- Actually both languages can be parsed (determining the structure of the sentence), but formal languages can be parsed more easily in software.
ambiguity, redundancy, and literalness.
- All of these can be present in natural languages, but cannot exist in formal languages.
there are no differences between natural and formal languages.
- There are several differences between the two but they are also similar.
tokens, structure, syntax, and semantics.
- These are the similarities between the two.
Checkpoint 1.16.4.