Re: bison and valgrind



Chris Uppal 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).

At one point we had a tool that parsed a specification language and built
its parse tree; we parsed the input /twice/. Once to find out if it was
syntactically valid, the second (if the first was OK) to build the tree.

I don't think I'd do it that way now -- I'd be more likely to build the
tree with an extra layer of memory-management, if I were using C or a
moral equivalent -- but it had the advantage of being dead easy, working
pretty much straight away, and not wasting effort on building the tree if
there were syntax errors in the input. (I recall that yes, this /did/ make
a difference ...)

--
JUC 2007, submit: http://hpl.hp.com/conferences/juc2007/submission.html
Scoring, bah. If I want scoring I'll go play /Age of Steam/.

Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England

.



Relevant Pages

  • Re: Code that ought to run fast, but cant due to Python limitations.
    ... have to fetch the next character to test against, ... the use case by far most common for this parser is to build a DOM (or ... DOM-like) tree of the whole document. ... more memory that the HTML source itself. ...
    (comp.lang.python)
  • 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: B+ Tree and its concept
    ... I'm going from memory here (and experience with certain implementations ... b+ tree is a representation of the index ... no need to maintain the leaf level of the index separate from the data. ... there's a b-tree variant that always splits two nodes into three, ...
    (comp.databases.theory)
  • Re: [PATCH] add b+tree library
    ... btrees maintain the tree externally. ... So btrees have to allocate memory ... +struct btree_item { ...
    (Linux-Kernel)
  • Re: hacker challenge - traverse a list
    ... Your own contributions to this subject that I have read ... Is an array "one" memory element, ... question is a proportional relationship of memory use to size of tree ... But, Harter's question belongs to programming, and not to computer ...
    (comp.programming)