Presentation is loading. Please wait.

Presentation is loading. Please wait.

Theory Of Automata By Dr. MM Alam

Similar presentations


Presentation on theme: "Theory Of Automata By Dr. MM Alam"— Presentation transcript:

1 Theory Of Automata By Dr. MM Alam
Lecture # 25 Theory Of Automata By Dr. MM Alam

2 Lecture#24 at a glance… Unrestricted Grammars Example
User controlled Parsing in JFLAP Regular Grammar Conversion to FA

3 FA Conversion to Regular grammar
EXAMPLE 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 grammar
EXAMPLE 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 Book page 264

5 FA Conversion to Regular grammar
EXAMPLE 4 Consider the CFG: S → aA | bB A → aS | a B → bS | b This language can be defined by the regular expression (aa + bb)+. It does not have any productions of the form Nx →ʎ

6 Important Point For 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 | bB A → aS | a
B → bS | b

8 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 Used 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 => aabSbaa S → bSb => aabbaa S → ʎ Derivation Production Used S => aSa S → aSa => aaSaa S → aSa => aabbaa S → bb

15 Null Production Elimination
EXAMPLE Consider the CFG for the language defined by (a + b)*a S → Xa X → 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 → a X → a X → b

17 Null Production Elimination
The full new CFG is: S → Xa I a X → 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 => baXa X → aX => baa X → ʎ Derivation Production Used S => Xa S → Xa => bXa X → bX => baa X → a

19 Null Production Elimination
Consider this CFG for the language defined by (a + b)*bb(a + b)* S → XY X → Zb Y → bW Z → AB W → Z A → 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 Productions X → Zb X → b Y → bW Y → b Z → AB Z → A and Z → B W → Z Nothing new A → aA A → a A → bA A → b B → Ba B → a B → 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 → XY X → Zb | b Y → bW | b Z → AB| A I B W → Z A → aA | bA | a | b B → Ba | Bb | a | b

22 Eliminate Unit Productions
DEFINITION A production of the form one Nonterminal → one Nonterminal is called a unit production. See Next Slide for Details.

23 Eliminate Unit Productions
EXAMPLE Consider S → A Ibb A → B Ib B → S | a Separate the units from the nonunits:. Unit Production Other ones S → A S → bb A → B A → b B → 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 → b S → A → B gives S → a A → B gives A → a A → B → S gives A → bb B → S gives B → bb B → S → A gives B → b

25 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.


Download ppt "Theory Of Automata By Dr. MM Alam"

Similar presentations


Ads by Google