Regular Grammar (Model Regular Grammars)
Last Updated : 30 May, 2025
Regular grammar is a formal grammar used to describe regular languages, which are the languages that can be recognized by finite automata. It serves as one of the simplest and most fundamental models in the Chomsky hierarchy of grammars. Regular grammars are widely used in computer science for lexical analysis, pattern matching, and text processing due to their efficiency and straightforward structure.
There are two standard forms of regular grammar:
- Right-Linear Grammar
- Left-Linear Grammar
In both cases, the production rules follow strict formats that ensure the language remains regular.
Right Linear Grammar
Right Linear Grammars are special type of CFGs, where each production rule has at most 1 variable on RHS & that variable is on right most position.
A ⇢ xB
A ⇢ x
where A,B ∈ V and x ∈ T*
Example 1: S -> aA | B
A -> aaB
B -> bB | a
Grammar G is right-linear
Example 2: FA for accepting strings that start with b
Finite Automata∑ = {a, b}
Initial state(q0) = A
Final state(F) = B
The RLG corresponding to FA is
A ⇢ bB
B ⇢ ∈/aB/bB
The above grammar is RLG, which can be written directly through FA.
Parse TreeThe above RLG can derive strings that start with b and after that any input symbol (i.e. ∑ ={a, b} can be accepted).
The regular language corresponding to RLG is
L= {b, ba, bb, baa, bab, bba, bbb, ... }
If we reverse the above production of the above RLG, then we get
A ⇢ Bb
B ⇢ ∈/Ba/Bb
It derives the language that contains all the strings which end with b.
i.e. L' = {b, bb, ab, aab, bab, abb, bbb, ...}
So we can conclude that if we have Finite Automata that represents language L and if we convert it, into RLG, which again represents language L, but after reversing RLG we get LLG which represents language L'(i.e. reverse of L).
Conversion of RLG to LLG
RLG to LLGFor converting the RLG into LLG for language L, the following procedure needs to be followed:
Step 1: Reverse the FA for language L
Step 2: Write the RLG for it.
Step 3: Reverse the right linear grammar.
after this we get the grammar that generates the language that represents the LLG for the same language L.
Conversion of Right Linear Grammar (RLG) to Finite Automaton (FA)
To convert a Right Linear Grammar (RLG) into its equivalent Finite Automaton (FA), follow the steps below:
LLG to FASteps for Conversion
1.Start from the first production rule: Identify the start symbol (non-terminal) of the grammar. This becomes the start state of the FA.
2. For each production rule, create transitions based on the structure:
- If the production is of the form A → aB, draw a transition from state A to state B on input symbol a.
- If the production is of the form A → a (i.e., no non-terminal follows the terminal), create a transition from state A to a final state on symbol a.
3. Define the final state(s): Any state that appears in a rule of the form A → a or A → ε (i.e., ends with a terminal or empty string) becomes a final state in the FA.
Left Linear Grammar
Left Linear Grammars are Special type of CFGs, where Each Production Rule has At Most 1 Variable on RHS & that variable is on Left Most position.
A ⇢ Bx
A ⇢ x
where A,B ∈ V and x ∈ T*
Example: A -> Da | Bc | b
B -> Bf | Ca | a
C -> Ca | D
D -> 𝛆
Conversion of LLG to FA
1. Convert the LLG to a Right Linear Grammar (RLG): Do this by reversing the strings in the productions (represents the reversed language L^R).
2. Build an FA for the reversed language (L^R): Use the standard method: non-terminals become states, and transitions are based on the productions.
3. Reverse the FA:
- Reverse all transitions.
- Make final states into start states and the original start state into the final state.
The resulting FA accepts the original language L.
For example, the above grammar is taken which represents language L(i.e. set of all strings that start with b)
The LLG for this grammar is
B ⇢ Ba/Bb/Ab
A ⇢ ∈
Step 1: Convert the LLG into FA (i.e. the conversion procedure is the same as above)

Step 2: Reverse the FA(i.e. initial state is converted into final state and convert final state to initial state and reverse all edges)

Step 3: Write RLG corresponding to reversed FA.
A ⇢ bB
B ⇢ aB/bB/∈

Read more about Right and Left Linear Grammar
Type-3 grammar/regular grammar
- Every Right Linear Grammar is a type of Regular Grammar.
- Every Left Linear Grammar is also a type of Regular Grammar.
Important Note: All production rules in a regular grammar must follow either right-linear or left-linear form consistently. You cannot mix left-linear and right-linear rules in the same grammar.
The productions must be in the form:
A ⇢ xB A ⇢ xA ⇢ Bx
where A, B ∈ Variable(V) and x ∈ T* i.e. string of terminals.
Similar Reads
Regular grammar (Model regular grammars ) Regular grammar is a formal grammar used to describe regular languages, which are the languages that can be recognized by finite automata. It serves as one of the simplest and most fundamental models in the Chomsky hierarchy of grammars. Regular grammars are widely used in computer science for lexic
4 min read
Regular Expressions, Regular Grammar and Regular Languages To work with formal languages and string patterns, it is essential to understand regular expressions, regular grammar, and regular languages. These concepts form the foundation of automata theory, compiler design, and text processing.Regular ExpressionsRegular expressions are symbolic notations used
7 min read
Right and Left linear Regular Grammars Regular Grammar is a type of grammar that describes a regular language. It is a set of rules used to describe very simple types of languages called regular languages that can be processed by computers easily, especially with finite automata. A regular grammar is a mathematical object, G, which consi
3 min read
Parsing ambiguous grammars using LR parser LR parser can be used to parse ambiguous grammars. LR parser resolves the conflicts (shift/reduce or reduce/reduce) in parsing table of ambiguous grammars based on certain rules (precedence and/or associativity of operators) of the grammar. Example: Lets take the following ambiguous grammar: E ->
3 min read
Star Height of Regular Expression and Regular Language The star height relates to the field of theoretical computation (TOC). It is used to indicate the structural complexity of regular expressions and regular languages. In this context, complexity refers to the maximum nesting depth of Kleene stars present in a regular expression.A regular language may
3 min read
Removing Direct and Indirect Left Recursion in a Grammar Left Recursion is a common problem that occurs in grammar during parsing in the syntax analysis part of compilation. It is important to remove left recursion from grammar because it can create an infinite loop, leading to errors and a significant decrease in performance. We will discuss how to remov
11 min read