0% found this document useful (0 votes)
10 views

Tutorial Six

Uploaded by

ahmed
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)
10 views

Tutorial Six

Uploaded by

ahmed
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/ 40

Switching Theory and

Models of Computation
Tutorial Six:
Correspondence between NFA and Regular Grammars
Conversion from NFA to Regular Grammar
Conversion from Regular Grammars to Regular Expressions
Lecture Instructor : Prof. Dr. Ahmed El Nahas
Tutorial Instructor: Eng. Ahmed Abdelhamid Waheed Abdelwahab

1
Representations of Finite State Machines
So far we have discovered a single representation of finite state
machines using state graphs.
Complexity of representing graphs is expensive in terms of memory.
Hard to deduce corresponding regular expression for the finite automaton we
built (state elimination procedure covered later on).
Another representation is with using finite set of rules that
corresponds to the candidate finite automaton.
Once the rules are given, they can be solved in algebraic like notion to deduce
the regular expression.

2
Quick Review: Right Linear Grammars and NFA(1)
• A right linear grammar G is a quadruple G=(V, Ʃ, S, P)
V is a finite set of (meta) symbols or variables.
Ʃ is a finite set of terminal symbols.
SϵV is a distinguished element of V called the start symbol.
P is a finite set of productions having one of two forms:
o VƩ*V OR VƩ*

3
Quick Review: Right Linear Grammars and NFA(2)

4
Quick Review: Right Linear Grammars and NFA(3)
• Additional Hint
• If there exists a rule A  σ1σ2σ3σn for A ϵ V and σ1,σ2,σ3,…σn ϵ Ʃ
• Then corresponding conversion is in the form:

σ1 σn
σ2
A

5
Illustration

6
Exercises(1)
1. Construct NFA that recognizes the language generated by the
regular grammar G=(V, Ʃ, S, P) where V={S, A}, Ʃ={0, 1}, and the
productions in P are:
S1A, S0, SԐ, A0A, A1

7
Illustration

8
Solution

1 1
S A 3

9
Exercises(2)
2. Construct NFA that recognizes the language generated by the
regular grammar G=(V, Ʃ, S, P) where V={S, A, B}, Ʃ={0, 1}, and the
productions in P are:
S0A, S1B, A0, AB, B0

10
Illustration

11
Solution

0 0
S A 3

1 Ԑ

0
B 3

12
Exercises(3)
3. Construct NFA that recognizes the language generated by the
regular grammar G=(V, Ʃ, S, P) where V={S, A, B}, Ʃ={0, 1}, and the
productions in P are:
S1A, S0, SԐ, A0B, B1B, B1

13
Illustration

14
Solution

1 0 1
S A B 3

15
Exercises(4)
4. Construct NFA that recognizes the language generated by the
regular grammar G=(V, Ʃ, S, P) where V={S, A, B}, Ʃ={0, 1}, and the
productions in P are:
S1B, S0, A1A, A0B, A1, A0, B1

16
Illustration

17
Solution

1 1
S B 3

0
0 3

3 1
A

3
1
0

18
Exercises(5)
5. Find a regular grammar generating the language accepted by the FA
shown below. a
b
b

a a
A B B
C

b
D

a, b

19
Illustration

20
Solution
• G=( {A, B, C, D}, {a, b}, P, A) where P is given by:
• A  aB A  bD AԐ
• B  aB B  aC B  bC
• C  bC CԐ
• D  aD D  bD

21
Exercises(6)
6. Find a regular grammar that generates the regular set recognized by
the NFA shown below 0, 1

0 1
S A
B B

22
Illustration

23
Solution
G=( {S, A, B}, {0, 1}, P, S) where P is given by:
• S0A S1B
• A1B AԐ
• B0B B1B

24
Exercises(7)
7. Find a regular grammar that generates the regular language
recognized by the FA shown below
1

1
S A

0
0, 1
0
B
C
B

0
1
25
Illustration

26
Solution
G=( {S, A, B, C}, {0, 1}, P, S) where P is given by:
• S0B S1A
• A0B A1A AԐ
• B0B B1C
• C0C C1C CԐ

27
Exercises(8)
8. Find a regular grammar generating the language accepted by the FA
shown below. a
b
b

a
A B B
C

b
D

a, b

28
Illustration

29
Solution
• G=({A, B, C, D}, {a, b}, P, A) where P is given by:
• A  aB A  bD AԐ
• B  aB B  bC
• C  aB C  bC CԐ
• D  aD D  bD

30
Quick Review: RE Simplification Rules

31
Exercises(9)
9. Convert following regular grammar into regular expression:
G=({S,R}, {a, b}, S, P) where P is
SaS, SbR, SԐ
RaS

32
Illustration

33
Solution
• Write Productions as system of linear equations (Replace epsilons
with 1):
S=aS+bR+1  eq.(1)
R=aS  eq.(2)
• Substitute eq.(2) in eq.(1)
S=aS + baS+1
=(a + ba)S+1
Apply Rule(22) : Q=P+RQ=R*P
S=(a+ba)*1
=(a+ba)*

34
Exercises(10)
10. Convert following regular grammar into regular expression:
G=({a,b}, {S,A,B}, ϕ, S) where ϕ consists of:
SaA SbB Sb
AbA AԐ
BbS

35
Illustration

36
Solution
• Write Productions as system of linear equations (Replace epsilons
with 1):
S=aA+bB+b  eq.(1)
A=bA+1  eq.(2)
B=bS  eq.(3)
• From eq.(2) we deduce that A=b*  eq.(4) (Q=RQ+P=R*P (Rule 22))
• Substitute eq.(3) and eq.(4)
S=ab* + bbS+b
=bbS+(ab*+b)
Apply Rule(22) : Q=R*P=P+RQ
=(bb)*(ab*+b)

37
Exercises(11)
11. Convert following regular grammar into regular expression:
G=({X,Y,Z}, {a, b, c}, ϕ, X) where ϕ consists of:
XaX XbY
YcX YaZ YbZ
ZԐ

38
Illustration

39
Solution
• Write Productions as system of linear equations (Replace epsilons with 1):
X=aX + bY  eq (1)
Y=cX + aZ+ bZ  eq (2)
Z=1  eq (3)
• Substitute eq.(3) in eq.(2)
Y = cX + a + b  eq (4)
• Substitute eq.(4) in eq.(1)
X = aX + b(cX + a + b)
X = aX + bcX + ba +bb
X = (a+bc)X + ba + bb
Apply (Q=RQ+P=R*P (Rule 22)) on above getting: (a+bc)*(ba+bb)
40

You might also like