Big Step Semantics Dr. Mattox Beckman University of Illinois at - - PowerPoint PPT Presentation

big step semantics
SMART_READER_LITE
LIVE PREVIEW

Big Step Semantics Dr. Mattox Beckman University of Illinois at - - PowerPoint PPT Presentation

Introduction The Rules Proof Trees Conclusion Big Step Semantics Dr. Mattox Beckman University of Illinois at Urbana-Champaign Department of Computer Science Introduction The Rules Proof Trees Conclusion Objectives Describe the


slide-1
SLIDE 1

Introduction The Rules Proof Trees Conclusion

Big Step Semantics

  • Dr. Mattox Beckman

University of Illinois at Urbana-Champaign Department of Computer Science

slide-2
SLIDE 2

Introduction The Rules Proof Trees Conclusion

Objectives

◮ Describe the components of a big step semantic rule. ◮ Use semantic rules to document the meaning of simple programming language. ◮ Explain the correspondence between big step semantics and the eval function.

slide-3
SLIDE 3

Introduction The Rules Proof Trees Conclusion

Grammar for Simple Imperative Programming Language

The Language

S ::= skip | u := A | S1; S2 | if B then S1 else S2 fi | while B do S1 od B ::= E ∼ E | true | false E ::= u | int | E ⊕ E

◮ Let u be a possibly subscripted variable. ◮ E represents arithmetic expressions, ⊕ is an arithmetic operator. ◮ B represents boolean expressions,

represents relationals.

slide-4
SLIDE 4

Introduction The Rules Proof Trees Conclusion

The Downarrow Notation

◮ In small step semantics we use the → to represent one step of computations. ◮ In big step semantics we use ⇓ to represent an entire evaluation.

Statements < S, σ >⇓ σ′ Expressions < E, σ >⇓e v Booleans < B, σ >⇓b b

slide-5
SLIDE 5

Introduction The Rules Proof Trees Conclusion

Expressions

Integers

Const < i, σ >⇓e i if i is an integer.

Variables

Var < u, σ >⇓e v if u := v ∈ σ.

Operations

< e1, σ >⇓e v1 < e2, σ >⇓e v2 Arith < e1 ⊕ e2, σ >⇓e v1 ⊕ v2 Here ⊕ represents typical binary operations like +, −, ×, etc.

slide-6
SLIDE 6

Introduction The Rules Proof Trees Conclusion

Boolean Expressions

Booleans

Const < b, σ >⇓b b if b is a boolean.

Variables

Var < u, σ >⇓b v if u := v ∈ σ.

Relational Operators

< e1, σ >⇓e v1 < e2, σ >⇓e v2 Rel < e1 ∼ e2, σ >⇓b v1 ∼ v2 Here ∼ represents the binary relational operations =, ≤, ≥, =, ≥, ≤, etc.

slide-7
SLIDE 7

Introduction The Rules Proof Trees Conclusion

Skip and Assignment

Skip < skip , σ >⇓ σ < e, σ >⇓e v Assign < x := e, σ >⇓ σ[x := v]

slide-8
SLIDE 8

Introduction The Rules Proof Trees Conclusion

Skip and Assignment

Skip < skip , σ >⇓ σ < e, σ >⇓e v Assign < x := e, σ >⇓ σ[x := v] Next is sequencing. See if you can guess what the rule looks like.

slide-9
SLIDE 9

Introduction The Rules Proof Trees Conclusion

Sequencing

< S1, σ >⇓ σ′ < S2, σ′ >⇓ σ′′ Seq < S1; S2, σ >⇓ σ′′

slide-10
SLIDE 10

Introduction The Rules Proof Trees Conclusion

Sequencing

< S1, σ >⇓ σ′ < S2, σ′ >⇓ σ′′ Seq < S1; S2, σ >⇓ σ′′ Next is if . There are two rules for this. See if you can guess what the rules looks like.

slide-11
SLIDE 11

Introduction The Rules Proof Trees Conclusion

If Statements

