CS5205Semantics1 CS5205: Foundation in Programming Languages Semantics Static Semantics Dynamic Semantics Operational Semantics Big-step Small-Step Denotational.

Slides:



Advertisements
Similar presentations
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Advertisements

CPSC 388 – Compiler Design and Construction
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
1 Mooly Sagiv and Greta Yorsh School of Computer Science Tel-Aviv University Modern Compiler Design.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
1 Compiler Construction Intermediate Code Generation.
Recap 1.Programmer enters expression 2.ML checks if expression is “well-typed” Using a precise set of rules, ML tries to find a unique type for the expression.
8. Introduction to Denotational Semantics. © O. Nierstrasz PS — Denotational Semantics 8.2 Roadmap Overview:  Syntax and Semantics  Semantics of Expressions.
Object Oriented Programming in Java George Mason University Fall 2011
Prof. Necula CS 164 Lecture 141 Run-time Environments Lecture 8.
ISBN Chapter 3 Describing Syntax and Semantics.
Copyright © 2006 Addison-Wesley. All rights reserved. 3.5 Dynamic Semantics Meanings of expressions, statements, and program units Static semantics – type.
Fall Semantics Juan Carlos Guzmán CS 3123 Programming Languages Concepts Southern Polytechnic State University.
Comp 205: Comparative Programming Languages Semantics of Imperative Programming Languages denotational semantics operational semantics logical semantics.
Lecture 02 – Structural Operational Semantics (SOS) Eran Yahav 1.
8. Introduction to Denotational Semantics. © O. Nierstrasz PS — Denotational Semantics 8.2 Roadmap  Syntax and Semantics  Semantics of Expressions 
1 Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications.
CS 536 Spring Run-time organization Lecture 19.
Denotational Semantics Syntax-directed approach, generalization of attribute grammars: –Define context-free abstract syntax –Specify syntactic categories.
Names and Scopes CS 351. Program Binding We should be familiar with this notion. A variable is bound to a method or current block e.g in C++: namespace.
Cse321, Programming Languages and Compilers 1 6/19/2015 Lecture #18, March 14, 2007 Syntax directed translations, Meanings of programs, Rules for writing.
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.
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
A Type-Checked Restrict Qualifier Jeff Foster OSQ Retreat May 9-10, 2001.
MinML: an idealized programming language CS 510 David Walker.
1 Semantics Q S EMANTICS (Q1,’07) Week 4 Jacob Andersen PhD student
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
Operational Semantics Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Describing Syntax and Semantics
Building An Interpreter After having done all of the analysis, it’s possible to run the program directly rather than compile it … and it may be worth it.
Introduction Even though the syntax of Scheme is simple, it can be very difficult to determine the semantics of an expression. Hacker’s approach: Run it.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
INF5110: Mandatory Exercise 2 Eyvind W. Axelsen @eyvindwa Slides are partly based on.
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
Syntax & Semantic Introduction Organization of Language Description Abstract Syntax Formal Syntax The Way of Writing Grammars Formal Semantic.
Imperative Programming
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
1 October 1, October 1, 2015October 1, 2015October 1, 2015 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University Azusa.
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
1 Programming Languages (CS 550) Lecture 9 Summary Introduction to Formal Semantics Jeremy R. Johnson TexPoint fonts used in EMF. Read the TexPoint manual.
Chapter Twenty-ThreeModern Programming Languages1 Formal Semantics.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
Semantics. Semantics is a precise definition of the meaning of a syntactically and type-wise correct program. Ideas of meaning: –Operational Semantics.
Eran Yahav 1. Previously…  An algorithmic view  Abstract data types (ADT)  Correctness Conditions  Sequential consistency  Linearizability  Treiber’s.
Formal Semantics of Programming Languages 虞慧群 Topic 1: Introduction.
Programming Languages 2nd edition Tucker and Noonan Chapter 6 Type Systems I was eventually persuaded of the need to design programming notations so as.
Chapter 3 Part II Describing Syntax and Semantics.
1 Review. 2 Creating a Runnable Program  What is the function of the compiler?  What is the function of the linker?  Java doesn't have a linker. If.
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.
CS536 Semantic Analysis Introduction with Emphasis on Name Analysis 1.
Introduction CPSC 388 Ellen Walker Hiram College.
Just Enough Type Theory or, Featherweight Java A Simple Formal Model of Objects Jonathan Aldrich
CMSC 330: Organization of Programming Languages Operational Semantics a.k.a. “WTF is Project 4, Part 3?”
Semantic Analysis II Type Checking EECS 483 – Lecture 12 University of Michigan Wednesday, October 18, 2006.
CSE 130 : Spring 2011 Programming Languages Ranjit Jhala UC San Diego Lecture 5: Functions and Closures.
Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications Chapter.
CMSC 330: Organization of Programming Languages Operational Semantics.
CS412/413 Introduction to Compilers Radu Rugina Lecture 11: Symbol Tables 13 Feb 02.
1 Iterative Program Analysis Abstract Interpretation Mooly Sagiv Tel Aviv University Textbook:
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
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Operational Semantics of Scheme
Describing Syntax and Semantics
Declarative Computation Model Kernel language semantics (Non-)Suspendable statements (VRH ) Carlos Varela RPI October 11, 2007 Adapted with.
CSE401 Introduction to Compiler Construction
Programming Languages (CS 550) Mini Language Semantics
Presentation transcript:

