Four Concepts in Programming Language Description: Syntax, Semantics, Pragmatics and Metalanguage

Robert D. Cameron
January 7, 2002

Syntax, Semantics, and Pragmatics

In the linguistics of both natural and computer languages, the terms syntax, semantics and pragmatics are used to categorize descriptions of language characteristics. The syntax of a language describes the structure and composition of allowable phrases and sentences of the language. But syntax itself is devoid of meaning, simply telling us what strings are valid and how they may be parsed or decomposed. The meaning of these syntactic elements must be provided through semantics. In essence, we may think of providing syntactic elements as inputs to a semantic function, which in turn provides some representation of the meaning of the elements as output. In computers, the semantic function of a programming language may be considered to be embedded in the logic of a compiler or intepreter which arranges for program execution. Of course, an equivalent semantic function, albeit using a different representation, should also be found in the mind of the programmer (we hope).

Pragmatics is the third general area of language description, referring to practical aspects of how constructs and features of a language may be used to achieve various objectives. Consider, for example, the syntax, semantics and pragmatics of an assignment statement. As a syntactic construct, an assignment statement may consist of a variable and an expression (themselves syntactic constructs), separated by the token = as an assignment operator. Semantically, the variable denotes a location in computer memory, while the expression denotes computation of a value based on the contents of memory. Overall, the semantics of assignment is to perform the expression evaluation based on current memory contents and then update the value stored in the particular location corresponding to the variable. But what is often most interesting to programmers is really the pragmatics, that is, what assignment statements are useful for. There are many possibilities: to set up a temporary variable for the value of an expression that is needed more than once, to communicate values from one part of a program to another, to modify part of a data structure, or to set successive values of a variable used in some iterative computation.

Metalanguage

Another important concept that applies to all aspects of language description is that of metalanguage. Metalanguage, in general, refers to the language in which a subject language is being described. For example, BNF (Backus-Naur Form) is a metalanguage widely used to describe the syntax of programming languages. Similarly, there are formal metalanguages for describing the semantics of programming languages, particularly associated with the approaches of axiomatic semantics and denotational semantics. In most cases, however, a less formal approach to semantic description is taken, using English as the metalanguage.

It is important to note that metalanguages are indeed languages in their own right. In particular, one should expect that metalanguages each have their own syntax, semantics and pragmatics, which in turn must be described by a metametalanguage. Typically, a combination of English prose and standard mathematical notation is used as metametalanguage.

Further Material