Exercise04 PDF
Exercise04 PDF
Exercise Sheet 4
Due: 27th November 2014
1 0
1
q0 0 q1 q2
0
1
Solution:
The language of the DFA is defined by the grammar G = (V, , R, S0 ) with V = {S0 , S1 , S2 },
= {0, 1}, and R being the following set of rules:
S0 0S1 | 1S0
S1 0S2 | 1S0
S2 0S2 | 1S0 |
(b) Show that the grammar ({S}, {a, b}, R, S) with rules R = S aS | aSbS | is ambiguous.
Solution:
Consider the string aab. We can give two different leftmost derivations of this string: S
aS aaSbS aabS aab and S aSbS aaSbS aabS aab.
(c) Give a grammar in Chomsky Normal Form that generates the same language as the grammar
G = (V, , R, S) with V = {S, X, Y }, = {a, b, c}, and R being the following set of rules:
S XY
X abb | aXb |
Y c | cY
Solution:
Using the algorithm from the lecture, we get the grammar G0 = (V 0 , , R0 , S) with V =
{S, X, X1 , X2 , Y, A, B, C}, = {a, b, c}, and R0 being the following set of rules:
S0 S
S XY
X abb | aXb |
Y c | cY
S0 S
S XY | Y
X abb | aXb | ab
Y c | cY
S0 S
S XY | c | cY
X abb | aXb | ab
Y c | cY
S0 S
S XY | c | cY
X aX1 | aX2 | ab
X1 bb
X2 Xb
Y c | cY
S XY | c | CY
X AX1 | AX2 | AB
X1 BB
X2 XB
Y c | CY
Aa
Bb
Cc
q4 q6
c, x
a, x a, y a, y b, y y
c, x x
, $ , d, , , $
q0 q1 q2 q3 q5 q7
Solution:
a, a
a, b, c, a
, $ , , , $
q0 q1 q2 q3 q4
L = {ai bj ck | i, j 0, k = i + j}
Solution:
c, a
a, a b, b c, b
, $ , , , $
q0 q1 q2 q3 q4