Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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
up vote 2 down vote accepted

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.

share|improve this answer

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.


share|improve this answer
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

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.