Spring 2001, CSE 428: Quiz 2.1 - 25 Jan 2001


Please write your Name, Student ID, and Section at the top of the page.
  1. [Points 1] What is the typical function of a parser (circle only one answer, please)

    1. takes a program and typechecks it
    2. takes a parse tree and executes it
    3. takes a list of tokens and produces a parse tree
    4. translates the source code of a program into assembly code
    5. takes a grammar and produces all possible parse trees

  2. [Points 1] What is the operational semantics of a programming language (circle only one answer, please)

    1. the specification of an abstract interpreter for the language
    2. the grammar defining the language
    3. the set of operations that the language is able to perform
    4. the set of rules that define the static correctness of a program
    5. the operations done by the compiler

  3. [Points 4] Consider the mini language of expressions seen in class, defined by the grammar
       Exp ::=  Num | Ide | Exp Op Exp | let Ide = Num in Exp end
       Op  ::=  + | * | - | /
    
    where Num and Ide are defined as usual. For each of the following expressions, say whether or not they are derivable from this grammar. (Note: you are not requested to say whether an expression is "correct", but only whether it can be derived from the grammar.)

    1. let x = 1 in 5 end       Derivable
    2. let x = 1 in y end       Derivable
    3. let x = 1 in x end + x       Derivable
    4. let x = 1 in let y = x in y end end       Not derivable (declaration y = x not allowed)

  4. [Points 4] Consider the same language as in previous question, and the interpreter seen in class for that language. For each of the following expressions, say what is the result of the evaluation.

    1. let x = 1 in let x = 2 in x end end       2
    2. let x = 1 in let x = 2 in x end + x end       3
    3. let x = 1 in x end + let x = 2 in x end       3
    4. let x = 1 in x + let y = 2 in x + y end end       4