Re: bison and valgrind



On Mar 29, 7:19 am, Allan Adler <a...@xxxxxxxxxxxxxxxxxxxx> wrote:
I've made some progress and have managed to use bison and flex to write
some simple parsers. The types that they return are complicated data
structures. Before I wrote the parser, the routines I wrote for working
with these data structures were very carefully tested to avoid memory
leaks. One of the things I did to avoid leaks was to use valgrind.

The normal way of using bison is to use it to produce a parse tree.
You write code in the actions that builds up a tree out of nodes, you
only need one or two different types of node. In the actions all that
happens is memory allocation. Then the parser completes and passes
the parse-tree to the next compiler pass. Cleanup is only done after
the parser has completed. Often either 1) The initial parse tree is
never deleted, it exists until the compiler terminates, 2) A GC is
used to clean up the tree, or 3) The whole tree is deleted after some
pass further into the compiler to save memory.

Ask on comp.compilers and you'll get a much more complete answer.

.



Relevant Pages

  • Re: c++ XML processor class?
    ... Do you imply xerces-c++ doesn't have a DOM parser? ... rather I don't see a easy way of traversing a tree with it and ... the key pairs I want to deal with not the whole tree structure. ...
    (comp.text.xml)
  • Re: Absolute beginner - Need some pointers
    ... This step usually is performed by a parser, ... sequence of tokens into an tree. ... use of registers later. ... Debugging a stack machine can be easier, ...
    (comp.compilers)
  • Re: bison and valgrind
    ... You write code in the actions that builds up a tree out of nodes, ... Then the parser completes and passes ... Worth checking what happens if the parser detects a syntax error. ... obviously a potential problem. ...
    (comp.programming)
  • Re: Extracting xml from html
    ... What's the best way to get at the XML? ... This is actually a tree that can be treated as XML, e.g. with XPath, XSLT, ... tree = etree.parse(r'path/to/nextpage.htm', parser) ... tag = elem.tag ...
    (comp.lang.python)
  • Re: [Q] How Is AST structured for entire program??
    ... I understand that when we parse a program, ... parse tree can be constructed, and I can construct a parse tree for ... to the parser. ... Continue reading about compiler ...
    (comp.compilers)