# Regular Grammars Generate Regular Languages 1 Theorem Regular

• Slides: 44

Regular Grammars Generate Regular Languages 1

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 2

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

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 4

Grammar is right-linear Example: 5

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

Add edges for each production: 7

8

9

10

11

12

NFA Grammar 13

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

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

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

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

Resulting NFA looks like this: 18

Now, we need to show: 19

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

Grammar looks like: strings 21

22

Since: …… …… We have: 26

Since: We have: and …… We have: 27

The Case: Take We will show that in 28

Since there is a path …… 29

Write: There is a path …… …… 30

Since: …… …… This derivation is possible 31

Since: We have: 32

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 33

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

Construct right-linear grammar In : 35

In : 36

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

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 38

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

Convert to a right-linear grammar 40

41

42

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

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