# SCPI message exchange control implementation

This is more of a software question but I figured more would be known about SCPI (IEEE 488.2) here.

I am implementing a full serial (using IEEE 1174) SCPI parser on an IC device but am wondering about the best way to implement this (in C). Currently I have used a large case switch but it is not ideal and am thinking of moving to a table approach. Does anyone have experience or suggestions on this?

-
This would be a better fit on Stack Overflow, since you're asking about how to handle a large number of formatted strings efficiently in C. –  Adam Lawrence Feb 14 '14 at 14:39
That being said, an array of a typedef struct (with a string to pattern-match and a function pointer to a handler function) could easily be put into a while loop and cranked through - I do this on a dsPIC33 to parse CLI input from RS-232 and it's quite slick. –  Adam Lawrence Feb 14 '14 at 14:42

I would recommend using some combination of lex/flex and/or yacc/bison. This is just the sort of thing that these tools were designed for.

-

If you want to code your own parser, I think Dave's answer is best (assuming you have ample runtime resources). I've used the flex/bison combination to build parsers and it was pretty straightforward and created bulletproof parsers. You might even be able to scarf up some kind of free grammar.

You could also consider just buying the IP from this company, last I looked their price was not completely insane.

-

Here is an open source library that I have tested and found to work perfectly.

I wish there was more to this answer but simply put, the work is all already done for you.

https://github.com/j123b567/scpi-parser

-
Thanks, @HL-SDK –  Spehro Pefhany Feb 14 '14 at 16:19
@HL-SDK Ta, thats a pretty good library I've come across before, however, for an embedded platform it's use of an array of full command strings takes too much memory e.g. ln# 184-189 @ github.com/j123b567/scpi-parser/blob/master/examples/common/… –  Toby Jul 29 '14 at 8:22