1
Lecture # 25
Theory Of AutomataBy
Dr. MM Alam
Lecture#24 at a glance…
• Unrestricted Grammars Example• User controlled Parsing in JFLAP• Regular Grammar Conversion to FA
3
FA Conversion to Regular grammarEXAMPLE 3
• Consider the CFG:S → aaS l bbS I abXI baX I λX → aaX l bbX l abS l baS
• The algorithm tells us that there will be three states: -, X, +.
4
FA Conversion to Regular grammarEXAMPLE 3
• Since there is only one production of the form
Np → wq • TG is
S → aaS l bbS I abXI baX I λX → aaX l bbX l abS l baS
5
FA Conversion to Regular grammarEXAMPLE 4
• Consider the CFG:S → aA | bBA → aS | aB → bS | b
• This language can be defined by the regular expression (aa + bb)+.
• It does not have any productions of the formNx →ʎ
6
Important PointFor a CFG to accept the word ʎ, it must have at least one production of this form, called a ʎ -production.
• A ʎ -production need not imply that ʎ is in the language, as with
S → aX X → ʎ
7
Regular Grammar • The corresponding TG:
S → aA | bBA → aS | aB → bS | b
• Regular Grammar Conversion to FA using JFLAP
• Practical Demonstration
9
Elimination of null production Theorem
Statement:If L is a context-free language generated by a CFG that includes ʎ -productions then there is a different context-free grammar that has no ʎ -productions that generates either the whole language L (if L does not include the word ʎ) or else generates the language of all the words in L that are not ʎ.
10
Proof (by Example)
• Consider CFG for EVENPALINDROME (the• palindromes with an even number of
letters):S → aSa I bSb I ʎ
• Following possible derivation:S => aSa => aaSaa => aabSbaa => aabbaa
11
Proof (Cont’d…)• When we apply this replacement rule to
the following CFG.S → aSa I bSb I ʎ
• We remove the production S → ʎ and replace it with S → aa and S → bb,
• These are the first two productions with the right-side S deleted.
12
Proof (Cont’d…)• The CFG is now:
S → aSa I bSb I aa I bb• Which also generates EVENPALINDROME,
except for the word ʎ, which can no longer be derived.
• For example, the derivation is generated in the old CFG: (Next slide)
13
Regular Grammar • OLD CFG: Derivation Production
UsedS => aSa S → aSa => aaSaa S → aSa
=> aabSbaa S → bSb
=> aabbaa S → ʎ
14
Regular Grammar • New CFG • We can combine the last two steps .
Derivation Production Used
S => aSa S → aSa => aaSaa S → aSa
=> aabbaa
S → bb
Derivation Production Used
S => aSa S → aSa => aaSaa S → aSa
=> aabSbaa S → bSb
=> aabbaa S → ʎ
15
Null Production EliminationEXAMPLE • Consider the CFG for the language defined
by (a + b)*aS → XaX → aX I bX I ʎ
• The only nullable nonterminal here is X,
16
Null Production Elimination• The productions that have right sides
including X are:Productions with Nullables
S → Xa X → aX X → bX
New Productions Formed by the Rule
S → aX → aX → b
17
Null Production Elimination• The full new CFG is:
S → Xa I aX → aX | bX | a I b
• To produce the word baa we formerly used the derivation shown In the table.
Derivation Production Used
S => Xa S → Xa
=> bXa X → bX
=> baXa X → aX
=> baa X → ʎ
18
Null Production Elimination• Combine the last two steps, and the new
derivation in the new CFG is:
Derivation Production Used
S => Xa S → Xa
=> bXa X → bX
=> baa X → a
Derivation Production Used
S => Xa S → Xa
=> bXa X → bX
=> baXa X → aX
=> baa X → ʎ
19
Null Production Elimination• Consider this CFG for the language defined
by (a + b)*bb(a + b)*S → XYX → ZbY → bWZ → ABW → ZA → aA I bA I ʎB → Ba | Bb| ʎ
20
Null Production Elimination• The modified replacement algorithm tells us
to generate new productions to replace the ʎ -productions as follows:
Old New ProductionsX → Zb X → bY → bW Y → bZ → AB Z → A and Z → BW → Z Nothing newA → aA A → aA → bA A → b B → Ba B → aB → Bb B → b
21
Null Production Elimination• We do not eliminate all of the old
productions, only the old A-productions.• The fully modified new CFG is:
S → XYX → Zb | bY → bW | bZ → AB| A I BW → ZA → aA | bA | a | bB → Ba | Bb | a | b
22
Eliminate Unit ProductionsDEFINITIONA production of the form
one Nonterminal → one Nonterminalis called a unit production.
See Next Slide for Details.
23
Eliminate Unit Productions EXAMPLE
• ConsiderS → A IbbA → B IbB → S | a
• Separate the units from the nonunits:.
Unit Production Other ones
S → A S → bbA → B A → bB → S B → a
24
Killing Unit Productions EXAMPLE
• We create the new productions that allow the first nonterminal to be replaced by any of the strings that could replace the last nonterminal in the sequence.
S → A gives S → bS → A → B gives S → aA → B gives A → aA → B → S gives A → bbB → S gives B → bbB → S → A gives B → b
Lecture# 25 Summary
• Elimination of NULL Productions• Elimination of UNIT Productions• Chomsky NORMAL Form• Thanks to Daniel I.A. cohen. The material for
these slides has been taken from his book Automata Theory.
Top Related