0% found this document useful (0 votes)
213 views

Application of Finite Automata

Applications of finite automata include string matching algorithms, network protocols and lexical analyzers. Finite automata can be used to find all occurrences of a pattern string within a text string by processing the text through a DFA for strings ending with the pattern. Finite-state machines extend finite automata by including actions on transitions. Statecharts also extend finite automata diagrams by modeling tasks as a set of states and actions. Lexical analysis in compiling isolates tokens like keywords and identifiers from a program and can be implemented using a finite automata based lexical analyzer.

Uploaded by

Karthi Keyan
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
213 views

Application of Finite Automata

Applications of finite automata include string matching algorithms, network protocols and lexical analyzers. Finite automata can be used to find all occurrences of a pattern string within a text string by processing the text through a DFA for strings ending with the pattern. Finite-state machines extend finite automata by including actions on transitions. Statecharts also extend finite automata diagrams by modeling tasks as a set of states and actions. Lexical analysis in compiling isolates tokens like keywords and identifiers from a program and can be implemented using a finite automata based lexical analyzer.

Uploaded by

Karthi Keyan
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Applications 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

Example: Finding 1001


To nd all occurrences of pattern 1001, construct the DFA for all strings ending in 1001.
1 0 1 q0 q1 1 0 1 0 0 0 q2 q3 1 q4

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

Example FSM: Bot Behavior


A bot is a computer-generated character in a video game.
nd dragon ee escape roam lose sight of nd peasant chase get far get close ght

Note that using nite-state machine allows automation.

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

You might also like