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
SPCI Parser
Started by ●April 18, 2009
Reply by ●April 24, 20092009-04-24
Reply by ●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 ●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 ●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