SPCI Parser

Hello,

I'm looking for an open source SPCI parser to put in a microcontroller project (ATMEL AVR) I'd like to communicate with this device using a USB com (using a FTDI FT232) I see on

formatting link
formatting link
that some other people wonder this... (without having any answer) Maybe you have a solution... Is there an open source implementation of a SPCI parser ? (at least a "free" implementation) I know the commercial JPA-SCPI Parser... but my device is not commercial (educational purpose) so I won't pay so much for this ! Maybe someone has ever made some lex/yacc script to do this... (because I don't like reinventing the wheel)

Kind regards

Sebastien Celles

Reply to
s.celles
Loading thread data ...

Sebastien

I have done all of this with Lex/Yacc for a test&measurement product on a 68332 years ago.

If this is not a commercial product, why would you want to take on the fairly painful process of getting Lex/Yacc going on an AVR? Why use such a PITA protocol (SCPI)? Will you need to support *RST, *IDN and their ilk from IEEE488? Do you need to support semicolons?

Each of these brings another level of pain to the design process.

A large part of the difficulty was getting yyparse.c and yylex.c to behave for the linker and in the memory of the 86332 and not think it is in a PC of any sort since I started with MKS. Are you using a BIG AVR? Do you know of a Lex/Yacc implementation that is already ported to a microcontroller?

Once all of these questions are answered it is not so bad building up scan.l and cmds.y to be a SCPI parser

Chris

Reply to
chris

Thanks for discouraging me ;-)

Let's say it won't be a SPCI parser... but just a parser for 3 commands :

*IDN? MEAS? get a value SET value

how will you do this (with or without lex/yacc) ? and why ?

for now I have read this

formatting link
you don't think that a C source code generated on a PC using Lex/Yacc couldn't compile and fit in an ATmega 16 ?

Reply to
scls19fr

This looks like a really small subset of SPCI. If you can't implement this on your own in some 20 lines of C in 10 minutes, you should try gardening instead of microcontroller programming :-)

I don't see why there should be a problem. I have used lex and yacc on PC (Windows and Linux), only so far, but the output should be standard C, so every C compiler should be able to compile it. And if you don't try to implement the C++ lexer and grammar file, it should fit on microcontrollers. Maybe there could be problem with available library functions, but should be easy to implement it, e.g. if strlen or something is missing.

--
Frank Buss, fb@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
Reply to
Frank Buss

Size could be an issue for a microcontroller (the ATmega16 has 16K of flash).

Machine-generated code tends to have a fair amount of boilerplate. Also, even with all of the table compression options, a state table can be inefficient for some grammars.

Reply to
Nobody

Thanks guys for your replies. To Frank... I like gardening too... ;-) but what we are talking is parsing an expression... it's, in my mind, quite different from programming a microcontroller since it's not just putting value in some registers... I have made a C source code (without Lex/Yacc) that implements the first two commands (with the hassle of upper case / lower case abbreviated commands) see

formatting link
or svn checkout svn://svn.berlios.de/openphysic/c/projets/scpi but I still wonder how I could do the third command !!!! I you have any idea it will be very helpfull I'd prefer doing in self made C source code than in Lex/Yacc because the generated code can but too long for this kind of little microcontroller

On an other hand I 've read this lex/yacc tutorial

formatting link
I have modified it to understand this commands heat on Heater on! heat off Heater off! set temperature 22 New temperature set to 22! get temperature Temperature is 22 (temperature is integer) Source code is avalaible at
formatting link
or svn checkout svn://svn.berlios.de/openphysic/compilation/2_yacc/thermostat2

Reply to
scls19fr

Hi,

If you can get hold of a copy of Anagram, I believe this would be ideal to generate suitable code. Look at

formatting link
Unfortunately the author is deceased and the software seems to be unobtanium. Another case of why proprietary is not the best. If this was an open source project, it would still have been available. I have not seen any other tool that can generate parsers which are suitable for use on small MCUs.

