460 likes | 608 Views
Regular Grammars Generate Regular Languages. 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. Proof. First we prove:
E N D
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
Proof • First we prove: • If is a • regular grammar • then is • a regular language can be: Right-linear grammar or Left-linear grammar
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
Grammar is right-linear Example:
Construct NFA such that • every state is a variable: special final state
NFA Grammar
In General • A right-linear grammar • has variables: • and productions: or
We construct the NFA such that: • each variable corresponds to a node:
For each production: • we add transitions and intermediate nodes ………
For each production: • we add transitions and intermediate nodes ………
The Case: • Take We will show: there is a path with label in from state to state …………
Grammar looks like: strings
…… ……
…… …… …… ……
Since: • We have: …… …… …… ……
Since: • We have: • We have: and ……
The Case: Take We will show that in
Since • there is a path ……
Write: • There is a path …… …… …… ……
Since: • This derivation is possible …… …… …… ……
Since: • We have: • We have:
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
Since is left-linear grammar the productions look like:
Construct right-linear grammar In : In :
In : In :
It is easy to see that: • Since is right-linear, we have: • is regular language • is regular language (homework) • is regular language
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
Since is regular • There is an NFA such that Example:
We can generalize this process for • any regular language : • For any regular language • we obtain an right-linear grammar • with
Since is right-linear grammar • is also a regular grammar • with