Denotational Semantics

Slides:



Advertisements
Similar presentations
Types and Programming Languages Lecture 7 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Advertisements

Digital Lesson An Introduction to Functions. Copyright © by Houghton Mifflin Company, Inc. All rights reserved. 2 A relation is a rule of correspondence.
Type Checking, Inference, & Elaboration CS153: Compilers Greg Morrisett.
Semantics Static semantics Dynamic semantics attribute grammars
Models of Concurrency Manna, Pnueli.
1 How to transform an analyzer into a verifier. 2 OUTLINE OF THE LECTURE a verification technique which combines abstract interpretation and Park’s fixpoint.
8. Introduction to Denotational Semantics. © O. Nierstrasz PS — Denotational Semantics 8.2 Roadmap Overview:  Syntax and Semantics  Semantics of Expressions.
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 3 LECTURE: LAMBDA CALCULUS PRACTICAL/TUTORIAL: (i) Do exercises given out.
Denotational Semantics Syntax-directed approach, generalization of attribute grammars: –Define context-free abstract syntax –Specify syntactic categories.
Data Flow Analysis Compiler Design Nov. 8, 2005.
Dec Formal Semantics1 Programming Language Theory Formal Semantics Leif Grönqvist The national Graduate School of Language Technology (GSLT) MSI.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Denotational Semantics ICS.
Function: Definition A function is a correspondence from a first set, called the domain, to a second set, called the range, such that each element in the.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
Syntax & Semantic Introduction Organization of Language Description Abstract Syntax Formal Syntax The Way of Writing Grammars Formal Semantic.
Imperative Programming
Chapter 3 Functions Functions provide a means of expressing relationships between variables, which can be numbers or non-numerical objects.
1 Programming Languages (CS 550) Lecture 9 Summary Introduction to Formal Semantics Jeremy R. Johnson TexPoint fonts used in EMF. Read the TexPoint manual.
Compiler Phases: Source program Lexical analyzer Syntax analyzer Semantic analyzer Machine-independent code improvement Target code generation Machine-specific.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Lecture#16 Discrete Mathematics. Recursion Now, 1 is an odd positive integer by the definition base. With k = 1, = 3, so 3 is an odd positive integer.
Principles of programming languages 5: An operational semantics of a small subset of C Department of Information Science and Engineering Isao Sasano.
Review: Compiler Phases: Source program Lexical analyzer Syntax analyzer Semantic analyzer Intermediate code generator Code optimizer Code generator Symbol.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Universidad Nacional de ColombiaUniversidad Nacional de Colombia Facultad de IngenieríaFacultad de Ingeniería Departamento de Sistemas- 2002Departamento.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
School of Computing and Mathematics, University of Huddersfield CHA2545: WEEK 4 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE TUTORIAL: Do exercises.
Dr. Muhammed Al-MulhemICS (Denotational Semantics)
Mathematical Preliminaries
Section 11.1 Sequences. Sequence – list of values following a pattern Arithmetic – from term to term there is a common difference we’ll call d Geometric.
Semantics of Predicate Calculus For the propositional calculus, an interpretation was simply an assignment of truth values to the proposition letters of.
Mathematical Induction Section 5.1. Climbing an Infinite Ladder Suppose we have an infinite ladder: 1.We can reach the first rung of the ladder. 2.If.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Denotational Semantics.
Warm Up Write down objective and homework in agenda Lay out homework (None) Homework (Recursive worksheet) Get a Calculator!!!
Louden’s Simple Language for Describing Formal Semantics program → stmt-list stmt-list → stmt ‘;’ stmt-list | stmt stmt → assign-stmt | if-stmt | while-stmt.
School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 8 LECTURE: LAMBDA CALCULUS SEMANTICS TUTORIAL: exercises.
Exception Handling and Tolerance of Software Faults Prepared by: Saeid Pashazadeh Written By: Flaviu Cristian University of California,San Diego (session.
Dr. M. Al-Mulhem Denotational Semantics 1 Chapter 4 Fundamentals (Denotational Semantics)
Fall 2002CMSC Discrete Structures1 Chapter 3 Sequences Mathematical Induction Recursion Recursion.
Functional Programming
Operational Semantics of Scheme
Warm UP Write down objective and homework in agenda
User-Written Functions
Theory of Computation Lecture 4: Programs and Computable Functions II
Programming Languages Translator
A lightening tour in 45 minutes
September 4, 1997 Programming Languages (CS 550) Lecture 6 Summary Operational Semantics of Scheme using Substitution Jeremy R. Johnson TexPoint fonts.
Counting Sets.
Warm UP Write down objective and homework in agenda
Relations and Functions
Mathematical Induction Recursion
Important Concepts from Clojure
Important Concepts from Clojure
Warm-Up Fill in the tables below for each INPUT-OUTPUT rule. 3)
Mini Language Interpreter Programming Languages (CS 550)
Programming Languages (CS 550) Mini Language Semantics
R.Rajkumar Asst.Professor CSE
Denotational Semantics (Denotational Semantics)
Semantics In Text: Chapter 3.
VOCABULARY! EXAMPLES! Relation: Domain: Range: Function:
Logics for Data and Knowledge Representation
Introduction to Functional Programming in Racket
Announcements Quiz 5 HW6 due October 23
Important Concepts from Clojure
This Lecture Substitution model
CSE S. Tanimoto Lambda Calculus
An Introduction to Functions
Programming Languages
Recursion.
Presentation transcript:

Denotational Semantics The meaning of a program is given by specifying the function (from input to output) that corresponds to the program. The denotational semantic definition, thus maps syntactical things into functions: P:Program→Input→Output We need to specify each of these: Syntactic domains (describing program syntax elements that are assigned common valuation functions) Semantic domains (that are used to express meanings of programs and their components). Semantic functions (that map syntax into semantics)

Elements for The Expression Language Syntactic Domains E: Expression N: Number D: Digit Semantic Domains v: Integer = {...,-2,-1,0,1,2,...} Operations +:Integer Χ Integer → Integer -:Integer Χ Integer → Integer *:Integer Χ Integer → Integer Semantic Functions E : Expression → Integer E[[E1 ‘+’ E2]] = E[[E1]] + E[[E2]] E[[E1 ‘*’ E2]] = E[[E1]] * E[[E2]] E[[E1 ‘-’ E2]] = E[[E1]] - E[[E2]] E[[‘(‘ E ‘)’]] = E[[E]] E[[N]] = N[[N]] N: Number → Integer N[[ND]] = 10*N[[N]] + N[[D]] N[[ND]] = D[[D]] D: Digit → Integer D[[‘0’]] = 0, D[[‘1’]] = 1, ... D[[‘9’]] = 9

Adding an Environment to the Expression Language Need to create a lifted domain from the Integers. A lifted domain has all the elements of some partially ordered domain together with a unique bottom element (), that is less than any other element in the original domain. We call the lifted integers Integer. New Semantic Domains: Env: Environment = Identifier → Integer Modified Semantic Functions E : Expression → Environment → Integer E[[E1 ‘+’ E2]](Env) = E[[E1]](Env) + E[[E2]] (Env) E[[E1 ‘*’ E2]](Env)= E[[E1]](Env) * E[[E2]](Env) E[[E1 ‘-’ E2]](Env) = E[[E1]](Env) - E[[E2]](Env) E[[‘(‘ E ‘)’]](Env) = E[[E]](Env) E[[I]](Env) = Env(I) E[[N]](Env) = N[[N]] Note that E is now a higher-order function (when given an Expression, it yields a function mapping an Environment to an Integer). Such functions can be constructed from normal functions by Currying. This is useful in this context, because it lets us explain what the meaning of an expression is, no matter what the environment in which we evaluate that expression.

Adding Statements New Syntactic Domains L: Statement-list S: Statement I: Identifier L: Letter New Semantic Functions P: Program → Environment P[[L]] = L[[L]](Env0)) L: Statement-list→Environment→Environment L[[L1 ‘;’ L2]] = L[[L2]] L[[L1]] L[[S]] = S[[S]] S: Statement → Environment → Environment S[[I ‘:=‘ E]](Env) = Env{I = E[[E]](Env)}

Mathematics of Functional Programming We can define a function by extension (by providing the graph of the function, namely, the set of ordered pairs that represent the function’s mapping) or by comprehension (by providing a rule that tells us how to calculate the value of the function at any point). Consider the normal definition of the factorial function: f(n) = if n = 0 then 1 else n*g(n-1) Think of a recursive definition of a function as really naming two functions, the function used in the body, and the function being defined: f(n) = if n = 0 then 1 else n*f(n-1) Now f has two arguments, n, and g. Think of defining a higher order function H H(g)(n) = if n = 0 then 1 else n*g(n-1) The factorial function f is a fixed-point of H, that is, a value of H such that H(g) = g. Why? H(f)(n) = if n = 0 then 1 else n*f(n-1) ≡ f(n)

Least-Fixed-Points If we think of a function being represented by extension, then we can talk about a partial ordering of all functions, with the bottom element being the empty set . Think of the function that just maps 0 to 1, {(0,1)}, and the function that in addition maps 1 to 1, {(0,1),(1,1)}, and the function that further maps 2 to 2, {(0,1),(1,1),(2,2)}, and the function that further maps 3 to 6, {(0,1),(1,1),(2,2),(3,6)}. We are constructing a sequence of functions, f0, f1, f2, f3, that begin a sequence of functions that represent the factorial function. If we defined a function f* that was just like f, but in addition mapped negative values to -1, f* would still satisfy the definition of the factorial function, however, f* would be a larger function in the natural lattice order of the function definitions because it contains every pair in f, but it also contains many other pairs. That’s why we say the factorial function is the least-fixed-point of the definition of H(f).

Adding Control Flow Defining if statements is relatively straightforward S[[‘if’ E ‘then’ L1 ‘else’ L2]](Env) = if E[[E]](Env) > 0 then L[[L1]](Env) else L[[L1]](Env) While and other repetitive statements, however present somewhat of a problem: S[[‘while’ E ‘do’ L ‘od’]](Env) = if E[[E]](Env)  0 then Env else S[[L ‘;’ ‘while’ E ‘do’ L ‘od’]](Env) The recursive nature of the while is typically handled by defining the meaning as the least-fixed-point of the specified semantic function.