Section 3.5

Pushdown Automata and Context-Free Grammars

[13/46%]
Show
LaTeX
Example 3.36

Consider the context-free grammar G=({S},{a,b},R,S)G=(\left\{ S\right\} , \left\{ a, b\right\} , R, S), with the rules

S⟶aS∣aSbS∣ε. S \longrightarrow a S \mid a S b S \mid \varepsilon .

Construct a PDA MM such that L(M)=L(G)L(M)=L(G).

?
Example 3.38

Construct a context-free grammar GG such that L(G)=L(M)L(G)= L(M), where MM is the PDA of Example 3.29.

?
Example 3.39

Show that if AA is a regular language and BB is a context-free language, then A∩BA \cap B is a context-free language.

?
Example 3.40

Show that L={0,1}∗−{(0m1m)n∣m,n≥1}L= \left\{ 0,1\right\}^{*}-\left\{ \left(0^{m} 1^{m}\right)^{n} \mid m, n \geq 1\right\} is a contextfree language.

?
Example 3.41

Show that if L1L_{1} is a context-free language and L2L_{2} is a regular language, then the quotient L1/L2L_{1} / L_{2} is a context-free language.

?
Example 3.42

Show that if LL is regular, then

L~={xz∣(∃y)[∣x∣=∣y∣=∣z∣,xyz∈L]} \widetilde{L}=\left\{ x z \mid (\exists y)[\left|x\right|=\left|y\right|=\left|z\right|, x y z \in L]\right\}

is context-free.

?
Problem 3.5.1

For each of the following context-free grammars GG, following the procedure of Theorem 3.35 to construct a PDA that accepts the language L(G)L(G) :

?
(a)

S→ε∣aSbS∣bSaSS \rightarrow \varepsilon \mid a S b S \mid b S a S.

(b)

S⟶ε∣SS∣aSbS \longrightarrow \varepsilon \mid S S \mid a S b.

(c)

The grammar of Solution 2 to Example 3.6.

(d)

The unambiguous grammar of Example 3.24(b).

Problem 3.5.2

For each of the following PDA's MM, following the procedure of Theorem 3.37 to construct a context-free grammar that generates the language L(M)L(M) :

?
(a)

The PDA of Example 3.30.

(b)

The PDA of Figure 3.14(a) (for language {aibj∣2i=3j}\left\{ a^{i} b^{j} \mid 2 i=3 j\right\}).

Problem 3.5.3

Construct pushdown automata to accept the following languages:

?
(a)

{0n1m∣m≠n,m≠2n,m≠3n}\left\{ 0^{n} 1^{m} \mid m \neq n, m \neq 2 n, m \neq 3 n\right\}.

(b)

{aibjck∣i≠j or j≠k or i≠k}\left\{ a^{i} b^{j} c^{k} \mid i \neq j\text{ or }j \neq k\text{ or }i \neq k\right\}.

(c)

{0,1}∗−{(0n1)n∣n≥1}\left\{ 0,1\right\}^{*}-\left\{ \left(0^{n} 1\right)^{n} \mid n \geq 1\right\}.

(d)

{0,1}∗−{bi#bi+1∣bi is the binary representation of i,i≥1}\left\{ 0,1\right\}^{*}-\left\{ b_{i} \# b_{i+1} \mid b_{i}\text{ is the binary representation of }i, i \geq 1\right\}.

Problem 3.5.4

Show that if LL is a regular language, then each of the following languages is context-free:

?
(a)

{x∈L∣x=xR}\left\{ x \in L \mid x=x^{R}\right\}.

(b)

{wy∣(∃x,z)[∣w∣=∣x∣=∣y∣=∣z∣,wxyz∈L]}\left\{ w y \mid (\exists x, z)\left[\left|w\right|=\left|x\right|=\left|y\right|=\left|z\right|, w x y z \in L\right]\right\}.

(c)

{yx∣(∃w,z)[∣w∣=∣x∣=∣y∣=∣z∣,wxyz∈L]}\left\{ y x \mid (\exists w, z)\left[\left|w\right|=\left|x\right|=\left|y\right|=\left|z\right|, w x y z \in L\right]\right\}.

(d)

{xz∣∣w∣=∣x∣=∣y∣=∣z∣,wxyz∈L}\left\{ x z \mid \left|w\right|=\left|x\right|=\left|y\right|=\left|z\right|, w x y z \in L\right\}.

Problem 3.5.5

Show that L1\L2L_{1} \backslash L_{2} is a context-free language, if L1L_{1} is context-free and L2L_{2} is regular.

?
Problem 3.5.6

A two-stack pushdown automaton (2-stack PDA) is a PDA with two pushdown stacks. At each move, MM can read, in addition to an input symbol, the top symbols of both stacks, and to write symbols to both stacks. Formally, a 2 -stack PDA is a 6 -tuple M=(Q,Σ,Γ,δ,s,F)M=(Q, \Sigma , \Gamma , \delta , s, F), where Q,Σ,Γ,s,FQ, \Sigma , \Gamma , s, F are the same as those of a PDA, and δ\delta is a transition function

δ:Q×(Σ∪{ε})×(Γ∪{ε})2→2Q×(Γ∪{ε})2 \delta : Q \times (\Sigma \cup \left\{ \varepsilon \right\} ) \times (\Gamma \cup \left\{ \varepsilon \right\} )^{2} \rightarrow 2^{Q \times (\Gamma \cup \left\{ \varepsilon \right\} )^{2}}

Let a∈Σ∪{ε}a \in \Sigma \cup \left\{ \varepsilon \right\}, and u1,u2,v1,v2∈Γ∪{ε}u_{1}, u_{2}, v_{1}, v_{2} \in \Gamma \cup \left\{ \varepsilon \right\}. Then, an instruction (p,v1,v2)∈δ(q,a,u1,u2)\left(p, v_{1}, v_{2}\right) \in \delta \left(q, a, u_{1}, u_{2}\right), indicates that the PDA MM reads the input aa, the top symbol u1u_{1} of stack 1, the top symbol u2u_{2} of stack 2, and then it moves to state pp, repaces u1u_{1} by v1v_{1} and replaces u2u_{2} by v2v_{2}.

?
(a)

Define formally the notion of configurations and successor configurations of a 2 -stack PDA.

(b)

Construct a 2-stack PDA to accept the language {anbncn∣n≥0}\left\{ a^{n} b^{n} c^{n} \mid n \geq 0\right\}.

(c)

Construct a 2 -stack PDA to accept the language {anbmcndm∣n≥m}\left\{ a^{n} b^{m} c^{n} d^{m} \mid n \geq m\right\}.

Problem 3.5.7

A pushdown automaton MM is called a linear-bounded PDA if there is a constant c>0c>0 such that the size of the stack of MM, during its computation on any input xx, is bounded by c∣x∣c\left|x\right|. Show that the class of languages accepted by linear-bounded PDA's is exactly the class of context-free languages.

?