Dr. Muhammed Al-Mulhem 1ICS535-101 ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Denotational Semantics ICS.

Slides:



Advertisements
Similar presentations
Semantics Static semantics Dynamic semantics attribute grammars
Advertisements

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.
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 330 Programming Languages 09 / 19 / 2006 Instructor: Michael Eckmann.
CS 355 – Programming Languages
Describing Syntax and Semantics
Concepts of Programming Languages 1 Describing Syntax and Semantics Brahim Hnich Högskola I Gävle
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.
Axiomatic Semantics Dr. M Al-Mulhem ICS
CS 330 Programming Languages 09 / 18 / 2007 Instructor: Michael Eckmann.
ISBN Chapter 3 Describing Syntax and Semantics.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Axiomatic Semantics ICS 535.
Describing Syntax and Semantics
ISBN Chapter 3 Describing Syntax and Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
Describing Syntax and Semantics
Copyright © 1998 by Addison Wesley Longman, Inc. 1 Chapter 3 Syntax - the form or structure of the expressions, statements, and program units Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
Chapter Describing Syntax and Semantics. Chapter 3 Topics 1-2 Introduction The General Problem of Describing Syntax Formal Methods of Describing.
ISBN Chapter 3 Describing Syntax and Semantics.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
Course: ICS313 Fundamentals of Programming Languages. Instructor: Abdul Wahid Wali Lecturer, College of Computer Science and Engineering.
TextBook Concepts of Programming Languages, Robert W. Sebesta, (10th edition), Addison-Wesley Publishing Company CSCI18 - Concepts of Programming languages.
Describing Syntax and Semantics
CS 363 Comparative Programming Languages Semantics.
Muhammad Idrees Lecturer University of Lahore 1. Outline Introduction The General Problem of Describing Syntax Formal Methods of Describing Syntax Attribute.
3.2 Semantics. 2 Semantics Attribute Grammars The Meanings of Programs: Semantics Sebesta Chapter 3.
Chapter 3 Part II Describing Syntax and Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
Chapter 3 Describing Syntax and Semantics. Copyright © 2012 Addison-Wesley. All rights reserved. 1-2 Chapter 3 Topics Introduction The General Problem.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Semantics In Text: Chapter 3.
Chapter 3 Describing Syntax and Semantics. Chapter 3: Describing Syntax and Semantics - Introduction - The General Problem of Describing Syntax - Formal.
Syntax and Semantics CIS 331 Syntax: the form or structure of the expressions, statements, and program units. Semantics: the meaning of the expressions,
Languages and Compilers
Dr. Muhammed Al-MulhemICS (Denotational Semantics)
CCSB 314 Programming Language Department of Software Engineering College of IT Universiti Tenaga Nasional Chapter 3 Describing Syntax and Semantics.
1 / 48 Formal a Language Theory and Describing Semantics Principles of Programming Languages 4.
Chapter 3 © 2002 by Addison Wesley Longman, Inc Introduction - Who must use language definitions? 1. Other language designers 2. Implementors 3.
Describing Syntax and Semantics Session 2 Course : T Programming Language Concept Year : February 2011.
Chapter 3 Describing Syntax and Semantics. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 3 Topics Introduction The General Problem.
ISBN Chapter 3 Describing Syntax and Semantics.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Denotational Semantics.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
C HAPTER 3 Describing Syntax and Semantics. D YNAMIC S EMANTICS Describing syntax is relatively simple There is no single widely acceptable notation or.
Lecture 3 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Dr. M. Al-Mulhem Denotational Semantics 1 Chapter 4 Fundamentals (Denotational Semantics)
Concepts of Programming Languages
Describing Syntax and Semantics
Describing Syntax and Semantics
Syntax Questions 6. Define a left recursive grammar rule.
Describing Syntax and Semantics
Describing Syntax and Semantics
Semantics In Text: Chapter 3.
Chapter 3: Describing Syntax and Semantics Sangho Ha
Denotational Semantics
Describing Syntax and Semantics
Describing Syntax and Semantics
Chapter 3 Describing Syntax and Semantics.
Describing Syntax and Semantics
Describing Syntax and Semantics
Describing Syntax and Semantics
Describing Syntax and Semantics
Chapter 3 (b) Semantics.
- Who must use language definitions?
Describing Syntax and Semantics
Presentation transcript:

Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Denotational Semantics ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Denotational Semantics

