
- 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
Removal of Useless Symbols in CFG
Context-free Grammars are crucial in many applications including compiler design. In defining the syntax of programming languages and other structured data using CFGs, it's often important to simplify them without altering the language they generate.
In this chapter, we will see the process of removing useless productions from a CFG and their importance in details.
What are Useless Productions?
A production in a CFG is can be termed as "useless" if it doesn't contribute to the derivation of any terminal string in the language. These productions can be seen as unwanted that complicates the grammar without adding any generative power. Our goal is to identify and eliminate these useless productions.
Two Key Principles: Derivability and Reachability
The process of removing useless productions relies on two fundamental principles −
- Derivability − This idea focuses on whether a variable within the grammar can actually derive a terminal string. If a variable cannot produce a string composed solely of terminals, it's considered non-deriving and thus, useless.
- Reachability − This idea checks whether a variable can be reached from the start variable of the grammar. If a variable is unreachable from the start variable, it implies that it can never participate in the derivation process and it is useless.
Steps to Remove Useless Productions
Let us see the steps for removing useless productions. Let's break down the process of removing useless productions into a series of clear steps −
Step 1: Identifying Useful Symbols
Terminals − As we know, terminals are the end symbols. The set of terminal symbols in the grammar forms the foundation of our useful symbols. This is because terminals are the building blocks of the strings generated by the grammar.
Deriving Variables − For each terminal symbol, identify the variables that directly derive them. These variables are also considered useful because they contribute to generating terminal strings.
Iteratively Expand the Set − Now continue examining the right-hand sides of productions for the newly identified useful variables. If a production contains a combination of terminals and/or already marked useful variables, the variable on the left-hand side is also useful.
Identify Useless Symbols − Any variable not marked as useful after this iterative process is considered useless.
Step 2: Eliminating Productions with Useless Symbols
Right-Hand Side Scan − Check the right-hand side of each production. If any useless symbol (terminal or variable) appears in the production, the entire production is useless and should be removed.
Step 3: Ensuring Reachability from the Start Variable
Trace from the Start − Starting from the start variable, follow the derivation paths allowed by the remaining productions. Any variable that cannot be reached through these derivations is considered unreachable.
Remove Unreachable Productions − Eliminate any productions containing unreachable variables on either the left-hand side or right-hand side.
Example of Removing Useless Symbols in CFG
Now, we will see the idea through a real example, let's consider a CFG with the following productions −
$$\mathrm{S\:\rightarrow\: aA \:|\: BC}$$
$$\mathrm{A\:\rightarrow\: b \:|\: bB}$$
$$\mathrm{B\:\rightarrow\: aB \:|\: \varepsilon}$$
$$\mathrm{C\:\rightarrow\: aC \:|\: D}$$
$$\mathrm{D\:\rightarrow\: bD}$$
Let's apply the steps to remove useless productions.
Step 1: Identify Useful Symbols
- Terminals − {a, b}
- Deriving Variables − 'A' derives 'b', 'B' derives 'ε' (which eventually leads to a string of terminals), 'C' derives 'a'. So, {A, B, C} are also useful.
- Iterative Expansion − 'S' derives 'aA' (combination of useful symbols). Therefore, {S} is useful.
Step 2: Eliminate Productions with Useless Symbols
Useless Symbols − {D}
We eliminate the following productions containing 'D' −
$$\mathrm{C \: \rightarrow \: D}$$
$$\mathrm{D \: \rightarrow \: bD}$$
The grammar now becomes −
$$\mathrm{S \: \rightarrow \: aA \: |\: BC}$$
$$\mathrm{A \: \rightarrow \: b \: |\: bB}$$
$$\mathrm{B \: \rightarrow \: aB \: |\: \varepsilon}$$
$$\mathrm{C \: \rightarrow \: aC}$$
Step 3: Ensure Reachability
Reachable − From 'S', we can reach 'A' and 'B'. From 'A' we can reach 'B'. From 'C' we cannot reach any other variable.
Unreachable − 'C' is unreachable from the start variable 'S'.
Removing Unreachable Productions −
$$\mathrm{S \: \rightarrow \: BC}$$
$$\mathrm{C \: \rightarrow \: aC}$$
The final simplified grammar becomes −
$$\mathrm{S \: \rightarrow \: aA}$$
$$\mathrm{A \: \rightarrow \: b \: |\: bB}$$
$$\mathrm{B \: \rightarrow \: aB \: |\: \varepsilon}$$
Conclusion
Removing useless productions is a crucial step while making our context free grammar simple. By using such principles like derivability and reachability, we can systematically identify and eliminate productions that don't contribute to the language generated by the grammar.