COMP 144 Midterm Exam (Spring 2004)


This is a closed book, closed notes, closed classmates exam. You have 70 minutes to complete it. When you are done, please sign here as a pledge that the exam represents your own work. Hand in this exam along with any paper on which you have written your answers. Be sure your name is written legibly on each page.


NAME (print): ___________________________________________________________


PLEDGE (sign): __________________________________________________________



  1. Consider the Java programming language. List 5 major binding times (skip link time and load time from the list of 7 given in your text) and for each discuss properties and aspects of programs in Java that are bound at each time. Briefly explain each item you name.



  2. a) Compare and contrast scripting languages to more traditional application development languages. Be sure to explain what each kind of language is good for, what each is poor for, and when you would want to use each one.

    b) Perl is a scripting language. Discuss features of Perl that make it useful for scripting in the sense of your answers to part (a).



  3. Write a Perl program that will read in all lines of a file (standard input is fine) and check each line to see if it contains a Pascal-style comment. Print each line that does contain a match, and toss each line that does not.

       (* this is a Pascal comment *)
       (* they may not be nested *) (* but two or more per line is ok *)
       it is also ok (* if they are only part *) of the line
       (* assume a comment will open and *) close on one line
       therefore (* this line would not be a match ... it has no close
       this line also is no *) match since it has no open
    
    Note that this solution can be done in 3 or 4 lines... I am not asking for a significant program, but rather a demonstration of using regular expressions in pattern matching.



  4. Let's say for some reason I have designed a language that will not allow recursion. But also let's say I have designed the language so that it still needs a heap for dynamic memory management. What language features might I have put in (give 3 good ones) that would cause this.







  5. Explain the difference between internal fragmentation and external fragmentation in heap management.



  6. Consider this program:

        int x; int y = 0; /* globals */
    
        proc One (int m) {
          local int y = 3;
          Two(m);
        }
    
        proc Two (int k) {
          y = k;
          k = 0;
        }
        
        main {
          x = 6;
          One(x);
          print x;
          print y;
        }
    
    (a) What is the output when the program is executed with static scope rules and call-by-reference parameter passing?

    (b) What output is produced when the program is executed with dynamic scope rules and call-by-value parameter passing?

    (c) What output is produced when the program is executed with dynamic scope rules and call-by-reference parameter passing?