The Bison parser stack can run out of memory if too many tokens are shifted and
not reduced. When this happens, the parser function
yyerror and then returns 2.
Because Bison parsers have growing stacks, hitting the upper limit usually results from using a right recursion instead of a left recursion, see Recursive Rules.
By defining the macro
YYMAXDEPTH, you can control how deep the
parser stack can become before memory is exhausted. Define the
macro with a value that is an integer. This value is the maximum number
of tokens that can be shifted (and not reduced) before overflow.
The stack space allowed is not necessarily allocated. If you specify a
large value for
YYMAXDEPTH, the parser normally allocates a small
stack at first, and then makes it bigger by stages as needed. This
increasing allocation happens automatically and silently. Therefore,
you do not need to make
YYMAXDEPTH painfully small merely to save
space for ordinary inputs that do not need much stack.
However, do not allow
YYMAXDEPTH to be a value so large that
arithmetic overflow could occur when calculating the size of the stack
space. Also, do not allow
YYMAXDEPTH to be less than
The default value of
YYMAXDEPTH, if you do not define it, is
You can control how much stack is allocated initially by defining the
YYINITDEPTH to a positive integer. For the deterministic
parser in C, this value must be a compile-time constant
unless you are assuming C99 or some other target language or compiler
that allows variable-length arrays. The default is 200.
Do not allow
YYINITDEPTH to be greater than
Because of semantic differences between C and C++, the deterministic
parsers in C produced by Bison cannot grow when compiled
by C++ compilers. In this precise case (compiling a C parser as C++) you are
suggested to grow
YYINITDEPTH. The Bison maintainers hope to fix
this deficiency in a future release.