
- Automata Theory - Applications
- Automata Terminology
- Basics of String in Automata
- Set Theory for Automata
- Finite Sets and Infinite Sets
- Algebraic Operations on Sets
- Relations Sets in Automata Theory
- Graph and Tree in Automata Theory
- Transition Table in Automata
- What is Queue Automata?
- Compound Finite Automata
- Complementation Process in DFA
- Closure Properties in Automata
- Concatenation Process in DFA
- Language and Grammars
- Language and Grammar
- Grammars in Theory of Computation
- Language Generated by a Grammar
- Chomsky Classification of Grammars
- Context-Sensitive Languages
- Finite Automata
- What is Finite Automata?
- Finite Automata Types
- Applications of Finite Automata
- Limitations of Finite Automata
- Two-way Deterministic Finite Automata
- Deterministic Finite Automaton (DFA)
- Non-deterministic Finite Automaton (NFA)
- NDFA to DFA Conversion
- Equivalence of NFA and DFA
- Dead State in Finite Automata
- Minimization of DFA
- Automata Moore Machine
- Automata Mealy Machine
- Moore vs Mealy Machines
- Moore to Mealy Machine
- Mealy to Moore Machine
- Myhill–Nerode Theorem
- Mealy Machine for 1’s Complement
- Finite Automata Exercises
- Complement of DFA
- Regular Expressions
- Regular Expression in Automata
- Regular Expression Identities
- Applications of Regular Expression
- Regular Expressions vs Regular Grammar
- Kleene Closure in Automata
- Arden’s Theorem in Automata
- Convert Regular Expression to Finite Automata
- Conversion of Regular Expression to DFA
- Equivalence of Two Finite Automata
- Equivalence of Two Regular Expressions
- Convert Regular Expression to Regular Grammar
- Convert Regular Grammar to Finite Automata
- Pumping Lemma in Theory of Computation
- Pumping Lemma for Regular Grammar
- Pumping Lemma for Regular Expression
- Pumping Lemma for Regular Languages
- Applications of Pumping Lemma
- Closure Properties of Regular Set
- Closure Properties of Regular Language
- Decision Problems for Regular Languages
- Decision Problems for Automata and Grammars
- Conversion of Epsilon-NFA to DFA
- Regular Sets in Theory of Computation
- Context-Free Grammars
- Context-Free Grammars (CFG)
- Derivation Tree
- Parse Tree
- Ambiguity in Context-Free Grammar
- CFG vs Regular Grammar
- Applications of Context-Free Grammar
- Left Recursion and Left Factoring
- Closure Properties of Context Free Languages
- Simplifying Context Free Grammars
- Removal of Useless Symbols in CFG
- Removal Unit Production in CFG
- Removal of Null Productions in CFG
- Linear Grammar
- Chomsky Normal Form (CNF)
- Greibach Normal Form (GNF)
- Pumping Lemma for Context-Free Grammars
- Decision Problems of CFG
- Pushdown Automata
- Pushdown Automata (PDA)
- Pushdown Automata Acceptance
- Deterministic Pushdown Automata
- Non-deterministic Pushdown Automata
- Construction of PDA from CFG
- CFG Equivalent to PDA Conversion
- Pushdown Automata Graphical Notation
- Pushdown Automata and Parsing
- Two-stack Pushdown Automata
- Turing Machines
- Basics of Turing Machine (TM)
- Representation of Turing Machine
- Examples of Turing Machine
- Turing Machine Accepted Languages
- Variations of Turing Machine
- Multi-tape Turing Machine
- Multi-head Turing Machine
- Multitrack Turing Machine
- Non-Deterministic Turing Machine
- Semi-Infinite Tape Turing Machine
- K-dimensional Turing Machine
- Enumerator Turing Machine
- Universal Turing Machine
- Restricted Turing Machine
- Convert Regular Expression to Turing Machine
- Two-stack PDA and Turing Machine
- Turing Machine as Integer Function
- Post–Turing Machine
- Turing Machine for Addition
- Turing Machine for Copying Data
- Turing Machine as Comparator
- Turing Machine for Multiplication
- Turing Machine for Subtraction
- Modifications to Standard Turing Machine
- Linear-Bounded Automata (LBA)
- Church's Thesis for Turing Machine
- Recursively Enumerable Language
- Computability & Undecidability
- Turing Language Decidability
- Undecidable Languages
- Turing Machine and Grammar
- Kuroda Normal Form
- Converting Grammar to Kuroda Normal Form
- Decidability
- Undecidability
- Reducibility
- Halting Problem
- Turing Machine Halting Problem
- Rice's Theorem in Theory of Computation
- Post’s Correspondence Problem (PCP)
- Types of Functions
- Recursive Functions
- Injective Functions
- Surjective Function
- Bijective Function
- Partial Recursive Function
- Total Recursive Function
- Primitive Recursive Function
- μ Recursive Function
- Ackermann’s Function
- Russell’s Paradox
- Gödel Numbering
- Recursive Enumerations
- Kleene's Theorem
- Kleene's Recursion Theorem
- Advanced Concepts
- Matrix Grammars
- Probabilistic Finite Automata
- Cellular Automata
- Reduction of CFG
- Reduction Theorem
- Regular expression to ∈-NFA
- Quotient Operation
- Parikh’s Theorem
- Ladner’s Theorem
CFG Equivalent to PDA Conversion
In automata theory and context-free grammars, the relationship between Pushdown Automata (PDA) and Context-Free Grammars (CFG) is fundamental.
Here in this chapter, we will explain how to construct a CFG that is equivalent to a given PDA. In other words, we will explain how to convert PDA to CFG. We will see the definitions and the corresponding examples to understand the process in a better way.
Relation Between PDA and CFG
A Pushdown Automaton (PDA) is a type of automaton that uses a stack to manage additional information. Using memory as stack makes it more powerful than a finite automaton.
Pushdown automata can recognize context-free languages, which are languages generated by Context-Free Grammars (CFGs).
A Context-free Grammar consists of:
- A set of variables or non-terminal symbols.
- A set of terminal symbols.
- A start symbol.
- A set of production rules that define how terminals and non-terminals can be combined.
The goal here is to construct a CFG equivalent to a PDA, which means the CFG generates the same language that the PDA recognizes.
Conversion of PDA to CFG
To convert a PDA into an equivalent CFG, we assume the PDA M = (Q, , , , q0, z0, F) accepts a language L by an empty stack.
The CFG G = (VN, , P, S) is constructed following specific rules that ensure it generates the same language as the PDA.
Let us see the steps one by one to convert PDA to CFG.
Start Symbol Production
For every state qi in the PDA, we add a production rule to the CFG:
$$\mathrm{S \: \rightarrow \:[q_0, \:z_0,\:q_i]}$$
If the PDA has n states, there will be n productions originating from the start symbol S.
Handling Transitions with Empty Stack Operation
For each transition function of the form (q, a, Y) → (r, ), where (q, r) ∈ Q, a ∈ , and Y ∈ , a production rule is added to the CFG as follows −
$$\mathrm{[qYr] \: \rightarrow \: a}$$
This rule handles cases where the PDA reads a symbol and pops the stack without pushing anything.
Handling Transitions with Stack Operations
For transition functions of the form (q, a, Y) → (r, Y_1, Y_2, , Y_k), a production rule is added for each combination of intermediate states q1,q2, ... ,qk as:
$$\mathrm{[qYq_k ] \: \rightarrow \:a [rY_1 q_1 ] [q_1 Y_2 q_2 ] \: \dotso \: [q_{k - 1} Y_k q_k]}$$
This rule addresses scenarios where the PDA pushes multiple symbols onto the stack in response to an input symbol.
Transition Table
The transition table with regards to converting CFG to PDA is as follows −
Sr | State | Unread Input | Stack | Transition |
---|---|---|---|---|
1 | q0 | abbccbba | 1 | |
2 | q0 | abbcbba | S | 1 |
3 | q0 | abbcbba | aSa | 2 |
4 | q1 | bbcbba | Sa | 5 |
5 | q0 | bbcbba | bSba | 3 |
6 | q2 | bcbba | Sba | 6 |
7 | q0 | bcbba | bsbba | 3 |
8 | q2 | cbba | Sbba | 6 |
9 | q0 | cbba | cbba | 4 |
10 | q3 | bba | bba | 7 |
11 | q2 | ba | ba | 6 |
12 | q1 | 5 |
Example 1: Constructing a CFG from PDA
Lets apply these steps to an example to make the conversion process clearer.
Given PDA,
$$\mathrm{\delta(q_0,\: a,\: z_0 ) \: \rightarrow \: (q_0,\: z_1\: z_0 )}$$
$$\mathrm{\delta(q_0,\: a,\: z_1 ) \: \rightarrow \: (q_0,\: z_1\: z_1)}$$
$$\mathrm{\delta(q_0,\: b,\: z_1 ) \: \rightarrow \: (q_1,\: \lambda)}$$
$$\mathrm{\delta(q_1,\: b,\: z_1 ) \: \rightarrow \: (q_1,\: \lambda)}$$
$$\mathrm{\delta(q_1,\: b,\: z_0 ) \: \rightarrow \: (q_1,\: z_2\: z_0)}$$
$$\mathrm{\delta(q_1,\: c,\: z_2 ) \: \rightarrow \: (q_2,\: \lambda)}$$
$$\mathrm{\delta(q_2,\: \lambda,\: z_0 ) \: \rightarrow \: (q_2,\: \lambda)}$$
This PDA has three states: q0, q1, and q2.
Step 1: Start Symbol Production
The following productions are added −
$$\mathrm{S \:\rightarrow\:[q_0 \:z_0\: q_0 ] \: /\: [q_0\: z_0\: q_1 ]\: / \:[q_0\: z_0\: q_2 ]}$$
Step 2: Transitions with Empty Stack
The transitions δ(q0, b, z1) → (q1, λ), δ(q1, b, z1) → (q1, λ), and δ(q1, c, z2) → (q2, λ) lead to the following productions:
$$\mathrm{[q_0 \: z_0 \: q_1 ] \: \rightarrow \: b}$$
$$\mathrm{[q_1 \: z_1 \: q_1 ] \: \rightarrow \: b}$$
$$\mathrm{[q_1 \: z_2 \: q_2 ] \: \rightarrow \: c}$$
$$\mathrm{[q_2 \: z_2 \: q_2 ] \: \rightarrow \: c}$$
$$\mathrm{[q_2 \: z_0 \: q_2 ] \: \rightarrow \: \epsilon}$$
Step 3: Transitions with Stack Operations
For the transition (q0, a, z0) → (q0,z1, z0), the following productions are added −
$$\mathrm{[q_0 \: z_0 \: q_0] \: \rightarrow \: a [q_0 \: z_1 \: q_0] \: [q_0 \: z_0 \: q_0]}$$
$$\mathrm{[q_0 \: z_0 \: q_0] \: \rightarrow \: a [q_0 \: z_1 \: q_0] \: [q_1 \: z_0 \: q_0]}$$
$$\mathrm{[q_0 \: z_0 \: q_1] \: \rightarrow \: a [q_0 \: z_1 \: q_0] \: [q_0 \: z_0 \: q_1]}$$
$$\mathrm{[q_0 \: z_0 \: q_1] \: \rightarrow \: a [q_0 \: z_1 \: q_1] \: [q_1 \: z_0 \: q_1]}$$
$$\mathrm{[q_0 \: z_0 \: q_2] \: \rightarrow \: a [q_0 \: z_1 \: q_0] \: [q_0 \: z_0 \: q_2]}$$
$$\mathrm{[q_0 \: z_0 \: q_2] \: \rightarrow \: a [q_0 \: z_1 \: q_1] \: [q_1 \: z_0 \: q_2]}$$
The CFG that generates the same language as the PDA is a collection of all these production rules.
Example 2: Another PDA to CFG Conversion
Let's consider another example for further clarity.
Given PDA:
$$\mathrm{\delta(q_0, \: a, \: z_0 ) \: \rightarrow \: (q_1, \: z_1 \: z_0)}$$
$$\mathrm{\delta(q_0, \: b, \: z_0 ) \: \rightarrow \: (q_1, \: z_2 \: z_0)}$$
$$\mathrm{\delta(q_1, \: a, \: z_1 ) \: \rightarrow \: (q_1, \: z_1 \: z_1)}$$
$$\mathrm{\delta(q_1, \: b, \: z_1 ) \: \rightarrow \: (q_1, \: \lambda)}$$
$$\mathrm{\delta(q_1, \: b, \: z_2 ) \: \rightarrow \: (q_1, \: z_2 \: z_2)}$$
$$\mathrm{\delta(q_1, \: \lambda, \: z_0 ) \: \rightarrow \: (q_1, \: \lambda)}$$
The start symbol production is:
$$\mathrm{S \: \rightarrow \: [q_0 \: z_0 \: q_0] \: / \: [q_0 \: z_0 \: q_1]}$$
Transitions with Empty Stack
The relevant transitions provide −
$$\mathrm{[q_1 \: z_1 \: q_1] \: \rightarrow \: b}$$
$$\mathrm{[q_1 \: z_2 \: q_1] \: \rightarrow \: a}$$
$$\mathrm{[q_1 \: z_0 \: q_1] \: \rightarrow \: \epsilon}$$
Transitions with Stack Operations
Transitions such as δ(q0, a, z0) → (q1, z1 z0) result in:
$$\mathrm{[q_0 \: z_0 \: q_0] \: \rightarrow \: a[q_1 \: z_1 \: q_0] \: [q_0 \: z_0 \: q_0]}$$
$$\mathrm{[q_0 \: z_0 \: q_1] \: \rightarrow \: a[q_1 \: z_1 \: q_0] \: [q_0 \: z_0 \: q_1]}$$
$$\mathrm{[q_0 \: z_0 \: q_1] \: \rightarrow \: a[q_1 \: z_2 \: q_0] \: [q_0 \: z_0 \: q_1]}$$
In this second example too, we used the same methodology for converting PDAs into CFGs.
Conclusion
The construction of a CFG equivalent to a PDA is a systematic process that involves start symbol production, handling transitions with empty stack operations, and stack operations. In this chapter, we explained the concept through examples and understood how CFG generates the same language recognized by the PDA.