Re: bison and valgrind



"Chris Uppal" <chris.uppal@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:xn0f4a48hc3wwkg000@xxxxxxxxxxxxxxxxxxxx
Rob Thorpe wrote:
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.

Worth checking what happens if the parser detects a syntax error. [...]

Any time parsing is aborted, or (I think) error recovery is activated, some
nodes may have been allocated but never attached to the tree. References to
these nodes will be lost, and in the absence of garbage collection, that is
obviously a potential problem. Fortunately, it is not a hard problem to
solve: keep the nodes in another data structure (if all nodes are the same
type, a linked list would work). Then you can trivially clean up after
yyparse() returns.

Apart from such cases, I'd imagine that Bison-generated parsers are
naturally leak-free, assuming the the programmer (the Bison user) has
taken normal care.

I would imagine so, too.

Alex


.



Relevant Pages

  • 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. ... it's just a guess based on my memory of Yacc from years gone by). ...
    (comp.programming)
  • 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: 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)