COEN  171

 

Sample Midterm

 

1.         (12 points)  Vocabulary

            Give short (two or three sentence) definitions of the following terms:

 

   a.      Anonymous type

 

   b.      Associativity (as applied to expressions)

 

   c.      Strongly typed

 

   d.      Symbol table

 

2.         (20 points) Consider the grammar for the monkey language as given below. Monkey language is simple, but only monkeys can speak it correctly.

 

<sentence> ::= <word> | <sentence> # <word>

<word>    ::= <syllable> | <syllable> <word> <syllable>

<syllable> ::= <plosive> | <plosive> <stop> | a <plosive> <stop>

<plosive> ::= <stop> a

<stop>    ::= b | d

 

          Also consider the statements by the following three speakers, one of whom is a secret agent in monkey disguise:

 

                        Ape:                 ba#ababadada#bad#dabbada

                        Chimp:             abdabaadab#ada

                        Baboon:           dad#ad#abaadad#badadbaad

 

    a.     (4 points) What are the terminal symbols?

    b.     (4 points) What are the non-terminal symbols?

    c.     (2 points) What is the start symbol?

    d.     (5 points) How would you go about determining which of the speakers is the secret agent?

    e.     (5 points) Which one is the secret agent?

 

3.         (10  points)  Compilation issues

   a.      What is the difference between the syntax of a programming language and the dynamic semantics of the same language?

 

   b.      Which phases (steps in the compilation process) of a compiler are concerned with syntax and which with dynamic semantics?

 

4.         (10 points) Binding

Consider the possible things that can be bound for a data object. What differences in binding time exist between a stack-dynamic variable and an explicit heap-dynamic variable?

 

5.         (10 points)  Type conversion

   a.      Why is it necessary for the design of a programming language to consider conversion between the various types provided by the language?

 

   b.      What is the difference between coercion and casts? What are the advantages and disadvantages of each?

 

6.         (10 points)  Data aggregates

   a.      What is the fundamental difference between records and arrays?

 

   b.      How is this difference reflected in the way components of records and arrays are accessed? Consider issues both of how the language allows the programmer to specify which component to access, and how the access actually occurs at run time.

 

7.         (12 points)  Control structures

   a.      With respect to looping control structures, what is the difference between a break or exit statement and a classic goto statement? Why have modern languages preferred break to goto?

 

   b.      Why does Ada's exit statement allow loop labels? Do you think that choice was due to efficiency of execution or because of differences in the clarity of the Ada source code that results?

 

8.         (10 points)  Control structures

            The COND statement in LISP is like what control construct in imperative languages? Give an example of a LISP COND statement and the equivalent construct in an imperative language of your choice (name the language).

 

9.         (10 points)  LISP

   a.      What does the following mystery function (which takes one list as an argument) do?

          (define  (mystery  arg)

                   (do  ((v1 0 (+ v1 1))

                         (v2 arg (cdr v2))

                        )

                        ((null?  v2)  v1)

                   )

          )

 

   b.  What is the result of the following application of Mystery?

 

                        (Mystery  '(A  (B  C) (D (E  F))))