Hello! Welcome back to our course on the Theory of Computation.
In our last lesson, we saw how any Context-Free Grammar (CFG) can be standardized into Chomsky Normal Form. This highlighted how we can impose a strict structure on grammars for easier algorithmic processing.
Today, we'll connect the world of grammars back to the world of automata that we started with. We will explore a special, restricted subclass of CFGs known as regular grammars. Our goal is to formally define regular grammars and prove their equivalence to finite automata. By doing so, we will establish the third major formalism for describing regular languages, alongside finite automata and regular expressions, completing a foundational picture of this language class.
1. Defining Regular Grammars
We've seen that CFGs can have production rules of the form A → γ, where γ is any string of variables and terminals. Regular grammars are much more restrictive. Their structure is designed to mirror the step-by-step computation of a finite automaton.
A grammar is considered regular if all of its production rules conform to one of two types: either it is entirely right-linear or entirely left-linear.
CSci 311, Models of Computation, Chapter 3 Regular ...
To understand the formal definitions, please read the following section from the 'Models of Computation' notes by John C. Morris.
Read the section '3.3 Regular Grammars' up to, but not including, '3.3.3 Right-Linear Grammars Generate Regular Languages'. Pay close attention to the definitions of right-linear and left-linear grammars, and note the example of a linear grammar that is not regular.
As you've just read, the definitions are:
- Right-Linear Grammar: All productions are of the form
A → aBorA → a, whereAandBare variables andais a terminal. - Left-Linear Grammar: All productions are of the form
A → BaorA → a.
The key constraint is that a regular grammar must be one or the other, not a mixture.
Notice the structure of a right-linear rule like A → aB. You can think of this as a computational instruction: "From state A, read the terminal a and transition to state B." Similarly, A → a corresponds to: "From state A, read a and transition to a final (accepting) state." This direct correspondence is the key to proving their equivalence with finite automata.
2. Proof of Equivalence, Part 1: Regular Grammar → NFA
To prove that regular grammars and finite automata are equivalent, we must show we can convert from one to the other. Let's start by constructing a Nondeterministic Finite Automaton (NFA) from a given right-linear grammar.
Theorem: For any right-linear grammar G, there exists an NFA M such that L(G) = L(M).
The construction is a direct mapping of grammar components to automaton components:
- States (
Q): The states of the NFA are the variables of the grammar, plus one new, dedicated final state (let's call itQ_f). - Input Alphabet (
Σ): The terminals of the grammar. - Start State (
q_0): The start symbol of the grammar. - Final States (
F): The set containing only our new state,F = {Q_f}. If the grammar generatesε(i.e.,S → ε), the start stateSis also a final state. - Transition Function (
δ):- For every production
A → aBin the grammar, we add a transitionδ(A, a) = B. - For every production
A → ain the grammar, we add a transition to our new final state:δ(A, a) = Q_f.
- For every production
The following video provides a clear walkthrough of this procedure with two examples.
Converting Regular Grammar to Finite Automata || Procedure || 2 Examples || Construction || TOC
This video will demonstrate the conversion of a regular grammar to a finite automaton. It clearly explains the procedure and the rationale for introducing a new final state.
Watch from 00:44 to 10:44. The first part (until 05:03) outlines the formal procedure. The second part demonstrates the construction with a detailed example. Pay attention to how productions of the form A → a are handled.
This constructive proof shows that any language generated by a right-linear grammar can be recognized by an NFA. Since NFAs recognize regular languages, all languages generated by right-linear grammars are regular.
3. Proof of Equivalence, Part 2: NFA → Regular Grammar
Now, let's prove the other direction: constructing a right-linear grammar from a given finite automaton.
Theorem: For any finite automaton M, there exists a right-linear grammar G such that L(M) = L(G).
This construction is the reverse of the previous one:
- Variables (
V): The states of the automaton. - Terminals (
T): The input alphabet of the automaton. - Start Symbol (
S): The start state of the automaton. - Productions (
P):- For every transition
δ(Q_i, a) = Q_j, we create a productionQ_i → aQ_j. - Crucially, if
Q_jis a final state, we add a second productionQ_i → a. This rule allows a derivation to terminate after entering a final state. - If the start state
Q_0is also a final state, we add the productionQ_0 → εto handle the empty string.
- For every transition
Let's see this in action.
Construction of Regular Grammar from Finite Automata || Theory of Computation || TOC || FLAT
The same instructor now demonstrates the reverse process: converting a finite automaton into a regular grammar. Notice the clever way final states are handled to create terminal-only productions.
Watch the two examples from 00:43 to 05:46. Focus on how a single transition can lead to two different production rules if the destination state is a final state.
Test your understanding!
Convert the following DFA into an equivalent right-linear grammar. The start state is q₀ and the final state is q₁.
A simple DFA to be converted into a regular grammar.
Show answer
We'll map the states q₀ and q₁ to variables Q₀ and Q₁, with Q₀ as the start symbol.
-
Transition
δ(q₀, a) = q₁:- This gives the production
Q₀ → aQ₁. - Since
q₁is a final state, we also addQ₀ → a.
- This gives the production
-
Transition
δ(q₀, b) = q₀:- This gives the production
Q₀ → bQ₀.
- This gives the production
-
Transition
δ(q₁, a) = q₀:- This gives the production
Q₁ → aQ₀.
- This gives the production
-
Transition
δ(q₁, b) = q₁:- This gives the production
Q₁ → bQ₁. - Since
q₁is a final state, we also addQ₁ → b.
- This gives the production
The complete grammar is:
Q₀ → aQ₁ | a | bQ₀Q₁ → aQ₀ | bQ₁ | b
4. The Complete Equivalence
We have now demonstrated through constructive algorithms that we can convert any right-linear grammar into an equivalent NFA, and any FA into an equivalent right-linear grammar. This completes the proof of their equivalence.
What about left-linear grammars? A similar proof exists (often by considering the reversal of the language), which shows they are also equivalent to finite automata. Therefore, both right-linear and left-linear grammars generate the class of regular languages.
This result solidifies a major concept in formal language theory. The class of regular languages can be characterized in three equivalent ways:
- Recognized by a Finite Automaton (DFA/NFA).
- Described by a Regular Expression.
- Generated by a Regular Grammar (Right-Linear or Left-Linear).
The following table from the Chomsky Hierarchy places this equivalence in a broader context, showing that Type-3 languages (Regular) are associated with both Regular Grammars and Finite State Machines.

CSci 311, Models of Computation, Chapter 3 Regular ...
For a formal statement of the equivalence theorems, you can review the summary section in the notes we looked at earlier.
Briefly review section '3.3.8 Equivalence Between Regular Languages and Regular Grammars'. This section contains Theorems 3.5 and 3.6, which formally state the equivalences we have discussed.
Conclusion
In this lesson, we have formally linked the generative power of grammars with the recognition power of automata at the regular language level. This is a significant milestone in our journey through the theory of computation.
Key Takeaways:
- Regular Grammars are a restricted form of CFGs that are either purely right-linear (
A → aBorA → a) or purely left-linear (A → BaorA → a). - The structure of a regular grammar production directly mirrors a state transition in a finite automaton.
- We can algorithmically convert between regular grammars and finite automata in both directions, proving their formal equivalence.
- This establishes regular grammars as the third major formalism for the class of regular languages.
Preview of the Next Lesson:
We have now thoroughly examined the regular languages and their formalisms. In the next module, we will climb one step up the Chomsky Hierarchy. We will finally introduce the abstract machine that corresponds to Context-Free Grammars: the Pushdown Automaton (PDA). Unlike finite automata, PDAs have a simple form of memory—a stack—which gives them significantly more computational power.