"Matt Froncek" <[EMAIL PROTECTED]> wrote:
> I have a program generator that creates ORs in SQL nested. This causes a
> stack overflow in SQLite. Has this been addressed or will it be? 

SQLite uses a push-down automaton to parse the input SQL.
(See http://en.wikipedia.org/wiki/Pushdown_automaton)
In the SQLite implementation, the stack depth is finite.
It is this push-down automaton stack that you are overflowing.

The default maximum stack depth is 100.  If you are planning
on parsing some deeply right-recursive SQL statements (and apparently
you are) then you will need to increase the depth of the stack.
If you use the version of Lemon that I just checked in to build
the parser, then you do this by compiling the parse.c file using

    -DYYSTACKDEPTH=10000

If you are using an older version of the code, look in parse.c 
and find the place where it sets YYSTACKDEPTH and change it
to whatever you want.

You can mitigate the deep stack problem by using left 
recursive expressions instead of right recursive expressions.  
This expression is left-recursive:

   ((((a=b OR c=d) OR e=f) OR g=h) OR i=j)

Left-recursive gets by with using a single level of the stack
for each level of parentheses.  The next expression is right-recursive:

   (a=b OR (c=d OR (e=f OR (g=h OR i=j))))

Right-recursive needs uses multiple levels of stack for each
parenthesis.  So you will overflow the stack much faster using
right-recursion.

If you omit the parentheses all together, like this:

   a=b OR c=d OR e=f OR g=h OR i=j

Then the the parser uses a finite depth stack no matter how long
the expression is.  This is your best option if you can get away
with it.

--
D. Richard Hipp  <[EMAIL PROTECTED]>


-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to