Take the 2-minute tour ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

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
1  
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. –  Madmanguruman Feb 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. –  Madmanguruman Feb 14 at 14:42

3 Answers 3

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.

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

share|improve this answer
    
Thanks, @HL-SDK –  Spehro Pefhany Feb 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 2 days ago

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

 
discard

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.