q0
| States | Inputs | |||
|---|---|---|---|---|
| a | b | c | all else | |
| q0 | q1 | - | - | - |
| q1 | - | q0 | q2 | - |
| q2 | - | - | q2 | - |
Pseudocode for a table-driven implementation is straightforward.
For the current state and input ch, table[state][ch] is the next state.
get a string
ch = first character of string
state = q0;
while ( characters remain in the string && not in reject state )
{
state = table[state][ch];
ch = next character of string
}
if ( state==q2 && no more characters in string )
string is accepted
else
string is rejected
For example, with the input string "abac" the state changes from
The final state is reached when the string is exhausted, so the string is accepted.
Will the pseudocode correctly handle an empty input string?