SE424 SemanticsRosemary Monahan NUIM Section 5: Imperative Languages Languages that utilise stores are called imperative languages. The store is a data.

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

Models of Concurrency Manna, Pnueli.
Programming Languages and Paradigms
Assignments and Procs w/Params EOPL3 Chapter 4. Expressible vs. Denotable values Expressible Values –the language can express and compute these –represented.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
Expressions and Statements. 2 Contents Side effects: expressions and statements Expression notations Expression evaluation orders Conditional statements.
8. Introduction to Denotational Semantics. © O. Nierstrasz PS — Denotational Semantics 8.2 Roadmap Overview:  Syntax and Semantics  Semantics of Expressions.
DATAFLOW PROCESS NETWORKS Edward A. Lee Thomas M. Parks.
Comp 205: Comparative Programming Languages Semantics of Imperative Programming Languages denotational semantics operational semantics logical semantics.
8. Introduction to Denotational Semantics. © O. Nierstrasz PS — Denotational Semantics 8.2 Roadmap  Syntax and Semantics  Semantics of Expressions 
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.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Chapter 7: Semantics Fall 2009 Marco.
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://
Chapter 8 High-Level Programming Languages Nell Dale John Lewis.
11/1/06 1 Hofstra University, CSC005 Chapter 8 (Part 3) High Level Programming Languages.
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
Operational Semantics Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Data Flow Analysis Compiler Design Nov. 8, 2005.
MAT 204 F Composite Functions
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
Imperative Programming
High-Level Programming Languages: C++
Flow of Control. 2 Control Structures Control structure: An instruction that determines the order in which other instructions in a program are executed.
The College of Saint Rose CIS 433 – Programming Languages David Goldschmidt, Ph.D. from Concepts of Programming Languages, 9th edition by Robert W. Sebesta,
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Algorithms and Algorithm Analysis The “fun” stuff.
Principles of programming languages 5: An operational semantics of a small subset of C Department of Information Science and Engineering Isao Sasano.
Semantics. Semantics is a precise definition of the meaning of a syntactically and type-wise correct program. Ideas of meaning: –Operational Semantics.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Functions Section 1.4. Relation The value of one variable is related to the value of a second variable A correspondence between two sets If x and y are.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Language Translation A programming language processor is any system that manipulates programs expressed in a PL A source program in some source language.
SE424 Languages with Context A Block Structured Language.
Languages and Compilers
School of Computing and Mathematics, University of Huddersfield CHA2545: WEEK 4 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE TUTORIAL: Do exercises.
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
Imperative Languages Section 5 Continued.... A Dynamically Typed Language Variable may take on values from different data types. Run­time type checking.
Concurrency Properties. Correctness In sequential programs, rerunning a program with the same input will always give the same result, so it makes sense.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
Sequence Control Syntax and Semantics Jian Xu March 3, 2004 CS706, CAS McMaster.
Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications Chapter.
Formal Semantics of Programming Languages 虞慧群 Topic 2: Operational Semantics.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Exception Handling and Tolerance of Software Faults Prepared by: Saeid Pashazadeh Written By: Flaviu Cristian University of California,San Diego (session.
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.
Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall Process Specifications and Structured Decisions Systems Analysis and Design, 8e Kendall.
Functional Programming
Chapter 5 Structures.
Important Concepts from Clojure
Important Concepts from Clojure
Programming Misconceptions
Elements of Programming Languages
3-3 Side Effects A side effect is an action that results from the evaluation of an expression. For example, in an assignment, C first evaluates the expression.
Programming Languages and Compilers (CS 421)
Denotational Semantics (Denotational Semantics)
Programming Languages and Compilers (CS 421)
High Level Programming Languages
Defining A Formal Semantics For The Rosetta Specification Language
Chapter 8 Advanced SQL.
Flow of Control.
Important Concepts from Clojure
Assignments and Procs w/Params
Type Topic in here! Created by Educational Technology Network
Subprograms General concepts Parameter passing Functions
Presentation transcript:

SE424 SemanticsRosemary Monahan NUIM Section 5: Imperative Languages Languages that utilise stores are called imperative languages. The store is a data structure that exists independently of any program in the language.

SE424 SemanticsRosemary Monahan NUIM Essential Features: Sequential execution, Implicit data structure (the ``store'') –Existence indpendent of any program, –Not mentioned in language syntax, –Phrases may access it and update it. Relationship between store and programs: – Critical for evaluation of phrases. Phrase meaning depends on store. –Communication between phrases. Phrases deposit values in store for use by other phrases; sequencing mechanism establishes communication order. – Inherently ``large'' argument. Only one copy existing during execution.

SE424 SemanticsRosemary Monahan NUIM A Language with Assignment Declaration­free Pascal subset. Program = sequence of commands C: Command  Store   Store  –A command produces a new store from its store argument. –Command might not terminate (``loop'') C[| C |]s =  –Follow up commands C ‘, will not evaluate C[| C ‘|] Store   Store  is strict. –Command sequencing is store composition C[| C 1 ; C 2 |] = C[| C 2 |]  C[| C 1 |] (See Photocopy from Schmidt, Figures 5.1 and 5.2)

SE424 SemanticsRosemary Monahan NUIM Valuation Functions P: Program  Nat  Nat  Program maps input number to an answer number; non­termination is possible (co­ domain includes ?). C: Command  Store   Store  Command maps store into a new store; predecessor command may not have terminated (domain includes  ) and command may not terminate (co-domain includes  ). E: Expression  Store  Nat Expression maps store into natural number. B: Bool­exp  Store  Tr Boolean expression maps store into truth value. N: Numeral  Nat Numeral yields a natural value.

SE424 SemanticsRosemary Monahan NUIM Program Denotation How to understand a program? A possibility is to compute its denotation with a particular input argument. P: Program  Nat  Nat  Various results for various inputs. Natural number or  (non­ termination) P [| Z:=1; if A=0 then diverge; Z:=3 |] (two)

SE424 SemanticsRosemary Monahan NUIM Simplification P[| Z:=1; if A=0 then diverge; Z:=3. |](two) = let s = (update [| A | ] two newstore) in let s’ = C[| Z:=1; if A=0 then diverge; Z:=3 |] s in access [| Z |] s' = let s1 = ( [ [| A |]  two ] newstore) let s' = C[| Z:=1; if A=0 then diverge; Z:=3 | ]s1 in access [| Z |] s'

SE424 SemanticsRosemary Monahan NUIM C[| Z:=1; if A=0 then diverge; Z:=3 |]s1 = ( s.C[| if A=0 then diverge; Z:=3 |] (C[| Z:=1|]s)) s1 = <as the store s1 may be bound to s) C[| if A=0 then diverge; Z:=3 |](C[| Z:=1 |]s1) Now work on C[| Z:=1 |]s1 C[| Z:=1 |]s1 = ( s.update [| Z |] (E[| 1|]s) s)s1 = update [| Z |] (E[| 1| ]s1 ) s1 = update [| Z | ] (N[|1|]) s1 = update [| Z | ] one s1 = [[| Z |]  one ]s1 which we call s2

SE424 SemanticsRosemary Monahan NUIM C[| if A=0 then diverge; Z:=3 |](C[| Z:=1 |]s1 ) = C[| if A=0 then diverge; Z:=3|]s2 = ( s.C[| Z:=3 |] (C[| if A=0 then diverge |]s)s2 = ( s.C[| Z:=3 |] (( s.B[| A=0|]s  C[| diverge |]s [] s) s) )s2 = C[| Z:=3|](( s.B[| A=0 |]s  C[| diverge |]s [] s)s2 ) = C[| Z:=3|](B[| A=0 |]s2  C[| diverge |]s2 [] s2 )

SE424 SemanticsRosemary Monahan NUIM B[| A=0 |]s2 = ( s.E[| A|]s equals E[| 0 |]s)s2 = E[| A|]s2 equals E[| 0 |]s2 = (access [| A |] s2 ) equals zero

SE424 SemanticsRosemary Monahan NUIM access [| A |] s2 = s2 [| A |] = ( [ [| Z |]  one ][ [| A |]  two ] newstore ) [| A |] = ([ [| A |]  two ] newstore) [| A |] = two (access [| A |] s2 ) equals zero = two equals zero = false

SE424 SemanticsRosemary Monahan NUIM C[| Z:=3| ](B[| A=0 |]s2  C[| diverge |]s2 [] s2 ) = C[| Z:=3 |](false  C[| diverge |]s2 [] s2 ) = C[| Z:=3 |]s2 = ( s.update [| Z |] (E[| 3| ]s) s)s2 = update [| Z | ] (E[| 3|]s2 ) s2 = update [| Z | ] (N[| 3 |]) s2 = update [| Z | ] three s2 = [ [| Z |]  three ]s2

SE424 SemanticsRosemary Monahan NUIM Denotation of the Entire Program let s1 = ( [ [| A |]  two] newstore) s2 = [ [| Z|]  one ]s1 s' = C[| Z:=1; if A=0 then diverge; Z:=3 |]s1 in access [| Z|] s' = let s1 = ( [ [| A| ]  two] newstore) s2 = [ [| Z |]  one ]s1 s' = [ [| Z |]  three ]s2 in access [| Z |] s' access [| Z |] s' = access [| Z |] [ [| Z |]  three ]s2 = [ [| Z |]  three ]s2 [| Z |] = three

SE424 SemanticsRosemary Monahan NUIM Program Denotation when input is zero P[| Z:=1; if A=0 then diverge; Z:=3 |](zero) = let s3 = [ [| A |]  zero ]newstore s' = C[| Z:=1; if A=0 then diverge; Z:=3 |]s3 in access [| Z |] s' =let s3 = [ [| A |]  zero ]newstore s 4 = [ [| Z |]  one ]s3 s' = C[| if A=0 then diverge; Z:=3 |]s 4 in access [| Z |] s'

SE424 SemanticsRosemary Monahan NUIM = let s 3 = [ [| A|]  zero ]newstore s 4 = [ [| Z |]  one ]s3 s 5 = C[| if A=0 then diverge |]s4 s' = C[| Z:=3 |]s5 in access [| Z |] s' C[| if A=0 then diverge |]s 4 =B[| A=0 |]s 4  C[| diverge |]s 4 [] s 4 = true  C[| diverge |]s 4 [] s 4 = C[| diverge |]s 4 = ( s.  )s 4 = 

SE424 SemanticsRosemary Monahan NUIM let s 3 = [ [| A |]  zero ]newstore s 4 = [ [| Z |]  one ]s 3 s 5 = C[| if A=0 then diverge |]s 4 s' = C[| Z:=3 |]s 5 in access [| Z |] s' = let s 3 = [ [| A |]  zero ]newstore s 4 = [ [| Z |]  one ]s 3 s 5 =  s' = C[| Z:=3 |]s 5 in access [| Z |] s' =

SE424 SemanticsRosemary Monahan NUIM let s' = C[| Z:=3 |]  in access [| Z |] s' = let s' = ( s.update [| Z |] (E[| 3|]s))  in access [| Z |] s' = let s' =  in access [| Z |] s' = access [| Z |]  = 

SE424 SemanticsRosemary Monahan NUIM Program Equivalence Is C[| X:=0; Y:=X+1 |] equivalent to C[| Y:=1;X:=0 |] C: Command  Store   Store  Show C[| C 1 |]s = C[| C 2 |]s for every s. C[| C 1 |]  =  = C[| C 2 | ] . Assume proper store s. C[| X:=0; Y:=X+1|]s = C[| Y:=X+1|] (C[| X:=0 |]s) = C[| Y:=X+1|] ([ [| X|]  zero ]s) = update [| Y| ] (E[| X+1 |]([ [| X |]  zero ]s)) [ [| X |]  zero ]s = update [| Y | ] one [ [| X |]  zero ]s = [ [| Y |]  one ] [ [| X |]  zero ]s Call this result s1

SE424 SemanticsRosemary Monahan NUIM Program Equivalence C[| Y:=1; X:=0 |]s = C[| X:=0 |] (C[| Y:=1 |]s) = C[| X:=0 |] ([ [| Y |]  one ]s) = [ [| X|]  zero ][ [| Y|]  one ]s Call this result s2 Is s1 equivalent to s2 ??? The two values are defined stores. Are they the same store? We cannot simplify s1 into s2 using the simplification rules. The stores are functions : Id  Nat To show that the two stores are the same, we must show that each produces the same number answer from the identifier argument. There are three cases to consider:

SE424 SemanticsRosemary Monahan NUIM Case 1: The argument is [| X|] s1 [| X |] = ([ [| Y |]  one ][ [| X |]  zero ]s)[| X |] = ([| X |]  zero ]s)[| X |] = zero s2 [| X |] = ([ [| X |]  zero ][ [| Y |]  one ]s)[| X |] = zero

SE424 SemanticsRosemary Monahan NUIM Case 2: The argument is [| Y |] s1[| Y |] = ([[| Y |]  one ][ [| X |]  zero ]s)[| Y |] = one s2 [| Y |] = ([ [| X |]  zero ][ [| Y |]  one ]s)[| Y |] = ([ [| Y |]  one ]s)[| Y|] = one

SE424 SemanticsRosemary Monahan NUIM Case 3: The argument is [| I |] (some other identifier) s1 [| I |] = ([ [| Y |]  one ][ [| X |]  zero ]s)[| I |] =([ [| X |]  zero ]s)[| I |] = s[| I |] = ([ [| Y |]  one ]s)[| I |] = ([ [| X |]  zero ][ [| Y |]  one]s)[| I |] = s2 [| I |].

SE424 SemanticsRosemary Monahan NUIM Programs Are Functions Simplifications were operational­like. Answer computed from program and input. P [|Z:=1; if A=0 then diverge; Z:=3 | ] = n.let s = ( [[| A |]  n] newstore) in let s’ = C[| Z:=1; if A=0 then diverge; Z:=3 |] s in access[|Z|]s’ = n.let s = ( [[| A |]  n] newstore) in let s’= ( s.( s.C[| Z:=3 |] (C[|if A =0 then diverge|] s))s)(C[[Z:=1|] s) in access[|Z|]s’

SE424 SemanticsRosemary Monahan NUIM = n.let s = ( [[| A |]  n] newstore) in let s’= ( s.( s.[[| Z|]  n]s) (( s.(access[|A|] s) equals zero  ( s.  ) s[] s)s)) (( s. [ [|Z |]  one ]s) s) in access[|Z|]s’ = n.let s = ( [[| A |]  n] newstore) in let s’= (let s’1 =.[[| Z|]  one]s) in let s’2 = (access[|A|] s’1) equals zero  ( s.  ) s’1[] s’1 in [ [|Z |]  three ]s’2) in access[|Z|]s’

SE424 SemanticsRosemary Monahan NUIM Program Denotation P [| Z:=1; if A=0 then diverge; Z:=3 |] = n.(n equals zero)   [] three Denotation extracts essence of a program. Store disappears –temporary data structure; not contained in the input/output relation of a program. Transformation resembles compilation. Simplification resembles code optimization.