Spring 2002, CSE 428: Quiz 2.4 - 24 Jan 2002

Solutions


  1. [Points 2] What is the typical function of an interpreter (circle only one answer, please)

    1. takes a program (represented as a parse tree) and executes it (i.e. simulates its execution)
    2. takes a list of tokens and produces a parse tree
    3. translates the source code of a program into machine code
    4. takes a program and produces a list of tokens
    5. takes a grammar and produces all possible parse trees

  2. [Points 2] How is the environment used by an interpreter (circle only one answer, please)

    1. to check whether an identifier has been declared
    2. to store the value of previous (sub)expressions
    3. to store and retrieve the associations between identifiers and values
    4. to check whether there is only one declaration for each identifier
    5. to check what are the resources available in the machine

  3. [Points 3] Given a declaration such as the following:
      int  x, y.
      bool b, c.
    

    This specification declares that two variables are integer and two are boolean. What is the type mapping that is intended by this declaration? Write your answer as a set of pairs.

    Answer: {(x, int), (y, int), (b, bool), (c, bool)}


  4. [Points 3] Given the following rule for assignment:


                  sigma |- Exp eval Val
       ____________________________________________
       sigma |-  X = Exp ===> {(X,Val)} union sigma
    

    Here, union is the usual set union operator. Why is placing union in this inference rule wrong? (Circle only one answer.)

    1. Val might be associated two different variables.
    2. The result of the union might be empty.
    3. X might have two values in the union.
    4. The union should be interaction.