|
|
A pattern is a set of objects with some recognizable property.
In a world of computers, a pattern is typically a string. Recognizing patterns (keywords, identifiers ...) is an essential part of compiling.
A typical problem is to recognize a special string. For example: Find the words
in a program.
The problem is: develop an algorithm which solves
find .... in a file.
Examples:
% egrep 'applepie' words applepie pineapplepie % egrep '^applepie$' words applepie
% egrep '^applepie$|^applecake$' words applepie applecake % egrep '^apple(pie|cake)$' words applepie applecake
% egrep '.*a.*e.*i.*o.*u.*' words adventitious facetious sacrilegious
% egrep '^x.*x$' words xerox
% grep '^\(.\)\(.\)\2\1$' words deed noon peep poop teet toot
-- the first and the fourth character are equal -- the second and the fifth character are equal -- the third and the sixth character are equal -- the length of the word is 6 characters
% grep '^\(.\)\(.\)\(.\)\1\2\3$' words murmur tartar testes
One solution is: Finite State Machines
|
|
Last modified 22/May/97