Open In App

Right and Left linear Regular Grammars

Last Updated : 23 Jul, 2025
Comments
Improve
Suggest changes
13 Likes
Like
Report

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 consists of four components, G = (N, ∑, P, S), where 

  • N: non-empty, finite set of non-terminal symbols.
  • : a finite set of terminal symbols, or alphabet, symbols.
  • P: a set of grammar rules, each of one having one of the forms.
    • A ⇢ aB
    • A⇢ a
    • A ⇢∈
    • Here ∈=empty string, A, B ∈ N, a ∈ ∑
  • S ∈ N is the start symbol.

Uses Of Regular Grammar

  • Lexical analyzers in compilers
  • Text searching
  • Pattern matching (like regex)
  • Finite state machines in digital design

This Regular grammar can be of two forms:

  • Right Linear Regular Grammar
  • Left Linear Regular Grammar

Right Linear Regular Grammar

In this type of regular grammar, all the non-terminals on the right-hand side exist at the rightmost place, or at the right ends.

Examples :

A ⇢ a, A ⇢ aB, A ⇢ ∈
where,
A and B are non-terminals,
a is terminal, and
∈ is empty string

S ⇢ 00B | 11S
B ⇢ 0B | 1B | 0 | 1
where,
S and B are non-terminals, and
0 and 1 are terminals

Left Linear Regular Grammar

In this type of regular grammar, all the non-terminals on the left-hand side exist at the leftmost place, or at the left ends.

Examples :

A ⇢ a, A ⇢ Ba, A ⇢ ∈
where,
A and B are non-terminals,
a is terminal, and
∈ is empty string

S ⇢ B00 | S11
B ⇢ B0 | B1 | 0 | 1
where
S and B are non-terminals, and
0 and 1 are terminals

Left linear to Right Linear Regular Grammar

In this type of conversion, we have to shift all the left-handed non-terminals to right as shown in example given below:

Left linear Right linear On putting the value of B on A and we get , Right
1. A ⇢ Ba 3. A ⇢ abaB Linear Grammar
B ⇢ ab B ⇢ ε

2. A ⇢ abB
B ⇢ a

So, this can be done to give multiple answers. Example explained above have multiple answers other than the given once.

Right linear to Left Linear Regular Grammar

In this type of conversion, we have to shift all the right-handed non-terminals to left as shown in example given below:

Right linear Left linear On putting the value of B on A ,we get Left
1. A ⇢ aB 3. A ⇢ Baab Linear Grammar
B ⇢ ab B ⇢ ε

2. A ⇢ Bab
B ⇢ a

 So, this can be done to give multiple answers. Example explained above have multiple answers other than the given.


Article Tags :

Explore