Find the equivalent CFG of the following PDA
P=({q0,q1},{a,b},{a,z0},δ,q0,z0) where δ is given by:
δ(q0,a,z0)=(q0,az0)
δ(q0,a,a)=(q1,aa)
δ(q1,a,a)=(q1,ε)
δ(q1,ε,z0)=(q1,ε)
Answer: Use the standard PDA-to-CFG construction: create a variable Apq generating all strings that take the PDA from state p to state q leaving the stack as it was found.
Given P = (
{q0,q1}
,
{a,b}
,
{a,Z0}
,delta,q0,Z0) with delta(q0,a,Z0)=(q0,aZ0), delta(q0,a,a)=(q1,aa), delta(q1,a,a)=(q1,epsilon), delta(q1,epsilon,Z0)=(q1,epsilon).
- For a push move that increases stack by one and goes p->r, and a later pop from r->q, add Apq -> a Arq a.
- For a move that leaves stack unchanged (p->r), add Apq -> a Arq.
- For epsilon moves, add Apq -> Arq.
- Base: App -> epsilon.
- Start variable = Aq0qf.
Converting a pushdown automaton into a grammar. Every pushdown automaton has an equivalent context free grammar, which is the basis of the standard construction from automata to grammars. The construction creates a nonterminal for every ordered pair of states of the automaton, representing the language of input strings that take the machine from the first state to the second while leaving the stack exactly as it was found. For each transition that pops a symbol and pushes a single symbol while moving from state P to state Q on input a, add a production from the pair of P and Q to a. For transitions that push several stack symbols, introduce intermediate nonterminals that represent the effect of consuming each pushed symbol in turn, so that the nested calls reproduce the stack discipline. Variables are also added for the start and final states so that derivation begins and ends at the correct states. A string is accepted by empty stack exactly when the corresponding nonterminal can derive it, because the derivation mirrors the sequence of stack operations. A complete answer states what each pair variable means, derives the productions from the given transition functions, lists the resulting grammar and checks a short string derivation against an accepting computation of the automaton. Explaining why leaving the stack unchanged is the key invariant makes the construction intelligible rather than a set of arbitrary productions. Mentioning that the converse construction turns a grammar in Greibach normal form into a pushdown automaton shows that the two models are equivalent in power.
Result: The grammar with variables Aij and rules generated from the four transitions above is an equivalent CFG; the construction works by pairing stack push with matching pop.
Tip from Examiner: State the formal definition, show the construction or derivation step by step, and verify the result on a short sample string.
Key Points
- Variables A_pq for state pairs
- Rules for push/pop pairs and epsilon moves
- Start symbol A_q0,qf