Regards Anton Erasmus

Reply to
Anton Erasmus

Thanks Anton So in your mind, I shouldn't make the parser myself and I should use a lexer/parser tool to generate C sourse I didn't know the parser generator you provide me... I just know lex/ yacc and flex/bison it seems to be quite similar... so if I decide to use such a tool using GNU tools (or standard unix tools) is probably a better idea...

Reply to
scls19fr

I don't like it, but sometimes I try to do some artwork :-)

formatting link

I hope you don't want to use this code in your microcontroller, because the scpi.c has at least one memory leak. And the abbreviations algorithm is wrong, e.g. "MicrocontrollErAS?" would be recognized as "MEASure?".

How does the SET command look like? The SPCI standard doesn't say anything about the data you can use for it. SPCI looks very over designed anyway. But if you want to parse more complex structures, like key/value pairs for the set command, semicolon delimited commands or e.g. the intersting CALCulate commands, I would use a recursive descent parser. if implementing it by hand, e.g. like I've demonstrated in this code:

formatting link

Are you sure this is allowed in SPCI? I've found the set command in the system subsystem, but not a get command, but I don't know which command of MEASURE, FETCH, INITIATE etc. you have to use to get some sensor value, if you want to comply to SPCI.

--
Frank Buss, fb@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
Reply to
Frank Buss

Wow ! maybe Pixar should hire you ;-) And I should work on microcontrollers in fields such as defence (what about a missile laucher) ;-)

What should MicrocontrollErAS? stands for ? It would be nice to say where is the memory leak and how I could find it (valgrind ?)

I will have a look at your code

Kind regards

Reply to
scls19fr

I don't know, but your parser would parse it as "MEASure?", because you commented the idea with the statemachine in your code. In German "As" is the name of a card (

formatting link
) and sometimes it is used for people, if they are very good in something ("he is a genius in math": "Er ist ein As in Mathe").

This is the tool I've used:

formatting link
Try searching for "malloc" and missing "free".

--
Frank Buss, fb@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
Reply to
Frank Buss

I played with a demo version of the parser generator which parsifalsoft sold. It generated much smaller code than flex/bison. Not as fast, but small is often much more important in an MCU environment than speed. It also generated code which required no library code. Unfortunately the author died the week I decided to purchase the software. I have been trying to obtain a copy ever since. I have not seen another tool which generates code which is geared towards small MCUs and which does not depend on any Standard C library code.

Regards Anton Erasmus

Reply to
Anton Erasmus

ok for the "free" command I forget... Do I need to put it before or after return ?

What do you think about using ANTLR for this ? (instead of Lex/Yacc or Flex/Bison) Is the generated code better ?

Reply to
scls19fr

I suggest that you first cleanup your code. You'll read it more often than you write it, so it is always a good idea to have a nice readable text, e.g. delete superflucious commented code and unused functions, comment each function what it does, what argument it expects, what it returns and who is responsible for allocating and deleting memory, if needed. You have already a version control system, so you can restore old versions, if you deleted too much. Imaging that you are weeding :-)

Another good idea are asserts, preconditions, postconditions and invariants. It helps you to implement algorithms and to write code with less bugs.

Regarding your question, try to follow the code line by line in your head and try to memorize the allocated and freed memory (or use a spreadsheet, one line for one line of code executing and e.g. columns for line numbers and allocated memory). This should answer your question.

I don't know, I didn't used it so far. Looks interesting. But maybe you should write your own parser, to learn more of the basic concepts. This helps you to use such parser generators later, too.

If you really want to learn this topic in-depth, I suggest this good book:

formatting link

The parser I've posted is based on some example code from the very beginning of this book. Later are more interesting topics covered, like how to implement an optimizing compiler. And unlike other books it is very practical, with not too much computer science theory.

--
Frank Buss, fb@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
Reply to
Frank Buss

Thanks for your suggestions.

Reply to
scls19fr

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.