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

Similar documents
Com S 541. Programming Languages I

An Annotated Language

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

Lecture 5 - Axiomatic semantics

Operational Semantics 1 / 13

Chapter 2 & 3: Representations & Reasoning Systems (2.2)

Programming Languages Third Edition

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

Introduction to Axiomatic Semantics

CS2104 Prog. Lang. Concepts

Lectures 20, 21: Axiomatic Semantics

3.4 Deduction and Evaluation: Tools Conditional-Equational Logic

From Hoare Logic to Matching Logic Reachability. Grigore Rosu and Andrei Stefanescu University of Illinois, USA

Chapter 3. Describing Syntax and Semantics ISBN

Denotational Semantics

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

The Programming Language Core

6. Hoare Logic and Weakest Preconditions

Semantics of programming languages

Contents. Chapter 1 SPECIFYING SYNTAX 1

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

Chapter 3 (part 3) Describing Syntax and Semantics

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

Formal Semantics of Programming Languages

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

Softwaretechnik. Program verification. Albert-Ludwigs-Universität Freiburg. June 28, Softwaretechnik June 28, / 24

CMSC 330: Organization of Programming Languages

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

CSE 307: Principles of Programming Languages

Formal Semantics of Programming Languages

Semantics of programming languages

An Evolution of Mathematical Tools

Theorem proving. PVS theorem prover. Hoare style verification PVS. More on embeddings. What if. Abhik Roychoudhury CS 6214

Axiomatic Rules. Lecture 18: Axiomatic Semantics & Type Safety. Correctness using Axioms & Rules. Axiomatic Rules. Steps in Proof

What if current foundations of mathematics are inconsistent? Vladimir Voevodsky September 25, 2010

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.

Hoare Logic. COMP2600 Formal Methods for Software Engineering. Rajeev Goré

Formal Systems and their Applications

Hoare triples. Floyd-Hoare Logic, Separation Logic

Induction and Semantics in Dafny

Introduction to Axiomatic Semantics (1/2)

Semantics of programming languages

Static verification of program running time

Revisiting Kalmar completeness metaproof

Axiomatic Specification. Al-Said, Apcar, Jerejian

Type Inference Systems. Type Judgments. Deriving a Type Judgment. Deriving a Judgment. Hypothetical Type Judgments CS412/CS413

Chapter 3. Describing Syntax and Semantics

Chapter 3. Describing Syntax and Semantics ISBN

Chapter 3. Describing Syntax and Semantics

Propositional Logic. Part I

CSC 501 Semantics of Programming Languages

A CRASH COURSE IN SEMANTICS

Chapter 1. Introduction

Modules, Structs, Hashes, and Operational Semantics

Chapter 3. Syntax - the form or structure of the expressions, statements, and program units

Abstract Interpretation

Denotational Semantics

Introduction to Axiomatic Semantics (1/2)

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

Chapter 3. Semantics. Topics. Introduction. Introduction. Introduction. Introduction

Part II. Hoare Logic and Program Verification. Why specify programs? Specification and Verification. Code Verification. Why verify programs?

The Substitution Model

Propositional Logic. Andreas Klappenecker

λ calculus is inconsistent

AXIOMS OF AN IMPERATIVE LANGUAGE PARTIAL CORRECTNESS WEAK AND STRONG CONDITIONS. THE AXIOM FOR nop

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter p. 1/27

Defining Languages GMU

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

ALGOL 48 AND ALGOL 50 ALGOLIC LANGUAGES IN MATHE- MATICS

Logic and Computation

Finite Model Generation for Isabelle/HOL Using a SAT Solver

Computing Fundamentals 2 Introduction to CafeOBJ

Warm-Up Problem. 1. What is the definition of a Hoare triple satisfying partial correctness? 2. Recall the rule for assignment: x (assignment)

Proving the Correctness of Distributed Algorithms using TLA

Verification Condition Generation

Verification Conditions. Juan Pablo Galeotti, Alessandra Gorla, Andreas Rau Saarland University, Germany

Higher-Order Logic. Specification and Verification with Higher-Order Logic

The Rule of Constancy(Derived Frame Rule)

CMSC 330: Organization of Programming Languages. Operational Semantics

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

Automated Reasoning. Natural Deduction in First-Order Logic

Principles of Programming Languages

Type Systems. Today. 1. Organizational Matters. 1. Organizational Matters. Lecture 1 Oct. 20th, 2004 Sebastian Maneth. 1. Organizational Matters

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

Towards a Logical Reconstruction of Relational Database Theory

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

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

Formal Methods for Java

3.7 Denotational Semantics

Proof Carrying Code(PCC)

