1 / 9

Normal Forms

Normal Forms. Reading: 6.2. Normal Forms. Normal forms are special types of context-free languages. Having more restricted (but still powerful) grammar forms make important algorithms efficient. Two widely-known forms: Chomsky Normal and Greibach Normal. Chomsky Normal Form.

ankti
Download Presentation

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 Reading: 6.2

  2. Normal Forms • Normal forms are special types of context-free languages. • Having more restricted (but still powerful) grammar forms make important algorithms efficient. • Two widely-known forms: Chomsky Normal and Greibach Normal

  3. Chomsky Normal Form • No more than 2 symbols on the right hand side. • All productions are of the form:A -> BC A -> a • A,B,C variables, a terminal

  4. Power of Chomsky Normal • Every CFG can be rewritten in Chomsky Normal Form • Step 1: For any production rule with more than one terminal on the right, substitute all with variables. • Step 2: Substitute more variables in order to make the variable strings shorter.

  5. Example: Convert to CNF Step 2: S -> AD1 D1 ->BBa A -> BaD2 D2 ->BaBb B -> ABc Ba -> a Bb -> b Bc -> c Original: S -> ABa A -> aab B -> Ac Step 1: S -> ABBa A -> BaBaBb B -> ABc Ba -> a Bb -> b Bc -> c

  6. Greibach Normal Form • No restriction on length of right-hand side • Restriction on placement of variables and terminals • All productions must have the form: • A -> ax where a is a terminal and x is a string of (0 or more) variables. • Similar to s-grammars.

  7. Conversion • Any CFG has an equivalent Greibach Normal Form Grammar. • Conversion algorithm is tricky – instead just manipulate symbols

  8. Example S -> AB A -> aA | bB | b B -> b

  9. Example S -> abSb | aa

More Related