Operational Semantics Program Testing and Analysis€¦ · Representations of programs This...

28
1 Program Testing and Analysis: Operational Semantics Prof. Dr. Michael Pradel Software Lab, TU Darmstadt

Transcript of Operational Semantics Program Testing and Analysis€¦ · Representations of programs This...

Page 1: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

1

Program Testing and Analysis:

Operational Semantics

Prof. Dr. Michael Pradel

Software Lab, TU Darmstadt

Page 2: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

2

Warm-up Quiz

var e = eval;

(function f() {var x = 5;e("x=7")console.log(x);

})();

What does the following code print?

Options: 5, 7, or something else

Page 3: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

3

Warm-up Quiz

var e = eval;

(function f() {var x = 5;e("x=7")console.log(x);

})();

Correct answer: 5

Page 4: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

3

Warm-up Quiz

var e = eval;

(function f() {var x = 5;e("x=7")console.log(x);

})();

Correct answer: 5

eval() evaluatesJavaScript codegiven as a string

Page 5: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

3

Warm-up Quiz

var e = eval;

(function f() {var x = 5;e("x=7")console.log(x);

})();

Correct answer: 5

Store function into variable(functions are first-classobjects)

Page 6: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

3

Warm-up Quiz

var e = eval;

(function f() {var x = 5;e("x=7")console.log(x);

})();

Correct answer: 5

Define a function andcall it immediately

Page 7: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

3

Warm-up Quiz

var e = eval;

(function f() {var x = 5;e("x=7")console.log(x);

})();

Correct answer: 5

Indirect eval():Works in globalscope rather thanlocal scope

Page 8: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

4

Big Picture

Last lecture:� Syntax of languages

� Representations of programs

This lecture:� Assign meaning (= semantics) to programs

� Focus: Operational semantics of imperativelanguages

� Formal foundation for specifying languages andfor describing dynamic analyses

Page 9: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

5

Plan for Today

� Motivation & preliminaries

� Abstract syntax of SIMP

� An abstract machine for SIMP

� Structural operation semantics forSIMP� Small-step semantics

� Big-step semantics

Page 10: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

1

Page 11: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

2

Page 12: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

3

Page 13: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

4

Page 14: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

5

Page 15: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

6

Page 16: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

6

Plan for Today

� Motivation & preliminaries

� Abstract syntax of SIMP

� An abstract machine for SIMP

� Structural operation semantics forSIMP� Small-step semantics

� Big-step semantics

Page 17: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

7

Page 18: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

8

Page 19: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

9

Page 20: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

10

Page 21: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

11

Page 22: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

7

Plan for Today

� Motivation & preliminaries

� Abstract syntax of SIMP

� An abstract machine for SIMP

� Structural operation semantics forSIMP� Small-step semantics

� Big-step semantics

Page 23: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

12

Page 24: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

13

Page 25: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

14

Page 26: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

15

Page 27: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

16

Page 28: Operational Semantics Program Testing and Analysis€¦ · Representations of programs This lecture: Assign meaning (= semantics) to programs Focus: Operational semantics of imperative

17