770 likes | 883 Views
Applications of Regular Closure. The intersection of a context-free language and a regular language is a context-free language. Regular Closure. context free. regular. context-free. An Application of Regular Closure. Prove that:. is context-free.
E N D
The intersection of a context-free language and a regular language is a context-free language Regular Closure context free regular context-free
An Application of Regular Closure Prove that: is context-free
We know: is context-free
We also know: is regular is regular
context-free regular (regular closure) is context-free context-free
Another Application of Regular Closure Prove that: is not context-free
Therefore, is not context free is context-free If (regular closure) Then context-free regular context-free Impossible!!!
Parsers Membership Algorithms: • Exhaustive search parser • CYK parsing algorithm Membership Question: for context-free grammar find if string
Algorithm: • Remove useless variables • Check if start variable is useless Empty Language Question: for context-free grammar find if
Infinite Language Question: Algorithm: 1. Remove useless variables 2. Remove unit and productions 3. Create dependency graph for variables 4. If there is a loop in the dependency graph then the language is infinite for context-free grammar find if is infinite
Example: Infinite language Dependency graph
Take an infinite context-free language Generates an infinite number of different strings Example:
Derivation tree string
Derivation tree string repeated
Therefore, the string is also generated by the grammar
We know: We also know this string is generated:
We know: Therefore, this string is also generated:
We know: Therefore, this string is also generated:
We know: Therefore, this string is also generated:
Therefore, knowing that is generated by grammar , we also know that is generated by
In general: We are given an infinite context-free grammar Assume has no unit-productions no -productions
Take a string with length bigger than > (Number of productions) x (Largest right side of a production) Consequence: Some variable must be repeated in the derivation of
String Last repeated variable repeated
Possible derivations:
We know: This string is also generated:
We know: This string is also generated: The original
We know: This string is also generated:
We know: This string is also generated:
We know: This string is also generated:
Therefore, any string of the form is generated by the grammar
Therefore, knowing that we also know that
Observation: Since is the last repeated variable
Observation: Since there are no unit or productions
The Pumping Lemma: For infinite context-free language there exists an integer such that for any string we can write with lengths and it must be:
Non-context free languages Context-free languages
Theorem: The language is not context free Proof: Use the Pumping Lemma for context-free languages
Assume for contradiction that is context-free Since is context-free and infinite we can apply the pumping lemma
Pumping Lemma gives a magic number such that: Pick any string with length We pick: