Left Linear Grammar
This is a bit of a detour. Previously, we defined regular grammar as,
Let's consider another kind of grammar,
Because the target has non-terminal on the left side, this grammar is called the left linear grammar. The regular grammar is sometimes called the right linear grammar.
In this section, we need to prove that left linear grammar can yield regular languages.
Proof by automaton
The first proof is done by constructing an FN that tests the language of the left linear grammar. And because FN recognizes regular language, we can prove that left linear grammar generates regular language if there exists such FN.
The construction is done backwards. Let's first define the starting state, .
For all,
We create state if there exists none. Then create an edge from to (please note that this is in a different direction).
Then, for,
We create an edge with label from to .
After the construction, we mark as the accept state.
This automaton will accept the language of the left linear grammar. And because FN yields regular language, the left linear grammar yields regular language.
Why this automaton accepts the language from left linear grammar? For right linear grammar, it is done by derivation- that every transition in the automaton means a derivation. For left linear grammar, it is done by induction.
If,
We say,
This operation from to is called induction.
If a sentence can be inducted to , then it is a sentence in the language.
Let's consider a induction sequence,
For a induction,
It can be mapped to the transition,
Because we mapped into accept state, we can prove that the automaton accepts all sentences generated by the left linear grammar.
Proof by Regularity Preservation under Reverse
Another approach to prove that left linear grammars generate regular languages is by transforming them into right linear grammars through a reversal process. Here's how the construction works:
-
Reverse Productions: For each production in the left linear grammar , reverse the order of symbols on the right-hand side. Specifically:
- A production of the form becomes .
- A production of the form remains .
-
Construct Right Linear Grammar: The resulting grammar from the previous step is a right linear grammar because all productions now conform to the right linear form (non-terminal on the right end, if present).
-
Language Relationship: The language generated by , denoted , is the reversal of the language generated by . That is, .
-
Regularity Preservation: Since is a right linear grammar, is a regular language. Regular languages are closed under reversal, meaning that if is regular, then (being the reversal of ) is also regular.
To prove that regular languages are closed under reversal, we can use the properties of regular expressions and structural induction. Here's the proof:
-
Regular Languages and Regular Expressions:
Every regular language can be represented by a regular expression . -
Reversal of Regular Expressions:
We define the reversal of a regular expression , denoted , recursively as follows:- Base cases:
- (reversal of the empty string is itself).
- for (reversal of a single symbol is itself).
- (reversal of the empty language is itself).
- Inductive cases:
- Union: .
- Concatenation: (reversing the order of concatenation).
- Kleene star: .
- Base cases:
-
Reversal Preserves Regularity:
By structural induction on :- Base cases: , , and are regular expressions, and their reversals are trivially regular.
- Union: If and are regular, then is regular (union of regular languages is regular).
- Concatenation: If and are regular, then is regular (concatenation of regular languages is regular).
- Kleene star: If is regular, then is regular (Kleene star of a regular language is regular).
-
Conclusion:
The reversal of a regular expression is also a regular expression. Therefore, the language is regular.
Hence, regular languages are closed under reversal.
In all, we can prove that left linear grammar is equivalent to right linear grammar, thus generates regular language.