Tải bản đầy đủ (.doc) (23 trang)

Bài tập ngôn ngữ hình thức

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.03 MB, 23 trang )

1. Let L = {ab,aa,baa}. Which of the following strings are in L*:
abaabaaabaa, aaaabaaaa,
baaaaabaaaab
baaaaabaa?
2. For which language it is true that L = L*?
a. L = {a
n
b
n+1
: n≥0}
b. L = {w: n
a
(w)=n
b
(w)}
3. Which of the strings 0001, 01001, 0000110 are accepted by the following
dfa:
4. Give dfa’s for the sets consisting of
a. all strings with exactly one a.
b. all strings with no more than three a’s
5. Give a dfa for the language L = {ab
5
wb
4
: w ∈ {a,b}*}
6. Find dfa’s for the following languages on ∑ = {a,b}
a. L = {w: |w| mod 3 = 0}
b. L = {w: |w| mod 5 ≠ 0}
c. L = {w: n
a
(w) mod 3 > 1}


7. Consider the set of strings on {0,1} in which every 00 is followed
immediately by 1. For example 101, 0010, 0010011001 are in the language,
but 0001 and 00100 are not. Construct an accepting dfa
8. Show that the language L = {a
n
: n ≥ 0, n ≠ 4} is regular.
9. Find δ*(q
0,
a) and δ*(q
1,
λ
) for the following nfa
10. For the following nfa, find δ*(q
0,
1010) and δ*(q
1,
00)
11. Find an nfa with three states that accepts the language {ab,abc}*
12. Convert the following nfa into dfa
13. Convert the following nfa into dfa
14. Find all strings in L((a+b)*b(a+ab)*) of length less than four.
15. Find a regular expression for the set {a
n
b
m
: (n+m) is even}
16. Give a regular expression for the language on ∑={a,b,c} containing no
run of a’s of length greater than two.
17. Give a regular expression for the language on ∑={a,b} containing all
strings not ending in 01.

18. Give a dfa that accepts L((a+b)*b(a+ab)*)
19. Find regular expressions for the language accepted by the following
automaton:
20. Construct a dfa that accepts that language generated by the following
grammar
S  abA
A  baB
B  aA | Bilbo
21. Construct left-linear grammar for the language in Problem 8
22. Construct right-linear and left-linear grammars for the language L =
{a
n
b
m
,n≥2,m≥3}
23. Construct a dfa that accepts that language generated by the following
grammar
S  abA
A  baB
B  aA | bb
24. Construct left-linear grammar for the language in Problem 2
25. Construct right-linear and left-linear grammars for the language L =
{a
n
b
m
,n≥2,m≥3}
26. Find intersection of the two following languages: L
1
= {a

n
b
2m
c
2k
} and L
2

= {a
2n
b
4m
c
k
}
27. The nor of two languages is defined as follows:
nor(L
1
,L
2
) = {w: w ∉L
1
and w ∉L
2
}
Show that nor is closed for regular lanaguages
28. Let L
1
= L(a*baa*) and L
2

= (aba*). Find L
1
/L
2
29. Suppose L
1
∪L
2
is regular and L
1
is finite. Can we conclude that L
2
is
regular?
30. Prove that the following languages are not regular
a. L = {a
n
b
m
, n ≤ m}
b. L = {w: n
a
(w) = n
b
(w)}
31. Find context-free grammars for the following languages
a. L = {a
n
b
m

: n ≤ m +3}
b. L = {a
n
b
m
: n ≠ m -1}
c. L = {a
n
b
m
: n ≠ 2m}
d. L = {a
n
b
m
: 2n ≤ m ≤ 3m}
e. L = {a
n
b
m
c
k
: n = m or m ≤ k}
f. L = {a
n
b
m
c
k
: k = |n-m|}

g. L = {a
n
ww
R
b
n
: w

{a,b}*}
h. L = {a
n
b
n
}
2
32. Show a derivation tree, together with the corresponding leftmost and
rightmost derivations of the string aabbbb with the grammar
S  AB | λ
A  aB
B  Sb
33. Find a context-free grammar for the set of all regular expressions on the
alphabet {a,b}*. Give a derivation tree for (a+b)*+a+b
34. Find an s-grammar for L(aaa*b+b)
35. Show that every s-grammar is unambigous
36. Show that the following grammars is ambigous
S  AB | aaB
A  a | aA
B  b
S  aSbS|bSaS|λ
37. Is it possible for a regular grammar to be ambigous?

38. Find an s-grammar for L(aaa*b+b)
39. Show that every s-grammar is unambigous
40. Consider the following grammar:
S  aSb | SS | λ
Eliminate left-recursive for the grammar.
Show a derivation for the string w = aabbab using both orignal and rewriten
grammars
41. Eliminate useless and unit productions for the following grammar:
S  a | aA | B | C
A  aB | λ
B  Aa
C  cCD
D  ddd
42. Eliminate all λ-production from
S  AaB | aaB
A  λ
B  bbA | λ
43. Transform the following grammars to Chomsky normal form:
S  aSb | ab
S  aSaA | A
A  abA |b
S  abAB
A  bAB | λ
B  BAa | A | λ
44. Convert the following grammars into Greibach normal form:
S  aSb | ab
S  ab | aS | SS
45. Transform the following grammars to Chomsky normal form:
S  aSb | ab
S  aSaA | A

A  abA |b
S  abAB
A  bAB | λ
B  BAa | A | λ
46. Convert the following grammars into Greibach normal form:
S  aSb | ab
S  ab | aS | SS
47. Prove that the following dpa does not accept any string not in {ww
R
}
Q = {q
0
,q
1
,q
2
}, ∑ = {a,b}, Γ = {a,b,z}, F = {q
2
}
δ(q
0
,a,a) = {(q
0
,aa)}
δ(q
0
,b,a) = {(q
0
,ba)}
δ(q

0
,a,b) = {(q
0
,ab)}
δ(q
0
,b,b) = {(q
0
,bb)}
δ(q
0
,a,z) = {(q
0
,az)}
δ(q
0
,b,z) = {(q
0
,bz)}
δ(q
0
,λ,a) = {(q
1
,a)}
δ(q
0
,λ,b) = {(q
1
,b)}
δ(q

1
,a,a) = {(q
1
,λ)}
δ(q
1
,b,b) = {(q
1
,λ)}
δ(q
1
,λ,z) = {(q
2
,λ)}
48. Construct npda’s that accept the following languages on ∑ = {a,b,c}
a) L = {a
n
b
2n
}
b) L = {wcw
R
}
c) L = {a
3
b
n
c
n
}

d) L = {a
n
b
m
, n ≤ m ≤ 3n}
e) L = {w: n
a
(w) = n
b
(w)}
f) L = {w: n
a
(w) = 2n
b
(w)}
49. Prove that the following pda accepts the language L = {a
n+1
b
2n
}
δ(q
0
,λ,z) = {(q
1
,Sz)}
δ(q
1
,a,S) = {(q
1
,SA),(q

1
,
λ
)}
δ(q
1
,b,A) = {(q
1
,B)}
δ(q
1
,b,B) = {(q
1
,
λ
)}
δ(q
1
,λ,z) = {(q
2
,
λ
)}
50. Construct an npda corresponding to the following grammar
S  aABB | aAA
A  aBB | a
B  bBB | A
51. Show that L = {a
n
b

2n
} is a deterministic context-free language
52. Let L = {ab,aa,baa}. Which of the following strings are in L*:
abaabaaabaa, aaaabaaaa, baaaaabaaaab, baaaaabaa?
abaabaaabaa
aaaabaaaa
baaaaabaa
53. For which language it is true that L = L*?
a. L = {a
n
b
n+1
: n≥0}
b. L = {w: n
a
(w)=n
b
(w)}
a. No (give a counter-example)
b. Yes (Proof is left for students)
54. Which of the strings 0001, 01001, 0000110 are accepted by the
following nfa:
0001
01001
55. Give dfa’s for the sets consisting of
a. all strings with exactly one a.
b. all strings with no more than three a’s
56. Give a nfa for the language L = {ab
5
wb

4
: w ∈ {a,b}*}
57. Find dfa’s for the following languages on ∑ = {a,b}
a. L = {w: |w| mod 3 = 0}
b. L = {w: |w| mod 5 ≠ 0}
c. L = {w: n
a
(w) mod 3 > 1}
58. Consider the set of strings on {0,1} in which every 00 is followed
immediately by 1. For example 101, 0010, 0010011001 are in the language,
but 0001 and 00100 are not. Construct an accepting dfa
59. Show that the language L = {a
n
: n ≥ 0, n ≠ 4} is regular.
60. Find δ*(q
0,
a) and δ*(q
1,
λ
) for the following nfa
δ*(q
0,
a) = {q
0
,q
1
,q
2
}
δ*(q

1,
λ
) = {q
0
,q
1
,q
2
}
61. For the following nfa, find δ*(q
0,
1010) and δ*(q
1,
00)
δ*(q
0,
1010) = {q
0
,q
2
}
δ*(q
1,
00) = {}
62. Find an nfa with three states that accepts the language {ab,abc}*
63. Convert the following nfa into dfa
a.
b.
Solutions:
a.

