ReynoldsCh06

# ReynoldsCh06 - Overview Transition Semantics...

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Overview Transition Semantics Conﬁgurations 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: Deﬁne the execution of a program as a sequence γ0, γ1, . . . of conﬁgurations γi ∈ Γ. Conﬁgurations are either terminal or nonterminal: e.g. for the SIL Γ = ΓT ∪ Γ N ΓT = Σ [x : 42] ∈ ΓT ΓT ∩ ΓN = {} ΓN = comm × Σ ￿x:= x+1, [x : 41]￿ ∈ ΓN Deﬁne 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 (ﬁnite or inﬁnite) sequence of conﬁgurations γ0, γ1, . . . such that γi ￿→ γi+1 whenever γi and γi+1 are in the sequence. The relation of computation ￿→∗ is the reﬂexive and transitive closure of ￿→ γ ￿→∗ γ ￿ if there is a ﬁnite execution starting with γ and ending with γ ￿. For the SIL we will deﬁne ￿→ which is a total function from ΓN to Γ, ⇒ for every γ ∈ Γ there is a longest execution starting with γ ; if it is inﬁnite, then γ diverges: γ ↑; otherwise there is a unique γ ￿ ∈ ΓT such that γ ￿→∗ γ ￿. Plotkin Style Small-Step Structural Operational Semantics for the SIL We deﬁne the relation ￿→ in terms of inference rules. (skip) (assgn) ￿skip, σ ￿ ￿→ σ ￿v := e, σ ￿ ￿→ [σ | v : [[e]]intexp σ ] ￿c0, σ ￿ ￿→ σ ￿ (seq t) ￿c0 ; c1, σ ￿ ￿→ ￿c1, σ ￿￿ Example: ￿c0, σ ￿ ￿→ ￿c￿ , σ ￿￿ 0 (seq s) ￿c0 ; c1, σ ￿ ￿→ ￿c￿ ; c1, σ ￿￿ 0 (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]￿ (by (seq s)) ￿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 reﬂect 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 ]￿ (assgn) (seq t) (decl s) ￿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 reﬂexive and transitive closure of ￿→ can also be deﬁned using inference rules: γ ￿→ γ ￿ (incl) γ ￿→∗ γ ￿ (reﬂ) γ ￿→∗ γ γ ￿→∗ γ ￿ γ ￿ ￿→∗ γ ￿￿ (trans) γ ￿→∗ γ ￿￿ Meaning of Commands ￿→ ∈ ΓN → Γ (total function) ⇒ ∀γ ∈ Γ there is a longest execution starting from γ , either inﬁnite or ending with a γ ￿ ∈ ΓT = Σ. ⊥, if ￿c, σ ￿ ↑ [[c]]comm σ = ￿ σ , if ￿c, σ ￿ ￿→∗ σ ￿ Transition Semantics of Failure Deﬁne ΓT = Σ ∪ ({abort} × Σ). Then (fail) Propagation of failure: ￿fail, σ ￿ ￿→ ￿abort, σ ￿ ￿c0, σ ￿ ￿→ ￿abort, σ ￿ (seq x) ￿c0 ; c1, σ ￿ ￿→ ￿abort, σ ￿￿ (decl x) ￿c, [σ | v : [[e]]intexp σ ]￿ ￿→ ￿abort, σ ￿￿ ￿newvar v :=e in c, σ ￿ ￿→ ￿abort, [σ ￿ | v : σ v ]￿ The semantics of commands becomes ⊥, [[c]]comm σ = σ ￿, ￿abort σ ￿￿, if ￿c, σ ￿ ↑ if ￿c, σ ￿ ￿→∗ σ ￿ if ￿c, σ ￿ ￿→∗ ￿abort σ ￿￿ Labeled Transition Semantics of Input and Output Informally: Write labels on transitions to show input or output. Rules: (output) (input) !n ￿!e, σ ￿ ￿→ σ when n = [[e]]intexp σ ?n ￿?v , σ ￿ ￿→ [σ | v : n] Formally, the transition “relation” becomes ternary: ￿→ ⊆ ΓN × Λ × Γ, where Λ = {￿} ∪ {?n | n ∈ Z} ∪ {!n | n ∈ Z} λ and ￿c, σ ￿ ￿→ γ stands for ￿￿c, σ ￿, λ, γ ￿ ∈ ￿→. (￿ is silent ) Labeled Transition Semantics cont’d The other rules are generalized to propagate the labels, e.g. λ (seq t) (seq s) ￿c0, σ ￿ ￿→ σ ￿ λ ￿c0 ; c1, σ ￿ ￿→ ￿c1, σ ￿￿ λ ￿c0, σ ￿ ￿→ ￿c￿ , σ ￿￿ 0 λ ￿c0 ; c1, σ ￿ ￿→ ￿c￿ ; c1, σ ￿￿ 0 λ (seq x) ￿c0, σ ￿ ￿→ ￿abort, σ ￿ λ ￿c0 ; c1, σ ￿ ￿→ ￿abort, σ ￿￿ Properties of the Labeled Transition Semantics If γ = ￿c, σ ￿ ∈ ΓN , then exactly one of these holds: ∃!γ ￿ ∈ Γ such that γ ￿→ γ ￿ (silent transition) !n ∃!γ ￿ ∈ Γ, n ∈ Z such that γ ￿→ γ ￿ λ {λ ∈ Λ | γ ￿ ∈ Γ and γ ￿→ γ ￿} = {?n | n ∈ Z} Hence for every γ ∈ Γ there is a longest sequence of silent transitions which is either inﬁnite ends with a γ ￿ ∈ ΓT !n ends with a γ ￿ ∈ ΓN such that ∃!γ ￿￿ ∈ Γ, n ∈ Z such that γ ￿ ￿→ γ ￿￿ ?n ends with a γ ￿ ∈ ΓN such that ∀n ∈ Z. ∃γ ￿￿ ∈ Γ. γ ￿ ￿→ γ ￿￿. Relationship with the Denotational Semantics So, for every γ ∈ Γ there is a longest sequence of silent transitions which is either inﬁnite ends with a γ ￿ ∈ ΓT !n ends with a γ ￿ ∈ ΓN such that ∃!γ ￿￿ ∈ Γ, n ∈ Z such that γ ￿ ￿→ γ ￿￿ ?n ends with a γ ￿ ∈ ΓN such that ∀n ∈ Z. ∃γ ￿￿ ∈ Γ. γ ￿ ￿→ γ ￿￿. ∼ˆ If Ω = (Σ + (Z × Ω) + [Z → Ω])⊥ and F ∈ [Γ → Ω] is the least solution of ⊥, ι term σ ￿, ￿ F γ = ιabort σ , ι out ￿n, F γ ￿￿￿, ι (λn ∈ Z. F γ ), n in then [[c]]comm σ = F ￿c, σ ￿. if γ ↑ if γ ￿→∗ σ ￿ if γ ￿→∗ ￿abort, σ ￿￿ !n if ∃γ ￿. γ ￿→∗ γ ￿ and γ ￿ ￿→ γ ￿￿ ?n if ∃γ ￿ ∈ Γ. ∀n ∈ Z. γ ￿→∗ γ ￿ and γ ￿ ￿→ γn ...
View Full Document

## This document was uploaded on 02/20/2012.

Ask a homework question - tutors are online