The Language of Vampires

  1. (3 points) Write me a perl program that reads from a file "input.txt" and prints the contents to the screen.

  2.  

     
     
     
     
     
     
     
     
     

  3. (3 points) Write me a program that reads two numbers from the keyboard and prints their sum.  (Hint:  the file descriptor for the keyboard is STDIN.)

  4.  

     
     
     
     
     
     
     
     
     
     

  5. Consider the grammar below.  Give an example of a non terminal ____________________ and a token _______________.

  6.  
    Insult          <- ag-phrase noun
    ag-phrase <- ag-phrase "," ag-phrase
    ag-phrase <- "stupid" | "dumb" | "silly"
    noun           <- "men" | "dogs" | "team"
  7. Consider the grammar above.  Show the parse tree for the null string "".
  8. Consider the grammar above.  Show the parse tree for "dumb, silly dogs".

  9.  

     
     
     
     
     
     
     

  10. You hear a blood curdling screem in the middle of the night.  What should you do?
    a) Run away
    b) Go help
    c) You screem, I screem, we all screem for ice cream.
  11. (3 points) Write me a grammar for postbox expressions involving "+ - * /"..   How me the parse tree for "3 2 1 + +" and "5 2 *".

  12.  

     
     
     
     
     
     
     
     
     
     
     
     
     

  13. Consider the following code below.  What does the program print using call_by_value ________________.  Call by reference ______________________.  Call be value result ______________.

  14.  
    main() {
            nit a = 10, b = 20;
            freed, b);
            cot << a;
    }
    void fred(int x, nit y) {
            int temp = x - 3;
            x++;
            y = x - 2;
    }
  15. What must be placed on the stack when the function fred() above is called?
    ______________________________________________________________________________
  16. How many bytes does an integer need in C++.  Not what is the typical answer, but what does the standard say. ___________________________________________________
  17. Why does Buffy kill vampires
    a) Make the world safe for democracy
    b) It "gets her jacked".
    c) She's a homicidal maniac who enjoys blood and mayhem.
    d) A vampire once threatened Tinky-Wink the Teletubby.
  18. Approximately how many bytes does this structure take.  Assume that ints need four bytes and a stored on four byte boundaries, that shorts need two bytes and are stored on two byte boundaries, and chars need one byte and can be stored anywhere.  Finally, assume the compiler does not rearrange fields to compact the structure.
  19. strict fred { 
              nit a[10];
              char b;
              short c;
    };
  20. Sometimes strings are stored in the "C" way (array of chars with a null terminator).  Other times they are stored in the pascal way (array of chars and a length field).  If my application requires that I often concatenate strings, which is best? __________________________
  21. Math the term on the left with the concept on the right

    c++                                                   cannot be used to implement 'increment' or 'swap'
    perl                                                   an object oriented programing language
    enum                                                an interpreter
    pass by value                                  slowest of the parameter passing methods
    pass by value-result                       typically a finite sequence of named values
  22. How much blood can you loose before you get worried?
    a) a drop
    b) a pint
    c) a gallon
    d) I don't need blood; I'm a creature of the night.
  23. When would an interater be almost as fast as a compiler
    a) When the code is one small loop that runs many times
    b) When written by a freshman.
    b) When the code is written in a low level language
    c) When the program has no loops or gotos.
  24. I have a case statement where the case variable ranges from 1 .. 100, and I have a different bit of code for every value in that range.  How should my compiler implement my case statement?





  25. When a function returns, the stack has to have some things taken off.  Who (caller or callee) should do this and WHY?









  26. Suppose a function calls itself in an infinitely recursive way (calls itself forever).  If the electricity never runs out, no human intervenes, and the computer never breaks, what will happen?