Example of Converting a PDA to a CFG

The PDA:

M = ({q0,q1}, {0,1}, {X, Zo}, D, q0, Zo, {})

with D (delta):

d(q0,0,Z0) = (q0,XZo)  (1a)
d(q0,0,X) = (q0,XX)    (1b) 
d(q0,1,X) = (q1,e)     (2a)
d(q1,1,X) = (q1,e)     (2b)
d(q1,e,X) = (q1,e)     (2c)
d(q1,e,Zo) = (q1,e)    (2d)

The CFG

Obviously, T = {0,1}  (same as sigma from the PDA)

We will call the Start Symbol "S".

V = (S, [q0,X,q0], [q0,X,q1], [q1,X,q0], [q1,X,q1],
        [q0,Zo,q0], [q0,Zo,q1], [q1,Zo,q0], [q1,Zo,q1])

The Productions

First, generate the productions from S:

S -> [q0,Zo,q0]   
S -> [q0,Zo,q1]    

(the first two components of the RHS are fixed, the last piece is every possible state from the machine).

We will derive forward, only building productions for variables that can be derived.

So, for the q0,Zo,q0 variable, generate the productions based on the 1a rule above:

[q0,Zo,q0] -> 0[q0,X,q0][q0,Zo,q0]   (1a')
           -> 0[q0,X,q1][q1,Zo,q0]   (1a'')

next come the matching productions from the second variable:

[q0,Zo,q1] -> 0[q0,X,q0][q0,Zo,q1]   (1a''')
           -> 0[q0,X,q1][q1,Zo,q1]   (1a'''')

Then, working from the two variables that mention X, and the matching rule 1b, we get the following collection of productions:

[q0,X,q0] -> 0[q0,X,q0][q0,X,q0]   (1b')
          -> 0[q0,X,q1][q1,X,q0]   (1b'')
[q0,X,q1] -> 0[q0,X,q0][q0,X,q1]   (1b''')
          -> 0[q0,X,q1][q1,X,q1]   (1b'''')

Then for the other four delta moves, we get the following productions:

[q0,X,q1] -> 1    (2a')
[q1,Zo,q1] -> e   (2b')
[q1,X,q1] -> e    (2c')
[q1,X,q1] -> 1    (2d')

Now, note that we can tidy up a bit:

The variables [q1,X,q0] and [q1,Zo,q0] never appear as a LHS, so we can drop these productions:  1a'', 1b''. 

Similarly, [q0,X,q0] and [q0,Zo,q0] always appear on the RHS of any of their own productions (or just on the RHS), so we can drop these productions: 1a', 1a''', 1b', 1b''', as well as the first production from the start symbol.

Which leaves us with
S -> [q0,Zo,q1]
[q0,Zo,q1] -> 0[q0,X,q1][q1,Zo,q1]
[q0,X,q1] -> 0[q0,X,q1][q1,X,q1]
and the four 2a-d' rules.

And all that can be renamed to:
S -> A
A -> 0BC
B -> 0BD |  1
C -> e
D -> 1 | e