Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 43 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
43
Dung lượng
1,78 MB
Nội dung
Regular Expression Regular Grammar Chapter 3: Regular Language and Regular Grammar October 5, 2009 Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Objectives Regular Expression Regular Expression vs Regular Language Regular Grammar Regular Grammar vs Regular Language Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Expression Regular Expressions & Languages Regular Expression What is expression ? Alphabet ∅, λ, a ∈ are regular expressions (known as primitive regular expressions). If r 1 and r 2 are regular expressions, so are r 1 + r 2 , r 1 .r 2 , r ∗ 1 and (r1). Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Expression Regular Expressions & Languages Operator Precedence parentheses star-closure (*) concatenation (.) union (+) Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Expression Regular Expressions & Languages Languages Associated with Regular Expressions Each regular expression stands for a set of strings of symbols in ⇐⇒ each regular expression represents a language, called regular language r → L(r) Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Expression Regular Expressions & Languages Example 3.1 L(a) = {a} L((a + b.c) ∗ ) = {λ, a, bc, aa, abc, bca, bcbc, aaa, aabc, } L(a + b+) → syntax error Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Expression Regular Expressions & Languages Regular Languages 1. L(∅) = {} 2. L(λ) = {λ} 3. L(a) = {a} 4. L(r 1 + r 2 ) = L(r 1 ) ∪ L(r 2 ) 5. L(r 1 .r 2 ) = L(r 1 )L(r 2 ) 6. L(r ∗ 1 ) = L(r 1 ) ∗ 7. L((r 1 )) = L(r 1 ) Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Expression Regular Expressions & Languages Example 3.2 L(a ∗ .(a + b)) = L(a ∗ )L(a + b) = (L(a)) ∗ (L(a) ∪ L(b)) = {λ, a, aa, aaa, }.{a, b} = {a, aa, aaa, , b, ab, aab, } Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Expression Regular Expressions & Languages Example 3.3 r = (a + b) ∗ (a + bb) L(r) =??? L(r) = {w | w ends with a or bb} Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Expression Regular Expressions & Languages Example 3.4 r = (aa) ∗ (bb) ∗ b L(r) =??? L(r) = {a 2n b 2m+1 : n ≥ 0, m ≥ 0} Chapter 3: Regular Language and Regular Grammar [...]... not regular Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Grammar Regular Grammar & Language Theorem 3. 3 - Linz ’s book Theorem If G is a right-linear grammar, then L(G) is a regular language Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Grammar Regular Grammar & Language Proof of Theorem 3. 3 G = (V, T, S, P) is... ) λ λ Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Expression Regular Expressions & Languages Example 3. 8 r = (a + bb)∗ (ba∗ + λ) Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Expression Regular Expressions & Languages Theorem 3. 2 - Linz ’s book Theorem Given a regular language L, there exists a regular expression... {ab, ac} Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Expression Regular Expressions & Languages Regular Languages Definition L is regular iff L = L(M) for some DFA M Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Expression Regular Expressions & Languages Theorem 3. 1 - Linz ’s book Theorem Given a regular expression... Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Expression Regular Expressions & Languages Regular Expressions & Languages q0 q1 NFA that accepts ∅ q0 λ q1 NFA that accepts {λ} q0 a q1 NFA that accepts {a} Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Expression Regular Expressions & Languages Regular Expressions & Languages... Expression Regular Expressions & Languages Example 3. 9 e d qi a ae ∗ d c q b qj ce ∗ b ce ∗ d qi ae ∗ b qj Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Expression Regular Expressions & Languages Generation of Regular Expression r4 r1 r3 q0 r2 qf ∗ ∗ r = r1 r2 (r4 + r3 r1 r2 )∗ Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular. .. λ λ λ M(r2 ) Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Expression Regular Expressions & Languages Regular Expressions & Languages NFA that accepts L(r1 r2 ) λ M(r1 ) λ M(r2 ) λ Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Expression Regular Expressions & Languages Regular Expressions & Languages ∗ NFA that... A, B ∈ V and x ∈ T ∗ Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Grammar Regular Grammar & Language Left-linear Grammar Left-linear grammar: G = (V , T , S, P) Productions are of the form: A → Bx A→x A, B ∈ V and x ∈ T ∗ Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Grammar Regular Grammar & Language Regular. .. (1 + 01)∗ (0 + λ) Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Expression Regular Expressions & Languages Equivalent Regular Expression Definition r1 and r2 are equivalent iff L(r1 ) = L(r2 ) Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Expression Regular Expressions & Languages Example 3. 7 r1 = a.(b + c) ≡ r2 =... Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Grammar Regular Grammar & Language Grammar Recalled Formal grammar: G = (V , T , S, P) V: finite set of variables T: finite set of terminal symbols S ∈ V: start variable P: finite set of productions Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Grammar Regular Grammar & Language. .. Definition Regular grammar = right-linear or left-linear grammar Example: S → abS | a or S → S1 ab S1 → S1 ab | S2 S2 → a Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Grammar Regular Grammar & Language Example 3. 11 G1 = ({S}, {a, b}, S, P1 ) P1 = {S → abS | a} L(G1 ) = L(r) where r = (ab)∗ a Chapter 3: Regular Language and Regular Grammar Regular Expression Regular . Grammar Objectives Regular Expression Regular Expression vs Regular Language Regular Grammar Regular Grammar vs Regular Language Chapter 3: Regular Language and Regular Grammar Regular Expression Regular. Regular Expression Regular Grammar Chapter 3: Regular Language and Regular Grammar October 5, 2009 Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Objectives Regular. error Chapter 3: Regular Language and Regular Grammar Regular Expression Regular Grammar Regular Expression Regular Expressions & Languages Regular Languages 1. L(∅) = {} 2. L(λ) = {λ} 3. L(a)