The previous slide makes the distinction between the syntax of a programming language—what the language constructs look like—and its semantics—what the language constructs actually do.
Compared to syntax, semantics is more difficult to specify.
There are several ways to specify programming language semantics:
By a language reference manual such as a Perl manual:
This method suffers from the lack of precision inherent in natural language descriptions and also may have omissions and ambiguities.
By a defining translator:
This approach answers questions about a language by experiment (as in chemistry or physics).
The main drawback is we must execute a program to discover what it does.
By a formal definition such as a C manual:
It is the approach will be discussed in this course.
Such mathematical methods are precise, but are also complex and abstract, and require study to understand.
Different formal methods are available, with the choice of method depending on its intended use.
Some of them and their references are listed below:
Action semantics,
which produce formal semantic specifications that directly reflect the
ordinary computational concepts of programming languages and that are
easy to read and understand.
Algebraic semantics,
which involve the algebraic specification of data and language constructs.
The basic idea of this approach is to name the different sorts of objects and the operations on the objects and to use algebraic axioms to describe their characteristic properties.