Download presentation
Presentation is loading. Please wait.
1
Programming Language Semantics Mooly SagivEran Yahav msagiv@postmsagiv@postyahave@post Schrirber 317Open space 03-640-760603-640-5358 html://www.cs.tau.ac.il/~msagiv/courses/sem03.html Textbook:Winskel The Formal Semantics of Programming Languages CS 0368-4348-01@listserv.tau.ac.il
2
Outline Course note summary Natural operational semantics –Commands –Example –Proving simple properties Small step operational semantics –The main ideas Proving properties of programs (Chapter 3)
3
Course note summary Word format Add examples for every term Add strawman examples Self contained
4
Abstract Syntax for IMP Aexp –a ::= n | X | a 0 + a 1 | a 0 – a 1 | a 0 a 1 Bexp –b ::= true | false | a 0 = a 1 | a 0 a 1 | b | b 0 b 1 | b 0 b 1 Com –c ::= skip | X := a | c 0 ; c 1 | if b then c 0 else c 1 | while b do c
5
Expression Evaluation States –Mapping locations to values – - The set of states : Loc N (X)= X=value of X in = [ X 5, Y 7] –The value of X is 5 –The value of Y is 7 –The value of Z is undefined – For a Exp, , n N, n –a is evaluated in to n
6
Expression Evaluation Rules Numbers – n Locations – (X) Sums Subtractions Products Axioms
7
Equivalence of IMP expressions a0 a1a0 a1 iff 2+3 ~ 5 exp 1 + exp 2 ~ exp 2 + exp 1
8
Boolean Expression Evaluation Rules true false
9
Boolean Expression Evaluation Rules(cont)
10
Equivalence of Boolean expressions b0 b1b0 b1 iff
11
The execution of commands ’ –c terminates on in a final state ’ Initial state 0 – 0 (X)=0 for all X Handling assignments ’ [5/X]
12
Rules for commands Sequencing: Conditionals: Atomic
13
Rules for commands (while) Euclid while (M=N) do if M N then N := N – M else M := M - N =[M 6, N 9]
14
Rules for commands (while) Loop while true do skip
15
Equivalence of commands c0 c1c0 c1 iff
16
Proposition 2.8 while b do c if b then (c; while b do c) else skip
17
Theorem 3.10 For all states : (M) 1 & (N) 1 ’ : ’
18
Small Step Operational Semantics The natural semantics defines evaluation in large steps –Abstracts “computation time” It is possible to define a small step operational semantics – 1 “one” step of executing a in a state yields a’ in a state ’
19
Small Step Semantics for Additions Homework
20
Summary Operational semantics enables to naturally express program behavior Can handle –Non determinism –Concurrency –Procedures –Object oriented –Pointers and dynamically allocated structures But remains very closed to the implementation –Two programs which compute the same functions are not necessarily equivalent
21
Induction Proving of program properties often uses mathematical induction Prove properties of a programming language by proving a small finite set of claims If a property is violated then there is a small finite set in which it is violated Examples – m & m m = n –Euclid terminates – ’ & ’ = ’’
22
Forms of induction Mathematical induction –(P(0) & ( m w. P(m) P(m+1))) m w. P(m) Structural induction Well-founded induction
23
Structural Induction Proposition 3.3 – m & m m = n Bad example – ’ & ’’ ’ = ’’
24
Well-Founded Induction A well-founded relation on a set A if –there are no infinite decreasing chains … a i … a 2 a 1 –a b a is a predecessor of b Proposition 3.7 a binary relation on A is well-founded iff any nonempty subset Q of A has a minimal element, m Q: b m. b Q
25
The Principle of Well Founded Induction is a well founded relation on A P is property Then – a A: P(a) –Iff – a A: ([ b a. P(b)] P(a)
26
Applications of the well founded induction principle Mathematical induction Course-of-values induction Structural induction …
27
Induction on Derivations A set of rule instances R consists pairs X/y where X is a finite set and y is an element –X/y – rule instance –X – premises –y – conclusion d R y – d is an R-derivation of y –( /y) R y if ( /y) R –({d 1, …, d n }/y) R y if ({x 1, …, x n }/y) R and d 1 R x 1 & … & d n R x n R y – for some d d R y Sub-derivation d 1 d’ if d (D/y) with d’ D = 1 + is well-founded
28
Theorem 3.10 For all states : (M) 1 & (N) 1 ’ : ’
29
Theorem 3.11 For all states , ’, ’’: – ’ & ’’ ’ = ’’
30
Proposition 3.12 For all states , ’: ’
31
Summary Induction is a powerful tool in proving semantic properties Can also be used in definitions –length(a)= # of operators in a –Loc L (c) = left-hand-side variables –Lval(a) –Rval(a)
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.