Formal Semantics of Programming Languages 虞慧群 Topic 6: Advanced Issues.

Slides:



Advertisements
Similar presentations
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 10.
Advertisements

COMMUNICATING SEQUENTIAL PROCESSES C. A. R. Hoare The Queen’s University Belfast, North Ireland.
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
Semantics Static semantics Dynamic semantics attribute grammars
Parallel Processing & Parallel Algorithm May 8, 2003 B4 Yuuki Horita.
Models of Concurrency Manna, Pnueli.
3-Valued Logic Analyzer (TVP) Tal Lev-Ami and Mooly Sagiv.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
8. Introduction to Denotational Semantics. © O. Nierstrasz PS — Denotational Semantics 8.2 Roadmap Overview:  Syntax and Semantics  Semantics of Expressions.
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
Formal Semantics of Programming Languages 虞慧群 Topic 5: Axiomatic Semantics.
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
Chapter 3 Functional Programming. Outline Introduction to functional programming Scheme: an untyped functional programming language.
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 11: An introduction to CSP.
DATAFLOW PROCESS NETWORKS Edward A. Lee Thomas M. Parks.
Programming Language Semantics Denotational Semantics Chapter 5 Based on a lecture by Martin Abadi.
1 Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications.
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
Denotational Semantics Syntax-directed approach, generalization of attribute grammars: –Define context-free abstract syntax –Specify syntactic categories.
Control Flow Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Programming Language Semantics Denotational Semantics Chapter 5 Part II.
Programming Language Semantics Java Threads and Locks Informal Introduction The Java Specification Language Chapter 17.
1 Control Flow Analysis Mooly Sagiv Tel Aviv University Textbook Chapter 3
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Kernel language semantics Carlos Varela RPI Adapted with permission.
Local Reasoning Peter O’Hearn John Reynolds Hongseok Yang.
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
1 Ivan Lanese Computer Science Department University of Bologna Italy Concurrent and located synchronizations in π-calculus.
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
Operational Semantics Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Programming Language Semantics Axiomatic Semantics of Parallel Programs.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Parallel & Concurrent Programming: Occam Vitaliy Lvin University of Massachusetts.
Imperative Programming
1111 Communicating Sequential Processes Based on: C. A. R. Hoare, Communicating Sequential Processes, CACM, 21(8): , November,
Advanced Topics in SE Spring Process Algebra Hossein Hojjat Formal Methods Lab University of Tehran.
Formal Semantics of Programming Languages 虞慧群 Topic 3: Principles of Induction.
Programming Paradigms for Concurrency Pavol Cerny Vasu Singh Thomas Wies Part III – Message Passing Concurrency.
02/04/2008 A Concrete Syntax for UML 2.1 Action Semantics Using +CAL 13th IEEE International Conference on Engineering of Complex Computer Systems – ICECCS.
Parallel execution Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
11/19/20151 Metodi formali nello sviluppo software a.a.2013/2014 Prof.Anna Labella.
Copyright 2001, Matt Dwyer, John Hatcliff, and Radu Iosif. The syllabus and all lectures for this course are copyrighted materials and may not be used.
1 Programming Languages (CS 550) Lecture 4 Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications Chapter.
1 Programming Languages (CS 550) Lecture 2 Summary Mini Language Interpreter Jeremy R. Johnson.
Formal Semantics of Programming Languages 虞慧群 Topic 2: Operational Semantics.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
CSE 425: Functional Programming I Programs as Functions Some programs act like mathematical functions –Associate a set of input values from the function’s.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Types and Programming Languages Lecture 16 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Π-AAL: An Architecture Analysis Language for Formally Specifying and Verifying Structural and Behavioral Properties of Software Architectures Presented.
CS314 – Section 5 Recitation 9
Operational Semantics of Scheme
Functional Programming
Functional Programming
September 4, 1997 Programming Languages (CS 550) Lecture 6 Summary Operational Semantics of Scheme using Substitution Jeremy R. Johnson TexPoint fonts.
Organization of Programming Languages
Graph-Based Operational Semantics
Declarative Computation Model Kernel language semantics (Non-)Suspendable statements (VRH ) Carlos Varela RPI October 11, 2007 Adapted with.
Spring 2017 Program Analysis and Verification Operational Semantics
Mini Language Interpreter Programming Languages (CS 550)
The Metacircular Evaluator
Programming Languages and Compilers (CS 421)
The Metacircular Evaluator
Programming Languages and Compilers (CS 421)
The Metacircular Evaluator (Continued)
6.001 SICP Interpretation Parts of an interpreter
Programming Languages and Compilers (CS 421)
Spring 2016 Program Analysis and Verification Operational Semantics
More Scheme CS 331.
Presentation transcript:

Formal Semantics of Programming Languages 虞慧群 Topic 6: Advanced Issues

