Professional Documents
Culture Documents
Software Development
Lecture 2
Semester 1, 2015
Dr. Pan Zheng
Logical reasoning
Axiomatic Semantics
{P}Q{R}
called a Hoare triple, to state that if the Boolean expression P holds prior the
Hoare Triple
{P}Q{R}
Precondition
Program
Postcondition
In
Hoare Triple
Hoare Triple
{} = 5{ = 5}
{ = } = + 3{ = + 3}
{ > 0} = 2 { > 2}
{ = } < 0 = { = ||}
{} = 3{ = 8}
{} + 1{}
{P}x:=x+1{x N}
Assignment/Substitution rule
{P0}x:=f{P}
Where x is a variable identifier;
P0 is obtained from P by substituting f for all occurrences of x
Example: exercise
{x+1 }x:=x+1{ }
or even better
{x -1}x:=x+1{ }
Sequence rule
{P}x:=x+1;y:=x+y{y>5}
Refer to whiteboard ...
Conditional rule
{0 x < 15 } x:=x+1 {0 x 15 }
AND
{x=15} x:=0 {0 x 15 }
Another example
Premise 1:
Premise 2:
Proof:
Operational Semantics
The basic idea of the operational method is to define the meaning of the
language elements by means of a (labelled) transition system.
Operational Semantics
Denotational Semantics
The denotational method does not maintain states, but the meaning of a
program is given as a function that interprets all language elements of a
given program as elements of a corresponding set of values.
Denotational Semantics
Types are collections of values that share some common properties. When we
say that v is a value of type T, we mean that v T.
In some systems, there may be types with types as members. Types with types
as members are usually called something else, such as universes, orders, or
kinds, to avoid the impression of circularity.
In most programming languages, types are checked in some way, either during
program compilation, or during execution. The main purpose of type checking is
the detection of errors, documentation, program optimization, etc.
Values
Constants
Examples:
EOF = -1
TRUE = 1
FALSE = 0
PI = 3.1415927
MESSAGE = Welcome to HIT3315
Constants
Examples:
EOF = -1
TRUE = 1
FALSE = 0
PI = 3.1415927
MESSAGE = Welcome to HIT3315
Primitive Values
Examples:
Truth values
Integers
Characters
Strings
Real numbers
Composite Values
Examples:
Records
Arrays
Enumerations
Sets
Lists
Tuples
Files
Pointers
A Language Interpreter
language)
to a abstract syntax tree (the internal representation of the program
text) and
abstract syntax tree and converts it, possibly using external inputs, to
an answer.
Examples:
A calculator, Basic, Perl, Python, sh, awk, Tcl
JVM
A Language Compiler
(meaning of a variable)
Examples: variables, parameters, procedures
The
The
Compiler
Interpreter
Errors are displayed after entire program is Errors are displayed for every
checked
instruction interpreted (if any)
generates the error message only after
scanning the whole program. Hence
debugging is comparatively hard.
Interpreter
compiler
End of lecture 2