notes20 Context-free Grammars and Ambiguity

# notes20 Context-free Grammars and Ambiguity - CS 373 Theory...

This preview shows pages 1–4. Sign up to view the full content.

CS 373: Theory of Computation Gul Agha Mahesh Viswanathan Fall 2010 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
1 Context Free Grammars 1.1 Deﬁnitions Context-Free Grammars Deﬁnition 1. A context-free grammar (CFG) is G = ( V, Σ ,R,S ) where V is a ﬁnite set of variables/non-terminals. Σ is a ﬁnite set of terminals. Σ is disjoint from V . R is a ﬁnite set of rules or productions of the form A α where A V and α ( V Σ) * S V is the start symbol Example: Palindromes Example 2 . A string w is a palindrome if w = w R . G pal = ( { S } , { 0 , 1 } ,R,S ) deﬁnes palindromes over { 0 , 1 } , where R is S ± S 0 S 1 S 0 S 0 S 1 S 1 Or more brieﬂy, R = { S ± | 0 | 1 | 0 S 0 | 1 S 1 } Language of a CFG Derivations Expand the start symbol using one of its rules. Further expand the resulting string by expanding one of the variables in the string, by the RHS of one of its rules. Repeat until you get a string of terminals. For the grammar G pal = ( { S } , { 0 , 1 } , { S ± | 0 | 1 | 0 S 0 | 1 S 1 } ,S ) we have S 0 S 0 00 S 00 001 S 100 0010100 Derivations Formal Deﬁnition Deﬁnition 3. Let G = ( V, Σ ,R,S ) be a CFG. We say αAβ G αγβ , where α,β,γ ( V Σ) * and A V if A γ is a rule of G . We say α * G β if either α = β or there are α 0 1 ,...α n such that α = α 0 G α 1 G α 2 G ··· ⇒ G α n = β 2
Notation When G is clear from the context, we will write and * instead of G and * G . Context-Free Language Deﬁnition 4. The language of CFG G = ( V, Σ ,R,S ), denoted L ( G ) is the collection of strings over the terminals derivable from S using the rules in R . In other words, L ( G ) = { w Σ * | S * w } Deﬁnition 5. A language L is said to be context-free if there is a CFG G such that L = L ( G ). 1.2 Proving Properties Palindromes Revisited Recall, L pal = { w ∈ { 0 , 1 } * | w = w R } is the language of palindromes. Consider G pal = ( { S } , { 0 , 1 } ,R,S ) deﬁnes palindromes over { 0 , 1 } , where R = { S ± | 0 | 1 | 0 S 0 | 1 S 1 } Proposition 6. L ( G pal ) = L pal Proving Correctness of CFG L pal L ( G pal ) Proof. Let w L pal . We prove that

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 10/04/2011 for the course CS 373 taught by Professor Viswanathan,m during the Fall '08 term at University of Illinois, Urbana Champaign.

### Page1 / 10

notes20 Context-free Grammars and Ambiguity - CS 373 Theory...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online