Ch3 - Chapter 3 Context-Free Grammars Context-Free Grammars...

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

View Full Document Right Arrow Icon
Context-Free Grammars Chapter 3
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Context-Free Grammars and Languages Defn. 3.1.1 A context-free grammar is a quadruple ( V , , P , S ), where V is a finite set of variables ( non-terminals ) , the alphabet , is a finite set of terminal symbols P is a finite set of rules of the form V × ( V )* , and S V , is the start symbol A production rule of the form A w , where w ( V )*, applied to the string uAv yields uwv , and u and v define the context in which A occurs. Because the context places no limitations on the applicability of a rule, such a grammar is called context-free grammar ( CFG )
Background image of page 2
3 Context-Free Grammars and Languages Defn. 3.1.2. Let G = ( V , , P , S ) be a CFG and v ( V )*. The set of strings derivable from v is defined recursively as follows: i) Basis: v is derivable from v ii) Recursion: If u = xAy is derivable from v and A w P, then xwy is derivable from v iii) Closure: All strings constructed from v and a finite number of applications of (ii) are derivable from v The derivability of w ( V )* from v ( V ) + is denoted v w The language of the grammar G is the set of terminal strings derivable from the start symbol of G * G n + * , or v w , v w , v w
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 CFG and Languages Defn. 3.1.3. Let G = ( V , , P , S ) be a CFG (i) A string w ( V )* is a sentential form of G if S w (ii) A string w * is a sentence of G if S w (iii) The language of G, denoted L(G), is the set { w * | S w } A set of strings w over an alphabet is called a CFL if there is a CFG that generates w Leftmost ( Rightmost ) derivation : a derivation that transforms the 1 st variable occurring in a string from left-to-right (right-to-left) e.g., Fig. 3.1(a) and (b) exhibit a leftmost derivation, whereas Fig. 3.1(c) shows a rightmost derivation The derivation of a string can be graphically depicted by a derivation/parse tree * G * * G
Background image of page 4
5 CFG and Languages
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 CFG and Languages Design CFG for the following languages: (i) The set { 0 n 1 n | n 0 }. (ii) The set { a i b j c k | i j or j k }, i.e., the set of strings of a ’s followed by b ’s followed by c ’s such that there are either a different number of a ’s and b ’s or a different number of b ’s and c ’s, or both. Given the following grammar: S A 1 B A 0 A | λ B 0 B | 1 B | λ Give the leftmost and rightmost derivation of the string 00101
Background image of page 6
7 CFG and Languages Defn. 3.1.4 . Let G = ( V , , P , S ) be a CFG and S w a derivation. The derivation tree , DT , of S w is an ordered tree that can be built iteratively as follows: (i) Initialize DT T with root S (ii) If A x 1 ... x n , where x i ( V ), is a rule in the derivation applied to rAv , then add x 1 ... x n as the children of A in T (iii) If A λ is a rule in the derivation applied to uAv , then add λ as the only child of
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/02/2012 for the course C S 252 taught by Professor Dennisng during the Winter '12 term at BYU.

Page1 / 23

Ch3 - Chapter 3 Context-Free Grammars Context-Free Grammars...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online