b.
Optimize the DFA if you want (read Section 1.3 for DFA optimization):
Thus, the language is, surprisingly, (0+1)*.
64. Find all strings in L((a+b)*b(a+ab)*) of length less than four.
|w| = 0: λ
|w| = 1: b
|w| = 2: ab,bb,ba
|w| = 3: aab,abb,bab,bbb,aba,bba
65. Find a regular expression for the set {a
n
b
m
: (n+m) is even}
(aa)*(bb)* + (aa)*a(bb)*b
66. Give a regular expression for the language on ∑={a,b,c} containing no
run of a’s of length greater than two
Method 1:
A string of the given language can be considered as a sequence of patterns
each of which is either ax, x or aax (when a run of 2 a’s appears, it must be
followed immediately by b to make sure that the run stops with no more a)
where x is either b or c . The sequence can stop exceptionally by either aa or
a.
The corresponding regular expression:
(a(b+c)+(b+c)+aa(b+c))(aa+a+λ)
Method 2:
One can easily construct a DFA for the language as follows:
The required regular expression can then be derived from the DFA, which
should be the same as that given from Method 1
67. Give a regular expression for the language on ∑={a,b} containing all
strings not ending in ab.

(a+b)*(aa+ab+ba) + b + λ
68. Give a dfa that accepts L((a+b)*b(a+ab)*)
69. Find regular expressions for the language accepted by the following
automaton:
1*01*01*0
70. Construct a dfa that accepts that language generated by the following
grammar
S  abA
A  baB
B  aA | bb
71. Construct left-linear grammar for the language in Problem 2
S  Bbb
B  Aba
A  Ba | ab
72. Construct right-linear and left-linear grammars for the language L =
{a
n
b
m
,n≥2,m≥3}
S  aaA
A  aA | bbbB
B  bB | λ
S  Abbb
A  Ab | Baa
B  Ba | λ
73. Find intersection of the two following languages: L
1
= {a
n

b
2m
c
2k
} and L
2
= {a
2n
b
4m
c
k
}
{a
2n
b
4m
c
2k
}
74. The nor of two languages is defined as follows:
nor(L
1
,L
2
) = {w: w ∉L
1
and w ∉L
2
}

Show that nor is closed for regular languages
nor(L
1
,L
2
) =
21
LL ∪
75. Let L
1
= L(a*baa*) and L
2
= (aba*). Find L
1
/L
2
L(a*)
76. Suppose L
1
∪L
2
is regular and L
1
is finite. Can we conclude that L
2
is
regular?
YES.
Proof:
L

2
= (L
2
– L
1
) ∪ (L
2
∩ L
1
) (1).
L
2
– L
1
= (L
2
∪ L
1
) ∩
1
L
. Thus L
2
– L
1
is regular (2).
Since L
1
is finite, so is L
2

∩ L
1
.

Hence L
2
∩ L
1
is also regular (3).
From (1),(2) and (3), L
2
is regular.
Note: If L
1
is regular but not finite, we could not conclude anything about L
2
since the fact (3) above can not be claimed to complete the proof. One can
easily find a counter-example showing that whereas L
1
∪L
2
and L
1
are
regular, L
2
can still be not regular.
77. Prove that the following languages are not regular
a. L = {a
n

b
m
, n ≤ m}
b. L = {w: n
a
(w) ≠ n
b
(w)}
Read Linz’s book.
78. Find context-free grammars for the following languages
a. L = {a
n
b
m
: n ≤ m +3}
S  ABC
B  aBb | λ
A  aaa | aa | a | λ
C  Cb | λ
b. L = {a
n
b
m
: n ≠ m -1}
S  S
1
| S
2
S
1

 BA
B  aB | a
A  aAb | b
S
2
 AC
C  bC | b
c. L = {a
n
b
m
: n ≠ 2m}
S  S
1
| S
2
| aSb
S
1
 BA
B  aB | a
A  aaAb |
λ

S
2
 AC
C  bC | b
d. L = {a
n

b
m
: 2n ≤ m ≤ 3m}
S  aSB |
λ
B  bb | bbb
e. L = {a
n
b
m
c
k
: n = m or m ≤ k}
S  S
1
| S
2
S
1
 AB
A  aAb | λ
B  cB | λ
S
2
 CD
C  aC | λ
D  bDc | B
f. L = {a
n
b

m
c
k
: k = |n-m|}
S  S
1
| S
2
S
1
 aS
1
c

| S
3
S
3
 aS
3
b

| λ
S
2
 S
3
S
4
S

4
 bS
4
c | λ
g. L = {a
n
ww
R
b
n
: w

{a,b}*}
S  aSb | A
A  aAa | aAb | λ
h. L = {a
n
b
n
}
2
S  LL
L  aLb | λ
79. Show a derivation tree, together with the corresponding leftmost and rightmost
derivations of the string aabbbb with the grammar
S  AB | λ
A  aB
B  Sb
S => AB => aBB => aSbB => aABbB => aaBBbB => aaSbBbB => aabBbS => aabSbbB
=> aabbbB => aabbbSb => aabbbb

80. Find a context-free grammar for the set of all regular expressions on the alphabet
{a,b}*. Give a derivation tree for (a+b)*+a+b
E  E + T | T
T  T.F | F
F  (E) | E*| a | b
The tree is left for students to construct
81. Show that the following grammars is ambigous
S  AB | aaB
A  a | aA
B  b
S => aaB => aab
S => AB => aAB => aaB => aab
S  aSbS|bSaS|λ
S => aSbS => abSaSbS =>* abab
S => aSbS => aSbaSbS =>* abab
Draw the corresponding trees for the above derivations to observe the ambiguities.
82. Is it possible for a regular grammar to be ambigous?
S  aAB | aaB
A  a
B  b
83. Find an s-grammar for L(aaa*b+b)
S aS
1
| b
S
1
 aA
A  aA | b
84. Show that every s-grammar is unambigous
Consider an s-grammar G

s
. If G
s
is ambigous, there is at least a string s = a
1
a
2
…a
n

L(G
s
) of which two distinct derivation tree exits, namely T
1
and T
2
. Let D
1
and D
2
be the
two leftmost derivations of T
1
and T
2
respectively. Since T
1
and T
2
are distinct, D

1
and D
2
must be different. However, since G
s
is an s-grammar, w should have only one unique
leftmost derivation as S=> a
1
x
1
=> a
1
a
2
x
2
=>…=> a
1
a
2
…a
n,
hence the conflict.
85. Consider the following grammar:
S  aSb | SS | λ
Eliminate left-recursive for the grammar.
S aSbT | T
T  ST | λ
Show a derivation for the string w = aabbab using both orignal and rewriten grammars
S => SS => aSbS =>aaSbbS => aabbS => aabbaSb => aabbab

S => aSbT => aaSbTbT => aaTbTbT => aabTbT => aabbT => aabbST => aabbaSbTT =>
aabbabTT => aabbabTT => aabbabT => aabbab
86. Eliminate useless and unit productions for the following grammar:
S  a | aA | B | C
A  aB | λ
B  Aa
C  cCD
D  ddd
Eliminate unit production
S  a | aA | Aa | cCD
A  aB | λ
B  Aa
C  cCD
D  ddd
Eliminate useless production
S  a | aA | Aa
A  aB | λ
B  Aa
87. Eliminate all λ-production from
S  AaB | aaB
A  λ
B  bbA | λ
Directly replace A by λ
S  aB | aaB
B  bb | λ
Remove the remained λ-production
S  aB | aaB | a | aa
B  bb
88. Transform the following grammars to Chomsky normal form:
a)

S  aSb | ab
b)
S  aSaA | A
A  abA |b
c)
S  abAB
A  bAB | λ
B  BAa | A | λ
Solution:
a)
S

AS
1
| AB
S
1
 SB
A  a
B b
b)
Remove unit production
S  aSaA | abA | b
A  abA | b
Convert to Chomsky form:
S  A
2
S
1
| A

2
S
2
| b
A
2
 a
S
1
 SS
3
S
3
 A
2
A
2
S
2
 BA
2
A  A
2
S
4
| b
S
4
 BA
2

c)
Remove λ-production
S  abAB | abB | abA | ab
A  bAB | bA | bB | b
B  BAa | A | Ba | Aa | a
Remove unit-production
S  abAB | abB | abA | ab
A  bAB | bA | bB | b
B  BAa | Ba | Aa | bAB | bA | bB | b | a
Convert to Chomsky form:
S  A’S
1
| A’S
3
| A’S
4
| A’B’
A’ a
B’  b
S
1
 BS
2
S
2
 AB
S
3
 B’B
S

4
 B’A
A  B’S
2
| B’A | B’B | b
B  BS
5
| BA’ | AA’ | B’S
2
| B’A | B’B | b | a
S
5
 AA’
89. Convert the following grammars into Greibach normal form:
a) S  aSb | ab
b) S  ab | aS | SS
Solutions:
a)
- Conversion to Chomsky form:
S AS
1
| AB
S
1
 SB
A a
B  b
- Labeling
A
1

 A
2
A
3
| A
2
A
4
A
3
 A
1
A
4
A
2
 a
A
4
 b
- Sorting
A
1
 A
2
A
3
| A
2
A

4
A
3
 aA
3
A
4
| aA
4
A
4
A
2
 a
A
4
 b
- Transforming
A
1
 aA
3
| aA
4
A
3
 aA
3
A
4

| aA
4
A
4
A
2
 a
A
4
 b
b)
- Conversion to Chomsky form:
S

AB | AS | SS
A  a
B  b
- Labeling
A
1
 A
2
A
3
| A
2
A
1
| A
1

A
1
A
2
 a
A
3
 b
- Sorting
A
1
 A
2
A
3
| A
2
A
1
| A
2
A
3
T | A
2
A
1
T
T  A
1

T | A
1
A
2
 a
A
3
 b
- Transforming
A
1
 aA
3
| aA
1
| aA
3
T | aA
1
T
T 

aA
3
T | aA
1
T| aA
3
TT | aA
1

TT | aA
3
| aA
1
| aA
3
T | aA
1
T
A
2
 a
A
3
 b
(One can realize that A
2
 a now becomes useless and removable from the grammar)
90. Prove that the following ndpa does not accept any string not in {ww
R
}
Q = {q
0
,q
1
,q
2
}, ∑ = {a,b}, Γ = {a,b,z}, F = {q
2
}

δ(q
0
,a,a) = {(q
0
,aa)}
δ(q
0
,b,a) = {(q
0
,ba)}
δ(q
0
,a,b) = {(q
0
,ab)}
δ(q
0
,b,b) = {(q
0
,bb)}
δ(q
0
,a,z) = {(q
0
,az)}
δ(q
0
,b,z) = {(q
0
,bz)}

δ(q
0
,λ,a) = {(q
1
,a)}
δ(q
0
,λ,b) = {(q
1
,b)}
δ(q
1
,a,a) = {(q
1
,λ)}
δ(q
1
,b,b) = {(q
1
,λ)}
δ(q
1
,λ,z) = {(q
2
,λ)}
One can observe that the following move sequences cannot happen on the ndpa:
(q
1
,x,y) |* (q
0

,x’,y’) ∀x,x’∈ ∑*, y,y’∈ ∑*; and
(q
2
,x,y) |* (q
1
,x’,y’) ∀x,x’∈ ∑*, y,y’∈ ∑*.
Thus any string w accepted by the ndpa must be of the sequence form as follows:
(q
0
,w,z) |* (q
1
,x’,y’) |*(q
1
,λ, z) | (q
2
,λ, λ).
It can be observed easily that in order to make above sequence possible, w must be of the
form {ww
R
}
91. Construct npda’s that accept the following languages on ∑ = {a,b,c}
a) L = {a
n
b
2n
}
δ(q
0
,λ,z) = {(q
f

,z)}
δ(q
0
,a,z) = {(q
0
,aaz)}
δ(q
0
,a,a) = {(q
0
,aaa)}
δ(q
0
,b,a) = {(q
1
,λ)}
δ(q
1
,b,a) = {(q
1
,λ)}
δ(q
1
,λ,z) = {(q
f
,z)}
b) L = {wcw
R
}
δ(q

0
,a,z) = {(q
0
,az)}
δ(q
0
,b,z) = {(q
0
,bz)}
δ(q
0
,c,z) = {(q
0
,cz)}
δ(q
0
,c,z) = {(q
1
,z)}
δ(q
0
,a,a) = {(q
0
,aa)}
δ(q
0
,a,b) = {(q
0
,ab)}
δ(q

0
,a,c) = {(q
0
,ac)}
δ(q
0
,b,a) = {(q
0
,ba)}
δ(q
0
,b,b) = {(q
0
,bb)}
δ(q
0
,b,c) = {(q
0
,bc)}
δ(q
0
,c,a) = {(q
0
,ca)}
δ(q
0
,c,b) = {(q
0
,cb)}
δ(q

0
,c,c) = {(q
0
,cc)}
δ(q
0
,c,a) = {(q
1
,a)}
δ(q
0
,c,b) = {(q
1
,b)}
δ(q
0
,c,c) = {(q
1
,c)}
δ(q
1
,a,a) = {(q
1
,λ)}
δ(q
1
,b,b) = {(q
1
,λ)}
δ(q

1
,c,c) = {(q
1
,λ)}
δ(q
1
,λ,z) = {(q
f
,z)}
c) L = {a
3
b
n
c
n
}
δ(q
0
,λ,z) = {(q
0
,3z)}
δ(q
0
,a,3) = {(q
0
,2)}
δ(q
0
,a,2) = {(q
0

,1)}
δ(q
0
,a,1) = {(q
0
,0)}
δ(q
0
,b,0) = {(q
0
,b)}
δ(q
0
,b,b) = {(q
0
,bb)}
δ(q
0
,c,b) = {(q
1
,λ)}
δ(q
1
,c,b) = {(q
1
,λ)}
δ(q
1
,λ,z) = {(q
f

,z)}
d) L = {a
n
b
m
, n ≤ m ≤ 3n}
δ(q
0
,λ,z) = {(q
f
,z)}
δ(q
0
,a,z) = {(q
0
,az)}
δ(q
0
,a,z) = {(q
0
,aaz)}
δ(q
0
,a,z) = {(q
0
,aaaz)}
δ(q
0
,a,a) = {(q
0

,aa)}
δ(q
0
,a,a) = {(q
0
,aaa)}
δ(q
0
,a,a) = {(q
0
,aaaa)}
δ(q
0
,b,a) = {(q
1
,λ)}
δ(q
1
,b,a) = {(q
1
,λ)}
δ(q
1
,λ,z) = {(q
f
,z)}
e) L = {w: n
a
(w) = n
b

(w)}
δ(q
0
,λ,z) = {(q
f
,z)}
δ(q
0
,a,z) = {(q
0
,az)}
δ(q
0
,a,a) = {(q
0
,aa)}
δ(q
0
,b,a) = {(q
0
,λ)}
δ(q
0
,b,z) = {(q
0
,bz)}
δ(q
0
,b,b) = {(q
0

,bb)}
δ(q
0
,a,b) = {(q
0
,λ)}
f) L = {w: n
a
(w) = 2n
b
(w)}
δ(q
0
,λ,z) = {(q
f
,z)}
δ(q
0
,a,z) = {(q
0
,az)}
δ(q
0
,a,a) = {(q
0
,aa)}
δ(q
0
,b,a) = {(q
1

,λ)}
δ(q
1
,λ,a) = {(q
0
,λ)}
δ(q
1
,λ,z) = {(q
0
,b)}
δ(q
0
,b,z) = {(q
0
,bbz)}
δ(q
0
,b,b) = {(q
0
,bbb)}
δ(q
0
,a,b) = {(q
0
,λ)}
92. Prove that the following pda accepts the language L = {a
n+1
b
2n

}
δ(q
0
,λ,z) = {(q
1
,Sz)}
δ(q
1
,a,S) = {(q
1
,SA),(q
1
,
λ
)}
δ(q
1
,b,A) = {(q
1
,B)}
δ(q
1
,b,B) = {(q
1
,
λ
)}
δ(q
1
,λ,z) = {(q

2
,
λ
)}
The above pda corresponds to the following grammar
S  aSA | a
A  bB
B  b
or
S  aSA | a
A  bb
or
S  aSbb | a
93. Construct an npda corresponding to the following grammar
S  aABB | aAA
A  aBB | a
B  bBB | A
Remove unit production
S  aABB | aAA
A  aBB | a
B  bBB | aBB | a
δ(q
0
,λ,z) = {(q
1
,Sz)}
δ(q
1
,a,S) = {(q
1

,ABB),(q
1
,AA)}
δ(q
1
,A,a) = {(q
1
,BB),(q
1
,λ)}
δ(q
1
,B,b) = {(q
1
,BB)}
δ(q
1
,B,a) = {(q
1
,BB),(q
1
,λ)}
δ(q
1
,λ,z) = {(q
f
,
λ
)}
94. Show that L = {a

n
b
2n
} is a deterministic context-free language
δ(q
0
,a,z) = {(q
1
,aaz)}
δ(q
1
,a,a) = {(q
1
,aaa)}
δ(q
1
,b,a) = {(q
2
,λ)}
δ(q
2
,b,a) = {(q
2
,λ)} δ(q
2
,λ,z) = {(q
0
,λ)}

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×