1. Trang chủ
  2. » Công Nghệ Thông Tin

sliek môn máy tự động chương 6 simplication of context-free

39 128 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 39
Dung lượng 128,23 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Simplification of Context-Free GrammarsSome useful substitution rules.. Chapter 6: Simplification of Context-Free Grammars... Removing Useless ProductionsG = V, T, S, P A production is u

Trang 1

Chapter 6: Simplification of Context-Free

Grammars

November 13, 2009

Trang 2

Simplification of Context-Free Grammars

Some useful substitution rules

Removing useless productions

Removing λ-productions

Removing unit-productions

Chapter 6: Simplification of Context-Free Grammars

Trang 3

Some Useful Substitution Rules

Trang 4

A → a | aaA | abbAc | abbc

Chapter 6: Simplification of Context-Free Grammars

Trang 7

Removing Useless Productions

S → aSb | λ | A

A → aA

S → A is redundant as Acannot be transformed into aterminal string

Trang 8

Removing Useless Productions

G = (V, T, S, P)

A production is useless if it involves anyuseless variable

Chapter 6: Simplification of Context-Free Grammars

Trang 12

Theorem 6.1 - Linz ’s book

Theorem

Let G = (V, T, S, P) be a context-free grammar Then there

contain any useless variables or productions

Chapter 6: Simplification of Context-Free Grammars

Trang 13

Proof of theorem 6.1 - Linz ’s book

Construct (V1, T, S, P1) such that V1 contains only variables

1 Set V1to ∅.

2 Repeat until no more variables are added to V 1 :

For every A ∈ T for which P has a production of the form

A → x 1 x 2 x n (x i ∈ T∗∪ V 1 ) add A to V 1

3 Take P1 as all the productions in P with symbols in (V1∪ T ) ∗

Trang 14

Proof of theorem 6.1 - Linz ’s book

variables that cannot be reached from S

Remove those variables and the productions involving them.Eliminate any terminal that does not occur in a usefulproduction

⇒ G∗ = (V∗, T∗, S, P∗)

Chapter 6: Simplification of Context-Free Grammars

Trang 16

Proof of theorem 6.1 - Linz ’s book

Chapter 6: Simplification of Context-Free Grammars

Trang 17

Theorem 6.2 - Linz ’s book

Theorem

Let G = (V, T, S, P) be a CFG such that λ ∈ L(G) Then there

Trang 18

Proof of theorem 6.2 - Linz ’s book

1 For all productions A → λ, put A into V N

2 Repeat until no more variables are added to V N :

For all productions

B → A 1 A 2 A n (A i ∈ V N ) add B to V N

Chapter 6: Simplification of Context-Free Grammars

Trang 19

Proof of theorem 6.2 - Linz ’s book

For each production in P of the form:

A → x1x2 xm (m ≥ 1, xi ∈ V ∪ T )

replacing null variables with λin all possible combination

Exception: if all xi are nullable, then A → λ is not put into

P∗

Trang 21

Removing Unit-Productions

Definition

Trang 22

Theorem 6.3 - Linz ’s book

Theorem

Let G = (V, T, S, P) be a CFG without λ-productions Then there

have any unit-productions

Chapter 6: Simplification of Context-Free Grammars

Trang 23

Proof of theorem 6.3 - Linz ’s book

For every A and B ∈ V such that

A ⇒∗B and B → y1| y2| | yn ∈ P ∗

add A → y 1 | y 2 | | y n to P∗.

Trang 25

Example 6.7

S → Aa | B

A → a | bc | B

B → A | bb

Trang 27

Theorem 6.4 - Linz ’s book

Theorem

Let L be a context-free language that does not contain λ Thenthere exists a CFG that generates L and does not have any uselessproductions, λ-productions, or unit-productions

Trang 28

Proof of theorem 6.4 - Linz ’s book

Trang 29

Two Important Normal Forms

Chomsky normal form

Greibachnormal form

Trang 30

Chomsky Normal Form

Trang 31

Theorem 6.5 - Linz ’s book

Theorem

normal form

Trang 32

Proof of theorem 6.5 - Linz ’s book

Remove all terminals from productions of length > 1:

1 Put all productions A → a into P 1

2 Repeat until no more productions are added to P 1 :

For each production

A → x 1 x 2 x n (n ≥ 2, x i ∈ T ∪ V ) add A → C 1 C 2 C n to P 1

where C i = x i if x i ∈ V or C i = B a if x i = a

Chapter 6: Simplification of Context-Free Grammars

Trang 33

Proof of theorem 6.5 - Linz ’s book

Construct G∗ = (V∗, T, S, P∗) from G1 = (V1, T, S, P1)

V∗= V1

Reduce the length of the right sides of the productions:

1 Put all productions A → a and A → BC into P∗.

2 Repeat until no more productions are added to P∗:

For each production A → C 1 C 2 C n (n ≥ 2) add A → C 1 D 1 , D 1 → C 2 D 2 , , D n−2 → C n−1 D n to P∗.

Trang 35

Greibach Normal Form

Trang 36

Theorem 6.6 - Linz ’s book

Theorem

normal form

Chapter 6: Simplification of Context-Free Grammars

Trang 37

Proof of theorem 6.6 - Linz ’s book

Rewrite the grammar in Chomsky normal form

Trang 39

Exercises: 3, 4, 5, 6, 7, 8, 17, 22 of Section 6.1 - Linzs book

Exercises: 2, 3, 4, 6, 9, 10, 11 of Section 6.2 - Linzs book

Ngày đăng: 23/10/2014, 17:47

TỪ KHÓA LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm

w