< B, σ >⇓b true < S1, σ >⇓ σ′ If1 < if B then S1 else S2 fi , σ >⇓ σ′ < B, σ >⇓b false < S2, σ >⇓ σ′ If2 < if B then S1 else S2 fi , σ >⇓ σ′

slide-12
SLIDE 12

Introduction The Rules Proof Trees Conclusion

If Statements

< B, σ >⇓b true < S1, σ >⇓ σ′ If1 < if B then S1 else S2 fi , σ >⇓ σ′ < B, σ >⇓b false < S2, σ >⇓ σ′ If2 < if B then S1 else S2 fi , σ >⇓ σ′ Next is while . There are two rules for this. See if you can guess what the rules looks like. The second one uses induction!

slide-13
SLIDE 13

Introduction The Rules Proof Trees Conclusion

While Statements

< B, σ >⇓b false While1 < while B do S od , σ >⇓ σ < B, σ >⇓b true < S, σ >⇓ σ′ < while B do S od , σ′ >⇓ σ′′ While2 < while B do S od , σ >⇓ σ′′

slide-14
SLIDE 14

Introduction The Rules Proof Trees Conclusion

Proof Trees

◮ To show the effect of a program, we need to build proof trees. ◮ Let σ = {x := 3, y := 4}. ◮ We want to prove that 2 × y + 9 × x = 35.

Here is what we want to evaluate. What kind of expression is this? < 2 × y + 9 × x, σ >⇓e 35

slide-15
SLIDE 15

Introduction The Rules Proof Trees Conclusion

Proof Trees

◮ To show the effect of a program, we need to build proof trees. ◮ Let σ = {x := 3, y := 4}. ◮ We want to prove that 2 × y + 9 × x = 35.

Because of precedence rules, we evaluate the + last. < 2 × y, σ >⇓e 8 < 9 × x, σ >⇓e 27 Arith < 2 × y + 9 × x, σ >⇓e 35

slide-16
SLIDE 16

Introduction The Rules Proof Trees Conclusion

Proof Trees

◮ To show the effect of a program, we need to build proof trees. ◮ Let σ = {x := 3, y := 4}. ◮ We want to prove that 2 × y + 9 × x = 35.

We go up one more level, and then we are done.

Const < 2, σ >⇓e 2 Var < y, σ >⇓e 4 Arith < 2 × y, σ >⇓e 8 Const < 9, σ >⇓e 9 Var < x, σ >⇓e 3 Arith < 9 × x, σ >⇓e 27 Arith < 2 × y + 9 × x, σ >⇓e 35

slide-17
SLIDE 17

Introduction The Rules Proof Trees Conclusion

Statement Proof Tree

◮ Let σ = {x := 10, y := 20}. ◮ Let σ′ = {x := 10, y := 20, m := 20}.

Here is an example that will use all three versions of ⇓. < if x > y then m := x else m := 2 × x fi , σ >⇓ σ′ Can you fjgure out what this tree should look like?

slide-18
SLIDE 18

Introduction The Rules Proof Trees Conclusion

Statement Proof Tree

◮ Let σ = {x := 10, y := 20}. ◮ Let σ′ = {x := 10, y := 20, m := 20}.

Rel < x > y, σ >⇓b false Assign < m := 2 × x, σ >⇓ σ′ If2 < if x > y then m := x else m := 2 × x fi , σ >⇓ σ′

slide-19
SLIDE 19

Introduction The Rules Proof Trees Conclusion

Statement Proof Tree

◮ Let σ = {x := 10, y := 20}. ◮ Let σ′ = {x := 10, y := 20, m := 20}.

Var < x, σ >⇓e 10 Var < y, σ >⇓e 20 Rel < x > y, σ >⇓b false Const < 2, σ >⇓e 2 Var < x, σ >⇓e 10 Assign < m := 2 × x, σ >⇓ σ′ If2 < if x > y then m := x else m := 2 × x fi , σ >⇓ σ′

slide-20
SLIDE 20

Introduction The Rules Proof Trees Conclusion

Connecting to Interpreters

◮ The ⇓ is really just eval that you already know and love. ◮ The σ is just the env parameter.