Describe Semantics
Describe Semantics
DESCRIBING SEMANTICS
Types:
Operational Semantics
Denotational Semantics
Axiomatic Semantics
1. Operational Semantics
• The process:
– Build a translator (translates source code to the machine code of an idealized computer)
– Extremely complex if used formally (e.g., VDL), it was used for describing semantics of PL/I.
Evaluation
2. Denotational Semantics
Based on recursive function theory It is the The most abstract semantics description
method, It was Originally developed by Scott and Strachey (1970)
Let VARMAP be a function that, when given a variable name and a state, returns the current
VARMAP(ij, s) = vj
3. Axiomatic Semantics
It is Based on formal logic (predicate calculus)
Original purpose: formal program verification
Axioms or inference rules are defined for each statement type in the language (to allow
transformations of logic expressions into more formal logic expressions)
The logic expressions are called assertions
An assertion before a statement (a precondition) states the relationships and constraints
among variables that are true at that point in execution
An assertion following a statement is a postcondition
A weakest precondition is the least restrictive precondition that will guarantee the
postcondition
An example: a := b + 1 {a > 1}
Program proof process: The post-condition for the whole program is the desired results. Work
back through the program to the first statement. If the precondition on the first statement is the
same as the program spec, the program is correct.
2. {I} B {I} (evaluation of the Boolean must not change the validity of I)
The loop invariant I is a weakened version of the loop postcondition, and it is also
a precondition.
I must be weak enough to be satisfied prior to the beginning of the loop, but when
combined with the loop exit condition, it must be strong enough to force the truth
of the postcondition
Developing axioms or inference rules for all of the statements in a language is difficult
It is a good tool for correctness proofs, and an excellent framework for reasoning about
programs, but it is not as useful for language users and compiler writers
Its usefulness in describing the meaning of a programming language is limited for
language users or compiler writers