Computer Science Department
Teodor C. Przymusinski

Compiler Construction


MidTerm Exam

Last name: First name: Social Security:



  1. (30 pts.) Write regular expressions for each of the following::
    (a) Strings over the alphabet { x, y, z, t } where the first x (if any) must occur before any y's but after all z's.
    (b) Strings over the alphabet { x, y, z, t } with the number of x's divisible by 3.

  2. (40 pts.) Given the following grammar: (a) describe all the LR(1) states and their transitions, and, (b) complete the corresponding parsing table (on the NEXT PAGE!).
    (0) Prog -> Exp $
    (1) Exp -> Term * Stm
    (2) Exp -> Stm
    (3) Term-> #
    (4) Term-> & Stm
    (5) Stm -> Term
         (a) LARL(1) STATES AND TRANSITIONS:







































     (b) PARSING TABLE FOR PROBLEM 2:



















          Left empty for your notes

Answers for sample problem 1:

This is not guaranteed to be correct:

Make sure you understand how these work.

1a:

(y|z|t)* | ( (z|t)* x (x|y|t)* )

1b:

(y|z|t)* (x(y|z|t)*x(y|z|t)*x(y|z|t)*)*