Notes #5

# Notes #5 - Operational Semantics References Kurtz(Ch 8.4...

This preview shows pages 1–8. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

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

Unformatted text preview: Operational Semantics References: Kurtz (Ch. 8.4, 8.5, 8.6) Many ways to define o.s.: 1. Define an interpreter for the language. 2. Define a compiler for the language, plus an interpreter for the assembly language used. 3. Specify how the state changes as various commands are executed. We will discuss the third approach now. 71 We will define a relation h c,σ i → σ to mean that the execution of c starting in σ terminates in σ . Example: h skip ,σ i → σ We also need to define h ae,σ i → n if the value of ae in σ is n . And, h be,σ i → bv if the value of be in σ is bv . Questions: 1. What if ae or be are not well defined? 2. What if ae or be have side-effects? 72 Arithmetic expressions: First the syntax: a ::= n | X | a + a 1 | a- a 1 | a × a 1 h n,σ i → n h X,σ i → σ ( X ) h a ,σ i → n , h a 1 ,σ i → n 1 h a + a 1 ,σ i → n where n is the sum of n and n 1 . h a ,σ i → n , h a 1 ,σ i → n 1 h a × a 1 ,σ i → n where n is the product of n and n 1 . h a ,σ i → n , h a 1 ,σ i → n 1 h a- a 1 ,σ i → n where n is the difference between n and n 1 . Using these we can, for instance, derive, h X + Y, σ i → 10 if σ ( X ) = 4 and σ ( Y ) = 6 73 Operational semantics of boolean expressions: First the syntax: b ::= true | false | a = a 1 | a ≤ a 1 | ¬ b | b ∧ b 1 | b ∨ b 1 h true ,σ i → true h false ,σ i → false h a ,σ i → n , h a 1 ,σ i → n 1 if n , n 1 are equal h a = a 1 ,σ i → true h a ,σ i → n , h a 1 ,σ i → n 1 if n , n 1 not equal. h a = a 1 ,σ i → false h a ,σ i → n , h a 1 ,σ i → n 1 if n less/equal to n 1 . h a ≤ a 1 ,σ i → true h a ,σ i → n , h a 1 ,σ i → n 1 if n greater than n 1 h a ≤ a 1 ,σ i → false h b,σ i → true h¬ b,σ i → false h b,σ i → false h¬ b,σ i → true 74 h b ,σ i → t , h b 1 ,σ i → t 1 h b ∧ b 1 ,σ i → t where t is true if both t and t 1 are true, and false otherwise. Or better: h b ,σ i → false h b ∧ b 1 ,σ i → false h b ,σ i → true , h b 1 ,σ i → false h b ∧ b 1 ,σ i → false h b ,σ i → true , h b 1 ,σ i → true h b ∧ b 1 ,σ i → true b ∨ b 1 is similar. 75 Commands : Notation: the state σ [ m/X ] is the same as σ except the value of X in the former is m (rather than σ ( X ) ). In other words, σ [ m/X ]( Y ) = m if X ≡ Y and σ ( Y ) if X 6≡ Y σ [ m/X ] is also written σ [ X ← m ]. h skip ,σ i → σ h a,σ i → m h X := a,σ i → σ [ m/X ] h c ,σ i → σ , h c 1 ,σ i → σ 00 h c ; c 1 ,σ i → σ 00 ***Need to define read and write. 76 h b,σ i → true , h c ,σ i → σ h if b then c else c 1 ,σ i → σ h b,σ i → false , h c 1 ,σ i → σ h if b then c else c 1 ,σ i → σ h b,σ i → false h while b do c,σ i → σ h b,σ i → true , h c,σ i → σ , h while b do c,σ i → σ 00 h while b do c,σ i → σ 00 This semantics is coarse , i.e., the details of the in- dividual steps are lost. It is also called ‘natural semantics’ or ‘big-step semantics’. (Slonnegarsemantics’ or ‘big-step semantics’....
View Full Document

{[ snackBarMessage ]}

### Page1 / 28

Notes #5 - Operational Semantics References Kurtz(Ch 8.4...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online