CS 476 Programming Language Design William Mansky Programming

  • Slides: 28
Download presentation
CS 476 – Programming Language Design William Mansky

CS 476 – Programming Language Design William Mansky

Programming Language Metatheory • We’ve used inference rules and proof trees to describe the

Programming Language Metatheory • We’ve used inference rules and proof trees to describe the behavior of programs • We can also use them to prove properties about the language itself! ― If a program is has a type, then its result has the same type ― Big-step and small-step semantics allow the same behaviors ― The interpreter correctly implements the language semantics 1

Programming Language Metatheory • We can also use them to prove properties about the

Programming Language Metatheory • We can also use them to prove properties about the language itself! ― If a program is has a type, then its result has the same type ― Big-step and small-step semantics allow the same behaviors ― The interpreter correctly implements the language semantics • The properties of the different systems that define the language are called its metatheory • Metatheory is (part of) why we bother with all these systems! ― We use a type system because it guarantees something about the execution of well-typed programs. ― We write semantics because it gives us a way of telling whether an interpreter is correct. 2

Metatheory #1: Type Safety • 3

Metatheory #1: Type Safety • 3

Proving Progress: Rule Induction • 4

Proving Progress: Rule Induction • 4

Proving Progress: Rule Induction • 5

Proving Progress: Rule Induction • 5

Expressions: Types • Types: int, bool • Rules: 6

Expressions: Types • Types: int, bool • Rules: 6

Proving Progress: Rule Induction • 7

Proving Progress: Rule Induction • 7

Proving Progress: Rule Induction • 8

Proving Progress: Rule Induction • 8

Proving Progress: Base Cases • 9

Proving Progress: Base Cases • 9

Proving Progress: Inductive Cases • 10

Proving Progress: Inductive Cases • 10

Proving Progress: Inductive Cases •

Proving Progress: Inductive Cases •

Proving Progress: Rule Induction • 12

Proving Progress: Rule Induction • 12

Proving Preservation • 13

Proving Preservation • 13

Proving Preservation: Base Cases • 14

Proving Preservation: Base Cases • 14

Proving Preservation: Inductive Cases • 15

Proving Preservation: Inductive Cases • 15

Expressions: Type Safety • 16

Expressions: Type Safety • 16

Small-Step vs. Big-Step Small-Step • Includes intermediate states • Allows control of evaluation order

Small-Step vs. Big-Step Small-Step • Includes intermediate states • Allows control of evaluation order • Can count the number of steps Big-Step • Doesn’t need structural rules • Turns into a more direct interpreter • Sometimes internal steps don’t matter Why not both? 17

Big- and Small-Step Equivalence • 18

Big- and Small-Step Equivalence • 18

Big to Small: Base Cases • 19

Big to Small: Base Cases • 19

Big to Small: Inductive Cases • 20

Big to Small: Inductive Cases • 20

Big to Small: Inductive Cases • 21

Big to Small: Inductive Cases • 21

Big to Small: Inductive Cases • 22

Big to Small: Inductive Cases • 22

Big to Small: Inductive Cases • 23

Big to Small: Inductive Cases • 23

Big to Small: Inductive Cases • 24

Big to Small: Inductive Cases • 24

Big- and Small-Step Equivalence • 25

Big- and Small-Step Equivalence • 25

Small to Big • 26

Small to Big • 26

Class Project (for 4 -credit students only) • Work alone or in group of

Class Project (for 4 -credit students only) • Work alone or in group of 2 -3 • Project ideas: ― Read a paper about an interesting language/feature and write semantics or interpreter for it ― Define and implement a stronger/more interesting type system for an existing language ― Prove equivalence of two semantics for a language, by hand or mechanically ― Design and implement a small domain-specific language • Project proposal due 10/12, but email me anytime! 27