From PDA to CFG (General Case)
Explore the process of converting pushdown automata (PDA) to context-free grammars (CFG). Understand how PDA states, stack symbols, and transitions correspond to CFG variables and rules. Gain insight into stack behavior, lifetimes of stack variables, and how these map to grammar productions. This lesson also covers normalizing PDAs and constructing CFG rules from PDA transitions, with examples including balanced parentheses and the language of equal numbers of symbols.
We'll cover the following...
Converting an arbitrary PDA to CFG
To convert an arbitrary PDA to a CFG, we somehow need to relate the states and transitions of the PDA, including stack operations, to variables and rules in a CFG. This is a tall order but a doable one. To understand the algorithm, we need to take a deeper look at stack behavior in PDAs. We start with the simple, one-state PDA for found in the figure below.
While referring to this figure, let’s study the following trace of .
| Step | Input | Stack |
|---|---|---|
| 0 | ||
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | ||
| 5 | ||
| 6 | ||
| 7 | ||
| 8 | ||
| 9 | ||
| 10 | ||
| 11 | ||
| 12 |
We have numbered the stack variables (and the lambdas) with subscripts according to the order in which they appear on the stack so we can inspect their stack lifetimes. As always, the stack begins and ends empty, and in between, it grows and shrinks in size repeatedly. A stack variable’s lifetime is the number of steps from when it is first pushed until it is removed from the stack. The lifetimes of the stack variables in the above table appear in the following table.
| Stack Variable | Lifetime (In Steps) | Step Range |
|---|---|---|
| 7 | 1–7 | |
| 5 | 2–6 | |
| 1 | 3–3 | |
| 1 | 5–5 | |
| 3 | 9–11 | |
| 1 | 10–10 |
From the time the first variable, , appears on the stack until it is removed, three other ’s ( ...