Re: bison and valgrind



On Mar 29, 10:31 am, "Chris Uppal" <chris.up...@xxxxxxxxxxxxxxxxxxx
THIS.org> wrote:
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. I
suspect that the parser (i.e. the Bison input) should probably have
semantic cleanup actions for such errors, or temporary data allocated
before the error was detected may be leaked. (NB: I haven't tested
that, it's just a guess based on my memory of Yacc from years gone by).

In a normal parser for a programming language that does not matter.
Since the parser has detected an error it will exist without
generating code, and do little further allocation. The OS can deal
with cleanup.

If it is a problem such as in a persistant program than there are
other tactics. As Chris D said the parsing can be done twice.
Another method is to issue the error then wipe the temporary data,
possibly the whole parse tree, this could prevent useful error
handling though. The most sophisticated solution, apart from GC, is
the one you mention to insert code into the path that results from
bison errors that cleans up any possible allocation problems.

.



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)