Chomsky and Greibach Normal Forms
Chomsky and Greibach Normal Forms – p.1/24
Chomsky and Greibach Normal Forms Chomsky and Greibach Normal Forms - - PowerPoint PPT Presentation
Chomsky and Greibach Normal Forms Chomsky and Greibach Normal Forms p.1/24 Simplifying a CFG It is often convenient to simplify CFG Chomsky and Greibach Normal Forms p.2/24 Simplifying a CFG It is often convenient to
Chomsky and Greibach Normal Forms – p.1/24
Chomsky and Greibach Normal Forms – p.2/24
Chomsky and Greibach Normal Forms – p.2/24
Chomsky and Greibach Normal Forms – p.2/24
Note the difference between grammar cleaning and simplifi cation
Chomsky and Greibach Normal Forms – p.2/24
Chomsky and Greibach Normal Forms – p.3/24
Chomsky and Greibach Normal Forms – p.4/24
Chomsky and Greibach Normal Forms – p.5/24
Chomsky and Greibach Normal Forms – p.6/24
Chomsky and Greibach Normal Forms – p.6/24
in Chomsky normal form
Chomsky and Greibach Normal Forms – p.6/24
in Chomsky normal form
violate Chomsky normal form conditions are replaced with equivalent rules that satisfy these conditions
Chomsky and Greibach Normal Forms – p.6/24
in Chomsky normal form
violate Chomsky normal form conditions are replaced with equivalent rules that satisfy these conditions
eliminate all
Chomsky and Greibach Normal Forms – p.6/24
in Chomsky normal form
violate Chomsky normal form conditions are replaced with equivalent rules that satisfy these conditions
eliminate all
defi nes the same language
Chomsky and Greibach Normal Forms – p.6/24
Chomsky and Greibach Normal Forms – p.7/24
Step 1: add a new start symbol
✂✁to
✄, and the rule
✂✁ ☎ ✆Chomsky and Greibach Normal Forms – p.7/24
Step 1: add a new start symbol
✂✁to
✄, and the rule
✂✁ ☎ ✆Note: this change guarantees that the start symbol of
does not occur
Chomsky and Greibach Normal Forms – p.7/24
where
✁is not the start symbol
with that occurrence of
✁deleted Example: replace
✂ ☎ ✆ ✄ ✁✆☎by
✂ ☎ ✆ ✄ ✁ ☎ ✝ ✄ ☎; replace
✂ ☎ ✆ ✄ ✁ ☎ ✁✆✞by
✂ ☎ ✆ ✄ ✁ ☎ ✁✆✞ ✝ ✄ ☎ ✁✆✞ ✝✠✟ ✁✆☎ ✞ ✝ ✄ ☎ ✞, (if it is present) by
✂ ☎ ✆ ✁ ✝rule
✂ ☎ ✆Chomsky and Greibach Normal Forms – p.8/24
, add the rule
✁ ☎ ✆ ✄to
✝, unless
✂ ✆ ✄was a unit rule previously removed
Chomsky and Greibach Normal Forms – p.9/24
,
☎ ✆ ✝, where each
✄ ✞,
✟ ✠ ✡ ✠ ☎, is a variable or a terminal, by:
✁ ☎ ✆ ✄,
✂ ✂ ✂,
✁ ✄☞☛ ✁ ☎ ✆ ✄ ✄☞☛where
✁,
✂ ✂ ✂,
✁ ✄☞☛ ✁are new variables
replace any terminal
✄ ✞with a new variable
✍ ✞and add the rule
✍ ✞ ☎ ✆ ✄ ✞Chomsky and Greibach Normal Forms – p.10/24
,
☎ ✆ ✝, where each
✄ ✞,
✟ ✠ ✡ ✠ ☎, is a variable or a terminal, by:
✁ ☎ ✆ ✄,
✂ ✂ ✂,
✁ ✄☞☛ ✁ ☎ ✆ ✄ ✄☞☛where
✁,
✂ ✂ ✂,
✁ ✄☞☛ ✁are new variables
replace any terminal
✄ ✞with a new variable
✍ ✞and add the rule
✍ ✞ ☎ ✆ ✄ ✞Chomsky and Greibach Normal Forms – p.10/24
,
☎ ✆ ✝, where each
✄ ✞,
✟ ✠ ✡ ✠ ☎, is a variable or a terminal, by:
✁ ☎ ✆ ✄,
✂ ✂ ✂,
✁ ✄☞☛ ✁ ☎ ✆ ✄ ✄☞☛where
✁,
✂ ✂ ✂,
✁ ✄☞☛ ✁are new variables
replace any terminal
✄ ✞with a new variable
✍ ✞and add the rule
✍ ✞ ☎ ✆ ✄ ✞Chomsky and Greibach Normal Forms – p.10/24
Consider the grammar
✁whose rules are:
After fi rst step of transformation we get:
Consider the grammar
✁whose rules are:
After fi rst step of transformation we get:
Consider the grammar
✁whose rules are:
After fi rst step of transformation we get:
Removing
✂ ✆Removing
✁ ✆Chomsky and Greibach Normal Forms – p.12/24
Removing
✂ ✆Removing
✁ ✆Chomsky and Greibach Normal Forms – p.12/24
Removing
✂ ✆Removing
✁ ✆Chomsky and Greibach Normal Forms – p.12/24
Removing
Removing
Chomsky and Greibach Normal Forms – p.13/24
Removing
Removing
Chomsky and Greibach Normal Forms – p.13/24
Removing
Removing
Chomsky and Greibach Normal Forms – p.13/24
Removing
✁ ✆ ✂:
Removing
✁ ✆Chomsky and Greibach Normal Forms – p.14/24
Removing
✁ ✆ ✂:
Removing
✁ ✆Chomsky and Greibach Normal Forms – p.14/24
Removing
✁ ✆ ✂:
Removing
✁ ✆Chomsky and Greibach Normal Forms – p.14/24
Chomsky and Greibach Normal Forms – p.15/24
Chomsky and Greibach Normal Forms – p.15/24
Chomsky and Greibach Normal Forms – p.15/24
Chomsky and Greibach Normal Forms – p.17/24
Chomsky and Greibach Normal Forms – p.17/24
Chomsky and Greibach Normal Forms – p.17/24
Proof idea: Let
✄✂ ☎ ✆✞✝ ✟ ✝ ✝ ✝be a CFG generating
✡. Assume that
be an ordering of nonterminals.
Chomsky and Greibach Normal Forms – p.18/24
Proof idea: Let
✄✂ ☎ ✆✞✝ ✟ ✝ ✝ ✝be a CFG generating
✡. Assume that
be an ordering of nonterminals.
Chomsky and Greibach Normal Forms – p.18/24
Proof idea: Let
✄✂ ☎ ✆✞✝ ✟ ✝ ✝ ✝be a CFG generating
✡. Assume that
be an ordering of nonterminals.
Chomsky and Greibach Normal Forms – p.18/24
so that if
✁ ✞ ✆ ✁✁ ✂then
✄ ☎ ✡this is done as follows: (a) Assume that productions have been modifi ed so that for
✟ ✠ ✡ ✠ ☎,
✁ ✞ ✆ ✁✁ ✂(b) If
✁ ✄ ✆ ✁✁ ✂is a production with
✄ ✆ ☎, generate a new set of productions substituting for the
✁(c) Repeating (b) at most
☎ ☎ ✟times we obtain rules of the form
✁ ✄ ✆ ✁✞✝ ✂,
✟ ✆ ☎(d) Replace rules
✁ ✄ ✆ ✁ ✄ ✂by removing left-recursive rules
Chomsky and Greibach Normal Forms – p.19/24
so that if
✁ ✞ ✆ ✁✁ ✂then
✄ ☎ ✡this is done as follows: (a) Assume that productions have been modifi ed so that for
✟ ✠ ✡ ✠ ☎,
✁ ✞ ✆ ✁✁ ✂(b) If
✁ ✄ ✆ ✁✁ ✂is a production with
✄ ✆ ☎, generate a new set of productions substituting for the
✁(c) Repeating (b) at most
☎ ☎ ✟times we obtain rules of the form
✁ ✄ ✆ ✁✞✝ ✂,
✟ ✆ ☎(d) Replace rules
✁ ✄ ✆ ✁ ✄ ✂by removing left-recursive rules
Chomsky and Greibach Normal Forms – p.19/24
so that if
✁ ✞ ✆ ✁✁ ✂then
✄ ☎ ✡this is done as follows: (a) Assume that productions have been modifi ed so that for
✟ ✠ ✡ ✠ ☎,
✁ ✞ ✆ ✁✁ ✂(b) If
✁ ✄ ✆ ✁✁ ✂is a production with
✄ ✆ ☎, generate a new set of productions substituting for the
✁(c) Repeating (b) at most
☎ ☎ ✟times we obtain rules of the form
✁ ✄ ✆ ✁✞✝ ✂,
✟ ✆ ☎(d) Replace rules
✁ ✄ ✆ ✁ ✄ ✂by removing left-recursive rules
Chomsky and Greibach Normal Forms – p.19/24
are all
✁left recursive rules, and
✁ ✆ ✄are all remaining
✁nonterminal, say
✂,
✟ ✠ ✡ ✠,
✟ ✠ ✡ ✠ ✂Chomsky and Greibach Normal Forms – p.20/24
are all
✁left recursive rules, and
✁ ✆ ✄are all remaining
✁nonterminal, say
✂,
✟ ✠ ✡ ✠,
✟ ✠ ✡ ✠ ✂Chomsky and Greibach Normal Forms – p.20/24
are all
✁left recursive rules, and
✁ ✆ ✄are all remaining
✁nonterminal, say
✂,
✟ ✠ ✡ ✠,
✟ ✠ ✡ ✠ ✂Chomsky and Greibach Normal Forms – p.20/24
21-1
Chomsky and Greibach Normal Forms – p.22/24
Chomsky and Greibach Normal Forms – p.23/24
Chomsky and Greibach Normal Forms – p.23/24
Chomsky and Greibach Normal Forms – p.23/24
conditions, hence only
✁Following the procedure we replace
✁,
✂Chomsky and Greibach Normal Forms – p.24/24
conditions, hence only
✁Following the procedure we replace
✁,
✂Chomsky and Greibach Normal Forms – p.24/24
conditions, hence only
✁Following the procedure we replace
✁,
✂Chomsky and Greibach Normal Forms – p.24/24