CS 3723-001 Programming Languages
Spring 2003 -- Mid-term Exam

Directions: Use your own paper for answers. When you are done you may keep this exam sheet. The answers will be posted.

  1. Consider the following finite automaton.
    1. Give a regular expression describing the language recognized by this automaton. (You haven't been given an algorithm to do this, though such algorithms exist, but you should just intuitively try to figure it out. If you can't do the regular expression, then give any kind of description of the language.)

    2. Write a regular grammar that recognizes the same language as this automaton. (Recall that a regular grammar has all grammar rules in one of two forms:
      
         A ---> a B
         A ---> a
      
      where A and B are any non-terminals and a is any terminal. You can rename the three states in the automaton A, B. and C.)

     

     


  2. Consider the formal Grammar

    1. Give the relative precedence of each of the five operators.
    2. What is the associativity of '+'. What is the associativity of '^'?
    3. Is this grammar ambiguous? (Just Yes or No.)
    4. Construct the parse tree for the sentence: (a + b^c)*a $
    5. What prevents this grammar from being parsed with a recursive descent parser?

     

     

  3. Consider a shift-reduce parser as we had in a recitation. Suppose the following grammar rule is being used for a reduction.
    1. What is being reduced?
    2. Where is the thing being reduced to be found?
    3. What is it being reduced to?
    4. What happens to the thing it is reduced to?

     


  4. Consider the following grammar rule from the parser assignment:
    1. What construct is this rule describing?
    2. How does the recursive descent parser know that it is encountering this particular construct on input?
    3. What does the portion { S } mean on the right side?
    4. Give the small part of your recursive descent parser that handles the { S }.
    5. Think about the MIPS code that is used to translate this construct. What comes first in this code? What are the last two parts of the MIPS code used to translate this construct?

     


  5. Consider the recitation that involved translating while and if-then-else statements. As part of the translation process, labels would be inserted into the assembly code. In order to handle nested and repeated instances of these constructs, what trick was needed (or if you like, how did you manage to translate these so that the constructs could be nested or repeated)?

     


  6. This is a question about passing an array to a function as a paramter.

    1. In C, C++, and Java, when an array is passed to a function as a parameter using only its name, what is actually passed?

    2. Give a way in C and C++ that would allow one to pass an array to a function by value, that is, a copy of the array would be passed, leaving the original array unchangeable from inside the function.

Points for each problem: 1-20, 2-20, 3-13, 4-20, 5-13, 6-14.