Dynamic Logic David Harel, The Weizmann Institute Dexter Kozen, Cornell University Jerzy Tiuryn, University of Warsaw The MIT Press, Cambridge, Massac

Formal Semantics of Programming Languages

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

Program Analysis: Lecture 02 Page 1 of 32

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

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

CIS 500 Software Foundations. Final Exam. May 3, Answer key

Type Systems COMP 311 Rice University Houston, Texas

Application: Programming Language Semantics

Formal Methods. CITS5501 Software Testing and Quality Assurance

Transcription:

Semantics The semantics of a programming language is concerned with the meaning of programs, that is, how programs behave when executed on computers. The semantics of a programming language assigns a precise meaning to every sentence of the language that can be formed using the given syntax definition. There are three approaches to define the semantics of a programming language: Axiomatic semantics, Operational semantics, Denotational semantics. 4

The Hilbert-style Proof System A Hilbert-style proof system consists of axioms and proof rules. An axiom of a proof system is a formula that is provable by definition. An inference rule asserts that if some list of formulas is provable, then so is another formula. A proof is a structured object built from formulas according to constraints established by a set of axioms and inference rules. The rule format: Premise 1 Premise 2 Conclusion... Premise n We construct a proof from proofs: Premise Conclusion Premise 2 Conclusion 2 Conclusion 1... 1 Premisen Conclusion n 5

Axiomatic Semantics The axiomatic semantics is a formal (proof) system for deriving equations between expressions. The basic idea of the axiomatic method is to define the meaning of language elements indirectly using logical assertions. For example, we can write {E 1 } C {E 2 }, called a Hoare triple, to state that if the boolean expression E 1 holds prior the computation of C, and if C terminates, then the boolean expression E 2 must hold as well. Examples: { a > 0 } a : a + 1 { a > 1 } {E 1 } C 1 {E 2 } {E 2 } C 2 {E 3 } {E 1 } C 1 ;C 2 {E 3 } 6

Example Rules Statement Type Proof Rule C def C.Target : C.Source true {Q[C.Source\ C.Target]}C{Q} C def if C.Test then C.Then else C.Else {C.Test P}C.Then{Q} { C.Test {P}C{Q} P}C.Else{Q} Rule of Consequence P P' {P'}C{Q'} {P}C{Q} Q' Q 7

Example Using axiomatic semantics, we need to prove the validity of a given Hoare triple. Example: {true} if (a > b) then C def m a; else m b; {m 8

9 Proof a;{m b}m {a a;{m m {a true b) a b a b;{m b}m {a b;{m m {b true b) b b a < < Premise I: Premise II: {true}c{m b;{m true}m b {a a;{m true}m b {a <

Operational Semantics The operational semantics is based on a directed form of equational reasoning called reduction. Reduction may be regarded as a form of symbolic evaluation. The basic idea of the operational method is to define the meaning of the language elements by means of a (labeled) transition system. The operational semantics definition provides means to display the computation steps undertaken when a program is evaluated to its output. Some forms of operational semantics are interpreted-based, with instruction counters, data structures, and the like, and others are inference rule-based, with proof trees that show control flows and data dependencies. 10

Example Transition Rules Statement Type Transition Rule C def C.Target : C.Source σ (C.Target : σ (C.Source) υ C.Source) σ {(C.Target, υ)} C def if C.Test then C.Then else C.Else σ (C.Test true) σ (C.Then) σ ' σ (if C.Test then C.Then else C.Else) σ ' σ (C.Test false) σ (C.Else) σ ' σ (if C.Test then C.Then else C.Else) σ ' 11

Denotational Semantics The denotational semantics, or model theory, is defined in the spirit of equational logic or first-order logic. A denotational semantics definition (model) consists of a family of sets, one for each type, with the property that each well-typed expression may be interpreted as a specific element of the appropriate set. The denotational semantics is a recursive definition that maps welltyped derivation trees to their mathematical meanings. For example, the set Bool consists of two meanings: Bool {true, false} and an operation not : Bool Bool with not(false) true, not(true) false. The denotational method does not maintain states, but the meaning of a program is given as a function that interprets all language elements of a given program as elements of a corresponding set of values. 12

Example Meaning Functions Statement Type C def C.Target : C.Source Meaning Functions f ( C.Target : C.Source, σ ) if ( f ( C.Target, σ ) υ) then σ {( f ( C.Target, σ ), f ( C.Source, σ ))} else ERROR C def if C.Test then C.Then else C.Else f ( if C.Test then C.Then else C.Else, σ ) if f ( C.Test, σ ) then f ( C.Then, σ ) else f ( C.Else, σ ) 13