1 / 33

2. Scanning

2. Scanning. College of Information and Communications Prof. Heejin Park. Finite automata. Finite automata consists of states transitions (on symbols) start state accepting states. f. i. 1. 2. 3. Finite automata. Used for recognizing pattern represented by regular expressions. if.

kaiya
Download Presentation

2. Scanning

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. 2. Scanning College of Information and Communications Prof. Heejin Park

  2. Finite automata • Finite automata consists of • states • transitions (on symbols) • start state • accepting states f i 1 2 3

  3. Finite automata • Used for recognizing pattern represented by regular expressions if f i 1 2 3 • 1  2  3 • i f

  4. Finite automata identifier = letter(letter|digit)*

  5. Finite automata • Error transitions are not drawn. ~letter ~(letter|digit)

  6. Finite automata • xtemp • 1  2  2  2  2  2 x t e m p

  7. Finite automata • DFA (deterministic finite automaton) • Given a state and a symbol, the next state is unique.

  8. Finite automata • NFA (nondeterministic finite automaton) • Given a state and a symbol, the next state is not unique.

  9. DFA • Examples • The set of all strings over {a,b,c} containing exactly one b. • (a|c)*b(a|c)*

  10. DFA • Examples • The set of all strings over {a,b,c} containing at most one b. • (a|c)* | (a|c)*b(a|c)* • (a|c)*(b|ε)(a|c)*

  11. DFAs for PL tokens • Examples • nat = [0-9]+ • signedNat = (+|-)? nat • number = signedNat (“.” nat)? (E signedNat)? • digit = [0-9] • nat = digit+ • signedNat = (+|-)? nat • number = signedNat (“.” nat)? (E signedNat)?

  12. DFAs for PL tokens • Examples • digit = [0-9] • nat = digit+ • singedNat = (+|-)? nat • number = signedNat (“.” nat)? (E signedNat)?

  13. DFAs for PL tokens • Examples • digit = [0-9] • nat = digit+ • signedNat = (+|-)? nat • number = signedNat (“.” nat)? (E signedNat)? nat

  14. DFAs for PL tokens • Examples • digit = [0-9] • nat = digit+ • signedNat = (+|-)? nat • number = signedNat (“.” nat)? (E signedNat)? signedNat nat

  15. DFAs for PL tokens • Examples • digit = [0-9] • nat = digit+ • signedNat = (+|-)? nat • number = signedNat (“.” nat)? (E signedNat)? signedNat signedNat nat

  16. DFAs for PL tokens • Comments • {this is a Pascal comment} • {(~})*}

  17. DFAs for PL tokens • Comments • /* this is a C comment */ • ba (b*(a*~(a|b)b*)*a*) ab

  18. DFAs for PL tokens • longest substring? ~letter ~(letter|digit) lookahead

  19. Merging DFAs • a DFA for each token  DFA for some tokens

  20. Merging DFAs • Merging DFAs when tokens begin with the same symbol. < = < > <

  21. a DFA for all PL tokens • It is possible to generate a DFA for each token and merging the DFAs. • However, it is not a systematic way. • There is a more systematic way • Regular expression  NFA  DFA

  22. NFA • Given a state and a symbol, the next state is not unique.

  23. NFA • It also includes ε-transitions. ε

  24. NFA • ε-transitions makes merging automata without combining states.

  25. NFA • NFA for the empty string. • DFA for the empty string ε

  26. NFA a b ε b 1  2  4  2  4 abb a εε b ε b 1  3  4  2  4  2  4

  27. NFA ε acab

  28. NFA • Corresponding regular expression ab+|ab*|b* or (a|ε)b*

  29. NFA • Corresponding regular expression ε (a|c)*b

  30. a a b b 1 1 2 2 3 3 a b a 4 4 Finite Automata • An alphabet Σ • the set of symbols: {a, b, … } • a set of states S • normal states, a start state, a set of accepting states • a transition function T (for avery pair of each state and each symbol) • T: SXΣ S (DFA) • T: SX (ΣU {ε})  p(S)(NFA) • T(1,a)  2 • T(1,a)  {2,4}

  31. a b 1 2 3 a 4 Finite Automata • Strings accepted by a finite automata • Strings that can reach one of the accepting states using transitions from the start state. • DFA • ab: 1  2  3 (accepted) a b • aa: 1  2  4 (not accepted) a a

  32. a b 1 2 3 b a 4 Finite Automata • Strings accepted by a finite automata • Strings that can reach one of the accepting states using transitions from the start state. • NFA • ab: 1  {2,4}  {3,2} (accepted) a b subset construction What if ε-transitions exist?

  33. Finite Automata • The language accepted by a finite automata • The set of strings accepted by the finite automata.

More Related