CS 655: Programming Languages David Evans Office 236A, 982-2218 University of Virginia Computer.

Slides:



Advertisements
Similar presentations
Software Development Languages and Environments. Programming languages High level languages are problem orientated contain many English words are easier.
Advertisements

David Evans CS655: Programming Languages University of Virginia Computer Science Lecture 6: Types of Types “It would.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
 Suppose for a moment that you were asked to perform a task and were given the following list of instructions to perform:
Introduction to Programming Languages Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.
David Evans CS655: Programming Languages University of Virginia Computer Science Lecture 13: Operational Semantics “Then.
Programming Types of Testing.
FLAC Lecture 19 Turing Machines and Real Life * Reductions Mihai Budiu March 3, 2000.
The Binary Machine Modern high-level programming languages are designed to make programming easier. On the other end, the low level, all modern digital.
The Analytical Engine Module 6 Program Translation.
1 Lecture 1  Getting ready to program  Hardware Model  Software Model  Programming Languages  The C Language  Software Engineering  Programming.
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
Describing Syntax and Semantics
1 CS101 Introduction to Computing Lecture 19 Programming Languages.
Introduction to Programming (in C++) Introduction Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC.
CS 331, Principles of Programming Languages Introduction.
1 Programming Languages Marjan Sirjani 2 1- The Study of Programming Languages The purpose of language is simply that it must convey meaning. (Confucius)
Announcements — Tues., Jan. 19 For next time, read Learning Computing with Robots, chs. 1 and 2. The Blackboard site is up and operational! not much content.
CS 415: Programming Languages Chapter 1 Aaron Bloomfield Fall 2005.
1 Chapter-01 Introduction to Computers and C++ Programming.
BIT Presentation 6. Contents GENERATIONS OF LANGUAGES COMPILERS AND INTERPRETERS VIRTUAL MACHINES OBJECT-ORIENTED PROGRAMMING SCRIPTING LANGUAGES.
Overview. Copyright © 2006 The McGraw-Hill Companies, Inc. Chapter 1 Overview A good programming language is a conceptual universe for thinking about.
Programming Languages CPS120: Introduction to Computer Science Lecture 5.
1 Software Development Topic 2 Software Development Languages and Environments.
Chapter 8 High-Level Programming Languages (modified by Erin Chambers)
High-Level Programming Languages: C++
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.
Levels of Architecture & Language CHAPTER 1 © copyright Bobby Hoggard / material may not be redistributed without permission.
COMPUTER PROGRAMS AND LANGUAGES Chapter 4. Developing a computer program Programs are a set (series) of instructions Programmers determine The instructions.
CS101 Introduction to Computing Lecture Programming Languages.
1 Programming Languages Marjan Sirjani Course web site:
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 2.
1 Programming Languages Fundamentals Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM.
Syntax and Semantics CIS 331 Syntax: the form or structure of the expressions, statements, and program units. Semantics: the meaning of the expressions,
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 36: Modeling Computing.
Introduction CPSC 388 Ellen Walker Hiram College.
David Evans CS655: Programming Languages University of Virginia Computer Science Lecture 14: Types of Types “It would.
CS 331, Principles of Programming Languages Chapter 1.
David Evans CS655: Programming Languages University of Virginia Computer Science Lecture 21: Proof-Carrying Code and.
Engr. Isabelo Jun D. Paat, ME-CoE Lecturer 1 Programming Languages.
 Programming - the process of creating computer programs.
