1
\$\begingroup\$

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?

\$\endgroup\$
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Adam Lawrence Feb 14 '14 at 14:39
  • \$\begingroup\$ 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. \$\endgroup\$ – Adam Lawrence Feb 14 '14 at 14:42
  • \$\begingroup\$ Please ask a more specific question, you'll get better answers \$\endgroup\$ – Voltage Spike May 22 '17 at 16:22
  • \$\begingroup\$ @laptop2d Why comment such on a 3yr old question that already has up-vote and answers, all of which have multiple up-votes, and one of which is selected as an answer?? \$\endgroup\$ – Toby May 24 '17 at 8:45
  • \$\begingroup\$ @Toby Sometimes I don't look at dates \$\endgroup\$ – Voltage Spike May 24 '17 at 14:12
2
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
3
\$\begingroup\$

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

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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