Dr. Muhammed Al-Mulhem 2ICS Outline Compilers: A review Compilers: A review Syntax specification Syntax specification BNF (EBNF) BNF (EBNF) Semantics specification Semantics specification Static semantics Static semantics Attribute grammar Attribute grammar Dynamic semantics Dynamic semantics Operational semantics Operational semantics Axiomatic semantics Axiomatic semantics Denotational semantics Denotational semantics

Dr. Muhammed Al-Mulhem 3ICS References 1. “Concepts in Programming Languages” by J. Mitchel [textbook] Chapter 4 2. “Programming Languages: Principles and Paradigms” by Allan Tucker and R. Noonan, Chapter 3 3. “Concepts of Programming Languages” by R. Sebesta, 6 th Edition, Chapter 3.

Dr. Muhammed Al-Mulhem 4ICS Denotational Semantics The most widely known method for describing the meaning of programs. The most widely known method for describing the meaning of programs. Based on recursive function theory. Based on recursive function theory. Originally developed by Scott and Strachey (1970) Originally developed by Scott and Strachey (1970)

Dr. Muhammed Al-Mulhem 5ICS Denotational Semantics (continued) The process of building a denotational specification for a language define for each language entity both The process of building a denotational specification for a language define for each language entity both a mathematical object and a mathematical object and a function that maps instances of that entity onto instances of the mathematical object. a function that maps instances of that entity onto instances of the mathematical object. The difficulty with this method lies in creating the objects and the mapping functions. The difficulty with this method lies in creating the objects and the mapping functions. The method is named denotational because the mathematical object denote the meaning of their corresponding language entity. The method is named denotational because the mathematical object denote the meaning of their corresponding language entity.

Dr. Muhammed Al-Mulhem 6ICS Example – Binary Number The syntax of a binary number is: The syntax of a binary number is: → 0 → 0 | 1 | 0 | 1 To describe the meaning of a binary number using denotational semantics we associate the actual meaning with each rule that has a single terminal symbol in its RHS. To describe the meaning of a binary number using denotational semantics we associate the actual meaning with each rule that has a single terminal symbol in its RHS. The syntactic entities in this case are ‘0’ and ‘1’. The syntactic entities in this case are ‘0’ and ‘1’. The objects are the decimal equivalent. The objects are the decimal equivalent.

Dr. Muhammed Al-Mulhem 7ICS Example – Binary Number Let the domain of semantic values of the objects be N, the set of nonnegative decimal integer values. Let the domain of semantic values of the objects be N, the set of nonnegative decimal integer values. The function M bin maps the syntactic entities of the previous grammar to the objects in N. The function M bin maps the syntactic entities of the previous grammar to the objects in N. The function M bin,for the above grammar, is defined as follows: The function M bin,for the above grammar, is defined as follows: M bin (‘0’) = 0 M bin (‘1’) = 1 M bin ( ‘0’) = 2 * M bin ( ) M bin ( ‘1’) = 2 * M bin ( ) + 1

