Formal Languages With Visualizations

Chapter 7 Pushdown Automata

| About   中文版   «  7.1. Pushdown Automata   ::   Contents   ::   7.3. Deterministic Pushdown Automata  »

7.2. PDAs and Context Free Languages

7.2.1. PDAs and Context Free Languages

Now we want to show that NPDA’s and CFG both represent CFL’s. Show that we can take any CFG and construct a NPDA and vice versa.

Theorem: For any CFL \(L\) not containing \(\lambda\), \(\exists\) a NPDA \(M\) such that \(L = L(M)\).

Proof (sketch)

Given (\(\lambda\) -free) CFL \(L\).
\(\Rightarrow \exists\) CFG \(G\) such that \(L = L(G)\).
\(\Rightarrow \exists G'\) in GNF, such that \(L(G) = L(G')\).
\(G' = (V,T,S,P)\). All productions in \(P\) are of the form:
\(A \rightarrow ax\)
\(A \in V, a \in T, x \in V^*\)
Construct NPDA \(M = (Q, \Sigma, \Gamma, \delta, q_0, z, F)\)
\(Q = \{q_0, q_1, q_f\}, \Sigma = T, \Gamma = V \cup \{z\}, F = \{q_f\}\)
1. \(M\) starts by putting \(S\) on the stack
2. For each production
\(A \rightarrow a X_1 X_2 \ldots X_n\)
put \((q_1, X_1 X_2 \ldots X_n)\) in \(\delta(q_1, a, A)\)
(Pop \(A\) from the stack, read “a” from tape, and push \(X_1 X_2 \ldots X_n\) onto the stack)
3. Accept if \(S \stackrel{*}{\Rightarrow} w \in \Sigma^*\) (all variables on the stack are replaced by terminals or \(\lambda\))
Show \(w \in L(G')\) iff \(w \in L(M)\). QED.

Now we want to show that given an NPDA, we can construct a CFG. But first, we will show a result to make the next proof easier.

Theorem: Given a NPDA \(M\), \(\exists\) a NPDA \(M'\) such that all transitions have the form \(\delta(q_i, a, A) = \{c_1, c_2, \ldots c_n\}\) where

\[\begin{split}\begin{eqnarray*} c_i &=& (q_j, \lambda)\\ \mbox{or}\ c_i &=& (q_j, BC)\\ \end{eqnarray*}\end{split}\]

Each move either increases or decreases stack contents by a single symbol.

Proof: (sketch)

lt7pf4

Theorem: If \(L = L(M)\) for some NPDA \(M\), then \(L\) is a CFL.

Settings

Proficient Saving... Error Saving
Server Error
Resubmit

Note

Want to show that each NPDA represents a CFL, so we will take a NPDA \(M\) and convert it to a CFG.

It will be an easier construction if we take the NPDA and put all the transitions in a simpler form.

Proof:

Given NPDA \(M\), first, construct an equivalent NPDA \(M'\) that will be easier to work with. Construct \(M'\) such that
1. \(M'\) accepts if stack is empty
2. Each move increases or decreases stack content by a single symbol. (Can only push 2 variables or no variables with each transition.)
\(M' = (Q, \Sigma, \Gamma, \delta, q_0, z, F)\)
Construct \(G = (V,\Sigma, S, P)\) where
\(V = \{(q_icq_j)\ |\ q_i, q_j \in Q, c \in \Gamma \}\)
(Some of these variables will be useless.)
\((q_icq_j)\) represents “starting at state \(q_i\) the stack contents are \(cw, w \in \Gamma^*\), some path is followed to state \(q_j\) and the contents of the stack are now \(w\)”.
Goal: \((q_0zq_f)\) which will be the start symbol in the grammar.
Meaning: We start in state \(q_0\) with \(z\) on the stack and process the input tape. Eventually we will reach the final state \(q_f\) and the stack will be empty. (Along the way we may push symbols on the stack, but these symbols will be popped from the stack).
(NOTE: Machine accepts by empty stack, but it is such that there is only 1 final state in which the machine accepts by final state.)
To construct the productions in P:
1) Replace
by
\[(q_iAq_j) \rightarrow a\]
where the stack changes are:
\[\begin{split}\begin{array}{lcclc} & q_i & \ \ (\mbox{some path}\ \rightarrow) \ \ & &q_j \\ \\ \mbox{stack:} & A && \mbox{stack:} & \\ & X_1 & && X_1 \\ & X_2 &&& X_2 \\ & \underline{X_n} &&& \underline{X_n} \\ \end{array}\end{split}\]
2) Replace
by
\[(q_iAq_k) \rightarrow a(q_jBq_l)(q_lCq_k)\ \mbox{for all}\ q_l, q_k \in Q\]
\[\begin{split}\begin{array}{ccccccc} q_i & \ \ (\mbox{path}\ \rightarrow) \ \ & q_j &\ \ (\mbox{path}\ \rightarrow) \ \ & q_l &\ \ (\mbox{path}\ \rightarrow) \ \ & q_k \\ \\ &&B&& \\ A && C &&C \\ X_1 & & X_1 & & X_1 & & X_1 \\ X_2 && X_2 && X_2 && X_2 \\ \underline{X_n} &&\underline{X_n} &&\underline{X_n} &&\underline{X_n}\\ \end{array}\end{split}\]
This will create some useless variables, but that’s ok.
Must show that the constructed grammar \(G\) is such that \(L(G) = L(M')\). That is, \(w \in L(G) \mbox{iff}\ w \in L(M)\). (see book) QED.

   «  7.1. Pushdown Automata   ::   Contents   ::   7.3. Deterministic Pushdown Automata  »

Close Window