e is a string of zero or more variables De64257nition A production U is said to be in the form left recursion if A for some Left recursion in can be eliminated by the following scheme If A A A then replace the above rules by i Z and ii Z If ID: 25215 Download Pdf

196K - views

Published bybriana-ranney

e is a string of zero or more variables De64257nition A production U is said to be in the form left recursion if A for some Left recursion in can be eliminated by the following scheme If A A A then replace the above rules by i Z and ii Z If

Tags :
string

Download Pdf

Download Pdf - The PPT/PDF document "MA Formal Languages and Automata Theory ..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.

Page 1

MA513: Formal Languages and Automata Theory Topic: Properties of Context-free Languages Lecture Number 29 Date: October 18, 2011 1 Greibach Normal Form (GNF) A CFG = ( V, T, R, S ) is said to be in GNF if every production is of the form a , where and , i.e., is a string of zero or more variables. Deﬁnition: A production U is said to be in the form left recursion , if A for some Left recursion in can be eliminated by the following scheme: If A A . . . A . . . , then replace the above rules by (i) Z, and (ii) Z, If = ( V, T, R, S ) is a CFG, then we can construct another

CFG = ( , T, R , S in Greibach Normal Form (GNF) such that ) = −{ The stepwise algorithm is as follows: 1. Eliminate null productions, unit productions and useles s symbols from the grammar and then construct a = ( , T, R , S ) in Chomsky Normal Form (CNF) generating the language ) = −{ 2. Rename the variables like , A , . . .A starting with 3. Modify the rules in so that if then j > i 4. Starting with and proceeding to this is done as follows: (a) Assume that productions have been modiﬁed so that for 1 k, A only if j > i (b) If is a production with j < k , generate a new

set of productions substituting for the the body of each production. (c) Repeating (b) at most 1 times we obtain rules of the form γ, p (d) Replace rules by removing left-recursion as stated above. 5. Modify the for , n , ., 1 in desired form at the same time change the production rules.

Page 2

Example: Convert the following grammar into Greibach Normal Form (GNF). XA BB SB To write the above grammar into GNF, we shall follow the following steps: 1. Rewrite in Chomsky Normal Form (CNF) It is already in CNF. 2. Re-label the variables with with with with After re-labeling the

grammar looks like: 3. Identify all productions which do not conform to any of the types listed below: such that j > i such that ax such that and 4. ................ identiﬁed 5. To eliminate we will use the substitution rule Therefore, we have The above two productions still do not conform to any of the ty pes in step 3. Substituting for bA Now we have to remove left recursive production

Page 3

bA bA bZ 6. At this stage our grammar now looks like bA bA bZ All rules now conform to one of the types in step 3. But the grammar is still not in Greibach Normal Form! 7. All

productions for , A and are in GNF for Substitute for and to convert it to GNF bA bA bA bA ZA bZA for Substitute for to convert it to GNF bA bA bA ZA bZA bA bA bA ZA bZA 8. Finally the grammar in GNF is bA bA bA bA ZA bZA bA bA bZ bA bA bA ZA bZA bA bA bA ZA bZA

© 2020 docslides.com Inc.

All rights reserved.