Download presentation

Presentation is loading. Please wait.

Published byClare Hancock Modified over 2 years ago

2
Dept. of Computer Science & IT, FUUAST Automata Theory 2 Automata Theory VII

3
Dept. of Computer Science & IT, FUUAST Automata Theory 3 Automata Theory VII Simplification of CFG Elimination of 1)Useless Symbols or Productions: A variable A is useful if it is generating as : S * xAy * w. A V and x,y in (V T)* otherwise useless. If a variable is not reachable it is useless as B is useless in the following rules. B is not reachable from starting symbol S. S A A aA| B bA 2) -productions (Empty Productions) A , it is called “NULLABLE” 3)Unit Productions A B

4
Dept. of Computer Science & IT, FUUAST Automata Theory 4 Automata Theory VII Examples: 1)Given a CFG as: G = ({S, A, B, C, E},{a,b,c}, P, S) P is defined as: S AB A a B b B C E c | New Grammar Ĝ is: Ĝ = ({S, A, B}, {a,b}, P’, S), P’ is given as: S AB A a B b

5
Dept. of Computer Science & IT, FUUAST Automata Theory 5 Automata Theory VII Examples: 2)Given a CFG as: P is defined as: S aS | A | C A a B aa C aCb Production Rules P’ for the new grammar Ĝ are: S aS | A A a Draw a dependency graph to eliminate B. Useless symbols eliminated

6
Dept. of Computer Science & IT, FUUAST Automata Theory 6 Automata Theory VII Examples: 3) Given a CFG as: P is defined as: S AB A aAA | B bBB | Production Rules P’ for the new grammar Ĝ are: S AB | A | B A aAA | aA | a B bBB | bB | b - Productions are eliminated

7
Dept. of Computer Science & IT, FUUAST Automata Theory 7 Automata Theory VII Examples: 4) Given a CFG as: G = ({S, A, B, C, D, E},{a,b}, P, S) P is defined as: S AB A a B C | b C D D E E a New Grammar Ĝ is: Ĝ = ({S, A, B, C, D}, {a,b}, P’, S), P’ is given as: S AB A a B b B a C a D a Eliminating unit production

8
Dept. of Computer Science & IT, FUUAST Automata Theory 8 Automata Theory VII Every nonempty CFL without has a grammar G in which all productions are in one of two simpler forms, either: 1)A BC, where A, B and C are each variables, or 2)A a G has no useless symbols Chomsky Normal Form (CNF) “ Every context-free language can be generated by a grammar with no useless symbols and no unit productions”

9
Dept. of Computer Science & IT, FUUAST Automata Theory 9 Automata Theory VII Examples: 1) A grammar with production P is given S aAbB A aA | a B bB | b For S aAbB, we have S B a AB b B B a a B b b For A aA, we have A B a A For B bB, we have B B b B New Grammar G 1 is given by G 1 = ({S, A, B, B a, B b }, {a,b},P’,S) P’ has productions S B a AB b B A B a A B B b B B a a B b b A a B b Still not CNF change S B a AB b B

10
Dept. of Computer Science & IT, FUUAST Automata Theory 10 Automata Theory VII Examples: CNF Grammar G1 is given by G 1 = ({S, A, B, B a, B b, D1, D2}, {a,b},P’,S) P’ has productions S B a D 1 D 1 AD 2 D 2 B b B A B a A B B b B B a a B b b A a B b Now making S B a AB b B into proper form we assume new variables D 1 and D 2 and the productions S B a D 1 D 1 AD 2 D 2 B b B

11
Dept. of Computer Science & IT, FUUAST Automata Theory 11 Automata Theory VII Examples: 2) A grammar with production P is given S ABa A aab B Ac For S ABa, we have S ABB a B a a For A aab we have A B a B a B b B b b For A Ac, we have B AB c B c c For B bB, we have B B b B New Grammar G 1 is given by with P’ G 1 = ({S, A, B, B a, B b,B c }, {a,b,c},P’,S) P’ has productions S ABB a A B a B a B b B AB c B a a B b b B c c S ABB a and A B a B a B b are not in proper form

12
Dept. of Computer Science & IT, FUUAST Automata Theory 12 Automata Theory VII Examples: CNF Grammar G1 is given by G 1 = ({S, A, B, B a, B b, D1, D2}, {a,b,c},P’,S) P’ has productions S A D 1 D 1 BB a A B a D 2 D 2 B a B b B AB c B a a B b b B c c Now making S ABB a and A B a B a B b into proper form we assume new variables D 1 and D 2 and the productions S A D 1 D 1 BB a A B a D 2 D 2 B a B b

13
Dept. of Computer Science & IT, FUUAST Automata Theory 13 Automata Theory VII End of Chapter 7

Similar presentations

Presentation is loading. Please wait....

OK

Context Free Grammars.

Context Free Grammars.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on shell structures pdf Ppt on human eye structure Ppt on fire training Ppt on nuclear family and joint family history Ppt on relations and functions for class 11th sample Ppt on job rotation program Ppt on network security free download Ppt on uniform circular motion for class 9 Ppt on traffic light control Ppt on mohandas karamchand gandhi