Finite-State Machines with No Output Longin Jan Latecki Temple University PowerPoint PPT Presentation

presentation player overlay
1 / 104
About This Presentation
Transcript and Presenter's Notes

Title: Finite-State Machines with No Output Longin Jan Latecki Temple University


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

2
Kleene closure
  • A and B are subsets of V, where V is a
    vocabularyThe concatenation of A and B
    isABxy x string in A and y string in B
  • Example A0, 11 and B1, 10,
    110AB01,010,0110,111,1110,11110
  • What is BA?
  • A0?An1AnA for n0,1,2,

3
Let A be any subset of V. Kleene closure of A,
denoted by A, is
Examples If C11, C12n n0,1,2, If
B0,1, BV.
4
Regular Expressions
  • Regular expressions
  • describe regular languages
  • Example
  • describes the language

5
Recursive Definition
Primitive regular expressions
6
Examples
A regular expression
7
Languages of Regular Expressions
  • language of regular expression
  • Example

8
Definition
  • For primitive regular expressions

9
Definition (continued)
  • For regular expressions and

10
Example
  • Regular expression

11
Example
  • Regular expression

12
Example
  • Regular expression

13
Example
  • Regular expression

14
Example
  • Regular expression

15
Equivalent Regular Expressions
  • Definition
  • Regular expressions and
  • are equivalent if

16
Example
all strings without two consecutive 0

17
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)

18
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

19
Three Equivalent Representations
Regular expressions
Each can describe the others
Regular languages
Finite automata
Kleenes Theorem For every regular expression,
there is a deterministic finite-state automaton
that defines the same language, and vice versa.
20
Regular Expression Regular Grammar
a S ? ? aS
(ab) S ? ? aS bS
a b S ? ? A B A ? a aA B ? b bB
S ? ? A B A ? a aA B ? b bB
S ? ? A B A ? a aA B ? b bB
ab S ? b aS
ba S ? bA A ? ? aA
S ? bA A ? ? aA
(ab) S ? ? abS
21
EXAMPLE 1
  • Consider the language ambn m, n ? N, which
    is represented by the regular expression ab.
  • A regular grammar for this language can be
    written as follows
  •  
  • S? ? aS B
  • B ? b bB.

22
Finite (State) Automata
  • A FA 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 digit
letter
S
A
23
Finite Automaton
Input

String
Output
Accept or Reject
Finite Automaton
24
Finite State Automata
  • A finite state automation 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

25
Transition Graph

initial state
accepting state
transition
state
26
Initial Configuration
Input String

27
Reading the Input

28

29

30

31
Input finished
accept
32
Rejection

33

34

35

36
Input finished
reject
37
Another Rejection

38

reject
39
Another Example
40
(No Transcript)
41
(No Transcript)
42
(No Transcript)
43
Input finished
accept
44
Rejection Example
45
(No Transcript)
46
(No Transcript)
47
(No Transcript)
48
Input finished
reject
49
Finite State Automata
  • A finite state automation M(S,I,f,s0,F) consists
    of
  • a finite set S of states,
  • a finite input alphabet I,
  • a state transition function f S x I ? S,
  • an initial state s0,
  • a subset F of S that represent the final states.

50
Finite Automata
  • Transition
  • s1 ?a s2
  • Is read In state s1 on input a go to state
    s2
  • If end of input
  • If in accepting state gt accept
  • Otherwise gt reject
  • If no transition possible (got stuck) gt reject
  • FSA Finite State Automata

51
Example FSA
Construct the state diagram for M(S,I,f,s0,F),
where Ss0, s1, s2, s3, I0,1, Fs0, s3and
the transition function
state Input 0 Input 1
s0 s0 s1
s1 s0 s2
s2 s0 s0
s3 s2 s1
52
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 digit
letter
S
A
53
Example
  • FSA that accepts three letter English words that
    begin with p and end with d or t.
  • Here we use the convenient notation of making the
    state name match the input that has to be on the
    edge leading to that state.

a
t
p
i
o
d
u
54
Languages Accepted by FAs
  • FA
  • Definition
  • The language contains
  • all input strings accepted by
  • strings that bring
  • to an accepting state

55
Example

accept
56
Example

accept
accept
accept
57
Example

trap state
accept
58
Formal Definition
  • Finite Automaton (FA)

set of states
input alphabet
transition function
initial state
set of accepting states
59
Input Alphabet

60
Set of States

61
Initial State

62
Set of Accepting States

