= 0 and m >= n"> = 0 and m >= n">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

Thopson NFA Presenter: Yuen-Shuo Li Date: 2014/5/7 Department of Computer Science and Information Engineering National Cheng Kung University, Taiwan R.O.C.

Similar presentations


Presentation on theme: "Thopson NFA Presenter: Yuen-Shuo Li Date: 2014/5/7 Department of Computer Science and Information Engineering National Cheng Kung University, Taiwan R.O.C."— Presentation transcript:

1 Thopson NFA Presenter: Yuen-Shuo Li Date: 2014/5/7 Department of Computer Science and Information Engineering National Cheng Kung University, Taiwan R.O.C.

2 Introduction A regular expression (regex or regexp for short) is a special text string for describing a search pattern. National Cheng Kung University CSIE Computer & Internet Architecture Lab 2

3 Introduction Regular expression grammar National Cheng Kung University CSIE Computer & Internet Architecture Lab 3 SyntaxExample Any character except[\^$.|?*+()a matches a.. matches x or (almost) any other character | (abc|def|xyz) matches abc, defor xyz * “ab*c" matches “ac“, “abc“, “abbc”, “abbbc”,... + “a+" matches “a“, “aa“, “aaa”, “aaa”,... ?abc? matches abc or ab [][abc] matches a, b or c {n} a{3} matches aaa {n,m}{n,m} where n >= 0 and m >= n

4 Introduction In automata theory, a nondeterministic finite automaton (NFA), or nondeterministic finite state machine, is a finite state machine that does not require input symbols for state transitions is capable of transitioning to zero or two or more states for a given start state and input symbol. National Cheng Kung University CSIE Computer & Internet Architecture Lab 4 ε a a ε

5 Introduction Thompson's Construction Algorithm (TCA) derives a nondeterministic finite automaton (NFA) from any regular expression by splitting it into its constituent subexpressions, from which the NFA will be constructed using a set of rules. National Cheng Kung University CSIE Computer & Internet Architecture Lab 5

6 The expression ε is converted to National Cheng Kung University CSIE Computer & Internet Architecture Lab 6 ε e.g. A? => (A|ε)

7 A symbol a of the input alphabet is converted to National Cheng Kung University CSIE Computer & Internet Architecture Lab 7 a

8 The union expression RE1|RE2 is converted to National Cheng Kung University CSIE Computer & Internet Architecture Lab 8 a ε RE1 ε ε RE2 ε

9 The concatenation expression RE1 . RE2 is converted to National Cheng Kung University CSIE Computer & Internet Architecture Lab 9 a RE1 RE2

10 The concatenation expression RE1 . RE2 is converted to National Cheng Kung University CSIE Computer & Internet Architecture Lab 10 a RE1 RE2 or

11 The Kleene star expression RE* is converted to National Cheng Kung University CSIE Computer & Internet Architecture Lab 11 ε RE ε ε ε

12 (AB|CD)E* National Cheng Kung University CSIE Computer & Internet Architecture Lab 12 A

13 (AB|CD)E* National Cheng Kung University CSIE Computer & Internet Architecture Lab 13 A B

14 (AB|CD)E* National Cheng Kung University CSIE Computer & Internet Architecture Lab 14 A B AB

15 (AB|CD)E* National Cheng Kung University CSIE Computer & Internet Architecture Lab 15 AB

16 (AB|CD)E* National Cheng Kung University CSIE Computer & Internet Architecture Lab 16 AB CD

17 (AB|CD)E* National Cheng Kung University CSIE Computer & Internet Architecture Lab 17 AB CD ε ε ε ε

18 (AB|CD)E* National Cheng Kung University CSIE Computer & Internet Architecture Lab 18 A B C D ε ε ε ε

19 (AB|CD)E* National Cheng Kung University CSIE Computer & Internet Architecture Lab 19 A B C D ε ε ε ε ε ε ε ε E

20 (AB|CD)E* National Cheng Kung University CSIE Computer & Internet Architecture Lab 20 A B C D ε ε ε ε ε ε ε ε E

21 National Cheng Kung University CSIE Computer & Internet Architecture Lab 21 . | * . . A B C D E (AB|CD) E* RegexParse TreeNFA

22 National Cheng Kung University CSIE Computer & Internet Architecture Lab 22 . | * . . A B C D E http://matt.might.net/articles/parsing-regex-with-recursive-descent/

23 National Cheng Kung University CSIE Computer & Internet Architecture Lab 23 . | * . . A B C D E

24 A National Cheng Kung University CSIE Computer & Internet Architecture Lab 24 . | * . . A B C D E

25 AB National Cheng Kung University CSIE Computer & Internet Architecture Lab 25 . | * . . A B C D E

26 AB . National Cheng Kung University CSIE Computer & Internet Architecture Lab 26 . | * . . A B C D E

27 AB . C National Cheng Kung University CSIE Computer & Internet Architecture Lab 27 . | * . . A B C D E

28 AB . CD National Cheng Kung University CSIE Computer & Internet Architecture Lab 28 . | * . . A B C D E

29 AB . CD . National Cheng Kung University CSIE Computer & Internet Architecture Lab 29 . | * . A B C D E

30 AB . CD . | National Cheng Kung University CSIE Computer & Internet Architecture Lab 30 . | * . A B C D E

31 AB . CD . |E National Cheng Kung University CSIE Computer & Internet Architecture Lab 31 . | * . A B C D E

32 AB . CD . |E* National Cheng Kung University CSIE Computer & Internet Architecture Lab 32 . | * . A B C D E

33 AB . CD . |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 33 . | * . . A B C D E

34 AB . CD . |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 34 . | * . . A B C D E postfix notation

35 AB . CD . |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 35

36 AB . CD . |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 36 stack

37 B . CD . |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 37 stack A

38 B . CD . |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 38 stack A A

39 B . CD . |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 39 stack A

40 . CD . |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 40 stack A B

41 . CD . |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 41 stack A B B

42 . CD . |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 42 stack A B

43 CD . |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 43 stack A B .

44 CD . |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 44 stack A . B

45 CD . |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 45 stack . B A

46 CD . |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 46 stack BA

47 CD . |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 47 stack B A

48 D . |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 48 stack B A C

49 D . |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 49 stack B A C C

50 D . |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 50 stack B A C

51 . |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 51 stack B A C D D

52 . |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 52 stack B A C D

53 |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 53 stack B A C D .

54 |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 54 stack B A C . D

55 |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 55 stack B A . D C

56 |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 56 stack B A DC

57 |E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 57 stack B A D C

58 E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 58 stack B A D C |

59 E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 59 stack B A | DC

60 E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 60 stack | DC BA

61 E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 61 stack A B C D ε ε ε ε

62 E* . National Cheng Kung University CSIE Computer & Internet Architecture Lab 62 stack A B C D ε ε ε ε

63 * . National Cheng Kung University CSIE Computer & Internet Architecture Lab 63 stack A B C D ε ε ε ε E

64 * . National Cheng Kung University CSIE Computer & Internet Architecture Lab 64 stack A B C D ε ε ε ε E E

65 * . National Cheng Kung University CSIE Computer & Internet Architecture Lab 65 stack A B C D ε ε ε ε E

66 . National Cheng Kung University CSIE Computer & Internet Architecture Lab 66 stack A B C D ε ε ε ε E *

67 . National Cheng Kung University CSIE Computer & Internet Architecture Lab 67 stack A B C D ε ε ε ε * E

68 . National Cheng Kung University CSIE Computer & Internet Architecture Lab 68 stack A B C D ε ε ε ε * ε ε ε ε E

69 . National Cheng Kung University CSIE Computer & Internet Architecture Lab 69 stack A B C D ε ε ε ε * ε ε ε ε E

70 National Cheng Kung University CSIE Computer & Internet Architecture Lab 70 A B C D ε ε ε ε ε ε ε ε E

71 Regular Expression to NFA DFA http://hackingoff.com/compilers/regular-expression-to- nfa-dfa http://hackingoff.com/compilers/regular-expression-to- nfa-dfa National Cheng Kung University CSIE Computer & Internet Architecture Lab 71


Download ppt "Thopson NFA Presenter: Yuen-Shuo Li Date: 2014/5/7 Department of Computer Science and Information Engineering National Cheng Kung University, Taiwan R.O.C."

Similar presentations


Ads by Google