Overview Transition Semantics Configurations and the transition relation Executions and computation Inference rules for small-step structural operational semantics for the simple imperative language Transition semantics of failure Labeled transition semantics of input and output Relationship with (direct) denotational semantics
Operational (or Transition) Semantics Idea: Define the execution of a program as a sequence γ 0, γ 1,... of configurations γ i Γ. Configurations are either terminal or nonterminal: e.g. for the SIL Γ = Γ T Γ N Γ T Γ N = {} Γ T = Σ Γ N = comm Σ [x : 42] Γ T x:= x+1, [x : 41] Γ N Define a transition relation from Γ N to Γ: informally, γ γ if γ is obtained in one step from γ, e.g. x:= x+1, [x : 41] [x : 42]
Executions and Computation An execution is a (finite or infinite) sequence of configurations γ 0, γ 1,... such that γ i γ i+1 whenever γ i and γ i+1 are in the sequence. The relation of computation is the reflexive and transitive closure of γ γ if there is a finite execution starting with γ and ending with γ. For the SIL we will define which is a total function from Γ N to Γ, for every γ Γ there is a longest execution starting with γ; if it is infinite, then γ diverges: γ ; otherwise there is a unique γ Γ T such that γ γ.
Plotkin Style Small-Step Structural Operational Semantics for the SIL We define the relation in terms of inference rules. Example: (skip) (assgn) (seq t) (seq s) skip, σ σ v:= e, σ [σ v : [[e]] intexp σ] c 0, σ σ c 0 ; c 1, σ c 1, σ c 0, σ c 0, σ c 0 ; c 1, σ c 0 ; c 1, σ (by (seq s)) (by (assgn)) x:= x+1, [x : 4 y : 6] [x : 5 y : 6] (by (seq t)) x:= x+1 ; y:= y+x, [x : 4 y : 6] y:= y+x, [x : 5 y : 6] x:= x+1 ; y:= y+x ; skip, [x : 4 y : 6] y:= y+x ; skip, [x : 5 y : 6]
More SOS Rules (cond t) (cond f) (while t) (while f) if b then c else c, σ c, σ if b then c else c, σ c, σ while b do c, σ c ; while b do c, σ while b do c, σ σ when [[b]] boolexp σ = true when [[b]] boolexp σ = false when [[b]] boolexp σ = true when [[b]] boolexp σ = false However the naïve rule for variable declaration newvar v:=e in c, σ c ; v:= n, [σ v : [[e]] intexp σ] where n = σ v exposes the local variable name in the result, which becomes a problem when we extend the language.
SOS Rule for Local Variable Declaration Idea: Use the declaration to reflect changes in the value of the variable. (decl t) (decl s) c, [σ v : [[e]] intexp σ] σ newvar v:=e in c, σ [σ v : σ v] c, [σ v : [[e]] intexp σ] c, σ newvar v:=e in c, σ newvar v:=σ v in c, [σ v : σ v] (decl s) (seq t) (assgn) x:= x+1, [x : 24 y : 10] [x : 25 y : 10] x:= x+1 ; y:= x+2, [x : 24 y : 10] y:= x+2, [x : 25 y : 10] newvar x:=x+3 in x:= x+1 ; y:= x+2, [x : 21 y : 10] newvar x:=25 in y:= x+2, [x : 21 y : 10]
Inference Rules for the Computation The reflexive and transitive closure of can also be defined using inference rules: (incl) (refl) (trans) γ γ γ γ γ γ γ γ γ γ γ γ
Meaning of Commands Γ N Γ (total function) γ Γ there is a longest execution starting from γ, either infinite or ending with a γ Γ T = Σ. [[c]] comm σ =, if c, σ σ, if c, σ σ
Transition Semantics of Failure Define Γ T = Σ ({abort} Σ). Then Propagation of failure: (fail) fail, σ abort, σ (seq x) c 0, σ abort, σ c 0 ; c 1, σ abort, σ c, [σ v : [[e]] intexp σ] abort, σ (decl x) newvar v:=e in c, σ abort, [σ v : σ v] The semantics of commands becomes [[c]] comm σ =, if c, σ σ, if c, σ σ abort σ, if c, σ abort σ
Labeled Transition Semantics of Input and Output Informally: Write labels on transitions to show input or output. Rules: (output) (input)!e, σ!n σ?v, σ?n [σ v : n] when n = [[e]] intexp σ Formally, the transition relation becomes ternary: Γ N Λ Γ, where Λ = {ɛ} {?n n Z} {!n n Z} (ɛ is silent ) and c, σ λ γ stands for c, σ, λ, γ.
Labeled Transition Semantics cont d The other rules are generalized to propagate the labels, e.g. (seq t) (seq s) (seq x) c 0, σ λ σ c 0 ; c 1, σ λ c 1, σ c 0, σ λ c 0, σ c 0 ; c 1, σ λ c 0 ; c 1, σ c 0, σ λ abort, σ c 0 ; c 1, σ λ abort, σ
Properties of the Labeled Transition Semantics If γ = c, σ Γ N, then exactly one of these holds:!γ Γ such that γ γ (silent transition)!γ Γ, n Z such that γ!n γ {λ Λ γ Γ and γ λ γ } = {?n n Z} Hence for every γ Γ there is a longest sequence of silent transitions which is either infinite ends with a γ Γ T ends with a γ Γ N such that!γ Γ, n Z such that γ!n γ ends with a γ Γ N such that n Z. γ Γ. γ?n γ.
Relationship with the Denotational Semantics So, for every γ Γ there is a longest sequence of silent transitions which is either infinite ends with a γ Γ T ends with a γ Γ N such that!γ Γ, n Z such that γ!n γ ends with a γ Γ N such that n Z. γ Γ. γ?n γ. If Ω = ( ˆΣ + (Z Ω) + [Z Ω]) and F [Γ Ω] is the least solution of F γ = then [[c]] comm σ = F c, σ., if γ ι term σ, if γ σ ι abort σ, if γ abort, σ ι out n, F γ, if γ. γ γ and γ!n γ ι in (λn Z. F γ n ), if γ Γ. n Z. γ γ and γ?n γn