Operational Semantics
1. While Language
The While programming language is composed of three syntactic categories:
Also,
We use operators like
and instead of and to avoid confusion. For example and are mathematically equal, but and are not syntactically equal.
We also define a smaller expression language for expressions without variables,
An operational symantic for
Inference rules describe term execution. They have two forms,
(i.e. if then ) or (i.e. always holds). We sometimes write them in the form:
1.1 Big Step Semantics
Big Step Semantics take the form of a relation
For example, the derivation tree of
- Determinacy:
. - Totality:
.
1.2 Small Step Semantics
Sometimes, it is desirable to be more explicit about exactly how programs are evaluated. We define a relation
These rules tell us to follow these steps:
- First evaluate the left hand argument.
- When you get a number, evaluate the right hand argument.
- When you get another number, add them using the
rule.
Note that the order of evaluation is fixed by these semantics. So here,
From
An expression
is in normal form if is deterministic if . is confluent if . is weakly normalized if . is strongly normalized if . has unique normal forms if .
We can relate
2. State
A state is a partial function from variables to numbers (
We define the state update operation
For example, if
2.1 Small Step Semantics
We can define a new relation for while
Similarly, we can define a relation for commands
We can also find that
- If
and , then . - If
and then there exists a such that and .
2.2 More Configurations
Answer configurations are normal form configurations that describe the answer to some computation:
- Answer configurations of
are in the form where . - Answer configurations of
are in the form where . - Answer configurations of
are in the form .
Stuck configurations are normal form configurations that are not answer configurations. They are configurations that cannot take any more steps.
The evaluations
2.3 Strictness
We can define some short circuit semantics for
An operation is called strict in one of its arguments if it always needs to evaluate that argument. For example:
- Addition is strict in both arguments.
is strict in its first argument (left-strict), but not in its second argument.