CSCI 5220
Spring 2016
Practice Questions for Exam 2

  1. Is an abstract syntax tree identical to a parse tree? Explain.

    Answer

  2. If a compiler uses abstract syntax trees, does it build them as explicit data structures or does it, instead, traverse them implicitly during the parsing process.

    Answer

  3. Show a parse tree for string cccdd using the following grammar. There is only one nonterminal, S, and it is the start nonterminal.

    Sc S d
    Sc

    Answer

  4. Show a parse tree for string aacacab using the following grammar. The start nonterminal is S.

    SF a S
    Sb
    Fa F
    Fc

    Answer

  5. Show that the following grammar is ambiguous. There is only one nonterminal, S.

    SS c S
    Sd

    Answer

  6. Show that the following grammar is ambiguous. Nonterminal S is the start nonterminal.

    Sif ( E ) S else S
    Sif ( E ) S
    Sx
    Etrue
    Efalse

    Answer

  7. A convenient notation for writing an abstract syntax tree is to write the root label followed by its subtrees, separated by commas, in parentheses.

    For example, tail(t) is a tree whose root is labeled tail and that has one subtree, t. Similarly, times(s, t) would be a tree whose root is labeled times and that has two subtrees, s and t. It represents the product of s and t.

    Some trees have extra integer parmeters. Write function:1(t) for a function labeled 1 with one subtree, t. num:n() is a tree representing number n, with no subtrees.

    Explain the steps that an interpreter would take to simplify tail(t), representing the tail of the value of subtree t.

    Answer

  8. Using the notation above, explain how to simplify tree if(x, y, z), which stands for an expression whose value is y if x has value true, and is z if x has value false.

    Answer