Left Linear and Right Linear Grammars and Conversions
Left-Linear Grammar (LLG)
-
In a left-linear grammar, every production rule has the nonterminal on the left side of the string.
-
The general forms are:
where:
-
= nonterminals
-
= terminal string (possibly empty)
Example:
This grammar generates "ab"
.
Right-Linear Grammar (RLG)
-
In a right-linear grammar, every production rule has the nonterminal on the right side of the string.
-
The general forms are:
where:
-
= nonterminals
-
= terminal string (possibly empty)
Example:
This grammar also generates "ab"
.
Difference Between Left-Linear and Right-Linear
-
Right-linear grammars generate strings by expanding towards the right.
-
Left-linear grammars generate strings by expanding towards the left.
-
Both describe exactly the class of regular languages ✅.
🔹 Converting Between Them
Suppose we have a right-linear grammar:
Step 1: Recognize that it generates "ab"
.
Step 2: To convert to left-linear, we "mirror" the structure:
Step 3: Both grammars generate the same language, but derivations work in different directions.
🔹 General Conversion (Idea)
👉 To convert Right-Linear → Left-Linear (or vice versa):
-
Take the finite automaton (FA) corresponding to the grammar.
(Since every regular grammar corresponds to an FA.) -
Reverse the FA transitions.
-
Construct the grammar again, but now in the other form (LLG or RLG).
This works because reversing a regular grammar gives the mirror language, and both left- and right-linear grammars describe regular languages.
✅ Key Point for Students:
-
Right-linear grammars are easier to read left to right.
-
Left-linear grammars are easier to read right to left.
-
But both describe regular languages, and we can always convert by going through a finite automaton representation.
Comments
Post a Comment