Professional Documents
Culture Documents
12-Regular Grammar and FA-01!02!2023
12-Regular Grammar and FA-01!02!2023
a b b D
A B C
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 | ε