Describe a Programming Language
A programming language is an artificial formalism in which algorithms can be expressed. For all its artificiality, though, this formalism remains a language. Its study
can make good use of the many concepts and tools developed in the last century in linguistics (which studies both natural and artificial languages).
Levels of Description
In a study which has now become a classic in linguistics, Morris studied the various levels at which a description of a language can occur. He identified three major areas: grammar, semantics and pragmatics.
Grammar is that part of the description of the language which answers the question: which phrases are correct? Once the alphabet of a language has been defined
as a first step (in the case of natural language, for example, the Latin alphabet of 22 or 26 letters, the Cyrillic alphabet, etc.), the lexical component, which uses this alphabet, identifies the sequence of symbols constituting the words (or tokens) of the language defined. When alphabet and words have been defined, the syntax describes which sequences of words constitute legal phrases.
Syntax is therefore a relation between signs. Between all possible sequences of words (over a given alphabet), the syntax chooses a subset of sequences to form phrases of the language proper.
Semantics is that part of the description of the language which seeks to answer the question “what does a correct phrase mean?” Semantics, therefore, attributes a significance to every correct phrase. In the case of natural languages, the process of attribution of meaning can be very complex; in the case of artificial languages the situation is rather simpler. It is not difficult to assume, in this case, that semantics is a relation between signs (correct sentences) and meanings (autonomous entities existing independently of the signs that are used to describe them). For example, the meaning of a certain program could be the mathematical function computed by that program. The semantic description of that language will be constructed using techniques allowing us, when given a program, to fix the function the program computes.
It is at the third level that the principal actor makes its appearance on the scene, the person who uses a certain language.Pragmatics is that part of a language description which asks itself “how do we use a meaningful sentence?” Sentences with the same meaning can be used in different ways by different users. Different linguistic contexts can require the use of different sentences; some are more elegant, some are antiquated, or more dialect-based than others. Understanding these linguistic mechanisms is no less important than knowing the syntax and semantics.
In the case of programming languages, we can add a fourth level to the three classical ones: the implementation level. Given that the languages that interest us are procedural languages (that is, languages whose correct phrases specify actions), it remains for us to describe “how to execute a correct sentence, in such a way that we respect the semantics”. A knowledge of the semantics is, in general, enough for the language user, but the software designer is also interested in the process with which operative phrases implement the state under consideration. It is precisely this which is described by the language implementation.