0% found this document useful (0 votes)
40 views9 pages

12-Regular Grammar and FA-01!02!2023

The document provides examples of constructing regular grammars from deterministic finite automata (DFAs) and constructing DFAs from regular grammars. It begins by defining the process for constructing a regular grammar G from a DFA M, which involves defining production rules based on the DFA's transitions. It then gives examples of applying this process to sample DFAs. The document later describes the inverse process of constructing a DFA from a regular grammar and provides examples of this as well.

Uploaded by

Devam Saini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views9 pages

12-Regular Grammar and FA-01!02!2023

The document provides examples of constructing regular grammars from deterministic finite automata (DFAs) and constructing DFAs from regular grammars. It begins by defining the process for constructing a regular grammar G from a DFA M, which involves defining production rules based on the DFA's transitions. It then gives examples of applying this process to sample DFAs. The document later describes the inverse process of constructing a DFA from a regular grammar and provides examples of this as well.

Uploaded by

Devam Saini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Module - 3

DFA to Regular Grammar


Dr. S K Somasundaram
Assistant Professor Senior Grade 2
School of Computer Science and Engineering,
Vellore Institute of Technology,
Vellore – 632014
Phone No: +91 9843665115
Mail ID: somasundaram.sk@vit.ac.in
Location: PRP Block – 218D
Constructing Regular Grammar from DFA
• M = (Q, ∑, Ꟙ, q0, f) • G = (Vn, ∑, P, S)
1. Vn = {A0, A1, A2, …}
2. ∑ → same for both M & G
3. Production rule
a) If Ꟙ(P, a)=Q ∉F, then P→aQ
b) If Ꟙ(P, a)=Q ∈F, then P→aQ and P→a
4. First production is Start Symbol, S
Example1
• Construct a Regular grammar for the following DFA
b a,b

a b b D
A B C

• Soln: Vn = {A, B ,C, D}


Q = {A, B ,C, D} T = {a, b}
∑ = {a, b} P:
A → aB | bA
q0 = {A} B → aA | bC
F = {D} C → aA |bD | b
D → aD | bD | a| b
S = {A}
Example 2
• Construct a Regular grammar for the following DFA
1
start A B
1
0 0 0 0
1
C 1 D
Vn = {A, B ,C, D}
Soln: T = {0, 1}
Q = {A, B ,C, D} P:
∑ = {0, 1} A → 0C | 1B | ε
q0 = {A} B → 0D | 1A | 1
F = {A} C → 0A |1D | 0
D → 0B | 1C
S = {A}
Example 3
Give regular grammars equivalent to the following finite state
automata

Solution
Exercises
• Give regular grammars
equivalent to the following
finite state automata:
Regular Grammar to Finite Automata
• G = (Vn, T, P, S) • M = (Q, ∑, Ꟙ, q0, F)
Vn = {A0, A1, A2, …} Q = Vn
∑ → same for both M & G ∑=T
Q0 = S
Ꟙ:
If P→aQ then Ꟙ(P,a)=Q
If P→a then Ꟙ(P,a)={F}
Example 1
Construct a FA from the following regular grammar:
S → 0A | 1A
A → 0A | 1A | +B | -B
Ꟙ:
B → 0B | 1B | 0 | 1 Ꟙ(S,0) = A
Ꟙ(S,1) = A
Soln: Ꟙ(A,0) = A
Ꟙ(A,1) = A
M = (Q, ∑, Ꟙ, q0, F) Ꟙ(A,+) = B
Q = {S,A,B,C} Ꟙ(A,-) = B
Ꟙ(B,0) = B
∑ = {0, 1, +, -} Ꟙ(B,1) = B
Q0 = S Ꟙ(B,0) = C
Ꟙ(B,1) = C
Example 2
Construct a FA from the following regular grammar:
S → a | aA | bB | ε
A → aA | aS
B → cS | ε

Soln:
Convert to ε-free grammar
S → a | aA | bB | b
A → aA | aS |a
B → cS | c
S1 → a | aA | bB | b | ε

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy