??? 05/13/09 17:57 Read: times |
#165300 - I WOULD write thsi in C Responding to: ???'s previous message |
I took a command parser I wrote in Keil C for the 8051 (SiLabs variants) and ported it with few changes to Xilinx MicroBlaze and PPC. In all cases, a serial-port handler accepted incoming characters until an end-of-line termination is found, and passes that buffer to the parser. The parser was identical, except for the specific commands, of course, for each project.
The parser looks for an 'S' or 'G' character (set or get), then a space, then a two-character command. A loop compares the two-character command string and if a match is found then a token is set indicating the command (this falls out of the loop iterator). If we test all commands and we don't find a match, then the parser exits with an "invalid command" indicator. Once it has a token, it's a simple switch statement based on that token to actually interpret the command. This compiles to a nice jump table, as you'd expect. -a |