DS 020 Chapter 6 Simplification of ContextFree Grammars

  • Slides: 7
Download presentation
DS 020 오토마타형식언어 Chapter 6. Simplification of Context-Free Grammars and Normal Forms Exercises October

DS 020 오토마타형식언어 Chapter 6. Simplification of Context-Free Grammars and Normal Forms Exercises October 16, 2003

6. 1 METHODS FOR TRANSFORMING GRAMMARS 8. Remove all unit-productions, all useless productions, and

6. 1 METHODS FOR TRANSFORMING GRAMMARS 8. Remove all unit-productions, all useless productions, and all λ-productions from the grammar S → a. A | a. BB, A → aa. A | λ, B → b. B | bb. C, C → B. • Solution) – S a. A | a – A aa. A | aa 1) B b. B | bb. C와 C B에서 B와 C는 끝나지 않는 변수가 되므로 제거합니다 2) B가 제거되었으므로 S a. BB를 제거합니다. 3) λ-production을 제거하는 기법을 사용하여 답을 구합니다. 힌트 : 끝나지 않는 변수를 먼저 제거해 주는 것이 좋을 것 같군요 October 16, 2003

6. 1 METHODS FOR TRANSFORMING GRAMMARS 23. Use the result of the preceding exercise

6. 1 METHODS FOR TRANSFORMING GRAMMARS 23. Use the result of the preceding exercise to rewrite the grammar A → Aa | a. Bc | λ, B → Bb | bc. so that it no longer has productions of the form A → Ax or B → Bx. • Solution) A a. Bc | λ | a. Bc. X | X X a. X | a B bc | bc. Y Y b | b. Y 힌트 : 연습문제 22의 결과를 그대로 이용해 봅시다. October 16, 2003

6. 2 TWO IMPORTANT NORMAL FORMS 4. Transform the grammar with productions S →

6. 2 TWO IMPORTANT NORMAL FORMS 4. Transform the grammar with productions S → ab. AB, A → b. AB | λ, B → BAa | A | λ. into Chomsky normal form. • Solution) 1) λ production 제거 – S ab | ab. A | ab. B | ab. AB – A b | b. A | b. B | b. AB – B a | Aa | BAa | A 2) unit production 제거 – B a | Aa | Baa | b. A | b. B | b. AB – S, A는 위와 동일 3) 촘스키 형태로 변경 – S CD | EA | EB | EF – A b | DA | DB | DF – B a | AC | BC | GC | b | DA | DB | DF – C a – D b – E CD – F AB – G BA 힌트 : 일단 λ production와 unit production을 제거해봅시다. October 16, 2003

6. 2 TWO IMPORTANT NORMAL FORMS 10. Convert the grammar S → a. Bb

6. 2 TWO IMPORTANT NORMAL FORMS 10. Convert the grammar S → a. Bb | b. Sa | b into Greibach normal form. • Solution) – S a. SD | b. SC | a | b – C a – D b 힌트 : λ production이 없으니 쉽게 풀리는군요. ^^ October 16, 2003

6. 3 A MEMBERSHIP ALGORITHM FOR CONTEXT-FREE GRAMMARS 1. Use the CYK algorithm to

6. 3 A MEMBERSHIP ALGORITHM FOR CONTEXT-FREE GRAMMARS 1. Use the CYK algorithm to determine whether the strings aabb, aabba, and abbbb are in the language generated by the grammar in Example 6. 11 October 16, 2003