More on Operational Semantics

Similar documents
Application: Programming Language Semantics

Hoare logic. WHILE p, a language with pointers. Introduction. Syntax of WHILE p. Lecture 5: Introduction to separation logic

Hoare logic. Lecture 5: Introduction to separation logic. Jean Pichon-Pharabod University of Cambridge. CST Part II 2017/18

Compilation and Program Analysis (#11) : Hoare triples and shape analysis

Formal Semantics of Programming Languages

Formal Semantics of Programming Languages

Hoare Logic and Model Checking

Formal Syntax and Semantics of Programming Languages

Formal Syntax and Semantics of Programming Languages

Big-step Operational Semantics (aka Natural Semantics)

The Programming Language Core

CS422 - Programming Language Design

Semantics and Verification of Software

PROGRAM ANALYSIS & SYNTHESIS

A CRASH COURSE IN SEMANTICS

Foundations. Yu Zhang. Acknowledgement: modified from Stanford CS242

3.7 Denotational Semantics

axiomatic semantics involving logical rules for deriving relations between preconditions and postconditions.

The Rule of Constancy(Derived Frame Rule)

Program Evaluation. From our evaluation rules we have, We have σ =(σ 0 [2/x])[3/y]. What is the value for σ(y) and σ(x)? How about σ(z), z Loc?

Formal Semantics of Programming Languages

Recency Types for Dynamically-Typed, Object-Based Languages

Syntax vs. semantics. Detour: Natural deduction. Syntax vs. semantics (cont d) Syntax = grammatical structure Semantics = underlying meaning

Programming Language Concepts, cs2104 Lecture 04 ( )

A Behavioral Type System for Memory-Leak Freedom. Qi Tan, Kohei Suenaga, and Atsushi Igarashi Kyoto University

Compiler Construction

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

Hoare triples. Floyd-Hoare Logic, Separation Logic

Type checking. Jianguo Lu. November 27, slides adapted from Sean Treichler and Alex Aiken s. Jianguo Lu November 27, / 39

CSC 7101: Programming Language Structures 1. Operational Semantics. Winskel, Ch. 2 Slonneger and Kurtz Ch 8.4, 8.5, 8.6. Operational vs.

A Structural Operational Semantics for JavaScript

02157 Functional Programming Interpreters for two simple languages including exercises

Separation Logic: syntax, semantics and calculus

Towards a Module System for K

3.1 IMP: A Simple Imperative Language

Note that in this definition, n + m denotes the syntactic expression with three symbols n, +, and m, not to the number that is the sum of n and m.

Modules, Structs, Hashes, and Operational Semantics

High-Level Small-Step Operational Semantics for Software Transactions

Writing Evaluators MIF08. Laure Gonnord

Common Misunderstandings from Exam 1 Material

CS 242. Fundamentals. Reading: See last slide

Operational Semantics. One-Slide Summary. Lecture Outline

Programmin Languages/Variables and Storage

Type Checking. Outline. General properties of type systems. Types in programming languages. Notation for type rules.

An Extended Behavioral Type System for Memory-Leak Freedom. Qi Tan, Kohei Suenaga, and Atsushi Igarashi Kyoto University

Induction and Semantics in Dafny

Outline. General properties of type systems. Types in programming languages. Notation for type rules. Common type rules. Logical rules of inference

Lecture Outline. COOL operational semantics. Operational Semantics of Cool. Motivation. Lecture 13. Notation. The rules. Evaluation Rules So Far

Introduction to Shape and Pointer Analysis

Compilers. Cool Semantics II. Alex Aiken

Chapter 11: Compiler II: Code Generation

Lecture 5 - Axiomatic semantics

Recap: Functions as first-class values

Lecture 20: High-level Synthesis (1)

Overview. Probabilistic Programming. Dijkstra s guarded command language: Syntax. Elementary pgcl ingredients. Lecture #4: Probabilistic GCL

Abstract Semantic Differencing for Numerical Programs

A Structural Operational Semantics for JavaScript

Relation Overriding. Syntax and Semantics. Simple Semantic Domains. Operational Semantics

Project 3 Due October 21, 2015, 11:59:59pm

Principles of Programming Languages

Dynamic Types, Concurrency, Type and effect system Section and Practice Problems Apr 24 27, 2018

Type Systems Winter Semester 2006

Mutable References. Chapter 1

Semantics with Applications 3. More on Operational Semantics

A Grainless Semantics for Parallel Programs with Shared Mutable Data

CPSC 427: Object-Oriented Programming

Exercises on Semantics of Programming Languages

CS360 Lecture 5 Object-Oriented Concepts

Getting to know you. Anatomy of a Process. Processes. Of Programs and Processes

A semantics for concurrent separation logic

0. Overview of this standard Design entities and configurations... 5

Verification of Parameterized Concurrent Programs By Modular Reasoning about Data and Control

Denotational Semantics. Domain Theory

Pointers. Chapter 8. Decision Procedures. An Algorithmic Point of View. Revision 1.0

Qualifying Exam in Programming Languages and Compilers

Lecture Outline. COOL operational semantics. Operational Semantics of Cool. Motivation. Notation. The rules. Evaluation Rules So Far.

3.4 Denotational Semantics

The exercises and answer for programming language class

Foundations: Syntax, Semantics, and Graphs

Linear Logic, Heap-shape Patterns and Imperative Programming

Shared Variables and Interference

A Revisionist History of Denotational Semantics

Compiler II: Code Generation Human Thought

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres

Lecture 3 SPIN and Promela

Lecture 6: The Declarative Kernel Language Machine. September 13th, 2011

Run-time Environments. Lecture 13. Prof. Alex Aiken Original Slides (Modified by Prof. Vijay Ganesh) Lecture 13

Introduction to CBMC. Software Engineering Institute Carnegie Mellon University Pittsburgh, PA Arie Gurfinkel December 5, 2011

Process a program in execution; process execution must progress in sequential fashion. Operating Systems

Static semantics. Lecture 3-6: Semantics. Attribute grammars (2) Attribute grammars. Attribute grammars example. Dynamic semantics

Mosig M1 - PLSCD Written exam

UNIT 3

Compiler Construction

Trust, but Verify. Two-Phase Typing for Dynamic Languages. Panagiotis Vekris, Benjamin Cosman, Ranjit Jhala. University of California, San Diego

Intermediate Programming, Spring 2017*

CS4215 Programming Language Implementation. Martin Henz

Computer Programming II C++ (830)

Shared Variables and Interference

Goals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1

Transcription:

More on Operational Semantics (Slides modified from those created by Xinyu Feng) 1 / 23

Outline Various formulations Extensions Going wrong Local variable declaration Heap Big-step operational semantics 2 / 23

Outline Various formulations Extensions Going wrong Local variable declaration Heap Big-step operational semantics 3 / 23

A different formulation Assignment: e intexp σ = n (x := e, σ) σ{x n} Here e intexp σ = n iff (e, σ) (n, σ) Compared to the original version: (e, σ) (e, σ) (x := e, σ) (x := e, σ) (x := n, σ) σ{x n} 4 / 23

A variation Assignment: e intexp σ = n (x := e, σ) (skip, σ{x n}) Here skip is overloaded as a flag for termination. 5 / 23

A variation Sequential composition: (c 0, σ) (c 0, σ ) (c 0 ; c 1, σ) (c 0 ; c 1, σ ) (skip ; c 1, σ) (c 1, σ) One more identity step is introduced after every command: consider x := x + 1 ; y := y + 2. Compared to the earlier rules: e intexp σ = n (x := e, σ) σ{x n} (skip, σ) σ (c 0, σ) (c 0, σ ) (c 0 ; c 1, σ) (c 0 ; c 1, σ ) (c 0, σ) σ (c 0 ; c 1, σ) (c 1, σ ) 6 / 23

A variation Other rules: b boolexp σ = tt (if b then c 0 else c 1, σ) (c 0, σ) b boolexp σ = ff (if b then c 0 else c 1, σ) (c 1, σ) b boolexp σ = tt (while b do c, σ) (c ; while b do c, σ) b boolexp σ = ff (while b do c, σ) (skip, σ) 7 / 23

Outline Various formulations Extensions Going wrong Local variable declaration Heap Big-step operational semantics 8 / 23

Going wrong Expressions: Expression evaluation: e ::=... e/e n 2 0 n 1 /n 2 = n (n 1 /n 2, σ) (n, σ) (n 1 /0, σ) abort 9 / 23

Going wrong Assignment: e intexp σ = n (x := e, σ) (skip, σ{x n}) e intexp σ = (x := e, σ) abort Here e intexp σ = n iff (e, σ) (n, σ) e intexp σ = iff (e, σ) abort 10 / 23

Going wrong Add new rules: (c 0, σ) abort (c 0 ; c 1, σ) abort b boolexp σ = (if b then c 0 else c 1, σ) abort b boolexp σ = (while b do c, σ) abort 11 / 23

Local variable declaration Statements: c ::=... newvar x := e in c An unsatisfactory attempt: n = σ x (newvar x := e in c, σ) (x := e ; c ; x := n, σ) Unsatisfactory because the value of local variable x could be exposed to external observers while c is executing. This is a problem when we have concurrency. 12 / 23

Semantics for newvar Solution (due to Eugene Fink): n = e intexp σ (c, σ{x n}) (c, σ ) n = σ x (newvar x := e in c, σ) (newvar x := n in c, σ {x σ x}) (newvar x := e in skip, σ) (skip, σ) e intexp σ = (newvar x := e in c, σ) abort n = e intexp σ (c, σ{x n}) abort (newvar x := e in c, σ) abort 13 / 23

Heap for dynamically-allocated data (States) σ ::= (s, h) (Stores) s Var Values (Heaps) h Loc fin Values (Values) v Int Bool Loc Here fin represents a partial mapping. 14 / 23

A simple language with heap manipulation Statements: c ::=... x := alloc(e) allocation y := [x] lookup [x] := e mutation free(x) deallocation 15 / 23

Operational semantics for alloc l dom(h) e intexp s = n (x := alloc(e), (s, h)) (skip, (s{x l}, h {l n})) 16 / 23

Operational semantics for free s x = l l dom(h) (free(x), (s, h)) (skip, (s, h\{l})) 17 / 23

Operational semantics for lookup and mutation s x = l h l = n (y := [x], (s, h)) (skip, (s{y n}, h)) s x = l l dom(h) e intexp s = n ([x] := e, (s, h)) (skip, (s, h{l n})) 18 / 23

Outline Various formulations Extensions Going wrong Local variable declaration Heap Big-step operational semantics 19 / 23

Big-Step Semantics (n, σ) n σ x = n (x, σ) n (e 1, σ) n 1 (e 2, σ) n 2 (e 1 + e 2, σ) n 1 + n 2 The last rule can be generalized to: (e 1, σ) n 1 (e 2, σ) n 2 (e 1 op e 2, σ) n 1 op n 2 Here italics indicates program text, and boldface indicates mathematical operators. 20 / 23

Big-Step Semantics (e, σ) n (x := e, σ) σ{x n} (skip, σ) σ (c 0, σ) σ (c 1, σ ) σ (c 0 ; c 1, σ) σ (b, σ) tt (c 0, σ) σ (if b then c 0 else c 1, σ) σ (b, σ) ff (c 1, σ) σ (if b then c 0 else c 1, σ) σ (b, σ) ff (while b do c, σ) σ (b, σ) tt (c, σ) σ (while b do c, σ ) σ (while b do c, σ) σ 21 / 23

Big-Step Semantics (e, σ) n (c, σ{x n}) σ (newvar x := e in c, σ) σ {x σ x} Also, we should add rules to handle the abort case. For instance, (e, σ) abort (x := e, σ) abort (c 0, σ) abort (c 0 ; c 1, σ) abort 22 / 23

Equivalence between big-step and small-step semantics For all c and σ, (c, σ) abort iff (c, σ) abort (c, σ) σ iff (c, σ) (skip, σ ) 23 / 23