CSCI 4627
Spring 2003
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.

  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.

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

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

  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

  6. Left factor the grammar of the preceding question and then write a recursive descent parser for it. The parser should only read a string and tell whether it is in this language.

    The tokens of this language are characters. Presume a lexical analyzer is available, and that statement match(c) will check the current lookahead token to see whether it is character c. If so, it will put the next token into variable lookahead. If not, it will print "no" and stop the program. Statement INIT_LEXER initializes the lexer, setting lookahead to the first token.

  7. When a (top-down) LL(1) parser needs to decide whether to use a production, how much of the sequence of tokens generated by the right-hand side of the production can the parser see? When a (bottom-up) SLR(1) parser needs to make the same decision, how much does it see?