Simpli Cation Of CFG’s. This Makes Life Eas-

2y ago
13 Views
2 Downloads
387.77 KB
27 Pages
Last View : 8d ago
Last Download : 3m ago
Upload by : Duke Fulford
Transcription

Properties of CFL’s Simplification of CFG’s. This makes life easier, since we can claim that if a language is CF,then it has a grammar of a special form. Pumping Lemma for CFL’s. Similar to theregular case. Not covered in this course. Closure properties. Some, but not all, of theclosure properties of regular languages carryover to CFL’s. Decision properties. We can test for membership and emptiness, but for instance, equivalence of CFL’s is undecidable.225

Chomsky Normal FormWe want to show that every CFL (without )is generated by a CFG where all productionsare of the formA BC, or A awhere A, B, and C are variables, and a is aterminal. This is called CNF, and to get therewe have to1. Eliminate useless symbols, those that do not appear in any derivation S w, forstart symbol S and terminal w.2. Eliminate -productions, that is, productions of the form A .3. Eliminate unit productions, that is, productions of the form A B, where A and Bare variables.226

Eliminating Useless Symbols A symbol X is useful for a grammar G (V, T, P, S), if there is a derivation GGS αXβ wfor a teminal string w. Symbols that are notuseful are called useless. A symbol X is generating if X w, for someG w T A symbol X is reachable if S αXβ, forsome {α, β} (V T ) GIt turns out that if we eliminate non-generatingsymbols first, and then non-reachable ones, wewill be left with only useful symbols.227

Example: Let G beS AB a, A bS and A are generating, B is not. If we eliminate B we have to eliminate S AB, leavingthe grammarS a, A bNow only S is reachable. Eliminating A and bleaves us withS awith language {a}.OTH, if we eliminate non-reachable symbolsfirst, we find that all symbols are reachable.FromS AB a, A bwe then eliminate B as non-generating, andare left withS a, A bthat still contains useless symbols228

Theorem 7.2: Let G (V, T, P, S) be a CFGsuch that L(G) 6 . Let G1 (V1, T1, P1, S)be the grammar obtained by1. Eliminating all nongenerating symbols andthe productions they occur in. Let the newgrammar be G2 (V2, T2, P2, S).2. Eliminate from G2 all nonreachable symbols and the productions they occur in.Then G1 has no useless symbols, andL(G1) L(G).229

Proof: We first prove that G1 has no uselesssymbols: Let X remain in V1 T1. Thus X w in G1, forsome w T . Moreover, every symbol used in this derivation is also generating. Thus X win G2 also. But this is not enough!Since X was not eliminated in step 2, there are α and β, such that S αXβ in G2. Furthermore, every symbol used in this derivation is also reachable, so S αXβ in G1.Now every symbol in αXβ is reachable and inV2 T2 V1 T1, so each of them is generatingin G2. The terminal derivation αXβ xwy in G2 involves only symbols that are reachable from S,because they are reached fromby symbols in αXβ.Thus the terminal derivation is also a derviain G1, i.e.,tion of S αXβ xwyin G1.230

We then show that L(G1) L(G).Since P1 P , we have L(G1) L(G). Then, let w L(G). Thus S w. Each symGbol is this derivation is evidently both reachable and generating, so this is also a derivationof G1.Thus w L(G1).231

We have to give algorithms to compute thegenerating and reachable symbols of G (V, T, P, S).The generating symbols g(G) are computed bythe following closure algorithm:Basis: g(G) T*Induction: If α g(G) and X α P , theng(G) g(G) {X}.Example: Let G be S AB a, A bThen first g(G) {a, b}.Since S a we put S in g(G), and becauseA b we add A also, and that’s it.232

Theorem 7.4: At saturation, g(G) containsall and only the generating symbols of G.Proof:by an induction on theWe’ll show in class onstage in which a symbol X is added to g(G)that X is indeed generating.Then, suppose that X is generating. Thus X w, for some w T . We prove by inducGtion on this derivation that X g(G).Basis: Zero Steps. Then X is added in thebasis of the closure algo.Induction: The derivation takes n 0 steps.Let the first production used be X α. Then X α w and α w in less than n steps and by the IH*α g(G). From the inductive part of the algoit follows that X g(G).233

The set of reachable symbols r(G) of G (V, T, P, S) is computed by the following closure algorithm:Basis: r(G) {S}.Induction: If variable A r(G) and A α Pthen add all symbols in α to r(G)Example: Let G be S AB a, A bThen first r(G) {S}.Based on the first production we add {A, B, a}to r(G).Based on the second production we add {b} tor(G) and that’s it.Theorem 7.6: At saturation, r(G) containsall and only the reachable symbols of G.Proof: Homework.234

