This preview shows pages 1–7. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Discussion #3 Chapter 10, Sections 1.35 1/20 Discussion #3 Grammar Formalization Discussion #3 Chapter 10, Sections 1.35 2/20 Topics Grammar Definitions Parse Trees Constructing Parse Trees Discussion #3 Chapter 10, Sections 1.35 3/20 Formal Definition of a Grammar A grammar G is a 4tuple: G = (V N , V T , S, ), where V N , V T , sets of nonterminal and terminal symbols S V N , a start symbol = a finite set of relations from (V T V N ) + to (V T V N ) * an element of , ( , ), is written as and is called a production rule or a rewriting rule Discussion #3 Chapter 10, Sections 1.35 4/20 Examples of Grammars G 1 = (V N , V T , S, ), where: V N = {S, B} V T = {a, b, c} S = S = { S aBSc , S abc , Ba aB , Bb bb } G 2 = (V N , V T , S, ), where: V N = {I, L, D} V T = {a, b, , z, 0, 1, , 9} S = I = { I L  ID  IL , L a  b   z , D 0  1   9 } G 3 = (V N , V T , S, ), where: = { S aA , V N = {S, A, B } A aA  bB , V T = {a, b} B bB  } S = S Discussion #3 Chapter 10, Sections 1.35 5/20 Definition of a ContextFree Grammar A contextfree grammar is a grammar with the following restriction: The relation is a finite set of relations from V N to (V T V N ) + i.e. the left hand side of a production is a single non terminal i.e. the right hand side of any production cannot be empty Contextfree grammars generate contextfree languages. With slight variations, essentially all programming languages are contextfree languages. Discussion #3 Chapter 10, Sections 1.35 6/20 Examples of Grammars (again) Which are contextfree grammars?...
View
Full
Document
This note was uploaded on 03/02/2012 for the course C S 236 taught by Professor Michaelgoodrich during the Winter '12 term at BYU.
 Winter '12
 MichaelGoodrich

Click to edit the document details