You are on page 1of 8

Question 1 (5 + 6 + 5 = 16 points)

Consider the following action-augmented regular definition hR(Σ, D), C, Ai, where
Σ = {a, b, c, !, ?, _}, D = {term, exp, quest, letter, id}, and C = {term, exp, quest}.
In the following, pref ix(s, n) evaluates to the prefix with length n of string s (e.g.
pref ix(“abc”, 2) =“ab”), and length(s) evaluates to the length of string s.

term −→ id | a?
A(term) = {return(hterm, lexi)}
exp −→ id_id_! | id !
A(exp) = {return(hexp, pref ix(lex, length(lex) − 1)i)}
quest −→ id ?
A(quest) = {return(hquest, pref ix(lex, length(lex) − 1)i)}
letter −→ a | b | c
id −→ letter+

1. Draw the state diagram of the corresponding NFA. (You do not need to follow
any particular algorithm for constructing the NFA.)

1
2. Draw the state diagram of the corresponding fallback DFA with actions, M .

3. Trace the operation of M on input “b_a_!a?ab?b”, showing (i) the output and
(ii) the sequence of states M goes through as it scans the input.

2
Question 2 (12 points)

Consider the CFG G2 = ({S, T }, {a, b, c}, R, S) where R is given by the following
productions.
S −→ aSc | bSc | T
T −→ T c | c
Prove that L(G2 ) = {wcn | n > 0 and w ∈ {a, b}k with k < n}.

3
Question 3 (6 + 9 + 5 + 5 = 25 points)

Consider CFG G3 = h{S, A, B}, {a, b, c}, R, Si, where R is given as follows.

S −→ aABb
A −→ aAc | ε
B −→ bB | c

1. Find the F irst and F ollow sets for all variables. (Fill the following table.)

F irst F ollow
S
A
B

2. Construct the LL(1) predictive parse table T3 for G3 .

4
3. Draw the state diagram of a PDA, P3 , which is equivalent to G3 . (Use the
qs -qloop -qa construction.)

4. By showing successive contents of the stack, trace the operation of a predictive


LL(1) parser working with P3 and the parsing table T3 on input string aacbcb
Please use the table on the next page.

5
Step Stack
1
2
3
4
5
.
.
.

6
7
8

You might also like