Tutorial 1 solution

3 0 0
Tutorial 1 solution

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

Thông tin tài liệu

COMPILER CONSTRUCTION COMPILER CONSTRUCTION Week 2 Tutorial Solutions Regular Expressions, NFA and DFA 1 Let ∑ = {a,b} Write regular expressions for the languages over ∑ that contain a All strings (a|[.]

COMPILER CONSTRUCTION Week Tutorial Solutions Regular Expressions, NFA and DFA Let ∑ = {a,b} Write regular expressions for the languages over ∑ that contain: a All strings (a|b)* b The empty string ∈ c The string abb abb d The strings ba and aba ba|aba e All strings beginning with ab ab(a|b)* f All strings beginning with a a and ending with a b a(a|b)*b g All strings that contain exactly two a’s b*ab*ab* h All strings in which every a is followed by a b (b|ab)* Construct nondeterministic finite automata (NFA) from the following regular expressions: a a a (a|b)(a|b) ∈ ∈ ∈ ∈ • / \ | | ∈ ∈ ∈ ∈ / \ / \ b b a b a b 10 ∈ b a(a|b)+ • / \ a + | / \ a b ∈ a ∈ a ∈ ∈ b ∈ ∈ ∈ c (ab|b)*a • / \ * a | | / \ • b / \ a b d abb(a|b)?a • / \ • a / \ • ? / \ | • b / \ / \ a b a b ∈ a b ∈ ∈ ∈ ∈ a ∈ b ∈ ∈ a b b ∈ ∈ a b ∈ ∈ ∈ ∈ 10 a 11 Note: You may use Thompson’s construction algorithm Construct deterministic finite automata (DFA) from the NFA’s constructed in question a a B D a b a A={0,1,3} {2,5,6,8} {4,5,6,8} a A B={2,5,6,8} {7,10} {9,10} b C={4,5,6,8} {7,10} {9,10} b D={7,10} b C E E={9,10} b a a b a A={0} {1,2,3,5} B A b B={1,2,3,5} {4,7,8,2,3,5} {6,7,8,2,3,5} b C={4,7,8,2,3,5} {4,7,8,2,3,5} {6,7,8,2,3,5} D={6,7,8,2,3,5} {4,7,8,2,3,5} {6,7,8,2,3,5} c B a b a a A={0,1,2,5,8} {3,9} {6,7,8,1,2,5} b A a B={3,9} {4,7,8,1,2,5} C={6,7,8,1,2,5} {3,9} {6,7,8,1,2,5} b b D={4,7,8,1,2,5} {3,9} {6,7,8,1,2,5} C D b a C a D b d A={0} B={1} C={2} D={3,4,6,8,9,10} E={5,10,11} F={7,10} G={11} a {1} {5,10,11} {11} {11} - b {2} {3,4,6,8,9,10} {7,10} - G a A B C D b a B a a a b a a b b F E A b b a Minimise the following DFA: Partition 1: {A,E,D} {B,C} For a, {B,B,B} {C,B} For b, {E,E,D} {D,D} A a a C b b B D E b b Write a phrase using wildcards to find the following words in a document written in MSWord: a Any number b “get” and “got” c Any word that starts with a ‘s’ and ends with ‘t’ E.g “sit”, “shoot”,… (which includes blanks “sa t”) (which does not include “st”) d Any word whose beginning is “re” E.g “repeat”, “recharge” but not “trend”

Ngày đăng: 11/04/2023, 11:05

Tài liệu cùng người dùng

Tài liệu liên quan