This preview shows page 1. Sign up to view the full content.
Unformatted text preview: CONTEXT FREE LANGUAGES CONTEXTFREE LANGUAGES
CONTEXTFREE REGULAR • ContextFree Grammars • PushDown Automata IDEA
Remember ”balanced parantheses” example from structural induction? IDEA
Remember ”balanced parantheses” example from structural induction? S= (S )S IDEA
Remember ”balanced parantheses” example from structural induction? S= (S )S If we write it this way: S −→ (S )S  IDEA
Remember ”balanced parantheses” example from structural induction? S= (S )S If we write it this way: S −→ (S )S 
it is a contextfree grammar generating a contextfree language containing all balanced parantheses strings. CONTEXTFREE GRAMMARS
A contextfree grammar is a tuple G = (V, T, P, S ) where • V is ﬁnite set of variables or nonterminals. • T is a ﬁnite set of terminals. • V ∩T =∅ • S ∈ V is a unique start symbol. • P is a ﬁnite set of productions (rules). CONTEXTFREE GRAMMARS
A contextfree grammar is a tuple G = (V, T, P, S ) where • V is ﬁnite set of variables or nonterminals. • T is a ﬁnite set of terminals. • V ∩T =∅ • S ∈ V is a unique start symbol. • P is a ﬁnite set of productions (rules). A −→ α CONTEXTFREE GRAMMARS
A contextfree grammar is a tuple G = (V, T, P, S ) where • V is ﬁnite set of variables or nonterminals. • T is a ﬁnite set of terminals. • V ∩T =∅ • S ∈ V is a unique start symbol. • P is a ﬁnite set of productions (rules). A −→ α A∈V α ∈ (V ∪ T )∗ EXAMPLE
G = ({S }, {0, 1}, , S) EXAMPLE
G = ({S }, {0, 1}, S −→ 0 S −→ , S) S −→ 1 S −→ 0S 0 S −→ 1S 1 EXAMPLE
G = ({S }, {0, 1}, S −→ 0 S −→ , S) S −→ 1 S −→ 0S 0 Generates Palindromes! S −→ 1S 1 EXAMPLE
G = ({S }, {0, 1}, S −→ 0 S −→ , S) S −→ 1 S −→ 0S 0 Generates Palindromes! S −→ 1S 1 S −→ 0S 0  1S 1   1  0 HOW DO WE DEFINE THE LANGUAGE OF A GRAMMAR? DERIVATIONS DERIVATIONS
Let α1 , α2 ∈ (V ∪ T )∗ , we say: α1 =⇒G α2 DERIVATIONS
Let α1 , α2 ∈ (V ∪ T )∗ , we say: If: α1 =⇒G α2 ∃A ∈ V ∃β , γ , λ ∈ (V ∪ T )∗ DERIVATIONS
Let α1 , α2 ∈ (V ∪ T )∗ , we say: If: α1 =⇒G α2 ∃A ∈ V such that α1 = β Aγ ∃β , γ , λ ∈ (V ∪ T )∗ α2 = βλγ DERIVATIONS
Let α1 , α2 ∈ (V ∪ T )∗ , we say: If: α1 =⇒G α2 ∃A ∈ V such that α1 = β Aγ And ∃β , γ , λ ∈ (V ∪ T )∗ α2 = βλγ A −→ λ is in P DERIVATIONS
Let α1 , α2 ∈ (V ∪ T )∗ , we say: If: α1 =⇒G α2 ∃A ∈ V such that α1 = β Aγ And ∃β , γ , λ ∈ (V ∪ T )∗ α2 = βλγ A −→ λ is in P α2 can be derived from α1 in a single production application. LANGUAGE OF A GRAMMAR
Let =⇒∗ be reﬂexive and transitive closure of =⇒G . G LANGUAGE OF A GRAMMAR
Let =⇒∗ be reﬂexive and transitive closure of =⇒G . G α1 =⇒∗ α2 iﬀ α2 can be derived from α1 in ﬁnite number (even zero) G of applications of productions in P LANGUAGE OF A GRAMMAR
Let =⇒∗ be reﬂexive and transitive closure of =⇒G . G α1 =⇒∗ α2 iﬀ α2 can be derived from α1 in ﬁnite number (even zero) G of applications of productions in P L(G) = {w : w ∈ T and S
∗ ∗ =⇒G w} LANGUAGE OF A GRAMMAR
Let =⇒∗ be reﬂexive and transitive closure of =⇒G . G α1 =⇒∗ α2 iﬀ α2 can be derived from α1 in ﬁnite number (even zero) G of applications of productions in P L(G) = {w : w ∈ T and S
∗ ∗ =⇒G w} The language generated by G is all strings of terminals derivable from the start symbol. LANGUAGE OF A GRAMMAR
Let =⇒∗ be reﬂexive and transitive closure of =⇒G . G α1 =⇒∗ α2 iﬀ α2 can be derived from α1 in ﬁnite number (even zero) G of applications of productions in P L(G) = {w : w ∈ T and S
∗ ∗ =⇒G w} The language generated by G is all strings of terminals derivable from the start symbol. ContextFree Languages = {L : ∃ grammar (CFG) G s.t. L(G) = L} EXAMPLE
L = {0n 1n  n ≥ 0} EXAMPLE
L = {0n 1n  n ≥ 0} S −→ 0S 1  EXAMPLE
{w : w has equal number of 0’s and 1’s} ...
View
Full
Document
This note was uploaded on 04/11/2010 for the course CSC CSC236 taught by Professor Farzanazadeh during the Spring '10 term at University of Toronto.
 Spring '10
 FarzanAzadeh

Click to edit the document details