1 / 18

Chapter 3. Lexical Analysis (2)

Chapter 3. Lexical Analysis (2). Nondeterministic Finite Automata. A nondeterministic finite automaton (NFA) is a mathematical model that consists of 1. a set of state S 2. a set of input symbols  (the input symbol alphabet )

Download Presentation

Chapter 3. Lexical Analysis (2)

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. Chapter 3.Lexical Analysis (2)

  2. Nondeterministic Finite Automata • A nondeterministic finite automaton(NFA) is a mathematical model that consists of 1. a set of state S 2. a set of input symbols  (the input symbol alphabet) 3. a transition function move that maps state-symbol pairs to sets of states 4. a state s0 that is distinguished as the start (or initial) state 5. a set of states F distinguished as accepting (or final) states

  3. Fig. 3.19. A nondeterministic finite automaton. Fig. 3.20. Transition table for the finite automaton of Fig. 3.19.

  4. Deterministic Finite Automata • A deterministic finite automata(DFA) is a special case of a nondeterministic finite automaton in which 1. no state has an -transition, i.e., a transition on input , and 2. for each state s and input symbol a, there is at most one edge labeled a leaving s.

  5. Fig. 3.21. NFA accepting aa* |bb*.

  6. Fig. 3.23. DFA accepting (a|b)*abb.

  7. Fig. 3.24. Operations on NFA states.

  8. Example 3.15 -closure(move(A, a)) -closure(move({0, 1, 2, 4, 7}, a)) = -closure({3, 8}) = {1, 2 , 3, 4, 6, 7, 8} C = -closure({5}) = {1, 2, 4, 5, 6, 7} • The five different sets of states are : A = {0, 1, 2, 4, 7} D = { 1, 2, 4, 5, 6, 7, 9} B = {1, 2, 3, 4, 6, 7, 8} E = { 1, 2, 4, 5, 6, 7, 10} C = {1, 2, 4, 5, 6, 7}

  9. Fig. 3.27. NFA N for (a|b)*abb.

  10. Fig. 3.28. Translation table Dtran for DFA.

  11. Fig. 3.29. Result of applying the subset construction of Fig. 3.27.

  12. Thompson’s construction (1/2) • For , construct the NFA • For a in , construct the NFA • Suppose N(s) and N(t) are NFA’s for regular expressions s and t. a) For the regular expression s|t, construct the following composite NFA N(s|t):

  13. Thompson’s construction (2/2) b) For the regular expression st, construct the composite NFA N(st): • For the regular expression s*, construct the composite NFA N(s*): • For the parenthesized regular expression (s), use N(s) itself as the NFA.

  14. Fig. 3.32. Space and time taken to recognize regular expressions.

  15. Fig. 3.35. NFA recognizing three different patterns. (a) NFA for a, abb, and a*b+. (b) Combined NFA.

  16. Fig. 3. 38. NFA recognizing Fortran keyword IF

  17. Fig. 3.41. firstpos and lastpos for nodes in syntax tree for (a|b)*abb#.

  18. Fig. 3.42. The function followpos.

More Related