Theory of Computation · Pushdown Automata
Conversion of CFG in GNF to Pushdown Automata
Overview
Greibach Normal Form (GNF) allows a context-free grammar (CFG) to be converted directly into a pushdown automaton (PDA), because every GNF production consumes exactly one input terminal.
The construction uses three states: an initial state that seeds the stack, a working state that simulates the productions, and a final state reached when the input is exhausted.
Key concepts
- GNF production form: every production is , where is a terminal and is a (possibly empty) string of variables. This guarantees one input symbol consumed per production applied.
- Bottom-of-stack marker : marks the bottom of the stack and is used to detect when the stack has been reduced to its base.
- Start symbol : pushed onto the stack at the beginning (or , if is the start symbol).
- States: (initial, pushes the start symbol), (simulates productions), (final).
- Acceptance: by final state together with empty stack; leaving in place is sufficient, and emptying it with epsilon is also correct.
How it works
- Push the start symbol. In , on epsilon input with on top, push the start symbol above and move to : . does nothing with the input.
- Simulate every GNF production in . For each production , add a transition that, in on input with on top, stays in and replaces by (pop , push ). Likewise for : .
Here and may be epsilon or one or more variables. - Add the final state. From , on epsilon input with on top (input over, bottom of stack reached), go to : , or if the stack is emptied.
The grammar must be in GNF before this procedure is applied.
Drawing the diagram…
Formulas
-
GNF production form: — is a terminal, is a string of variables, possibly epsilon.
-
Step 1: — is the start symbol, is the bottom-of-stack marker.
-
Step 2 for : — pop , push .
-
Step 2 for : .
-
Step 3: , or if the stack is emptied.
-
PDA from GNF grammar
Drawing the diagram…
- The three-state PDA construction: Q0 seeds the stack with the start symbol, Q1 simulates each GNF production while consuming one terminal, and QF is reached when input is over and Z0 is on top.
Worked examples
Convert a grammar to GNF, then to a PDA.
Given grammar (two productions), not in GNF because a production mixes variables and terminals (a terminal followed by a string containing both variables and terminals):
Convert to GNF: introduce a new variable with , and rewrite:
Every production is now a terminal followed by only variables, so the grammar is in GNF.
Build the PDA.
Step 1 — push start symbol:
| State | Input | Stack top | Move | New state | Stack action |
|---|---|---|---|---|---|
| epsilon | push above |
Step 2 — one transition per production:
| State | Input | Stack top | Move | New state | Stack action |
|---|---|---|---|---|---|
| apply | (replace by ) | ||||
| apply | (replace by ) | ||||
| apply | (push nothing) |
Step 3 — acceptance:
| State | Input | Stack top | Move | New state | Stack action |
|---|---|---|---|---|---|
| epsilon | input over, bottom of stack reached | leave (or empty it) |
Revision summary
- GNF makes CFG-to-PDA conversion direct: each production consumes exactly one input terminal.
- Always convert the grammar to GNF first; a production like is not in GNF and must be rewritten by introducing new variables (e.g., ).
- The three steps: (1) push the start symbol from to , (2) for each production add , (3) add .
- and in a GNF production may be epsilon or one or more variables.
- The final move gives acceptance by final state together with empty stack; leaving in place is sufficient, and emptying it is also allowed.
Previous-year exam insights
- A language is accepted by some PDA by final state iff it is accepted by some PDA by empty stack; the two classes of accepted languages are identical (both equal the context-free languages).
Asked inGATE 1999UGC NET 2018 - Nondeterministic PDAs are strictly more powerful than deterministic PDAs: there is no algorithm to convert an NPDA into an equivalent DPDA, and some context-free languages are not deterministic context-free.
Asked inGATE 1998GATE 1994GATE 1992ISRO 2017 - A PDA whose stack is bounded to a fixed finite number of symbols is equivalent to a finite automaton, so it accepts exactly the regular languages.
Asked inGATE 2002 - Every regular language (and every NFA/DFA) can be converted to an equivalent PDA; the context-free languages properly contain the regular languages.
Asked inISRO 2017UGC NET 2018 - In the standard transition notation (q, Y) in delta(p, a, X), the PDA reads input a (or epsilon), pops X from the stack top, moves from p to q, and pushes the string Y (Y = epsilon means pop only;
X = epsilon means no pop).
Asked inGATE 2021GATE 2015GATE 2004 - The complement of every context-free language is recursive (context-free languages are recursive, and recursive languages are closed under complement), even though CFLs are not closed under complement.
Asked inISRO 2017