CS5205Semantics1 CS5205: Foundation in Programming Languages Semantics Static Semantics Dynamic Semantics Operational Semantics Big-step Small-Step Denotational Semantics Abstract Machines

CS5205Semantics2 Introduction Introduction Important to give precise meanings to programs. Semantics provide a formal definition for the constructs of a programming language. Static Semantics : abstract properties ascertained at compile-time e.g. variable scope and typing rules; Dynamic Semantics : differs across languages with different abstraction levels provides detailed run-time properties

CS5205Semantics3 An Example Language An Example Language Expression Syntax e ::= Var x | Num i | Plus e 1 e 2 | Times e 1 e 2 | Bool b | Neg e | Or e 1 e 2 | And e 1 e 2 | If e 1 e 2 e 3 | Let x e 1 e 2 | Lam v e | Apply e 1 e 2 | Ref e | Assign e 1 e 2 | ! e | Pair e 1 e 2 | Fst e | Snd e | While e 1 e 2 | e 1 ; e 2 Three categories (i) pure expressions, (ii) commands, (iii) expressions with side-effetcs

CS5205Semantics4 An Example Language An Example Language Possible Values Val ::= ( ) | i | b | l | (Lam x. e) | (Val 1,Val 2 )  ` v v 2  Static Semantics – Scope Rules Static Semantics – Scope Rules Checking that all variables are correctly bound.  ` expr set of free variables expression to check judgment for scope rule

CS5205Semantics5 Variable Scope Rules Variable Scope Rules  ` Var x x 2   ` Num i  ` Bool b  ` op e 1.. e n  ` e 1  ` e n ….  ` Lam x e  {x}  ` e  ` Letrec x e 1 e 2  {x}  ` e 1  {x}  ` e 2

CS5205Semantics6 Type Judgment Type Judgment  ` e : t type environment type expression Possible Types t ::= Void | Int | Bool | Ref t | t 1 ! t 2 | (t 1,t 2 )  ` Letrec x:t e 1 e 2 : t 2  {x:t}  ` e 1 : t  {x:t}  ` e 2 : t 2  ` Var x t 2  (x)

CS5205Semantics7 Transition System Transition System A transition is a structure ( , ! ) where  is a set of elements (called configuration) and ! ::  x  is a binary relation (called a transition relation). Terminal Transition System Terminal Transition System A terminal transition is a structure ( , !, T ) where ( , ! ) is a transition system, while T µ  is a set of final configurations that satisfies: 8 y 2 T. : ( 9 y' 2 . y ! y').

CS5205Semantics8 Dynamic Semantics Dynamic Semantics Previously, we use for a pure language: One-step: e 1 ! e 2 Many-steps: e 1 ! * e 2 In case of side-effects (e.g memory store), we will need a configuration. Thus, better to use: ! store command variable environment

