skip navigational linksPJRC
Shopping Cart Download Website
Home Products Teensy Blog Forum
You are here: 8051 Tools Code Library Lexer

PJRC Store
8051 Board, $79
LCD 128x64 Pixel, $29
LCD 16x2 Char, $14
Serial Cable, $5
9 Volt Power, $6
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: February 24, 2005
Status: needs a bit more work
Suggestions, comments, criticisms: <paul@pjrc.com>