Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 50 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
50
Dung lượng
205 KB
Nội dung
RegularLanguageandRegularGrammar Objectives • Regular Expression andRegularLanguage • Regular Expression vs RegularLanguage • RegularGrammarRegular Expression Alphabet Σ 1. ∅, λ, a∈Σ are regular expressions (known as primitive regular expressions). 2. If r1 and r2 are regular expressions, so are r1 + r2, r1 . r2, r1 * , and (r1). Operator Precedence • parentheses • star-closure (*) • concatenation (.) • union (+) Languages Associated with Regular Expressions • Each regular expression stands for a set of strings of symbols in Σ each regular expression represents a language, called regularlanguage • r L(r) Example 3.1 • L(a) = {a} • L((a + b.c)* ) = {λ, a, bc, aa, abc, bca, bcbc, aaa, aabc, } • L( a + b +) syntax error Regular Languages 1. L(∅) = {} 2. L(λ) = {λ} 3. L(a) = {a} 4. L(r1 + r2) = L(r1)∪L(r2) 5. L(r1 . r2) = L(r1)L(r2) 6. L(r1 * ) = (L(r1)) * 7. L((r1)) = L(r1) 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, } Example 3.3 r = (a + b) * (a + bb) L(r) = ? Example 3.3 r = (a + b) * (a + bb) L(r) = {w| w ends with a or bb} [...]... 1} | w has no pair of consecutive zeros} * r = (1 + 01) (0 + λ) Equivalent Regular Expression r1 and r2 are equivalent iff L(r1) = L(r2) Example 3.8 r1 = a (b + c) r2 = a b + a c L(r1) = L(r2) = {ab, ac} Regular Expressions and Languages Given a regular expression r, there exists an NFA that accepts L(r) L(r) is a regularlanguage Primitive NFAs q0 q0 q0 q1 λ a NFA that accepts ∅ q1 NFA that accepts... λ Example 3.9 r = (a + bb)*(ba* + λ) λ a λ λ λ b λ b λ λ λ λ λ λ λ λ b λ λ λ a λ λ λ λ Languages andRegular Expressions Given a regularlanguage L, there exists a regular expression r such that L = L(r) Generalized Transition Graph Generalized transition graph is a transition graph whose edges are labelled with regular expressions a* q0 c* a+b q1 L(a* + a*(a +b)c*) Example 3.10 ae*d e d qi c a ce*d... finite set of terminal symbols S∈V: start variable P: finite set of productions Right-linear Grammar • Right-linear grammar: G = (V, T, S, P) Productions are of the form: A → xB A→x A, B ∈ V and x ∈ T * 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 * ... Generation of Regular Expression r1 r3 q0 r4 qf r2 r = r1*r2(r4 + r3r1*r2)* Example 3.12 r1 q0 r2 r3 r4 qf r = r1*r2(r4 + r3r1*r2)* Example 3.13 a, b b b a q0 q1 b q2 b+ab*a q0 a r = (b + ab*a)* ab*b(a + b)* ab*b a+b q2 Equivalent Regular Expression r1 and r2 are equivalent iff L(r1) = L(r2) • Example 3.14 r1 = a (b + c) r2 = a b + a c L(r1) = L(r2) = {ab, ac} Grammar Recalled • Formal grammar: G =