63
Transition Function

64

65

66
(No Transcript)
67
Transition Function

68
Extended Transition Function

69
(No Transcript)
70
(No Transcript)
71
(No Transcript)
72
Observation if there is a walk from to
with label then
73
Example There is a walk from to
with label
74
Recursive Definition
75

76
Language Accepted by FAs
  • For a FA
  • Language accepted by

77
Observation
  • Language rejected by

78
Example
all strings with prefix

accept
79
Example
all strings without substring

80
Example

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

82
Example FSA
  • Regular expression (0 ? 1) 1
  • Deterministic FSA

83
Example DFSA
  • Regular expression (0 ? 1) 1
  • Accepts string 0 1 1 0 1

84
Example DFSA
  • Regular expression (0 ? 1) 1
  • Accepts string 0 1 1 0 1

1
0
1
0
85
Example DFSA
  • Regular expression (0 ? 1) 1
  • Accepts string 0 1 1 0 1

1
0
1
0
86
Example DFSA
  • Regular expression (0 ? 1) 1
  • Accepts string 0 1 1 0 1

1
0
1
0
87
Example DFSA
  • Regular expression (0 ? 1) 1
  • Accepts string 0 1 1 0 1

1
0
1
0
88
Example DFSA
  • Regular expression (0 ? 1) 1
  • Accepts string 0 1 1 0 1

1
0
1
0
89
Example DFSA
  • Regular expression (0 ? 1) 1
  • Accepts string 0 1 1 0 1

1
0
1
0
90
Example NFSA
  • Regular expression (0 ? 1) 1
  • Non-deterministic FSA

0
1
1
91
Example NFSA
  • Regular expression (0 ? 1) 1
  • Accepts string 0 1 1 0 1
  • Regular expression (0 1) 1
  • Accepts string 0 1 1 0 1

0
1
1
92
Example NFSA
  • Regular expression (0 ? 1) 1
  • Accepts string 0 1 1 0 1
  • Regular expression (0 1) 1
  • Accepts string 0 1 1 0 1

0
1
1
93
Example NFSA
  • Regular expression (0 ? 1) 1
  • Accepts string 0 1 1 0 1
  • Regular expression (0 1) 1
  • Accepts string 0 1 1 0 1

0
1
1
94
Example NFSA
  • Regular expression (0 ? 1) 1
  • Accepts string 0 1 1 0 1
  • Guess
  • Regular expression (0 1) 1
  • Accepts string 0 1 1 0 1

0
1
1
95
Example NFSA
  • Regular expression (0 ? 1) 1
  • Accepts string 0 1 1 0 1
  • Backtrack
  • Regular expression (0 1) 1
  • Accepts string 0 1 1 0 1

0
1
1
96
Example NFSA
  • Regular expression (0 ? 1) 1
  • Accepts string 0 1 1 0 1
  • Guess again
  • Regular expression (0 1) 1
  • Accepts string 0 1 1 0 1

0
1
1
97
Example NFSA
  • Regular expression (0 1) 1
  • Accepts string 0 1 1 0 1
  • Guess
  • Regular expression (0 1) 1
  • Accepts string 0 1 1 0 1

0
1
1
98
Example NFSA
  • Regular expression (0 ? 1) 1
  • Accepts string 0 1 1 0 1
  • Backtrack
  • Regular expression (0 1) 1
  • Accepts string 0 1 1 0 1

0
1
1
99
Example NFSA
  • Regular expression (0 ? 1) 1
  • Accepts string 0 1 1 0 1
  • Guess again
  • Regular expression (0 1) 1
  • Accepts string 0 1 1 0 1

0
1
1
100
Example NFSA
  • Regular expression (0 ? 1) 1
  • Accepts string 0 1 1 0 1
  • Regular expression (0 1) 1
  • Accepts string 0 1 1 0 1

0
1
1
101
Example NFSA
  • Regular expression (0 ? 1) 1
  • Accepts string 0 1 1 0 1
  • Guess (Hurray!!)
  • Regular expression (0 1) 1
  • Accepts string 0 1 1 0 1

0
1
1
102
If a language L is recognized by a
nondeterministic FSA, then L is recognized by a
deterministic FSA Example 9, p. 763
103
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.
  • Tablejk
  • which state to go to from state j on character k,
  • an empty entry corresponds to the machine getting
    stuck.

104
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 Tstate,k
  • if state empty then reject // got stuck
Write a Comment
User Comments (0)
About PowerShow.com