[antlr-interest] Stack overflow problem with C++

Ric Klaren ric.klaren at gmail.com
Tue Jul 19 10:48:41 PDT 2005


Jorg Halker wrote:
> Okay, i tried it with linux (feodora core 2) and gcc (v3.2.2). It looks like
> that the stack is larger there. So if i count until 150000 i have the same
> problem with linux and gcc: segmentation fault/stack overflow. But if i set
> up a parser which parses a file and creates an ast with the same amount of
> ast nodes like the loop from the code snippet does, everything is fine and
> the program exits well.
> 
> Is it intended that the loop creates objects on the stack?? am i wrong if i
> think that the stack should not overflow because the objects should be
> created on the heap?? 

Hmmm my guess is then that it's the reference counter that recurses too
deep while destroying the tree structure. Note that the structure you
made is very deep probably deeper than any 'real' AST would be.

Destroying the tree 'manually' with a stack you yourself maintain on the
heap might be a solution. Actually I now recall a person running into
this as well but that was a few years ago.

Cheers,

Ric


More information about the antlr-interest mailing list