Motivation Specifying the semantics of real programming languages is more difficult than IMP… Language Features o Higher order types o Dynamic memory allocation o Pointers o Procedures and recursion o Parameter passing o Concurrency

Plan Handling memory allocation (Ex 2) A simple parallel construct Guarded commands Concurrency with communication

Abstract Syntax for IMP++ L X | L.car | L.cdr Aexp a ::= n | L | cons(a, a) | nil | a 0 + a 1 | a 0 – a 1 | a 0  a 1 Bexp b ::= true | false | a 0 = a 1 | a 0  a 1 |  b | b 0  b 1 | b 0  b 1 Com c ::= skip | L := a | c 0 ; c 1 | if b then c 0 else c 1 | while b do c

Extending the semantic domain States cannot be mapping from variables to values Need a way to represent “sharing” Two level stores  = (env, store) env : Loc  Val store=(Cells, car, cdr) car: Cells  Val, cdr: Cells  Val Val = Cells  {nil}  N

Extending the semantic relation expressions  1 What is the intermediate result of computing L- value? (((X).cdr).car) Allow location expressions a  cells cons expressions modify the store

Expression rules (1)  1  1  1, sel  {car, cdr} s=(cells, car, cdr) and c  cells, sel  {car, cdr} and sel(c)=c’  1

Expression rules (2)  1  1 s=(cells, car, cdr), c0  Val  1 s=(cells, car, cdr), c  cells, c0, c1  Val  1

Boolean expressions(1)  1, t  {true, false}  1  1  1, s=(cells, car, cdr), c0  Val  1 s=(cells, car, cdr),c0, c1  Val, c0=c1  1 s=(cells, car, cdr),c0, c1  Val, c0≠c1  1

Commands(1)  1   1 X  Loc  1  1, X  Loc, c  Val  1  1  1 s=(cells, car, cdr), c  cells  1 s=(cells, car, cdr), c0  cells, c1  Val  1 <(e, (cells, car[c1/c0], cdr)

Commands (2)  1  1  1  ’,  1  ’’  1  ’’  1,  1  ’’  1  ’’  1

A Simple Parallel Construct c0 || c1 Execute co and c1 in parallel (X := 1 || (X:=2 ; X := X + 1)) Natural Operational Semantics Small step rules  1

Parallelism Introduces (Demonic) Nondeterminism (X := 0 || X := 1); if X = 0 then c0 else c1

Guarded Commands Com c ::= skip | abort | X := a | c 0 ; c 1 | if gc fi | do gc od GC gc ::= b  c | gc0  gc1 if X  Y  MAX := X  Y  X  MAX := Y fi do X >Y  X := X - Y  Y >X  Y := Y - X od

Rules for commands  1   n  1  [n/X]  1  ’  1  1  1  1  1 fail  1  1   1

Rules for guarded commands  true  1  1  1  1 false  1 fail  1 fail  1 fail  1 fail

Example do X >Y  X := X - Y  Y >X  Y := Y - X od

Communicating processes Languages for modeling distributed systems CSP, Occam, Ada? Hoare, Milner Support Parallelism Non-determinism Synchronization via communication  ? X   ! a

Communication Processes Channel names , ,   Chan Input expression  ? X where X  Loc Output expressions  ! A where a  Aexp Commands c::= skip | abort | X := a |  ? X |  ! A | c0 ; c1 | if gc fi | do gc od | c0 || c1 | c   Guarded commands gc ::= b  c | b   ? X  c | b   ! a  c| gc 0  gc 1

Examples do (true   ? X   ! X) od do (true   ? X   ! X) od || do (true   ? Y   ! Y) od || 

Examples if (true   ? X  c0)  (true   ? Y  c1) fi if (true   ? X; c0)  (true   ? Y ;c1) fi

Formal semantics Need a way to model communication events Label transitions {  ? n |  Chan & n  N}  {  ! n |  Chan & n  N}

Example transitions  if  n   ?n   !n if  n   ?n   !n

Conventions in formal semantics Empty command * *; c  c; *  c || *  * || c  c * ; *  (*   )  *    1  =  ? n =  ! n = 

Rules for commands    n   [n/X]   ?n  n   !n 

Rules for commands(2)  fail         ?n   !n    ?n   !n 

Rules for commands(3)  provided that  ?n and  !n

Rules for guarded commands(1)  true  false   fail  false  false  fail  fail  fail

Rules for guarded commands(2)  true  true,  n   !n  

Uncovered Calculus for Communicating Systems (CCS) A specification language The modal  -calculus Local model checking

Summary Writing a small step semantics for a real programming language is non-trivial Small step semantics can model Nondeterminism Concurrency Failures Guarded command is a powerful language construct

Exercise 6 (1)