Understanding Regular Grammars and Languages: Theorem and Proof
460 likes | 665 Vues
Learn about regular grammars generating regular languages, such as right-linear and left-linear grammars. Follow the proof showing the interrelation between regular languages and regular grammars. Convert NFAs to regular grammars and explore the generalization of the process.
Understanding Regular Grammars and Languages: Theorem and Proof
E N D
Presentation Transcript
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