170 likes | 423 Vues
Lecture # 5. Topics. Minimization of DFA Examples What are the Important states of NFA? How to convert a Regular Expression directly into a DFA ?. Example # 2. The DFA for a( b|c )*. Example #2: Applying Minimization. Example # 3. Minimize the following DFA:. Example 3: Minimized.
E N D
Topics • Minimization of DFA Examples • What are the Important states of NFA? • How to convert a Regular Expression directly into a DFA ?
Example # 2 • The DFA for a(b|c)*
Example # 3 • Minimize the following DFA:
Example # 4 • Minimize the following DFA: b C a b a b start a b b a b b A B D E A B D E a a a a b a
Section 3.9: From Regular Expression to DFA Directly • The “important states” of an NFA are those without an -transition, that is ifmove({s},a) for some athen s is an important state • The subset construction algorithm uses only the important states when it determines-closure(move(T,a))
From Regular Expression to DFA Directly (Algorithm) • Augment the regular expression r with a special end symbol # to make accepting states important: the new expression is r# • Construct a syntax tree for r# • Traverse the tree to construct functions nullable, firstpos, lastpos, and followpos
From Regular Expression to DFA Directly: Syntax Tree of (a|b)*abb# concatenation # 6 b closure 5 b 4 a * 3 alternation | positionnumber (for leafs ) a b 1 2
From Regular Expression to DFA Directly: Annotating the Tree • nullable(n): the sub tree at node n generates languages including the empty string • firstpos(n): set of positions that can match the first symbol of a string generated by the sub tree at node n • lastpos(n): the set of positions that can match the last symbol of a string generated be the sub tree at node n • followpos(i): the set of positions that can follow position iin the tree
From Regular Expression to DFA Directly: Annotating the Tree
From Regular Expression to DFA Directly: Syntax Tree of (a|b)*abb# {1, 2, 3} {6} # {6} {6} {1, 2, 3} {5} 6 b {1, 2, 3} {4} {5} {5} nullable 5 b {1, 2, 3} {3} {4} {4} 4 firstpos lastpos a {3} {3} {1, 2} * {1, 2} 3 | {1, 2} {1, 2} a b {1} {1} {2} {2} 1 2
From Regular Expression to DFA Directly: followpos for each node n in the tree do if n is a cat-node with left child c1 and right child c2then for each iin lastpos(c1) dofollowpos(i) := followpos(i) firstpos(c2)end do else if n is a star-node for each iin lastpos(n) dofollowpos(i) := followpos(i) firstpos(n)end do end ifend do
From Regular Expression to DFA Directly: Algorithm s0 := firstpos(root) where root is the root of the syntax treeDstates := {s0} and is unmarkedwhile there is an unmarked state T in Dstatesdomark T for each input symbol a dolet U be the set of positions that are in followpos(p) for some position p in T, such that the symbol at position p is a if U is not empty and not in Dstatesthenadd U as an unmarked state to Dstates end ifDtran[T,a] := U end doend do
From Regular Expression to DFA Directly: Example 1 3 4 5 6 2 b b a start 1,2,3 1,2,3,4 b 1,2,3,5 b 1,2,3,6 a a a