Eliminating -ProductionsWe shall prove that if L is CF, then L \ { } hasa grammar without -productions. Variable A is said to be nullable if A .Let A be nullable. We’ll then replace a rulelikeA BADwithA BAD, A BDand delete any rules with body .We’ll compute n(G), the set of nullable symbols of a grammar G (V, T, P, S) as follows:Basis: n(G) {A : A P }Induction: If {C1C2 · · · Ck } n(G) and A C1C2 · · · Ck P , then n(G) n(G) {A}.235

Theorem 7.7: At saturation, n(G) containsall and only the nullable symbols of G.Proof: Easy induction in both directions.Once we know the nullable symbols, we cantransform G into G1 as follows: For each A X1X2 · · · Xk P with m knullable symbols, replace it by 2m rules, onewith each sublist of the nullable symbols absent.Exeption: If m k we don’t delete all m nullable symbols. Delete all rules of the form A .236

Example: Let G beS AB, A aAA , B bBB Now n(G) {A, B, S}. The first rule will becomeS AB A Bthe secondA aAA aA aA athe thirdB bBB bB bB bWe then delete rules with -bodies, and end upwith grammar G1 :S AB A B, A aAA aA a, B bBB bB b237

Theorem 7.9: L(G1) L(G) \ { }.Proof: We’ll prove the stronger statement: (]) A w in G1 if and only if w 6 and A win G. -direction: Suppose A w in G1. Thenclearly w 6 (Why?). We’ll show by and induction on the length of the derivation that A w in G also.Basis: One step. Then there exists A wroin G1. Formthe construction of G1 it followsthat there exists A α in G, where α is w plussome nullable variables interspersed. Then A α win G.238

Induction: Derivation takes n 1 steps. Then A X1X2 · · · Xk w in G1and the first derivation is based on a productionA Y1Y2 · · · Ym in Gwhere m k, some Yi’s are Xj ’s and the otherare nullable symbols of G. thFurhtermore,w w1w2 · · · wk , and Xi wi inG1 in less than n steps. By the IH we have Xi wi in G. Now we get GGA Y1Y2 · · · Ym X1X2 · · · Xk w1w2 · · · wk wG239

-direction: Let A w, and w 6 . We’ll showGby induction of the length of the derivation that A w in G1.Basis: Length is one. Then A w is in G,and since w 6 the rule is in G1 also.Induction: Derivation takes n 1 steps. Thenit looks like A Y1Y2 · · · Ym wGG Now w w1w2 · · · wm, and Yi wi in less thanGn steps.Let X1X2 · · · Xk be those Yj ’s in order, suchthat wj 6 . Then A X1X2 · · · Xk is a rule inG1. Now X1X2 · · · Xk w (Why?)G240

Each Xj /Yj wj in less than n steps, so byG IH we have that if wj 6 then Yj wj in G1.Thus A X1X2 · · · Xk w in G1The claim of the theorem now follows fromstatement (]) on slide 238 by choosing A S.241

Eliminating Unit ProductionsA Bis a unit production, whenever A and B arevariables.Unit productions can be eliminated.Let’s look at grammarI F T E a b Ia Ib I0 I1I (E)F T FT E TIt has unit productions E T , T F , andF I242

We’ll expand rule E T and get rulesE F, E T FWe then expand E F and getE I (E) T FFinally we expand E I and getE a b Ia Ib I0 I1 (E) T FThe expansion method works as long as thereare no cycles in the rules, as e.g. inA B, B C, C AThe following method based on unit pairs willwork for all grammars.243

(A, B) is a unit pair if A B using unit productions only. Note: In A BC, C we have A B, butnot using unit productions only.To compute u(G), the set of all unit pairs ofG (V, T, P, S) we use the following closurealgorithmBasis: u(G) {(A, A) : A V }Induction: If (A, B) u(G) and B C Pthen add (A, C) to u(G).Theorem: At saturation, u(G) contains alland only the unit pair of G.Proof: Easy.244

Given G (V, T, P, S) we can construct G1 (V, T, P1, S) that doesn’t have unit productions,and such that L(G1) L(G) by settingP1 {A α : α / V, B α P, (A, B) u(G)}Example: Form the grammar of slide 242 wegetPair(E, E)(E, T )(E, F )(E, I)(T, T )(T, F )(T, I)(F, F )(F, I)(I, I)ProductionsE E TE T FE (E)E a b Ia Ib I0 I1T T FT (E)T a b Ia Ib I0 I1F (E)F a b Ia Ib I0 I1I a b Ia Ib I0 I1The resulting grammar is equivalent to theoriginal one (proof omitted).245

SummaryTo “clean up” a grammar we can1. Eliminate -productions2. Eliminate unit productions3. Eliminate useless symbolsin this order.This cannot be doneearlier due to the removalof ε productions and unitproductions.246

Chomsky Normal Form, CNFWe shall show that every nonempty CFL without has a grammar G without useless symbols, and such that every production is of theform A BC, where {A, B, C} TV , or A α, where A V , and α T .To achieve this, start with any grammar forthe CFL, and1. “Clean up” the grammar.2. Arrange that all bodies of length 2 or moreconsists of only variables.3. Break bodies of length 3 or more into acascade of two-variable-bodied productions.247

