





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The process of converting a context-free grammar into chomsky normal form by eliminating ϵ-productions, unit productions, and useless symbols. The document also includes examples and algorithms for each simplification step.
Typology: Study notes
1 / 9
This page cannot be seen from the preview
Don't miss anything!






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:
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.
2 Three Simplifications
Eliminating -productions
Eliminating -productions Given a grammar G produce an equivalent grammar G′^ (i.e., L(G) = L(G′)) such that G′^ has no rules of the form A → , except possibly S → , and S does not appear on the right hand side of any rule.
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.
Eliminating -productions
Definition: Nullable Variables A variable A (of grammar G) is nullable if A ⇒∗ .
How do you determine if a variable is nullable?
Eliminating Unit Productions
Eliminating unit-productions Given a grammar G produce an equivalent grammar G′^ (i.e., L(G) = L(G′)) such that G′^ has no rules of the form A → B where B ∈ V ′.
Eliminating Unit Productions Unit Productions Unit productions can play an important role in designing grammars:
I → a | b | Ia | Ib N → 0 | 1 | N 0 | N 1 | − N | + N F → I | N | (E) T → F | T ∗ F E → T | E + T
But as we shall see now, they can be (safely) eliminated
Eliminating Unit Productions Basic Idea Introduce new “look-ahead” productions to replace unit productions: look ahead to see where the unit production (or a chain of unit productions) leads to and add a rule to directly go there.
Example 2. E → T → F → I → a|b|Ia|Ib. So introduce new rules E → a|b|Ia|Ib
But what if the grammar has cycles of unit productions? For example, A → B|a, B → C|b and C → A|c. You cannot use the “look-ahead” approach, because then you will get into an infinite loop.
Eliminating Unit Productions Basic Idea: Fixed
Algorithm
Let G′^ be the grammar obtained from G using this algorithm. Then L(G′) = L(G)
Eliminating Unit Productions L(G) = L(G′): Proof
Doesn’t remove any useful symbol in either step (Why?) Only remains to show how to do the two steps in this algorithm Eliminating Useless Symbols Generating and Reachable Symbols
The set of generating symbols
The set of reachable symbols
Fixed point algorithm: Propagate the label (generating or reachable) until no change.
The Three Simplifications, Together
Given a grammar G, such that L(G) 6 = ∅, we can find a grammar G′^ such that L(G′) = L(G) and G′^ has no -productions (except possibly S → ), unit productions, or useless symbols, and S does not appear in the RHS of any rule.
Proof. Apply the following 3 steps in order:
Note: Applying the steps in a different order may result in a grammar not having all the desired properties.
3 Chomsky Normal Form
Chomsky Normal Form
Proposition 3. For any non-empty context-free language L, there is a grammar G, such that L(G) = L and each rule in G is of the form
Furthermore, G has no useless symbols.
Chomsky Normal Form Outline of Normalization Given G = (V, Σ, S, P ), convert to CNF
Chomsky Normal Form Make the RHS consist only of variables Let A → X 1 X 2 · · · Xn, with Xi being either a variable or a terminal. We want rules where all the Xi are variables.
Example 4. Consider A → BbCdef G. How do you remove the terminals? For each a, b, c... ∈ Σ add variables Xa, Xb, Xc,... with productions Xa → a, Xb → b,.. .. Then replace the production A → BbCdef G by A → BXbCXdXeXf G
For every a ∈ Σ
Chomsky Normal Form Make the RHS be of length 2