Dr. Muhammed Al-Mulhem 8ICS Example - Decimal Numbers  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | ( 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9)  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | ( 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9) The denotational semantics for these syntax rules are: The denotational semantics for these syntax rules are: M dec ('0')=0, M dec ('1') =1, …, M dec ('9') = 9 M dec ( '0') = 10 * M dec ( ) M dec ( '1’) = 10 * M dec ( ) + 1 … M dec ( '9') = 10 * M dec ( ) + 9

Dr. Muhammed Al-Mulhem 9ICS Denotational Semantics: Program Constructs Let the state of a program be represented as a set of ordered pairs as follows: Let the state of a program be represented as a set of ordered pairs as follows: s = {,, …, } s = {,, …, } Each i is a variable and the associated v is its current value. Each i is a variable and the associated v is its current value. Any of the v’s can have the special value undef. Any of the v’s can have the special value undef. Let VARMAP be a function that, when given a variable name and a state, returns the current value of the variable Let VARMAP be a function that, when given a variable name and a state, returns the current value of the variable VARMAP(i j, s) = v j VARMAP(i j, s) = v j The state changes are used to define the meanings of programs and program constructs. The state changes are used to define the meanings of programs and program constructs. Some constructs, such as expressions, are mapped to values, not states. Some constructs, such as expressions, are mapped to values, not states.

Dr. Muhammed Al-Mulhem 10ICS Denotational Semantics: Expressions We assume here that we deal with only simple expressions: We assume here that we deal with only simple expressions: Only + and * operators. Only + and * operators. An expression can have at most one operator. An expression can have at most one operator. The only operands are scalar variables and integer literals. The only operands are scalar variables and integer literals. No parenthesis. No parenthesis. The value of an expression is integer. The value of an expression is integer.

Dr. Muhammed Al-Mulhem 11ICS Denotational Semantics: Expressions The BNF description of these expressions: The BNF description of these expressions:  | |  | |    |  |  + | *  + | * The only error we consider in expressions is that a variable has an undefined value. The only error we consider in expressions is that a variable has an undefined value. Let Z be the set of integers, and let error be the error value. Let Z be the set of integers, and let error be the error value. Then Z U {error} is the set of values to which an expression can evaluate. Then Z U {error} is the set of values to which an expression can evaluate.

Dr. Muhammed Al-Mulhem 12ICS Denotational Semantics: Expressions The DS of expressions are (dot notation refer to child nodes of a node) The DS of expressions are (dot notation refer to child nodes of a node) M e (, s) = case of = M dec (, s) = M dec (, s) = if VARMAP(, s) == undef = if VARMAP(, s) == undef then error then error else VARMAP(, s) else VARMAP(, s) = if (M e (., s) == undef OR = if (M e (., s) == undef OR M e (., s) = undef) M e (., s) = undef) then error then error else if (. == ‘+’ then else if (. == ‘+’ then M e (., s) + M e (., s) + M e (., s) M e (., s) else M e (., s) * else M e (., s) * M e (., s) M e (., s)

Dr. Muhammed Al-Mulhem 13ICS Assignment Statements An assignment statement is an expression evaluation plus the setting of the left-side variable to the expression’s value. Maps state sets to state sets An assignment statement is an expression evaluation plus the setting of the left-side variable to the expression’s value. Maps state sets to state sets M a (x := E, s) = if M e (E, s) == error then error else s’ = {,,..., }, where for j = 1, 2,..., n, where for j = 1, 2,..., n, v j ’ = VARMAP(i j, s) if i j <> x v j ’ = VARMAP(i j, s) if i j <> x = M e (E, s) if i j == x = M e (E, s) if i j == x

Dr. Muhammed Al-Mulhem 14ICS Logical Pretest Loops Logical Pretest Loops Assume we have two mapping functions, M sl and M b Assume we have two mapping functions, M sl and M b M sl Maps statement list to states. M sl Maps statement list to states. M b Maps boolean expression to boolean value. M b Maps boolean expression to boolean value. The DS of a simple loop are: The DS of a simple loop are: M l (while B do L, s) = if M b (B, s) == undef M l (while B do L, s) = if M b (B, s) == undef then error else if M b (B, s) == false then s else if M sl (L, s) == error then error else M l (while B do L, M sl (L, s))

Dr. Muhammed Al-Mulhem 15ICS Loop Meaning The meaning of the loop is the value of the program variables after the statements in the loop have been executed the prescribed number of times, assuming there have been no errors The meaning of the loop is the value of the program variables after the statements in the loop have been executed the prescribed number of times, assuming there have been no errors In essence, the loop has been converted from iteration to recursion, where the recursive control is mathematically defined by other recursive state mapping functions In essence, the loop has been converted from iteration to recursion, where the recursive control is mathematically defined by other recursive state mapping functions