CIS 400 LECTURE 7

 

Denotational semantics

            Functional calculus

 

Machine state     <memory, input, output>

 

Current binding to all identifiers in memory and registers

 

dsem      denotational semantic function (similar to parsing)

 

Arithmetic:

dsemex:  Ex C S®Z È {error}, for EX=all legal expressions, S=states, Z=integers

dsemex  (E, S0) = error if S0 = <mem, i, o> and mem(v) = undefined for some           variable, v, in E. Otherwise:

 

dsemex  (E, S0) = evalue expression

 

see accompanying handout for dsemas and dsemrd

 

Program p

 

Read (n)

 

   fact := 1;

   i := 1;

while i <= n do

   fact := fact * i;

      i := i + 1;

od;

write(fact);

 

recurrence relations;

sum(x) = 1  if x = 1

else

     sum(x) = sum(x - 1) + 1

 

so:

 

    sum[3] = sum[2] + 1

                = [sum[(1) + 1] + 1]

                = [1 + 1] + 1

                = 3

 

 

 

Attribute grammars

·        Associated with each grammar item-like symbol x-is a set of attributes (or variables) denoted A(x). There are two disjoint sub-sets of A(x).

v     S(x), synthesis attributes

v     I(x), inherited attributes

 

·        Associated with each grammar rule is a set of semantic functions, (attribute computation functions) and predicate functions

 

Syntax rule: <assign>®<var> := <exp>

 

Semantics rule: <var>.<env> ¬ <assign>.env

                          <expr>.env ¬ <assign>.env

                          <assign>.lhs_type ¬ <var>.actual_type

                          <expr>.expected_type ¬ <assign>.lhs_type

 

Attributes:

            actual_type

            expected_type

            lhs_type

            env

 

Synthesized values:

            Computed by semantic function

S(x0) = f( A(x1), …A(xn))

I(x0) = (xj), 1 £ j £ n

 

Variable, expressions, statements

 

Variable-quadruple

·        Name

·        Attributes

·        Reference, memory location

·        Value

 

Pascal

 

 

  

Snobol: (aliasing)

 

 

It is very important to know the specific language protocol for aliasing

Aliasing:

·        Equivalence-Fortran

·        Define-PL/1

 

Bindings-association of a program element with a particular characteristic or property

(E.g. Once you declare int x; you can't use it as char x;)

Binding time-time during program formulation or processing when association occurs

·        Writing program

·        Compiling

·        Linking module

·        Loading program into memory

·        Entry into sub-program

·        Execution of statement

 

In the case of x := x + 10;

·        What type is allowed for x?

·        What type is x?

·        What is representation for x? (binary, hex, etc.)

·        What does "+" mean? (add, concatenate, etc.)

·        When is it decoded?

 

When is binding times important?

·         Many subtle differences in languages are binding time differences

·        Early  binding time languages are usually compiled and efficiency is important, (defined/ declared variables before use)

·        Late binding languages have interpretive bindings, done at execution, flexibility is most important

 

Declaration

Explicit vs. implicit

(provides translator with info relative to type checking and storage management)

specifies:

·        Data type

·        Attributes of data object

·        Value

·        Name or placement within larger object

·        Binding to storage location