notes22-23 Normal Forms of Grammars

notes22-23 Normal Forms of Grammars - CS 373 Theory of...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 373: Theory of Computation Gul Agha Mahesh Viswanathan Fall 2010 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
1 Normal Forms for CFG Normal Forms for Grammars It is typically easier to work with a context free language if given a CFG in a normal form . Normal Forms A grammar is in a normal form if its production rules have a special structure: Chomsky Normal Form: Productions are of the form A BC or A a Greibach Normal Form Productions are of the form A , where α V * If ± is in the language, we allow the rule S ± . We will require that S does not appear on the right hand side of any rules. In this lecture. . . How to convert any context-free grammar to an equivalent grammar in the Chomsky Normal Form We will start with a series of simplifications. .. 2 Three Simplifications 2.1 Eliminating ± -productions Eliminating ± -productions Often would like to ensure that the length of the intermediate strings in a derivation are not longer than the final string derived But a long intermediate string can lead to a short final string if there are ± -productions (rules of the form A ± ). Can we rewrite the grammar not to have ± -productions? Eliminating ± -production The Problem Given a grammar G produce an equivalent grammar G 0 (i.e., L ( G ) = L ( G 0 )) such that G 0 has no rules of the form A ± , except possibly S ± , and S does not appear on the right hand side of any rule. 2
Background image of page 2
Note: If S can appear on the RHS of a rule, say S SS , then when there is the rule S ± , we can again have long intermediate strings yielding short final strings. Nullable Variables Definition 1. A variable A (of grammar G ) is nullable if A * ± . How do you determine if a variable is nullable? If A ± is a production in G then A is nullable If A B 1 B 2 ··· B k is a production and each B i is nullable, then A is nullable. Fixed point algorithm: Propagate the label of nullable until there is no change. Using nullable variables Initial Ideas Intuition: For every variable A in G have a variable A in G 0 such that A * G 0 w iff A * G w and w 6 = ± . For every rule B CAD in G , where A is nullable, add two rules in G 0 : B CD and B CAD . The Algorithm G 0 has same variables, except for a new start symbol S 0 . For each rule A X 1 X 2 ··· X k in G , create rules A α 1 α 2 ··· α k where α i = ( X i if X i is a non-nullable variable/terminal in G X i or ± if X i is nullable in G and not all α i are ± Add rule S 0 S . If S nullable in G , add S 0 ± also. Correctness of the Algorithm By construction, there are no rules of the form A ± in G 0 (except possibly S 0 ± ), and S 0 does not appear in the RHS of any rule. L
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/04/2011 for the course CS 373 taught by Professor Viswanathan,m during the Fall '08 term at University of Illinois, Urbana Champaign.

Page1 / 9

notes22-23 Normal Forms of Grammars - CS 373 Theory of...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online