CORNELL CS 611 - Lecture 3 Small-Step Semantics

Unformatted text preview:

CS611 Lecture 3 Small-Step Semantics September 5, 2001Scribe: Michael Brukman & Michael Kamzyuk Lecturer: Andrew MyersA configuration is a tuple of the form c, σ,wherec is the command to be executed, and σ is thecurrent store. The program terminates when we reach a configuration of the form skip, σ. The idea behindsmall-step semantics is that we make one small step at a time. A small step is the evaluation of some part ofthe expression. The notation is as follows: if a denotes some arithmetic expression, then adenotes a afterone small step was made. Similarly, if b is a boolean expression, then bis b after one small step. Thesenotes cover the small-step semantics.Rules are of the form c, σ →c,σ,where →⊆ (Com × Store) × (Com × Store)1 Commands1.1 Skipskip, σ - we are at the final step. No rule is needed.1.2 Assignmenta, σ →a,σx := a, σ →x := a,σ x := n, σ →skip,σ[x → n]1.3 ; (Semicolon)c0,σ →c0,σc0; c1,σ →c0; c1,σ skip; c1,σ →skip,σ[x → n]1.4 Ifb, σ →a,σif b then c0else c1,σ →if bthen c0else c1,σif true then c0else c1 →c0,σ if false then c0else c1 →c1,σ1.5 Whilewhile b do c, σ →if b then (c; while b do c)else skip,σ1.6 Variable evaluationx, σ →σ(x),σ12 Order of evaluationSome rules enforce the order of evaluation and other rules actually evaluate. For instance, simply havingthe rule on the left will force left-to-right evaluation, while having both allows evaluation of the right sidebefore the evaluation of the left side has been completed:a0,σ →a0,σa0⊕ a1,σ →a0⊕ a1,σa1,σ →a1,σa0⊕ a1,σ →a0⊕ a1,σ3 Arithmetic ExpressionsEvaluation of arithmetic expressions proceeds as normal with addition (left rule):n = n0⊕ n1,σn0⊕ n1,σ →n, σn = n0÷ n1,σn0÷ n1,σ →n, σThe rule for division (right rule above), however, cannot be accepted since it may result in a runtimeerror on 2 ÷ 0,σ → ?, resulting in a stuck configuration.4 ParallelismSince the commands in the language IMP may lack interdependency on each other, we may allow commandevaluation to proceed in parallel as given by these inference rules:c0,σ →c0,σc0|c1,σ →c0|c1,σc1,σ →c1,σc0|c1,σ →c0|c1,σThis allows evaluation of either commands in a pair of parallel commands proceed before completion ofevaluation of the other.5 Non-determinismNon-determinism allows us to specify that either of two commands will be executed at run time:c0 c1,σ →c0,σ c0 c1,σ →c1,σIt is interesting to note that we could not specify either par allelism or non-determinism using large-stepsemantics, but small-step semantics allow us to express both succinctly.6 Equivalence of Large- and Small-Step SemanticsIn addition, it turns out that large-step semantics are equivalent to small-step semantics. Define the relation →∗as follows:c, σ →∗c, σc, σ →c,σc,σ →∗c,σc, σ →∗c,σTheideaistoprovethatc, σ⇓σ⇐⇒  a, σ →∗sk ip, σProof (this lecture covered only arithmetic expressions): by induction on the depth of the abstract syntaxtree of the expression. For arithmetic expressions we need•a, σ⇓n ⇐⇒  a, σ →∗n, σ2•x, σ⇓σ(x) ⇐⇒  x, σ →∗σ(x),σ•a0⊕ a1,σ⇓n ⇐⇒  a0⊕ a1,σ →∗n, σThe first two cases are trivial.Now assume a0⊕ a1,σ⇓n.Thena0,σ⇓n0and a1,σ⇓n1,wheren0⊕ n1= n. By inductionhypothesis, a0,σ →∗n0,σ and a0,σ →∗n0,σ , since the tree associated with a0and the treeassociated with a1are both less deep than the tree associated with a0⊕ a1. Therefore, by induction, wehave a0,σ →∗n0,σ,anda0,σ →∗n0,σ.Thus,a0⊕ a1,σ →∗n0⊕ a1,σ →∗n0⊕ n1,σ →n, σ.The other direction was not covered in


View Full Document

CORNELL CS 611 - Lecture 3 Small-Step Semantics

Download Lecture 3 Small-Step Semantics
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 3 Small-Step Semantics and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 3 Small-Step Semantics 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?