1 / 17

Lecture # 5

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.

ianthe
Télécharger la présentation

Lecture # 5

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture # 5

  2. Topics • Minimization of DFA Examples • What are the Important states of NFA? • How to convert a Regular Expression directly into a DFA ?

  3. Example # 2 • The DFA for a(b|c)*

  4. Example #2: Applying Minimization

  5. Example # 3 • Minimize the following DFA:

  6. Example 3: Minimized

  7. 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

  8. 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))

  9. 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

  10. 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

  11. 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

  12. From Regular Expression to DFA Directly: Annotating the Tree

  13. 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

  14. 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

  15. 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

  16. 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

  17. Time-Space Tradeoffs

More Related