PJRC.COM Offline Archive, February 07, 2004
Visit this page on the live site

skip navigational linksPJRC
Shopping Cart Checkout Shipping Cost Download Website
Home MP3 Player 8051 Tools All Projects PJRC Store Site Map
You are here: 8051 Tools Code Library Lexer Search PJRC

PJRC Store
8051 Dev Board, $79
LCD 20x2 Display, $11
Serial Cable, $5
12 Volt Power, $8
More Components...
8051 Tools
Main Page
Software
PAULMON Monitor
Development Board
Code Library
89C2051 Programmer
Other Resources

Fixed String Lexer

Don't like reading docs? Why not just Skip Down to the Code?

What is it, What's it good for?

This simple fixed string lexer searches for any number of fixed strings of any length (with some limitations) in a stream of characters. Each string may be a different length, and it's pretty easy to add strings to the list or to change the string texts it will detect.

The most likely use for this simple lexer is an 8051 based system which receives commands from a computer, probably while performing other tasks. This lexer allows you to easily implement several multiple character command words in your project/product. The lexer is designed to return control quickly... no waiting for more data once the first part of a string is detected... no failure to recognize any complete command because part of another command was only partially received.

Many 8051 based projects can't spare much CPU time (or perhaps the designer's time and effort)... the typical solution seems to be single character command sets. This code uses relatively few CPU cycles and should be quite easy to use. Hopefully you won't have to resort to single character command sets unless that's what you really wanted.

Limitations

(under construction... if you need help, just ask)

Briefly, here's the limitations:

Can't recognize numbers, parameters, etc... string must be fixed when you assemble the code.

Finds overlapping and inclusive strings... command set design must be chosen carefully to avoid problems.

No error checking on your strings, string lengths, etc

Strings limited to 255 bytes long, each needs one byte of internal ram, thus limiting the number that can be included in the search list.

Can't deal with backspace.

Some code customization necessary, see the comments in the code for details.

Files to Download


Paul's 8051 Code Library, Paul Stoffregen
http://www.pjrc.com/tech/8051/lexer-fixed-string.html
Last updated: November 28, 2003
Status: needs a bit more work
Suggestions, comments, criticisms: <paul@pjrc.com>