Reply by Frank Buss April 27, 20092009-04-27
scls19fr wrote:

> ok for the "free" command I forget... > Do I need to put it before or after return ?
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.
> What do you think about using ANTLR for this ? (instead of Lex/Yacc or > Flex/Bison) > Is the generated code better ?
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: http://www.amazon.de/Compilers-Principles-Techniques-Alfred-Aho/dp/0321491696 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 by scls19fr April 27, 20092009-04-27
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 by Anton Erasmus April 24, 20092009-04-24
On Wed, 22 Apr 2009 02:25:51 -0700 (PDT), scls19fr
<s.celles@gmail.com> wrote:

>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 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 by Frank Buss April 24, 20092009-04-24
scls19fr wrote:

> What should MicrocontrollErAS? stands for ?
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 ( http://www.skatlernen.de/tpl/karten/pik_as.png ) 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").
> It would be nice to say where is the memory leak and how I could find > it > (valgrind ?)
This is the tool I've used: http://tinyurl.com/3395mf Try searching for "malloc" and missing "free". -- Frank Buss, fb@frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de
Reply by scls19fr April 24, 20092009-04-24
On 23 avr, 07:51, Frank Buss <f...@frank-buss.de> wrote:
> scls19fr wrote: > > To Frank... I like gardening too... ;-) > > I don't like it, but sometimes I try to do some artwork :-) > http://www.shapeways.com/forum/index.php?t=msg&th=842
Wow ! maybe Pixar should hire you ;-) And I should work on microcontrollers in fields such as defence (what about a missile laucher) ;-)
> 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?".
What should MicrocontrollErAS? stands for ? It would be nice to say where is the memory leak and how I could find it (valgrind ?)
> http://groups.google.de/group/de.sci.electronics/msg/c1467276cd3776c9
I will have a look at your code Kind regards
Reply by Frank Buss April 23, 20092009-04-23
scls19fr wrote:

> To Frank... I like gardening too... ;-)
I don't like it, but sometimes I try to do some artwork :-) http://www.shapeways.com/forum/index.php?t=msg&th=842
> 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 http://svn.berlios.de/viewcvs/openphysic/c/projets/scpi > or > svn checkout svn://svn.berlios.de/openphysic/c/projets/scpi
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?".
> 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
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: http://groups.google.de/group/de.sci.electronics/msg/c1467276cd3776c9
> On an other hand I 've read this lex/yacc tutorial > http://ds9a.nl/lex-yacc/cvs/lex-yacc-howto.html > 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 > http://svn.berlios.de/viewcvs/openphysic/compilation/2_yacc/thermostat2 > or > svn checkout svn://svn.berlios.de/openphysic/compilation/2_yacc/thermostat2
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 by scls19fr April 22, 20092009-04-22
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 by Anton Erasmus April 22, 20092009-04-22
On Sat, 18 Apr 2009 12:50:59 -0700 (PDT), "noone@nowhere.undef"
<s.celles@gmail.com> wrote:

>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 >http://compilers.iecc.com/comparch/article/00-07-096 >http://coding.derkeiler.com/Archive/General/comp.arch.embedded/2007-12/msg00829.html >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
Hi, If you can get hold of a copy of Anagram, I believe this would be ideal to generate suitable code. Look at http://www.parsifalsoft.com/ 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 by scls19fr April 22, 20092009-04-22
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  http://svn.berlios.de/viewcvs/openphysic/c/projets/scpi
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
http://ds9a.nl/lex-yacc/cvs/lex-yacc-howto.html
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
http://svn.berlios.de/viewcvs/openphysic/compilation/2_yacc/thermostat2
or
svn checkout svn://svn.berlios.de/openphysic/compilation/2_yacc/thermostat2
Reply by Nobody April 22, 20092009-04-22
On Tue, 21 Apr 2009 23:15:35 +0200, Frank Buss wrote:

>> for now I have read this >> http://ds9a.nl/lex-yacc/cvs/lex-yacc-howto.html >> 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 ? > > 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.
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.