Imperative Languages Section 5 Continued.... A Dynamically Typed Language Variable may take on values from different data types. Run­time type checking.

Slides:



Advertisements
Similar presentations
COMMUNICATING SEQUENTIAL PROCESSES C. A. R. Hoare The Queen’s University Belfast, North Ireland.
Advertisements

Models of Concurrency Manna, Pnueli.
Kathleen Fisher cs242 Reading: “A history of Haskell: Being lazy with class”,A history of Haskell: Being lazy with class Section 6.4 and Section 7 “Monads.
SE424 SemanticsRosemary Monahan NUIM Section 5: Imperative Languages Languages that utilise stores are called imperative languages. The store is a data.
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.
PART 4: (2/2) Central Processing Unit (CPU) Basics CHAPTER 13: REDUCED INSTRUCTION SET COMPUTERS (RISC) 1.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model From kernel to practical language (CTM 2.6) Exceptions (CTM.
Parallel and Distributed Simulation Time Warp: Other Mechanisms.
Parameterization. Abstracts usually carry parameters. Parameters = dummy identifiers. Replaced by values when abstract invoked. Formal parameters and.
CSCI 8150 Advanced Computer Architecture Hwang, Chapter 2 Program and Network Properties 2.3 Program Flow Mechanisms.
Denotational Semantics Syntax-directed approach, generalization of attribute grammars: –Define context-free abstract syntax –Specify syntactic categories.
1 SOCK and JOLIE from the formal basis to a service oriented programming language Ivan Lanese Computer Science Department University of Bologna Italy Joint.
Why Behavioral Wait statement Signal Timing Examples of Behavioral Descriptions –ROM.
2/23/2009CS50901 Implementing Fault-Tolerant Services Using the State Machine Approach: A Tutorial Fred B. Schneider Presenter: Aly Farahat.
Catriel Beeri Pls/Winter 2004/5 environment1 1 The Environment Model  Introduction and overview  A look at the execution model  Dynamic scoping  Static.
CSE S. Tanimoto Syntax and Types 1 Representation, Syntax, Paradigms, Types Representation Formal Syntax Paradigms Data Types Type Inference.
Operational Semantics Semantics with Applications Chapter 2 H. Nielson and F. Nielson
1 Ivan Lanese Computer Science Department University of Bologna Italy On the expressive power of primitives for compensation handling Joint work with Catia.
From Essentials of Computer Architecture by Douglas E. Comer. ISBN © 2005 Pearson Education, Inc. All rights reserved. 7.2 A Central Processor.
Chapter 7Louden, Programming Languages1 Chapter 7 - Control I: Expressions and Statements "Control" is the general study of the semantics of execution.
Query Processing Presented by Aung S. Win.
Advances in Language Design
Computer Architecture Computational Models Ola Flygt V ä xj ö University
Imperative Programming
Chapter 6-2 Multiplier Multiplier Next Lecture Divider
Benjamin Gamble. What is Time?  Can mean many different things to a computer Dynamic Equation Variable System State 2.
AXML Transactions Debmalya Biswas. 16th AprSEIW Transactions A transaction can be considered as a group of operations encapsulated by the operations.
CSC-682 Cryptography & Computer Security Sound and Precise Analysis of Web Applications for Injection Vulnerabilities Pompi Rotaru Based on an article.
Dynamic Verification of Cache Coherence Protocols Jason F. Cantin Mikko H. Lipasti James E. Smith.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
SECTION 2.7 DIVISION OF REAL NUMBERS Objectives: Divide real numbers Use division to simplify algebraic expressions.
Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 20 Slide 1 Critical systems development 3.
Computer Architecture Lecture 2 System Buses. Program Concept Hardwired systems are inflexible General purpose hardware can do different tasks, given.
Semantics. Semantics is a precise definition of the meaning of a syntactically and type-wise correct program. Ideas of meaning: –Operational Semantics.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
Shared Memory Consistency Models. SMP systems support shared memory abstraction: all processors see the whole memory and can perform memory operations.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
SE424 Languages with Context A Block Structured Language.
Processor Architecture
Chapter 6: Computer Components Dr Mohamed Menacer Taibah University
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
Transaction Processing Concepts Muheet Ahmed Butt.
Simplifying Algebraic Expressions. 1. Evaluate each expression using the given values of the variables (similar to p.72 #37-49)
Copyright Curt Hill The Assignment Operator and Statement The Most Common Statement you will use.
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
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Overview: Using Hardware.
© Kenneth C. Louden, Chapter 7 - Control I: Expressions and Statements Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
In this session, you will learn to: Create and manage views Implement a full-text search Implement batches Objectives.
Lecture 3 – MapReduce: Implementation CSE 490h – Introduction to Distributed Computing, Spring 2009 Except as otherwise noted, the content of this presentation.
Notes Over 1.2.
Representation, Syntax, Paradigms, Types
Organization of Programming Languages
Representation, Syntax, Paradigms, Types
Denotational Semantics (Denotational Semantics)
Representation, Syntax, Paradigms, Types
CS 611: Lecture 10 More Lambda Calculus September 20, 1999
Lesson 12: more on Equations
Representation, Syntax, Paradigms, Types
CS 611: Lecture 10 More Lambda Calculus September 20, 1999
Fault Tolerant Systems in a Space Environment
EE 345S Real-Time Digital Signal Processing Lab Spring 2009
Presentation transcript:

Imperative Languages Section 5 Continued...

A Dynamically Typed Language Variable may take on values from different data types. Run­time type checking required. Input and output included. Introduction of ``type tags'' –Storable­value = Tr + Nat –Store = Id  Storable­value –Errvalue = Unit –Expressible­value = –Storable­value + Errvalue

Valuation Functions State = Store x Input x Output –store, input and output buffers Post­State = OK + Err –OK = State, Err = State –successful evaluation or type error P: Program  Store  Input  Poststate  –Program takes input store and input buffer and returns a new state

C: Command  State  Post­state  –Command takes state and returns a new state. E: Expression  Store  Expressible­value –Expression takes store and returns a value.

Composition of States C[[C1 ; C2]] = C[[C1 ]] check­cmd C[[C2 ]] Command = State  Post­state  check­cmd: Command x Command  Command h 1 check­cmd h 2 = a. let z = h1(a) in cases z of isOK(s, i, o)  h 2 (s; i; o) isErr(s, i, o)  z end

1.Give current state a to C[[C 1 ]] producing a post­state z = C[[C 2 ]]a’. 2.If z is a proper state a’ and if the state component is OK, produce C[[C 2 ]]a’ 3.If z is errnoneous, C[[C 2 ]] is ignored and z is the result. Similar for check of expression results.

Error Handling Algebra operations abort normal evaluation when type error occurs. –Representation of low­level (e.g. hardware­ level) fault detection and branching mechanisms. Machine action: on fault, branch out of the program. Semantics: on fault, branch out of function expression –Propagation of type errors yields same result as machine action.

Altering the Properties of Stores 1. Store critical to evaluation of a phrase. 2. Only one copy of store exists during execution. 3. Store serves as means of communication between phrases. Typical features of a store in sequential programming languages. What happens if we relax each of these restrictions?

Delayed Evaluation How to rewrite a function application f(e)? Call­by­value simplification – e evaluated before f is executed – Safe method if f is strict. Call­by­name simplification –f executed with non­evaluated e; –Safe method also if f is non­strict. f: Nat   Nat  f = x: zero f(  ) = zero E[[e]] =  f(E[[e]]) )  ? Simplification of argument may require in­ finite number of steps!

Non­strict Store Updates May store operate on improper values? Store = Id  Nat  –Improper values may be stored. update: Id  Nat   Store  Store -- update = i: n: s:[i  n]s -- update[[I]](E[[E]]s) s) is defined even in the``loop forever situation'' E[[E]]s = . -- Unevaluated expressions may be stored in s. E[[E]]s needs not be evaluated until used. -- Delayed (lazy) evaluation. -- Value must be determined with respect to the store that was active when [[E]] was saved.

EXAMPLE: begin X := 0 Y := X+1 X := 4 return Y K: Block  Store   Nat  K[[begin C return E]] = s: E[[E]] (C[[C]]s)

K[[begin X:=0; Y:= X+1; X:=4 return Y]]s0 = E[[Y]] (C[[X:=0; Y:= X+1; X:=4]]s0 ) = E[[Y]] (C[[Y:= X+1; X:=4]] (C[[X:=0]]s0 )) = E[[Y]] (C[[Y:= X+1; X:=4]] (update [[X]] (E[[0]]s0 ) s0 )) = E[[Y]] (C[[Y:= X+1; X:=4]] s1 ) s 1 = (E[[0]]s0 ) needs not be simplified!

EXAMPLE: s2 = update [[Y]] (E[[X+1]]s1 ) s1 s3 = update [[X]] (E[[4]]s 2 ) s2 E[[Y]] (C[[Y:= X+1; X:=4]] s1 ) = E[[Y]]s3 = access [[Y]] s3 = E[[X+1]]s1 = E[[X]]s1 plus one = (access [[X]] s1 ) plus one = E[[0]]s0 plus one = zero plus one = one

Non­Strict Command Execution Carry delayed evaluation up to level of commands. Make C, E, and K non­strict in their store arguments. Only those commands need to be evaluated that have an effect on the output of a program!

EXAMPLE: begin X:=0; diverge; X:=2 return X+1 K[[begin X:=0; diverge; X:=2 return X+1]]s0 = E[[X+1]] (C[[X:=0; diverge X:=2]]s0 ) = E[[X+1]] (C[[X:=2]](C[[diverge; X:=2]]s0 )) = E[[X+1]](C[[X:=2]]s1 ) = E[[X+1]](update [[X]] (E[[2]]s1 ) s1 ) = E[[X+1]]([ [[X]]  (E[[2]]s1 ) ]s1 ) = E[[X]]([ [[X]]  (E[[2]]s1 ) ]s1 ) plus one = E[[2]]s 1 plus one = two plus one = three s 1 = C[[X:=0; diverge]]s 0 needs not be simplified!

Retaining Multiple Stores E[[E 1 + E 2 ]] = s.E[[E 1 ]]s plus E[[E 2 ]]s E uses store s in ``read only'' mode. No second store required for implementation. E[[begin C return E]] = s: let s’ = C[[C]]s in E[[E]]s’ Side effects in expression evaluation possible. Multiple stores required for implementation.

E[[E 1 + E 2 ]] = s: let (v’; s’ ) = E[[E 1 ]]s (v’’ ; s’’ ) = E[[E 2 ]]s’ in (v’ plus v’’ ; s’’ ) E[[begin C return E]] = s: let s’ = C[[C]]s in (E[[E]]s’, s’) Local updates remain in global store. Expression evaluation returns new store.

Non­Communicating Commands Store facilitates the building up of side effects that lead to some final value. Command advances computation by reading and modifying the values left in the store by previous commands. Otherwise, communication breaks down and language loses sequential flavor.

combine: D x D  D Domain s2 Store = Id  D C: Command  Store   Store  C[[C 1;C 2]] = s. join (C[[C1]]s) (C[[C2 ]]s) join: Store   Store   Store  join = s1 : s2:( i:s1 (i) combine s2 (i)) Parallel but non­interfering parallelism.