1

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?

Toby
  • 825
  • 1
  • 8
  • 16
  • 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. – 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
  • Please ask a more specific question, you'll get better answers – Voltage Spike May 22 '17 at 16:22
  • @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?? – Toby May 24 '17 at 08:45
  • @Toby Sometimes I don't look at dates – Voltage Spike May 24 '17 at 14:12

3 Answers3

3

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

HL-SDK
  • 2,539
  • 1
  • 19
  • 26
  • @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 @ https://github.com/j123b567/scpi-parser/blob/master/examples/common/scpi-def.c – Toby Jul 29 '14 at 08:22
2

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.

Dave Tweed
  • 168,369
  • 17
  • 228
  • 393
2

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.

Spehro Pefhany
  • 376,485
  • 21
  • 320
  • 842