Download presentation

Presentation is loading. Please wait.

Published byVirginia Turkett Modified about 1 year ago

1
Finite-State Machines with No Output Ying Lu Based on Slides by Elsa L Gunter, NJIT, Costas Busch Costas Busch, and Longin Jan Latecki, Temple University

2
Kleene closure A and B are two sets of strings. The concatenation of A and B is AB={xy: x string in A and y string in B} Example: A={0, 11} and B={1, 10, 110} AB={01,010,0110,111,1110,11110} A 0 ={λ}, where λ represents the empty string A n+1 =A n Afor n=0,1,2,…

3
Let A be any set of strings formed of characters in V. Kleene closure of A, denoted by A*, is Examples: If C={11}, then C*={1 2n : n=0,1,2,…} If B={0,1}, then B*={all binary strings}.

4
Finite State Automata A FSA is similar to a compiler in that: –A compiler recognizes legal programs in some (source) language. –A finite-state machine recognizes legal strings in some language. Example: Pascal Identifiers –sequences of one or more letters or digits, starting with a letter: letter letter | digit S A

5
Finite Automaton Input “Accept” or “Reject” String Finite Automaton Output

6
Finite State Automata A finite state automaton over an alphabet is illustrated by a state diagram: – a directed graph – edges are labeled with elements of alphabet, –some nodes (or states), marked as final –one node marked as start state

7
Transition Graph initial state accepting state transition

8
Initial Configuration Input String

9
Reading the Input

10

11

12

13
accept Input finished

14
Rejection

15

16

17

18
reject Input finished

19
Another Rejection

20
reject

21
Another Example

22

23

24

25
accept Input finished

26
Rejection Example

27

28

29

30
reject Input finished

31
Finite State Automata A finite state automaton M=(S,Σ,δ,s 0,F) consists of a finite set S of states, a finite input alphabet Σ, a state transition function δ: S x Σ S, an initial state s 0, F subset of S that represent the final states.

32
Finite Automata Transition Is read ‘ In state s 1 on input “a” go to state s 2 ’ At the end of input –If in accepting state => accept –Otherwise => reject If no transition possible (got stuck) => reject FSA = Finite State Automata

33
Input Alphabet

34
Set of States

35
Initial State

36
Set of Accepting States

37
Transition Function

38

39

40

41
Transition Function

42
Language accepted by FSA The language accepted by a FSA is the set of strings accepted by the FSA. in the language of the FSM shown below: x, tmp2, XyZzy, position27. not in the language of the FSM shown below: 123, a?, 13apples. letter letter | digit S A

43
Example accept

44
Example accept

45
Example accept trap state

46
Extended Transition Function

47

48

49

50
Observation: if there is a walk from to with label then

51
Example: There is a walk from to with label

52
Recursive Definition

53
Language Accepted by FSAs For a FSA Language accepted by :

54
Observation Language rejected by :

55
Example = { all strings with prefix } accept

56
Example = { all strings without substring }

57
Example

58
Deterministic FSAs If a FSA has for every state exactly one edge for each letter in alphabet then FSA is deterministic In general a FSA is non-deterministic. Deterministic FSA special kind of non- deterministic FSA

59
Example FSA Deterministic FSA Regular expression: (0 1)* 1 0 1 1 0

60
Example DFSA Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1 0 1 1 0

61
Example DFSA Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1 0 1 1 0

62
Example DFSA Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1 0 1 1 0

63
Example DFSA Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1 0 1 1 0

64
Example DFSA Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1 0 1 1 0

65
Example DFSA Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1 0 1 1 0

66
Example DFSA Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1 0 1 1 0

67
Example NFSA Regular expression: (0 1)* 1 Non-deterministic FSA 0 1 1

68
Example NFSA Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1 0 1 1 Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1

69
Example NFSA Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1 0 1 1 Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1

70
Example NFSA Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1 0 1 1 Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1

71
Example NFSA Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1 Guess 0 1 1 Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1

72
Example NFSA Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1 Backtrack 0 1 1 Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1

73
Example NFSA Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1 Guess again 0 1 1 Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1

74
Example NFSA Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1 Guess 0 1 1 Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1

75
Example NFSA Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1 Backtrack 0 1 1 Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1

76
Example NFSA Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1 Guess again 0 1 1 Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1

77
Example NFSA Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1 0 1 1 Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1

78
Example NFSA Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1 Guess (Hurray!!) 0 1 1 Regular expression: (0 1)* 1 Accepts string 0 1 1 0 1

79
If a language L is recognized by a nondeterministic FSA, then L is recognized by a deterministic FSA NFSAFSA

80
How to Implement an FSA A table-driven approach: table: –one row for each state in the machine, and –one column for each possible character. Table[j][k] –which state to go to from state j on character k, –an empty entry corresponds to the machine getting stuck.

81
The table-driven program for a Deterministic FSA state = S // S is the start state repeat { k = next character from the input if (k == EOF) // the end of input if state is a final state then accept else reject state = T[state,k] if state = empty then reject // got stuck }

82
In-Class Exercise Construct a finite-state automaton that recognizes the set of bit strings consisting of a 0 followed by a string with an odd number of 1s.

83
Appendix

84
Regular Expressions Regular expressions describe regular languages Example: describes the language

85
Recursive Definition Are regular expressions Primitive regular expressions: Given regular expressions and

86
Examples A regular expression: Not a regular expression:

87
Languages of Regular Expressions : language of regular expression Example

88
Definition For primitive regular expressions:

89
Definition (continued) For regular expressions and

90
Example Regular expression:

91
Example Regular expression

92
Example Regular expression

93
Example Regular expression = { all strings with at least two consecutive 0 }

94
Example Regular expression = { all strings without two consecutive 0 }

95
Equivalent Regular Expressions Definition: Regular expressions and are equivalent if

96
Example = { all strings without two consecutive 0 } and are equivalent regular expr.

97
Example: Lexing Regular expressions good for describing lexemes (words) in a programming language –Identifier = (a b … z A B … Z) (a b … z A B … Z 0 1 … 9 _ ‘ )* –Digit = (0 1 … 9)

98
Implementing Regular Expressions Regular expressions, regular grammars reasonable way to generates strings in language Not so good for recognizing when a string is in language Regular expressions: which option to choose, how many repetitions to make Answer: finite state automata

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google