CS 381 HW 8 Solutions
Dan FitzGerald, [email protected]
November 1, 2006
1. Convert the following CFG to a one state PDA:
S
→
bA
S
→
aB
A
→
a
A
→
bAA
A
→
aS
B
→
b
B
→
bS
B
→
aBB
The main idea of this problem is summarized on page 238 of the text.
Basically, we plan to expand the grammar from left to right on the stack.
Whenever we see terminals (a and b in this case), we will compare them to
the input tape and erase the symbol from the stack if they match. When
we encounter a production (S,A, or B), we will guess which production to
follow and expand it onto the stack. We continue this process of eating
the terminals at the top of the stack and expanding productions until no
productions remain, and we will continue comparing terminals to the in
put and erasing them if they match. In the end, we will reach an empty
stack and accept if the string is in the grammar, and thus have a PDA for
the grammar.
More formally, our PDA
P
= (
Q,
Σ
,
Γ
, δ, q
0
, Z
0
, F
)
is de ned as:
Q
=
{
1
}
,
Σ =
{
a, b
}
, δ, q
0
= 1
, Z
0
=
Z
0
, S
= 1
, F
=
K
where
δ
is de ned as
δ
(1
, ±, S
)
→
(1
, bA
)
,
{
(1
, aB
)
}
δ
(1
, ±, A
)
→ {
(1
, a
)
,
(1
, bAA
)
,
(1
, aS
)
}
δ
(1
, ±, B
)
→ {
(1
, b
)
,
(1
, bS
)
,
(1
, aBB
)
}
δ
(1
, a, a
)
→ {
(1
, ±
)
}
δ
(1
, b, b
)
→ {
(1
, ±
)
}
All other transitions are empty.
¥
1
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document2. Problem 6.3.3: Convert the PDA
P
= (
{
p, q
}
,
{
0
,
1
}
,
{
X, Z
0
}
, δ, q, Z
0
)
to a
CFG, if
δ
is given by
δ
(
q,
1
, Z
0
)
=
{
(
q, XZ
0
)
}
δ
(
q,
1
, X
)
=
{
(
q, XX
)
}
δ
(
q,
0
, X
)
=
{
(
p, X
)
}
δ
(
q, ±, X
)
=
{
(
q, ±
)
}
δ
(
p,
1
, X
)
=
{
(
p, ±
)
}
δ
(
p,
0
, Z
0
)
=
{
(
q, Z
0
)
}
Solution: we seek to construct
G
= (
V,
Σ
, R, S
)
where
L
(
G
) =
N
(
P
)
as
seen on page 242 of the text. The set of variables,
V
, consists of (1)
the start symbol
S
and (2) all symbols of the form
[
pXq
]
where
p
and
q
are
states in
Q
and
X
is a stack symbol in
Γ
. Thus, our variables are as follows
S,
[
qXq
]
,
[
qZ
0
q
]
,
[
qXp
]
,
[
qZ
0
p
]
,
[
pXq
]
,
[
pZ
0
q
]
,
[
pXp
]
,
[
pZ
0
p
]
This is simply all combinations of states and stack symbols
Now let's create the productions. First we will start with the special
start production. We know
q
is our start symbol and we could go to either
p
or stay at
q
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '06
 HOPCROFT
 Trigraph, Formal language, Regular expression, Regular language, Contextfree grammar

Click to edit the document details