Académique Documents
Professionnel Documents
Culture Documents
Exercise 2.1
2
Recall the CFG G4 that we gave in Example 2.4. For convenience, let's
rename its variables with single letters as follows.
Solution 2.1
3
a. The derivation is .
b. The derivation is E E + T T + T F + T
a + T a + F a + a.
Solution 2.1
4
c. The derivation is +
+ + + + +
+ + + + +
+ + + + + +
.
d. The derivation is () ()
() (()) (()) (()) (()).
Exercise 2.3
5
Solution 2.3
6
a.
b.
c.
d.
e.
f.
g.
h.
The variables of G
are , , , .
The terminals of G are , .
The start variable is R.
Strings in G are ab, ba, and aab.
Strings not in G are a, b, and .
False.
True.
False.
i.
j.
k.
l.
m.
n.
o.
True.
True.
False.
True.
True.
False.
L(G) is the language of all
strings w over {a, b} such
that w is not palindrome.
Exercise 2.4
7
Solution 2.4
8
a. 111
0 1
b. 00 11
0 1
c. 0 1 00 01 10 | 11
d. 0 | 00 01 10 | 11
Exercise 2.6
9
Solution
a. |
Exercise 2.9
10
Solution 2.9
11
Exercise 2.13
12
a.
Let G = (V, Z, R, S) be the following grammar. V = {S, T, U}; Y {0, #}; and R
is the set of rules:
L(G) is a set of strings of 0s and #s that either contain exactly 2 #s and any
number of 0s, or contain exactly 1 # and the number of 0s to the right of the # is
twice the of 0s to the left.
Exercise 2.14
13
Solution 2.14
14
0
BAB | B |
00 |
S0 A
A BAB | AB | BA A B |
B 00
S0 A |
A BAB | AB | BA A B |
B 00
S0 A |
A BAB | AB | BA A 00 |
B 00
S0 BAB | AB | BA A 00 | |
A BAB | AB | BA A 00 |
B 00
0 BA1 | AB | BA | B1 B1 | BB |
BA1 | AB | BA | B1 B1 | BB
B1 B1
B1 0
A1