Comp 205: Comparative Programming Languages Semantics of Imperative Programming Languages denotational semantics operational semantics logical semantics.

Slides:



Advertisements
Similar presentations
Semantics Static semantics Dynamic semantics attribute grammars
Advertisements

11111 Functional Program Verification CS 4311 A. M. Stavely, Toward Zero Defect Programming, Addison-Wesley, Y. Cheon and M. Vela, A Tutorial on.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
Introduction to Programming Languages Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.
Annoucements  Next labs 9 and 10 are paired for everyone. So don’t miss the lab.  There is a review session for the quiz on Monday, November 4, at 8:00.
David Evans CS655: Programming Languages University of Virginia Computer Science Lecture 19: Minding Ps & Qs: Axiomatic.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
Fall Semantics Juan Carlos Guzmán CS 3123 Programming Languages Concepts Southern Polytechnic State University.
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
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics Fall 2005.
1 Basic abstract interpretation theory. 2 The general idea §a semantics l any definition style, from a denotational definition to a detailed interpreter.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Defining practical programming languages Carlos Varela RPI.
Language Specfication and Implementation - PART II: Semantics of Procedural Programming Languages Lee McCluskey Department of Computing and Mathematical.
Denotational Semantics Syntax-directed approach, generalization of attribute grammars: –Define context-free abstract syntax –Specify syntactic categories.
Axiomatic Semantics Dr. M Al-Mulhem ICS
CS 330 Programming Languages 09 / 18 / 2007 Instructor: Michael Eckmann.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Operational Semantics.
Chair of Software Engineering 1 Concurrent Object-Oriented Programming Arnaud Bailly, Bertrand Meyer and Volkan Arslan.
PSUCS322 HM 1 Languages and Compiler Design II Formal Semantics Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU Spring.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Axiomatic Semantics ICS 535.
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
Describing Syntax and Semantics
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Denotational Semantics ICS.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Dr. Muhammed Al-Mulhem ICS An Introduction to Functional Programming.
Imperative Programming
Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 2: Operational Semantics I Roman Manevich Ben-Gurion University.
1 Relational Expressions Relational expressions: –Expressions that compare operands –Sometimes called conditions –Evaluated to yield a result –Typically.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
1 Relational Algebra and Calculas Chapter 4, Part A.
Semantics. Semantics is a precise definition of the meaning of a syntactically and type-wise correct program. Ideas of meaning: –Operational Semantics.
Propositional Calculus CS 270: Mathematical Foundations of Computer Science Jeremy Johnson.
The College of Saint Rose CIS 433 – Programming Languages David Goldschmidt, Ph.D. from Concepts of Programming Languages, 9th edition by Robert W. Sebesta,
3.2 Semantics. 2 Semantics Attribute Grammars The Meanings of Programs: Semantics Sebesta Chapter 3.
Chapter 3 Part II Describing Syntax and Semantics.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Syntax and Semantics CIS 331 Syntax: the form or structure of the expressions, statements, and program units. Semantics: the meaning of the expressions,
Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.
Languages and Compilers
School of Computing and Mathematics, University of Huddersfield CHA2545: WEEK 4 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE TUTORIAL: Do exercises.
Dr. Muhammed Al-MulhemICS (Denotational Semantics)
An Axiomatic Basis for Computer Programming Robert Stewart.
1 / 48 Formal a Language Theory and Describing Semantics Principles of Programming Languages 4.
1-1 An Introduction to Functional Programming Sept
CMSC 330: Organization of Programming Languages Operational Semantics a.k.a. “WTF is Project 4, Part 3?”
Principle of Programming Lanugages 3: Compilation of statements Statements in C Assertion Hoare logic Department of Information Science and Engineering.
This Week Lecture on relational semantics Exercises on logic and relations Labs on using Isabelle to do proofs.
Classical Control in Quantum Programs Dominique Unruh IAKS, Universität Karlsruhe Founded by the European Project ProSecCo IST
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Denotational Semantics.
CMSC 330: Organization of Programming Languages Operational Semantics.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
Prof. Necula CS 164 Lecture 171 Operational Semantics of Cool ICOM 4029 Lecture 10.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Dr. M. Al-Mulhem Denotational Semantics 1 Chapter 4 Fundamentals (Denotational Semantics)
Functional Programming
Functional Programming
Formal methods: Lecture
Programming Languages and Compilers (CS 421)
Denotational Semantics (Denotational Semantics)
Programming Languages and Compilers (CS 421)
Semantics In Text: Chapter 3.
Defining A Formal Semantics For The Rosetta Specification Language
Functional Program Verification
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Presentation transcript:

Comp 205: Comparative Programming Languages Semantics of Imperative Programming Languages denotational semantics operational semantics logical semantics Lecture notes, exercises, etc., can be found at:

