1 / 10

Normal Forms

Normal Forms. Lecture 19 Naveen Z Quazilbash. Overview. CNFs-Assignment Greibach Normal Forms. Assignment. Begin with the grammar: S ASB| ε AaAS|a BSbS|A|bb Are there any useless symbols? Eliminate them if so. Eliminate ε -productions. Eliminate unit productions.

lola
Télécharger la présentation

Normal Forms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Normal Forms 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 • Are there any useless symbols? Eliminate them if so. • Eliminate ε-productions. • Eliminate unit productions. • Put the grammar into Chomsky normal form.

  4. Greibach Normal Form • Each production is of the form • As or • AsB1B2B3…Bn • Where s is a symbol and B1, B2,…, Bn are variables.

  5. S-grammars (from lecture 15) • Simple grammars a.k.a s-grammars. • Rules for s-grammars: • Productions of the form AsB1B2B3….Bn,where s is a symbol and B1B2B3….Bnare variables. • For each variable A and symbol s, there is at most one production of the form: AsB1B2B3….Bn

  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

More Related