Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Regular Grammars Generate Regular Languages. 2 Theorem Regular grammars generate exactly the class of regular languages: If is a regular grammar then.

Similar presentations


Presentation on theme: "1 Regular Grammars Generate Regular Languages. 2 Theorem Regular grammars generate exactly the class of regular languages: If is a regular grammar then."— Presentation transcript:

1 1 Regular Grammars Generate Regular Languages

2 2 Theorem Regular grammars generate exactly the class of regular languages: If is a regular grammar then is a regular language If is a regular language then there is a regular grammar with

3 3 Proof First we prove: If is a regular grammar then is a regular language can be: Right-linear grammar or Left-linear grammar

4 4 The case of Right-Linear Grammars Let be a right-linear grammar We will show: is regular The proof: We will construct an NFA with

5 5 Grammar is right-linear Example:

6 6 Construct NFA such that every state is a variable: special final state

7 7 Add edges for each production:

8 8

9 9

10 10

11 11

12 12

13 13 Grammar NFA

14 14 In General A right-linear grammar has variables: and productions: or

15 15 We construct the NFA such that: each variable corresponds to a node:

16 16 For each production: we add transitions and intermediate nodes ………

17 17 For each production: we add transitions and intermediate nodes ………

18 18 Resulting NFA looks like this:

19 19 Now, we need to show:

20 20 The Case: Take We will show: there is a path with label in from state to state …………

21 21 strings Grammar looks like:

22 22

23 23 ……

24 24 ……

25 25 ……

26 26 Since: We have: ……

27 27 Since: We have: …… and

28 28 The Case: Take We will show that in

29 29 Since there is a path ……

30 30 Write: There is a path ……

31 31 Since: This derivation is possible ……

32 32 Since: We have:

33 33 The Case of Left-Linear Grammars Let be a left-linear grammar We will show: is regular The proof: We will construct a right-linear grammar with

34 34 Since is left-linear grammar the productions look like:

35 35 Construct right-linear grammar In :

36 36 In :

37 37 It is easy to see that: Since is right-linear, we have: is regular language is regular language (homework) is regular language

38 38 Proof - Part 2 Now we will prove: If is a regular language then there is a regular grammar with Proof outline: we will take an NFA for and convert it to a regular grammar

39 39 Since is regular There is an NFA such that Example:

40 40 Convert to a right-linear grammar

41 41

42 42

43 43 We can generalize this process for any regular language : For any regular language we obtain an right-linear grammar with

44 44 Since is right-linear grammar is also a regular grammar with


Download ppt "1 Regular Grammars Generate Regular Languages. 2 Theorem Regular grammars generate exactly the class of regular languages: If is a regular grammar then."

Similar presentations


Ads by Google