OLLSCOIL NA hÉIREANN, MÁ NUAD

NATIONAL UNIVERSITY OF IRELAND, MAYNOOTH

SECOND COMPUTER SCIENCE AND SOFTWARE ENGINEERING EXAMINATION

SAMPLE EXAM 2000

PAPER SE209

Principles of Programming I

Dr. J. Power.


Attempt any FOUR questions. Time Allowed: 2 hours.

 

1

(a)

Explain the actions carried out by a typical C++ compiler given the following piece of code:

  #include <iostream.h>
  int main(int argc, char *argv[])
  {
    cout << "Hello world";
  }

[10 marks]

 

(b)

Explain the main differences between compiling, linking and running programs in Forth and Java.

[15 marks]

 

2

(a)

Explain the use of intermediate representations in the implementation of interpreters for programming languages

[10 marks]

 

(b)

Consider the following piece of Forth code:

 
  dup
  DO
      I
      2 + I -     ( This is line 2 )
      dup
  LOOP

Given that the stack initially contains the number 6, draw the contents of the stack after line 2 has been executed, for each time that it is executed.

[15 marks]

 

3

 

Consider the following piece of ML code:

  type myList
    = Nil
    | Node of int * int * myList
   ;;

  let sumList t =
    match t with 
      nil -> 0
    | Node (x,y,tl) -> x+y+(sumList tl)
  ;;
 

 

 

(a)

Show how the following term might be evaluated using combinator reduction:
  
  sumList Node(3,4+3,Node(2,1,nil))

[10 marks]

 

(b)

Give an equivalent definition of this type of structure and operation in Prolog, and comment on the differences in implementation.

[15 marks]

 

4

 

(a)

Describe the differences between the preparation and initialisation phases of class loading, as carried out by the Java Virtual Machine (JVM)

[10 marks]

 

(b)

Explain why garbage collection is used in the JVM, as well as implementations of Prolog and ML, but not in implementations of C++.

[15 marks]

 

5

(a)

Briefly describe the purpose of performing data-flow analysis of Java bytecode, as carried out by the JVM.

[5 marks]

 

(b)

Explain what happens when the following piece of Java bytecode is run:

  .method public static test (DI)D
    dload_0
    dstore_3
    dload_3
    dreturn
  .end method

[20 marks]

 

6

(a)

Briefly describe the differences between peephole and structural optimisations

[10 marks]

 

(b)

Discuss some optimisation techniques that might apply to Prolog programs.

[15 marks]