Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 19 Naveen Z Quazilbash. Overview CNFs-Assignment Greibach Normal Forms.

Similar presentations


Presentation on theme: "Lecture 19 Naveen Z Quazilbash. Overview CNFs-Assignment Greibach Normal Forms."— Presentation transcript:

1 Lecture 19 Naveen Z Quazilbash

2 Overview CNFs-Assignment Greibach Normal Forms

3 Assignment Begin with the grammar: S  ASB| ε A  aAS|a B  SbS|A|bb 1. Are there any useless symbols? Eliminate them if so. 2. Eliminate ε-productions. 3. Eliminate unit productions. 4. Put the grammar into Chomsky normal form.

4 Greibach Normal Form Each production is of the form A  s or A  sB 1 B 2 B 3 …B n Where s is a symbol and B 1, B 2,…, B n are variables.

5 S-grammars (from lecture 15) Simple grammars a.k.a s-grammars. Rules for s-grammars: Productions of the form A  sB 1 B 2 B 3 ….B n,where s is a symbol and B 1 B 2 B 3 ….B n are variables. For each variable A and symbol s, there is at most one production of the form: A  sB 1 B 2 B 3 ….B n

6 S-grammars (2) (from lecture 15) For example, we can not have A  aBC A  aCD Because we must only have one “A  a…” production.

7 Difference Difference from s-grammars: for a given variable, we may have multiple productions with the same symbol. E.g. S  aS|a Two productions S  a… ==== OK for Greibach; not OK for s-grammars.

8 For every grammar that does not generate ε, there is an equivalent grammar in Greibach normal form. Example : S  aAbB A  aaA|a B  bB|b S  aAXB A  aYA|a B  bB|b X  b Y  a

9 Solution a)Only S is nullable, so we must choose, at each point where S occurs in a body, to eliminate it or not. Since there is no body that consists only of S's, we do not have to invoke the rule about not eliminating an entire body. The resulting grammar: S -> ASB | AB A -> aAS | aA | a B -> SbS | bS | Sb | b | A | bb b)The only unit production is B -> A. Thus, it suffices to replace this body A by the bodies of all the A-productions. The result: S -> ASB | AB A -> aAS | aA | a B -> SbS | bS | Sb | b | aAS | aA | a | bb

10 c)Observe that A and B each derive terminal strings, and therefore so does S. Thus, there are no useless symbols. d)Introduce variables and productions C -> a and D -> b, and use the new variables in all bodies that are not a single terminal: S -> ASB | AB A -> CAS | CA | a B -> SDS | DS | SD | b | CAS | CA | a | DD C -> a D -> b Finally, there are bodies of length 3; one, CAS, appears twice. Introduce new variables E, F, and G to split these bodies, yielding the CNF grammar: S -> AE | AB A -> CF | CA | a B -> SG | DS | SD | b | CF | CA | a | DD C -> a D -> b E -> SB F -> AS G -> DS


Download ppt "Lecture 19 Naveen Z Quazilbash. Overview CNFs-Assignment Greibach Normal Forms."

Similar presentations


Ads by Google