Formal Semantics of Programming Languages 虞慧群 Topic 2: Operational Semantics.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 10.
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
Semantics Static semantics Dynamic semantics attribute grammars
Intermediate Code Generation
Models of Concurrency Manna, Pnueli.
ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Formal Semantics of Programming Languages 虞慧群 Topic 6: Advanced Issues.
3-Valued Logic Analyzer (TVP) Tal Lev-Ami and Mooly Sagiv.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
Formal Semantics of Programming Languages 虞慧群 Topic 5: Axiomatic Semantics.
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.
CS 355 – Programming Languages
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
Programming Language Semantics Axiomatic Semantics Chapter 6.
1 Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications.
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.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Operational Semantics ICS.
Programming Language Semantics Denotational Semantics Chapter 5 Part II.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Kernel language semantics Carlos Varela RPI Adapted with permission.
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
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.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Axiomatic Semantics ICS 535.
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.
Propositional Equivalence Goal: Show how propositional equivalences are established & introduce the most important such equivalences.
Imperative Programming
CPSC 388 – Compiler Design and Construction Parsers – Context Free Grammars.
Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 2: Operational Semantics I Roman Manevich Ben-Gurion University.
Formal Semantics of Programming Languages 虞慧群 Topic 3: Principles of Induction.
CS 363 Comparative Programming Languages Semantics.
Formal Semantics Chapter Twenty-ThreeModern Programming Languages, 2nd ed.1.
Principles of programming languages 5: An operational semantics of a small subset of C Department of Information Science and Engineering Isao Sasano.
CS 611: Lecture 6 Rule Induction September 8, 1999 Cornell University Computer Science Department Andrew Myers.
Semantics. Semantics is a precise definition of the meaning of a syntactically and type-wise correct program. Ideas of meaning: –Operational Semantics.
Propositional Calculus CS 270: Mathematical Foundations of Computer Science Jeremy Johnson.
Eran Yahav 1. Previously…  An algorithmic view  Abstract data types (ADT)  Correctness Conditions  Sequential consistency  Linearizability  Treiber’s.
Chapter 3 Part II Describing Syntax and Semantics.
Semantics In Text: Chapter 3.
Compiler Principles Fall Compiler Principles Lecture 7: Lowering Correctness Roman Manevich Ben-Gurion University of the Negev.
Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications Chapter.
1 Programming Languages (CS 550) Lecture 2 Summary Mini Language Interpreter Jeremy R. Johnson.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
Code Generation for Control Flow Mooly Sagiv html:// Chapter
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
Semantics(1). 2 Symantec(1)  To provide an authoritative definition of the meaning of all language constructs for: 1.Programmers 2.Compiler writers 3.Standards.
Program Analysis and Verification Noam Rinetzky Lecture 2: Operational Semantics 1 Slides credit: Tom Ball, Dawson Engler, Roman Manevich, Erik.
Operational Semantics of Scheme
tautology checking continued
(State) Model-Based Approaches I Software Specification Lecture 35
Propositional Calculus: Boolean Functions and Expressions
Graph-Based Operational Semantics
Syntax versus Semantics
Propositional Calculus: Boolean Functions and Expressions
Declarative Computation Model Kernel language semantics (Non-)Suspendable statements (VRH ) Carlos Varela RPI October 11, 2007 Adapted with.
Program Analysis and Verification
Spring 2017 Program Analysis and Verification Operational Semantics
Mini Language Interpreter Programming Languages (CS 550)
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
The Metacircular Evaluator (Continued)
Spring 2016 Program Analysis and Verification Operational Semantics
Presentation transcript:

Formal Semantics of Programming Languages 虞慧群 Topic 2: 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   ’ A notation:   [5/X]

Rules for commands   Sequencing: Conditionals: Atomic commands

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

Exercise 2 (1) Evaluate a  (X  4) + 3 in a state  s.t.  (X)=0. (2) Write down rules which express the “parallel” evaluation of b0 and b1 in b0 V b1 so that evaluates to true if either b0 evaluates to true, and b1 is unevaluated, or b1 evaluates to true, and b0 is unevaluated.