Open otac0n opened 10 years ago
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:
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.
Oh yeah, and here is possibly the most mind-bending error case:
expr -memoize
= expr expr "foo"
/ #STATE{ state["bar"] = 1; }
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.