Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space 03-640-760603-640-5358 html://www.cs.tau.ac.il/~msagiv/courses/sem03.html.

Slides:



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

Semantics Static semantics Dynamic semantics attribute grammars
Formal Semantics of Programming Languages 虞慧群 Topic 6: Advanced Issues.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
Principles of programming languages 1: Introduction (with a simple language) Isao Sasano Department of Information Science and Engineering.
8. Introduction to Denotational Semantics. © O. Nierstrasz PS — Denotational Semantics 8.2 Roadmap Overview:  Syntax and Semantics  Semantics of Expressions.
Formal Semantics of Programming Languages 虞慧群 Topic 5: Axiomatic Semantics.
Introduction to Programming Languages Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.
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.
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.
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.
Programming Language Semantics Inductive Definitions Mooly SagivEran Yahav Schrirber 317Open space
Language Specfication and Implementation - PART II: Semantics of Procedural Programming Languages Lee McCluskey Department of Computing and Mathematical.
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.
Concepts of Programming Languages 1 Describing Syntax and Semantics Brahim Hnich Högskola I Gävle
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.
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.
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
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Denotational Semantics ICS.
Program Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Overview of program analysis Mooly Sagiv html://
Syntax & Semantic Introduction Organization of Language Description Abstract Syntax Formal Syntax The Way of Writing Grammars Formal Semantic.
CPSC 388 – Compiler Design and Construction Parsers – Context Free Grammars.
CS 2104 Prog. Lang. Concepts Dr. Abhik Roychoudhury School of Computing Introduction.
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.
Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 2: Operational Semantics I Roman Manevich Ben-Gurion University.
Chapter 25 Formal Methods Formal methods Specify program using math Develop program using math Prove program matches specification using.
Chapter Twenty-ThreeModern Programming Languages1 Formal Semantics.
Formal Semantics of Programming Languages 虞慧群 Topic 3: Principles of Induction.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
CS 363 Comparative Programming Languages Semantics.
Formal Semantics Chapter Twenty-ThreeModern Programming Languages, 2nd ed.1.
CS 611: Lecture 6 Rule Induction September 8, 1999 Cornell University Computer Science Department Andrew Myers.
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.
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.
Semantics In Text: Chapter 3.
Language Translation A programming language processor is any system that manipulates programs expressed in a PL A source program in some source language.
Languages and Compilers
Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications Chapter.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Denotational Semantics.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
C HAPTER 3 Describing Syntax and Semantics. D YNAMIC S EMANTICS Describing syntax is relatively simple There is no single widely acceptable notation or.
Formal Semantics of Programming Languages 虞慧群 Topic 2: Operational Semantics.
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
Dr. M. Al-Mulhem Denotational Semantics 1 Chapter 4 Fundamentals (Denotational Semantics)
Program Analysis and Verification Noam Rinetzky Lecture 2: Operational Semantics 1 Slides credit: Tom Ball, Dawson Engler, Roman Manevich, Erik.
CENG 424-Logic for CS Introduction Based on the Lecture Notes of Konstantin Korovin, Valentin Goranko, Russel and Norvig, and Michael Genesereth.
Information Science and Engineering
Representation, Syntax, Paradigms, Types
Spring 2017 Program Analysis and Verification Operational Semantics
Representation, Syntax, Paradigms, Types
Semantics In Text: Chapter 3.
Representation, Syntax, Paradigms, Types
Representation, Syntax, Paradigms, Types
Language semantics Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Program correctness Axiomatic semantics
Spring 2016 Program Analysis and Verification Operational Semantics
Presentation transcript:

Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html:// Textbook:Winskel The Formal Semantics of Programming Languages CS

Outline Course requirements What is semantics Who needs semantics Forms of semantics Tentative Plan Introduction to operational semantics

Course Requirements Prerequisites –Compiler Course –Basic set theory and logic A theoretical course –Forms of induction –Domain theory –No algorithms Grade –Course Notes 10% –Assignments 60% Mostly theoretical with some programming –Home exam 30%

Modern Programming Languages Imperative –PL/1 –Pascal –C Object Oriented –C++ –Java –C# Functional –Scheme –ML Logic –Prolog

