You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since this changes the state of the cursor just before recursing into expr, and since memoization is used as an implementation detail of left-recursion, this alters the state of the left-recursion algorithm.
That's bad.
Basically, any left recursive call that can be preceded by a state change is a no-no.
Need to add a detector and a compiler error for this.
The text was updated successfully, but these errors were encountered:
I'm not sure if this is strictly computable, but my hunch is that it is.
Here's my half-baked algorithm for figuring this out:
Build a control flow graph of the entire grammar.
Find all nodes relating to #STATE expressions in the graph.
Find all succeeding nodes from those state nodes.
Mark these nodes as being reached by the aforementioned #STATE expression.
Repeat the following process until no reachable nodes can be added:
Find any zero width node that is reached by a #STATE expression
Find the succeeding nodes from those nodes
Mark these nodes as being reached by the #STATE expressions
For each left-recursive rule
Find all paths* through the control flow graph that reach a name node referring to the rule.
Filter these paths to just those that contain only zero-width expressions
Filter these paths to just those that end with a node that is reachable by any #STATE expression
The remaining paths are guaranteed to stack overflow (unless the programmer adds code expressions to prevent it).
The definition of *all paths above is dubious, since there could easily be infinitely many paths through the graph. It may be sufficient (since we are talking about zero-width expressions) to use all strongly connected zero-width paths that touch a rule starting node and touch a name expression for that same rule.
In any case, this should only ever be a compiler warning, since code expressions can technically avoid it, but the workbench needs to be hardened against stack overflows.
Since this changes the state of the cursor just before recursing into
expr
, and since memoization is used as an implementation detail of left-recursion, this alters the state of the left-recursion algorithm.That's bad.
Basically, any left recursive call that can be preceded by a state change is a no-no.
Need to add a detector and a compiler error for this.
The text was updated successfully, but these errors were encountered: