Introduction to Structural Operational Semantics

Similar documents
2 Introduction to operational semantics

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.

CS2104 Prog. Lang. Concepts

Introduction to Axiomatic Semantics (1/2)

Introduction to Axiomatic Semantics (1/2)

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

Programming Languages Third Edition

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

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

Propositional Calculus. CS 270: Mathematical Foundations of Computer Science Jeremy Johnson

Introduction to Axiomatic Semantics

Propositional Calculus: Boolean Algebra and Simplification. CS 270: Mathematical Foundations of Computer Science Jeremy Johnson

Propositional Calculus: Boolean Functions and Expressions. CS 270: Mathematical Foundations of Computer Science Jeremy Johnson

In Our Last Exciting Episode

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

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

[Ch 6] Set Theory. 1. Basic Concepts and Definitions. 400 lecture note #4. 1) Basics

Lecture 5 - Axiomatic semantics

The Formal Semantics of Programming Languages An Introduction. Glynn Winskel. The MIT Press Cambridge, Massachusetts London, England

Formal Semantics of Programming Languages

Semantics. There is no single widely acceptable notation or formalism for describing semantics Operational Semantics

Formal Semantics of Programming Languages

CSC 501 Semantics of Programming Languages

Chapter 3. Describing Syntax and Semantics

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

Denotational Semantics

COSC252: Programming Languages: Semantic Specification. Jeremy Bolton, PhD Adjunct Professor

Lectures 20, 21: Axiomatic Semantics

Propositional Calculus. Math Foundations of Computer Science

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

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

Syntax and Grammars 1 / 21

6. Hoare Logic and Weakest Preconditions

Chapter 3. Describing Syntax and Semantics ISBN

Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax

Propositional Logic. Andreas Klappenecker

Principles of Programming Languages

2SAT Andreas Klappenecker

7. Introduction to Denotational Semantics. Oscar Nierstrasz

Semantics with Applications 3. More on Operational Semantics

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

3. According to universal addressing, what is the address of vertex d? 4. According to universal addressing, what is the address of vertex f?

Lecture 4 Searching Arrays

Lecture Notes on Linear Search

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions):

CSc 520 Principles of Programming Languages

Denotational Semantics. Domain Theory

Promela and SPIN. Mads Dam Dept. Microelectronics and Information Technology Royal Institute of Technology, KTH. Promela and SPIN

Flow of Control. Flow of control The order in which statements are executed. Transfer of control

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed

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

CMSC 330: Organization of Programming Languages. Operational Semantics

Abstract Interpretation

Chapter 10 Part 1: Reduction

Foundations: Syntax, Semantics, and Graphs

Application: Programming Language Semantics

A CRASH COURSE IN SEMANTICS

CA4003 Compiler Construction Assignment Language Definition

Semantics. A. Demers Jan This material is primarily from Ch. 2 of the text. We present an imperative

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

Com S 541. Programming Languages I

Chapter 3. Describing Syntax and Semantics ISBN

Chapter 3. Describing Syntax and Semantics

SOFTWARE VERIFICATION AND COMPUTER PROOF (lesson 1) Enrico Tassi Inria Sophia-Antipolis

Chapter 3 (part 3) Describing Syntax and Semantics

Chapter 9 Deductive Arguments II Truth-Functional Logic. Tutorial: Truth Tables

Flow Control. So Far: Writing simple statements that get executed one after another.

1 A question of semantics

10/30/18. Dynamic Semantics DYNAMIC SEMANTICS. Operational Semantics. An Example. Operational Semantics Definition Process

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #06 Loops: Operators

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS522 Programming Language Semantics

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

Motivating Examples (1.1) Selections. Motivating Examples (1.2) Learning Outcomes. EECS1022: Programming for Mobile Computing Winter 2018

Contents. Chapter 1 SPECIFYING SYNTAX 1

3.4 Denotational Semantics

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS422 Programming Language Semantics

Outline for Today CSE 142. CSE142 Wi03 G-1. withdraw Method for BankAccount. Class Invariants

Selections. EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG

Lambda Calculus.

The learning objectives of this chapter are the followings. At the end of this chapter, you shall

Lecture 9. Monday, January 31 CS 205 Programming for the Sciences - Lecture 9 1

Operational Semantics. One-Slide Summary. Lecture Outline

Denotational Semantics

Syntax of Eiffel: a Brief Overview

SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION

Axiomatic Specification. Al-Said, Apcar, Jerejian

Basic Structure of Denotational Definitions

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions):

Commands, and Queries, and Features. Syntax of Eiffel: a Brief Overview. Escape Sequences. Naming Conventions

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFR08013 INFORMATICS 1 - FUNCTIONAL PROGRAMMING

Ch 3.4 The Integers and Division

Homework 1. Due Date: Wednesday 11/26/07 - at the beginning of the lecture

Software Engineering Lecture Notes

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages. Lambda calculus

Introduction to Denotational Semantics

Programming Language Definition. Regular Expressions

Program Analysis: Lecture 02 Page 1 of 32

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

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

Discrete Mathematics Lecture 4. Harper Langston New York University

Transcription:

Introduction to Structural Operational Semantics Patricia ILL School of Computing University of Leeds United Kingdom Roberto ANARA Department of Mathematics University of Parma Italy Copyright c 200 Patricia ill Distributed under the terms of the NU Free Documentation License 12 1

SYNTAX AND SEMANTICS Syntax is concerned with the form of expressions that are allowed in a language Semantics describes what should be the result of executing or evaluating the program Static semantics describes what kinds of syntactically correct expressions are executable Dynamic semantics describes the run-time behaviour including the expected results YNTAX AND SEMANTICS 2

APPROACES TO SEMANTICS Operational Semantics: The meaning of a program in terms of how it executes on an abstract machine This course will follow the approach called Structural Operational Semantics SOS) proposed by Plotkin Useful for modelling the execution behaviour of a program Denotational Semantics: The mathematical meaning of a program and models the expected result rather than how the result might be obtained This approach was first proposed by C Strachey and later formalised by D Scott Useful for understanding the internal logic of a program PPROACES TO SEMANTICS 3

APPROACES TO SEMANTICS CONT Axiomatic Semantics: Provides correctness assertions for each program construct The approach was developed by RW Floyd and CAR oare Useful for verying that a program s computed results are correct with respect to the specication PPROACES TO SEMANTICS CONT

IMP: AN IMPERATIVE LANUAE Imp is a simple imperative language for elementary arithmetic with just a conditional command and a while loop command see Chapter 2 of Winskel) We present here: the abstract syntax ie the sentences to which we will associate a semantics) the operational semantics of expressions ie the rules governing their evaluation the operational semantics of commands ie the rules governing their evaluation execution) P: AN IMPERATIVE LANUAE

) * %& ' %& ' $ " " The basic syntactic sets are: IMP: TE ASTRACT SYNTAX Integers: ooleans: Variables: Arithmetic expressions: oolean expressions: Commands: + We shall regard the variables as locations The )and are called syntactic metavariables: they denote a generic element of the respective syntactic category P: TE ASTRACT SYNTAX 6

IMP: TE LANUAE FORMATION RULES $ %& ' : - - - - 0 %& ' : - - 1-2 - - * +: ) skip - - ) 3 ) - )then else ) " - while )do P: TE LANUAE FORMATION RULES

1 1 * + : %& ' %& ' $ 3 6 8 1< 6 8 0 IMP: EXAMPLES OF SYNTACTICALLY CORRECT SENTENCES while do skip else P: EXAMPLES OF SYNTACTICALLY CORRECT SENTENCES 8

@ >?% A EXECUTION STORES A store maps each variable location) to a value In the language Imp these values must be numbers Let DC F @ C A E Example: Let F so that The store can and will) be more compactly denoted by XECUTION STORES

I I J 0 ) CONFIURATIONS A non-terminal configuration is a pair of the form or boolean expression denote the situation of an arithmetic expression waiting for evaluation using the store or a : ) J I using the store : denotes the situation of a command ) waiting for execution I J skip J ONFIURATIONS 10

Kin a store TRANSITION RULES Structural operational semantics provides transition rules for the evaluation of expressions and execution of commands A transition for an arithmetic expression forms: has one of the K K KML L A transition rule is written as premise conclusion RANSITION RULES 11

EVALUATION OF ARITMETIC EXPRESSIONS 3 3 3 0 VALUATION OF ARITMETIC EXPRESSIONS 12

N EVALUATION OF ARITMETIC EXPRS: EXAMPLES Let Then and Using the rules we write: and then VALUATION OF ARITMETIC EXPRS: EXAMPLES 13

0 EVALUATION OF ARITMETIC EXPRS: EXAMPLES CONT The rules for evaluating arithmetic expressions can be combined to form a derivation tree For example consider the expression with We obtain the derivation tree 0 O 0 VALUATION OF ARITMETIC EXPRS: EXAMPLES CONT 1

EVALUATION OF OOLEAN EXPRESSIONS I Truth values: Equality: 3 P VALUATION OF OOLEAN EXPRESSIONS I 1

EVALUATION OF OOLEAN EXPRESSIONS II Inequality: 1 1 3 RQ 1 VALUATION OF OOLEAN EXPRESSIONS II 16

EVALUATION OF OOLEAN EXPRESSIONS III Negation: 3 Conjunction: TS 2 Disjunction: VU VALUATION OF OOLEAN EXPRESSIONS III 1

EVALUATION OF EXPRESSIONS: EXAMPLES The rules for evaluating arithmetic expressions can be combined For example consider the expression 2 with 2 VALUATION OF EXPRESSIONS: EXAMPLES 18

ZY \ ^ ZY \ 3 [ \ >?% ZY ^ XW []\ >?% ZY XW EQUIVALENCE OF EXPRESSIONS Two expressions are equivalent they evaluate to the same value in any given store: QUIVALENCE OF EXPRESSIONS 1

2 SORT-CIRCUIT EVALUATION OF OOLEAN EXPRESSIONS Ever heard of short-circuit evaluation? It is a mechanism used by C C ++ and many other programming languages but not by IMP whereby the evaluation of boolean expressions is stopped as soon as the overall value of the expression is known If is true is always true independently from Short-circuit evaluation means that in this case is not evaluated The case for is dual: is false evaluating avoided can be Exercise: Define a variation of IMP that uses short-circuit evaluation of boolean expressions Exercise: Can something similar be done for arithmetic expressions? ow? ORT-CIRCUIT EVALUATION OF OOLEAN EXPRESSIONS 20

except for the location EXECUTION OF COMMANDS: INTRODUCTION The execution of a command may change the values of the store Transition relations and transition systems are used to define the operational semantics of a program Example: L where is the same as the store has the value L which XECUTION OF COMMANDS: INTRODUCTION 21

d c ` a b a EXECUTION OF COMMANDS: NOTATION Let each : `_be a store Then the store is defined as follows for _ P Then we can write L _ a ` It is assumed that in the initial state of the store all the variables have a value Suppose is the initial store then L L XECUTION OF COMMANDS: NOTATION 22

3 ) ` ) L ) L L ) L L L _ a skip EVALUATION OF COMMANDS: RULES I Skip operation: Assignment: Command sequence: VALUATION OF COMMANDS: RULES I 23

)then )then )do )do )do 3 ) ) 3 while ) while L L L L L while ) L ) L EVALUATION OF COMMANDS: RULES II Conditional: While-loop: VALUATION OF COMMANDS: RULES II 2 L else L else L

EVALUATION OF COMMANDS: AN EXAMPLE For example with consider the command while do _ ` a VALUATION OF COMMANDS: AN EXAMPLE 2

AN EXAMPLE CONT Let So we can continue the derivation: while do e gf h i kj while do N EXAMPLE CONT 26

) EQUIVALENCE OF COMMANDS Two commands are equivalent when executed starting from the same store they evaluate to the same store W [ \ L ) L ) ^ L ) ) ZY ) ml ) ml >?% ZY Exercise: Let while while Kdo Kdo n Is XW )? QUIVALENCE OF COMMANDS 2