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
Kind regards
Sebastien Celles
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
Kind regards
Sebastien Celles
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
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 valuehow will you do this (with or without lex/yacc) ? and why ?
for now I have read this
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
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.
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
On an other hand I 've read this lex/yacc tutorial
Hi,
If you can get hold of a copy of Anagram, I believe this would be ideal to generate suitable code. Look at
Regards 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...
I don't like it, but sometimes I try to do some artwork :-)
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:
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
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
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 (
This is the tool I've used:
-- Frank Buss, fb@frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de
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
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 ?
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:
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
Thanks for your suggestions.
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.