Programming Languages Syntax –Which string is a legal program? –Usually defined using context free grammar+ contextual constraints Semantics –What does a program mean? –What is the output of the program on a given run? –When does a runtime error occur? –A formal definition

Benefits of Formal Semantics Programming language design –hard- to-define= hard-to-implement=hard-to-use –Avoid design mistakes Programming language implementation –Compiler Correctness Correctness of program optimizations Design of Static Analysis Programming language understanding Program correctness Program equivalence Automatic generation of interpreter Techniques used in software engineering

Desired Features of PL Semantics Tractable –as simple as possible without losing the ability to express behavior accurately Abstract –uncluttered by irrelevant detail Computational –an accurate abstraction from runtime behavior Compositional –The meaning of compound language construct is defined using the meaning of subconstructs –Supports modular reasoning

Alternative Formal Semantics Operational Semantics [Plotkin] –The meaning of the program is described “operationally” –Structural Operational Semantics Denotational Semantics [Strachey, Scott] –The meaning of the program is an input/output relation Axiomatic Semantics [Floyd, Hoare] –The meaning of the program is observed properties –Proof rules to show that the program is correct Complement each other

Tentative Plan A simple programming language IMP –Structural operational Semantics of IMP –Denotational Semantics of IMP –[Axiomatic Semantics of IMP] –Non-Determinism and Parallelism Advanced programming languages –Java byte code

Chapter 2 Introduction to Operational Semantics

IMP: A Simple Imperative Language numbers N –Positive and negative numbers –n, m  N truth values T={true, false} locations Loc –X, Y  Loc arithmetic Aexp –a  Aexp boolean expressions Bexp –b  Bexp commands Com –c  Com

(3+5)   5+ 3 Abstract Syntax for IMP Aexp –a ::= n | X | 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 | X := a | c 0 ; c 1 | if b then c 0 else c 1 | while b do c 2+3  4-5 (2+(3  4))-5 ((2+3)  4))-5

Example Program Y := 1; while  (X=1) do Y := Y * X; X := X - 1

But what about semantics

Expression Evaluation States –Mapping locations to values –  - The set of states  : Loc  N  (X)=  X=value of X in   = [ X  5, Y  7] –The value of X is 5 –The value of Y is 7 –The value of Z is undefined – For a  Exp,   , n  N,  n –a is evaluated in  to n

Evaluating (a 0 + a 1 ) at  Evaluate a 0 to get a number n 0 at  Evaluate a 1 to get a number n 1 at  Add n 0 and n 1

Expression Evaluation Rules Numbers –  n Locations –   (X) Sums Subtractions Products Axioms

Derivations A rule instance –Instantiating meta variables with corresponding values

Derivation (Tree) Axioms in the leafs Rule instances at internal nodes

Computing a derivation We write  n when there exists a derivation tree whose root is  n Can be computed in a top-down manner At every node try all derivations “in parallel”

Recap Operational Semantics –The rules can be implemented easily –Define interpreter Structural Operational Semantics –Syntax directed Natural semantics

Equivalence of IMP expressions a0  a1a0  a1 iff

Boolean Expression Evaluation Rules  true  false

Boolean Expression Evaluation Rules(cont)

Equivalence of Boolean expressions b0 b1b0 b1 iff

Extensions Shortcut evaluation of Boolean expressions “Parallell” evaluation of Boolean expressions Other data types

The execution of commands   ’ –c terminates on  in a final state  ’ Initial state  0 –  0 (X)=0 for all X Handling assignments   ’   [5/X]

Rules for commands   Sequencing: Conditionals: Atomic

Rules for commands (while)

Example Program Y := 1; while  (X=1) do Y := Y * X; X := X - 1

Equivalence of commands c0 c1c0 c1 iff

Proposition 2.8 while b do c  if then (c; while b do c) else skip

Small Step Operational Semantics The natural semantics define evaluation in large steps –Abstracts “computation time” It is possible to define a small step operational semantics –  1 “one” step of executing a in a state  yields a’ in a state  ’

Small Step Semantics for Additions

Summary Operational semantics enables to naturally express program behavior Can handle –Non determinism –Concurrency –Procedures –Object oriented –Pointers and dynamically allocated structures But remains very closed to the implementation –Two programs which compute the same functions are not necessarily equivalent