The goal of operational semantics is, given a programming language, to be able to describe how to use it to compute.
There are several approaches:
- Denotational semantics
- The meaning of a term is an abstract mathematical object
- An advantage is that there are often many known mathematical properties of the object (term). We can use these rules to derive properties of the language we are deriving semantics for.
- Axiomatic semantics
- The meanings of programs are provided by laws (axioms)
- This approach focuses on the process of reasoning about programs
- Operational semantics (Covered in this lecture)
- Specifies the behavior of programs by describing how they execute on abstract machines that perform the steps of computation
- This approach helps with the development of a language interpreter
Rules are specified in a syntax directed way
Multiple kinds:
The operational semantics of a language is given by a transition system that is made up of:
- A set of states
- A binary relation "next state" transition relation between states
For example, in the λ-Calculus states can just be λ-terms
In languages with references, states can be pairs of a program and a store. Where the store contains the values currently held in the memory
The transition relation can be defined as a proof system consisting of derivation rules in a natural deduction style.
We say: There is a transition from M to N if there is a derivation that M and N are related.
In the λ-Calculus:
- States are λ-terms
- Transitions are provided by 2 inference rules
1st Rule:
λx.M⟹vλx.MVAL
2nd Rule:
MN⟹vVM⟹vλx.PN⟹vQP[x\Q]⟹vVAPP
The examples seen in slide 11 require evaluating the argument before doing a β-reduction.
Here we say that these semantics employ a strategy known as call-by-value, strict or eager, where the arguments to functions are always evaluated whether or not they are used in the body of the function.
Often λ-terms have several redexes. An evaluation strategy fixes the order in which redexes must be reduced.
The semantics seen so far is called call-by-value big step operational semantics This is why we have used the v notation on ⟹v
We will go on to see the call-by-name (lazy) evaluation strategy.
This also has 2 rules:
λx.M⟹nλx.MVAL
MN⟹nVM⟹nλx.PP[x\N]⟹nVAPP
Values:
- If M⟹vN then N is a λ-abstraction
- If M⟹nN then N is a λ-abstraction
Deterministic
- If M \implies_v NandM \implies_v PthenN = P$
- If M⟹nN and M⟹nP then N=P
β-equality
- If M⟹vN then M=βN
- If M⟹nN then M=βN