Regular Grammers
Regular Grammar
Formally, a grammar is regular if all productions in are of one of the following forms:
-
Right-linear form:
where , .
-
Left-linear form:
Note: A grammar must be entirely right-linear or left-linear to be regular. Mixing both may lead to a CFG that is not regular.
Intuition
-
Regular grammars correspond to finite automata (DFA/NFA).
-
Productions represent transitions:
-
means “on reading , go from state to state .”
-
means “on reading , finish (accept).”
-
means “accept without consuming input.”
-
So:
-
Right-linear → strings “grow” to the right.
-
Left-linear → strings “grow” to the left.
Examples of Regular Grammars
Strings ending with ab
Language:
Right-linear Grammar:
Derivation:
-
For
aab
:
Language (zero or more a’s)
-
Generates ε, a, aa, aaa, …
Language
-
Generates ε, ab, abab, ababab, …
Left-linear version of
-
Generates ε, a, aa, aaa, …
-
This is left-linear instead of right-linear.
Relation to Finite Automata
Every regular grammar corresponds to a finite automaton, and vice versa:
-
↔ transition from state A to state B on input a.
-
↔ transition to a final state.
-
↔ nonterminal A is a final state.
Example:
Grammar:
Generates all strings ending in a
.
Equivalent NFA:
-
States: {S,F}
-
Transitions: S —a→ S, S —b→ S
-
Accept: final state F after reading
a
.

Key Properties of Regular Grammars
-
Generate only regular languages.
-
Strictly less powerful than context-free grammars.
-
Ambiguity is usually not an issue, because regular grammars are very restrictive.
-
Always convertible to finite automata or regular expressions.
Comments
Post a Comment