Syntax... Syntax concerns notation and the rules that describe when an expression is legitimate (i.e., when an expression is - potentially - meaningful). publid doNothing(int i, j) { return } contains a number of syntactic errors (mistyped keywords, missing semicolons, etc.) For example, the following Java code

… and Semantics Semantics is concerned with meaning. In Computer Science, we are particularly interested in the meanings of programs and their constituent parts (expressions, function or type definitions, etc.)

Why? Semantics is important for: Language design and implementation E.g., the Java Virtual Machine makes Java portable because it has a simple but formal semantics Verification of programs In order to prove something about a program you have to know what the program means Fun, Depth of understanding, …

Flavours of Semantics Denotational Semantics describes the meaning of a program by saying what the program denotes (usually, some kind of mathematical object) Operational Semantics describes how programs are evaluated Logical Semantics (or Axiomatic Semantics) describes the meaning of programs indirectly, by specifying what abstract properties they have

Denotational Semantics The notion of state is central to the imperative paradigm and to its denotational semantics. A state records the values that are associated with the variables used in a computation. Programs change these values and therefore change the state. The denotation of a program is a function from states to states.

States In order to understand how programs behave when executed starting from a certain state, all we need know is the values of the variables in that state. A reasonable abstraction of the notion of state is: A state is a function of type Id  Nat, where Id is the set of variable names. (For simplicity, we assume that all variables take values in the natural numbers.)

Values and Expressions If a state is a function of type Id  Nat, we can use a state to obtain a value for expressions that contain variables. For example if S : Id  Nat is a state, then a variable i will have a certain value, S( i ), in that state; similarly, the value of an expression, say i*2 + j, will have a value S( i ) * 2 + S( j )

Some Notation Given a state S : Id  Nat, we write S[[ i ]] instead of S( i ) ; similarly, given an expression, e, we write S[[ e ]] for the value of e in the state S. For example, S[[ i*2 + j ]] = S( i ) * 2 + S( j ).

Assignment Consider the program i = i+1; This program changes a state by changing only the value associated with the variable i. If we run this program in a state S, we obtain a new state, S', such that S' [[ i ]] = S[[ i ]] + 1 S' [[ x ]] = S[[ x ]], for all x  Id such that x  i.

Semantics of Assignment The denotation of an assignment y = e ; is a function that takes a state S and returns the state S' such that S' [[ y ]] = S [[ e ]] S' [[ x ]] = S [[ x ]], for all x  Id such that x  y. We write U[ y = e ]( S ) for S'.

Operational Semantics While denotational semantics says what a program means, operational semantics describes how programs are evaluated. Typically this is done by presenting either: an abstract machine that evaluates programs (e.g., a Turing Machine, the JVM), or an "evaluation" relation that describes the step-by-step evaluation of programs

An Evaluation Relation As an example, we define a relation  on pairs of states and programs. The pair (S, P) represents a state S and a program P which is to be run in the state S.

An Evaluation Relation We write (S, P)  (S', P') to indicate that when the program P is run in state S, a single step of the evaluation of P results in the new state S', and P' is the remaining part of the program to be evaluated (i.e., the rest of P after the first step of the evaluation).

Done Evaluation It is convenient to write done to denote a fully-evaluated program. This allows us to denote a complete evaluation of a program P in a state S by a chain of the form: (S, P)  (S 1, P 1 )  (S 2, P 2 )   (S n, done) which means that when run in state S, the program P terminates, producing a new state S n.

Assignment Operationally As with denotational semantics, assignment forms the basis of operational semantics. The first part of our definition of the evaluation relation is: ( S, y = e )  ( U[ y = e ]( S ), done ) which is, more or less, exactly what denotational semantics says about assignment.

Composition Operationally Operational semantics is also hierarchical (or "structured"), in that the semantics of other constructs are built from the semantics of assignment. If ( S, P 1 )  ( S', P 1 ' ) then ( S, P 1 ; P 2 )  ( S', P 1 ' ; P 2 ) and if ( S, P 1 )  ( S', done ) then ( S, P 1 ; P 2 )  ( S', P 2 )

If-then-else Operationally If S[[ e ]] is true then ( S, if ( e ) { P 1 } else { P 2 } )  ( S, P 1 ) and if S[[ e ]] is false then ( S, if ( e ) { P 1 } else { P 2 } )  ( S, P 2 )

Loops Operationally If S[[ e ]] is false then ( S, while ( e ) { P } )  ( S, done ) and if S[[ e ]] is true then ( S, while ( e ) { P } )  ( S, P ; while ( e ) { P } )

Loops Operationally Note that we don't have the difficulty we faced with denotational semantics: we don't need to explicitly say what a non-terminating computation denotes; we can simply allow an infinite chain of evaluation steps: (S, P)  (S 1, P 1 )  (S 2, P 2 ) 

Summary The semantics of imperative languages is based on the semantics of assignment The semantics of other constructs is built up from that of assignment Next: Semantics of Functional Languages