Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dr. Muhammed Al-MulhemICS535-0911 (Denotational Semantics)

Similar presentations


Presentation on theme: "Dr. Muhammed Al-MulhemICS535-0911 (Denotational Semantics)"— Presentation transcript:

1 Dr. Muhammed Al-MulhemICS535-0911 (Denotational Semantics)

2 Dr. Muhammed Al-MulhemICS535-0912 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.

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

4 Dr. Muhammed Al-MulhemICS535-0914 Denotational Semantics (continued)  The process of building a denotational specification for a language define for each language entity both a mathematical object and 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 method is named denotational because the mathematical object denote the meaning of their corresponding language entity.

5 Dr. Muhammed Al-MulhemICS535-0915 Example – Binary Number  The syntax of a binary number is: → 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.  The syntactic entities in this case are ‘0’ and ‘1’.  The objects are the decimal equivalent.

6 Dr. Muhammed Al-MulhemICS535-0916 Example – Binary Number  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,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

7 Dr. Muhammed Al-MulhemICS535-0917 Example - Decimal Numbers  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: 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

8 Dr. Muhammed Al-MulhemICS535-0918 Denotational Semantics: Program Constructs  Let the state of a program be represented as a set of ordered pairs as follows: s = {,, …, }  Each i is a variable and the associated v is its current value.  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 VARMAP(i j, s) = v j  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.

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

10 Dr. Muhammed Al-MulhemICS535-09110 Denotational Semantics: Expressions  The BNF description of these expressions:  | |   |  + | *  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.  Then Z U {error} is the set of values to which an expression can evaluate.

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

12 Dr. Muhammed Al-MulhemICS535-09112 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 M a (x :=, s) = if M e (, s) == error then error else s’ = {,,..., }, where for j = 1, 2,..., n, v j ’ = VARMAP(i j, s) if i j <> x = M e (, s) if i j == x

13 Dr. Muhammed Al-MulhemICS535-09113 Logical Pretest Loops  Assume we have two mapping functions, M sl and M b M sl Maps statement list to states. M b Maps boolean expression to boolean value.  The DS of a simple loop are: 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))

14 Dr. Muhammed Al-MulhemICS535-09114 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  In essence, the loop has been converted from iteration to recursion, where the recursive control is mathematically defined by other recursive state mapping functions


Download ppt "Dr. Muhammed Al-MulhemICS535-0911 (Denotational Semantics)"

Similar presentations


Ads by Google