David Evans CS655: Programming Languages University of Virginia Computer Science Lecture 13: Operational Semantics “Then.

Slides:



Advertisements
Similar presentations
David Evans CS655: Programming Languages University of Virginia Computer Science Lecture 6: Types of Types “It would.
Advertisements

Class 39: Universality cs1120 Fall 2009 David Evans University of Virginia.
David Evans CS200: Computer Science University of Virginia Computer Science Class 27: Modeling Computation.
Week 7 - Wednesday.  What did we talk about last time?  Set proofs and disproofs  Russell’s paradox.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 39: Lambda Calculus.
David Evans CS655: Programming Languages University of Virginia Computer Science Lecture 19: Minding Ps & Qs: Axiomatic.
ISBN Chapter 3 Describing Syntax and Semantics.
CS 330 Programming Languages 09 / 19 / 2006 Instructor: Michael Eckmann.
1 Semantic Description of Programming languages. 2 Static versus Dynamic Semantics n Static Semantics represents legal forms of programs that cannot be.
CS 355 – Programming Languages
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming The software development method algorithms.
1 Introduction to Computability Theory Lecture15: Reductions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture12: Reductions Prof. Amos Israeli.
FLAC Lecture 19 Turing Machines and Real Life * Reductions Mihai Budiu March 3, 2000.
CPSC 411, Fall 2008: Set 12 1 CPSC 411 Design and Analysis of Algorithms Set 12: Undecidability Prof. Jennifer Welch Fall 2008.
1 Undecidability Andreas Klappenecker [based on slides by Prof. Welch]
Reasons to study concepts of PL
CS 330 Programming Languages 09 / 18 / 2007 Instructor: Michael Eckmann.
Computability and Complexity 3-1 Turing Machine Computability and Complexity Andrei Bulatov.
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
Tim Sheard Oregon Graduate Institute Lecture 11: A Reduction Semantics for MetaML CS510 Section FSC Winter 2005 Winter 2005.
Describing Syntax and Semantics
CS 104 Introduction to Computer Science and Graphics Problems Software and Programming Language (2) Programming Languages 09/26/2008 Yang Song (Prepared.
David Evans CS200: Computer Science University of Virginia Computer Science Class 31: Universal Turing Machines.
ITP © Ron Poet Lecture 1 1 IT Programming Introduction.
Programming Languages CPS120: Introduction to Computer Science Lecture 5.
The following is a conditional statement: If I go to the mall, then I use my credit card. If I use my credit card, I must be at the mall. What do you think.
High level & Low level language High level programming languages are more structured, are closer to spoken language and are more intuitive than low level.
Cs3102: Theory of Computation Class 18: Proving Undecidability Spring 2010 University of Virginia David Evans.
Class 37: Computability in Theory and Practice cs1120 Fall 2011 David Evans 21 November 2011 cs1120 Fall 2011 David Evans 21 November 2011.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
3.2 Semantics. 2 Semantics Attribute Grammars The Meanings of Programs: Semantics Sebesta Chapter 3.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Semantics In Text: Chapter 3.
Syntax and Semantics CIS 331 Syntax: the form or structure of the expressions, statements, and program units. Semantics: the meaning of the expressions,
CS 655: Programming Languages David Evans Office 236A, University of Virginia Computer.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 36: Modeling Computing.
Introduction CPSC 388 Ellen Walker Hiram College.
Data Structures and Algorithms Dr. Tehseen Zia Assistant Professor Dept. Computer Science and IT University of Sargodha Lecture 1.
David Evans CS655: Programming Languages University of Virginia Computer Science Lecture 14: Types of Types “It would.
David Evans CS655: Programming Languages University of Virginia Computer Science Lecture 21: Proof-Carrying Code and.
CSCI1600: Embedded and Real Time Software Lecture 28: Verification I Steven Reiss, Fall 2015.
Programming Language Descriptions. What drives PL Development? Computers are “in charge” of extremely important issues Execute a program literally. Exercise.
Introduction CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
David Evans Class 15: P vs. NP (Smiley Puzzles and Curing Cancer) CS150: Computer Science University of Virginia Computer.
David Evans CS200: Computer Science University of Virginia Computer Science Class 32: The Meaning of Truth.
Programming Language Concepts (CIS 635) Elsa L Gunter 4303 GITC NJIT,
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
David Evans CS200: Computer Science University of Virginia Computer Science Class 32: The Meaning of Truth.
Week 7 - Wednesday.  What did we talk about last time?  Proving the subset relationship  Proving set equality  Set counterexamples  Laws of set algebra.
Chapter 2 Reasoning and Proof 2.1 Conditional Statements.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
David Evans CS200: Computer Science University of Virginia Computer Science Class 26: Halting Problem It is plain at any.
(Thunking about Thunks)
Lecture 4: Metacircles Eval Apply David Evans
Component 1.6.
Lecture 2: Schreme David Evans
Class 27: Universal Turing Machines CS150: Computer Science
Lecture 37: A Universal Computer
Lambda Calculus Revisited
Compiler Construction
Lecture 25: Metalinguistics > (meval '((lambda (x) (* x x)) 4)
Class 33: Making Recursion M.C. Escher, Ascending and Descending
Lecture 10: Fixed Points ad Infinitum M.C. Escher, Moebius Ants
Program Execution.
David Evans Lecture 19: ||ism I don’t think we have found the right programming concepts for parallel computers yet.
Class 26: Modeling Computing CS150: Computer Science
Lecture 15: Crazy Eddie and the Fixed Points Background
Lecture 23: Computability CS200: Computer Science
Presentation transcript:

David Evans CS655: Programming Languages University of Virginia Computer Science Lecture 13: Operational Semantics “Then you should say what you mean,” the March Hare went on. “I do,” Alice hastily replied; “at least – at least I mean what I say – that’s the same thing, you know.” “Not the same thing a bit!” said the Hatter. “Why, you might as well say that ‘I see what I eat’ is the same thing as ‘I eat what I see’!" Lewis Carrol, Alice in Wonderland “When I use a word,” Humpty Dumpty said, in a rather scornful tone, “it means just what I choose it to mean – neither more nor less.” Lewis Carroll, Through the Looking Glass

1 March 2001CS 655: Lecture132 Menu Quiz Results Intro to Formal Semantics Operational Semantics

1 March 2001CS 655: Lecture133 Quiz Results Preferences –Mostly formal techniquesx –Balancedxx –Mostly language designxxxxx –Just language designxx Mock Trial –Heard aboutYes6No3 Yes, very 1 Yes 2 Maybe 1.5 No, research0.5 No, sleeping 1 Speed: way too fast (0), too fast (6), wrote in just right/both (3), too slow (1)

1 March 2001CS 655: Lecture134 Other Comments “disappointed to hear that there were no more programming assignments...I’d be interested in playing with and analyzing languages like Smalltalk, CLU, and APL...” “though I’ve found a good deal of the material interesting, I don’t necessarily feel entirely prepared to write a Why X is not my favorite Programming Language” “I’m tired of Scheme...mostly because the MIT scheme interpreter is poorly written and doesn’t allow you to easily perform editing operations...” Run M-x scheme in emacs

1 March 2001CS 655: Lecture135 Other Comments “complaint is that we’re doing homework on old stuff that is no longer focused on in class, making it difficult for me to devote my energies to the new stuff.” “hasn’t taken the approach I would’ve expected – such as covering PL concepts (types, binding, etc.) in the context of a range of languages” “hope we can get lectures before class, so that we can have some preparation before class,..., and take some notes beside the lectures.” “there are too many readings. I don’t have enough time to read them all.” (also checked “Mostly language design and history”)

1 March 2001CS 655: Lecture136 Find a Lambda calculus term that has a normal form, but that will not be reduced to that form if beta reductions are not done in normal order. Like asking: “Find a Scheme program that terminates with lazy evaluation, but doesn’t terminate with eager evaluation. Translate it into Lambda calculus.”

1 March 2001CS 655: Lecture137 What does a program mean? Compile and run –Implementation dependencies –Not useful for reasoning Informal Semantics –Natural language description of PL Formal Semantics –Description in terms of notation with formally understood meaning

1 March 2001CS 655: Lecture138 Why not informal semantics? Two types have compatible types if their types are the same [footnote: Two types need not be identical to be compatible.]. ANSI C Standard,

1 March 2001CS 655: Lecture139 Formal Semantics Approaches Operational –Map to execution of a virtual machine –Easier to understand, harder to reason about –Depends on informal understanding of machine Denotational –Map parts to mathematical meanings, rules for composing meanings of pieces –Harder to understand, easier to reason about –Depends on informal understanding of mathematics Lots of others: Algebraic, Translator, etc. What about Lambda Calculus?

1 March 2001CS 655: Lecture1310 A Toy Language: BARK Program ::= Instruction*Program is a sequence of instructions Instructions are numbered from 0. Instruction ::= STORE Loc Literal Loc gets the value of Literal | ADD Loc 1 Loc 2 Loc 1 gets the value of Loc 1 + Loc 2 | MUL Loc 1 Loc 2 Loc 1 gets the value of Loc 1 * Loc 2 | HALT Stop program execution, answer in R0 | ERROR Stop program execution, error | GOTO LocJump to instruction corresponding to value in Loc. | IF Loc 1 THEN Loc 1 If value in Loc 1 is non-zero, jump to instruction corresponding to value in Loc 2. Loc ::= R[ - ] ? [ ][ ]* Literal ::= [ - ] ? [ ][ ]* (Beginner’s All-Purpose Register Kode)

1 March 2001CS 655: Lecture1311 A BARK Program [0]STORE R0 1 [1]STORE R1 10 [3]STORE R2 –1 [4] STORE R3 6 [5] STORE R4 8 [6]IF R1 THEN R4 [7]HALT [8] MUL R0 R1 [9]ADD R1 R2 [10]GOTO R3

1 March 2001CS 655: Lecture1312 Operational Semantics Game Input Function Abstract Machine Initial Configuration Final Configuration Output Function Answer Intermediate Configuration Intermediate Configuration Transition Rules Real World Program

1 March 2001CS 655: Lecture1313 Structured Operational Semantics SOS for a language is five-tuple: C Set of configurations for an abstract machine  Transition relation (subset of C x C ) I Program  C (input function) F Set of final configurations OF  Answer(output function)

1 March 2001CS 655: Lecture1314 Abstract Machine: Register Virtual Machine (RVM) Configuration defined by: –Array of Instructions –Program counter –Values in registers (any integer) C = Instructions x PC x RegisterFile Instruction[0] Instruction[1] Instruction[2] …. Instruction[-1] …. PC Register[0] Register[1] Register[2] …. Register[-1] ….

1 March 2001CS 655: Lecture1315 Input Function: I : Program  C C = Instructions x PC x RegisterFile where For a Program with n instructions numbered from 0 to n - 1: Instructions[m] = Program[m] for m >= 0 && m < n Instructions[m] = ERROR otherwise PC = 0 RegisterFile[n] = 0 for all integers n

1 March 2001CS 655: Lecture1316 Final Configurations F = Instructions x PC x RegisterFile where Instructions[PC] = HALT Output Function O : F  Answer Answer = value in RegisterFile[0]

1 March 2001CS 655: Lecture1317 Operational Semantics Game Input Function Abstract Machine Initial Configuration Final Configuration Output Function Answer Intermediate Configuration Intermediate Configuration Transition Rules Real World Program

1 March 2001CS 655: Lecture1318 Form of Transition Rules Antecedents c  c ’ Where c is a member of C.

1 March 2001CS 655: Lecture1319 STORE Loc Literal Instructions[PC] = STORE Loc Literal  where PC’ = PC + 1 RegisterFile’[n] = RegisterFile[n] if n  Loc RegisterFile’[n] = value of Literal if n  Loc

1 March 2001CS 655: Lecture1320 ADD Loc 1 Loc 2 Instructions[PC] = ADD Loc 1 Loc 2  where PC’ = PC + 1 RegisterFile’[n] = RegisterFile[n] if n  Loc RegisterFile’[n] = RegisterFile[Loc 2 ] if n  Loc 1

1 March 2001CS 655: Lecture1321 GOTO Loc Instructions[PC] = GOTO Loc  where PC’ = value in RegisterFile[Loc]

1 March 2001CS 655: Lecture1322 IF Loc 1 THEN Loc 2 Instructions[PC] = IF Loc 1 THEN Loc 2  where PC’ = value in RegisterFile[Loc 2 ] if Loc 1 is non-zero PC’ = PC + 1 otherwise

1 March 2001CS 655: Lecture1323 What’s it good for? Understanding programs Write a compiler or interpreter (?) Prove properties about programs and languages

1 March 2001CS 655: Lecture1324 Variation: BARK-forward Same as BARK except: GOTO LocJump forward Loc instructions. Loc must be positive. | IF Loc 1 THEN Loc 2 If value in Loc 1 is non-zero, jump forward value in Loc 2. instructions. Loc 2 must be positive.

1 March 2001CS 655: Lecture1325 GOTO Loc Instructions[PC] = GOTO Loc  where PC’ = value in RegisterFile[Loc] BARK: Instructions[PC] = GOTO Loc,value in Loc > 0  where PC’ = PC + value in RegisterFile[Loc]

1 March 2001CS 655: Lecture1326 Proving Termination Idea: Prove by Induction –Define a function Energy: C  positive integer –Show Energy of all Initial Configurations is finite –Show there are no transitions from a configuration with Energy = 0 –If C  C’ is a valid transition step, Energy of C’ must be less than Energy of C

1 March 2001CS 655: Lecture1327 Energy Function Energy: C  positive integer C = Energy = h – PC where h is an integer such that Instructions[k] = error for all k >= h

1 March 2001CS 655: Lecture1328 Initial Configurations For all Initial Configurations C, Energy is finite. Consider Input Function: C = Instructions x PC x RegisterFile where For a Program with n instructions numbered from 0 to n - 1: Instructions[m] = Program[m] for m >= 0 && m < n Instructions[m] = ERROR otherwise PC = 0 RegisterFile[n] = 0 for all integers n

1 March 2001CS 655: Lecture1329 Initial Configuration Energy Energy ( C ) = n where n is number of program instructions PC = 0 Instruction[m] = ERROR for m >= n

1 March 2001CS 655: Lecture1330 Energy = 0  Terminated Energy = h – PC where h is an integer such that Instructions[k] = error for all k >= h so, Energy = 0  h = PC and Instructions[PC] = ERROR No transitions for configuration where Instructions[PC] = ERROR

1 March 2001CS 655: Lecture1331 STORE reduces Energy Instructions[PC] = STORE Loc Literal  where PC’ = PC + 1 RegisterFile’[n] = RegisterFile[n] if n  Loc RegisterFile’[n] = value of Literal if n  Loc Energy ( ) =h – PC Energy ( ) = h – (PC + 1) h depends only on Instructions, doesn’t change Therefore: Energy’ < Energy

1 March 2001CS 655: Lecture1332 GOTO reduces Energy Instructions[PC] = GOTO Loc,value in Loc > 0  where PC’ = PC + value in RegisterFile[Loc] Energy( ) = h - PC Energy( ) = h – (PC + RegisterFile[Loc]) but antecedent says RegisterFile[Loc] > 0, so PC + RegisterFile[Loc] > PC and Energy’ < Energy.

1 March 2001CS 655: Lecture1333 To complete proof… Show the same for every transition rule. Then: –Start with finite energy, –Every transition reduces energy, –Energy must eventually reach 0. –And energy 0 means we terminated. Minor flaw? could skip 0 (e.g., Energy = –1)

1 March 2001CS 655: Lecture1334 Charge Gifford’s Ch 3 uses a stack-based virtual machine to provide an operational semantics for a stack-based language Next time: –Projects Kickoff – start thinking about things you want to do –Types and Static Semantics