1) Regular Expressions and Finite Automata (Spr 2001 Necula)

Consider the language over the alphabet {a} containing strings whose length is either a multiple of 2 or a multiple of 3, including the empty string.

1a) Write a regular expression for this language.


1b) Draw an NFA for this language.


1c) Draw a DFA for this language.



2) Context Free Languages (Sipser Ex 2.6)

2a) Write a CFG for the language from problem 1.


2b) Write a CFG for the language of strings with at least as many a's as b's, over the alphabet { a, b }.



3) LL Parsing (Spr 2000 Aiken/Necula)

Consider the grammar: 

S -> aS | Ab

A -> XYZ | epsilon

X -> cS | epsilon

Y -> dS | epsilon

Z -> eS | epsilon


3a) Give an LL(1) parsing table for the grammar.


3b) Give a leftmost derivation of the string aebb.  Is this derivation unique?  Why or why not?


3c) Show that if we add the production X -> bS, the grammer is no longer LL(1).  Is the new grammar ambiguous?



4) LR Parsing (Spr 2001 Necula)

Consider the grammar:

S -> A

A -> A + A | B + +

B -> y

The first rule (with nonterminal S) has been added as the conventional start rule for LR parsers.


4a) Draw a parse tree for the input "y + + + y + +"


4b) Complete the table below showing the trace of an LR(1) parser on the above input.  The "Stack" column shows the stack contents with the top of the stack on the right.  The "Input" column shows the not-yet-processed input terminals.  The "Action" column shows whether the parser performs a shift, reduction, or accepts the input.  Reduce actions should specify the production used.


Stack Input Action

> y + + + y + + $        shift

y > + + + y + + $


4c) Compute the set of items in the start state of the item-state DFA.  That is, compute Closure( [ S -> . A, $ ] )


4d) Build the entire item-state DFA for the grammar.  The solution contains 8 states and can be checked against your solution to part b above.


4e) This grammar has a shift-reduce conflict.  In which state of the DFA does the conflict occur, and on what input symbol?


4f) Assume we resolve the conflict by choosing to "shift" given this choice.  What is the associativity that corresponds to this choice?



5) Syntax-Directed Translation (Spr 2000 Aiken/Necula)

For the following grammar for arithmetic expressions, define a syntax-direction translation that computes the sign (POS or NEG) of each subexpression E as its semantic value.  Write your semantic actions to the right of the corresponding production.  You may assume that all integers are non-zero (so you don't need to worry about the sign of zero).


E -> unsigned_integer


E -> + E1


E -> - E1

 

E -> E1 * E2