ECS 120 Lesson 13 – Pushdown Automata,
Pt. 2
Oliver Kreylos
Friday, April 27th, 2001
In the last lecture, we introduced pushdown automata as an alternative
means to specify contextfree languages. We still have left to prove that they
are actually capable of that; in other words, we have to show that the class of
languages that can be accepted by pushdown automata is exactly the class of
languages that can be generated by contextfree grammars. As usual, we will
prove this equivalence in two directions. The ﬁrst direction is a constructive
proof that describes how to build a PDA that accepts the language generated
by a given grammar. This construction is important in practice, because it
shows how to create a parser for a given grammar. The reverse direction,
building a grammar from a given PDA, is of lesser practical value.
1 Converting a ContextFree Grammar into
a PDA
We have to show that every contextfree language is accepted by some PDA.
In other words, if
L
is a contextfree language, i. e., there exists a context
free grammar
G
such that
L
=
L
(
G
), there must exist a PDA
P
such that
L
=
L
(
P
). The basic idea for the construction of
P
is to simulate the leftmost
derivations in
G
, and to accept a word iﬀ there exists a leftmost derivation
that generates it. The PDA will use its stack to store and manipulate the
intermediate strings in the derivation it simulates, and after all variables have
been replaced by characters, the resulting string will be compared to the input
string. The PDA will use its nondeterminism to “guess” which rule to apply
to the leftmost variable in each step. If the input word can be generated
1
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Documentby the grammar, at least one of the resulting branches of computation will
succeed in matching the word and the PDA will accept.
When looking at leftmost derivations
S
⇒
s
1
⇒ ··· ⇒
s
n

1
⇒
w
in
G
,
every intermediate string
s
i
can be written as
s
i
=
xAα
, where
A
∈
V
is the
leftmost variable,
x
∈
Σ
*
is a string of only characters, and
α
∈
(
V
∪
Σ)
*
is a string of variables and characters. Since the PDA needs to access the
leftmost variable
A
in any derivation step, it is not possible to store the entire
string
s
i
on the stack – a PDA can only access the topmost stack symbol.
But we know that the symbols to the left of
A
(the word
x
) will never change
during further derivations, and in the end they have to match the beginning
characters in the input string. Therefore, it is not necessary to store the
characteronly preﬁx of
s
i
, but only all symbols from the ﬁrst variable on.
The suﬃx of an intermediate string including the leftmost variable,
Aα
, is
called a
tail
. Whenever during derivation the intermediate string has a preﬁx
of only characters, that preﬁx is going to be matched against input characters
immediately. Using this strategy, the leftmost variable of all intermediate
strings is always the topmost stack symbol, and can be accessed by the PDA.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '07
 Filkov
 Formal language, Contextfree grammar, PDAs

Click to edit the document details