"Prof A Olowofoyeku (The African Chief)" wrote:
I have been trying to implement a "pos" function that only matches whole words. Below is my best effort. Is there a more efficient (or "better") way of implementing this? Thanks.
On looking over this thread I wonder if you are using the best technique for the job, since you don't actually specify the job. It sounds as if you are trying to parse some selection of identifiers or reserved words from incoming text. If so, I consider you are attacking the wrong end of the problem.
The first thing to do would be to isolate the identifier in the incoming text. This is very easily done in Pascal, because of the presence of one char. lookahead via f^. Once the identifier is isolated, it can be checked against one or more lists of words very rapidly.
In fact, this is an ideal spot for a perfect hash algorithm, which can establish non-membership in a single binary comparison, and confirm both membership and identity with a single string comparison. However any such perfect hash is a secondary consideration.