Keyword Interpreter Code Generator

By Nikolai Golovchenko

Keywords List


Whitespaces:
Delimeters:
Case insensitive
Whole words match


Description

This code generator produces the PIC assembler code to look for keywords in a string or a serial ASCII stream.

Parsing routine receives one character at a time and returns the keyword code, or the next state, or error code. The keywords codes are given in the order they were written, starting from 1.

You can specify whether keywords are matched as the whole words or just starting unique part. This let's you use shorthand names for the keywords. Also, case insensitiveness can be specified.

The routine can skip whitespaces before a keyword. Enter the desired characters in the form entry Whitespaces. In some cases it's probably better to delete carriage return (0x0d) or line feed (0x0a) characters if you don't need them, or add some others. To detect the end of a keyword the routine needs to know what characters separate keywords in the text stream (form entry Delimiters). Often, they are the same as whitespaces, but you might want to add '\0' to work with zero terminated strings, or '(' in case the keyword is a function name, e.g. Speed(100). A delimiter character is received as a look-ahead character after a keyword matched to make sure that the keyword ended.



The routine is implemented as a variation of state machine, without explicit tables. The routine is a relatively fast runner, since it compares a character to a minimum number of constant characters, just enough to disambiguate the text meaning.

The size of the generated code is directly related to the number of keywords and their length. It takes about four instructions of program memory per each character in the text area plus jump table and a couple of small routines.

See example on how to call the parsing routine.


See:

Questions:

See also: