Semantics

The semantics of a language defines the meaning of programs, how they behave when they are executed on a computer.

Link to original

There are two kinds of semantics:

  • Static Semantics

    Static Semantics (typing): detect (before execution) that programs that are syntactically correct but will give errors during execution

    Link to original
  • Dynamic Semantics

    Dynamic Semantics (or just Semantics): specifies meaning of programs

    Link to original

Informal Semantics

Informal semantics are descriptions in natural language.

Link to original

Formal Semantics

Formal semantics are precise and important for:

  • implementation of the language; behaviour of each construct is specified providing an abstraction of the execution process which is independent of the machine
  • programmers: formal semantics provides tools / techniques to reason about programs
  • language designers: allows to detect ambiguities in the constructs and suggest improvements and new constructs
Link to original

Formal semantics can be quite complex so usually only a part of the language is formally defined.

There are different styles of semantics:

  • Denotational Semantics: meaning of expressions (and in general, constructs) is given in an abstract, mathematical way.
  • Axiomatic Semantics: uses axioms and deduction rules in a specific logic. Predicates or assertions are given before and after each construct, describing the constraints on program variables before and after execution of a statement.
  • Operational Semantics: the meaning of each construct is given in terms of computation steps; the behaviour of the program during execution can be described using a transition system.

We study operational semantics in this course. Operational is useful for implementation and proving correctness of compiler optimisation. Denotational / axiomatic are useful to reason and prove properties of programs.

Transition Systems

Transition System

A transition system is specified by:

  • a set of configurations or states
  • a binary relation called a transition relation we use the notation (infix) to indicate that , are related by
Link to original

Deterministic Transition System

A transition system is deterministic if for all :

Link to original

Notation

Additional notes on notation:

  • denotes a transition / change of state from to
  • is the reflexive transitive closure of it holds iff there is a sequence of transitions: where

We distinguish an initial and final (terminal) subset of configurations, written and . For all , there is no such that . The idea is that a sequence of transitions from to represents a run of the program.

Abstract Machines

An abstract machine is a transition system that specifies an interpreter for a programming language.

It is an abstraction of a computer, describing how the program will execute. For a real programming language, these descriptions can be large and complicated.