CS5205Semantics9 Structured Operational Semantics Structured Operational Semantics Small Step Semantics: ! Good for progress + preservation proofs Big Step Semantics: E ` ) Good for optimization proofs

CS5205Semantics10 Environment Environment E : Var ! Value Extension : E + {x:v} Update : E {x:v} Removal : E - {x} Look-up : E(x) OPERATIONS

CS5205Semantics11 Store Store  Loc ! Value Extension :  + {l : v} Update :  {l : v} Removal :  - {l} Look-up :  (l) OPERATIONS :

CS5205Semantics12 Big Step Semantics Big Step Semantics E ` )

CS5205Semantics13 Big Step Semantics Big Step Semantics E ` ! E ` ) E+{x:v 1 } ` )

CS5205Semantics14 Big Step Semantics Big Step Semantics E ` ) fresh l E ` ) E ` )

CS5205Semantics15 Small Step Semantics Small Step Semantics !

CS5205Semantics16 Small Step Semantics Small Step Semantics !

CS5205Semantics17 Small Step Semantics Small Step Semantics ! fresh l

CS5205Semantics18 Small Step Semantics Small Step Semantics !

CS5205Semantics19 Small Step Semantics Small Step Semantics ! intermediate expression

CS5205Semantics20 Homework Homework Finish the rest of the (i) big-step operational semantics (ii) small-step operational semantics for our simple language.

CS5205Semantics21 Denotational Semantics Denotational Semantics describes meaning of program as a mathematical object typically: denotation of a command "maps states to states“ denotation of a pure expression "maps states to value“ denotation of an expression with effects "maps states to states and value"

CS5205Semantics22 Denotation Denotation Pure Expression [[ Expr ]] :: State ! Value [[ Num i ]] st = i [[ Var v ]] st = st(v) [[ e 1 + e 2 ]] st = [[ e 1 ]] st + [[ e 2 ]] st

CS5205Semantics23 Denotation Denotation Command with Side-Effects [[ Command ]] :: State ! State [[ skip ]] st = st [[ s 1 ; s 2 ]] st = [[ s 2 ]] ([[ s 1 ]] st) [[ v := e ]] st = st ( v -> [[ e ]] st )

CS5205Semantics24 Denotation Denotation Expression with side-effect [[ Expr ]] :: State ! (State, Value) [[ Ref e ]] st = let (st1,v) = [[ e ]] in let l = freshLoc in (st1 + [l->new v], l) [[ Let v e 1 e 2 ]] st = let (st 1,v 1 ) = [[ e 1 ]] st in let (st 2,v 2 ) = [[ e 2 ]] st 1 +(v:v 1 ) in (st 2 -{v},v 2 )

CS5205Semantics25 Abstract Machine Abstract Machine - lower-level semantics where abstract configuration is closer to actual machine - made popular via Java abstract machine where source code is first compiled to byte code format - Two key uses of abstract machine: (i) portable architecture with an interpreter (ii) allow type-checking of byte code

CS5205Semantics26 Abstract Machine Abstract Machine Configuration Configuration : Stack : [ Value ] Env : Var ! Value Heap : Loc ! Value Control : [ Expr ] Initial Configuration : Final Configuration:, if e is an expression,if e is a command

CS5205Semantics27 Transition System Transition System )

CS5205Semantics28 Transition System Transition System ) ) )

CS5205Semantics29 Transition System Transition System ) ) )

CS5205Semantics30 Transition System Transition System ) ) where not (l 2 dom(H)) )

CS5205Semantics31 Transition System Transition System )

CS5205Semantics32 Transition System Transition System )

CS5205Semantics33 Transition System Transition System ) ) ) )

CS5205Semantics34 Java Abstract Machine Java Abstract Machine Reference : Tobias Nipkow and David von Oheimb Java Light is Type-Safe – Definitely, POPL Can be viewed as a bytecode language. - Being used as a portable implementation for Java. - Important to check for type-safety (subject of the paper). - Useful to prove correctness of compilation and optimization.