For step 2, for every terminal a that appearsin a body of length 2, create a new variable,say A, and replace a by A in all bodies.Then add a new rule A a. For step 3, for each rule of the formA B1 B2 · · · Bk ,k 3, introduce new variables C1, C2, . . . Ck 2,and replace the rule withA B 1 C1C1 B 2 C2···Ck 3 Bk 2Ck 2Ck 2 Bk 1Bk248

Illustration of the effect of step 3AB1C1B2C2.C k -2B k-1Bk(a)AB1B2. . .Bk(b)249

Example of CNF conversionLet’s start with the grammar (step 1 alreadydone)E E T T F (E) a b Ia Ib I0 I1T T F (E)a b Ia Ib I0 I1F (E) a b Ia Ib I0 I1I a b Ia Ib I0 I1For step 2, we need the rulesA a, B b, Z 0, O 1P , M , L (, R )and by replacing we get the grammarE EP T T M F LER a b IA IB IZ IOT T M F LER a b IA IB IZ IOF LER a b IA IB IZ IOI a b IA IB IZ IOA a, B b, Z 0, O 1P , M , L (, R )250

For step 3, we replaceE EP T by E EC1, C1 P TE T M F, T T M F byE T C2 , T T C2 , C2 M FE LER, T LER, F LER byE LC3, T LC3, F LC3, C3 ERThe final CNF grammar isE EC1 T C2 LC3 a b IA IB IZ IOT T C2 LC3 a b IA IB IZ IOF LC3 a b IA IB IZ IOI a b IA IB IZ IOC1 P T, C2 M F, C3 ERA a, B b, Z 0, O 1P , M , L (, R )251

Properties of CFL’s Simpli cation of CFG’s. This makes life eas-ier, since we can claim that if a language is CF, then it has a grammar of a special form. Pumping Lemma for CFL’s. Similar to the regular case. Not covered in this course. Closure properties. Some, but not all, of the closure properties of regular languages carry over to CFL .

Related Documents:

alent. We describe here two procedures to convert a CFG to a PDA. To follow along, enter the following grammar into JFLAP S! b S! aTb T! T! Ta Converting a CFG to a PDA using ideas from LL parsing The PDAs that get created from a CFG are generally of the

4. From a CFG to an equivalent PDA ¾ Given a CFG G , we can construct a PDA P such that N( P ) L( G ). ¾ The PDA will simulate leftmost derivations of G. ¾ Algorithm to construct a PDA for a CFG o Input: a CFG G (V, T, P, S). o Output: a PDA P such that N( P )

3 In the root directory, open the folder named Config and identify the following three files you will be editing: reg-basic.cfg sip-basic.cfg 00000000000.cfg (the master configuration file) 4 To simplify provisioning, place copies of these three files in the root directory and not in a subfolder. Polycom recommends editing

pero IMstarter Seite 2 von 33 1 General description SIMstarter is a program which launches “Microsoft Flight Simulator X”, “Microsoft Flight Simulator X – SteamEdition” or “PREPAR3D v2.x” with pre-defined configuration profiles. Changes, based on those profiles, will be done to “fsx.cfg/prepar3d.cfg” or “scenery.cfg”.

CFG implementation of the latest Windows 10 technical preview build (10.0.9926) has a slight change at that same point, I will point out the difference. To fully implement CFG, both the compiler and the operating system must support it properly. As an exploit mitigation mechanism in the system level, the CFG implementation

1 Lab meeting and introduction to qualitative analysis 2 Anion analysis (demonstration) 3 Anion analysis 4 5. group cation anion analysis 5 4. group cation (demonstration) 6 4. group cation anion analysis 7 3. group cation (demonstration) 8 3. group cation anion analysis 9 Mid-term exam 10 2. group cation (demonstration)

Independent Personal Pronouns Personal Pronouns in Hebrew Person, Gender, Number Singular Person, Gender, Number Plural 3ms (he, it) א ִוה 3mp (they) Sֵה ,הַָּ֫ ֵה 3fs (she, it) א O ה 3fp (they) Uֵה , הַָּ֫ ֵה 2ms (you) הָּ תַא2mp (you all) Sֶּ תַא 2fs (you) ְ תַא 2fp (you

Sharma, O.P. (1986). Text book of Algae- TATA McGraw-Hill New Delhi. Mycology 1. Alexopolous CJ and Mims CW (1979) Introductory Mycology. Wiley Eastern Ltd, New Delhi. 2. Bessey EA (1971) Morphology and Taxonomy of Fungi. Vikas Publishing House Pvt Ltd, New Delhi. 3. Bold H.C. & others (1980) – Morphology of Plants & Fungi – Harper & Row Public, New York. 4. Burnet JH (1971) Fundamentals .