Quantcast
Channel: MEL PICBASIC Forum
Viewing all articles
Browse latest Browse all 4745

String matching?

$
0
0
I'm playing around with the idea of writing a SCPI-parser. I need to match an incomming string to a series (could be dozens or hundreds) commands/keywords. For example an incoming string might look like OUTP:CH1 ON or MEAS:CURR:DC? so I need to create a list of all the keywords and then try to figure out which (if any) matches what's in the incomming string.

My idea is to use the db directive to store the keywords as null-terminated strings, like so:
Code:

ASM
Keywords
  db "OUTP", 0
  db "MEAS", 0
  db "CURR", 0
  db "VOLT", 0
  db "AC", 0
  db "DC", 0
  db "ON", 0
  db "OFF", 0
ENDASM

Obviously way simplified but it serves as an example.

I can use the EXT modifier to "get" the address in FLASH where the table Keywords starts and then use READCODE to get a char at the time and match against my incomming string. But as soon as a char doesn't match I'd rather not continue to the NULL of that keyword but instead jump to the start of the next keyword.

For that I think I'll need another table holding the addresses of where EACH keyword starts but I can't seem to figure out a way to build that table "automatically". I suppose I could do it at runtime and use WRITECODE to store it back into FLASH on the very first time the code executes but ideally I'd like the assembler (or pre-processor) to create that table for me and put it somewhere in FLASH where I can read it with READCODE.

Does that make sense? Any ideas of how to achieve this? Or, for that matter any ideas in general on how to perform string matching would be welcome!

/Henrik.

Viewing all articles
Browse latest Browse all 4745

Trending Articles