Beruflich Dokumente
Kultur Dokumente
REGULAR GRAMMER
Regular Grammar
The concept of regular grammar is already introduced in chapter 5. Here we will study the
equivalence and conversion of regular grammar with respect to Finite Automata.
Regular grammar is a one of the types of Chomsky hierarchy which is used to represent regular
language. There are certain restrictions on productions of regular grammar, such as:
The left hand side of production should contain exactly one non terminal.
The right hand side of production can contain at most one non terminal and that
can appear as either leftmost or rightmost symbol.
Based on the position of non terminal on right hand side of the production, the regular grammar
is classified as
1. Left-Linear Grammar (GL)
2. Right-Linear Grammar (GR).
If the non terminal is a leftmost symbol on the right hand side of production then the
grammar is called as Left-Linear Grammar.
The production S is allowed only for start symbol S and does not appear on right hand
side of any production.
The production S is allowed only for start symbol S and does not appear on right hand
side of any production.
Solution:
Step1 : Draw Transition Graph
Draw the transition diagram for the given grammar as shown below.
Step 2: Exchange position of initial state and final state.
Example
Find equivalent DFA accepting the regular language defined by RLG given as
S0A|1B
A0C|1A|0
B1B|1A|1
C0|0A
Solution-
Let [S] is initial state and [] is a final state.
As S0A and S1B, add -transitions from state S to state 0A and from state S to 1B.
Similarly we add remaining -transitions like:
from state A to state [0C]
from state A to state [1A]
from state B to state [1B]
from state B to state [1A]
from state C to state [0A]
from state A to state [0]
from state B to state [1]
from state C to state [0]
[0A] is in the form of [a] so add transition from [0A] to A on symbol 0. Similarly we add
remaining transitions like
from state [0C] to state [C] on symbol 0
from state [1A] to state [A] on symbol 1
from state [1B] to state [B] on symbol 1
from state [0A] to state [A] on symbol 0
Thus the transition diagram for above NFA is
Figure- DFA
The final DFA is
Figure- DFA with relabeling
0 1
Q
A B D
B C B
*C E --
D -- F
*E C B
*F C F
Example 2
Construct DFA for given RLG
SbB
BbC|aB|b
Ca
Solution-
The NFA with -moves is as follows
Figure- NFA with -moves
for every production add -transition and by applying rule obtain above NFA with -moves. The
DFA can be constructed as follows:
New Name x y=-closure of x (y,a) (y,b)
A S S, bB -- B
B B B, bC, aB, b B C,
C C C, , a --
D -- --
Example
Construct DFA from given Left Linear Grammar
SS10|0
Solution-
Reverse the right hand side of all productions to obtain right linear grammar as
S01S|0
Construct NFA with -moves from above right linear grammar
A B --
*B -- C
C D --
*D -- C
0 1
Q
A B --
*B -- C
C B --
Example
Construct DFA from given Left Linear Grammar
SCa|Bb
CBa
BBa|b
Solution-
The Right Linear Grammar from grammar by reversing right side is
SaC|bB
CaB
BaB|b