notes20 Context-free Grammars and Ambiguity

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

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

View Full Document Right Arrow Icon
CS 373: Theory of Computation Gul Agha Mahesh Viswanathan Fall 2010 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
1 Context Free Grammars 1.1 Definitions Context-Free Grammars Definition 1. A context-free grammar (CFG) is G = ( V, Σ ,R,S ) where V is a finite set of variables/non-terminals. Σ is a finite set of terminals. Σ is disjoint from V . R is a finite 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 ) defines palindromes over { 0 , 1 } , where R is S ± S 0 S 1 S 0 S 0 S 1 S 1 Or more briefly, 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 Definition Definition 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
Background image of page 2
Notation When G is clear from the context, we will write and * instead of G and * G . Context-Free Language Definition 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 } Definition 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 ) defines 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
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
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 Right Arrow Icon
Ask a homework question - tutors are online