This preview shows pages 1–2. Sign up to view the full content.
CS 181 — Winter 2005
Formal Languages and Automata Theory
Problem Set #4 Solutions
Problem 4.1.
(10 points)
1. Show that if all productions of a CFG
G
are of the form
A
→
wB
or
A
→
w
for variables
A,B
∈
V
and strings of terminals
w
∈
Σ
*
, then
L
(
G
) is regular.
Solution
Given a contextfree grammar
G
= (
V,
Σ
,R,S
) where each production
R
has either form
A
→
wB
or
A
→
w
, we will construct a GNFA for
L
(
G
). Here is the intuition: Our GNFA
will have a state for each variable in
V
an initial state
q
0
and a ﬁnal state
q
f
. Our initial
state
q
0
has a transition into
S
on
ε
. For each production of the form
A
→
wB
we have a
transition from the state
A
to the state
B
over regular expression
w
. For each production of
the form
A
→
w
we have a transition from the state
A
to the state
q
f
over
w
.
Formally, our GNFA is deﬁned as
M
= (
V
∪ {
q
0
,q
f
}
,
Σ
,δ,q
0
,
{
q
f
}
) where the transition
function is
δ
(
q,p
) =
ε,
if
q
=
q
0
and
p
=
S
S
w
:(
q
→
w
)
∈
R
w,
if
q
∈
V
and
p
=
q
f
S
w
:(
q
→
wp
)
∈
R
w,
if
q,p
∈
V
∅
,
otherwise
Notice that to handle cases where our grammar has productions
A
→
w
1
B
and
A
→
w
2
B
,
we have a transition from
A
to
B
over
w
1
∪
w
2
.
Let us now show that in fact
L
(
M
) =
L
(
G
). Suppose
w
∈
L
(
G
) then there is some derivation
S
=
⇒
w
1
V
1
=
⇒
w
1
w
2
V
2
=
⇒ ···
=
⇒
w
1
w
2
···
w
k

1
V
k

1
=
⇒
w
1
w
2
···
w
k
=
w
Then clearly the run of
M
on
w
with state sequence
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.
 Spring '08
 griebach

Click to edit the document details