CSCI 431 Lecture Notes - Semantics

Informal Semantics

Example: FORTRAN DO-loops.

``DO n i = m1, m2, m3

Repeat execution through statement n, beginning with i = m1, incrementing by m3, while i is less than or equal to m2. If m3 is omitted, it is assumed to be 1. m's and i's cannot be subscripted. m's can be either integer numbers or integer variables; i is an integer variable.''
-- from DEC Fortran-II Manual, 1974.

Consider:

      DO 100 I = 10, 9, 1
        ...
100   CONTINUE

How many times is the body executed?

How about this example in Pascal?


     I := 1
     J := 2 ;
     while (I < J) do
     begin
        I := I+1 ;
        J := J+1 ;
     end

In the early days

Formal Semantics

Semantic Models

VDL -- Vienna Definition Language

Axiomatic Semantics

Notation

The Basic Idea

Example: {X=1} X:=X+1 {X=2}

Formal Specification

Example: I want a program that swaps the values in X and Y How do we determine when the program fulfills the specification?

A formal Proof

Weakest preconditions

Assignment Statements

Selection statements

Loop invariants