Avoiding bison memory leaks + more
Hello!
Recently I decided to create a configuration-file/console-command parser for my engine, using flex/bison - primarily inspirred by the really great PxdScript series of tutorials (found at http://www.peroxide.dk/).
My original intention (it still is actually), was to write a complete UnrealScript-like system, but I thought it would be better to start with something a lot more simple, as this is the first time I''m playing around with flex/bison. So a .conf-parser it is... (with support for expressions, ifs, loops, etc etc)
At this point it works really fine - BUT with a couple of really evil problems:
When the bison-generated parser encounters an error, it simply loses the entire syntax tree "on the floor" - leaving all the allocated memory unfreed. Can anyone tell me how to avoid this? - right now I''m simply listing all allocated nodes somewhere else, but isn''t there some way to force bison to finish the tree generation, even when it encounters errors? (of course there''s situations where the generation can''t continue)
Next problem: Flex/bison tend to use loads of global variables and stuff -- and that''s not totally nice I think, as this makes "nested script execution" rather "hackish". Is it possible to tell flex/bison not to have any global variables? - if not, are there any (more OOP''ish) alternatives to flex/bision?
Sorry for these rather diffuse questions, but please enlighten me if you can
Thank you,
Rasmus Neckelmann
http://royal.adsl.dk
-- Rasmus Neckelmann
You may want to search for Flex/Bison alternatives. They are tried and tested but there are more modern systems that are probably equally full-featured. Which one you choose will depend on your platform and language.
As for why it dumps the entire syntax tree, does it construct it itself? I was under the impression that Bison only executes rules you give it, so you should be able to free the allocated memory in the error handling function.
[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]
As for why it dumps the entire syntax tree, does it construct it itself? I was under the impression that Bison only executes rules you give it, so you should be able to free the allocated memory in the error handling function.
[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]
quote: Original post by Kylotan
You may want to search for Flex/Bison alternatives. They are tried and tested but there are more modern systems that are probably equally full-featured. Which one you choose will depend on your platform and language.
I found flex++/bison++ which are C++ variants of the tools, and will certainly look into those. One course at my university mentioned JavaCC, but I''m indeed not going to use Java
Do anyone know any alternatives?
Regarding,
quote: Original post by Kylotan,
As for why it dumps the entire syntax tree, does it construct it itself? I was under the impression that Bison only executes rules you give it, so you should be able to free the allocated memory in the error handling function.
I realized how stupid my question was, a couple of days after I posted it Sure, it is just a matter of cleverly constructing the tree, so it won''t disappear into thin air. The problem arose, because I counted on bison to refine the entire tree up to the final "program" node, where I took the node and stored it globally (yick! ).
--
Rasmus Neckelmann
http://royal.adsl.dk
-- Rasmus Neckelmann
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement