headerphoto

Method: maxCallStackDepth()

maxCallStackDepth() returns an estimate of the maximum call stack depth. It is well known that recursive-descent parsers can exhibit exponential behavior for some patterns. This is due to recursion which opens the possibility that the parser may extend deep into the parse tree. This function is a simple helper to estimate the maximum call depth or recursion depth available to the current JavaScript engine. Because the call depth is limited by the call-stack space, the actual depth will be dependent on how much data a recursive function leaves on each stack frame. Therefore, the return of this function should be regarded as an upper bound.

Syntax

var exp = new apgExp(pattern[, flags]);
var depth = exp.maxCallStackDepth();

Parameters

none

Return

integer: An upper bound on the current JavaScript engine's call stack depth.

Example

var pattern, exp, result;
pattern  = 'word  = "abc"\n';
exp = new apgExp(pattern);
result = exp.maxCallStackDepth();
console.log("max depth: "+result);
/* returns */
max depth: 15699