Application of Finite Automata
Application of Finite Automata
Applications of nite automata include string matching algorithms, network protocols and lexical analyzers
String Processing
Consider nding all occurrences of a short string (pattern string) within a long string (text string). This can be done by processing the text through a DFA: the DFA for all strings that end with the pattern string. Each time the accept state is reached, the current position in the text is output.
Goddard 5: 2
Goddard 5: 3
Finite-State Machines
A nite-state machine is an FA together with actions on the arcs. A trivial example for a communication link:
send packet idle receive ack wait if NAK then resend
Goddard 5: 4
Goddard 5: 5
Statecharts
Statecharts model tasks as a set of states and actions. They extend FA diagrams. Here is a simplied statechart for a stopwatch.
active stopped start running
reset
stop
Goddard 5: 6
Lexical Analysis
In compiling a program, the rst step is lexical analysis. This isolates keywords, identiers etc., while eliminating irrelevant symbols. A token is a category, for example identier, relation operator or specic keyword. For example, token RE keyword then then variable name [a-zA-Z][a-zA-Z0-9]* where latter RE says it is any string of alphanumeric characters starting with a letter.
Goddard 5: 7
Lexical Analyzer
A lexical analyzer takes source code as a string, and outputs sequence of tokens. For example, for i = 1 to max do x[i] = 0; might have token sequence for id = num to id do id [ id ] = num sep As a token is identied, there may be an action. For example, when a number is identied, its value is calculated,
Goddard 5: 8