CSCI 5220
Spring 2009
Practice Questions for Exam 1

  1. Give a regular expression using flex notation that descibes the set of strings that start with a, end with c and have zero or more digits between them.

    Answer

  2. Write a program using flex that copies the standard input to the standard output, except that it replaces each sequence of consecutive blanks and tabs by a single blank.

    This program is not a typical lexical analyzer, but a full program.

    Answer

  3. Show that the following grammar is ambiguous.
    S -> S c S
    S -> d

    Answer

  4. Show a parse tree for string cccdd with respect to grammar
    S -> c S d
    S -> c

    Answer

  5. What are the FIRST and FOLLOW sets for the following grammar? The start nonterminal is E.
    E -> A
    E -> L
    A -> n
    A -> i
    L -> ( S )
    S -> E , S
    S -> E

    Answer

  6. Build the finite state machine of LR(0) items for the grammar of the preceding problem, showing the set of LR(0) items in each state. Number the states.

  7. Show the SLR(1) parsing table for the grammar from the preceding problem, using the finite state machine that you created. Show both the action and goto parts of the table.