CSCE 222 Lecture 29
Jump to navigation
Jump to search
« previous | Friday, April 15, 2011 | next »
Finite State Automata
Given by 5-tuple: Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle M=(S, I, s, s_0, F)}
- is a set of states
- is the input alphabet
- is a transition function mapping one state to another based on the input
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle s_0} is the starting state (s0 ∈ S)
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle F} is a set of the accepting states (F ⊆ S) that we're supposed to end on
Recognize strings that end in "–ing"
States:
- Start (0)
- Saw "i" (1)
- Saw "in" (2)
- Saw "ing" (3)
Functions:
- (0|1|2|3) + "i" → (1)
- (1) + "n" → (2)
- (2) + "g" → (3)
- (1|2|3|) + anything not matching → (0)
Representing this in code: Make a piece of code for each state that
- reads the next input
- decides the next state
- jumps to the beginning of the code for that state
void start() {
char c = getNextInput();
if (c == 'i') sawI();
else start()
}
void sawI() {
char c = getNextInput();
if (c == 'n') sawIN();
else if (c == 'i') sawI();
else start();
}
void sawIN() {
char c = getNextInput();
if (c == "g") sawING();
else start();
}
void sawING() {
char c = getNextInput();
if (c) start();
}Footnotes
Read Design Patterns: Elements of Reusable Object-Oriented Software by the Gang of Four