Programming Language Descriptions. What drives PL Development? Computers are “in charge” of extremely important issues Execute a program literally. Exercise.
int k = Integer.MAX_VALUE; k++; int k = Integer.MAX_VALUE; k++; What happens when the following code executes? byte b = someFile.readByte(); b = (byte)(b.
CPS120: Introduction to Computer Science Variables and Constants.
Programming Language Concepts (CIS 635) Elsa L Gunter 4303 GITC NJIT,
Programming Language Theory 2014, 1 Chapter 1 :: Introduction Origin : Michael L. Scott School of Computer & Information Engineering,
Software Engineering Algorithms, Compilers, & Lifecycle.
a medium allowing humans and computers to communicate an abstraction of the real world a notation for expressing algorithms the set of all syntactically.
Chapter 1. Introduction.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Basic Concepts: computer, program, programming …
Introduction to programming languages, Algorithms & flowcharts
Introduction to programming languages, Algorithms & flowcharts
PROGRAMMING LANGUAGES
Programming Language Hierarchy, Phases of a Java Program
Problem Solving Using C: Orientation & Lecture 1
CS101 Introduction to Computing Lecture 19 Programming Languages
Introduction to programming languages, Algorithms & flowcharts
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
CMP 131 Introduction to Computer Programming
Problem Solving Using C: Orientation & Lecture 1
Principles of Programming Languages
ICT Programming Lesson 1:
Lecture 8 Programming Paradigm & Languages. Programming Languages The process of telling the computer what to do Also known as coding.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
David Evans Lecture 19: ||ism I don’t think we have found the right programming concepts for parallel computers yet.
School of Computer & Information Engineering,
Presentation transcript:

CS 655: Programming Languages David Evans Office 236A, University of Virginia Computer Science Lecture 2: 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

27 Jan 2000CS 655: Lecture 22 Menu Survey Summary Position Papers Results Intro to Formal Semantics Operational Semantics

27 Jan 2000CS 655: Lecture 23 Students’ Experience C years, C , BASIC 64, Pascal – 45, Java , assemblies – 26, FORTRAN – 22, LISP – 17, Perl – 14.5 Ada, ADAMS, Common LISP, Delphi, Elf, Forth, Haskell, HP Calculator, Hypertalk, JavaScript (large system for DOD!), ksh, LOGO, ML, nawk, ObjectPal, Python, Prolog, REBOL, Relay Ladder Logic, Sather, Scheme, Smalltalk, SQL, Tcl/Tk

27 Jan 2000CS 655: Lecture 24 No  +, 5  + 2 (= = 1.4…) Our not favorite languages: BASIC (1)C (8 - 1) C++ (3)FORTRAN (2) Java (8 - 2)Perl (2 - 2) Good papers had to get at underlying issues, not just symptoms Some misconceptions about GC Position Paper 1

27 Jan 2000CS 655: Lecture 25 Project Teams You have until noon Monday to submit team requests Use the discussion board if you are looking for teammates (link off ~cs655 page)

27 Jan 2000CS 655: Lecture 26 Formal Semantics

27 Jan 2000CS 655: Lecture 27 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

27 Jan 2000CS 655: Lecture 28 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,

27 Jan 2000CS 655: Lecture 29 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.

27 Jan 2000CS 655: Lecture 210 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)

27 Jan 2000CS 655: Lecture 211 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

27 Jan 2000CS 655: Lecture 212 Operational Semantics Game Input Function Abstract Machine Initial Configuration Final Configuration Output Function Answer Intermediate Configuration Intermediate Configuration Transition Rules Real World Program

27 Jan 2000CS 655: Lecture 213 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)

27 Jan 2000CS 655: Lecture 214 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] ….

27 Jan 2000CS 655: Lecture 215 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

27 Jan 2000CS 655: Lecture 216 Final Configurations F = Instructions x PC x RegisterFile where Instructions[PC] = HALT Output Function O : F  Answer Answer = value in RegisterFile[0]

27 Jan 2000CS 655: Lecture 217 Operational Semantics Game Input Function Abstract Machine Initial Configuration Final Configuration Output Function Answer Intermediate Configuration Intermediate Configuration Transition Rules Real World Program

27 Jan 2000CS 655: Lecture 218 Form of Transition Rules Antecedents c  c ’ Where c is a member of C.

27 Jan 2000CS 655: Lecture 219 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

27 Jan 2000CS 655: Lecture 220 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

27 Jan 2000CS 655: Lecture 221 GOTO Loc Instructions[PC] = GOTO Loc  where PC’ = value in RegisterFile[Loc]

27 Jan 2000CS 655: Lecture 222 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

27 Jan 2000CS 655: Lecture 223 What’s it good for? Understanding programs Write a compiler or interpreter (?) Prove properties about programs and languages

27 Jan 2000CS 655: Lecture 224 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.

27 Jan 2000CS 655: Lecture 225 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]

27 Jan 2000CS 655: Lecture 226 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

27 Jan 2000CS 655: Lecture 227 Energy Function Energy: C  positive integer C = Energy = h – PC where h is an integer such that Instructions[k] = error for all k >= h

27 Jan 2000CS 655: Lecture 228 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

27 Jan 2000CS 655: Lecture 229 Initial Configuration Energy Energy ( C ) = n where n is number of program instructions PC = 0 Instruction[m] = ERROR for m >= n

27 Jan 2000CS 655: Lecture 230 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

27 Jan 2000CS 655: Lecture 231 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

27 Jan 2000CS 655: Lecture 232 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.

27 Jan 2000CS 655: Lecture 233 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)

27 Jan 2000CS 655: Lecture 234 Charge Problem Set 1: –Develop Operational Semantics for simplified PostFix using RVM –Prove termination property Final project team requests by Monday Next time: –Projects –Discuss Wenger paper: come to class prepared to discuss how well his milestones work today