Operational Semantics 1 / 13

Similar documents
Outline. What is semantics? Denotational semantics. Semantics of naming. What is semantics? 2 / 21

3.4 Deduction and Evaluation: Tools Conditional-Equational Logic

CS 381: Programming Language Fundamentals

Semantics via Syntax. f (4) = if define f (x) =2 x + 55.

Intro to semantics; Small-step semantics Lecture 1 Tuesday, January 29, 2013

The semantics of a programming language is concerned with the meaning of programs, that is, how programs behave when executed on computers.

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics

The Substitution Model

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.

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

Logic: The Big Picture. Axiomatizing Arithmetic. Tautologies and Valid Arguments. Graphs and Trees

The Substitution Model. Nate Foster Spring 2018

Formal Systems and their Applications

CS2 Algorithms and Data Structures Note 10. Depth-First Search and Topological Sorting

Formal Semantics. Aspects to formalize. Lambda calculus. Approach

Last class. CS Principles of Programming Languages. Introduction. Outline

1 Introduction. 3 Syntax

The design of a programming language for provably correct programs: success and failure

Programming Languages

Lecture 3: Recursion; Structural Induction

Formal Semantics. Prof. Clarkson Fall Today s music: Down to Earth by Peter Gabriel from the WALL-E soundtrack

Programming Languages Third Edition

CIS 500 Software Foundations Fall September 25

Global Optimization. Lecture Outline. Global flow analysis. Global constant propagation. Liveness analysis. Local Optimization. Global Optimization

CMSC 330: Organization of Programming Languages

Gradual Typing for Functional Languages. Jeremy Siek and Walid Taha (presented by Lindsey Kuper)

Lecture 5 - Axiomatic semantics

Chapter 2 The Language PCF

Chapter 3. The While programming language

4.5 Pure Linear Functional Programming

Semantics of programming languages

Operational Semantics. One-Slide Summary. Lecture Outline

Programming Languages Fall 2014

Chapter 3 (part 3) Describing Syntax and Semantics

Denotational Semantics. Domain Theory

This is already grossly inconvenient in present formalisms. Why do we want to make this convenient? GENERAL GOALS

Fundamental Concepts. Chapter 1

Type Systems. Pierce Ch. 3, 8, 11, 15 CSE

CMSC 330: Organization of Programming Languages. Operational Semantics

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS522 Programming Language Semantics

Introduction to Axiomatic Semantics

Programming Languages Lecture 14: Sum, Product, Recursive Types

Simply-Typed Lambda Calculus

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS422 Programming Language Semantics

7. Introduction to Denotational Semantics. Oscar Nierstrasz

Lambda Calculus. Type Systems, Lectures 3. Jevgeni Kabanov Tartu,

Resource-bound process algebras for Schedulability and Performance Analysis of Real-Time and Embedded Systems

Type Systems Winter Semester 2006

Semantics of programming languages

Semantics of programming languages

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

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

CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011

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

Concepts of programming languages

Propositional Logic Formal Syntax and Semantics. Computability and Logic

Array Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7)

The Lambda Calculus. 27 September. Fall Software Foundations CIS 500. The lambda-calculus. Announcements

Introduction to Denotational Semantics. Brutus Is An Honorable Man. Class Likes/Dislikes Survey. Dueling Semantics

Program Syntax; Operational Semantics

CS 4110 Programming Languages & Logics. Lecture 17 Programming in the λ-calculus

Lecture Outline. Type systems and their expressiveness. Type Checking in COOL (II) Type checking with SELF_TYPE in COOL

Review. CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Let bindings (CBV) Adding Stuff. Booleans and Conditionals

Principles of Programming Languages

Mutable References. Chapter 1

CSC 501 Semantics of Programming Languages

Abstract register machines Lecture 23 Tuesday, April 19, 2016

Fall 2013 Midterm Exam 10/22/13. This is a closed-book, closed-notes exam. Problem Points Score. Various definitions are provided in the exam.

Static and User-Extensible Proof Checking. Antonis Stampoulis Zhong Shao Yale University POPL 2012

Softwaretechnik. Lecture 03: Types and Type Soundness. Peter Thiemann. University of Freiburg, Germany SS 2008

PROGRAM ANALYSIS & SYNTHESIS

The syntax and semantics of Beginning Student

The syntax and semantics of Beginning Student

Programming Up-to-Congruence, Again. WG 2.8 Estes Park

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

(How Not To Do) Global Optimizations

Constraint-based Analysis. Harry Xu CS 253/INF 212 Spring 2013

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

CSE 307: Principles of Programming Languages

Introduction to Denotational Semantics. Class Likes/Dislikes Survey. Dueling Semantics. Denotational Semantics Learning Goals. You re On Jeopardy!

