Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CSE4250&5250 Stansifer

Midterm Exam

Fall 2022

1.  (24 points).    Assuming the simple Hoare logic as presented in class in which x, y, and z are names/variables, identify which of the things below are valid Hoare triples (valid), well- formed Hoare triples (wff HT) but not valid, or neither (not).  For each statement below, circle the one best answer of the three choices. Correct answers are worth one point, incorrect answers lose one point. (The symbol ^ stands for logical disjunction, and ⊥ for false.)

(a) valid / wff HT / not   { y = 5 } if  x > y  then  x  :=  8  else  y  :=  5 { y = 5 } (b) valid / wff HT / not   { z = 8 } while  z > x  do  x :=x + 1  od { x = 8 ^ y = 8 } (c) valid / wff HT / not   { x = 0 } while  z = x  do  x :=x + 1  od { x = 8 ^ y = 5 } (d) valid / wff HT / not   { ⊥ } y, z  :=  x, y { x = 8 }

(e) valid / wff HT / not   { x + 1 = 2 } y  :=  2 ;  x  :=  x + 1 { x = y }

(f) valid / wff HT / not   { x > y } if  x > z  then  x  :=  8  else  y  :=  5 { y = 5 } (g) valid / wff HT / not   { y = 5 } if  x > y  then  x  :=  8  else  y  :=  5 { x = 8 } (h) valid / wff HT / not   { x = 2 } y  :=  2 ;  x  :=  x + y { x = y }

(i) valid / wff HT / not   { 8 = 8 } x  :=  8 { x = 8 }

(j) valid / wff HT / not   { z > 8 } if  x > z  then  y  :=  x  else  y  :=  8 { y >= 8 } (k) valid / wff HT / not   { x ≤ 8 } x  :=  8 { }

(l) valid / wff HT / not   { x := 8 } x  :=  8 { z = 2 }

2.  (10 points).   What does it mean that arrays are covariant in C# and Java?

3.  (10 points).    Generally speaking, what is bounded quantification polymorphism and what problem does it solve?

4.  (10 points).    Write a simple, Algol-like program that distinguishes dynamic scoping from static scoping. Explain.

5.  (10 points).   Considering the scope of names in a program, the C programming language is “flat,” but Algo-like languages, Ada for example, are hierarchical” or nested.

(a) Explain what this means with a small example or illustration.

(b) What are the advantages of flat?”

(c) What are the advantages of hierarchical?”

6.  (10 points).    Suppose you are writing a compiler for a language like Modula-3 which has procedure variables. In the program Main, x is a procedure variable.

MODULE   Main ;

TYPE   f   =   PROCEDURE   ( z :   INTEGER );    (*   procedure   type   *) VAR   x :   f ;

PROCEDURE   P   ( z :   INTEGER )   =   BEGIN    (*   ...   *)   END   P ;

BEGIN

x   :=   P ;         (*      assignment      *)

x (2);               (*      call                       *)

END   Main .

Explain exactly how the assignment gets implemented and how the call gets implemented so that non-local variable access works correctly.

7.  (40 points).   For each statement below, circle either “true” or “false” as appropriate. Correct answers are worth one point, incorrect answers lose one point.

(a) true / false

Dynamic scoping is compatiable with strong typing.

(b) true / false

A type variable stands in place of a specific type.

(c) true / false

An Ada derived type is generative.

(d) true / false

The type operator for arrays in Java is covariant.

(e) true / false

Static scoping is the same as dynamic scoping for local variables.

(f) true / false

Structural equivalence is necessary to strengthen type abstraction.

(g) true / false

The record {a:int,b:char} is a subtype of {a:int}.

(h) true / false

Arrow (function) types are, by their nature, covariant in the domain and contravariant in the range.

(i) true / false

It makes no difference when the l-value of an actual arguments is computed for copy-in/copy-out parameters.

(j) true / false

A characteristic of universal polymorphism is a finite number of possibili- ties.

(k) true / false

An associative array is a dynamically-accessed, heterogeneous, composite data structure.

(l) true / false

The same sequence of bits can mean different things.

(m) true / false

A type insecurity arises when the data is misinterpreted.

(n) true / false

Polymorphism means many values.”

(o) true / false

Non-local variable access in a block-structured language can be imple- mented in a single machine instruction.

(p) true / false

Modern languages tend to favor structural equivalence of types.

(q) true / false

Ada uses name equivalence.

(r) true / false

A program that cannot be statically type has a type insecurity.

(s) true / false

Modula-3 uses name equivalence.

(t) true / false

In generational garbage collection different parts of the heap are scavanged with different frequecencies.