CHAPTER 8. Copyright Cengage Learning. All rights reserved.

Types for References, Exceptions and Continuations. Review of Subtyping. Γ e:τ τ <:σ Γ e:σ. Annoucements. How s the midterm going?

9.5 Equivalence Relations

Contents. Chapter 1 SPECIFYING SYNTAX 1

Introduction to Lambda Calculus. Lecture 7 CS /08/09

Recursively Enumerable Languages, Turing Machines, and Decidability

CS558 Programming Languages

Computing Fundamentals 2 Introduction to CafeOBJ

Semantics of Programming Languages

Proving Theorems with Athena

! Use of formal notations. ! in software system descriptions. ! for a broad range of effects. ! and varying levels of use. !

Meeting13:Denotations

Module 3. Requirements Analysis and Specification. Version 2 CSE IIT, Kharagpur

CS558 Programming Languages

Static verification of program running time

Lecture Notes on Static Semantics

Specification and verification of a simple machine

The Java Memory Model

Subsumption. Principle of safe substitution

Meeting14:Denotations

Transcription:

Operational Semantics 1 / 13

Outline What is semantics? Operational Semantics What is semantics? 2 / 13

What is the meaning of a program? Recall: aspects of a language syntax: the structure of its programs semantics: the meaning of its programs What is semantics? 3 / 13

How to define the meaning of a program? Formal specifications denotational semantics: relates terms directly to values operational semantics: describes how to evaluate a term axiomatic semantics: describes the effects of evaluating a term... Informal/non-specifications reference implementation: execute/compile program in some implementation community/designer intuition: how people think a program should behave What is semantics? 4 / 13

Advantages of a formal semantics A formal semantics... is simpler than an implementation, more precise than intuition can answer: is this implementation correct? supports the definition of analyses and transformations prove properties about the language prove properties about programs written in the language promotes better language design better understand impact of design decisions apply semantic insights to improve the language design (e.g. compositionality) What is semantics? 5 / 13

Outline What is semantics? Operational Semantics Operational Semantics 6 / 13

What is operational semantics? Defines the meaning of a program by describing how it is evaluated General strategy 1. identify machine state: the state of evaluation sometimes just the term being evaluated 2. define the machine transitions: relates old states to new states typically using inference rules 3. define semantics in terms of machine transitions (this part is trivial) Operational Semantics 7 / 13

Two styles of operational semantics Structural operational semantics (a.k.a. small-step semantics) define transition relation ( ) representing one step of evaluation semantics is the reflexive, transitive closure of this relation ( ) Natural semantics (a.k.a. big-step semantics) define transition relation ( ) representing evaluation to a final state semantics is this relation directly Argument for structural operational semantics: + reason about intermediate steps + reason about incomplete derivations + systematic type soundness proof a bit more complicated Operational Semantics 8 / 13

Structural operational semantics example e Exp ::= true false not e if e e e Define one-step evaluation relation Step 1. identify machine state: Exp Step 2. define transition relation: e e Exp Exp Definition: e e Exp Exp not true false not false true } reduction rules how to evaluate if true e 2 e 3 e 2 if false e 2 e 3 e 3 Not e e not e not e If e e if e e 2 e 3 if e e 2 e 3 } congruence rules where to evaluate Operational Semantics 9 / 13

Defining the one-step transition Terminology: reduction rule: replaces an expression by a simpler expression redex (reducible expression): an expression that matches a reduction rule congruence rule: describes where to find the next redex value: a final state, has no more redexes (e.g. true or false) Observations: No rules for values nothing left to do! Congruence rules define the order of evaluation The meaning of a term is the sequence of steps that reduce it to a final state Operational Semantics 10 / 13

Completion of the semantics Semantics: the reflexive, transitive closure of the one-step transition judgment Step 3. Define the judgment ( ) as follows just replace state by your machine state this last step is the same for any structural operational semantics! Definition: s s Refl s s state state Trans s s s s s s Operational Semantics 11 / 13

Full definition of the Boolean language e Exp ::= true false not e if e e e Definition: e e Exp Exp not true false not false true if true e 2 e 3 e 2 if false e 2 e 3 e 3 Not e e not e not e If e e if e e 2 e 3 if e e 2 e 3 Definition: e e Refl e e Exp Exp Trans e e e e e e Operational Semantics 12 / 13

Reduction sequences Reduction sequence Shows the sequence of states after each application of a reduction rule congruence rules indicate where to find next redex (underline) reduction rules indicate how to reduce it Example reduction sequence if (not true) (not false) (if true (not true) false) if false (not false) (if true (not true) false) if true (not true) false not true false Operational Semantics 13 / 13